1 /**
2  * \file    appendAnnotation.cpp
3  * \brief   adds annotation strings to a model and a species
4  * \author  Akiya Jouraku
5  *
6  * <!--------------------------------------------------------------------------
7  * This sample program is distributed under a different license than the rest
8  * of libSBML.  This program uses the open-source MIT license, as follows:
9  *
10  * Copyright (c) 2013-2018 by the California Institute of Technology
11  * (California, USA), the European Bioinformatics Institute (EMBL-EBI, UK)
12  * and the University of Heidelberg (Germany), with support from the National
13  * Institutes of Health (USA) under grant R01GM070923.  All rights reserved.
14  *
15  * Permission is hereby granted, free of charge, to any person obtaining a
16  * copy of this software and associated documentation files (the "Software"),
17  * to deal in the Software without restriction, including without limitation
18  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
19  * and/or sell copies of the Software, and to permit persons to whom the
20  * Software is furnished to do so, subject to the following conditions:
21  *
22  * The above copyright notice and this permission notice shall be included in
23  * all copies or substantial portions of the Software.
24  *
25  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
28  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
30  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
31  * DEALINGS IN THE SOFTWARE.
32  *
33  * Neither the name of the California Institute of Technology (Caltech), nor
34  * of the European Bioinformatics Institute (EMBL-EBI), nor of the University
35  * of Heidelberg, nor the names of any contributors, may be used to endorse
36  * or promote products derived from this software without specific prior
37  * written permission.
38  * ------------------------------------------------------------------------ -->
39  */
40 
41 #include <iostream>
42 #include <sbml/SBMLTypes.h>
43 
44 #include <sbml/xml/XMLNode.h>
45 #include <sbml/annotation/CVTerm.h>
46 #include <sbml/annotation/ModelHistory.h>
47 using namespace std;
48 LIBSBML_CPP_NAMESPACE_USE
49 
50 int
main(int argc,char * argv[])51 main (int argc, char *argv[])
52 {
53 
54   SBMLDocument* d;
55   unsigned int  errors;
56 
57   if (argc != 3)
58   {
59     cout << endl
60          << "  usage: appendAnnotation <input-filename> <output-filename>" << endl
61          << endl;
62     return 2;
63   }
64 
65 
66   d      = readSBML(argv[1]);
67   errors = d->getNumErrors();
68 
69   if (errors > 0)
70   {
71     cout << "Read Error(s):" << endl;
72 	  d->printErrors(cout);
73 
74     cout << "Correct the above and re-run." << endl;
75   }
76   else
77   {
78     int n;
79     Species_t* s;
80 
81     const string model_history_annotation =
82        "<annotation>\n"
83        "  <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/\">\n"
84        "    <rdf:Description rdf:about=\"#\">\n"
85        "      <dc:creator rdf:parseType=\"Resource\">\n"
86        "        <rdf:Bag>\n"
87        "          <rdf:li rdf:parseType=\"Resource\">\n"
88        "            <vCard:N rdf:parseType=\"Resource\">\n"
89        "              <vCard:Family>Keating</vCard:Family>\n"
90        "              <vCard:Given>Sarah</vCard:Given>\n"
91        "            </vCard:N>\n"
92        "            <vCard:EMAIL>sbml-team@caltech.edu</vCard:EMAIL>\n"
93        "            <vCard:ORG>\n"
94        "              <vCard:Orgname>University of Hertfordshire</vCard:Orgname>\n"
95        "            </vCard:ORG>\n"
96        "          </rdf:li>\n"
97        "        </rdf:Bag>\n"
98        "      </dc:creator>\n"
99        "      <dcterms:created rdf:parseType=\"Resource\">\n"
100        "        <dcterms:W3CDTF>1999-11-13T06:54:32Z</dcterms:W3CDTF>\n"
101        "      </dcterms:created>\n"
102        "      <dcterms:modified rdf:parseType=\"Resource\">\n"
103        "        <dcterms:W3CDTF>2007-11-31T06:54:00-02:00</dcterms:W3CDTF>\n"
104        "      </dcterms:modified>\n"
105        "    </rdf:Description>\n"
106        "  </rdf:RDF>\n"
107        "</annotation>\n";
108 
109     d->getModel()->appendAnnotation(model_history_annotation);
110 
111     /*
112      * The above code can be replaced by the following code.
113      *
114 
115        ModelHistory * h = new ModelHistory();
116 
117        ModelCreator *c = new ModelCreator();
118        c->setFamilyName("Keating");
119        c->setGivenName("Sarah");
120        c->setEmail("sbml-team@caltech.edu");
121        c->setOrganisation("University of Hertfordshire");
122 
123        h->addCreator(c);
124 
125        Date * date = new Date("1999-11-13T06:54:32");
126        Date * date2 = new Date("2007-11-31T06:54:00-02:00");
127 
128        h->setCreatedDate(date);
129        h->setModifiedDate(date2);
130 
131        d->getModel()->setModelHistory(h);
132 
133       *
134       */
135 
136 
137     n = d->getModel()->getNumSpecies();
138 
139     if (n > 0)
140     {
141       s = d->getModel()->getSpecies(0);
142 
143       const string cvterms_annotation =
144         "<annotation>\n"
145         "  <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/\">\n"
146         "    <rdf:Description rdf:about=\"#\">\n"
147         "      <bqbiol:isVersionOf>\n"
148         "        <rdf:Bag>\n"
149         "          <rdf:li rdf:resource=\"http://www.geneontology.org/#GO:0005892\"/>\n"
150         "          <rdf:li rdf:resource=\"http://www.ebi.ac.uk/interpro/#IPR002394\"/>\n"
151         "        </rdf:Bag>\n"
152         "      </bqbiol:isVersionOf>\n"
153         "      <bqbiol:is>\n"
154         "        <rdf:Bag>\n"
155         "          <rdf:li rdf:resource=\"http://www.geneontology.org/#GO:0005895\"/>\n"
156         "        </rdf:Bag>\n"
157         "      </bqbiol:is>\n"
158         "    </rdf:Description>\n"
159         "  </rdf:RDF>\n"
160         "</annotation>\n";
161 
162       s->appendAnnotation(cvterms_annotation);
163 
164       /*
165        * The above code can be replaced by the following code.
166        *
167 
168          CVTerm *cv = new CVTerm();
169          cv->setQualifierType(BIOLOGICAL_QUALIFIER);
170          cv->setBiologicalQualifierType(BQB_IS_VERSION_OF);
171          cv->addResource("http://www.geneontology.org/#GO:0005892");
172 
173          CVTerm *cv2 = new CVTerm();
174          cv2->setQualifierType(BIOLOGICAL_QUALIFIER);
175          cv2->setBiologicalQualifierType(BQB_IS);
176          cv2->addResource("http://www.geneontology.org/#GO:0005895");
177 
178          CVTerm *cv1 = new CVTerm();
179          cv1->setQualifierType(BIOLOGICAL_QUALIFIER);
180          cv1->setBiologicalQualifierType(BQB_IS_VERSION_OF);
181          cv1->addResource("http://www.ebi.ac.uk/interpro/#IPR002394");
182 
183          s->addCVTerm(cv);
184          s->addCVTerm(cv2);
185          s->addCVTerm(cv1);
186 
187         *
188         */
189     }
190 
191     writeSBML(d, argv[2]);
192   }
193 
194   delete d;
195   return errors;
196 }
197 
198 
199