annotate split_paired_reads.py @ 0:e7d1ffdbb9b6 draft default tip

Uploaded
author devteam
date Wed, 21 Aug 2013 13:20:57 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
e7d1ffdbb9b6 Uploaded
devteam
parents:
diff changeset
1 #!/usr/bin/env python
e7d1ffdbb9b6 Uploaded
devteam
parents:
diff changeset
2
e7d1ffdbb9b6 Uploaded
devteam
parents:
diff changeset
3 """
e7d1ffdbb9b6 Uploaded
devteam
parents:
diff changeset
4 Split fixed length paired end reads
e7d1ffdbb9b6 Uploaded
devteam
parents:
diff changeset
5 """
e7d1ffdbb9b6 Uploaded
devteam
parents:
diff changeset
6
e7d1ffdbb9b6 Uploaded
devteam
parents:
diff changeset
7 import os, sys
e7d1ffdbb9b6 Uploaded
devteam
parents:
diff changeset
8
e7d1ffdbb9b6 Uploaded
devteam
parents:
diff changeset
9 if __name__ == '__main__':
e7d1ffdbb9b6 Uploaded
devteam
parents:
diff changeset
10
e7d1ffdbb9b6 Uploaded
devteam
parents:
diff changeset
11 infile = sys.argv[1]
e7d1ffdbb9b6 Uploaded
devteam
parents:
diff changeset
12 outfile_end1 = open(sys.argv[2], 'w')
e7d1ffdbb9b6 Uploaded
devteam
parents:
diff changeset
13 outfile_end2 = open(sys.argv[3], 'w')
e7d1ffdbb9b6 Uploaded
devteam
parents:
diff changeset
14
e7d1ffdbb9b6 Uploaded
devteam
parents:
diff changeset
15 i = 0
e7d1ffdbb9b6 Uploaded
devteam
parents:
diff changeset
16
e7d1ffdbb9b6 Uploaded
devteam
parents:
diff changeset
17 for line in file( infile ):
e7d1ffdbb9b6 Uploaded
devteam
parents:
diff changeset
18 line = line.rstrip()
e7d1ffdbb9b6 Uploaded
devteam
parents:
diff changeset
19
e7d1ffdbb9b6 Uploaded
devteam
parents:
diff changeset
20 if not line:
e7d1ffdbb9b6 Uploaded
devteam
parents:
diff changeset
21 continue
e7d1ffdbb9b6 Uploaded
devteam
parents:
diff changeset
22
e7d1ffdbb9b6 Uploaded
devteam
parents:
diff changeset
23 end1 = ''
e7d1ffdbb9b6 Uploaded
devteam
parents:
diff changeset
24 end2 = ''
e7d1ffdbb9b6 Uploaded
devteam
parents:
diff changeset
25
e7d1ffdbb9b6 Uploaded
devteam
parents:
diff changeset
26 line_index = i % 4
e7d1ffdbb9b6 Uploaded
devteam
parents:
diff changeset
27
e7d1ffdbb9b6 Uploaded
devteam
parents:
diff changeset
28 if line_index == 0:
e7d1ffdbb9b6 Uploaded
devteam
parents:
diff changeset
29 end1 = line + '/1'
e7d1ffdbb9b6 Uploaded
devteam
parents:
diff changeset
30 end2 = line + '/2'
e7d1ffdbb9b6 Uploaded
devteam
parents:
diff changeset
31
e7d1ffdbb9b6 Uploaded
devteam
parents:
diff changeset
32 elif line_index == 1:
e7d1ffdbb9b6 Uploaded
devteam
parents:
diff changeset
33 seq_len = len(line)/2
e7d1ffdbb9b6 Uploaded
devteam
parents:
diff changeset
34 end1 = line[0:seq_len]
e7d1ffdbb9b6 Uploaded
devteam
parents:
diff changeset
35 end2 = line[seq_len:]
e7d1ffdbb9b6 Uploaded
devteam
parents:
diff changeset
36
e7d1ffdbb9b6 Uploaded
devteam
parents:
diff changeset
37 elif line_index == 2:
e7d1ffdbb9b6 Uploaded
devteam
parents:
diff changeset
38 end1 = line + '/1'
e7d1ffdbb9b6 Uploaded
devteam
parents:
diff changeset
39 end2 = line + '/2'
e7d1ffdbb9b6 Uploaded
devteam
parents:
diff changeset
40
e7d1ffdbb9b6 Uploaded
devteam
parents:
diff changeset
41 else:
e7d1ffdbb9b6 Uploaded
devteam
parents:
diff changeset
42 qual_len = len(line)/2
e7d1ffdbb9b6 Uploaded
devteam
parents:
diff changeset
43 end1 = line[0:qual_len]
e7d1ffdbb9b6 Uploaded
devteam
parents:
diff changeset
44 end2 = line[qual_len:]
e7d1ffdbb9b6 Uploaded
devteam
parents:
diff changeset
45
e7d1ffdbb9b6 Uploaded
devteam
parents:
diff changeset
46 outfile_end1.write('%s\n' %(end1))
e7d1ffdbb9b6 Uploaded
devteam
parents:
diff changeset
47 outfile_end2.write('%s\n' %(end2))
e7d1ffdbb9b6 Uploaded
devteam
parents:
diff changeset
48
e7d1ffdbb9b6 Uploaded
devteam
parents:
diff changeset
49 i += 1
e7d1ffdbb9b6 Uploaded
devteam
parents:
diff changeset
50
e7d1ffdbb9b6 Uploaded
devteam
parents:
diff changeset
51 if i % 4 != 0 :
e7d1ffdbb9b6 Uploaded
devteam
parents:
diff changeset
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")
e7d1ffdbb9b6 Uploaded
devteam
parents:
diff changeset
53 outfile_end1.close()
e7d1ffdbb9b6 Uploaded
devteam
parents:
diff changeset
54 outfile_end2.close()