-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert_bedpe_to_link.py
64 lines (54 loc) · 1.78 KB
/
convert_bedpe_to_link.py
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python
import csv
import re
import os
import sys
import argparse
def init_args():
"""
Initialize command line arguments
"""
description = 'Convert a BEDPE file to a link file that can be used with circos'
parser = argparse.ArgumentParser(description = description)
parser.add_argument('-s', '--sample', required=True,
help='name of the sample being processed')
parser.add_argument('-b', '--bedpe', required=True,
help='BEDPE file containing translocations')
return parser.parse_args()
def main():
"""
Main program
"""
args = init_args()
tx_colname = ['chrA', 'startA', 'endA', 'chrB', 'startB', 'endB', 'val1', 'val2']
is_intra = False
output_file = f'{args.sample}.translocation.fixed.link'
ofh = open(output_file, 'w')
with open(args.bedpe, 'r') as tx:
reader = csv.DictReader(tx, fieldnames=tx_colname, delimiter='\t')
for line in reader:
if line['chrA'].startswith('chr'):
line['chrA'] = re.sub('chr', 'hs', line['chrA'])
if line['chrB'].startswith('chr'):
line['chrB'] = re.sub('chr', 'hs', line['chrB'])
if re.search(',', line['chrB']):
continue
if line['chrA'] == line['chrB']:
is_intra = True
if is_intra:
line_color = "color=red_a5"
else:
line_color = "color=black_a5"
ofh.write('\t'.join([
line['chrA'],
line['startA'],
line['endA'],
line['chrB'],
line['startB'],
line['endB'],
line_color]))
ofh.write('\n')
ofh.close()
if __name__ == '__main__':
main()
#__END__