def write_rarefied_otu_table(**kwargs): output_table_io = kwargs.pop('output_table_io') table_collection = kwargs.pop('table_collection') number_to_choose = kwargs.pop('number_to_choose', None) if len(kwargs) > 0: raise Exception("Unexpected arguments detected: %s" % kwargs) if number_to_choose is None: counts = {} for otu in table_collection: key = "%s_singlem_RAND8_%s" % (otu.sample_name, otu.marker) try: counts[key] += otu.count except KeyError: counts[key] = otu.count number_to_choose = min(counts.values()) logging.info( "Minimum number of sequences detected is %i, rarefying all sample/gene combinations to this level" % number_to_choose) logging.info( "Rarefying OTU table to max %i sequences per sample/gene combination and writing to %s" % (number_to_choose, output_table_io.name)) OtuTable.write_otus_to( Rarefier().rarefy(table_collection, number_to_choose), output_table_io)
def write_otu_table(**kwargs): output_table_io = kwargs.pop('output_table_io') table_collection = kwargs.pop('table_collection') output_extras = kwargs.pop('output_extras') if len(kwargs) > 0: raise Exception("Unexpected arguments detected: %s" % kwargs) if hasattr(output_table_io, 'name'): logging.info("Writing %s" % output_table_io.name) else: logging.info("Writing an OTU table") if output_extras: OtuTable.write_otus_to(table_collection, output_table_io, fields_to_print=table_collection.example_field_names()) else: OtuTable.write_otus_to(table_collection, output_table_io)
def write_rarefied_otu_table(**kwargs): output_table_io = kwargs.pop('output_table_io') table_collection = kwargs.pop('table_collection') number_to_choose = kwargs.pop('number_to_choose', None) if len(kwargs) > 0: raise Exception("Unexpected arguments detected: %s" % kwargs) if number_to_choose is None: counts = {} for otu in table_collection: key = "%s_singlem_RAND8_%s" % (otu.sample_name, otu.marker) try: counts[key] += otu.count except KeyError: counts[key] = otu.count number_to_choose = min(counts.values()) logging.info("Minimum number of sequences detected is %i, rarefying all sample/gene combinations to this level" % number_to_choose) logging.info("Rarefying OTU table to max %i sequences per sample/gene combination and writing to %s" % (number_to_choose, output_table_io.name)) OtuTable.write_otus_to(Rarefier().rarefy(table_collection, number_to_choose), output_table_io)