Example #1
0
def main1():
    util._mkdir("../results/ec-list")
    counter = 1
    for line in util.parse_text_file("../rec/ec-list.smiles"):
        print counter, ")", line
        smiles2svg(line, "../results/ec-list/%d.svg" % counter)
        counter += 1
def main():
    util._mkdir("../results/svg")
    #substrate = '_GAP + _GAP'
    #substrate = '_GLC-6P_OCF'
    #(substrate, target) = ('L-Serine', '_3-PG')
    (substrate, target) = ('3-Phospho-Hydroxypyruvate', 'L-Serine')
    G_subs = compounds2graph(substrate)
    h_target = compounds2graph(target).hash()
    h_subs = G_subs.hash()

    product_html_writer = html_writer.HtmlWriter("../results/valid_products.html")
    product_html_writer.write("<center>Substrate : " + strip_hash_chirality(h_subs) + "</center><br>")
    product_html_writer.write("<center>Target : " + strip_hash_chirality(h_target) + "</center><br>")
    product_html_writer.write_svg(G_subs.svg(Scene(400, 200, 10)), "svg/" + h_subs)
    product_html_writer.write("<p>")
    
    for (h_substrate, G_product, reaction) in generate_new_compounds({h_subs : G_subs}, False):
        h_product = G_product.hash()
        product_html_writer.write("<br><center>" + reaction + " : " + strip_hash_chirality(h_product) + "</center><br>")

        if (strip_hash_chirality(h_product) == strip_hash_chirality(h_target)):
            product_html_writer.write("<center>Target Found !!!</center><br>")
        product_html_writer.write_svg(G_product.svg(Scene(400, 200, 10)), "svg/" + h_product)

    product_html_writer.write("</p>")

    product_html_writer.close()
    return
Example #3
0
def main1():
    util._mkdir("../results/ec-list")
    counter = 1
    for line in util.parse_text_file("../rec/ec-list.smiles"):
        print counter, ")", line
        smiles2svg(line, "../results/ec-list/%d.svg" % counter)
        counter += 1
Example #4
0
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()
Example #5
0
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()
Example #6
0
def verify_file(max_subgraph_size):
    util._mkdir("../results/stat")
    motif_filename = "../results/stat/motifs%d.txt" % max_subgraph_size
    if (not os.path.exists(motif_filename)):
        print "Computing motif histogram for subgraphs of size <= %d ..." % max_subgraph_size,
        motifs = compute_motifs(max_subgraph_size)
        print "[DONE]"
        write_dictionary(motifs, motif_filename)
        return motifs
    else:
        motifs = read_dictionary(motif_filename)
        for key in motifs.keys():
            motifs[key] = int(float(motifs[key]))
        return motifs
Example #7
0
def verify_file(max_subgraph_size):
    util._mkdir("../results/stat")
    motif_filename = "../results/stat/motifs%d.txt" % max_subgraph_size
    if (not os.path.exists(motif_filename)):
        print "Computing motif histogram for subgraphs of size <= %d ..." % max_subgraph_size,
        motifs = compute_motifs(max_subgraph_size)
        print "[DONE]"
        write_dictionary(motifs, motif_filename)
        return motifs
    else:
        motifs = read_dictionary(motif_filename)
        for key in motifs.keys():
            motifs[key] = int(float(motifs[key]))
        return motifs
