-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflankBEDpositionsStrandSpecific.py
More file actions
executable file
·41 lines (37 loc) · 1.46 KB
/
flankBEDpositionsStrandSpecific.py
File metadata and controls
executable file
·41 lines (37 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/python
'''
Created on Aug 20, 2014
@author: Igor Ruiz de los Mozos
The script will flank the region in both directions in a new bed file.
'''
import sys
def flank_positions(fin_fname, fout_fname, left_shift, right_shift):
fin = open(fin_fname, "rt")
fout = open(fout_fname, "w")
line = fin.readline()
while line:
col = line.rstrip('\n').rsplit('\t')
if line.__len__() > 6:
chr = col[0]
start = col[1]
end = col[2]
strand = col[5]
shift_start = shift_end = 0
if strand == '+':
shift_start = int(start) - int(left_shift)
shift_end = int(end) + int(right_shift)
else:
shift_end = int(end) + int(left_shift)
shift_start = int(start) - int(right_shift)
if shift_start >= 0:
fout.write(chr + '\t' + str(shift_start) + '\t' + str(shift_end) + '\t' + col[3] + '\t' + col[0] + ':' + col[1] + ':' + col[2] + '\t' + col[5] + '\n')
line = fin.readline()
if sys.argv.__len__() == 5:
fin_fname = sys.argv[1]
fout_fname = sys.argv[2]
left_shift = int(sys.argv[3])
right_shift = int(sys.argv[4])
flank_positions(fin_fname, fout_fname, left_shift, right_shift)
else:
#print str(sys.argv.__len__())
print "error:\t4 arguments are needed\n" + '\n' +"example:\t $ python bed_expand_positions.py input_fname.bed output_fname.bed left_shiftNUM right_shiftNUM"