def pathway2text(self, G_subs, expanded_reaction_list):
        num_reactions = len(expanded_reaction_list)
        num_compounds = len(expanded_reaction_list) + 1
        
        i = 0
        G = G_subs.clone()
        rid = None
        
        s = ""

        while True:
            if (i == len(expanded_reaction_list)):
                break
            
            (rid, mapping, reaction_list) = expanded_reaction_list[i]

            s += str(G) + " (" + graph2compound(G, self.ignore_chirality) + ") - " +  str(rid) + " : " + str(mapping) + "\n"
            for reaction in reaction_list:
                s += "\t" + str(G) + " (" + graph2compound(G, self.ignore_chirality) + ") - " + str(reaction.tostring(mapping)) + "\n"
                reaction.apply(G, mapping)
            
            G.update_attributes()
            if (self.ignore_chirality):
                G.reset_chiralities()

            i += 1
        s += str(G) + " (" + graph2compound(G, self.ignore_chirality) + ")\n"
        return (s, G)
Exemple #2
0
    def pathway2text(self, G_subs, expanded_reaction_list):
        num_reactions = len(expanded_reaction_list)
        num_compounds = len(expanded_reaction_list) + 1

        i = 0
        G = G_subs.clone()
        rid = None

        s = ""

        while True:
            if (i == len(expanded_reaction_list)):
                break

            (rid, mapping, reaction_list) = expanded_reaction_list[i]

            s += str(G) + " (" + graph2compound(
                G, self.ignore_chirality) + ") - " + str(rid) + " : " + str(
                    mapping) + "\n"
            for reaction in reaction_list:
                s += "\t" + str(G) + " (" + graph2compound(
                    G, self.ignore_chirality) + ") - " + str(
                        reaction.tostring(mapping)) + "\n"
                reaction.apply(G, mapping)

            G.update_attributes()
            if (self.ignore_chirality):
                G.reset_chiralities()

            i += 1
        s += str(G) + " (" + graph2compound(G, self.ignore_chirality) + ")\n"
        return (s, G)
Exemple #3
0
    def reaction2svg(self, G_old, G_new, rid):
        font_size = 10
        scene = svg.Scene(800, 300)
        scene.add(G_old.svg(svg.Scene(300, 300)))
        scene.add(svg.Text((30, font_size), graph2compound(G_old, self.ignore_chirality), font_size, fill_color=magenta))
        scene.add(svg.Text((325, 120), self.reaction_templates[rid]['NAME'], font_size=font_size, fill_color=red))
        scene.add(svg.ChemicalArrow((380, 150), (420, 150), stroke_width=2))
        scene.add(G_new.svg(svg.Scene(300, 300)), (500, 0))
        scene.add(svg.Text((530, font_size), graph2compound(G_new, self.ignore_chirality), font_size, fill_color=magenta))
#        scene.justify()
        scene.border(True)
        return scene
Exemple #4
0
 def reaction2svg(self, G_old, G_new, rid):
     font_size = 10
     scene = svg.Scene(800, 300)
     scene.add(G_old.svg(svg.Scene(300, 300)))
     scene.add(
         svg.Text((30, font_size), graph2compound(G_old, self.ignore_chirality), font_size, fill_color=magenta)
     )
     scene.add(svg.Text((325, 120), self.reaction_templates[rid]["NAME"], font_size=font_size, fill_color=red))
     scene.add(svg.ChemicalArrow((380, 150), (420, 150), stroke_width=2))
     scene.add(G_new.svg(svg.Scene(300, 300)), (500, 0))
     scene.add(
         svg.Text((530, font_size), graph2compound(G_new, self.ignore_chirality), font_size, fill_color=magenta)
     )
     #        scene.justify()
     scene.border(True)
     return scene
Exemple #5
0
    def test(self, comp=None):
        util._mkdir('../results')
        util._mkdir('../results/svg')

        if (comp == None):
            html = html_writer.HtmlWriter("../results/reaction_templates.html")
            counter = 0
            for rid in self.forward_reaction_list:
                html.write(self.get_reaction_info(rid))
                html.write_svg(self.template2svg(rid), "svg/reaction_template_%d" % counter)
                counter += 1
            html.display()
        else:
            G = compound2graph(comp)
            html = html_writer.HtmlWriter("../results/reaction_example.html")
            html.write("<h1>Reactions for compound: " + comp + "</h1>")
            html.write("<p>")
            html.write_svg(G.svg(), "svg/compound")
            html.write("</p>")
            counter = 0
            
            products_set = set()
            print "Products for " + comp + " : "
            for (G_new, rid, mapping) in self.apply_all_reactions(G, backward=False):
                products_set.add(G_new.hash(ignore_chirality=self.ignore_chirality))
                print rid + ": " + graph2compound(G_new, ignore_chirality=False)
                html.write(self.get_reaction_info(rid, mapping))
                html.write_svg(self.template2svg(rid), "svg/reaction_template_%d" % counter)
                html.write("</br>")
                html.write_svg(self.reaction2svg(G, G_new, rid), "svg/product_%d" % counter)
                counter += 1

            product_file = open("../results/products.txt", 'w')
            product_file.write("\n".join(products_set))
            product_file.close()
            
            html.display()
            return
Exemple #6
0
    def test(self, comp=None):
        util._mkdir("../results")
        util._mkdir("../results/svg")

        if comp == None:
            html = html_writer.HtmlWriter("../results/reaction_templates.html")
            counter = 0
            for rid in self.forward_reaction_list:
                html.write(self.get_reaction_info(rid))
                html.write_svg(self.template2svg(rid), "svg/reaction_template_%d" % counter)
                counter += 1
            html.display()
        else:
            G = compound2graph(comp)
            html = html_writer.HtmlWriter("../results/reaction_example.html")
            html.write("<h1>Reactions for compound: " + comp + "</h1>")
            html.write("<p>")
            html.write_svg(G.svg(), "svg/compound")
            html.write("</p>")
            counter = 0

            products_set = set()
            print "Products for " + comp + " : "
            for (G_new, rid, mapping) in self.apply_all_reactions(G, backward=False):
                products_set.add(G_new.hash(ignore_chirality=self.ignore_chirality))
                print rid + ": " + graph2compound(G_new, ignore_chirality=False)
                html.write(self.get_reaction_info(rid, mapping))
                html.write_svg(self.template2svg(rid), "svg/reaction_template_%d" % counter)
                html.write("</br>")
                html.write_svg(self.reaction2svg(G, G_new, rid), "svg/product_%d" % counter)
                counter += 1

            product_file = open("../results/products.txt", "w")
            product_file.write("\n".join(products_set))
            product_file.close()

            html.display()
            return