Example #8
0
 def __init__(self, filename, force_path_creation=True):
     self.filename = filename
     self.filepath = os.path.dirname(filename)
     if (not os.path.exists(self.filepath)):
         if (force_path_creation):
             util._mkdir(self.filepath)
         else:
             raise Exception("cannot write to HTML file %s since the directory doesn't exist" % filename)
     
     self.file = open(self.filename, "w")
     self.write("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" ")
     self.write("\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">")
     self.write("<html>\n<body>\n")
     return
Example #9
0
def convert_compounds_hash(compound_dat_filename):
    compound2hash = util.parse_dat(compound_dat_filename, "UNIQUE-ID", "HASH")
    util._mkdir("../mol")
    for (key, smiles) in compound2hash.iteritems():
        mol_filename = "../mol/" + key + ".mol"
        if (not os.path.exists(mol_filename)):
            print "Writing a MOL file to: " + mol_filename
            if (len(smiles) > 0):
                mol = chemconvert.hash2graph(smiles[0]).to_mol()
                mol_file = open(mol_filename, "w")
                mol_file.write(mol)
                mol_file.close()
        else:
            print "Found the MOL file: " + mol_filename
    return
Example #10
0
def convert_compounds_hash(compound_dat_filename):
    compound2hash = util.parse_dat(compound_dat_filename, "UNIQUE-ID", "HASH")
    util._mkdir("../mol")
    for (key, smiles) in compound2hash.iteritems():
        mol_filename = "../mol/" + key + ".mol"
        if (not os.path.exists(mol_filename)):
            print "Writing a MOL file to: " + mol_filename
            if (len(smiles) > 0):
                mol = chemconvert.hash2graph(smiles[0]).to_mol()
                mol_file = open(mol_filename, "w")
                mol_file.write(mol)
                mol_file.close()
        else:
            print "Found the MOL file: " + mol_filename
    return
Example #11
0
def main2():
    util._mkdir("../results")
    f = open("../results/hash2compound.txt", "w")
    for (h, compound) in map_hash2compound.iteritems():
        f.write("compound = %s\n" % compound)
        f.write("hash = %s\n" % h)
        f.write("$$$$\n")
    f.close()
    
    import html_writer
    compound_list = sorted(map_compound2graph.keys())
    
    util._mkdir("../results/svg")
    html_writer = html_writer.HtmlWriter("../results/compounds.html")
    html_writer.write("<h1><center>Known Compounds</h1></center>")
    for i in range(len(compound_list)):
        G = map_compound2graph[compound_list[i].upper()]
        scene = G.svg(svg.Scene(300, 300, 10))
        scene.add(svg.Text((30, 10), compound_list[i], 10, fill_color=magenta))
        html_writer.write_svg(scene, "svg/%s" % G.hash())

    html_writer.display()
Example #12
0
def test():
    util._mkdir("../results")
    f = open("../results/hash2compound.txt", "w")
    for (h, compound) in map_hash2compound.iteritems():
        f.write("compound = %s\n" % compound)
        f.write("hash = %s\n" % h)
        f.write("$$$$\n")
    f.close()

    import html_writer
    compound_list = sorted(map_compound2graph.keys())

    util._mkdir("../results/svg")
    html_writer = html_writer.HtmlWriter("../results/compounds.html")
    html_writer.write("<h1><center>Known Compounds</h1></center>")
    for i in range(len(compound_list)):
        G = map_compound2graph[compound_list[i].upper()]
        scene = G.svg(svg.Scene(300, 300, 10))
        scene.add(svg.Text((30, 10), compound_list[i], 10, fill_color=magenta))
        html_writer.write_svg(scene, "svg/%s" % G.hash())

    html_writer.display()
Example #13
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
Example #14
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
def main():
    util._mkdir("../results/svg")
    #substrate = '_GAP + _GAP'
    #substrate = '_GLC-6P_OCF'
    #(substrate, target) = ('L-Serine', '_3-PG')
    (substrate, target) = ('3-Phospho-Hydroxypyruvate', 'L-Serine')
    G_subs = compounds2graph(substrate)
    h_target = compounds2graph(target).hash()
    h_subs = G_subs.hash()

    product_html_writer = html_writer.HtmlWriter(
        "../results/valid_products.html")
    product_html_writer.write("<center>Substrate : " +
                              strip_hash_chirality(h_subs) + "</center><br>")
    product_html_writer.write("<center>Target : " +
                              strip_hash_chirality(h_target) + "</center><br>")
    product_html_writer.write_svg(G_subs.svg(Scene(400, 200, 10)),
                                  "svg/" + h_subs)
    product_html_writer.write("<p>")

    for (h_substrate, G_product,
         reaction) in generate_new_compounds({h_subs: G_subs}, False):
        h_product = G_product.hash()
        product_html_writer.write("<br><center>" + reaction + " : " +
                                  strip_hash_chirality(h_product) +
                                  "</center><br>")

        if (strip_hash_chirality(h_product) == strip_hash_chirality(h_target)):
            product_html_writer.write("<center>Target Found !!!</center><br>")
        product_html_writer.write_svg(G_product.svg(Scene(400, 200, 10)),
                                      "svg/" + h_product)

    product_html_writer.write("</p>")

    product_html_writer.close()
    return
Example #16
0
    def __init__(self, modules_file, experiment_name, max_module_size=6):

        self.modules_file = modules_file
        self.experiment_name = experiment_name
        self.max_module_size = max_module_size
        util._mkdir("../log")
        self.logfile = open("../log/pathologic_" + self.experiment_name + ".log", "w")
        
        util._mkdir("../results")
        util._mkdir("../results/pathologic_" + self.experiment_name)
        self.html_writer = HtmlWriter("../results/pathologic_" + self.experiment_name + ".html")
        self.html_writer.write("<h1>List of optimal and non-optimal pathways</h1>\n")
        self.html_writer.write("<ul>\n")
        self.line_counter = 0
        self.pathfinder = None
Example #17
0
    def __init__(self, modules_file, experiment_name, max_module_size=6):

        self.modules_file = modules_file
        self.experiment_name = experiment_name
        self.max_module_size = max_module_size
        util._mkdir("../log")
        self.logfile = open(
            "../log/pathologic_" + self.experiment_name + ".log", "w")

        util._mkdir("../results")
        util._mkdir("../results/pathologic_" + self.experiment_name)
        self.html_writer = HtmlWriter("../results/pathologic_" +
                                      self.experiment_name + ".html")
        self.html_writer.write(
            "<h1>List of optimal and non-optimal pathways</h1>\n")
        self.html_writer.write("<ul>\n")
        self.line_counter = 0
        self.pathfinder = None
Example #18
0
from chemistry import *
from chemconvert import molfile2graph
import sys
from svg import Scene
import os

pathway_path = "../pathways"
mol_path = "../mol"
html_path = "../pathways/html"

#pathway = "glycolysis-2"
pathway = "glycolysis-1"
#pathway = "pentose-phosphate"
#pathway = "frucolysis"

util._mkdir(html_path + "/" + pathway)
html_filename = html_path + "/" + pathway + ".html"
html_file = open(html_filename, "w")

prev_line_bag = None
reaction_titles = []
reaction_compounds = []
line_number = 0
for line in util.parse_text_file(pathway_path + "/" + pathway + ".pth"):  
    line_number += 1
    if (line[0:2] == "//"):
        prev_line_bag = None
        reaction_titles.append("*"*60 + " " + line[2:] + " " + "*"*60)
        reaction_compounds.append(None)
    elif (prev_line_bag == None):
        prev_line_bag = bag.Bag().from_string(line)
Example #19
0
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),
                                     "&#916;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
Example #20
0
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), "&#916;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
Example #21
0
#!/usr/bin/python
""" This is a script that runs through a CSV file of pairs of compounds and
    tests if they are part of an optimality module (the wild-type path between
    them is one of the possible shortest paths).
"""

