1#!/usr/bin/env perl
2# -*-Perl-*-
3##
4## \file    appendAnnotation.pl
5## \brief   adds annotation strings to a model and a species
6## \author  Akiya Jouraku
7##
8## <!--------------------------------------------------------------------------
9## This sample program is distributed under a different license than the rest
10## of libSBML.  This program uses the open-source MIT license, as follows:
11##
12## Copyright (c) 2013-2018 by the California Institute of Technology
13## (California, USA), the European Bioinformatics Institute (EMBL-EBI, UK)
14## and the University of Heidelberg (Germany), with support from the National
15## Institutes of Health (USA) under grant R01GM070923.  All rights reserved.
16##
17## Permission is hereby granted, free of charge, to any person obtaining a
18## copy of this software and associated documentation files (the "Software"),
19## to deal in the Software without restriction, including without limitation
20## the rights to use, copy, modify, merge, publish, distribute, sublicense,
21## and/or sell copies of the Software, and to permit persons to whom the
22## Software is furnished to do so, subject to the following conditions:
23##
24## The above copyright notice and this permission notice shall be included in
25## all copies or substantial portions of the Software.
26##
27## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
30## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
31## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
32## FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
33## DEALINGS IN THE SOFTWARE.
34##
35## Neither the name of the California Institute of Technology (Caltech), nor
36## of the European Bioinformatics Institute (EMBL-EBI), nor of the University
37## of Heidelberg, nor the names of any contributors, may be used to endorse
38## or promote products derived from this software without specific prior
39## written permission.
40## ------------------------------------------------------------------------ -->
41##
42
43
44use LibSBML;
45no strict;
46
47if ($#ARGV != 1){
48  print "usage: appendAnnotation <input-filename> <output-filename>\n";
49  print "       Adds annotatons\n";
50  exit 2;
51}
52
53$d = LibSBML::readSBML($ARGV[0]);
54$errors = $d->getNumErrors();
55
56if (errors > 0) {
57    print("Read Error(s):\n");
58    $d->printErrors();
59    print("Correct the above and re-run.\n");
60	exit $errors;
61}
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
119if ($n <= 0) {
120  print "No Species found, cannot attach annotation. Please load a model including species.\n";
121  exit 0;
122}
123
124$s = $d->getModel()->getSpecies(0);
125
126$cvterms_annotation = '<annotation>
127<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/">
128  <rdf:Description rdf:about="#">
129    <bqbiol:isVersionOf>
130      <rdf:Bag>
131        <rdf:li rdf:resource="http://www.geneontology.org/#GO:0005892"/>
132        <rdf:li rdf:resource="http://www.ebi.ac.uk/interpro/#IPR002394"/>
133      </rdf:Bag>
134    </bqbiol:isVersionOf>
135    <bqbiol:is>
136      <rdf:Bag>
137        <rdf:li rdf:resource="http://www.geneontology.org/#GO:0005895"/>
138      </rdf:Bag>
139    </bqbiol:is>
140  </rdf:Description>
141</rdf:RDF>
142</annotation>';
143
144  $s->appendAnnotation($cvterms_annotation);
145}
146
147#
148# The above code can be replaced by the following code.
149#
150#
151# CVTerm *cv = CVTerm();
152# cv.setQualifierType(BIOLOGICAL_QUALIFIER);
153# cv.setBiologicalQualifierType(BQB_IS_VERSION_OF);
154# cv.addResource("http://www.geneontology.org/#GO:0005892");
155#
156# CVTerm *cv2 = CVTerm();
157# cv2.setQualifierType(BIOLOGICAL_QUALIFIER);
158# cv2.setBiologicalQualifierType(BQB_IS);
159# cv2.addResource("http://www.geneontology.org/#GO:0005895");
160#
161# CVTerm *cv1 = CVTerm();
162# cv1.setQualifierType(BIOLOGICAL_QUALIFIER);
163# cv1.setBiologicalQualifierType(BQB_IS_VERSION_OF);
164# cv1.addResource("http://www.ebi.ac.uk/interpro/#IPR002394");
165#
166# s.addCVTerm(cv);
167# s.addCVTerm(cv2);
168# s.addCVTerm(cv1);
169#
170#
171#
172
173LibSBML::writeSBML($d, $ARGV[1]);
174exit $errors;
175
176