#NEWLINE# def main( ) : #NEWLINE# #INDENT# usage = 'usage: %prog [options]' #NEWLINE# description = 'blah blah blah' #NEWLINE# optparser = OptionParser ( version = '%prog 0.1' , description = description , usage = usage , add_help_option = False ) #NEWLINE# optparser . add_option ( '-h' , '--help' , action = 'help' , help = 'Show this help message and exit.' ) #NEWLINE# optparser . add_option ( '-i' , '--ifile' , dest = 'ifile' , type = 'string' , help = 'input files, if you give a pattern for files, please use " to surround the pattern string' ) #NEWLINE# optparser . add_option ( '-w' , '--window' , dest = 'window' , type = 'int' , default = 1000 , help = 'window to extract a sample sequence, default:1000' ) #NEWLINE# optparser . add_option ( '-s' , '--sample' , dest = 'sample' , type = 'int' , default = 36 , help = 'size of a sample sequence,default=36' ) #NEWLINE# optparser . add_option ( '-f' , '--frag' , dest = 'frag' , type = 'int' , help = 'if pair-end calculation is needed, give the fragment size' ) #NEWLINE# optparser . add_option ( '-o' , '--ofile' , dest = 'ofile' , help = 'output file' ) #NEWLINE# ( options , args ) = optparser . parse_args ( ) #NEWLINE# if ( ( not options . ifile ) or ( not options . window ) or ( not options . sample ) or ( not options . ofile ) ) : #NEWLINE# #INDENT# optparser . print_help ( ) #NEWLINE# sys . exit ( 1 ) #NEWLINE# #UNINDENT# ohd = open ( options . ofile , 'w' ) #NEWLINE# files = glob ( options . ifile ) #NEWLINE# if ( not files ) : #NEWLINE# #INDENT# sys . stderr . write ( ( 'no file found: %s\n' % options . ifile ) ) #NEWLINE# sys . exit ( 1 ) #NEWLINE# #UNINDENT# m = 0 #NEWLINE# for f in files : #NEWLINE# #INDENT# sys . stdout . write ( ( '%s ... \n' % f ) ) #NEWLINE# sys . stdout . flush ( ) #NEWLINE# fahd = open ( f , 'r' ) #NEWLINE# record = SeqIO . parse ( fahd , 'fasta' ) #NEWLINE# for i in record : #NEWLINE# #INDENT# n = ( len ( i . seq ) / 1000 ) #NEWLINE# for l in range ( 0 , ( n - 1 ) ) : #NEWLINE# #INDENT# s = ( ( l * 1000 ) + randint ( 0 , 999 ) ) #NEWLINE# if options . frag : #NEWLINE# #INDENT# slice = i . seq [ s : ( s + options . frag ) ] . tostring ( ) . upper ( ) #NEWLINE# if ( slice . find ( 'N' ) == ( - 1 ) ) : #NEWLINE# #INDENT# m += 1 #NEWLINE# ohd . write ( ( '%s\t%d\n' % ( slice [ : options . sample ] , m ) ) ) #NEWLINE# m += 1 #NEWLINE# ohd . write ( ( '%s\t%d\n' % ( rc ( slice [ ( ( - 1 ) * options . sample ) : ] ) , m ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# slice = i . seq [ s : ( s + options . sample ) ] . tostring ( ) . upper ( ) #NEWLINE# if ( slice . find ( 'N' ) == ( - 1 ) ) : #NEWLINE# #INDENT# m += 1 #NEWLINE# ohd . write ( ( '%s\t%d\n' % ( slice , m ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# fahd . close ( ) #NEWLINE# #UNINDENT# ohd . close ( )