def collapse_samples(table, mapping_f, collapse_fields, collapse_mode):
 collapsed_metadata = _collapse_metadata(mapping_f, collapse_fields)
 (new_index_to_group, old_index_to_new_index) = _group_by_sample_metadata(collapsed_metadata)
 partition_f = partial(_sample_id_from_group_id, sid_to_group_id=old_index_to_new_index)
 collapse_fns = get_collapse_fns()
 try:
  collapse_f = collapse_fns[collapse_mode]
 except KeyError:
  raise KeyError(('Unknown collapse function %s. Valid choices are: %s.' % (collapse_mode, ', '.join(collapse_fns.keys()))))
 output_table = table.collapse(partition_f, collapse_f=collapse_f, norm=False, axis='sample')
 return (collapsed_metadata, output_table)

def collapse_samples ( table , mapping_f , collapse_fields , collapse_mode ) : collapsed_metadata = _collapse_metadata ( mapping_f , collapse_fields ) ( new_index_to_group , old_index_to_new_index ) = _group_by_sample_metadata ( collapsed_metadata ) partition_f = partial ( _sample_id_from_group_id , sid_to_group_id = old_index_to_new_index ) collapse_fns = get_collapse_fns ( ) try : collapse_f = collapse_fns [ collapse_mode ] except KeyError : raise KeyError ( ( 'Unknown collapse function %s. Valid choices are: %s.' % ( collapse_mode , ', ' . join ( collapse_fns . keys ( ) ) ) ) ) output_table = table . collapse ( partition_f , collapse_f = collapse_f , norm = False , axis = 'sample' ) return ( collapsed_metadata , output_table )
collapse samples in a biom table and sample metadata parameters table : biom .