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

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

import galaxy-central

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