comparison tabular_to_fastq.py @ 3:643018aa1435 draft

planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/galaxy_sequence_utils/tabular_to_fastq commit f2582539542b33240234e8ea6093e25d0aee9b6a
author devteam
date Sat, 30 Sep 2017 13:54:43 -0400
parents 9ae652b76979
children e8ca9af08774
comparison
equal deleted inserted replaced
2:6e9c13e70d45 3:643018aa1435
1 #Dan Blankenberg 1 # Dan Blankenberg
2 from __future__ import print_function
3
2 import sys 4 import sys
5
3 6
4 def main(): 7 def main():
5 input_filename = sys.argv[1] 8 input_filename = sys.argv[1]
6 output_filename = sys.argv[2] 9 output_filename = sys.argv[2]
7 identifier_col = int( sys.argv[3] ) - 1 10 identifier_col = int(sys.argv[3]) - 1
8 sequence_col = int( sys.argv[4] ) - 1 11 sequence_col = int(sys.argv[4]) - 1
9 quality_col = int( sys.argv[5] ) - 1 12 quality_col = int(sys.argv[5]) - 1
10 13
11 max_col = max( identifier_col, sequence_col, quality_col ) 14 max_col = max(identifier_col, sequence_col, quality_col)
12 num_reads = None 15 num_reads = None
13 fastq_read = None
14 skipped_lines = 0 16 skipped_lines = 0
15 out = open( output_filename, 'wb' ) 17 out = open(output_filename, 'w')
16 for num_reads, line in enumerate( open( input_filename ) ): 18 for num_reads, line in enumerate(open(input_filename)):
17 fields = line.rstrip( '\n\r' ).split( '\t' ) 19 fields = line.rstrip('\n\r').split('\t')
18 if len( fields ) > max_col: 20 if len(fields) > max_col:
19 out.write( "@%s\n%s\n+\n%s\n" % ( fields[identifier_col], fields[sequence_col], fields[quality_col] ) ) 21 out.write("@%s\n%s\n+\n%s\n" % (fields[identifier_col], fields[sequence_col], fields[quality_col]))
20 else: 22 else:
21 skipped_lines += 1 23 skipped_lines += 1
22 24
23 out.close() 25 out.close()
24 if num_reads is None: 26 if num_reads is None:
25 print "Input was empty." 27 print("Input was empty.")
26 else: 28 else:
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 ) 29 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))
28 30
29 if __name__ == "__main__": main() 31
32 if __name__ == "__main__":
33 main()