#NEWLINE# @ merge ( loadMetaphlanReadmaps , 'metaphlan.dir/taxonomic.counts' ) #NEWLINE# def countMetaphlanTaxonomicGroups( infiles , outfile ) : #NEWLINE# #INDENT# '\n    count the total number of species that\n    were found by metaphlan\n    ' #NEWLINE# outf = open ( outfile , 'w' ) #NEWLINE# outf . write ( 'track\ttaxon_level\tcount\n' ) #NEWLINE# taxons = [ '_order' , 'class' , 'family' , 'genus' , 'kingdom' , 'phylum' , 'species' ] #NEWLINE# dbh = connect ( ) #NEWLINE# cc = dbh . cursor ( ) #NEWLINE# for infile in infiles : #NEWLINE# #INDENT# table = P . toTable ( infile ) #NEWLINE# track = P . snip ( table , '_readmap' ) #NEWLINE# for taxon in taxons : #NEWLINE# #INDENT# count = cc . execute ( ( 'SELECT COUNT(DISTINCT %s) FROM %s' % ( taxon , table ) ) ) . fetchone ( ) [ 0 ] #NEWLINE# outf . write ( ( '\t' . join ( [ track , track , str ( count ) ] ) + '\n' ) ) #NEWLINE# #UNINDENT# #UNINDENT# outf . close ( )