summaryrefslogtreecommitdiff
path: root/examples/python/fbc/print_gene_product_association.py
blob: fb98c7fef2d593e9a9d7fd4bdc9aaafa0909896c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/python3
import libsbml
import sys


def print_gene_product_association(file_name):
    doc = libsbml.readSBMLFromFile(file_name)
    assert (isinstance(doc, libsbml.SBMLDocument))

    if doc.getNumErrors(libsbml.LIBSBML_SEV_ERROR) > 0:
        print("There were errors while reading, better to fix those first")
        doc.printErrors()
        sys.exit(1)

    model = doc.getModel()
    if model is None:
        print("document has no model, bailing")

    num_reactions = model.getNumReactions()
    print("      Model: %s" % model.getName())
    print("# reactions: %d" % num_reactions)

    for reaction in model.getListOfReactions():
        print(" Reaction: %s" % reaction.getId())
        plugin = reaction.getPlugin('fbc')
        if plugin is None:
            # not relevant for us
            continue

        if not plugin.isSetGeneProductAssociation():
            continue

        gpa = plugin.getGeneProductAssociation()

        association = gpa.getAssociation()
        print ("    Association: %s" % association.toInfix())

    print("done")


if __name__ == "__main__":
    argc = len(sys.argv)
    model_file = 'iJO1366.xml.gz'
    if argc > 1:
        model_file = sys.argv[1]
    print_gene_product_association(model_file)