annotate interleave-fastqgz-MITOBIM.py @ 9:19d3ec566471 draft

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