def make_envs_dict(abund_mtx, sample_names, taxon_names):
 (num_samples, num_seqs) = abund_mtx.shape
 if ((num_samples, num_seqs) != (len(sample_names), len(taxon_names))):
  raise ValueError(("Shape of matrix %s doesn't match # samples and # taxa (%s and %s)" % (abund_mtx.shape, num_samples, num_seqs)))
 envs_dict = {}
 sample_names = asarray(sample_names)
 for (i, taxon) in enumerate(abund_mtx.T):
  nonzeros = taxon.nonzero()
  envs_dict[taxon_names[i]] = dict(zip(sample_names[nonzeros], taxon[nonzeros]))
 return envs_dict

def make_envs_dict ( abund_mtx , sample_names , taxon_names ) : ( num_samples , num_seqs ) = abund_mtx . shape if ( ( num_samples , num_seqs ) != ( len ( sample_names ) , len ( taxon_names ) ) ) : raise ValueError ( ( "Shape of matrix %s doesn't match # samples and # taxa (%s and %s)" % ( abund_mtx . shape , num_samples , num_seqs ) ) ) envs_dict = { } sample_names = asarray ( sample_names ) for ( i , taxon ) in enumerate ( abund_mtx . T ) : nonzeros = taxon . nonzero ( ) envs_dict [ taxon_names [ i ] ] = dict ( zip ( sample_names [ nonzeros ] , taxon [ nonzeros ] ) ) return envs_dict
makes an envs dict suitable for unifrac from an abundance matrix abund_mtx is samples by seqs numpy 2d array sample_names is a list .