import util
import sys
import bag
from pathfinder import PathFinder
from chemconvert import compound2graph

util._mkdir('../log')
logfile = open('../log/pathcounter.log', 'a')

substrates = []
substrates.append(('Acetyl-CoA', range(1, 4)))
substrates.append(('Phosphoenolpyruvate', range(1, 4)))
substrates.append(('Pyruvate', range(1, 4)))
substrates.append(('D-Glyceraldehyde-3P', range(1, 4)))
substrates.append(('3-Phosphoglycerate', range(1, 4)))
substrates.append(('oxaloacetate', range(1, 4)))
substrates.append(('fumarate', range(1, 4)))

pairs = []
pairs.append(('D-fructose-6P_ring', 'D-glucolactone-6P', range(1, 5)))
pairs.append(('D-fructose-6P', 'D-ribose-5P', range(1, 5)))
pairs.append(('D-Glyceraldehyde-3P', '3-Phosphoglycerate', range(1, 5)))
pairs.append(('3-Phosphoglycerate', 'Phosphoenolpyruvate', range(1, 5)))
pairs.append(('fumarate', 'oxaloacetate', range(1, 5)))
pairs.append(('oxaloacetate', 'pyruvate', range(1, 5)))
Example #22
0
#!/usr/bin/python

import sys
import os
import util
from chemconvert import hash2graph
from html_writer import HtmlWriter
from svg import Scene

html = HtmlWriter("../results/hash_list.html")
util._mkdir("../results/hash_list")

for line in util.parse_text_file(sys.argv[1]):
    print line
    graph = hash2graph(line)
    graph.initialize_pos()
    scene = graph.svg(Scene(200, 200, font_size=12))
    html.write_svg(scene, "../results/hash_list/" + line)

