Example #1
0
 def add_species_to_model(self, reagent):
     if reagent not in self.seen_reagents:
         species = self.model.createSpecies()
         name = ExpandGraph.node_name(self.graph, reagent)
         name = self.replace_non_alphanumeric_with_underscore(name)
         SBMLGenerator.check(species.setId(name), 'set species id')
         self.seen_reagents.add(reagent)
Example #2
0
 def add_reaction(self, reaction):
     _, _, reversibility = reaction
     current_reaction = self.model.createReaction()
     reaction_name = ExpandGraph.human_readable_reaction(self.graph, reaction)
     reaction_name = self.replace_non_alphanumeric_with_underscore(reaction_name)
     SBMLGenerator.check(current_reaction.setId(reaction_name), 'set reaction id')
     SBMLGenerator.check(current_reaction.setReversible(reversibility), 'set reaction reversibility flag')
     return current_reaction
    def test_generate_empty_stoichiometric_matrix_size_43(self):
        g = nx.DiGraph()
        g.add_nodes_from([1, 2, 3, 4])
        g.add_edge(1, 2)

        n_of_rows = len(g.nodes())
        n_of_columns = 3 * len(g.edges())
        lead = ExpandGraph.generate_empty_stoichiometric_matrix(
            n_of_rows, n_of_columns)
        gold = [[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]]
        assert lead == gold
Example #4
0
def export_efm_human_readable():
    with open('result/EFM_human.txt', 'w') as f:
        f.write("Total number of EFMs: {}\n".format(len(r.result)))
        for i, efms in enumerate(r.result, start=1):
            f.write('EFM #{}\n'.format(str(i)))
            for index, reaction in enumerate(efms):
                if reaction == 1:
                    f.write('{}\n'.format(
                        ExpandGraph.human_readable_reaction(
                            expanded_graph.graph,
                            expanded_graph.reactions[index])))
            f.write('\n')
Example #5
0
 def add_species_to_reaction(self, reagent, reaction_reference):
     name = ExpandGraph.node_name(self.graph, reagent)
     name = GenerateSBML.replace_non_alphanumeric_with_underscore(name)
     SBMLGenerator.check(reaction_reference.setSpecies(name), 'assign species')
 def test_generate_empty_stoichiometric_matrix_size_00(self):
     lead = ExpandGraph.generate_empty_stoichiometric_matrix(0, 0)
     gold = list()
     assert lead == gold
 def test_generate_empty_stoichiometric_matrix_size_11(self):
     lead = ExpandGraph.generate_empty_stoichiometric_matrix(1, 1)
     gold = [[0]]
     assert lead == gold
Example #8
0
                    f.write(str(expanded_graph.reactions[index]))
                    f.write('\n')
            f.write('\n')


def export_sbml(graph, reactions):
    document = GenerateSBML(graph, reactions=reactions).generate_sbml()
    with open('result/stoichiometric_matrix_in_SBML.xml', "w") as f:
        f.write(SBMLGenerator.convert_to_xml(document=document))


if __name__ == '__main__':
    parser = pars()
    args = parser.parse_args()
    graph = GraphReader(args.edge_list).create_graph()
    expanded_graph = ExpandGraph(graph)
    print("I've deleted rows %s with all zeroes" %
          expanded_graph.deleted_rows_count)

    export_stoichiometric_matrix()
    export_reactions_human_readable()
    # feed stoichiometric matrix and reaction vector to EFM Sampler
    r = Sampler(expanded_graph.matrix, expanded_graph.vector)

    nx.write_graphml(graph, "result/imported_graph.graphml")
    nx.write_graphml(expanded_graph.graph, "result/expanded_graph.graphml")
    export_sbml(expanded_graph.graph, expanded_graph.reactions)
    export_efm_human_readable()
    export_efm_reaction_numbers()

    # print expanded_graph.vector