1#!/usr/bin/env perl 2# -*-Perl-*- 3## 4## \file extractReactions.pl 5## \brief Illustrates howto extract the reactions from a SBML file 6## \author TBI {xtof,raim}@tbi.univie.ac.at 7## 8 9## 10## Copyright 2007 TBI 11## 12## This library is free software; you can redistribute it and/or modify it 13## under the terms of the GNU Lesser General Public License as published 14## by the Free Software Foundation; either version 2.1 of the License, or 15## any later version. 16## 17## This library is distributed in the hope that it will be useful, but 18## WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF 19## MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. The software and 20## documentation provided hereunder is on an "as is" basis, and the 21## California Institute of Technology and Japan Science and Technology 22## Corporation have no obligations to provide maintenance, support, 23## updates, enhancements or modifications. In no event shall the 24## California Institute of Technology or the Japan Science and Technology 25## Corporation be liable to any party for direct, indirect, special, 26## incidental or consequential damages, including lost profits, arising 27## out of the use of this software and its documentation, even if the 28## California Institute of Technology and/or Japan Science and Technology 29## Corporation have been advised of the possibility of such damage. See 30## the GNU Lesser General Public License for more details. 31## 32## You should have received a copy of the GNU Lesser General Public License 33## along with this library; if not, write to the Free Software Foundation, 34## Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 35## 36## The original code contained here was initially developed by: 37## 38## Christoph Flamm and Rainer Machne 39## Institut fuer Theoretische Chemie 40## Universitaet Wien 41## Waehringerstrasse 17/3/308 42## A-1090 Wien, Austria 43 44use File::Basename; 45use blib '../../src/bindings/perl'; 46use LibSBML; 47use strict; 48 49my $filename = shift() 50 || do { printf STDERR "\n usage: @{[basename($0)]} <filename>\n\n"; 51 exit (1); 52 }; 53 54print "Reading \"$filename\"\n"; 55 56my $rd = new LibSBML::SBMLReader(); 57my $d = $rd->readSBML($filename); 58 59$d->printErrors(); 60 61my $model = $d->getModel(); 62my @reactions = (); 63 64foreach my $reaction ($model->getListOfReactions()) { 65 my @reactants = $reaction->getListOfReactants(); 66 my $reactants = to_string(@reactants); 67 my @products = $reaction->getListOfProducts(); 68 my $products = to_string(@products); 69 push @reactions, [ $reaction->getId(), 70 join " ", 71 $reactants, 72 $reaction->getReversible() ? '<=>' : '->', 73 $products ]; 74} 75 76@reactions = sort {length $b->[0] <=> length $a->[0]} @reactions; 77my $format = sprintf("%%%ds: %%s\n", length $reactions[0]->[0]); 78foreach my $r (@reactions) { 79 printf $format, @$r; 80} 81 82#--- 83sub to_string { join(" + ", 84 map { join(" * ", 85 $_->getStoichiometry(), 86 $_->getSpecies()) } @_ ) } 87 88__END__ 89 90