def sync_biom_and_mf(pmf, bt):
 mf_samples = set(pmf)
 bt_samples = set(bt.ids())
 if (mf_samples == bt_samples):
  return (pmf, bt, set())
 else:
  shared_samples = mf_samples.intersection(bt_samples)
  assert (len(shared_samples) != 0), 'sync_biom_and_mf: No shared samples, no point in continuing.'
  nonshared_samples = (mf_samples.union(bt_samples) - shared_samples)
  npmf = {k: v for (k, v) in pmf.items() if (k in shared_samples)}
  def _f(sv, sid, smd):
   return (sid in shared_samples)
  nbt = bt.filter(_f, axis='sample')
 return (npmf, nbt, nonshared_samples)

def sync_biom_and_mf ( pmf , bt ) : mf_samples = set ( pmf ) bt_samples = set ( bt . ids ( ) ) if ( mf_samples == bt_samples ) : return ( pmf , bt , set ( ) ) else : shared_samples = mf_samples . intersection ( bt_samples ) assert ( len ( shared_samples ) != 0 ) , 'sync_biom_and_mf: No shared samples, no point in continuing.' nonshared_samples = ( mf_samples . union ( bt_samples ) - shared_samples ) npmf = { k : v for ( k , v ) in pmf . items ( ) if ( k in shared_samples ) } def _f ( sv , sid , smd ) : return ( sid in shared_samples ) nbt = bt . filter ( _f , axis = 'sample' ) return ( npmf , nbt , nonshared_samples )
reduce mapping file dict and biom table to shared samples .