root/galaxy-central/tools/fastq/fastq_filter.py

リビジョン 2, 1.2 KB (コミッタ: hatakeyama, 14 年 前)

import galaxy-central

行番号 
1#Dan Blankenberg
2import sys, os, shutil
3from galaxy_utils.sequence.fastq import fastqReader, fastqWriter
4
5def main():
6    #Read command line arguments
7    input_filename = sys.argv[1]
8    script_filename = sys.argv[2]
9    output_filename = sys.argv[3]
10    additional_files_path = sys.argv[4]
11    input_type = sys.argv[5] or 'sanger'
12   
13    #Save script file for debuging/verification info later
14    os.mkdir( additional_files_path )
15    shutil.copy( script_filename, os.path.join( additional_files_path, 'debug.txt' ) )
16   
17    out = fastqWriter( open( output_filename, 'wb' ), format = input_type )
18   
19    i = None
20    reads_kept = 0
21    for i, fastq_read in enumerate( fastqReader( open( input_filename ), format = input_type ) ):
22        local = {'fastq_read':fastq_read, 'ret_val':False}
23        execfile( script_filename, {}, local )
24        if local['ret_val']:
25            out.write( fastq_read )
26            reads_kept += 1
27    out.close()
28    if i is None:
29        print "Your file contains no valid fastq reads."
30    else:
31        print 'Kept %s of %s reads (%.2f%%).' % ( reads_kept, i + 1, float( reads_kept ) / float( i + 1 ) * 100.0 )
32
33if __name__ == "__main__":
34    main()
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。