PageRenderTime 11ms CodeModel.GetById 7ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/tools/fastq/tabular_to_fastq.py

https://bitbucket.org/cistrome/cistrome-harvard/
Python | 29 lines | 24 code | 4 blank | 1 comment | 5 complexity | 430e3005b333784fa0df5345883bac75 MD5 | raw file
 1#Dan Blankenberg
 2import sys
 3
 4def main():
 5    input_filename = sys.argv[1]
 6    output_filename = sys.argv[2]
 7    identifier_col = int( sys.argv[3] ) - 1
 8    sequence_col = int( sys.argv[4] ) - 1
 9    quality_col = int( sys.argv[5] ) - 1
10    
11    max_col = max( identifier_col, sequence_col, quality_col )
12    num_reads = None
13    fastq_read = None
14    skipped_lines = 0
15    out = open( output_filename, 'wb' )
16    for num_reads, line in enumerate( open( input_filename ) ):
17        fields = line.rstrip( '\n\r' ).split( '\t' )
18        if len( fields ) > max_col:
19            out.write( "@%s\n%s\n+\n%s\n" % ( fields[identifier_col], fields[sequence_col], fields[quality_col] ) )
20        else:
21            skipped_lines += 1
22    
23    out.close()
24    if num_reads is None:
25        print "Input was empty."
26    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 )
28    
29if __name__ == "__main__": main()