def assemble_distance_matrix(dm_components):
 data = {}
 for c in dm_components:
  col_ids = []
  for line in c:
   fields = line.strip().split()
   if fields:
    if (not col_ids):
     col_ids = fields
    else:
     sid = fields[0]
     data[sid] = dict(zip(col_ids, fields[1:]))
 labels = data.keys()
 dm = []
 for l1 in labels:
  dm.append([float(data[l1][l2]) for l2 in labels])
 dm = format_distance_matrix(labels, dm)
 return dm

def assemble_distance_matrix ( dm_components ) : data = { } for c in dm_components : col_ids = [ ] for line in c : fields = line . strip ( ) . split ( ) if fields : if ( not col_ids ) : col_ids = fields else : sid = fields [ 0 ] data [ sid ] = dict ( zip ( col_ids , fields [ 1 : ] ) ) labels = data . keys ( ) dm = [ ] for l1 in labels : dm . append ( [ float ( data [ l1 ] [ l2 ] ) for l2 in labels ] ) dm = format_distance_matrix ( labels , dm ) return dm
assemble distance matrix components into a complete dm string .