-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse_breseq.py
executable file
·53 lines (43 loc) · 1.46 KB
/
parse_breseq.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
#!/usr/bin/env python
import sys
'''
Parses through multiple breseq files and prints a tab delimited file with all
mutations listed according to the respective files they were found in.
Usage: parse_breseq.py <breseq1.txt> <breseq2.txt> ...
Note: breseq files are generated by copying ALL text on breseq "index.html" pages
and saving in text format. Simply CTRL+A, CTRL+C on webpage and CTRL+V into text document.
Formatting must be precise!
Output format:
evidence seq id position mutation annotation gene description <in_file1?> <in_file2?> ...
'''
file_list = sys.argv[1:]
lines_by_file = {}
all_lines = []
for file in file_list:
lines_by_file[file] = []
file_handle = open(file)
for i, line in enumerate(file_handle.readlines()):
if i <= 5:
continue
elif line.strip().split() == []:
break
lines_by_file[file].append('\t'.join(line.strip().split(' \t')))
all_lines.append('\t'.join(line.strip().split(' \t')))
line_set = set(all_lines)
files_by_line = {}
for file in file_list:
for line in lines_by_file[file]:
if line not in files_by_line:
files_by_line[line]=[file]
else:
files_by_line[line].append(file)
sys.stdout.write('evidence\tseq id\tposition\tmutation\tannotation\tgene\tdescription\t{0}\n'.format('\t'.join(file_list)))
for line in files_by_line:
print_line = line
for query_file in file_list:
if query_file in files_by_line[line]:
print_line += '\t1'
else:
print_line += '\t0'
print_line += '\n'
sys.stdout.write(print_line)