html.display()
Example #23
0
def main():
    Pentose_target_compounds = ['D-Xylulose-5P', 'D-Ribulose-5P', 'D-Ribose-5P']
    
    PP_compounds = \
        ['D-Xylulose-5P',\
         'D-Ribulose-5P',\
         'D-Ribose-5P',\
         'D-Erythrose-4P',\
         'D-Sedoheptulose-7P',\
         'D-Fructose-6P',\
         'D-Glyceraldehyde-3P']
    
    Glycolysis_compounds = \
        ['Dihydroxyacetone-3P',\
         'D-Glyceraldehyde-3P',\
         'Bisphosphoglycerate',\
         '3-Phosphoglycerate',\
         '2-Phosphoglycerate',\
         'Phosphoenolpyruvate',\
         'Pyruvate']
    
    TCA_compounds = \
        ['Oxaloacetate',\
         'Citrate',\
         'cis-Aconitate',\
         'D-Isocitrate',\
         '2-Ketoglutarate',\
         #succinyl-CoA\
         'Succinate',\
         'Fumarate',\
         'Malate',\
         ]
    
    Biosynthese_compounds = PP_compounds + Glycolysis_compounds + TCA_compounds
    
    pathway_list = []
    # fast test
    pathway_list.append(("TEST", ['2-Phosphoglycerate'], ['Bisphosphoglycerate'], None))

    # Optimality Modules:
    pathway_list.append(("Glucose to Fructose", ['D-glucose-6P'], ['D-fructose-6P'], None))
    pathway_list.append(("Fructose to Glucose", ['D-fructose-6P'], ['D-glucose-6P'], None))
    
    pathway_list.append(("oxaloacetate+acetyl-CoA to citrate", ['oxaloacetate + acetyl-CoA'], ['citrate'], None))
    pathway_list.append(("cis-aconitate to succinate", ['cis-aconitate'], ['succinate'], None))
    pathway_list.append(("D-xylose to D-xylulose-5P", ['D-Xylose'], ['D-Xylulose-5P'], None))
    pathway_list.append(("D-arabitol to D-xylulose-5P", ['D-Arabitol'], ['D-Xylulose-5P'], None))
    pathway_list.append(("L-arabinose to D-xylulose-5P", ['L-Arabinose'], ['D-Xylulose-5P'], None))
    pathway_list.append(("L-xylulose to D-xylulose-5P", ['L-Xylulose'], ['D-Xylulose-5P'], None))
    pathway_list.append(("ribitol to D-xylulose-5P", ['Ribitol'], ['D-Xylulose-5P'], None))
    pathway_list.append(("D-ribose to D-xylulose-5P", ['D-Ribose'], ['D-Xylulose-5P'], None))
    pathway_list.append(("Oxaloacetate to 2-Ketoglutarate", ['Oxaloacetate'], ['2-Ketoglutarate'], None))
    pathway_list.append(("Citrate to 2-Ketoglutarate", ['Citrate'], ['2-Ketoglutarate'], None))
    
    
    pathway_list.append(("Pentose Phosphate", ['D-Xylulose-5P + D-Xylulose-5P + D-Ribose-5P'], ['D-Fructose-6P + D-Fructose-6P + D-Glyceraldehyde-3P'], None))
    #pathway_list.append(("Pentose Phosphate", ['D-Xylulose-5P + D-Ribose-5P'], ['D-Glyceraldehyde-3P + D-Sedoheptulose-7P'], None))
    pathway_list.append(("D-glucose to D-ribulose-5P", ['D-Glucose'], ['D-Ribulose-5P'], None))
    pathway_list.append(("D-glucose to D-fructose-16P", ['D-Glucose'], ['D-Fructose-16P'], None))
    pathway_list.append(("D-fructose-6P to GAP+DHAP", ['D-Fructose-6P'], ['D-Glyceraldehyde-3P + Dihydroxyacetone-3P'], None))
    pathway_list.append(("GAP to 3-PG", ['D-Glyceraldehyde-3P'], ['3-Phosphoglycerate'], None))
    pathway_list.append(("GAP to 2-PG", ['D-Glyceraldehyde-3P'], ['2-Phosphoglycerate'], None))
    pathway_list.append(("BPG to 3-PG", ['Bisphosphoglycerate'], ['3-Phosphoglycerate'], None))
    pathway_list.append(("BPG to 2-PG", ['Bisphosphoglycerate'], ['2-Phosphoglycerate'], None))
    pathway_list.append(("BPG to PEP", ['Bisphosphoglycerate'], ['Phosphoenolpyruvate'], None))
    pathway_list.append(("3-PG to PYR", ['3-Phosphoglycerate'], ['Pyruvate'], None))

    # Biosynthesis
    pathway_list.append(("3-PG to L-Serine", ['3-Phosphoglycerate'], ['L-Serine'], None))
    pathway_list.append(("L-Serine to Glycine", ['L-Serine'], ['Glycine'], None))
    pathway_list.append(("Pyruvate to L-Alanine", ['Pyruvate'], ['L-Alanine'], None))
    
    pathway_list.append(("Synthesis of L-Serine", Biosynthese_compounds, ['L-Serine'], None))
    pathway_list.append(("Synthesis of L-Alanine", Biosynthese_compounds, ['L-Alanine'], None))
    pathway_list.append(("Synthesis of Glycine", Biosynthese_compounds, ['Glycine'], None))
    pathway_list.append(("Synthesis of L-Aspartate", Biosynthese_compounds, ['L-Aspartate'], None))
    pathway_list.append(("Synthesis of L-Glutamate", Biosynthese_compounds, ['L-Glutamate'], None))

    # Pentose utilization
    pathway_list.append(("L-Arabinose to Pentose Phosphate", ['L-Arabinose'], Pentose_target_compounds, None))
    pathway_list.append(("D-Xylose to Pentose Phosphate", ['D-Xylose'], Pentose_target_compounds, None))
    pathway_list.append(("D-Ribose to Pentose Phosphate", ['D-Ribose'], Pentose_target_compounds, None))
    pathway_list.append(("Ribitol to Pentose Phosphate", ['Ribitol'], Pentose_target_compounds, None))
    pathway_list.append(("D-Arabitol to Pentose Phosphate", ['D-Arabitol'], Pentose_target_compounds, None))

    # Glycolysis
    pathway_list.append(("GAP to PYR", ['D-Glyceraldehyde-3P'], ['Pyruvate'], 'PP'))
    pathway_list.append(("GAP to DHAP", ['D-Glyceraldehyde-3P'], ['Dihydroxyacetone-3P'], 'PP'))
    pathway_list.append(("GAP to PEP", ['D-Glyceraldehyde-3P + H2O'], ['Phosphoenolpyruvate + H2O'], 'PP'))
    pathway_list.append(("GAP to 2-PG", ['D-Glyceraldehyde-3P'], ['2-Phosphoglycerate'], 'PP'))
    pathway_list.append(("GLC to GAP", ['D-Glucose'], ['D-Glyceraldehyde-3P + D-Glyceraldehyde-3P'], 'PP'))
    pathway_list.append(("GLC to PYR", ['Glucose'], ['Pyruvate + Pyruvate'], 'PP'))
    pathway_list.append(("GLC-36P to GAP", ['D-Glucose-36P'], ['D-Glyceraldehyde-3P + D-Glyceraldehyde-3P'], 'PP'))
    pathway_list.append(("GLC-6P to GAP", ['D-Glucose-6P'], ['D-Glyceraldehyde-3P + D-Glyceraldehyde-3P'], 'PP'))
    pathway_list.append(("GLC-6P to BPG", ['D-Glucose-6P'], ['Bisphosphoglycerate + Bisphosphoglycerate'], 'PP'))
    pathway_list.append(("GLC-6P to 3-PG", ['D-Glucose-6P'], ['3-Phosphoglycerate + 3-Phosphoglycerate'], 'PP'))
    pathway_list.append(("GLC-6P to 2-PG", ['D-Glucose-6P'], ['2-Phosphoglycerate + 2-Phosphoglycerate'], 'PP'))
    pathway_list.append(("GLC-6P to PEP", ['D-Glucose-6P'], ['Phosphoenolpyruvate + Phosphoenolpyruvate'], 'PP'))
    pathway_list.append(("2-PG to PYR", ['2-Phosphoglycerate'], ['Pyruvate'], 'PP'))
    pathway_list.append(("3-PG to PYR", ['3-Phosphoglycerate'], ['Pyruvate'], 'PP'))
    pathway_list.append(("BPG to PYR", ['Bisphosphoglycerate'], ['Pyruvate'], 'PP'))
    pathway_list.append(("BPG to PEP", ['Bisphosphoglycerate'], ['Phosphoenolpyruvate'], 'PP'))
    
    # Arren's project
    pathway_list.append(("Glyoxylate + GAP to Pentose", ['Glyoxylate + D-Glyceraldehyde-3P'], Pentose_target_compounds, None))
    pathway_list.append(("Glyoxylate + PYR to Pentose", ['Glyoxylate + Pyruvate'], Pentose_target_compounds, None))
    pathway_list.append(("Glycolate + GAP to Pentose", ['Glycolate + D-Glyceraldehyde-3P'], Pentose_target_compounds, None))
    pathway_list.append(("Glycolate + PYR to Pentose", ['Glycolate + Pyruvate'], Pentose_target_compounds, None))
    
    pathway_names = [pathway[0] for pathway in pathway_list]
    pathway_map = {}
    for pathway in pathway_list:
        pathway_map[pathway[0]] = pathway[1:]
    
    if (len(sys.argv) > 1):
        pathway_name = pathway_names[int(sys.argv[1]) - 1]
    else:
        pathway_name = TkListSelection(pathway_names, "Choose a pathway:")
        if (pathway_name == None):
            sys.exit(0)
    
    (substrates, products, pruning_method) = pathway_map[pathway_name]
    pathfinder = PathFinder(carbon_only=False, pruning_method=pruning_method, ignore_chirality=True)

    print "-"*80 + "\nChosen pathway name is %s\n" % pathway_name + "-"*80

    util._mkdir("../results")
    util._mkdir("../results/" + pathway_name)
    html_writer = HtmlWriter("../results/" + pathway_name + ".html")
    html_writer.write("<h1><center>%s</center></h1>\n" % pathway_name)
    html_writer.write("<ul>\n")
    for i in range(len(substrates)):
        for j in range(len(products)):
            ##(subs, prod) = pathfinder.balance_reaction(substrates[i], products[j])
            (subs, prod) = (substrates[i], products[j])
            pathway_prefix = "pathway_%d_%d" % (i, j)
            util._mkdir("../results/" + pathway_name + "/" + pathway_prefix)
            pathfinder.solve_pathway(subs, prod, html_writer, pathway_name, pathway_prefix, max_levels=6, stop_after_first_solution=True)
            html_writer.flush()
    html_writer.write("</ul>\n")
    html_writer.display()
    
    return
