libSBML Python API  5.18.0
appendAnnotation.py

Adds annotation strings to a model and a species.

1 #!/usr/bin/env python
2 ##
3 ## \file appendAnnotation.py
4 ## \brief adds annotation strings to a model and a species
5 ## \author Akiya Jouraku
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 
46 def main(args):
47  """usage: appendAnnotation <input-filename> <output-filename>
48  Adds annotations
49  """
50  if len(args) != 3:
51  print(main.__doc__)
52  sys.exit(2)
53 
54  d = readSBML(args[1])
55  errors = d.getNumErrors()
56 
57  if errors > 0:
58  print("Read Error(s):")
59  d.printErrors()
60 
61  print("Correct the above and re-run.")
62  else:
63  model_history_annotation = """<annotation>
64  <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:vCard="http://www.w3.org/2001/vcard-rdf/3.0#" xmlns:bqbiol="http://biomodels.net/biology-qualifiers/" xmlns:bqmodel="http://biomodels.net/model-qualifiers/">
65  <rdf:Description rdf:about="#">
66  <dc:creator rdf:parseType="Resource">
67  <rdf:Bag>
68  <rdf:li rdf:parseType="Resource">
69  <vCard:N rdf:parseType="Resource">
70  <vCard:Family>Keating</vCard:Family>
71  <vCard:Given>Sarah</vCard:Given>
72  </vCard:N>
73  <vCard:EMAIL>sbml-team@caltech.edu</vCard:EMAIL>
74  <vCard:ORG>
75  <vCard:Orgname>University of Hertfordshire</vCard:Orgname>
76  </vCard:ORG>
77  </rdf:li>
78  </rdf:Bag>
79  </dc:creator>
80  <dcterms:created rdf:parseType="Resource">
81  <dcterms:W3CDTF>1999-11-13T06:54:32Z</dcterms:W3CDTF>
82  </dcterms:created>
83  <dcterms:modified rdf:parseType="Resource">
84  <dcterms:W3CDTF>2007-11-31T06:54:00-02:00</dcterms:W3CDTF>
85  </dcterms:modified>
86  </rdf:Description>
87  </rdf:RDF>
88  </annotation>
89  """
90  d.getModel().appendAnnotation(model_history_annotation)
91 
92  #
93  # The above code can be replaced by the following code.
94  #
95  #
96  # ModelHistory * h = ModelHistory();
97  #
98  # ModelCreator *c = ModelCreator();
99  # c.setFamilyName("Keating");
100  # c.setGivenName("Sarah");
101  # c.setEmail("sbml-team@caltech.edu");
102  # c.setOrganisation("University of Hertfordshire");
103  #
104  # h.addCreator(c);
105  #
106  # Date * date = Date("1999-11-13T06:54:32");
107  # Date * date2 = Date("2007-11-31T06:54:00-02:00");
108  #
109  # h.setCreatedDate(date);
110  # h.setModifiedDate(date2);
111  #
112  # d.getModel().setModelHistory(h);
113  #
114  #
115  #
116 
117 
118  n = d.getModel().getNumSpecies()
119 
120  if n > 0:
121  s = d.getModel().getSpecies(0)
122 
123  cvterms_annotation = """<annotation>
124  <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:vCard="http://www.w3.org/2001/vcard-rdf/3.0#" xmlns:bqbiol="http://biomodels.net/biology-qualifiers/" xmlns:bqmodel="http://biomodels.net/model-qualifiers/">
125  <rdf:Description rdf:about="#">
126  <bqbiol:isVersionOf>
127  <rdf:Bag>
128  <rdf:li rdf:resource="http://www.geneontology.org/#GO:0005892"/>
129  <rdf:li rdf:resource="http://www.ebi.ac.uk/interpro/#IPR002394"/>
130  </rdf:Bag>
131  </bqbiol:isVersionOf>
132  <bqbiol:is>
133  <rdf:Bag>
134  <rdf:li rdf:resource="http://www.geneontology.org/#GO:0005895"/>
135  </rdf:Bag>
136  </bqbiol:is>
137  </rdf:Description>
138  </rdf:RDF>
139  </annotation>
140  """
141 
142  s.appendAnnotation(cvterms_annotation)
143 
144  #
145  # The above code can be replaced by the following code.
146  #
147  #
148  # CVTerm *cv = CVTerm();
149  # cv.setQualifierType(BIOLOGICAL_QUALIFIER);
150  # cv.setBiologicalQualifierType(BQB_IS_VERSION_OF);
151  # cv.addResource("http://www.geneontology.org/#GO:0005892");
152  #
153  # CVTerm *cv2 = CVTerm();
154  # cv2.setQualifierType(BIOLOGICAL_QUALIFIER);
155  # cv2.setBiologicalQualifierType(BQB_IS);
156  # cv2.addResource("http://www.geneontology.org/#GO:0005895");
157  #
158  # CVTerm *cv1 = CVTerm();
159  # cv1.setQualifierType(BIOLOGICAL_QUALIFIER);
160  # cv1.setBiologicalQualifierType(BQB_IS_VERSION_OF);
161  # cv1.addResource("http://www.ebi.ac.uk/interpro/#IPR002394");
162  #
163  # s.addCVTerm(cv);
164  # s.addCVTerm(cv2);
165  # s.addCVTerm(cv1);
166  #
167  #
168  #
169 
170  writeSBML(d, args[2])
171  return errors
172 
173 
174 if __name__ == '__main__':
175  main(sys.argv)