comparison split_paired_reads.py @ 0:36163bff76cc draft default tip

Uploaded tool tarball.
author devteam
date Wed, 25 Sep 2013 11:29:58 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:36163bff76cc
1 #!/usr/bin/env python
2
3 """
4 Split fixed length paired end reads
5 """
6
7 import os, sys
8
9 if __name__ == '__main__':
10
11 infile = sys.argv[1]
12 outfile_end1 = open(sys.argv[2], 'w')
13 outfile_end2 = open(sys.argv[3], 'w')
14
15 i = 0
16
17 for line in file( infile ):
18 line = line.rstrip()
19
20 if not line:
21 continue
22
23 end1 = ''
24 end2 = ''
25
26 line_index = i % 4
27
28 if line_index == 0:
29 end1 = line + '/1'
30 end2 = line + '/2'
31
32 elif line_index == 1:
33 seq_len = len(line)/2
34 end1 = line[0:seq_len]
35 end2 = line[seq_len:]
36
37 elif line_index == 2:
38 end1 = line + '/1'
39 end2 = line + '/2'
40
41 else:
42 qual_len = len(line)/2
43 end1 = line[0:qual_len]
44 end2 = line[qual_len:]
45
46 outfile_end1.write('%s\n' %(end1))
47 outfile_end2.write('%s\n' %(end2))
48
49 i += 1
50
51 if i % 4 != 0 :
52 sys.stderr.write("WARNING: Number of lines in the input file was not divisible by 4.\nCheck consistency of the input fastq file.\n")
53 outfile_end1.close()
54 outfile_end2.close()