def _make_compatible_taxa_summaries(ts1, ts2, sample_id_map=None):
 if sample_id_map:
  for samp_id in (ts1[0] + ts2[0]):
   if (samp_id not in sample_id_map):
    raise ValueError(("The original sample ID '%s' does not have a mapping in the sample ID map. All sample IDs must have a mapping." % samp_id))
 (new_samp_ids1, new_samp_ids2, new_data1, new_data2) = ([], [], [], [])
 for (samp_idx, samp_id) in enumerate(ts1[0]):
  matching_samp_id = None
  if sample_id_map:
   new_samp_id = sample_id_map[samp_id]
   for orig_samp_id in sample_id_map:
    if ((orig_samp_id != samp_id) and (sample_id_map[orig_samp_id] == new_samp_id)):
     matching_samp_id = orig_samp_id
  elif (samp_id in ts2[0]):
   matching_samp_id = samp_id
  if matching_samp_id:
   new_samp_ids1.append(samp_id)
   new_samp_ids2.append(matching_samp_id)
   new_data1.append(ts1[2].T[samp_idx])
   new_data2.append(ts2[2].T[ts2[0].index(matching_samp_id)])
 if (len(new_samp_ids1) == 0):
  raise ValueError('No sample IDs matched between the taxa summaries. The taxa summaries are incompatible.')
 return ((new_samp_ids1, ts1[1], array(new_data1).T), (new_samp_ids2, ts2[1], array(new_data2).T))

def _make_compatible_taxa_summaries ( ts1 , ts2 , sample_id_map = None ) : if sample_id_map : for samp_id in ( ts1 [ 0 ] + ts2 [ 0 ] ) : if ( samp_id not in sample_id_map ) : raise ValueError ( ( "The original sample ID '%s' does not have a mapping in the sample ID map. All sample IDs must have a mapping." % samp_id ) ) ( new_samp_ids1 , new_samp_ids2 , new_data1 , new_data2 ) = ( [ ] , [ ] , [ ] , [ ] ) for ( samp_idx , samp_id ) in enumerate ( ts1 [ 0 ] ) : matching_samp_id = None if sample_id_map : new_samp_id = sample_id_map [ samp_id ] for orig_samp_id in sample_id_map : if ( ( orig_samp_id != samp_id ) and ( sample_id_map [ orig_samp_id ] == new_samp_id ) ) : matching_samp_id = orig_samp_id elif ( samp_id in ts2 [ 0 ] ) : matching_samp_id = samp_id if matching_samp_id : new_samp_ids1 . append ( samp_id ) new_samp_ids2 . append ( matching_samp_id ) new_data1 . append ( ts1 [ 2 ] . T [ samp_idx ] ) new_data2 . append ( ts2 [ 2 ] . T [ ts2 [ 0 ] . index ( matching_samp_id ) ] ) if ( len ( new_samp_ids1 ) == 0 ) : raise ValueError ( 'No sample IDs matched between the taxa summaries. The taxa summaries are incompatible.' ) return ( ( new_samp_ids1 , ts1 [ 1 ] , array ( new_data1 ) . T ) , ( new_samp_ids2 , ts2 [ 1 ] , array ( new_data2 ) . T ) )
returns two taxa summaries that are ready for direct comparison .