#NEWLINE# def ids( args ) : #NEWLINE# #INDENT# '\n    %prog ids cdhit.clstr\n\n    Get the representative ids from clstr file.\n    ' #NEWLINE# p = OptionParser ( ids . __doc__ ) #NEWLINE# p . add_option ( '--prefix' , type = 'int' , help = 'Find rep id for prefix of len [default: %default]' ) #NEWLINE# ( opts , args ) = p . parse_args ( args ) #NEWLINE# if ( len ( args ) != 1 ) : #NEWLINE# #INDENT# sys . exit ( ( not p . print_help ( ) ) ) #NEWLINE# #UNINDENT# ( clstrfile , ) = args #NEWLINE# cf = ClstrFile ( clstrfile ) #NEWLINE# prefix = opts . prefix #NEWLINE# if prefix : #NEWLINE# #INDENT# reads = list ( cf . iter_reps_prefix ( prefix = prefix ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# reads = list ( cf . iter_reps ( ) ) #NEWLINE# #UNINDENT# nreads = len ( reads ) #NEWLINE# idsfile = clstrfile . replace ( '.clstr' , '.ids' ) #NEWLINE# fw = open ( idsfile , 'w' ) #NEWLINE# for ( i , name ) in reads : #NEWLINE# #INDENT# ( ( print >> fw ) , '\t' . join ( ( str ( x ) for x in ( i , name ) ) ) ) #NEWLINE# #UNINDENT# logging . debug ( 'A total of {0} unique reads written to `{1}`.' . format ( nreads , idsfile ) ) #NEWLINE# fw . close ( ) #NEWLINE# return idsfile