def sort_otu_table(otu_table, sorted_sample_ids):
 sorted_sample_ids_set = set(sorted_sample_ids)
 if (set(otu_table.ids()) - sorted_sample_ids_set):
  raise KeyError(('Sample IDs present in OTU table but not sorted sample id list: ' + ' '.join(list((set(otu_table.ids()) - set(sorted_sample_ids))))))
 if (len(sorted_sample_ids_set) != len(sorted_sample_ids)):
  raise ValueError('Duplicate sample IDs are present in sorted sample id list.')
 safe_sorted_sample_ids = []
 for k in sorted_sample_ids:
  if otu_table.exists(k):
   safe_sorted_sample_ids.append(k)
 sorted_table = otu_table.sort_order(safe_sorted_sample_ids)
 return sorted_table

def sort_otu_table ( otu_table , sorted_sample_ids ) : sorted_sample_ids_set = set ( sorted_sample_ids ) if ( set ( otu_table . ids ( ) ) - sorted_sample_ids_set ) : raise KeyError ( ( 'Sample IDs present in OTU table but not sorted sample id list: ' + ' ' . join ( list ( ( set ( otu_table . ids ( ) ) - set ( sorted_sample_ids ) ) ) ) ) ) if ( len ( sorted_sample_ids_set ) != len ( sorted_sample_ids ) ) : raise ValueError ( 'Duplicate sample IDs are present in sorted sample id list.' ) safe_sorted_sample_ids = [ ] for k in sorted_sample_ids : if otu_table . exists ( k ) : safe_sorted_sample_ids . append ( k ) sorted_table = otu_table . sort_order ( safe_sorted_sample_ids ) return sorted_table
sort an otu table by sorted sample ids .