Example #24
0
#!/usr/bin/python

import sys
import os
import util
from chemconvert import hash2graph
from html_writer import HtmlWriter
from svg import Scene

html = HtmlWriter("../results/hash_list.html")
util._mkdir("../results/hash_list")

for line in util.parse_text_file(sys.argv[1]):
	print line
	graph = hash2graph(line)
	graph.initialize_pos()
	scene = graph.svg(Scene(200, 200, font_size=12))    
	html.write_svg(scene, "../results/hash_list/" + line)

html.display()
Example #25
0
def main():
    Pentose_target_compounds = [
        'D-Xylulose-5P', 'D-Ribulose-5P', 'D-Ribose-5P'
    ]

    PP_compounds = \
        ['D-Xylulose-5P',\
         'D-Ribulose-5P',\
         'D-Ribose-5P',\
         'D-Erythrose-4P',\
         'D-Sedoheptulose-7P',\
         'D-Fructose-6P',\
         'D-Glyceraldehyde-3P']

    Glycolysis_compounds = \
        ['Dihydroxyacetone-3P',\
         'D-Glyceraldehyde-3P',\
         'Bisphosphoglycerate',\
         '3-Phosphoglycerate',\
         '2-Phosphoglycerate',\
         'Phosphoenolpyruvate',\
         'Pyruvate']

    TCA_compounds = \
        ['Oxaloacetate',\
         'Citrate',\
         'cis-Aconitate',\
         'D-Isocitrate',\
         '2-Ketoglutarate',\
         #succinyl-CoA\
         'Succinate',\
         'Fumarate',\
         'Malate',\
         ]

    Biosynthese_compounds = PP_compounds + Glycolysis_compounds + TCA_compounds

    pathway_list = []
    # fast test
    pathway_list.append(
        ("TEST", ['2-Phosphoglycerate'], ['Bisphosphoglycerate'], None))

    # Optimality Modules:
    pathway_list.append(
        ("Glucose to Fructose", ['D-glucose-6P'], ['D-fructose-6P'], None))
    pathway_list.append(
        ("Fructose to Glucose", ['D-fructose-6P'], ['D-glucose-6P'], None))

    pathway_list.append(("oxaloacetate+acetyl-CoA to citrate",
                         ['oxaloacetate + acetyl-CoA'], ['citrate'], None))
    pathway_list.append(
        ("cis-aconitate to succinate", ['cis-aconitate'], ['succinate'], None))
    pathway_list.append(
        ("D-xylose to D-xylulose-5P", ['D-Xylose'], ['D-Xylulose-5P'], None))
    pathway_list.append(("D-arabitol to D-xylulose-5P", ['D-Arabitol'],
                         ['D-Xylulose-5P'], None))
    pathway_list.append(("L-arabinose to D-xylulose-5P", ['L-Arabinose'],
                         ['D-Xylulose-5P'], None))
    pathway_list.append(("L-xylulose to D-xylulose-5P", ['L-Xylulose'],
                         ['D-Xylulose-5P'], None))
    pathway_list.append(
        ("ribitol to D-xylulose-5P", ['Ribitol'], ['D-Xylulose-5P'], None))
    pathway_list.append(
        ("D-ribose to D-xylulose-5P", ['D-Ribose'], ['D-Xylulose-5P'], None))
    pathway_list.append(("Oxaloacetate to 2-Ketoglutarate", ['Oxaloacetate'],
                         ['2-Ketoglutarate'], None))
    pathway_list.append(
        ("Citrate to 2-Ketoglutarate", ['Citrate'], ['2-Ketoglutarate'], None))

    pathway_list.append(
        ("Pentose Phosphate", ['D-Xylulose-5P + D-Xylulose-5P + D-Ribose-5P'],
         ['D-Fructose-6P + D-Fructose-6P + D-Glyceraldehyde-3P'], None))
    #pathway_list.append(("Pentose Phosphate", ['D-Xylulose-5P + D-Ribose-5P'], ['D-Glyceraldehyde-3P + D-Sedoheptulose-7P'], None))
    pathway_list.append(
        ("D-glucose to D-ribulose-5P", ['D-Glucose'], ['D-Ribulose-5P'], None))
    pathway_list.append(("D-glucose to D-fructose-16P", ['D-Glucose'],
                         ['D-Fructose-16P'], None))
    pathway_list.append(("D-fructose-6P to GAP+DHAP", ['D-Fructose-6P'],
                         ['D-Glyceraldehyde-3P + Dihydroxyacetone-3P'], None))
    pathway_list.append(
        ("GAP to 3-PG", ['D-Glyceraldehyde-3P'], ['3-Phosphoglycerate'], None))
    pathway_list.append(
        ("GAP to 2-PG", ['D-Glyceraldehyde-3P'], ['2-Phosphoglycerate'], None))
    pathway_list.append(
        ("BPG to 3-PG", ['Bisphosphoglycerate'], ['3-Phosphoglycerate'], None))
    pathway_list.append(
        ("BPG to 2-PG", ['Bisphosphoglycerate'], ['2-Phosphoglycerate'], None))
    pathway_list.append(
        ("BPG to PEP", ['Bisphosphoglycerate'], ['Phosphoenolpyruvate'], None))
    pathway_list.append(
        ("3-PG to PYR", ['3-Phosphoglycerate'], ['Pyruvate'], None))

    # Biosynthesis
    pathway_list.append(
        ("3-PG to L-Serine", ['3-Phosphoglycerate'], ['L-Serine'], None))
    pathway_list.append(
        ("L-Serine to Glycine", ['L-Serine'], ['Glycine'], None))
    pathway_list.append(
        ("Pyruvate to L-Alanine", ['Pyruvate'], ['L-Alanine'], None))

    pathway_list.append(
        ("Synthesis of L-Serine", Biosynthese_compounds, ['L-Serine'], None))
    pathway_list.append(
        ("Synthesis of L-Alanine", Biosynthese_compounds, ['L-Alanine'], None))
    pathway_list.append(
        ("Synthesis of Glycine", Biosynthese_compounds, ['Glycine'], None))
    pathway_list.append(("Synthesis of L-Aspartate", Biosynthese_compounds,
                         ['L-Aspartate'], None))
    pathway_list.append(("Synthesis of L-Glutamate", Biosynthese_compounds,
                         ['L-Glutamate'], None))

    # Pentose utilization
    pathway_list.append(("L-Arabinose to Pentose Phosphate", ['L-Arabinose'],
                         Pentose_target_compounds, None))
    pathway_list.append(("D-Xylose to Pentose Phosphate", ['D-Xylose'],
                         Pentose_target_compounds, None))
    pathway_list.append(("D-Ribose to Pentose Phosphate", ['D-Ribose'],
                         Pentose_target_compounds, None))
    pathway_list.append(("Ribitol to Pentose Phosphate", ['Ribitol'],
                         Pentose_target_compounds, None))
    pathway_list.append(("D-Arabitol to Pentose Phosphate", ['D-Arabitol'],
                         Pentose_target_compounds, None))

    # Glycolysis
    pathway_list.append(
        ("GAP to PYR", ['D-Glyceraldehyde-3P'], ['Pyruvate'], 'PP'))
    pathway_list.append(("GAP to DHAP", ['D-Glyceraldehyde-3P'],
                         ['Dihydroxyacetone-3P'], 'PP'))
    pathway_list.append(("GAP to PEP", ['D-Glyceraldehyde-3P + H2O'],
                         ['Phosphoenolpyruvate + H2O'], 'PP'))
    pathway_list.append(
        ("GAP to 2-PG", ['D-Glyceraldehyde-3P'], ['2-Phosphoglycerate'], 'PP'))
    pathway_list.append(("GLC to GAP", ['D-Glucose'],
                         ['D-Glyceraldehyde-3P + D-Glyceraldehyde-3P'], 'PP'))
    pathway_list.append(
        ("GLC to PYR", ['Glucose'], ['Pyruvate + Pyruvate'], 'PP'))
    pathway_list.append(("GLC-36P to GAP", ['D-Glucose-36P'],
                         ['D-Glyceraldehyde-3P + D-Glyceraldehyde-3P'], 'PP'))
    pathway_list.append(("GLC-6P to GAP", ['D-Glucose-6P'],
                         ['D-Glyceraldehyde-3P + D-Glyceraldehyde-3P'], 'PP'))
    pathway_list.append(("GLC-6P to BPG", ['D-Glucose-6P'],
                         ['Bisphosphoglycerate + Bisphosphoglycerate'], 'PP'))
    pathway_list.append(("GLC-6P to 3-PG", ['D-Glucose-6P'],
                         ['3-Phosphoglycerate + 3-Phosphoglycerate'], 'PP'))
    pathway_list.append(("GLC-6P to 2-PG", ['D-Glucose-6P'],
                         ['2-Phosphoglycerate + 2-Phosphoglycerate'], 'PP'))
    pathway_list.append(("GLC-6P to PEP", ['D-Glucose-6P'],
                         ['Phosphoenolpyruvate + Phosphoenolpyruvate'], 'PP'))
    pathway_list.append(
        ("2-PG to PYR", ['2-Phosphoglycerate'], ['Pyruvate'], 'PP'))
    pathway_list.append(
        ("3-PG to PYR", ['3-Phosphoglycerate'], ['Pyruvate'], 'PP'))
    pathway_list.append(
        ("BPG to PYR", ['Bisphosphoglycerate'], ['Pyruvate'], 'PP'))
    pathway_list.append(
        ("BPG to PEP", ['Bisphosphoglycerate'], ['Phosphoenolpyruvate'], 'PP'))

    # Arren's project
    pathway_list.append(
        ("Glyoxylate + GAP to Pentose", ['Glyoxylate + D-Glyceraldehyde-3P'],
         Pentose_target_compounds, None))
    pathway_list.append(
        ("Glyoxylate + PYR to Pentose", ['Glyoxylate + Pyruvate'],
         Pentose_target_compounds, None))
    pathway_list.append(
        ("Glycolate + GAP to Pentose", ['Glycolate + D-Glyceraldehyde-3P'],
         Pentose_target_compounds, None))
    pathway_list.append(
        ("Glycolate + PYR to Pentose", ['Glycolate + Pyruvate'],
         Pentose_target_compounds, None))

    pathway_names = [pathway[0] for pathway in pathway_list]
    pathway_map = {}
    for pathway in pathway_list:
        pathway_map[pathway[0]] = pathway[1:]

    if (len(sys.argv) > 1):
        pathway_name = pathway_names[int(sys.argv[1]) - 1]
    else:
        pathway_name = TkListSelection(pathway_names, "Choose a pathway:")
        if (pathway_name == None):
            sys.exit(0)

    (substrates, products, pruning_method) = pathway_map[pathway_name]
    pathfinder = PathFinder(carbon_only=False,
                            pruning_method=pruning_method,
                            ignore_chirality=True)

    print "-" * 80 + "\nChosen pathway name is %s\n" % pathway_name + "-" * 80

    util._mkdir("../results")
    util._mkdir("../results/" + pathway_name)
    html_writer = HtmlWriter("../results/" + pathway_name + ".html")
    html_writer.write("<h1><center>%s</center></h1>\n" % pathway_name)
    html_writer.write("<ul>\n")
    for i in range(len(substrates)):
        for j in range(len(products)):
            ##(subs, prod) = pathfinder.balance_reaction(substrates[i], products[j])
            (subs, prod) = (substrates[i], products[j])
            pathway_prefix = "pathway_%d_%d" % (i, j)
            util._mkdir("../results/" + pathway_name + "/" + pathway_prefix)
            pathfinder.solve_pathway(subs,
                                     prod,
                                     html_writer,
                                     pathway_name,
                                     pathway_prefix,
                                     max_levels=6,
                                     stop_after_first_solution=True)
            html_writer.flush()
    html_writer.write("</ul>\n")
    html_writer.display()

    return
