def sort_otu_table_by_mapping_field(otu_table_data, mapping_file_data, sort_field, sort_f=natsort):
 (mapping_data, header_data, comments) = mapping_file_data
 mapping_field_index = header_data.index(sort_field)
 sorted_sample_ids = [(e[mapping_field_index], e[0]) for e in mapping_data]
 sorted_sample_ids = sort_f(sorted_sample_ids)
 sorted_sample_ids = [e[1] for e in sorted_sample_ids]
 return sort_otu_table(otu_table_data, sorted_sample_ids)

def sort_otu_table_by_mapping_field ( otu_table_data , mapping_file_data , sort_field , sort_f = natsort ) : ( mapping_data , header_data , comments ) = mapping_file_data mapping_field_index = header_data . index ( sort_field ) sorted_sample_ids = [ ( e [ mapping_field_index ] , e [ 0 ] ) for e in mapping_data ] sorted_sample_ids = sort_f ( sorted_sample_ids ) sorted_sample_ids = [ e [ 1 ] for e in sorted_sample_ids ] return sort_otu_table ( otu_table_data , sorted_sample_ids )
sort otu table based on the value of sort_field for each sample .