def collapse(table: biom.Table, mapping: str, normalize: bool = False) -> biom.Table: """Collapse a feature table based on many-to-many mapping. """ with open(mapping, 'r') as fh: mapping = read_map_many(fh) table = collapse_biom(table, mapping, normalize) table.generated_by = f'{__name__}-{__version__}' return table
def coverage(table: biom.Table, mapping: str, threshold: int = None, count: bool = False) -> biom.Table: """Calculate a feature table's coverage over feature groups. """ with open(mapping, 'r') as fh: mapping = dict(read_map_all(fh)) table = calc_coverage(table, mapping, threshold, count) table = table_to_biom(*table) table.generated_by = f'{__name__}-{__version__}' return table
def filter_table(table: biom.Table, min_count: int = None, min_percent: float = None) -> biom.Table: """Filter a feature table by per-sample abundance of features. """ # validate parameters if not any((min_count, min_percent)): raise ValueError('Please specify either minimum count or minimum ' 'percentage threshold.') if all((min_count, min_percent)): raise ValueError('Only one of minimum count or minimum percentage ' 'thresholds can be specified.') if min_percent and min_percent >= 100: raise ValueError('Minimum percentage threshold must be below 100.') # determine threshold th = min_count or min_percent / 100 # filter feature table table = filter_biom(table, th) table.generated_by = f'{__name__}-{__version__}' return table