#!/bin/env python

from __future__ import print_function
import sys

#Another script in the series on phasing using GATK and CNVnator. This script is to make
#the regions (like regnsForComplmnt.txt) from the file, for which breakpoints, CNVnator gave phasing. Here the idea is that one can give +/- kbp values, so that one can work with a larger window.

#Two arguments are being given. 
#The first is the file containing phased breakpoint coordinates. 

phsBrkPt = open(sys.argv[1])
win = int(sys.argv[2]) #specify the window
for line in phsBrkPt:
  flds = line.strip().split()
  chr = flds[0]
  lfBrkPt = int(flds[1]) #( coordinate
  rtBrkPt = int(flds[2]) #] coordinate
  lStrt = lfBrkPt-(win-1)
  rEnd = rtBrkPt+win 
  if lStrt > 0:
    print("{0}:{1}-{2}\t{3}\t{4},{5},{6}".format(chr, lStrt, lfBrkPt, flds[3], chr,lfBrkPt, rtBrkPt))
    print("{0}:{1}-{2}\t{3}\t{4},{5},{6}".format(chr, rtBrkPt+1, rEnd, flds[3], chr,lfBrkPt, rtBrkPt))#the +1 for making it )

phsBrkPt.close()
