#NEWLINE# @ merge ( loadMetaphlanRelativeAbundances , 'metaphlan.dir/taxonomic.abundances' ) #NEWLINE# def buildMetaphlanTaxonomicAbundances( infiles , outfile ) : #NEWLINE# #INDENT# '\n    build a file that combines taxonomic abundances \n    from each sample\n    ' #NEWLINE# dbh = connect ( ) #NEWLINE# cc = dbh . cursor ( ) #NEWLINE# outf = open ( outfile , 'w' ) #NEWLINE# outf . write ( 'track\ttaxon_level\ttaxon\tabundance\tidx\n' ) #NEWLINE# for infile in infiles : #NEWLINE# #INDENT# table = P . toTable ( infile ) #NEWLINE# track = P . snip ( table , '_relab' ) #NEWLINE# for data in cc . execute ( ( 'SELECT taxon_level, taxon, rel_abundance FROM %s' % table ) ) . fetchall ( ) : #NEWLINE# #INDENT# idx = track . split ( '_' ) [ 1 ] #NEWLINE# if ( data [ 1 ] . find ( 'unclassified' ) != ( - 1 ) ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# outf . write ( ( '\t' . join ( [ track , data [ 0 ] , data [ 1 ] , str ( data [ 2 ] ) , idx ] ) + '\n' ) ) #NEWLINE# #UNINDENT# #UNINDENT# outf . close ( )