def test(): init() util._mkdir("../svg") html_file = open("../svg/templates.html", "w") for template in get_all_templates(): template_svg = chemconvert.hash2svg(template, svg_size, svg_size, white, grey) html_file.write("<p>") template_svg.embed_in_html(html_file, "../svg/", template) html_file.write(template + "</p>") html_file.flush() html_file.close()
def main(): init() subdir = "motifs" motif_fullpath = html_path + "/motifs" util._mkdir(motif_fullpath) main_html_file = open(html_path + "/motifs.html", "w") anti_motif_list = [] for size in motif_sizes: motifs = verify_file(size) motifs_t = motifs_templates(motifs) motif_hist = normalize_motifs(motifs) motif_hist_t = normalize_motifs(motifs_t) print "Generating all graphs of size %d ..." % size, all_graphs = generate_all_graphs(motif_hist, size) print "[DONE]" results = {} for h in all_graphs: G = chemconvert.hash2graph(h) template = G.template() count = int(motifs.get(h, 0)) likelihoods = [0, 0] for i in range(2, size+1): likelihoods.append(get_likelihood(G, motif_hist, i)) delta_l = likelihoods[-2] - likelihoods[-1] if (not results.has_key(template)): results[template] = [] results[template].append((delta_l, likelihoods, count, h)) main_html_file.write("<p>") size_html_file = util.embed_link(main_html_file, html_path, subdir + "/motifs%s" % size, "Motifs of size %s" % size) main_html_file.write("</p>") for (template, graph_list) in results.iteritems(): size_html_file.write("<p>") template_svg = chemconvert.hash2svg(template, 200, 200, node_color=black, bond_color=grey) template_svg.embed_in_html(size_html_file, motif_fullpath, template) count_t = len(graph_list) if (count_t > 0): template_html_file = util.embed_link(size_html_file, motif_fullpath, template, "View all %d instances" % count_t) for (delta_l, likelihoods, count, h) in sorted(graph_list): if (likelihoods[-1] <= log_zero and likelihoods[-2] <= log_zero): continue elif (likelihoods[-1] <= log_zero): bond_color = red anti_motif_list.append(h) else: #bond_color = (0, 255 * math.exp(-delta_l), 255 * (1 - math.exp(-delta_l))) bond_color = green motif_svg = chemconvert.hash2svg(h, 150, 150, black, bond_color) motif_svg.set_attribute("height", 200) if (True): # add #motif_svg.add(svg.Text((35, 25), h, 12, green)) l_string = ",".join(["%.1f" % l for l in likelihoods[2:]]) motif_svg.add(svg.Text((10, 160), "ΔL = %.1f" % delta_l, font_size=12)) motif_svg.add(svg.Text((10, 175), l_string, font_size=12)) if (count > 0): #motif_svg.add(svg.Text((35, 75), "diff = %.1f" % (l1-l0), 12, black)) motif_svg.add(svg.Text((10, 190), "count = %d" % count, font_size=12)) motif_svg.embed_in_html(template_html_file, motif_fullpath, h) else: template_html_file.write("<p>") motif_svg.embed_in_html(template_html_file, motif_fullpath, h) template_html_file.write("<a href=\"" + h + ".svg\">" + h + "</a>") template_html_file.write(", count = %d" % count) for i in range(2, size+1): template_html_file.write(", L(%d) = %.1f" % (i, likelihoods[i])) template_html_file.write("</p>") template_html_file.close() else: size_html_file.write("No instances") size_html_file.write("</p>") size_html_file.close() main_html_file.close() util.write_text_file(anti_motif_list, "../results/stat/anti_motifs.txt") return
def main(): init() subdir = "motifs" motif_fullpath = html_path + "/motifs" util._mkdir(motif_fullpath) main_html_file = open(html_path + "/motifs.html", "w") anti_motif_list = [] for size in motif_sizes: motifs = verify_file(size) motifs_t = motifs_templates(motifs) motif_hist = normalize_motifs(motifs) motif_hist_t = normalize_motifs(motifs_t) print "Generating all graphs of size %d ..." % size, all_graphs = generate_all_graphs(motif_hist, size) print "[DONE]" results = {} for h in all_graphs: G = chemconvert.hash2graph(h) template = G.template() count = int(motifs.get(h, 0)) likelihoods = [0, 0] for i in range(2, size + 1): likelihoods.append(get_likelihood(G, motif_hist, i)) delta_l = likelihoods[-2] - likelihoods[-1] if (not results.has_key(template)): results[template] = [] results[template].append((delta_l, likelihoods, count, h)) main_html_file.write("<p>") size_html_file = util.embed_link(main_html_file, html_path, subdir + "/motifs%s" % size, "Motifs of size %s" % size) main_html_file.write("</p>") for (template, graph_list) in results.iteritems(): size_html_file.write("<p>") template_svg = chemconvert.hash2svg(template, 200, 200, node_color=black, bond_color=grey) template_svg.embed_in_html(size_html_file, motif_fullpath, template) count_t = len(graph_list) if (count_t > 0): template_html_file = util.embed_link( size_html_file, motif_fullpath, template, "View all %d instances" % count_t) for (delta_l, likelihoods, count, h) in sorted(graph_list): if (likelihoods[-1] <= log_zero and likelihoods[-2] <= log_zero): continue elif (likelihoods[-1] <= log_zero): bond_color = red anti_motif_list.append(h) else: #bond_color = (0, 255 * math.exp(-delta_l), 255 * (1 - math.exp(-delta_l))) bond_color = green motif_svg = chemconvert.hash2svg(h, 150, 150, black, bond_color) motif_svg.set_attribute("height", 200) if (True): # add #motif_svg.add(svg.Text((35, 25), h, 12, green)) l_string = ",".join( ["%.1f" % l for l in likelihoods[2:]]) motif_svg.add( svg.Text((10, 160), "ΔL = %.1f" % delta_l, font_size=12)) motif_svg.add( svg.Text((10, 175), l_string, font_size=12)) if (count > 0): #motif_svg.add(svg.Text((35, 75), "diff = %.1f" % (l1-l0), 12, black)) motif_svg.add( svg.Text((10, 190), "count = %d" % count, font_size=12)) motif_svg.embed_in_html(template_html_file, motif_fullpath, h) else: template_html_file.write("<p>") motif_svg.embed_in_html(template_html_file, motif_fullpath, h) template_html_file.write("<a href=\"" + h + ".svg\">" + h + "</a>") template_html_file.write(", count = %d" % count) for i in range(2, size + 1): template_html_file.write(", L(%d) = %.1f" % (i, likelihoods[i])) template_html_file.write("</p>") template_html_file.close() else: size_html_file.write("No instances") size_html_file.write("</p>") size_html_file.close() main_html_file.close() util.write_text_file(anti_motif_list, "../results/stat/anti_motifs.txt") return