root/galaxy-central/tools/filters/gff/extract_GFF_Features.py @ 2

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

import galaxy-central

行番号 
1#!/usr/bin/env python
2#Guruprasad Ananda
3"""
4Extract features from GFF file.
5
6usage: %prog input1 out_file1 column features
7"""
8
9import sys, os
10
11from galaxy import eggs
12import pkg_resources; pkg_resources.require( "bx-python" )
13from bx.cookbook import doc_optparse
14
15assert sys.version_info[:2] >= ( 2, 4 )
16
17def stop_err( msg ):
18    sys.stderr.write( msg )
19    sys.exit()
20
21def main():   
22    # Parsing Command Line here
23    options, args = doc_optparse.parse( __doc__ )
24   
25    try:
26        inp_file, out_file, column, features = args
27    except:
28        stop_err( "One or more arguments is missing or invalid.\nUsage: prog input output column features" )
29    try:
30        column = int( column )
31    except:
32        stop_err( "Column %s is an invalid column." % column )
33   
34    if features == None:
35        stop_err( "Column %d has no features to display, select another column." %( column + 1 ) )
36
37    fo=open( out_file, 'w' )
38    for i, line in enumerate( file( inp_file ) ):
39        line = line.rstrip( '\r\n' )
40        if line and line.startswith( '#' ):
41            # Keep valid comment lines in the output
42            fo.write( "%s\n" % line )
43        else:
44            try:
45                if line.split( '\t' )[column] in features.split( ',' ):
46                    fo.write( "%s\n" % line )
47            except:
48                pass
49    fo.close()
50           
51    print 'Column %d features: %s' %( column + 1, features )
52
53if __name__ == "__main__":
54    main()       
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。