def get_adjacent_distances(dist_matrix_header, dist_matrix, sample_ids, strict=False):
 filtered_idx = []
 filtered_sids = []
 for sid in sample_ids:
  try:
   idx = dist_matrix_header.index(sid)
  except ValueError:
   if strict:
    raise ValueError(('Sample ID (%s) is not present in distance matrix' % sid))
   else:
    pass
  else:
   filtered_idx.append(idx)
   filtered_sids.append(sid)
 if (len(filtered_idx) < 2):
  raise ValueError(('At least two of your sample_ids must be present in the distance matrix. %d are present.' % len(filtered_idx)))
 distance_results = []
 header_results = []
 for i in range((len(filtered_idx) - 1)):
  distance_results.append(dist_matrix[filtered_idx[i]][filtered_idx[(i + 1)]])
  header_results.append((filtered_sids[i], filtered_sids[(i + 1)]))
 return (distance_results, header_results)

def get_adjacent_distances ( dist_matrix_header , dist_matrix , sample_ids , strict = False ) : filtered_idx = [ ] filtered_sids = [ ] for sid in sample_ids : try : idx = dist_matrix_header . index ( sid ) except ValueError : if strict : raise ValueError ( ( 'Sample ID (%s) is not present in distance matrix' % sid ) ) else : pass else : filtered_idx . append ( idx ) filtered_sids . append ( sid ) if ( len ( filtered_idx ) < 2 ) : raise ValueError ( ( 'At least two of your sample_ids must be present in the distance matrix. %d are present.' % len ( filtered_idx ) ) ) distance_results = [ ] header_results = [ ] for i in range ( ( len ( filtered_idx ) - 1 ) ) : distance_results . append ( dist_matrix [ filtered_idx [ i ] ] [ filtered_idx [ ( i + 1 ) ] ] ) header_results . append ( ( filtered_sids [ i ] , filtered_sids [ ( i + 1 ) ] ) ) return ( distance_results , header_results )
return the distances between the adjacent sample_ids as a list dist_matrix_header: distance matrix headers .