Example #26
0
#!/usr/bin/python

""" This is a script that runs through a CSV file of pairs of compounds and
    tests if they are part of an optimality module (the wild-type path between
    them is one of the possible shortest paths).
"""

import util
import sys
import bag
from pathfinder import PathFinder
from chemconvert import compound2graph

util._mkdir('../log')
logfile = open('../log/pathcounter.log', 'a')

substrates = []
substrates.append(('Acetyl-CoA', range(1,4)))
substrates.append(('Phosphoenolpyruvate', range(1,4)))
substrates.append(('Pyruvate', range(1,4)))
substrates.append(('D-Glyceraldehyde-3P', range(1,4)))
substrates.append(('3-Phosphoglycerate', range(1,4)))
substrates.append(('oxaloacetate', range(1,4)))
substrates.append(('fumarate', range(1,4)))

pairs = []
pairs.append(('D-fructose-6P_ring', 'D-glucolactone-6P', range(1,5)))
pairs.append(('D-fructose-6P', 'D-ribose-5P', range(1,5)))
pairs.append(('D-Glyceraldehyde-3P', '3-Phosphoglycerate', range(1,5)))
pairs.append(('3-Phosphoglycerate', 'Phosphoenolpyruvate', range(1,5)))
pairs.append(('fumarate', 'oxaloacetate', range(1,5)))