annotate tabular_to_fastq.py @ 1:7bde4f066435 draft

planemo upload commit 33927a87ba2eee9bf0ecdd376a66241b17b3d734
author devteam
date Tue, 13 Oct 2015 12:45:21 -0400
parents 9ae652b76979
children 643018aa1435
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
9ae652b76979 Imported from capsule None
devteam
parents:
diff changeset
1 #Dan Blankenberg
9ae652b76979 Imported from capsule None
devteam
parents:
diff changeset
2 import sys
9ae652b76979 Imported from capsule None
devteam
parents:
diff changeset
3
9ae652b76979 Imported from capsule None
devteam
parents:
diff changeset
4 def main():
9ae652b76979 Imported from capsule None
devteam
parents:
diff changeset
5 input_filename = sys.argv[1]
9ae652b76979 Imported from capsule None
devteam
parents:
diff changeset
6 output_filename = sys.argv[2]
9ae652b76979 Imported from capsule None
devteam
parents:
diff changeset
7 identifier_col = int( sys.argv[3] ) - 1
9ae652b76979 Imported from capsule None
devteam
parents:
diff changeset
8 sequence_col = int( sys.argv[4] ) - 1
9ae652b76979 Imported from capsule None
devteam
parents:
diff changeset
9 quality_col = int( sys.argv[5] ) - 1
9ae652b76979 Imported from capsule None
devteam
parents:
diff changeset
10
9ae652b76979 Imported from capsule None
devteam
parents:
diff changeset
11 max_col = max( identifier_col, sequence_col, quality_col )
9ae652b76979 Imported from capsule None
devteam
parents:
diff changeset
12 num_reads = None
9ae652b76979 Imported from capsule None
devteam
parents:
diff changeset
13 fastq_read = None
9ae652b76979 Imported from capsule None
devteam
parents:
diff changeset
14 skipped_lines = 0
9ae652b76979 Imported from capsule None
devteam
parents:
diff changeset
15 out = open( output_filename, 'wb' )
9ae652b76979 Imported from capsule None
devteam
parents:
diff changeset
16 for num_reads, line in enumerate( open( input_filename ) ):
9ae652b76979 Imported from capsule None
devteam
parents:
diff changeset
17 fields = line.rstrip( '\n\r' ).split( '\t' )
9ae652b76979 Imported from capsule None
devteam
parents:
diff changeset
18 if len( fields ) > max_col:
9ae652b76979 Imported from capsule None
devteam
parents:
diff changeset
19 out.write( "@%s\n%s\n+\n%s\n" % ( fields[identifier_col], fields[sequence_col], fields[quality_col] ) )
9ae652b76979 Imported from capsule None
devteam
parents:
diff changeset
20 else:
9ae652b76979 Imported from capsule None
devteam
parents:
diff changeset
21 skipped_lines += 1
9ae652b76979 Imported from capsule None
devteam
parents:
diff changeset
22
9ae652b76979 Imported from capsule None
devteam
parents:
diff changeset
23 out.close()
9ae652b76979 Imported from capsule None
devteam
parents:
diff changeset
24 if num_reads is None:
9ae652b76979 Imported from capsule None
devteam
parents:
diff changeset
25 print "Input was empty."
9ae652b76979 Imported from capsule None
devteam
parents:
diff changeset
26 else:
9ae652b76979 Imported from capsule None
devteam
parents:
diff changeset
27 print "%i tabular lines were written as FASTQ reads. Be sure to use the FASTQ Groomer tool on this output before further analysis." % ( num_reads + 1 - skipped_lines )
9ae652b76979 Imported from capsule None
devteam
parents:
diff changeset
28
9ae652b76979 Imported from capsule None
devteam
parents:
diff changeset
29 if __name__ == "__main__": main()