| 1 | package Bio::ECell; | ||
| 2 | |||
| 3 | use 5.006; | ||
| 4 | use strict; | ||
| 5 | use warnings; | ||
| 6 | |||
| 7 | BEGIN{ | ||
| 8 | my @lines = qx|ecell3-python -h|; | ||
| 9 | |||
| 10 | if ($?){ | ||
| 11 | print STDERR "E-Cell3 is not installed on your system. Bio::ECell will not work.\n"; | ||
| 12 | }else{ | ||
| 13 | |||
| 14 | my $flag = 0; | ||
| 15 | foreach my $line (@lines){ | ||
| 16 | chomp($line); | ||
| 17 | |||
| 18 | $flag = 1 if($line =~ /^Configurations:/); | ||
| 19 | if($flag == 1 && $line =~ /^\s+(\S+)\s+\=\s+(.*)/){ | ||
| 20 | $ENV{$1} .= ':' if ($ENV{$1}); | ||
| 21 | $ENV{$1} .= $2; | ||
| 22 | } | ||
| 23 | } | ||
| 24 | |||
| 25 | $ENV{ECELL3_DM_PATH} .= ':' . $ENV{prefix} . '/lib/' . $ENV{PACKAGE} . '/' . $ENV{VERSION}; | ||
| 26 | $ENV{ECELL3_DM_PATH} .= ':' . $ENV{prefix} . '/lib/' . $ENV{PACKAGE} . '-3.1/dms/'; | ||
| 27 | $ENV{ECELL3_PREFIX} = $ENV{prefix}; | ||
| 28 | $ENV{OSOGOPATH} = $ENV{prefix} . '/lib/osogo'; | ||
| 29 | $ENV{MEPATH} = $ENV{prefix} . '/lib/modeleditor'; | ||
| 30 | $ENV{TLPATH} = $ENV{prefix} . '/lib/toollauncher'; | ||
| 31 | $ENV{PYTHONDIR} = $ENV{pythondir}; | ||
| 32 | $ENV{LTDL_LIBRARY_PATH} .= ':.:/sw/lib/ecell-3.1/dms/' . $ENV{ECELL3_DM_PATH} . ':' . $ENV{prefix} . '/lib/ecell/' . $ENV{VERSION}; | ||
| 33 | |||
| 34 | require Inline; | ||
| 35 | import Inline Python => << '__INLINE_PYTHON__'; | ||
| 36 | import sys | ||
| 37 | import string | ||
| 38 | import getopt | ||
| 39 | import os | ||
| 40 | |||
| 41 | import ecell | ||
| 42 | import ecell.ecs | ||
| 43 | import ecell.emc | ||
| 44 | import ecell.eml | ||
| 45 | import ecell.analysis.emlsupport | ||
| 46 | |||
| 47 | from ecell.Session import Session | ||
| 48 | from ecell.ECDDataFile import * | ||
| 49 | |||
| 50 | def internalLoadEcell3(): | ||
| 51 | aSimulator = ecell.emc.Simulator() | ||
| 52 | aSession = Session(aSimulator) | ||
| 53 | return aSession | ||
| 54 | |||
| 55 | def internalECDDataFile(logger): | ||
| 56 | return ECDDataFile(logger.getData()) | ||
| 57 | |||
| 58 | def internalEmlSupport(eml): | ||
| 59 | return ecell.analysis.emlsupport.EmlSupport(eml) | ||
| 60 | |||
| 61 | __INLINE_PYTHON__ | ||
| 62 | |||
| 63 | |||
| 64 | } | ||
| 65 | } | ||
| 66 | |||
| 67 | |||
| 68 | require Exporter; | ||
| 69 | |||
| 70 | our @ISA = qw(Exporter); | ||
| 71 | |||
| 72 | # Items to export into callers namespace by default. Note: do not export | ||
| 73 | # names by default without a very good reason. Use EXPORT_OK instead. | ||
| 74 | # Do not simply export all your public functions/methods/constants. | ||
| 75 | |||
| 76 | # This allows declaration use Bio::ECell ':all'; | ||
| 77 | # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK | ||
| 78 | # will save memory. | ||
| 79 | our %EXPORT_TAGS = ( 'all' => [ qw( | ||
| 80 | |||
| 81 | ) ] ); | ||
| 82 | |||
| 83 | our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); | ||
| 84 | |||
| 85 | our @EXPORT = qw( | ||
| 86 | |||
| 87 | ); | ||
| 88 | |||
| 89 | our $VERSION = '0.10'; | ||
| 90 | |||
| 91 | |||
| 92 | sub new{ | ||
| 93 | my $this = internalLoadEcell3(); | ||
| 94 | my $pkg = shift; | ||
| 95 | my $eml = shift; | ||
| 96 | |||
| 97 | if(length($eml)){ | ||
| 98 | $this->loadModel($eml); | ||
| 99 | |||
| 100 | if(wantarray()){ | ||
| 101 | return ($this, internalEmlSupport($eml)); | ||
| 102 | } | ||
| 103 | } | ||
| 104 | return $this; | ||
| 105 | } | ||
| 106 | |||
| 107 | sub ECDDataFile{ | ||
| 108 | my $this = shift; | ||
| 109 | my $logger = shift; | ||
| 110 | |||
| 111 | return internalECDDataFile($logger); | ||
| 112 | } | ||
| 113 | |||
| 114 | sub EMLSupport{ | ||
| 115 | my $this = shift; | ||
| 116 | my $eml = shift; | ||
| 117 | |||
| 118 | return internalEmlSupport($eml); | ||
| 119 | } | ||
| 120 | |||
| 121 | |||
| 122 | |||
| 123 | =head1 NAME | ||
| 124 | |||
| 125 | Bio::ECell - Perl interface for E-Cell Simulation Environment. | ||
| 126 | |||
| 127 | =head1 SYNOPSIS | ||
| 128 | |||
| 129 | # E-Cell way | ||
| 130 | |||
| 131 | use Bio::ECell; | ||
| 132 | |||
| 133 | my $ecell = Bio::ECell::new(); | ||
| 134 | |||
| 135 | $ecell->loadModel("simple.eml"); | ||
| 136 | $ecell->message("Message from Perl!"); | ||
| 137 | |||
| 138 | my $logger = $ecell->createLoggerStub('Variable:/:S:Value'); | ||
| 139 | $logger->create(); | ||
| 140 | |||
| 141 | print $ecell->getCurrentTime(), "\n"; | ||
| 142 | $ecell->run(100); | ||
| 143 | print $ecell->getCurrentTime(), "\n"; | ||
| 144 | |||
| 145 | my $data = Bio::ECell->ECDDataFile($logger ); | ||
| 146 | $data->setDataName( $logger->getName() ); | ||
| 147 | $data->save('S.ecd'); | ||
| 148 | |||
| 149 | # more Perl-ish way:) | ||
| 150 | |||
| 151 | use Bio::ECell; | ||
| 152 | my ($ecell, $eml) = new Bio::ECell("simple.eml"); | ||
| 153 | |||
| 154 | my $duration = 100; | ||
| 155 | my $step = 0.001; | ||
| 156 | |||
| 157 | my %loggers; | ||
| 158 | foreach my $variable ($eml->getVariableList()){ | ||
| 159 | next if ($variable =~ /:SIZE/); | ||
| 160 | $loggers{$variable} = $ecell->createLoggerStub($variable . ':Value'); | ||
| 161 | $loggers{$variable}->create(); | ||
| 162 | $loggers{$variable}->setLoggerPolicy([$step, 0, 1, 1024 * 100]); | ||
| 163 | } | ||
| 164 | |||
| 165 | $ecell->run($duration); | ||
| 166 | |||
| 167 | foreach my $variable (keys %loggers){ | ||
| 168 | my $data = Bio::ECell->ECDDataFile($loggers{$variable}); | ||
| 169 | my @name = split(/:/, $variable); | ||
| 170 | $data->setDataName($name[2]); | ||
| 171 | $data->save($name[2]); | ||
| 172 | } | ||
| 173 | |||
| 174 | $ecell->saveModel('hoge.eml'); | ||
| 175 | |||
| 176 | |||
| 177 | =head1 DESCRIPTION | ||
| 178 | |||
| 179 | Bio::ECell is a Perl interface for the E-Cell Simulation Environment | ||
| 180 | version 3 (http://www.e-cell.org/), a generic cell simulation software | ||
| 181 | for molecular cell biology researches that allow object-oriented modeling | ||
| 182 | and simulation, multi-algorithm/time-scale simulation, and scripting | ||
| 183 | through Python. This module allows scripting of sessions with Perl. | ||
| 184 | |||
| 185 | For the details of the E-Cell API, users should refer to the chapter | ||
| 186 | about scripting a simulation session of E-Cell3 Users Manual, available | ||
| 187 | at the above-mentioned web-site. | ||
| 188 | |||
| 189 | =head2 new | ||
| 190 | |||
| 191 | The constructor is just a wrapper around the instance given by | ||
| 192 | |||
| 193 | ecell.Session(ecell.emc.Simulator()) | ||
| 194 | |||
| 195 | in Python. | ||
| 196 | |||
| 197 | Basically functions required for scripting can be called from this instance. | ||
| 198 | |||
| 199 | As a shortcut, if this constructor is called with an EML file path, | ||
| 200 | the system loads the model with $ecell->loadModel(), and returns | ||
| 201 | the loaded session instance as well as an eml object. | ||
| 202 | |||
| 203 | ex. ($ecell, $eml) = new Bio::ECell("simple.eml"); | ||
| 204 | |||
| 205 | =head2 ECDDataFile | ||
| 206 | |||
| 207 | ECDDataFile constructor can be called as follows: | ||
| 208 | |||
| 209 | $ecell = Bio::ECell::new(); | ||
| 210 | $logger = $ecell->createLoggerStub('Path-name-for-logger'); | ||
| 211 | $logger->create(); | ||
| 212 | $data = Bio::ECell->ECDDataFile( $logger ); | ||
| 213 | |||
| 214 | Here usage is slightly different from the Python interface, passing | ||
| 215 | the logger instance instead of the DATA tuple. Internally the system | ||
| 216 | calls logger.getData() to pass onto ECDDataFile. | ||
| 217 | |||
| 218 | =head2 $ecell->loadModel( $file ) | ||
| 219 | |||
| 220 | Load an EML file, and create a cell model as described in the file. | ||
| 221 | file can be either a filename or a file object. | ||
| 222 | |||
| 223 | =head2 loadScript( $filename ) | ||
| 224 | |||
| 225 | Load a ESS file. Usually this is not used in ESS. | ||
| 226 | |||
| 227 | =head2 $ecell->message( $message ) | ||
| 228 | |||
| 229 | Output message. By default the message is printed to stdout. | ||
| 230 | The way the message is handled can be changed by using setMessageMethod | ||
| 231 | method. For example, GUI frontend software may give a method to steal the message for its message printing widget. | ||
| 232 | |||
| 233 | =head2 $ecell->saveModel( $file ) | ||
| 234 | |||
| 235 | Save the current model in memory as an EML file. File may be either a filename or | ||
| 236 | a file object. | ||
| 237 | |||
| 238 | =head2 $ecell->setMessageMethod( $method ) | ||
| 239 | |||
| 240 | This method changes what happens when message method is called. | ||
| 241 | method must be a Python callable object which takes just one string parameter. | ||
| 242 | |||
| 243 | =head2 $ecell->restoreMessageMethod() | ||
| 244 | |||
| 245 | This method undoes saveMessageMethod, by restoring the default | ||
| 246 | MessageMethod for the Session. | ||
| 247 | |||
| 248 | =head2 $ecell->plainMessageMethod() | ||
| 249 | |||
| 250 | This method undoes saveMessageMethod, by restoring the default | ||
| 251 | MessageMethod for the Session. | ||
| 252 | |||
| 253 | =head2 $ecell->getCurrentTime() | ||
| 254 | |||
| 255 | This method returns the current time of the simulator. | ||
| 256 | |||
| 257 | =head2 $ecell->getNextEvent() | ||
| 258 | |||
| 259 | This method returns the next scheduled event as a Python 2-tuple consisting of a | ||
| 260 | scheduled time and a StepperID. The event will be processed in the next time whe | ||
| 261 | step() or run() is called. | ||
| 262 | |||
| 263 | The time is usually different from one that getCurrentTime() returns. This method | ||
| 264 | returns the scheduled time of the next event, while getCurrentTime() returns the | ||
| 265 | time of the last event. These methods can return the same number if more than one | ||
| 266 | events are scheduled at the same point in time. | ||
| 267 | |||
| 268 | =head2 $ecell->run( $sec ) | ||
| 269 | |||
| 270 | Run the simulation for $sec seconds. | ||
| 271 | When this method is called, the simulator internally calls step() method repeat- | ||
| 272 | edly until the equation tcurrent > tstart + sec holds. That means, the simulator | ||
| 273 | stops immediately after the simulation step in which the time exceeds the speci- | ||
| 274 | fied point. The time can be far after the specified time point if all step sizes taken | ||
| 275 | by Steppers in the model are very long. | ||
| 276 | |||
| 277 | If event checker event handler object are set, sec can be omitted. | ||
| 278 | |||
| 279 | =head2 $ecell->setEventChecker( $eventchecker ) | ||
| 280 | |||
| 281 | If the event checker and an event handler are correctly set, and the run method is | ||
| 282 | called with or without time duration, the simulator checks if the event checker | ||
| 283 | returns true once in n simulation steps , where n is a positive integer number set | ||
| 284 | by using setEventCheckInterval (default n= 20 steps). If it happens, the | ||
| 285 | simulator then calls the event handler. If the event handler calls stop method of | ||
| 286 | Session, the simulator stops before the next step. This is the only way to quit | ||
| 287 | from the simulation loop when run is called without an argument. | ||
| 288 | |||
| 289 | This mechanism is used to implement, mainly but not limited to, GUI frontend | ||
| 290 | components to the Session class. | ||
| 291 | |||
| 292 | event checker and event handler must be Python callable objects. event | ||
| 293 | checker must return an object which can be evaluated as either true or false. | ||
| 294 | |||
| 295 | =head2 $ecell->setEventCheckInterval( $n ) | ||
| 296 | |||
| 297 | This method is NOT IMPLEMENTED YET. | ||
| 298 | |||
| 299 | =head2 $ecell->setEventHandler( $eventhandler | ||
| 300 | |||
| 301 | See setEventChecker | ||
| 302 | |||
| 303 | =head2 $ecell->step( $numsteps ) | ||
| 304 | |||
| 305 | Perform a step of the simulation. If the optional integer numsteps parameter is | ||
| 306 | given, the simulator steps that number. If it is omitted, it steps just once. | ||
| 307 | |||
| 308 | =head2 $ecell->stop() | ||
| 309 | |||
| 310 | Stop the simulation. Usually this is called from the event handler, or other | ||
| 311 | methods called by the event handler. | ||
| 312 | |||
| 313 | =head2 $ecell->initialize() | ||
| 314 | |||
| 315 | Do preparation of the simulation. Usually there is no need to call this method | ||
| 316 | because this is automatically called before executing step and run. | ||
| 317 | Stepper methods | ||
| 318 | |||
| 319 | =head2 $ecell->getStepperList() | ||
| 320 | |||
| 321 | This method returns a Python tuple which contains ID strings of Stepper objects | ||
| 322 | in the simulator. | ||
| 323 | |||
| 324 | =head2 $ecell->createStepperStub( $id ) | ||
| 325 | |||
| 326 | This method returns a StepperStub object bound to this Session object and the | ||
| 327 | given id. | ||
| 328 | |||
| 329 | =head2 $ecell->getEntityList( $entitytype, $systempath ) | ||
| 330 | |||
| 331 | This method returns a Python tuple which contains FullID strings of Entity | ||
| 332 | objects of entitytype existing in the System pointed by the systempath | ||
| 333 | argument entitytype must be one of "Variable", "Process", or "System". VARIABLE, PROCESS, | ||
| 334 | or SYSTEM defined in ecell.ECS module. systempath must be a valid SystemPath | ||
| 335 | string. | ||
| 336 | |||
| 337 | |||
| 338 | =head2 $ecell->createEntityStub( $fullid ) | ||
| 339 | |||
| 340 | This method returns an EntityStub object bound to this Session object and the | ||
| 341 | given fullid. | ||
| 342 | |||
| 343 | |||
| 344 | =head2 $ecell->getLoggerList() | ||
| 345 | |||
| 346 | This method returns a Python tuple which contains FullPN strings of all the | ||
| 347 | Logger objects in the simulator. | ||
| 348 | |||
| 349 | =head2 $ecell->createLoggerStub( $fullpn ) | ||
| 350 | |||
| 351 | This method returns a LoggerStub object bound to this Session object and the | ||
| 352 | given fullpn. | ||
| 353 | |||
| 354 | fullpn must be a valid FullPN string. | ||
| 355 | |||
| 356 | =head2 $ecell->saveLoggerData( $fullpn, $aSaveDirectory , $aSaveDirectory , $aSaveDirectory , $aSaveDirectory ) | ||
| 357 | |||
| 358 | This saves all logger data associated with logger fullpn to | ||
| 359 | aSaveDirectory. If fullpn is not specified, all loggers are | ||
| 360 | dumped by this method. If a fullpn is provided, than that | ||
| 361 | logger alone will be dumped. aSaveDirectory specifies the | ||
| 362 | directory for saving the dump files; if left blank it defaults to | ||
| 363 | ./Data. Within no start times, interval increments, or finish | ||
| 364 | times, this function will print out all data, however, any of | ||
| 365 | these can be given in seconds as a parameter. | ||
| 366 | |||
| 367 | =head2 $ecell->theSimulator | ||
| 368 | |||
| 369 | theSimulator variable holds this Session’s Simulator object. | ||
| 370 | Usually ESS users should rarely have need to get into details of the Simulator | ||
| 371 | class because almost all simulation jobs can be done with the Session API | ||
| 372 | and the ObjectStub classes, which were in fact developed to make it eas- | ||
| 373 | ier by providing a simple and consistent object-oriented appearance to the | ||
| 374 | lower level flat Simulator API. For the details of Simulator class, consult E- | ||
| 375 | Cell C++ library reference manual and the sourcecode of the system, especially | ||
| 376 | ecell3/ecell/libemc/Simulator.hpp. | ||
| 377 | |||
| 378 | =head2 $eml->getAllEntityList($entityType, $rootSystemPath) | ||
| 379 | |||
| 380 | get the list of all entities under the root system path | ||
| 381 | entityType: (str) 'Variable' or 'Process' or 'System' | ||
| 382 | |||
| 383 | =head2 $eml->getVariableList() | ||
| 384 | |||
| 385 | get the list of all variables. | ||
| 386 | |||
| 387 | =head2 $eml->getProcessList() | ||
| 388 | |||
| 389 | get the list of all processes. | ||
| 390 | |||
| 391 | =head2 $eml->calculateActivityArray() | ||
| 392 | |||
| 393 | create an Session from Eml and calculate the initial activity of processes | ||
| 394 | return activityArray | ||
| 395 | |||
| 396 | =head2 $eml->getActivityArray() | ||
| 397 | |||
| 398 | create an Session from Eml and calculate the initial activity of processes | ||
| 399 | return activityArray | ||
| 400 | |||
| 401 | =head2 $eml->getValueArray() | ||
| 402 | |||
| 403 | create an Session from Eml and get the initial value of variables | ||
| 404 | return valueArray | ||
| 405 | |||
| 406 | |||
| 407 | |||
| 408 | =head1 SEE ALSO | ||
| 409 | |||
| 410 | For complete descriptions of E-Cell API, see | ||
| 411 | http://www.e-cell.org/software/documentation/ecell3-users-manual_0606.pdf | ||
| 412 | |||
| 413 | =head1 AUTHOR | ||
| 414 | |||
| 415 | Kazuharu Arakawa, E<lt>gaou@sfc.keio.ac.jpE<gt> | ||
| 416 | |||
| 417 | =head1 COPYRIGHT AND LICENSE | ||
| 418 | |||
| 419 | Copyright (C) 2007 by Kazuharu Arakawa | ||
| 420 | |||
| 421 | This library is free software; you can redistribute it and/or modify | ||
| 422 | it under the same terms as Perl itself, either Perl version 5.8.5 or, | ||
| 423 | at your option, any later version of Perl 5 you may have available. | ||
| 424 | |||
| 425 | |||
| 426 | =cut | ||
| 427 | |||
| 428 | |||
| 429 | |||
| 430 | 1; | ||
| 431 | __END__ |