def filter_samples_from_distance_matrix(dm, samples_to_discard, negate=False):
 try:
  (sample_ids, dm_data) = dm
 except ValueError:
  (sample_ids, dm_data) = parse_distmat(dm)
 sample_lookup = {}.fromkeys([e.split()[0] for e in samples_to_discard])
 temp_dm_data = []
 new_dm_data = []
 new_sample_ids = []
 if negate:
  def keep_sample(s):
   return (s in sample_lookup)
 else:
  def keep_sample(s):
   return (s not in sample_lookup)
 for (row, sample_id) in zip(dm_data, sample_ids):
  if keep_sample(sample_id):
   temp_dm_data.append(row)
   new_sample_ids.append(sample_id)
 temp_dm_data = array(temp_dm_data).transpose()
 for (col, sample_id) in zip(temp_dm_data, sample_ids):
  if keep_sample(sample_id):
   new_dm_data.append(col)
 new_dm_data = array(new_dm_data).transpose()
 return format_distance_matrix(new_sample_ids, new_dm_data)

def filter_samples_from_distance_matrix ( dm , samples_to_discard , negate = False ) : try : ( sample_ids , dm_data ) = dm except ValueError : ( sample_ids , dm_data ) = parse_distmat ( dm ) sample_lookup = { } . fromkeys ( [ e . split ( ) [ 0 ] for e in samples_to_discard ] ) temp_dm_data = [ ] new_dm_data = [ ] new_sample_ids = [ ] if negate : def keep_sample ( s ) : return ( s in sample_lookup ) else : def keep_sample ( s ) : return ( s not in sample_lookup ) for ( row , sample_id ) in zip ( dm_data , sample_ids ) : if keep_sample ( sample_id ) : temp_dm_data . append ( row ) new_sample_ids . append ( sample_id ) temp_dm_data = array ( temp_dm_data ) . transpose ( ) for ( col , sample_id ) in zip ( temp_dm_data , sample_ids ) : if keep_sample ( sample_id ) : new_dm_data . append ( col ) new_dm_data = array ( new_dm_data ) . transpose ( ) return format_distance_matrix ( new_sample_ids , new_dm_data )
remove specified samples from distance matrix dm: tuple .