def get_order_from_categories(otu_table, category_labels):
 category_labels = np.array(category_labels)
 sample_order = []
 for label in np.unique(category_labels):
  label_ix = (category_labels == label)
  selected = [s for (i, s) in zip(label_ix, otu_table.ids()) if i]
  sub_otu_table = filter_samples_from_otu_table(otu_table, selected, (- np.inf), np.inf)
  data = np.asarray(list(sub_otu_table.iter_data(axis='observation')))
  label_ix_ix = get_clusters(data, axis='column')
  sample_order += list(np.nonzero(label_ix)[0][np.array(label_ix_ix)])
 return np.array(sample_order)

def get_order_from_categories ( otu_table , category_labels ) : category_labels = np . array ( category_labels ) sample_order = [ ] for label in np . unique ( category_labels ) : label_ix = ( category_labels == label ) selected = [ s for ( i , s ) in zip ( label_ix , otu_table . ids ( ) ) if i ] sub_otu_table = filter_samples_from_otu_table ( otu_table , selected , ( - np . inf ) , np . inf ) data = np . asarray ( list ( sub_otu_table . iter_data ( axis = 'observation' ) ) ) label_ix_ix = get_clusters ( data , axis = 'column' ) sample_order += list ( np . nonzero ( label_ix ) [ 0 ] [ np . array ( label_ix_ix ) ] ) return np . array ( sample_order )
groups samples by category values; clusters within each group .