1#!/usr/bin/env ruby 2# 3## 4## \file addModelHistory.py 5## \brief adds Model History to a model 6## \author Sarah Keating 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 44 45require 'libSBML' 46 47 48def printStatus(message, status) 49 statusString = ""; 50 if status == LibSBML::LIBSBML_OPERATION_SUCCESS 51 statusString = "succeeded"; 52 elsif status == LibSBML::LIBSBML_INVALID_OBJECT 53 statusString = "invalid object"; 54 elsif status == LibSBML::LIBSBML_OPERATION_FAILED 55 statusString = "operation failed"; 56 else 57 statusString = "unknown"; 58 end 59 puts "#{message} #{statusString}" 60end 61 62 63if ARGV.size != 2: 64 puts "usage: addModelHistory <input-filename> <output-filename>" 65 puts "Adds a model history to the model" 66 exit(2) 67end 68 69d = LibSBML::readSBML(ARGV[0]); 70errors = d.getNumErrors 71 72if errors > 0 73 print("Read Error(s):" + "\n"); 74 d.printErrors(); 75 print("Correct the above and re-run." + "\n"); 76 exit(errors); 77end 78 79h = LibSBML::ModelHistory.new 80 81c = LibSBML::ModelCreator.new 82c.setFamilyName("Keating"); 83c.setGivenName("Sarah"); 84c.setEmail("sbml-team@caltech.edu"); 85c.setOrganization("University of Hertfordshire"); 86 87status = h.addCreator(c); 88printStatus("Status for addCreator: ", status); 89 90 91date = LibSBML::Date.new("1999-11-13T06:54:32"); 92date2 = LibSBML::Date.new("2007-11-30T06:54:00-02:00"); 93 94status = h.setCreatedDate(date); 95printStatus("Set created date: ", status); 96 97status = h.setModifiedDate(date2); 98printStatus("Set modified date: ", status); 99 100status = d.getModel().setModelHistory(h); 101printStatus("Set model history: ", status); 102 103 104LibSBML::writeSBML(d, ARGV[1]); 105 106exit(errors); 107 108 109 110