libSBML Python API  5.18.0
addingEvidenceCodes_1.py

Adds controlled vocabulary terms to a reaction in a model.

1 #!/usr/bin/env python
2 ##
3 ## \file addingEvidenceCodes_1.py
4 ## \brief adds controlled vocabulary terms to a reaction in a model
5 ## \author Sarah Keating
6 ##
7 ## <!--------------------------------------------------------------------------
8 ## This sample program is distributed under a different license than the rest
9 ## of libSBML. This program uses the open-source MIT license, as follows:
10 ##
11 ## Copyright (c) 2013-2018 by the California Institute of Technology
12 ## (California, USA), the European Bioinformatics Institute (EMBL-EBI, UK)
13 ## and the University of Heidelberg (Germany), with support from the National
14 ## Institutes of Health (USA) under grant R01GM070923. All rights reserved.
15 ##
16 ## Permission is hereby granted, free of charge, to any person obtaining a
17 ## copy of this software and associated documentation files (the "Software"),
18 ## to deal in the Software without restriction, including without limitation
19 ## the rights to use, copy, modify, merge, publish, distribute, sublicense,
20 ## and/or sell copies of the Software, and to permit persons to whom the
21 ## Software is furnished to do so, subject to the following conditions:
22 ##
23 ## The above copyright notice and this permission notice shall be included in
24 ## all copies or substantial portions of the Software.
25 ##
26 ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27 ## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28 ## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
29 ## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30 ## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
31 ## FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
32 ## DEALINGS IN THE SOFTWARE.
33 ##
34 ## Neither the name of the California Institute of Technology (Caltech), nor
35 ## of the European Bioinformatics Institute (EMBL-EBI), nor of the University
36 ## of Heidelberg, nor the names of any contributors, may be used to endorse
37 ## or promote products derived from this software without specific prior
38 ## written permission.
39 ## ------------------------------------------------------------------------ -->
40 
41 import sys
42 import os.path
43 from libsbml import *
44 
45 def main (args):
46  """usage: addingEvidenceCodes_1 <input-filename> <output-filename>
47  Adds controlled vocabulary term to a reaction
48  """
49  if len(args) != 3:
50  print(main.__doc__)
51  sys.exit(2)
52 
53  d = readSBML(args[1])
54  errors = d.getNumErrors()
55 
56  if errors > 0:
57  print("Read Error(s):\n")
58  d.printErrors()
59 
60  print("Correct the above and re-run.\n")
61  else:
62  n = d.getModel().getNumReactions()
63 
64  if n <= 0:
65  print("Model has no reactions.\n Cannot add CV terms\n")
66  else:
67  r = d.getModel().getReaction(0)
68 
69  # check that the reaction has a metaid
70  # no CVTerms will be added if there is no metaid to reference
71  #
72  if not r.isSetMetaId():
73  r.setMetaId("metaid_0000052")
74 
75  cv1 = CVTerm(BIOLOGICAL_QUALIFIER)
76  cv1.setBiologicalQualifierType(BQB_IS_DESCRIBED_BY)
77  cv1.addResource("urn:miriam:obo.eco:ECO%3A0000183")
78 
79  r.addCVTerm(cv1)
80 
81  cv2 = CVTerm(BIOLOGICAL_QUALIFIER)
82  cv2.setBiologicalQualifierType(BQB_IS)
83  cv2.addResource("urn:miriam:kegg.reaction:R00756")
84  cv2.addResource("urn:miriam:reactome:REACT_736")
85 
86  r.addCVTerm(cv2)
87 
88  writeSBML(d, args[2])
89  return errors
90 
91 
92 if __name__ == '__main__':
93  main(sys.argv)