def GetReactionString(self, r, show_cids=False):
     rid = self.rids[r]
     sparse = dict([(self.cids[c], self.S[c, r])
                    for c in self.S[:, r].nonzero()[0].flat])
     if self.fluxes[0, r] >= 0:
         direction = '=>'
     else:
         direction = '<='
     reaction = Reaction(self.kegg.rid2string(rid), sparse, rid=rid,
                         direction=direction)
     return reaction.to_hypertext(show_cids=show_cids)
Exemple #2
0
 def GetReactionString(self, r, show_cids=False):
     rid = self.rids[r]
     sparse = dict([(self.cids[c], self.S[c, r])
                    for c in self.S[:, r].nonzero()[0].flat])
     if self.fluxes[0, r] >= 0:
         direction = '=>'
     else:
         direction = '<='
     reaction = Reaction(self.kegg.rid2string(rid), sparse, rid=rid,
                         direction=direction)
     return reaction.to_hypertext(show_cids=show_cids)
def stoichiometric_matrix2html(html_writer, A, cids, eps=1e-10):
    """
        Print a table in HTML format.
        A is a stoichiometric matrix where each row is a reaction and 
        each column is a compound, corresponding in position to the list "cids".
    """
    dict_list = []
    for i in xrange(A.shape[0]):
        sparse_reaction = dict([(cids[j], A[i, j]) for j in xrange(A.shape[1]) if abs(A[i, j]) > eps])
        r = Reaction("reaction%d" % i, sparse_reaction=sparse_reaction)
        dict_list.append({"reaction": r.to_hypertext()})
    html_writer.write_ul(
        ["%d rows" % A.shape[0], "%d columns" % A.shape[1], "%d rank" % LinearRegression.MatrixRank(A)]
    )
    html_writer.write_table(dict_list, headers=["#", "reaction"])
Exemple #4
0
def stoichiometric_matrix2html(html_writer, A, cids, eps=1e-10):
    """
        Print a table in HTML format.
        A is a stoichiometric matrix where each row is a reaction and 
        each column is a compound, corresponding in position to the list "cids".
    """
    dict_list = []
    for i in xrange(A.shape[0]):
        sparse_reaction = dict([(cids[j], A[i, j]) for j in xrange(A.shape[1])
                                if abs(A[i, j]) > eps])
        r = Reaction("reaction%d" % i, sparse_reaction=sparse_reaction)
        dict_list.append({'reaction': r.to_hypertext()})
    html_writer.write_ul([
        '%d rows' % A.shape[0],
        '%d columns' % A.shape[1],
        '%d rank' % LinearRegression.MatrixRank(A)
    ])
    html_writer.write_table(dict_list, headers=['#', 'reaction'])
 def GetTotalReactionString(self, show_cids=False):
     total_S = self.S * self.fluxes.T
     sparse = dict([(self.cids[c], total_S[c, 0])
                    for c in total_S.nonzero()[0].flat])
     reaction = Reaction("Total", sparse, direction="=>")
     return reaction.to_hypertext(show_cids=show_cids)
Exemple #6
0
 def GetTotalReactionString(self, show_cids=False):
     total_S = self.S * self.fluxes.T
     sparse = dict([(self.cids[c], total_S[c, 0])
                    for c in total_S.nonzero()[0].flat])
     reaction = Reaction("Total", sparse, direction="=>")
     return reaction.to_hypertext(show_cids=show_cids)
Exemple #7
0
    def write_current_solution(self, exp_html, lp, experiment_name,
                               output_kegg_file=None):
        solution = lp.get_active_reaction_data()
        solution_id = '%03d' % lp.solution_index
        
        exp_html.write('%d reactions, flux = %g, \n' %
                       (len(solution.reactions),
                        float(solution.fluxes.sum(1))))

        # draw network as a graph and link to it
        Gdot = self.kegg_pathologic.draw_pathway(solution.reactions,
                                                 list(solution.fluxes.flat))
        svg_fname = '%s/%s_graph' % (experiment_name, solution_id)
        exp_html.embed_dot_inline(Gdot, width=240, height=320, name=svg_fname)

        # write the solution for the concentrations in a table
        if solution.concentrations is not None:
            exp_html.insert_toggle(start_here=True)
            
            rowdicts = []
            for c, compound in enumerate(solution.compounds):
                rowdict = {}
                rowdict['KEGG ID'] = '<a href="%s">C%05d</a>' % (compound.get_link(), compound.cid)
                rowdict['Compound'] = compound.name
                rowdict[symbol_df_G0_prime + "[kJ/mol]"] = solution.dG0_f[0, c]
                rowdict[symbol_df_G_prime + "[kJ/mol]"] = solution.dG_f[0, c]

                if np.isfinite(solution.concentrations[0, c]):
                    rowdict['Conc. [M]'] = '%.1e' % solution.concentrations[0, c]
                else:
                    rowdict['Conc. [M]'] = 'N/A'
                rowdicts.append(rowdict)
            
            headers=['KEGG ID', 'Compound', symbol_df_G0_prime + "[kJ/mol]",
                     symbol_df_G_prime + "[kJ/mol]", 'Conc. [M]']
            exp_html.write('Compound Concentrations<br>\n')
            exp_html.write_table(rowdicts, headers, decimal=1)

            total_reaction = Reaction('total', {})
            rowdicts = []
            for r, reaction in enumerate(solution.reactions):
                rowdict = {}
                flux = solution.fluxes[0, r]
                rowdict['KEGG ID'] = '<a href="%s">R%05d</a>' % (reaction.get_link(), reaction.rid)
                rowdict['Reaction'] = reaction.to_hypertext(show_cids=False)
                rowdict['Flux'] = flux
                rowdict[symbol_dr_Gc_prime + "[kJ/mol]"] = solution.dGc_r[0, r]
                rowdict[symbol_dr_G_prime + "[kJ/mol]"] = solution.dG_r[0, r]
                rowdicts.append(rowdict)
                total_reaction += (flux * reaction)
            
            rowdict = {}
            rowdict['KEGG ID'] = 'total'
            rowdict['Reaction'] = total_reaction.to_hypertext(show_cids=False)
            rowdict[symbol_dr_Gc_prime + "[kJ/mol]"] = float(solution.dGc_r.sum(1))
            rowdict[symbol_dr_G_prime + "[kJ/mol]"] = float(solution.dG_r.sum(1))
            rowdicts.append(rowdict)
            
            headers=['KEGG ID', 'Reaction', symbol_dr_Gc_prime + "[kJ/mol]",
                     symbol_dr_G_prime + "[kJ/mol]", "Flux"]
            exp_html.write('Reaction Gibbs energies<br>\n')
            exp_html.write_table(rowdicts, headers, decimal=1)

            exp_html.div_end()

        # write the pathway in KEGG format
        if output_kegg_file is not None:
            write_kegg_pathway(output_kegg_file,
                               entry=experiment_name + ' ' + solution_id,
                               reactions=solution.reactions,
                               fluxes=list(solution.fluxes.flat))
            
        exp_html.write('<br>\n')