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