libSBML Python API  5.11.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-2014 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: appendAnnotation <input-filename> <output-filename>
47  Adds annotatons
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):" + Environment.NewLine);
58  d.printErrors();
59 
60  print("Correct the above and re-run." + Environment.NewLine);
61  else:
62  model_history_annotation = """<annotation>
63  <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/">
64  <rdf:Description rdf:about="#">
65  <dc:creator rdf:parseType="Resource">
66  <rdf:Bag>
67  <rdf:li rdf:parseType="Resource">
68  <vCard:N rdf:parseType="Resource">
69  <vCard:Family>Keating</vCard:Family>
70  <vCard:Given>Sarah</vCard:Given>
71  </vCard:N>
72  <vCard:EMAIL>sbml-team@caltech.edu</vCard:EMAIL>
73  <vCard:ORG>
74  <vCard:Orgname>University of Hertfordshire</vCard:Orgname>
75  </vCard:ORG>
76  </rdf:li>
77  </rdf:Bag>
78  </dc:creator>
79  <dcterms:created rdf:parseType="Resource">
80  <dcterms:W3CDTF>1999-11-13T06:54:32Z</dcterms:W3CDTF>
81  </dcterms:created>
82  <dcterms:modified rdf:parseType="Resource">
83  <dcterms:W3CDTF>2007-11-31T06:54:00-02:00</dcterms:W3CDTF>
84  </dcterms:modified>
85  </rdf:Description>
86  </rdf:RDF>
87  </annotation>
88  """
89  d.getModel().appendAnnotation(model_history_annotation);
90 
91  #
92  # The above code can be replaced by the following code.
93  #
94  #
95  # ModelHistory * h = ModelHistory();
96  #
97  # ModelCreator *c = ModelCreator();
98  # c.setFamilyName("Keating");
99  # c.setGivenName("Sarah");
100  # c.setEmail("sbml-team@caltech.edu");
101  # c.setOrganisation("University of Hertfordshire");
102  #
103  # h.addCreator(c);
104  #
105  # Date * date = Date("1999-11-13T06:54:32");
106  # Date * date2 = Date("2007-11-31T06:54:00-02:00");
107  #
108  # h.setCreatedDate(date);
109  # h.setModifiedDate(date2);
110  #
111  # d.getModel().setModelHistory(h);
112  #
113  #
114  #
115 
116 
117  n = d.getModel().getNumSpecies();
118 
119  if (n > 0):
120  s = d.getModel().getSpecies(0);
121 
122  cvterms_annotation = """<annotation>
123  <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/">
124  <rdf:Description rdf:about="#">
125  <bqbiol:isVersionOf>
126  <rdf:Bag>
127  <rdf:li rdf:resource="http://www.geneontology.org/#GO:0005892"/>
128  <rdf:li rdf:resource="http://www.ebi.ac.uk/interpro/#IPR002394"/>
129  </rdf:Bag>
130  </bqbiol:isVersionOf>
131  <bqbiol:is>
132  <rdf:Bag>
133  <rdf:li rdf:resource="http://www.geneontology.org/#GO:0005895"/>
134  </rdf:Bag>
135  </bqbiol:is>
136  </rdf:Description>
137  </rdf:RDF>
138  </annotation>
139  """
140 
141  s.appendAnnotation(cvterms_annotation);
142 
143  #
144  # The above code can be replaced by the following code.
145  #
146  #
147  # CVTerm *cv = CVTerm();
148  # cv.setQualifierType(BIOLOGICAL_QUALIFIER);
149  # cv.setBiologicalQualifierType(BQB_IS_VERSION_OF);
150  # cv.addResource("http://www.geneontology.org/#GO:0005892");
151  #
152  # CVTerm *cv2 = CVTerm();
153  # cv2.setQualifierType(BIOLOGICAL_QUALIFIER);
154  # cv2.setBiologicalQualifierType(BQB_IS);
155  # cv2.addResource("http://www.geneontology.org/#GO:0005895");
156  #
157  # CVTerm *cv1 = CVTerm();
158  # cv1.setQualifierType(BIOLOGICAL_QUALIFIER);
159  # cv1.setBiologicalQualifierType(BQB_IS_VERSION_OF);
160  # cv1.addResource("http://www.ebi.ac.uk/interpro/#IPR002394");
161  #
162  # s.addCVTerm(cv);
163  # s.addCVTerm(cv2);
164  # s.addCVTerm(cv1);
165  #
166  #
167  #
168 
169  writeSBML(d, args[2]);
170  return errors;
171 
172 
173 if __name__ == '__main__':
174  main(sys.argv)