-
Notifications
You must be signed in to change notification settings - Fork 0
/
NLRparser_txt2bed.py
37 lines (28 loc) · 1.13 KB
/
NLRparser_txt2bed.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
#!/usr/bin/env python
import argparse, csv
def main():
# Parse arguments.
parser = argparse.ArgumentParser(description='convert NLR-parser txt output to bed')
parser.add_argument('-i', '--input', help='indicate input.txt', required=True)
parser.add_argument('-o', '--output', help='indicate output.bed', required=True)
args = parser.parse_args()
file_in = open(args.input, 'r')
file_out = open(args.output, 'w')
reader_in = csv.reader(file_in, delimiter = '\t')
count = 0
file_out.write('#track name="NLR-Parser_predicted"\n#itemRgb="Off"\n')
for row in reader_in:
if 'SequenceName'in row[0]:
pass
else:
count += 1
if 'forward' in row[3]:
strand = '+'
elif 'reverse' in row[3]:
strand = '-'
nuRow = row[0] + '\t' + row[4] + '\t' + row[5] + '\t' + row[0] + '_' + row[2] + '\t0\t' + strand + '\t' + row[4] + '\t' + row[5] + '\t0,0,0\n'
file_out.write(nuRow)
file_out.close()
print('wrote ' + str(count) + ' rows to ' + args.output)
if __name__ == '__main__':
main()