motifs_tfbs = MotifTools.load(file_tfbs) 

match_dict = {}
for unknown in motifs_unknown:
  tf_list = []
  for tfbs in motifs_tfbs:
    #print 
    #print "Comparing motifs:"
    #print "    %s  vs  %s" % (unknown.source, tfbs.source)
    #print "    Unknown motif ( %s ) vs TFBS ( %s ) " % (unknown, tfbs)
    #print
    joined_motifs = []
    joined_motifs.append(unknown)
    joined_motifs.append(tfbs)
    print joined_motifs
    Dmat = MotifCompare.computeDmat(joined_motifs)
    cluster = Kmedoids.bestaveKMedoids_cluster(Dmat,kmax=2,min_dist=0.2)
    for i in cluster[1].keys():
      cluster_list = cluster[1][i]
      if len(cluster_list) > 1:
        dist = Dmat[0][1]
        tf_list.append( (dist, tfbs.source, tfbs.oneletter) )
        #print 
        #print "*** Motif match found! ***" 
        #tfbs.giflogo("%s" % tfbs.oneletter)
        #for i in cluster_list:
          #print joined_motifs[i]
  novel_id = unknown.source
  tf_list.sort()
  match_dict[novel_id] = {'query_motif': unknown.oneletter,
                          'subject': tf_list }