Mercurial > repos > lijing > bubio
comparison interleave-fastqgz-MITOBIM.py @ 6:a03d23c6ab95 draft
MitoBim and interleave
author | lijing |
---|---|
date | Thu, 02 Nov 2017 12:44:55 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
5:7c679db88fa3 | 6:a03d23c6ab95 |
---|---|
1 #!/usr/bin/python | |
2 # encoding:utf8 | |
3 # authors: Erik Garrison, Sébastien Boisvert | |
4 # modified by github@cypridina on 20151104 to work with MITObim | |
5 """This script takes two fastq or fastq.gz files and interleaves them | |
6 Usage: | |
7 interleave-fasta fasta_file1 fasta_file2 | |
8 """ | |
9 | |
10 import sys,re | |
11 | |
12 def interleave(f1, f2): | |
13 """Interleaves two (open) fastq files. | |
14 """ | |
15 while True: | |
16 line = f1.readline() | |
17 if line.strip() == "": | |
18 break | |
19 print re.sub(r" 1:N.*", "/1",line.strip()) | |
20 | |
21 for i in xrange(3): | |
22 print re.sub(r" 2:N.*","/2",f1.readline().strip()) | |
23 | |
24 for i in xrange(4): | |
25 print re.sub(r" 2:N.*","/2",f2.readline().strip()) | |
26 | |
27 if __name__ == '__main__': | |
28 try: | |
29 file1 = sys.argv[1] | |
30 file2 = sys.argv[2] | |
31 except: | |
32 print __doc__ | |
33 sys.exit(1) | |
34 | |
35 if file1[-2:] == "gz": | |
36 import gzip | |
37 with gzip.open(file1) as f1: | |
38 with gzip.open(file2) as f2: | |
39 interleave(f1, f2) | |
40 else: | |
41 with open(file1) as f1: | |
42 with open(file2) as f2: | |
43 interleave(f1, f2) | |
44 f1.close() | |
45 f2.close() |