libSBML C API  libSBML 5.20.2 C API
Loading...
Searching...
No Matches
addingEvidenceCodes_2.c

Adds evidence codes to a species in a model.

Adds evidence codes to a species in a model.

/**
* \file addingEvidenceCodes_2.cpp
* \brief adds evidence codes to a species in a model
* \author Sarah Keating
*
* <!--------------------------------------------------------------------------
* This sample program is distributed under a different license than the rest
* of libSBML. This program uses the open-source MIT license, as follows:
*
* Copyright (c) 2013-2018 by the California Institute of Technology
* (California, USA), the European Bioinformatics Institute (EMBL-EBI, UK)
* and the University of Heidelberg (Germany), with support from the National
* Institutes of Health (USA) under grant R01GM070923. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
* Neither the name of the California Institute of Technology (Caltech), nor
* of the European Bioinformatics Institute (EMBL-EBI), nor of the University
* of Heidelberg, nor the names of any contributors, may be used to endorse
* or promote products derived from this software without specific prior
* written permission.
* ------------------------------------------------------------------------ -->
*/
#include <stdio.h>
#include <sbml/SBMLTypes.h>
int
main (int argc, char *argv[])
{
Model_t* m;
unsigned int errors, n;
if (argc != 3)
{
printf("\n"
" usage: addingEvidenceCodes_2 <input-filename> <output-filename>\n"
" Adds controlled vocabulary term to a species\n"
"\n");
return 2;
}
d = readSBML(argv[1]);
if (errors > 0)
{
printf("Read Error(s):\n");
printf("Correct the above and re-run.\n");
}
else
{
if (n <= 0)
{
printf( "Model has no reactions.\n Cannot add CV terms\n");
}
else
{
CVTerm_t *cv1;
XMLAttributes_t* blank_att;
XMLAttributes_t* resource_att;
XMLTriple_t* statement_triple;
XMLToken_t* statement_token;
XMLNode_t* statement;
XMLTriple_t* subject_triple ;
XMLToken_t* subject_token;
XMLNode_t* subject;
XMLTriple_t* predicate_triple;
XMLToken_t* predicate_token;
XMLNode_t* predicate;
XMLTriple_t* object_triple;
XMLToken_t* object_token;
XMLNode_t* object;
XMLTriple_t* bqbiol_triple;
XMLToken_t* bqbiol_token;
XMLNode_t* bqbiol;
XMLTriple_t* bag_triple;
XMLToken_t* bag_token;
XMLNode_t* bag;
XMLTriple_t* li_triple;
XMLToken_t* li_token;
XMLNode_t* li;
XMLTriple_t* RDF_triple;
XMLToken_t* RDF_token;
XMLNode_t* annotation;
s = Model_getSpecies(m ,0);
/* check that the species has a metaid
* no CVTerms will be added if there is no metaid to reference
*/
SBase_setMetaId((SBase_t*)s, "metaid_0000052");
CVTerm_addResource(cv1, "urn:miriam:obo.go:GO%3A0005764");
// now create the additional annotation
//<rdf:Statement>
// <rdf:subject rdf:resource="#metaid_0000052"/>
// <rdf:predicate rdf:resource="http://biomodels.net/biology-qualifiers/occursIn"/>
// <rdf:object rdf:resource="urn:miriam:obo.go:GO%3A0005764"/>
// <bqbiol:isDescribedBy>
// <rdf:Bag>
// <rdf:li rdf:resource="urn:miriam:obo.eco:ECO%3A0000004"/>
// <rdf:li rdf:resource="urn:miriam:pubmed:7017716"/>
// </rdf:Bag>
// </bqbiol:isDescribedBy>
//</rdf:Statement>
/* attributes */
blank_att = XMLAttributes_create();
resource_att = XMLAttributes_create();
/* create the outer statement node */
statement_triple = XMLTriple_createWith("Statement",
"http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"rdf");
statement_token = XMLToken_createWithTripleAttr (statement_triple, blank_att);
statement = XMLNode_createFromToken (statement_token);
/*create the subject node */
subject_triple = XMLTriple_createWith ("subject",
"http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"rdf");
XMLAttributes_clear(resource_att);
XMLAttributes_add(resource_att, "rdf:resource", SBase_getMetaId((SBase_t*)s));
subject_token = XMLToken_createWithTripleAttr (subject_triple, resource_att);
subject = XMLNode_createFromToken (subject_token);
/*create the predicate node */
predicate_triple = XMLTriple_createWith ("predicate",
"http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"rdf");
XMLAttributes_clear(resource_att);
XMLAttributes_add(resource_att, "rdf:resource",
"http://biomodels.net/biology-qualifiers/occursIn");
predicate_token = XMLToken_createWithTripleAttr (predicate_triple, resource_att);
predicate = XMLNode_createFromToken (predicate_token);
/*create the object node */
object_triple = XMLTriple_createWith("object",
"http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"rdf");
XMLAttributes_clear(resource_att);
XMLAttributes_add(resource_att, "rdf:resource",
"urn:miriam:obo.go:GO%3A0005764");
object_token = XMLToken_createWithTripleAttr(object_triple, resource_att);
object = XMLNode_createFromToken(object_token);
/* create the bqbiol node */
bqbiol_triple = XMLTriple_createWith("isDescribedBy",
"http://biomodels.net/biology-qualifiers/",
"bqbiol");
bqbiol_token = XMLToken_createWithTripleAttr(bqbiol_triple, blank_att);
bqbiol = XMLNode_createFromToken (bqbiol_token);
/* create the bag node */
bag_triple = XMLTriple_createWith("Bag",
"http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"rdf");
bag_token = XMLToken_createWithTripleAttr(bag_triple, blank_att);
bag = XMLNode_createFromToken(bag_token);
/* create each li node and add to the bag */
li_triple = XMLTriple_createWith("li",
"http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"rdf");
XMLAttributes_clear(resource_att);
XMLAttributes_add(resource_att, "rdf:resource",
"urn:miriam:obo.eco:ECO%3A0000004");
li_token = XMLToken_createWithTripleAttr(li_triple, resource_att);
XMLToken_setEnd(li_token);
li = XMLNode_createFromToken(li_token);
XMLNode_addChild(bag, li);
XMLAttributes_clear(resource_att);
XMLAttributes_add(resource_att, "rdf:resource",
"urn:miriam:pubmed:7017716");
XMLToken_free(li_token);
li_token = XMLToken_createWithTripleAttr(li_triple, resource_att);
XMLToken_setEnd(li_token);
li = XMLNode_createFromToken(li_token);
XMLNode_addChild(bag, li);
/* add the bag to bqbiol */
XMLNode_addChild(bqbiol, bag);
/* add subject, predicate, object and bqbiol to statement */
XMLNode_addChild(statement, subject);
XMLNode_addChild(statement, predicate);
XMLNode_addChild(statement, object);
XMLNode_addChild(statement, bqbiol);
/* create a top-level RDF element
* this will ensure correct merging
*/
XMLNamespaces_add(xmlns, "http://www.w3.org/1999/02/22-rdf-syntax-ns#", "rdf");
XMLNamespaces_add(xmlns, "http://purl.org/dc/elements/1.1/", "dc");
XMLNamespaces_add(xmlns, "http://purl.org/dc/terms/", "dcterms");
XMLNamespaces_add(xmlns, "http://www.w3.org/2001/vcard-rdf/3.0#", "vCard");
XMLNamespaces_add(xmlns, "http://biomodels.net/biology-qualifiers/", "bqbiol");
XMLNamespaces_add(xmlns, "http://biomodels.net/model-qualifiers/", "bqmodel");
RDF_triple = XMLTriple_createWith("RDF",
"http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"rdf");
RDF_token = XMLToken_createWithTripleAttrNS(RDF_triple, blank_att, xmlns);
annotation = XMLNode_createFromToken(RDF_token);
/* add the staement node to the RDF node */
XMLNode_addChild(annotation, statement);
SBase_appendAnnotation((SBase_t*)s, annotation);
writeSBML(d, argv[2]);
XMLAttributes_free(blank_att);
XMLAttributes_free(resource_att);
XMLToken_free(RDF_token);
XMLToken_free(li_token);
XMLToken_free(object_token);
XMLToken_free(bag_token);
XMLToken_free(predicate_token);
XMLToken_free(statement_token);
XMLToken_free(subject_token);
XMLToken_free(bqbiol_token);
XMLTriple_free(RDF_triple);
XMLTriple_free(li_triple);
XMLTriple_free(object_triple);
XMLTriple_free(bag_triple);
XMLTriple_free(predicate_triple);
XMLTriple_free(statement_triple);
XMLTriple_free(subject_triple);
XMLTriple_free(bqbiol_triple);
XMLNode_free(object);
XMLNode_free(predicate);
XMLNode_free(statement);
XMLNode_free(subject);
XMLNode_free(bqbiol);
XMLNode_free(annotation);
}
}
return errors;
}
void CVTerm_free(CVTerm_t *term)
_tFrees_t _tthe_t _tgiven_t _tCVTerm_t_t _tstructure_t.
Definition CVTerm.cpp:713
CVTerm_t * CVTerm_createWithQualifierType(QualifierType_t type)
@_tendcond_t
Definition CVTerm.cpp:697
int CVTerm_addResource(CVTerm_t *term, const char *resource)
_tAdds_t _ta_t _tresource_t _tto_t _tthe_t _tCVTerm_t_t.
Definition CVTerm.cpp:829
int CVTerm_setBiologicalQualifierType(CVTerm_t *term, BiolQualifierType_t type)
_tSets_t _tthe_t #_tBiolQualifierType_t_t _tof_t _tthis_t CVTerm_t_t.
Definition CVTerm.cpp:798
Definition of a CVTerm_t class for adding annotations to a Model_t.
@ BQB_OCCURS_IN
Definition CVTerm.h:445
@ BIOLOGICAL_QUALIFIER
Definition CVTerm.h:332
unsigned int Model_getNumSpecies(const Model_t *m)
_tGet_t _tthe_t _tnumber_t _tof_t _tSpecies_t_t _tstructures_t _tin_t _tthe_t _tgiven_t _tModel_t_t _...
Definition Model.cpp:8158
Species_t * Model_getSpecies(Model_t *m, unsigned int n)
_tGet_t _tthe_t _tnth_t _tSpecies_t_t _tstructure_t _tcontained_t _tin_t _tthe_t _tgiven_t _tModel_t_...
Definition Model.cpp:8006
void SBMLDocument_printErrors(SBMLDocument_t *d, FILE *stream)
_tPrints_t _tto_t _tthe_t _tgiven_t _toutput_t _tstream_t _tall_t _tthe_t _terrors_t _tor_t _twarning...
Definition SBMLDocument.cpp:2525
unsigned int SBMLDocument_getNumErrors(const SBMLDocument_t *d)
_tReturns_t _tthe_t _tnumber_t _tof_t _terrors_t _tor_t _twarnings_t _tencountered_t _tduring_t _tpar...
Definition SBMLDocument.cpp:2510
void SBMLDocument_free(SBMLDocument_t *d)
_tFrees_t _tthe_t _tgiven_t _tSBMLDocument_t_t _tstructure_t.
Definition SBMLDocument.cpp:2248
Model_t * SBMLDocument_getModel(SBMLDocument_t *d)
_tReturns_t _tthe_t _tModel_t_t _tstructure_t _tstored_t _tin_t _tthis_t _tSBMLDocument_t_t _tstructu...
Definition SBMLDocument.cpp:2290
SBMLDocument_t * readSBML(const char *filename)
@_tcopydoc_t _tdoc_readsbmlfromfile_t
Definition SBMLReader.cpp:446
Include all SBML types in a single header file.
int writeSBML(const SBMLDocument_t *d, const char *filename)
_tWrites_t _tthe_t _tgiven_t _tSBML_t _tdocument_t @_tp_t _td_t _tto_t _tthe_t _tfile_t _tnamed_t _tb...
Definition SBMLWriter.cpp:440
int SBase_appendAnnotation(SBase_t *sb, const XMLNode_t *annotation)
_tAppends_t _tthe_t _tannotation_t _tfor_t _tthe_t _tgiven_t _tSBML_t _tstructure_t.
Definition SBase.cpp:7820
const char * SBase_getMetaId(SBase_t *sb)
_tReturns_t _tthe_t _tvalue_t _tof_t _tthe_t "_tmetaid_t" _tattribute_t _tof_t _tthe_t _tgiven_t _tSB...
Definition SBase.cpp:7473
int SBase_setMetaId(SBase_t *sb, const char *metaid)
_tSets_t _tthe_t _tvalue_t _tof_t _tthe_t "_tmetaid_t" _tattribute_t _tof_t _tthe_t _tgiven_t _tstruc...
Definition SBase.cpp:7645
int SBase_isSetMetaId(const SBase_t *sb)
_tPredicate_t _treturning_t @_tc_t _t1_t (_ttrue_t) _tor_t @_tc_t _t0_t (_tfalse_t) _tdepending_t _to...
Definition SBase.cpp:7597
int SBase_addCVTerm(SBase_t *sb, CVTerm_t *term)
@_tendcond_t
Definition SBase.cpp:7373
LIBLAX_EXTERN void XMLAttributes_free(XMLAttributes_t *xa)
_tFrees_t _tthe_t _tgiven_t _tXMLAttributes_t_t _tstructure_t.
Definition XMLAttributes.cpp:1284
LIBLAX_EXTERN int XMLAttributes_add(XMLAttributes_t *xa, const char *name, const char *value)
_tAdds_t _ta_t _tname_t/_tvalue_t _tpair_t _tto_t _tthis_t _tXMLAttributes_t_t _tstructure_t.
Definition XMLAttributes.cpp:1302
LIBLAX_EXTERN int XMLAttributes_clear(XMLAttributes_t *xa)
_tClears_t (_tdeletes_t) _tall_t _tattributes_t _tin_t _tthis_t _tXMLAttributes_t_t _tstructure_t.
Definition XMLAttributes.cpp:1382
LIBLAX_EXTERN XMLAttributes_t * XMLAttributes_create(void)
@_tendcond_t
Definition XMLAttributes.cpp:1276
LIBLAX_EXTERN void XMLNamespaces_free(XMLNamespaces_t *ns)
_tFrees_t _tthe_t _tgiven_t _tXMLNamespaces_t_t _tstructure_t.
Definition XMLNamespaces.cpp:475
LIBLAX_EXTERN int XMLNamespaces_add(XMLNamespaces_t *ns, const char *uri, const char *prefix)
_tAppends_t _tan_t _tXML_t _tnamespace_t _tprefix_t/_tURI_t _tpair_t _tto_t _tthis_t _tXMLNamespaces_...
Definition XMLNamespaces.cpp:493
LIBLAX_EXTERN XMLNamespaces_t * XMLNamespaces_create(void)
@_tendcond_t
Definition XMLNamespaces.cpp:467
LIBLAX_EXTERN XMLNode_t * XMLNode_createFromToken(const XMLToken_t *token)
_tCreates_t _ta_t _tnew_t _tXMLNode_t_t _tstructure_t _tby_t _tcopying_t _ttoken_t _tand_t _treturns_...
Definition XMLNode.cpp:717
LIBLAX_EXTERN void XMLNode_free(XMLNode_t *node)
_tDestroys_t _tthis_t _tXMLNode_t_t _tstructure_t.
Definition XMLNode.cpp:795
LIBLAX_EXTERN int XMLNode_addChild(XMLNode_t *node, const XMLNode_t *child)
_tAdds_t _ta_t _tcopy_t _tof_t _tchild_t _tnode_t _tto_t _tthis_t _tXMLNode_t_t _tstructure_t.
Definition XMLNode.cpp:804
LIBLAX_EXTERN XMLToken_t * XMLToken_createWithTripleAttr(const XMLTriple_t *triple, const XMLAttributes_t *attr)
_tCreates_t _ta_t _tnew_t _tstart_t _telement_t _tXMLToken_t_t _tstructure_t _twith_t _tXMLTriple_t_t...
Definition XMLToken.cpp:1302
LIBLAX_EXTERN void XMLToken_free(XMLToken_t *token)
_tDestroys_t _tthis_t _tXMLToken_t_t _tstructure_t.
Definition XMLToken.cpp:1330
LIBLAX_EXTERN int XMLToken_setEnd(XMLToken_t *token)
_tDeclares_t _tthis_t _tXML_t _tstart_t _telement_t _tis_t _talso_t _tan_t _tend_t _telement_t.
Definition XMLToken.cpp:1913
LIBLAX_EXTERN XMLToken_t * XMLToken_createWithTripleAttrNS(const XMLTriple_t *triple, const XMLAttributes_t *attr, const XMLNamespaces_t *ns)
_tCreates_t _ta_t _tnew_t _tstart_t _telement_t _tXMLToken_t_t _tstructure_t _twith_t _tXMLTriple_t_t...
Definition XMLToken.cpp:1312
LIBLAX_EXTERN void XMLTriple_free(XMLTriple_t *triple)
_tDestroys_t _tthis_t _tXMLTriple_t_t _tstructure_t.
Definition XMLTriple.cpp:258
LIBLAX_EXTERN XMLTriple_t * XMLTriple_createWith(const char *name, const char *uri, const char *prefix)
_tCreates_t _ta_t _tnew_t _tXMLTriple_t_t _tstructure_t _twith_t _tname_t, _tprefix_t _tand_t _turi_t...
Definition XMLTriple.cpp:249
Stores an XML namespace triple.