comparison deinterlacer.py @ 3:e320ef2d105a draft

Uploaded
author petr-novak
date Thu, 05 Sep 2019 09:04:56 -0400
parents
children
comparison
equal deleted inserted replaced
2:ff658cf87f16 3:e320ef2d105a
1 #!/usr/bin/env python3
2 '''very simple deinterlacer - fasta and fastq'''
3 import sys
4 import itertools
5
6
7 def is_header(line, counter, fasta):
8 ''' return True is line is header '''
9 if fasta:
10 if line[0] == ">":
11 return True
12 else:
13 if counter == 4 and line[0] == "@":
14 return True
15 return False
16
17
18 def main():
19 '''deinterlace fasta or fastq format'''
20 infile = sys.argv[1]
21 file_a = sys.argv[2]
22 file_b = sys.argv[3]
23 with open(infile) as f, open(file_a, 'w') as A, open(file_b, 'w') as B:
24 ABiter = itertools.cycle([A, B])
25 counter = 3 # four lines per record in fastq
26 pos = f.tell()
27 is_fasta = f.readline()[0] == ">"
28 f.seek(pos)
29 for line in f:
30 counter += 1
31 if is_header(line, counter, is_fasta):
32 fout = next(ABiter)
33 counter = 0
34 fout.write(line)
35
36
37 if __name__ == "__main__":
38 main()