Migrated from GitHub
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +129 -0
- data/.dockerignore +460 -0
- data/.mailmap +5 -0
- data/.quarkus/cli/plugins/quarkus-cli-catalog.json +5 -0
- data/CODE_OF_CONDUCT.md +123 -0
- data/CONTRIBUTING.md +34 -0
- data/Dockerfile +90 -0
- data/README_BioSim.md +115 -0
- data/auto.docker +2 -0
- data/auto.vcellapps +9 -0
- data/bionetgen/BNG2.pl +251 -0
- data/bionetgen/CHANGES.txt +467 -0
- data/bionetgen/CREDITS.txt +88 -0
- data/bionetgen/LICENSE.txt +674 -0
- data/bionetgen/Perl2/Aux2/MakeBin.pl +66 -0
- data/bionetgen/Perl2/Aux2/bnglstat.pl +12 -0
- data/bionetgen/Perl2/Aux2/count_blocks.pl +26 -0
- data/bionetgen/Perl2/Aux2/count_lines.pl +51 -0
- data/bionetgen/Perl2/Aux2/countdown.pl +6 -0
- data/bionetgen/Perl2/Aux2/diff_cdat.pl +120 -0
- data/bionetgen/Perl2/Aux2/express.pl +164 -0
- data/bionetgen/Perl2/Aux2/express_main.pl +114 -0
- data/bionetgen/Perl2/Aux2/group_size.pl +17 -0
- data/bionetgen/Perl2/Aux2/runBNG.pl +135 -0
- data/bionetgen/Perl2/Aux2/test.pl +21 -0
- data/bionetgen/Perl2/Aux2/test_compartment.pl +56 -0
- data/bionetgen/Perl2/Aux2/test_molorder.pl +20 -0
- data/bionetgen/Perl2/Aux2/test_redirect.pl +19 -0
- data/bionetgen/Perl2/Aux2/test_sub.pl +13 -0
- data/bionetgen/Perl2/BNGAction.pm +1931 -0
- data/bionetgen/Perl2/BNGMessages.pm +46 -0
- data/bionetgen/Perl2/BNGModel.pm +2614 -0
- data/bionetgen/Perl2/BNGOptions.pm +66 -0
- data/bionetgen/Perl2/BNGOutput.pm +0 -0
- data/bionetgen/Perl2/BNGUtils.pm +599 -0
- data/bionetgen/Perl2/Boolean2BNGL/ABC_example.txt +7 -0
- data/bionetgen/Perl2/Boolean2BNGL/Boolean2BNGL.pl +222 -0
- data/bionetgen/Perl2/Boolean2BNGL/Tcell_model_Nov2013_LAH.txt +110 -0
- data/bionetgen/Perl2/Boolean2BNGL/Tcell_model_Oct2013.txt +108 -0
- data/bionetgen/Perl2/Boolean2BNGL/Tcell_model_v16.txt +20 -103
- data/bionetgen/Perl2/Cache.pm +93 -0
- data/bionetgen/Perl2/CartesianProduct.pm +309 -0
- data/bionetgen/Perl2/Compartment.pm +449 -0
- data/bionetgen/Perl2/CompartmentList.pm +240 -0
- data/bionetgen/Perl2/Component.pm +453 -0
- data/bionetgen/Perl2/ComponentType.pm +157 -0
- data/bionetgen/Perl2/Console.pm +228 -0
- data/bionetgen/Perl2/EnergyPattern.pm +252 -0
- data/bionetgen/Perl2/Expression.pm +1987 -0
- data/bionetgen/Perl2/Function.pm +543 -0
.gitattributes
CHANGED
|
@@ -57,3 +57,132 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 57 |
# Video files - compressed
|
| 58 |
*.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 59 |
*.webm filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
# Video files - compressed
|
| 58 |
*.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 59 |
*.webm filter=lfs diff=lfs merge=lfs -text
|
| 60 |
+
data/bionetgen/win32Standalone/BNG2_32bit.exe filter=lfs diff=lfs merge=lfs -text
|
| 61 |
+
data/bionetgen/win64Standalone/BNG2.exe filter=lfs diff=lfs merge=lfs -text
|
| 62 |
+
data/docker/build/installers/icons/vcell.icns filter=lfs diff=lfs merge=lfs -text
|
| 63 |
+
data/nativelibs/linux32/libjhdf.so filter=lfs diff=lfs merge=lfs -text
|
| 64 |
+
data/nativelibs/linux32/libjhdf5.so filter=lfs diff=lfs merge=lfs -text
|
| 65 |
+
data/nativelibs/linux64/libjhdf.so filter=lfs diff=lfs merge=lfs -text
|
| 66 |
+
data/nativelibs/linux64/libjhdf5.so filter=lfs diff=lfs merge=lfs -text
|
| 67 |
+
data/nativelibs/mac64/libjhdf.jnilib filter=lfs diff=lfs merge=lfs -text
|
| 68 |
+
data/nativelibs/mac64/libjhdf5.jnilib filter=lfs diff=lfs merge=lfs -text
|
| 69 |
+
data/nativelibs/win32/jhdf.dll filter=lfs diff=lfs merge=lfs -text
|
| 70 |
+
data/nativelibs/win32/jhdf5.dll filter=lfs diff=lfs merge=lfs -text
|
| 71 |
+
data/nativelibs/win32/msvcp100.dll filter=lfs diff=lfs merge=lfs -text
|
| 72 |
+
data/nativelibs/win32/msvcp100d.dll filter=lfs diff=lfs merge=lfs -text
|
| 73 |
+
data/nativelibs/win32/msvcr100.dll filter=lfs diff=lfs merge=lfs -text
|
| 74 |
+
data/nativelibs/win32/msvcr100d.dll filter=lfs diff=lfs merge=lfs -text
|
| 75 |
+
data/nativelibs/win64/jhdf.dll filter=lfs diff=lfs merge=lfs -text
|
| 76 |
+
data/nativelibs/win64/jhdf5.dll filter=lfs diff=lfs merge=lfs -text
|
| 77 |
+
data/nativelibs/win64/msvcp100.dll filter=lfs diff=lfs merge=lfs -text
|
| 78 |
+
data/nativelibs/win64/msvcr100.dll filter=lfs diff=lfs merge=lfs -text
|
| 79 |
+
data/vcell-cli/src/test/resources/OmexWithThirdPartyResults/BIOMD0000000003_tellurium_A_minimal_cascade_model_for_th.spec.omex filter=lfs diff=lfs merge=lfs -text
|
| 80 |
+
data/vcell-cli/src/test/resources/OmexWithThirdPartyResults/BIOMD0000000006_tellurium_Modeling_the_cell_division_cyc.spec.omex filter=lfs diff=lfs merge=lfs -text
|
| 81 |
+
data/vcell-cli/src/test/resources/OmexWithThirdPartyResults/BIOMD0000000036_tellurium_A_simple_model_of_circadian_rh.spec.omex filter=lfs diff=lfs merge=lfs -text
|
| 82 |
+
data/vcell-cli/src/test/resources/OmexWithThirdPartyResults/BIOMD0000000300.spec.omex filter=lfs diff=lfs merge=lfs -text
|
| 83 |
+
data/vcell-cli/src/test/resources/bsts-omex/misc-projects/BIOMD0000000005.omex filter=lfs diff=lfs merge=lfs -text
|
| 84 |
+
data/vcell-cli/src/test/resources/bsts-omex/misc-projects/BIOMD0000000175.omex filter=lfs diff=lfs merge=lfs -text
|
| 85 |
+
data/vcell-cli/src/test/resources/bsts-omex/misc-projects/BIOMD0000000302.omex filter=lfs diff=lfs merge=lfs -text
|
| 86 |
+
data/vcell-cli/src/test/resources/bsts-omex/misc-projects/BIOMD0000000561.omex filter=lfs diff=lfs merge=lfs -text
|
| 87 |
+
data/vcell-cli/src/test/resources/bsts-omex/misc-projects/BIOMD0000000569.omex filter=lfs diff=lfs merge=lfs -text
|
| 88 |
+
data/vcell-cli/src/test/resources/bsts-omex/misc-projects/BIOMD0000000618.omex filter=lfs diff=lfs merge=lfs -text
|
| 89 |
+
data/vcell-cli/src/test/resources/bsts-omex/misc-projects/BIOMD0000000651.omex filter=lfs diff=lfs merge=lfs -text
|
| 90 |
+
data/vcell-cli/src/test/resources/bsts-omex/misc-projects/BIOMD0000000668.omex filter=lfs diff=lfs merge=lfs -text
|
| 91 |
+
data/vcell-cli/src/test/resources/bsts-omex/misc-projects/BIOMD0000000669.omex filter=lfs diff=lfs merge=lfs -text
|
| 92 |
+
data/vcell-cli/src/test/resources/bsts-omex/misc-projects/BIOMD0000000676.omex filter=lfs diff=lfs merge=lfs -text
|
| 93 |
+
data/vcell-cli/src/test/resources/bsts-omex/misc-projects/BIOMD0000000679.omex filter=lfs diff=lfs merge=lfs -text
|
| 94 |
+
data/vcell-cli/src/test/resources/bsts-omex/misc-projects/BIOMD0000000680.omex filter=lfs diff=lfs merge=lfs -text
|
| 95 |
+
data/vcell-cli/src/test/resources/bsts-omex/misc-projects/BIOMD0000000681.omex filter=lfs diff=lfs merge=lfs -text
|
| 96 |
+
data/vcell-cli/src/test/resources/bsts-omex/misc-projects/BIOMD0000000684.omex filter=lfs diff=lfs merge=lfs -text
|
| 97 |
+
data/vcell-cli/src/test/resources/bsts-omex/misc-projects/BIOMD0000000718.omex filter=lfs diff=lfs merge=lfs -text
|
| 98 |
+
data/vcell-cli/src/test/resources/bsts-omex/misc-projects/BIOMD0000000724.omex filter=lfs diff=lfs merge=lfs -text
|
| 99 |
+
data/vcell-cli/src/test/resources/bsts-omex/misc-projects/BIOMD0000000731.omex filter=lfs diff=lfs merge=lfs -text
|
| 100 |
+
data/vcell-cli/src/test/resources/bsts-omex/misc-projects/BIOMD0000000842.omex filter=lfs diff=lfs merge=lfs -text
|
| 101 |
+
data/vcell-cli/src/test/resources/bsts-omex/misc-projects/BIOMD0000000843.omex filter=lfs diff=lfs merge=lfs -text
|
| 102 |
+
data/vcell-cli/src/test/resources/bsts-omex/misc-projects/BIOMD0000000915.omex filter=lfs diff=lfs merge=lfs -text
|
| 103 |
+
data/vcell-cli/src/test/resources/bsts-omex/misc-projects/BIOMD0000000932.omex filter=lfs diff=lfs merge=lfs -text
|
| 104 |
+
data/vcell-cli/src/test/resources/bsts-omex/misc-projects/BIOMD0000000968.omex filter=lfs diff=lfs merge=lfs -text
|
| 105 |
+
data/vcell-cli/src/test/resources/bsts-omex/misc-projects/BIOMD0000000972.omex filter=lfs diff=lfs merge=lfs -text
|
| 106 |
+
data/vcell-cli/src/test/resources/bsts-omex/misc-projects/BIOMD0000000983.omex filter=lfs diff=lfs merge=lfs -text
|
| 107 |
+
data/vcell-cli/src/test/resources/bsts-omex/misc-projects/BIOMD0000000989.omex filter=lfs diff=lfs merge=lfs -text
|
| 108 |
+
data/vcell-cli/src/test/resources/bsts-omex/misc-projects/BIOMD0000000997.omex filter=lfs diff=lfs merge=lfs -text
|
| 109 |
+
data/vcell-cli/src/test/resources/bsts-omex/misc-projects/BIOMD0000001010.omex filter=lfs diff=lfs merge=lfs -text
|
| 110 |
+
data/vcell-cli/src/test/resources/bsts-omex/misc-projects/BIOMD0000001014.omex filter=lfs diff=lfs merge=lfs -text
|
| 111 |
+
data/vcell-cli/src/test/resources/bsts-omex/misc-projects/BIOMD0000001018.omex filter=lfs diff=lfs merge=lfs -text
|
| 112 |
+
data/vcell-cli/src/test/resources/bsts-omex/misc-projects/BIOMD0000001061.omex filter=lfs diff=lfs merge=lfs -text
|
| 113 |
+
data/vcell-cli/src/test/resources/bsts-omex/misc-projects/BIOMD0000001064.omex filter=lfs diff=lfs merge=lfs -text
|
| 114 |
+
data/vcell-cli/src/test/resources/bsts-omex/misc-projects/BIOMD0000001072.omex filter=lfs diff=lfs merge=lfs -text
|
| 115 |
+
data/vcell-cli/src/test/resources/bsts-omex/sbml-core/Caravagna-J-Theor-Biol-2010-tumor-suppressive-oscillations.omex filter=lfs diff=lfs merge=lfs -text
|
| 116 |
+
data/vcell-cli/src/test/resources/bsts-omex/sbml-core/Ciliberto-J-Cell-Biol-2003-morphogenesis-checkpoint-Fehlberg.omex filter=lfs diff=lfs merge=lfs -text
|
| 117 |
+
data/vcell-cli/src/test/resources/bsts-omex/sbml-core/Ciliberto-J-Cell-Biol-2003-morphogenesis-checkpoint-continuous.omex filter=lfs diff=lfs merge=lfs -text
|
| 118 |
+
data/vcell-cli/src/test/resources/bsts-omex/sbml-core/Edelstein-Biol-Cybern-1996-Nicotinic-excitation.omex filter=lfs diff=lfs merge=lfs -text
|
| 119 |
+
data/vcell-cli/src/test/resources/bsts-omex/sbml-core/Parmar-BMC-Syst-Biol-2017-iron-distribution.omex filter=lfs diff=lfs merge=lfs -text
|
| 120 |
+
data/vcell-cli/src/test/resources/bsts-omex/sbml-core/Szymanska-J-Theor-Biol-2009-HSP-synthesis.omex filter=lfs diff=lfs merge=lfs -text
|
| 121 |
+
data/vcell-cli/src/test/resources/bsts-omex/sbml-core/Varusai-Sci-Rep-2018-mTOR-signaling-LSODA-LSODAR-SBML.omex filter=lfs diff=lfs merge=lfs -text
|
| 122 |
+
data/vcell-cli/src/test/resources/bsts-omex/sbml-core/Vilar-PNAS-2002-minimal-circardian-clock-continuous.omex filter=lfs diff=lfs merge=lfs -text
|
| 123 |
+
data/vcell-cli/src/test/resources/bsts-omex/sbml-core/Vilar-PNAS-2002-minimal-circardian-clock.omex filter=lfs diff=lfs merge=lfs -text
|
| 124 |
+
data/vcell-cli/src/test/resources/bsts-omex/synths/combine_archive/CombineArchiveHasSedDocumentsInNestedDirectories/1.execution-should-succeed.omex filter=lfs diff=lfs merge=lfs -text
|
| 125 |
+
data/vcell-cli/src/test/resources/bsts-omex/synths/combine_archive/CombineArchiveHasSedDocumentsWithSameNamesInDifferentInNestedDirectories/1.execution-should-succeed.omex filter=lfs diff=lfs merge=lfs -text
|
| 126 |
+
data/vcell-cli/src/test/resources/bsts-omex/synths/combine_archive/WhenACombineArchiveHasAMasterFileSimulatorOnlyExecutesThisFile/1.execution-should-succeed.omex filter=lfs diff=lfs merge=lfs -text
|
| 127 |
+
data/vcell-cli/src/test/resources/bsts-omex/synths/combine_archive/WhenACombineArchiveHasNoMasterFileSimulatorExecutesAllSedDocuments/1.execution-should-succeed.omex filter=lfs diff=lfs merge=lfs -text
|
| 128 |
+
data/vcell-cli/src/test/resources/bsts-omex/synths/docker_image/SingularityImageExecutesSimulationsSuccessfully/1.execution-should-succeed.omex filter=lfs diff=lfs merge=lfs -text
|
| 129 |
+
data/vcell-cli/src/test/resources/bsts-omex/synths/log/SimulatorReportsTheStatusOfTheExecutionOfCombineArchives/1.execution-should-succeed.omex filter=lfs diff=lfs merge=lfs -text
|
| 130 |
+
data/vcell-cli/src/test/resources/bsts-omex/synths/log/SimulatorReportsTheStatusOfTheExecutionOfSedDocuments/1.execution-should-succeed.omex filter=lfs diff=lfs merge=lfs -text
|
| 131 |
+
data/vcell-cli/src/test/resources/bsts-omex/synths/log/SimulatorReportsTheStatusOfTheExecutionOfSedOutputs/1.execution-should-succeed.omex filter=lfs diff=lfs merge=lfs -text
|
| 132 |
+
data/vcell-cli/src/test/resources/bsts-omex/synths/log/SimulatorReportsTheStatusOfTheExecutionOfSedTasks/1.execution-should-succeed.omex filter=lfs diff=lfs merge=lfs -text
|
| 133 |
+
data/vcell-cli/src/test/resources/bsts-omex/synths/results_report/SimulatorGeneratesReportsOfSimulationResults/1.execution-should-succeed.omex filter=lfs diff=lfs merge=lfs -text
|
| 134 |
+
data/vcell-cli/src/test/resources/bsts-omex/synths/sedml/SimulatorCanResolveModelSourcesDefinedByUriFragments/1.execution-should-succeed.omex filter=lfs diff=lfs merge=lfs -text
|
| 135 |
+
data/vcell-cli/src/test/resources/bsts-omex/synths/sedml/SimulatorCanResolveModelSourcesDefinedByUriFragmentsAndInheritChanges/1.execution-should-succeed.omex filter=lfs diff=lfs merge=lfs -text
|
| 136 |
+
data/vcell-cli/src/test/resources/bsts-omex/synths/sedml/SimulatorProducesLinear2DPlots/1.execution-should-succeed.omex filter=lfs diff=lfs merge=lfs -text
|
| 137 |
+
data/vcell-cli/src/test/resources/bsts-omex/synths/sedml/SimulatorProducesLinear2DPlots/2.execution-should-succeed.omex filter=lfs diff=lfs merge=lfs -text
|
| 138 |
+
data/vcell-cli/src/test/resources/bsts-omex/synths/sedml/SimulatorProducesLogarithmic2DPlots/1.execution-should-succeed.omex filter=lfs diff=lfs merge=lfs -text
|
| 139 |
+
data/vcell-cli/src/test/resources/bsts-omex/synths/sedml/SimulatorProducesLogarithmic2DPlots/2.execution-should-succeed.omex filter=lfs diff=lfs merge=lfs -text
|
| 140 |
+
data/vcell-cli/src/test/resources/bsts-omex/synths/sedml/SimulatorProducesMultiplePlots/1.execution-should-succeed.omex filter=lfs diff=lfs merge=lfs -text
|
| 141 |
+
data/vcell-cli/src/test/resources/bsts-omex/synths/sedml/SimulatorProducesMultiplePlots/2.execution-should-succeed.omex filter=lfs diff=lfs merge=lfs -text
|
| 142 |
+
data/vcell-cli/src/test/resources/bsts-omex/synths/sedml/SimulatorSupportsAddReplaceRemoveModelElementChanges/1.execute-should-fail.omex filter=lfs diff=lfs merge=lfs -text
|
| 143 |
+
data/vcell-cli/src/test/resources/bsts-omex/synths/sedml/SimulatorSupportsAddReplaceRemoveModelElementChanges/2.execution-should-succeed.omex filter=lfs diff=lfs merge=lfs -text
|
| 144 |
+
data/vcell-cli/src/test/resources/bsts-omex/synths/sedml/SimulatorSupportsAddReplaceRemoveModelElementChanges/3.execute-should-fail.omex filter=lfs diff=lfs merge=lfs -text
|
| 145 |
+
data/vcell-cli/src/test/resources/bsts-omex/synths/sedml/SimulatorSupportsAlgorithmParameters/1.execution-should-succeed.omex filter=lfs diff=lfs merge=lfs -text
|
| 146 |
+
data/vcell-cli/src/test/resources/bsts-omex/synths/sedml/SimulatorSupportsComputeModelChanges/1.execute-should-fail.omex filter=lfs diff=lfs merge=lfs -text
|
| 147 |
+
data/vcell-cli/src/test/resources/bsts-omex/synths/sedml/SimulatorSupportsComputeModelChanges/2.execution-should-succeed.omex filter=lfs diff=lfs merge=lfs -text
|
| 148 |
+
data/vcell-cli/src/test/resources/bsts-omex/synths/sedml/SimulatorSupportsDataGeneratorsWithDifferentShapes/1.execution-should-succeed.omex filter=lfs diff=lfs merge=lfs -text
|
| 149 |
+
data/vcell-cli/src/test/resources/bsts-omex/synths/sedml/SimulatorSupportsDataSetsWithDifferentShapes/1.execution-should-succeed.omex filter=lfs diff=lfs merge=lfs -text
|
| 150 |
+
data/vcell-cli/src/test/resources/bsts-omex/synths/sedml/SimulatorSupportsModelAttributeChanges/1.execute-should-fail.omex filter=lfs diff=lfs merge=lfs -text
|
| 151 |
+
data/vcell-cli/src/test/resources/bsts-omex/synths/sedml/SimulatorSupportsModelAttributeChanges/2.execution-should-succeed.omex filter=lfs diff=lfs merge=lfs -text
|
| 152 |
+
data/vcell-cli/src/test/resources/bsts-omex/synths/sedml/SimulatorSupportsModelsSimulationsTasksDataGeneratorsAndReports/1.execution-should-succeed.omex filter=lfs diff=lfs merge=lfs -text
|
| 153 |
+
data/vcell-cli/src/test/resources/bsts-omex/synths/sedml/SimulatorSupportsMultipleReportsPerSedDocument/1.execution-should-succeed.omex filter=lfs diff=lfs merge=lfs -text
|
| 154 |
+
data/vcell-cli/src/test/resources/bsts-omex/synths/sedml/SimulatorSupportsMultipleTasksPerSedDocument/1.execution-should-succeed.omex filter=lfs diff=lfs merge=lfs -text
|
| 155 |
+
data/vcell-cli/src/test/resources/bsts-omex/synths/sedml/SimulatorSupportsRepeatedTasksWithChanges/1.execute-should-fail.omex filter=lfs diff=lfs merge=lfs -text
|
| 156 |
+
data/vcell-cli/src/test/resources/bsts-omex/synths/sedml/SimulatorSupportsRepeatedTasksWithChanges/2.execution-should-succeed.omex filter=lfs diff=lfs merge=lfs -text
|
| 157 |
+
data/vcell-cli/src/test/resources/bsts-omex/synths/sedml/SimulatorSupportsRepeatedTasksWithFunctionalRangeVariables/1.execute-should-fail.omex filter=lfs diff=lfs merge=lfs -text
|
| 158 |
+
data/vcell-cli/src/test/resources/bsts-omex/synths/sedml/SimulatorSupportsRepeatedTasksWithFunctionalRangeVariables/2.execution-should-succeed.omex filter=lfs diff=lfs merge=lfs -text
|
| 159 |
+
data/vcell-cli/src/test/resources/bsts-omex/synths/sedml/SimulatorSupportsRepeatedTasksWithFunctionalRanges/1.execution-should-succeed.omex filter=lfs diff=lfs merge=lfs -text
|
| 160 |
+
data/vcell-cli/src/test/resources/bsts-omex/synths/sedml/SimulatorSupportsRepeatedTasksWithLinearUniformRanges/1.execution-should-succeed.omex filter=lfs diff=lfs merge=lfs -text
|
| 161 |
+
data/vcell-cli/src/test/resources/bsts-omex/synths/sedml/SimulatorSupportsRepeatedTasksWithLogarithmicUniformRanges/1.execution-should-succeed.omex filter=lfs diff=lfs merge=lfs -text
|
| 162 |
+
data/vcell-cli/src/test/resources/bsts-omex/synths/sedml/SimulatorSupportsRepeatedTasksWithMultipleSubTasks/1.execution-should-succeed.omex filter=lfs diff=lfs merge=lfs -text
|
| 163 |
+
data/vcell-cli/src/test/resources/bsts-omex/synths/sedml/SimulatorSupportsRepeatedTasksWithNestedFunctionalRanges/1.execution-should-succeed.omex filter=lfs diff=lfs merge=lfs -text
|
| 164 |
+
data/vcell-cli/src/test/resources/bsts-omex/synths/sedml/SimulatorSupportsRepeatedTasksWithNestedRepeatedTasks/1.execution-should-succeed.omex filter=lfs diff=lfs merge=lfs -text
|
| 165 |
+
data/vcell-cli/src/test/resources/bsts-omex/synths/sedml/SimulatorSupportsRepeatedTasksWithSubTasksOfMixedTypes/1.execution-should-succeed.omex filter=lfs diff=lfs merge=lfs -text
|
| 166 |
+
data/vcell-cli/src/test/resources/bsts-omex/synths/sedml/SimulatorSupportsRepeatedTasksWithSubTasksOfMixedTypes/2.execution-should-succeed.omex filter=lfs diff=lfs merge=lfs -text
|
| 167 |
+
data/vcell-cli/src/test/resources/bsts-omex/synths/sedml/SimulatorSupportsRepeatedTasksWithVectorRanges/1.execution-should-succeed.omex filter=lfs diff=lfs merge=lfs -text
|
| 168 |
+
data/vcell-cli/src/test/resources/bsts-omex/synths/sedml/SimulatorSupportsSubstitutingAlgorithms/1.execute-should-fail.omex filter=lfs diff=lfs merge=lfs -text
|
| 169 |
+
data/vcell-cli/src/test/resources/bsts-omex/synths/sedml/SimulatorSupportsSubstitutingAlgorithms/2.execution-should-succeed.omex filter=lfs diff=lfs merge=lfs -text
|
| 170 |
+
data/vcell-cli/src/test/resources/bsts-omex/synths/sedml/SimulatorSupportsSubstitutingAlgorithms/3.execute-should-fail.omex filter=lfs diff=lfs merge=lfs -text
|
| 171 |
+
data/vcell-cli/src/test/resources/bsts-omex/synths/sedml/SimulatorSupportsSubstitutingAlgorithms/4.execution-should-succeed.omex filter=lfs diff=lfs merge=lfs -text
|
| 172 |
+
data/vcell-cli/src/test/resources/bsts-omex/synths/sedml/SimulatorSupportsUniformTimeCoursesWithNonZeroInitialTimes/1.execution-should-succeed.omex filter=lfs diff=lfs merge=lfs -text
|
| 173 |
+
data/vcell-cli/src/test/resources/bsts-omex/synths/sedml/SimulatorSupportsUniformTimeCoursesWithNonZeroOutputStartTimes/1.execution-should-succeed.omex filter=lfs diff=lfs merge=lfs -text
|
| 174 |
+
data/vcell-cli/src/test/resources/bsts-omex/vcml/Powers-Pflugers-Arch-2016-Drosophila-synaptic-strength.omex filter=lfs diff=lfs merge=lfs -text
|
| 175 |
+
data/vcell-cli/src/test/resources/org/vcell/cli/run/plotting/MultiplePlotsTest.omex filter=lfs diff=lfs merge=lfs -text
|
| 176 |
+
data/vcell-client/UserDocumentation/originalXML/topics/originalImages/AccessingSimResults[[:space:]]copy.psd filter=lfs diff=lfs merge=lfs -text
|
| 177 |
+
data/vcell-client/UserDocumentation/originalXML/topics/originalImages/SimResSpatialSliceView.psd filter=lfs diff=lfs merge=lfs -text
|
| 178 |
+
data/vcell-client/UserDocumentation/originalXML/topics/originalImages/analyticGeometrySubdomainOps.psd filter=lfs diff=lfs merge=lfs -text
|
| 179 |
+
data/vcell-client/UserDocumentation/originalXML/topics/originalImages/rxdiag.psd filter=lfs diff=lfs merge=lfs -text
|
| 180 |
+
data/vcell-client/UserDocumentation/originalXML/topics/originalImages/vcell.psd filter=lfs diff=lfs merge=lfs -text
|
| 181 |
+
data/vcell-client/UserDocumentation/originalXML/topics/originalImages/vcellMain.psd filter=lfs diff=lfs merge=lfs -text
|
| 182 |
+
data/vcell-client/UserDocumentation/originalXML/topics/originalImages/vcellMain.psd~master filter=lfs diff=lfs merge=lfs -text
|
| 183 |
+
data/vcell-client/src/main/resources/cubes.blend filter=lfs diff=lfs merge=lfs -text
|
| 184 |
+
data/vcell-client/src/main/resources/vcellSplash7.psd filter=lfs diff=lfs merge=lfs -text
|
| 185 |
+
data/vcell-core/src/test/resources/cbit/vcell/simdata/SimID_946368938_0_.hdf5 filter=lfs diff=lfs merge=lfs -text
|
| 186 |
+
data/vcell-rest/src/test/resources/flybrain-035.tif filter=lfs diff=lfs merge=lfs -text
|
| 187 |
+
data/vcell-rest/src/test/resources/mitosis.tif filter=lfs diff=lfs merge=lfs -text
|
| 188 |
+
data/vcell-rest/src/test/resources/small-mitosis.tif filter=lfs diff=lfs merge=lfs -text
|
data/.dockerignore
ADDED
|
@@ -0,0 +1,460 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.settings
|
| 2 |
+
|
| 3 |
+
# ignore .git and .cache folders
|
| 4 |
+
.git
|
| 5 |
+
.cache
|
| 6 |
+
|
| 7 |
+
# ignore all markdown files (md) beside all README*.md
|
| 8 |
+
*.md
|
| 9 |
+
!README*.md
|
| 10 |
+
|
| 11 |
+
### PuTTY template
|
| 12 |
+
# Private key
|
| 13 |
+
*.ppk
|
| 14 |
+
|
| 15 |
+
### Python template
|
| 16 |
+
# Byte-compiled / optimized / DLL files
|
| 17 |
+
__pycache__/
|
| 18 |
+
*.py[cod]
|
| 19 |
+
*$py.class
|
| 20 |
+
|
| 21 |
+
# C extensions
|
| 22 |
+
*.so
|
| 23 |
+
|
| 24 |
+
# Distribution / packaging
|
| 25 |
+
.Python
|
| 26 |
+
build/
|
| 27 |
+
develop-eggs/
|
| 28 |
+
dist/
|
| 29 |
+
downloads/
|
| 30 |
+
eggs/
|
| 31 |
+
.eggs/
|
| 32 |
+
lib/
|
| 33 |
+
lib64/
|
| 34 |
+
parts/
|
| 35 |
+
sdist/
|
| 36 |
+
var/
|
| 37 |
+
wheels/
|
| 38 |
+
pip-wheel-metadata/
|
| 39 |
+
share/python-wheels/
|
| 40 |
+
*.egg-info/
|
| 41 |
+
.installed.cfg
|
| 42 |
+
*.egg
|
| 43 |
+
MANIFEST
|
| 44 |
+
|
| 45 |
+
# PyInstaller
|
| 46 |
+
# Usually these files are written by a python script from a template
|
| 47 |
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
| 48 |
+
*.manifest
|
| 49 |
+
*.spec
|
| 50 |
+
|
| 51 |
+
# Installer logs
|
| 52 |
+
pip-log.txt
|
| 53 |
+
pip-delete-this-directory.txt
|
| 54 |
+
|
| 55 |
+
# Unit test / coverage reports
|
| 56 |
+
htmlcov/
|
| 57 |
+
.tox/
|
| 58 |
+
.nox/
|
| 59 |
+
.coverage
|
| 60 |
+
.coverage.*
|
| 61 |
+
nosetests.xml
|
| 62 |
+
coverage.xml
|
| 63 |
+
*.cover
|
| 64 |
+
*.py,cover
|
| 65 |
+
.hypothesis/
|
| 66 |
+
.pytest_cache/
|
| 67 |
+
cover/
|
| 68 |
+
|
| 69 |
+
# Translations
|
| 70 |
+
*.mo
|
| 71 |
+
*.pot
|
| 72 |
+
|
| 73 |
+
# Django stuff:
|
| 74 |
+
*.log
|
| 75 |
+
local_settings.py
|
| 76 |
+
db.sqlite3
|
| 77 |
+
db.sqlite3-journal
|
| 78 |
+
|
| 79 |
+
# Flask stuff:
|
| 80 |
+
instance/
|
| 81 |
+
.webassets-cache
|
| 82 |
+
|
| 83 |
+
# Scrapy stuff:
|
| 84 |
+
.scrapy
|
| 85 |
+
|
| 86 |
+
# Sphinx documentation
|
| 87 |
+
docs-misc/_build/
|
| 88 |
+
|
| 89 |
+
# PyBuilder
|
| 90 |
+
.pybuilder/
|
| 91 |
+
target/
|
| 92 |
+
|
| 93 |
+
# Jupyter Notebook
|
| 94 |
+
.ipynb_checkpoints
|
| 95 |
+
|
| 96 |
+
# IPython
|
| 97 |
+
profile_default/
|
| 98 |
+
ipython_config.py
|
| 99 |
+
|
| 100 |
+
# pyenv
|
| 101 |
+
# For a library or package, you might want to ignore these files since the code is
|
| 102 |
+
# intended to run in multiple environments; otherwise, check them in:
|
| 103 |
+
# .python-version
|
| 104 |
+
|
| 105 |
+
# pipenv
|
| 106 |
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
| 107 |
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
| 108 |
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
| 109 |
+
# install all needed dependencies.
|
| 110 |
+
#Pipfile.lock
|
| 111 |
+
|
| 112 |
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
|
| 113 |
+
__pypackages__/
|
| 114 |
+
|
| 115 |
+
# Celery stuff
|
| 116 |
+
celerybeat-schedule
|
| 117 |
+
celerybeat.pid
|
| 118 |
+
|
| 119 |
+
# SageMath parsed files
|
| 120 |
+
*.sage.py
|
| 121 |
+
|
| 122 |
+
# Environments
|
| 123 |
+
.env
|
| 124 |
+
.venv
|
| 125 |
+
env/
|
| 126 |
+
venv/
|
| 127 |
+
ENV/
|
| 128 |
+
env.bak/
|
| 129 |
+
venv.bak/
|
| 130 |
+
|
| 131 |
+
# Spyder project settings
|
| 132 |
+
.spyderproject
|
| 133 |
+
.spyproject
|
| 134 |
+
|
| 135 |
+
# Rope project settings
|
| 136 |
+
.ropeproject
|
| 137 |
+
|
| 138 |
+
# mkdocs documentation
|
| 139 |
+
/site
|
| 140 |
+
|
| 141 |
+
# mypy
|
| 142 |
+
.mypy_cache/
|
| 143 |
+
.dmypy.json
|
| 144 |
+
dmypy.json
|
| 145 |
+
|
| 146 |
+
# Pyre type checker
|
| 147 |
+
.pyre/
|
| 148 |
+
|
| 149 |
+
# pytype static type analyzer
|
| 150 |
+
.pytype/
|
| 151 |
+
|
| 152 |
+
# Cython debug symbols
|
| 153 |
+
cython_debug/
|
| 154 |
+
|
| 155 |
+
### NotepadPP template
|
| 156 |
+
# Notepad++ backups #
|
| 157 |
+
*.bak
|
| 158 |
+
|
| 159 |
+
### Xcode template
|
| 160 |
+
# Xcode
|
| 161 |
+
#
|
| 162 |
+
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
|
| 163 |
+
|
| 164 |
+
## User settings
|
| 165 |
+
xcuserdata/
|
| 166 |
+
|
| 167 |
+
## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9)
|
| 168 |
+
*.xcscmblueprint
|
| 169 |
+
*.xccheckout
|
| 170 |
+
|
| 171 |
+
## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4)
|
| 172 |
+
DerivedData/
|
| 173 |
+
*.moved-aside
|
| 174 |
+
*.pbxuser
|
| 175 |
+
!default.pbxuser
|
| 176 |
+
*.mode1v3
|
| 177 |
+
!default.mode1v3
|
| 178 |
+
*.mode2v3
|
| 179 |
+
!default.mode2v3
|
| 180 |
+
*.perspectivev3
|
| 181 |
+
!default.perspectivev3
|
| 182 |
+
|
| 183 |
+
## Gcc Patch
|
| 184 |
+
/*.gcno
|
| 185 |
+
|
| 186 |
+
### VirtualEnv template
|
| 187 |
+
# Virtualenv
|
| 188 |
+
# http://iamzed.com/2009/05/07/a-primer-on-virtualenv/
|
| 189 |
+
[Bb]in
|
| 190 |
+
[Ii]nclude
|
| 191 |
+
[Ll]ib
|
| 192 |
+
[Ll]ib64
|
| 193 |
+
[Ll]ocal
|
| 194 |
+
[Ss]cripts
|
| 195 |
+
pyvenv.cfg
|
| 196 |
+
pip-selfcheck.json
|
| 197 |
+
|
| 198 |
+
### macOS template
|
| 199 |
+
# General
|
| 200 |
+
.DS_Store
|
| 201 |
+
.AppleDouble
|
| 202 |
+
.LSOverride
|
| 203 |
+
|
| 204 |
+
# Icon must end with two \r
|
| 205 |
+
Icon
|
| 206 |
+
|
| 207 |
+
# Thumbnails
|
| 208 |
+
._*
|
| 209 |
+
|
| 210 |
+
# Files that might appear in the root of a volume
|
| 211 |
+
.DocumentRevisions-V100
|
| 212 |
+
.fseventsd
|
| 213 |
+
.Spotlight-V100
|
| 214 |
+
.TemporaryItems
|
| 215 |
+
.Trashes
|
| 216 |
+
.VolumeIcon.icns
|
| 217 |
+
.com.apple.timemachine.donotpresent
|
| 218 |
+
|
| 219 |
+
# Directories potentially created on remote AFP share
|
| 220 |
+
.AppleDB
|
| 221 |
+
.AppleDesktop
|
| 222 |
+
Network Trash Folder
|
| 223 |
+
Temporary Items
|
| 224 |
+
.apdisk
|
| 225 |
+
|
| 226 |
+
### JetBrains template
|
| 227 |
+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
|
| 228 |
+
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
| 229 |
+
|
| 230 |
+
# User-specific stuff
|
| 231 |
+
.idea/**/workspace.xml
|
| 232 |
+
.idea/**/tasks.xml
|
| 233 |
+
.idea/**/usage.statistics.xml
|
| 234 |
+
.idea/**/dictionaries
|
| 235 |
+
.idea/**/shelf
|
| 236 |
+
|
| 237 |
+
# Generated files
|
| 238 |
+
.idea/**/contentModel.xml
|
| 239 |
+
|
| 240 |
+
# Sensitive or high-churn files
|
| 241 |
+
.idea/**/dataSources/
|
| 242 |
+
.idea/**/dataSources.ids
|
| 243 |
+
.idea/**/dataSources.local.xml
|
| 244 |
+
.idea/**/sqlDataSources.xml
|
| 245 |
+
.idea/**/dynamic.xml
|
| 246 |
+
.idea/**/uiDesigner.xml
|
| 247 |
+
.idea/**/dbnavigator.xml
|
| 248 |
+
|
| 249 |
+
# Gradle
|
| 250 |
+
.idea/**/gradle.xml
|
| 251 |
+
.idea/**/libraries
|
| 252 |
+
|
| 253 |
+
# Gradle and Maven with auto-import
|
| 254 |
+
# When using Gradle or Maven with auto-import, you should exclude module files,
|
| 255 |
+
# since they will be recreated, and may cause churn. Uncomment if using
|
| 256 |
+
# auto-import.
|
| 257 |
+
# .idea/artifacts
|
| 258 |
+
# .idea/compiler.xml
|
| 259 |
+
# .idea/jarRepositories.xml
|
| 260 |
+
# .idea/modules.xml
|
| 261 |
+
# .idea/*.iml
|
| 262 |
+
# .idea/modules
|
| 263 |
+
# *.iml
|
| 264 |
+
# *.ipr
|
| 265 |
+
|
| 266 |
+
# CMake
|
| 267 |
+
cmake-build-*/
|
| 268 |
+
|
| 269 |
+
# Mongo Explorer plugin
|
| 270 |
+
.idea/**/mongoSettings.xml
|
| 271 |
+
|
| 272 |
+
# File-based project format
|
| 273 |
+
*.iws
|
| 274 |
+
|
| 275 |
+
# IntelliJ
|
| 276 |
+
out/
|
| 277 |
+
|
| 278 |
+
# result dir
|
| 279 |
+
results/
|
| 280 |
+
|
| 281 |
+
# mpeltonen/sbt-idea plugin
|
| 282 |
+
.idea_modules/
|
| 283 |
+
|
| 284 |
+
# JIRA plugin
|
| 285 |
+
atlassian-ide-plugin.xml
|
| 286 |
+
|
| 287 |
+
# Cursive Clojure plugin
|
| 288 |
+
.idea/replstate.xml
|
| 289 |
+
|
| 290 |
+
# Crashlytics plugin (for Android Studio and IntelliJ)
|
| 291 |
+
com_crashlytics_export_strings.xml
|
| 292 |
+
crashlytics.properties
|
| 293 |
+
crashlytics-build.properties
|
| 294 |
+
fabric.properties
|
| 295 |
+
|
| 296 |
+
# Editor-based Rest Client
|
| 297 |
+
.idea/httpRequests
|
| 298 |
+
|
| 299 |
+
# Android studio 3.1+ serialized cache file
|
| 300 |
+
.idea/caches/build_file_checksums.ser
|
| 301 |
+
|
| 302 |
+
### Java template
|
| 303 |
+
# Compiled class file
|
| 304 |
+
# Log file
|
| 305 |
+
# BlueJ files
|
| 306 |
+
*.ctxt
|
| 307 |
+
|
| 308 |
+
# Mobile Tools for Java (J2ME)
|
| 309 |
+
.mtj.tmp/
|
| 310 |
+
|
| 311 |
+
# Package Files #
|
| 312 |
+
*.jar
|
| 313 |
+
*.war
|
| 314 |
+
*.nar
|
| 315 |
+
*.ear
|
| 316 |
+
*.zip
|
| 317 |
+
*.tar.gz
|
| 318 |
+
*.rar
|
| 319 |
+
|
| 320 |
+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
| 321 |
+
hs_err_pid*
|
| 322 |
+
|
| 323 |
+
### C template
|
| 324 |
+
# Prerequisites
|
| 325 |
+
*.d
|
| 326 |
+
|
| 327 |
+
# Object files
|
| 328 |
+
*.o
|
| 329 |
+
*.ko
|
| 330 |
+
*.obj
|
| 331 |
+
*.elf
|
| 332 |
+
|
| 333 |
+
# Linker output
|
| 334 |
+
*.ilk
|
| 335 |
+
*.map
|
| 336 |
+
*.exp
|
| 337 |
+
|
| 338 |
+
# Precompiled Headers
|
| 339 |
+
*.gch
|
| 340 |
+
*.pch
|
| 341 |
+
|
| 342 |
+
# Libraries
|
| 343 |
+
*.lib
|
| 344 |
+
*.a
|
| 345 |
+
*.la
|
| 346 |
+
*.lo
|
| 347 |
+
|
| 348 |
+
# Shared objects (inc. Windows DLLs)
|
| 349 |
+
*.dll
|
| 350 |
+
*.so.*
|
| 351 |
+
*.dylib
|
| 352 |
+
|
| 353 |
+
# Executables
|
| 354 |
+
*.exe
|
| 355 |
+
*.out
|
| 356 |
+
*.app
|
| 357 |
+
*.i*86
|
| 358 |
+
*.x86_64
|
| 359 |
+
*.hex
|
| 360 |
+
|
| 361 |
+
# Debug files
|
| 362 |
+
*.dSYM/
|
| 363 |
+
*.su
|
| 364 |
+
*.idb
|
| 365 |
+
*.pdb
|
| 366 |
+
|
| 367 |
+
# Kernel Module Compile Results
|
| 368 |
+
*.mod*
|
| 369 |
+
*.cmd
|
| 370 |
+
.tmp_versions/
|
| 371 |
+
modules.order
|
| 372 |
+
Module.symvers
|
| 373 |
+
Mkfile.old
|
| 374 |
+
dkms.conf
|
| 375 |
+
|
| 376 |
+
### C++ template
|
| 377 |
+
# Prerequisites
|
| 378 |
+
# Compiled Object files
|
| 379 |
+
*.slo
|
| 380 |
+
# Precompiled Headers
|
| 381 |
+
# Compiled Dynamic libraries
|
| 382 |
+
# Fortran module files
|
| 383 |
+
*.mod
|
| 384 |
+
*.smod
|
| 385 |
+
|
| 386 |
+
# Compiled Static libraries
|
| 387 |
+
*.lai
|
| 388 |
+
# Executables
|
| 389 |
+
### VisualStudioCode template
|
| 390 |
+
.vscode/*
|
| 391 |
+
!.vscode/settings.json
|
| 392 |
+
!.vscode/tasks.json
|
| 393 |
+
!.vscode/launch.json
|
| 394 |
+
!.vscode/extensions.json
|
| 395 |
+
*.code-workspace
|
| 396 |
+
|
| 397 |
+
# Local History for Visual Studio Code
|
| 398 |
+
.history/
|
| 399 |
+
|
| 400 |
+
### Eclipse template
|
| 401 |
+
.metadata
|
| 402 |
+
bin/
|
| 403 |
+
tmp/
|
| 404 |
+
*.tmp
|
| 405 |
+
*.swp
|
| 406 |
+
*~.nib
|
| 407 |
+
local.properties
|
| 408 |
+
.settings/
|
| 409 |
+
.loadpath
|
| 410 |
+
.recommenders
|
| 411 |
+
|
| 412 |
+
# External tool builders
|
| 413 |
+
.externalToolBuilders/
|
| 414 |
+
|
| 415 |
+
# Locally stored "Eclipse launch configurations"
|
| 416 |
+
*.launch
|
| 417 |
+
|
| 418 |
+
# PyDev specific (Python IDE for Eclipse)
|
| 419 |
+
*.pydevproject
|
| 420 |
+
|
| 421 |
+
# CDT-specific (C/C++ Development Tooling)
|
| 422 |
+
.cproject
|
| 423 |
+
|
| 424 |
+
# CDT- autotools
|
| 425 |
+
.autotools
|
| 426 |
+
|
| 427 |
+
# Java annotation processor (APT)
|
| 428 |
+
.factorypath
|
| 429 |
+
|
| 430 |
+
# PDT-specific (PHP Development Tools)
|
| 431 |
+
.buildpath
|
| 432 |
+
|
| 433 |
+
# sbteclipse plugin
|
| 434 |
+
.target
|
| 435 |
+
|
| 436 |
+
# Tern plugin
|
| 437 |
+
.tern-project
|
| 438 |
+
|
| 439 |
+
# TeXlipse plugin
|
| 440 |
+
.texlipse
|
| 441 |
+
|
| 442 |
+
# STS (Spring Tool Suite)
|
| 443 |
+
.springBeans
|
| 444 |
+
|
| 445 |
+
# Code Recommenders
|
| 446 |
+
.recommenders/
|
| 447 |
+
|
| 448 |
+
# Annotation Processing
|
| 449 |
+
.apt_generated/
|
| 450 |
+
.apt_generated_test/
|
| 451 |
+
|
| 452 |
+
# Scala IDE specific (Scala & Java development for Eclipse)
|
| 453 |
+
.cache-main
|
| 454 |
+
.scala_dependencies
|
| 455 |
+
.worksheet
|
| 456 |
+
|
| 457 |
+
# Uncomment this line if you wish to ignore the project description file.
|
| 458 |
+
# Typically, this file would be tracked if it contains build/dependency configurations:
|
| 459 |
+
#.project
|
| 460 |
+
|
data/.mailmap
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Anvin Thomas <anvin@localhost>
|
| 2 |
+
Frank Morgan <frm@uchc.edu> <frm@frmdev2.cam.uchc.edu>
|
| 3 |
+
Jim Schaff <schaff@uchc.edu> <schaff@nrcamdev5.cam.uchc.edu>
|
| 4 |
+
Kevin Gaffney <kgaffney@localhost>
|
| 5 |
+
Mike Wilson <mpw6@users.noreply.github.com>
|
data/.quarkus/cli/plugins/quarkus-cli-catalog.json
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"version" : "v1",
|
| 3 |
+
"lastUpdate" : "01/11/2023 16:25:33",
|
| 4 |
+
"plugins" : { }
|
| 5 |
+
}
|
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Contributor Covenant Code of Conduct
|
| 2 |
+
|
| 3 |
+
## Our Pledge
|
| 4 |
+
|
| 5 |
+
We as members, contributors, and leaders pledge to make participation in our
|
| 6 |
+
community a harassment-free experience for everyone, regardless of age, body
|
| 7 |
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
| 8 |
+
identity and expression, level of experience, education, socio-economic status,
|
| 9 |
+
nationality, personal appearance, race, religion, or sexual identity
|
| 10 |
+
and orientation.
|
| 11 |
+
|
| 12 |
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
| 13 |
+
diverse, inclusive, and healthy community.
|
| 14 |
+
|
| 15 |
+
## Our Standards
|
| 16 |
+
|
| 17 |
+
Examples of behavior that contributes to a positive environment for our
|
| 18 |
+
community include:
|
| 19 |
+
|
| 20 |
+
* Demonstrating empathy and kindness toward other people
|
| 21 |
+
* Being respectful of differing opinions, viewpoints, and experiences
|
| 22 |
+
* Giving and gracefully accepting constructive feedback
|
| 23 |
+
* Accepting responsibility and apologizing to those affected by our mistakes,
|
| 24 |
+
and learning from the experience
|
| 25 |
+
* Focusing on what is best not just for us as individuals, but for the
|
| 26 |
+
overall community
|
| 27 |
+
|
| 28 |
+
Examples of unacceptable behavior include:
|
| 29 |
+
|
| 30 |
+
* The use of sexualized language or imagery, and sexual attention or
|
| 31 |
+
advances of any kind
|
| 32 |
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
| 33 |
+
* Public or private harassment
|
| 34 |
+
* Publishing others' private information, such as a physical or email
|
| 35 |
+
address, without their explicit permission
|
| 36 |
+
* Other conduct which could reasonably be considered inappropriate in a
|
| 37 |
+
professional setting
|
| 38 |
+
|
| 39 |
+
## Enforcement Responsibilities
|
| 40 |
+
|
| 41 |
+
Community leaders are responsible for clarifying and enforcing our standards of
|
| 42 |
+
acceptable behavior and will take appropriate and fair corrective action in
|
| 43 |
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
| 44 |
+
or harmful.
|
| 45 |
+
|
| 46 |
+
Community leaders have the right and responsibility to remove, edit, or reject
|
| 47 |
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
| 48 |
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
| 49 |
+
decisions when appropriate.
|
| 50 |
+
|
| 51 |
+
## Scope
|
| 52 |
+
|
| 53 |
+
This Code of Conduct applies within all community spaces, and also applies when
|
| 54 |
+
an individual is officially representing the community in public spaces.
|
| 55 |
+
Examples of representing our community include using an official e-mail address,
|
| 56 |
+
posting via an official social media account, or acting as an appointed
|
| 57 |
+
representative at an online or offline event.
|
| 58 |
+
|
| 59 |
+
## Enforcement
|
| 60 |
+
|
| 61 |
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
| 62 |
+
reported to the community leaders responsible for enforcement at
|
| 63 |
+
[vcell_support@uchc.edu](mailto:vcell_support@uchc.edu).
|
| 64 |
+
All complaints will be reviewed and investigated promptly and fairly.
|
| 65 |
+
|
| 66 |
+
All community leaders are obligated to respect the privacy and security of the
|
| 67 |
+
reporter of any incident.
|
| 68 |
+
|
| 69 |
+
## Enforcement Guidelines
|
| 70 |
+
|
| 71 |
+
Community leaders will follow these Community Impact Guidelines in determining
|
| 72 |
+
the consequences for any action they deem in violation of this Code of Conduct:
|
| 73 |
+
|
| 74 |
+
### 1. Correction
|
| 75 |
+
|
| 76 |
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
| 77 |
+
unprofessional or unwelcome in the community.
|
| 78 |
+
|
| 79 |
+
**Consequence**: A private, written warning from community leaders, providing
|
| 80 |
+
clarity around the nature of the violation and an explanation of why the
|
| 81 |
+
behavior was inappropriate. A public apology may be requested.
|
| 82 |
+
|
| 83 |
+
### 2. Warning
|
| 84 |
+
|
| 85 |
+
**Community Impact**: A violation through a single incident or series
|
| 86 |
+
of actions.
|
| 87 |
+
|
| 88 |
+
**Consequence**: A warning with consequences for continued behavior. No
|
| 89 |
+
interaction with the people involved, including unsolicited interaction with
|
| 90 |
+
those enforcing the Code of Conduct, for a specified period of time. This
|
| 91 |
+
includes avoiding interactions in community spaces as well as external channels
|
| 92 |
+
like social media. Violating these terms may lead to a temporary or
|
| 93 |
+
permanent ban.
|
| 94 |
+
|
| 95 |
+
### 3. Temporary Ban
|
| 96 |
+
|
| 97 |
+
**Community Impact**: A serious violation of community standards, including
|
| 98 |
+
sustained inappropriate behavior.
|
| 99 |
+
|
| 100 |
+
**Consequence**: A temporary ban from any sort of interaction or public
|
| 101 |
+
communication with the community for a specified period of time. No public or
|
| 102 |
+
private interaction with the people involved, including unsolicited interaction
|
| 103 |
+
with those enforcing the Code of Conduct, is allowed during this period.
|
| 104 |
+
Violating these terms may lead to a permanent ban.
|
| 105 |
+
|
| 106 |
+
### 4. Permanent Ban
|
| 107 |
+
|
| 108 |
+
**Community Impact**: Demonstrating a pattern of violation of community
|
| 109 |
+
standards, including sustained inappropriate behavior, harassment of an
|
| 110 |
+
individual, or aggression toward or disparagement of classes of individuals.
|
| 111 |
+
|
| 112 |
+
**Consequence**: A permanent ban from any sort of public interaction within
|
| 113 |
+
the community.
|
| 114 |
+
|
| 115 |
+
## Attribution
|
| 116 |
+
|
| 117 |
+
This Code of Conduct is adapted from the [Contributor Covenant](https://www.contributor-covenant.org/version/2/0/code_of_conduct.html).
|
| 118 |
+
|
| 119 |
+
The Community Impact Guidelines were inspired by [Mozilla's Code of Conduct Enforcement ladder](https://github.com/mozilla/diversity).
|
| 120 |
+
|
| 121 |
+
Answers to common questions about this code of conduct are available at
|
| 122 |
+
https://www.contributor-covenant.org/faq. Translations of this code of conduct are available at
|
| 123 |
+
https://www.contributor-covenant.org/translations.
|
data/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Guide to contributing to the Virtual Cell
|
| 2 |
+
|
| 3 |
+
We believe - and we hope you do too - that learning how to code, how to think, and how to contribute to open source can delegate the next generation of coders and creators. We exuberantly welcome contributions to Virtual Cell! This document describes how developers can contribute to the Virtual Cell. Modelers can contribute new models to VCell via multi-platform standalone application downloading from http://vcell.org.
|
| 4 |
+
|
| 5 |
+
If you have never contributed to an open-source project before and you’re just getting started, consider exploring these resources.
|
| 6 |
+
|
| 7 |
+
[A Step by Step Guide to Making Your First GitHub Contribution](https://codeburst.io/a-step-by-step-guide-to-making-your-first-github-contribution-5302260a2940)
|
| 8 |
+
|
| 9 |
+
[How to Contribute to Open Source](https://opensource.guide/how-to-contribute/)
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
To get some insights about Github terminologies, consider exploring these resources.
|
| 13 |
+
|
| 14 |
+
[Collaborating With Issues And Pull Requests](https://help.github.com/categories/collaborating-with-issues-and-pull-requests/)
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
If you are still facing some issues while contributing to the repository, please reach us on [VCell Support](mailto:vcell_support@uchc.edu).
|
| 18 |
+
|
| 19 |
+
**Note** : Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
## Coordinating contributions, Issues, and bugs
|
| 23 |
+
|
| 24 |
+
Before getting started, please contact the lead developers at [vcell_support@uchc.edu](mailto:vcell_support@uchc.edu) to coordinate your planned contributions with other ongoing efforts. VCell Support is open at all junctures, emails about issues, bugs, and enhancements.
|
| 25 |
+
|
| 26 |
+
## Setting up your development environment
|
| 27 |
+
|
| 28 |
+
To contribute to Virtual Cell, please follow README.MD file instructions to the setup development environment.
|
| 29 |
+
|
| 30 |
+
## Submitting changes
|
| 31 |
+
|
| 32 |
+
Please use GitHub pull requests to submit changes. Each submission should include a brief description of the new and/or modified features upon each pull request. Pull requests will be approved after the review by one of the developers.
|
| 33 |
+
|
| 34 |
+
|
data/Dockerfile
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM eclipse-temurin:17-jammy as jre-build
|
| 2 |
+
|
| 3 |
+
# Create a custom Java runtime
|
| 4 |
+
RUN $JAVA_HOME/bin/jlink \
|
| 5 |
+
--add-modules ALL-MODULE-PATH \
|
| 6 |
+
--strip-debug \
|
| 7 |
+
--no-man-pages \
|
| 8 |
+
--no-header-files \
|
| 9 |
+
--compress=2 \
|
| 10 |
+
--output /javaruntime
|
| 11 |
+
|
| 12 |
+
# Define base image and copy in jlink created minimal Java 17 environment
|
| 13 |
+
FROM ubuntu:jammy
|
| 14 |
+
ENV JAVA_HOME=/opt/java/openjdk
|
| 15 |
+
ENV PATH "${JAVA_HOME}/bin:${PATH}"
|
| 16 |
+
COPY --from=jre-build /javaruntime $JAVA_HOME
|
| 17 |
+
|
| 18 |
+
# now we have Java 17 and Python 3.9
|
| 19 |
+
ARG SIMULATOR_VERSION="7.5.0.11"
|
| 20 |
+
ARG MAX_JAVA_MEM=0
|
| 21 |
+
# Make sure you don't sap all of docker's memory when you set this.
|
| 22 |
+
ENV ENV_SIMULATOR_VERSION=$SIMULATOR_VERSION
|
| 23 |
+
ENV MAX_JAVA_MEM_MB=$MAX_JAVA_MEM
|
| 24 |
+
|
| 25 |
+
# metadata
|
| 26 |
+
LABEL \
|
| 27 |
+
org.opencontainers.image.title="VCell" \
|
| 28 |
+
org.opencontainers.image.version="${SIMULATOR_VERSION}" \
|
| 29 |
+
org.opencontainers.image.description="Open-source software package for modeling cell biological systems that is built on a central database and disseminated as a standalone application." \
|
| 30 |
+
org.opencontainers.image.url="http://vcell.org/" \
|
| 31 |
+
org.opencontainers.image.documentation="https://vcell.org/support" \
|
| 32 |
+
org.opencontainers.image.source="https://github.com/biosimulators/Biosimulators_VCell" \
|
| 33 |
+
org.opencontainers.image.authors="BioSimulators Team <info@biosimulators.org>" \
|
| 34 |
+
org.opencontainers.image.vendor="BioSimulators Team" \
|
| 35 |
+
org.opencontainers.image.licenses="MIT" \
|
| 36 |
+
\
|
| 37 |
+
base_image="ubuntu:22.04" \
|
| 38 |
+
version="${SIMULATOR_VERSION}" \
|
| 39 |
+
software="Virtual Cell" \
|
| 40 |
+
software.version="${SIMULATOR_VERSION}" \
|
| 41 |
+
about.summary="Open-source software package for modeling cell biological systems that is built on a central database and disseminated as a standalone application." \
|
| 42 |
+
about.home="http://vcell.org/" \
|
| 43 |
+
about.documentation="https://vcell.org/support" \
|
| 44 |
+
about.license_file="https://github.com/virtualcell/vcell/blob/master/license.txt" \
|
| 45 |
+
about.license="SPDX:MIT" \
|
| 46 |
+
about.tags="rule-based modeling,kinetic modeling,dynamical simulation,systems biology,BNGL,SED-ML,COMBINE,OMEX" \
|
| 47 |
+
maintainer="BioSimulators Team <info@biosimulators.org>"
|
| 48 |
+
|
| 49 |
+
ENV DEBIAN_FRONTEND noninteractive
|
| 50 |
+
RUN apt -y update && apt install -y software-properties-common
|
| 51 |
+
RUN apt install -y --no-install-recommends curl python3.10 python3-pip build-essential dnsutils \
|
| 52 |
+
apt-utils libfreetype6 fontconfig fonts-dejavu
|
| 53 |
+
|
| 54 |
+
RUN mkdir -p /usr/local/app/vcell/lib && \
|
| 55 |
+
mkdir -p /usr/local/app/vcell/simulation && \
|
| 56 |
+
mkdir -p /usr/local/app/vcell/installDir && \
|
| 57 |
+
mkdir -p /usr/local/app/vcell/installDir/python/vcell_cli_utils && \
|
| 58 |
+
mkdir -p /usr/local/app/vcell/installDir/bionetgen
|
| 59 |
+
|
| 60 |
+
RUN python3 -m pip install poetry && poetry config cache-dir "/poetry/.cache"
|
| 61 |
+
ENV PATH="/root/.poetry/bin:/root/.local/bin:$PATH"
|
| 62 |
+
|
| 63 |
+
# Copy JAR files
|
| 64 |
+
COPY ./vcell-cli/target/vcell-cli-0.0.1-SNAPSHOT.jar \
|
| 65 |
+
./vcell-cli/target/maven-jars/*.jar \
|
| 66 |
+
/usr/local/app/vcell/lib/
|
| 67 |
+
|
| 68 |
+
# Install required python-packages
|
| 69 |
+
COPY ./vcell-cli-utils/ /usr/local/app/vcell/installDir/python/vcell_cli_utils/
|
| 70 |
+
RUN cd /usr/local/app/vcell/installDir/python/vcell_cli_utils/ && \
|
| 71 |
+
poetry config cache-dir "/poetry/.cache" --local && \
|
| 72 |
+
chmod 755 poetry.toml && \
|
| 73 |
+
poetry install
|
| 74 |
+
|
| 75 |
+
# Add linux local solvers only
|
| 76 |
+
ADD ./localsolvers /usr/local/app/vcell/installDir/localsolvers
|
| 77 |
+
ADD ./nativelibs /usr/local/app/vcell/installDir/nativelibs
|
| 78 |
+
COPY ./docker_run.sh /usr/local/app/vcell/installDir/
|
| 79 |
+
COPY ./bionetgen/BNG2.pl ./bionetgen/*.txt ./bionetgen/VERSION /usr/local/app/vcell/installDir/bionetgen/
|
| 80 |
+
COPY ./bionetgen/Perl2 /usr/local/app/vcell/installDir/bionetgen/Perl2
|
| 81 |
+
COPY ./biosimulations_log4j2.xml /usr/local/app/vcell/installDir/
|
| 82 |
+
|
| 83 |
+
# Declare supported environment variables
|
| 84 |
+
ENV ALGORITHM_SUBSTITUTION_POLICY=SIMILAR_VARIABLES
|
| 85 |
+
EXPOSE 1433
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
# Entrypoint
|
| 89 |
+
ENTRYPOINT ["/usr/local/app/vcell/installDir/docker_run.sh"]
|
| 90 |
+
CMD []
|
data/README_BioSim.md
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+

|
| 2 |
+
[](https://github.com/biosimulators/Biosimulators_vcell/issues)
|
| 3 |
+
|
| 4 |
+
---
|
| 5 |
+
# Biosimulators_vcell
|
| 6 |
+
BioSimulators-compliant command-line interface to the [VCell](http://vcell.org/) simulation program.
|
| 7 |
+
|
| 8 |
+
## Contents
|
| 9 |
+
* [Installation](#installation)
|
| 10 |
+
* [Project setup IntelliJ IDEA](#to-setup-the-project-in-intellij-idea)
|
| 11 |
+
* [Project setup Eclipse](#to-setup-the-project-in-eclipse)
|
| 12 |
+
* [Maven installation](#maven-installation-package)
|
| 13 |
+
* [Usage](#local-usage)
|
| 14 |
+
* [License](#license)
|
| 15 |
+
* [Development team](#development-team)
|
| 16 |
+
* [Questions and comments](#questions-and-comments)
|
| 17 |
+
|
| 18 |
+
## Installation
|
| 19 |
+
|
| 20 |
+
### To set up the project in IntelliJ IDEA
|
| 21 |
+
* Requirements: Git, Maven, Python 3.10, Poetry, Jetbrains IntelliJ IDEA and Java JDK 17
|
| 22 |
+
1. Clone the repo
|
| 23 |
+
2. Open the project as new project in IntelliJ
|
| 24 |
+
3. Go to `Files` > `Project Structure...` > `Modules` and select all modules and then click apply.
|
| 25 |
+
4. follow instructions in [README.md](./README.md) to build python dependencies
|
| 26 |
+
5. Run `mvn clean install dependency:copy-dependencies` to build the project
|
| 27 |
+
6. For creating Run/Debug Configurations:
|
| 28 |
+
* Go to `Run/Debug Configurations` > `+` > select `Application`
|
| 29 |
+
* Name it `VCell-CLI`
|
| 30 |
+
* Now setup the configuration
|
| 31 |
+
* Add `org.vcell.cli.CLIStandalone` for `Main class:`
|
| 32 |
+
* For `VM options:`
|
| 33 |
+
```
|
| 34 |
+
-Dvcell.installDir=<Your-Project-Directory-Path>
|
| 35 |
+
-Dvcell.softwareVersion="frm_VCell_7.2"
|
| 36 |
+
```
|
| 37 |
+
* eg for `<Your-Project-Directory-Path>`: `/Users/akhil/projects/Biosimulators_vcell`
|
| 38 |
+
* Add `-h` for `Program arguments:` (refer [Local Usage](#local-usage) for more options)
|
| 39 |
+
* `Working Directory:` is `<Your-Project-Directory-Path>`
|
| 40 |
+
* Select `vcell-cli` as `Use classpath of module:`
|
| 41 |
+
8. Click `apply` and `build`
|
| 42 |
+
|
| 43 |
+
### To setup the project in Eclipse
|
| 44 |
+
* Requirements: Git, Maven, Python 3.10, Poetry, Eclipse IDE and Java JDK 17
|
| 45 |
+
1. Open terminal, navigate to the Eclipse workspace folder.
|
| 46 |
+
2. Clone the repo
|
| 47 |
+
3. follow instructions in [README.md](./README.md) to build python dependencies
|
| 48 |
+
4. Run `mvn clean install dependency:copy-dependencies` to build the project
|
| 49 |
+
4. Open Eclipse, Import the project using Maven. Depending on the Eclipse version there'll be small differences with the importing steps.
|
| 50 |
+
5. Create a `Debug configuration` as a `Java Application`.
|
| 51 |
+
* the Main Class is `org.vcell.cli.CLIStandalone`
|
| 52 |
+
* Leave the 'Program Arguments' blank.
|
| 53 |
+
* The VM needed arguments are:
|
| 54 |
+
```
|
| 55 |
+
-Dvcell.installDir=<Your-Project-Directory-Path>
|
| 56 |
+
-Dvcell.softwareVersion="VCell_7.3.0.0"
|
| 57 |
+
```
|
| 58 |
+
|
| 59 |
+
### Program arguments for both Eclipse and IntelliJ
|
| 60 |
+
|
| 61 |
+
1. For running a simulation from OMEX and VCML files as an input:
|
| 62 |
+
`-i "/PATH/TO/OMEX/OR/VCML" -o "/PATH/TO/SAVE"`
|
| 63 |
+
2. For converting a VCML to OMEX file:
|
| 64 |
+
`convert -i "/PATH/TO/VCML" -o "/PATH/TO/SAVE/OMEX"`
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
### Maven installation package
|
| 68 |
+
|
| 69 |
+
` `
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
### Install Docker image
|
| 74 |
+
```
|
| 75 |
+
docker pull ghcr.io/biosimulators/vcell
|
| 76 |
+
```
|
| 77 |
+
|
| 78 |
+
## Local usage
|
| 79 |
+
```
|
| 80 |
+
usage: vcell [-h] [-d] [-q] -i ARCHIVE [-o OUT_DIR] [-v]
|
| 81 |
+
|
| 82 |
+
BioSimulators-compliant command-line interface to the VCELL simulation program <http://vcell.org>.
|
| 83 |
+
|
| 84 |
+
optional arguments:
|
| 85 |
+
-h, --help show this help message and exit
|
| 86 |
+
-d, --debug full application debug mode
|
| 87 |
+
-q, --quiet suppress all console output
|
| 88 |
+
-i ARCHIVE, --archive ARCHIVE
|
| 89 |
+
Path to OMEX file which contains one or more SED-ML-
|
| 90 |
+
encoded simulation experiments or VCML file
|
| 91 |
+
-o OUT_DIR, --out-dir OUT_DIR
|
| 92 |
+
Directory to save outputs
|
| 93 |
+
-v, --version show program's version number and exit
|
| 94 |
+
```
|
| 95 |
+
|
| 96 |
+
## Usage through Docker container
|
| 97 |
+
```
|
| 98 |
+
docker run \
|
| 99 |
+
--tty \
|
| 100 |
+
--rm \
|
| 101 |
+
--mount type=bind,source="$(pwd)"/tests/fixtures,target=/root/in,readonly \
|
| 102 |
+
--mount type=bind,source="$(pwd)"/tests/results,target=/root/out \
|
| 103 |
+
ghcr.io/biosimulators/vcell:latest \
|
| 104 |
+
-i /root/in/BIOMD0000000297.omex \
|
| 105 |
+
-o /root/out
|
| 106 |
+
```
|
| 107 |
+
|
| 108 |
+
## License
|
| 109 |
+
This package is released under the [MIT license](LICENSE).
|
| 110 |
+
|
| 111 |
+
## Development team
|
| 112 |
+
This package was developed by the BioSimulators Team of the [Center for Reproducible Biomedical Modeling](https://reproduciblebiomodels.org).
|
| 113 |
+
|
| 114 |
+
## Questions and comments
|
| 115 |
+
Please contact the [BioSimulators Team](mailto:info@biosimulators.org) with any questions or comments.
|
data/auto.docker
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/opt/vcelldata -fstype=nfs,tcp,hard,intr,noatime,nfsvers=3 cfs05:/vcellroot
|
| 2 |
+
|
data/auto.vcellapps
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# +auto.vcellapps
|
| 2 |
+
vcell5parallel -fstype=nfs,tcp,noac,nosharecache,hard,intr,noatime,nfsvers=3 cfs09:/vcell5
|
| 3 |
+
vcell3parallel -fstype=nfs,tcp,hard,intr,noatime,noac,nfsvers=3 cfs09:/vcellparallel
|
| 4 |
+
vcell2 -fstype=nfs,tcp,hard,intr,noatime,nfsvers=3 cfs02:/ifs/RAID/vcell
|
| 5 |
+
vcell3 -fstype=nfs,tcp,hard,intr,noatime,nfsvers=3 cfs09:/vcell
|
| 6 |
+
vcell7 -fstype=nfs,tcp,hard,intr,noatime,nfsvers=3 cfs07:/ifs/vcell
|
| 7 |
+
vcell5 -fstype=nfs,tcp,hard,intr,noatime,nosharecache,nfsvers=3 cfs09:/vcell5
|
| 8 |
+
vcell10 -fstype=nfs,tcp,hard,intr,noatime,nosharecache,nfsvers=3 cfs10:/vcell
|
| 9 |
+
vcell12 -fstype=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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/perl
|
| 2 |
+
|
| 3 |
+
# BioNetGen : rule-based modeling language and simulation platform
|
| 4 |
+
#
|
| 5 |
+
# Copyright (C) 2006,2009,2012 by
|
| 6 |
+
#
|
| 7 |
+
# James R. Faeder (faeder at pitt dot edu)
|
| 8 |
+
# Justin S. Hogg (justinshogg at gmail dot com)
|
| 9 |
+
# Leonard A. Harris (lh64 at cornell dot com)
|
| 10 |
+
# John A. P. Sekar (johnarul dot sekar at gmail dot com)
|
| 11 |
+
# Jose Juan Tapia
|
| 12 |
+
# Arshi Arora
|
| 13 |
+
#
|
| 14 |
+
# This program is free software: you can redistribute it and/or modify
|
| 15 |
+
# it under the terms of the GNU General Public License as published by
|
| 16 |
+
# the Free Software Foundation, either version 3 of the License, or
|
| 17 |
+
# (at your option) any later version.
|
| 18 |
+
#
|
| 19 |
+
# This program is distributed in the hope that it will be useful,
|
| 20 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 21 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 22 |
+
# GNU General Public License for more details.
|
| 23 |
+
#
|
| 24 |
+
# You should have received a copy of the GNU General Public License
|
| 25 |
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
| 26 |
+
|
| 27 |
+
# pragmas
|
| 28 |
+
use strict;
|
| 29 |
+
use warnings;
|
| 30 |
+
|
| 31 |
+
# Perl Modules
|
| 32 |
+
use Config;
|
| 33 |
+
use File::Spec;
|
| 34 |
+
use FindBin;
|
| 35 |
+
use Getopt::Long;
|
| 36 |
+
use IO::Handle;
|
| 37 |
+
|
| 38 |
+
# get Perl2 Module directory: look for environment variables BNGPATH or BioNetGenRoot.
|
| 39 |
+
# If neither are defined, use RealBin module
|
| 40 |
+
use lib File::Spec->catdir( ( exists $ENV{'BNGPATH'}
|
| 41 |
+
? $ENV{'BNGPATH'}
|
| 42 |
+
: ( exists $ENV{'BioNetGenRoot'}
|
| 43 |
+
? $ENV{'BioNetGenRoot'}
|
| 44 |
+
: $FindBin::RealBin
|
| 45 |
+
)
|
| 46 |
+
),
|
| 47 |
+
'Perl2'
|
| 48 |
+
);
|
| 49 |
+
# BNG Modules
|
| 50 |
+
use BNGUtils;
|
| 51 |
+
use BNGModel;
|
| 52 |
+
use Console;
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
# Set up Signal Handlers..
|
| 56 |
+
# Define global variable to store PID of child process.
|
| 57 |
+
$::CHILD_PID = undef;
|
| 58 |
+
# Get signal names
|
| 59 |
+
my $i = 0;
|
| 60 |
+
my %SIGNO=();
|
| 61 |
+
defined($Config{sig_name}) or die "No signals defined";
|
| 62 |
+
foreach my $signame ( split " ", $Config{sig_name} )
|
| 63 |
+
{
|
| 64 |
+
$SIGNO{$signame} = $i;
|
| 65 |
+
$i++;
|
| 66 |
+
}
|
| 67 |
+
# TERM signal handler: make sure any child processes are shutdown before termination
|
| 68 |
+
$SIG{'TERM'} = sub
|
| 69 |
+
{
|
| 70 |
+
if (defined $::CHILD_PID)
|
| 71 |
+
{ # kill off child process
|
| 72 |
+
print "\n>>> relaying TERM signal to child with PID: ", $::CHILD_PID, " <<<\n";
|
| 73 |
+
kill $SIGNO{"TERM"}, $::CHILD_PID;
|
| 74 |
+
}
|
| 75 |
+
exit_error( sprintf "BioNetGen received TERM signal (%d)", $SIGNO{"TERM"} );
|
| 76 |
+
};
|
| 77 |
+
# INT signal handler: make sure any child processes are shutdown before termination
|
| 78 |
+
$SIG{'INT'} = sub
|
| 79 |
+
{
|
| 80 |
+
if (defined $::CHILD_PID)
|
| 81 |
+
{ # kill off child process
|
| 82 |
+
print "\n>>> relaying INT signal to child with PID: ", $::CHILD_PID, " <<<\n";
|
| 83 |
+
kill $SIGNO{"INT"}, $::CHILD_PID;
|
| 84 |
+
}
|
| 85 |
+
exit_error( sprintf "BioNetGen received TERM signal (%d)", $SIGNO{"INT"} );
|
| 86 |
+
};
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
# Defaults params for File mode
|
| 91 |
+
my %default_args = ( 'write_xml' => 0, 'write_mfile' => 0,
|
| 92 |
+
'write_SBML' => 0, 'generate_network' => 0,
|
| 93 |
+
'skip_actions' => 0, 'action_skip_warn' => 1,
|
| 94 |
+
'logging' => 0, 'no_exec' => 0,
|
| 95 |
+
'allow_perl' => 0, 'no_nfsim' => 0,
|
| 96 |
+
'output_dir' => File::Spec->curdir(),
|
| 97 |
+
'no_atomizer' => 0,
|
| 98 |
+
'write_autos' => 0
|
| 99 |
+
);
|
| 100 |
+
# Default params for Console mode
|
| 101 |
+
my %default_args_console = ( 'write_xml' => 0, 'write_mfile' => 0,
|
| 102 |
+
'write_SBML' => 0, 'generate_network' => 0,
|
| 103 |
+
'skip_actions' => 1, 'action_skip_warn' => 1,
|
| 104 |
+
'logging' => 0, 'no_exec' => 0,
|
| 105 |
+
'allow_perl' => 0, 'no_nfsim' => 0,
|
| 106 |
+
'output_dir' => File::Spec->curdir(),
|
| 107 |
+
'no_atomizer' => 0,
|
| 108 |
+
'write_autos' => 0
|
| 109 |
+
);
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
# variables to contain user args
|
| 113 |
+
my $console = 0;
|
| 114 |
+
my $findbin = '';
|
| 115 |
+
my $help = 0;
|
| 116 |
+
my $version = 0;
|
| 117 |
+
my %user_args = ( 'console' => \$console,
|
| 118 |
+
'findbin' => \$findbin,
|
| 119 |
+
'help' => \$help,
|
| 120 |
+
'version' => \$version
|
| 121 |
+
);
|
| 122 |
+
|
| 123 |
+
# parse command line arguments
|
| 124 |
+
GetOptions( \%user_args,
|
| 125 |
+
'help|h',
|
| 126 |
+
'version|v',
|
| 127 |
+
'console',
|
| 128 |
+
'findbin=s',
|
| 129 |
+
'skip_actions|check',
|
| 130 |
+
'no_nfsim|no-nfsim',
|
| 131 |
+
'no_atomizer|no-atomizer',
|
| 132 |
+
'output_dir|outdir=s',
|
| 133 |
+
'logging|log',
|
| 134 |
+
'generate_network|netgen',
|
| 135 |
+
'write_SBML|sbml',
|
| 136 |
+
'write_mfile|mfile',
|
| 137 |
+
'write_xml|xml',
|
| 138 |
+
'write_autos|autos'
|
| 139 |
+
)
|
| 140 |
+
or die "Error in command line arguments (try: BNG2.pl --help)";
|
| 141 |
+
|
| 142 |
+
# display help if requested
|
| 143 |
+
if ($help)
|
| 144 |
+
{
|
| 145 |
+
display_help();
|
| 146 |
+
exit(0);
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
# display version info
|
| 150 |
+
if ($version)
|
| 151 |
+
{
|
| 152 |
+
printf "BioNetGen version %s\n", BNGversion();
|
| 153 |
+
exit(0);
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
# try to find binary
|
| 157 |
+
if (not( $findbin eq ''))
|
| 158 |
+
{
|
| 159 |
+
# exit with value 0 if binary is found, 1 otherwise
|
| 160 |
+
exit( BNGModel::findExec($findbin) ? 0 : 1 );
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
if ( $console )
|
| 166 |
+
{
|
| 167 |
+
# get arguments
|
| 168 |
+
my %args = ();
|
| 169 |
+
while ( my ($opt,$val) = each %default_args_console )
|
| 170 |
+
{
|
| 171 |
+
$args{$opt} = exists $user_args{$opt} ? $user_args{$opt} : $val;
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
# check if output directory exists and is writable
|
| 175 |
+
unless ( -d $args{output_dir} )
|
| 176 |
+
{ send_warning( sprintf "Default output directory '%s' is not a directory.", $args{output_dir}); }
|
| 177 |
+
unless ( -w $args{output_dir} )
|
| 178 |
+
{ send_warning( sprintf "Not able to write to default output directory '%s'.", $args{output_dir}); }
|
| 179 |
+
|
| 180 |
+
# start console
|
| 181 |
+
my $err = BNGconsole( \%args );
|
| 182 |
+
exit_error($err) if ($err);
|
| 183 |
+
}
|
| 184 |
+
else
|
| 185 |
+
{
|
| 186 |
+
unless (@ARGV)
|
| 187 |
+
{ display_help(); }
|
| 188 |
+
|
| 189 |
+
# get arguments
|
| 190 |
+
my %args = ();
|
| 191 |
+
while ( my ($opt,$val) = each %default_args )
|
| 192 |
+
{
|
| 193 |
+
$args{$opt} = exists $user_args{$opt} ? $user_args{$opt} : $val;
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
# check if output directory exists and is writable
|
| 197 |
+
unless ( -d $args{output_dir} )
|
| 198 |
+
{ send_warning( sprintf "Default output directory '%s' is not a directory.", $args{output_dir}); }
|
| 199 |
+
unless ( -w $args{output_dir} )
|
| 200 |
+
{ send_warning( sprintf "Not able to write to default output directory '%s'.", $args{output_dir}); }
|
| 201 |
+
|
| 202 |
+
# Process any files
|
| 203 |
+
while ( my $file = shift @ARGV )
|
| 204 |
+
{
|
| 205 |
+
# create BNGMOdel object
|
| 206 |
+
my $model = BNGModel->new();
|
| 207 |
+
$model->initialize();
|
| 208 |
+
$BNGModel::GLOBAL_MODEL = $model;
|
| 209 |
+
|
| 210 |
+
# set file argument
|
| 211 |
+
$args{'file'} = $file;
|
| 212 |
+
|
| 213 |
+
# read and process Model file
|
| 214 |
+
my $err = $model->readFile( \%args );
|
| 215 |
+
exit_error($err) if ($err);
|
| 216 |
+
|
| 217 |
+
# undefine model
|
| 218 |
+
%$model = (); undef %$model;
|
| 219 |
+
$BNGModel::GLOBAL_MODEL = undef;
|
| 220 |
+
}
|
| 221 |
+
}
|
| 222 |
+
|
| 223 |
+
# all done!
|
| 224 |
+
exit(0);
|
| 225 |
+
|
| 226 |
+
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
# Display Help Menu
|
| 230 |
+
sub display_help
|
| 231 |
+
{
|
| 232 |
+
printf "\nBioNetGen version %s\n", BNGversion();
|
| 233 |
+
print "--------------------------------------------------/ HELP MENU /-----\n"
|
| 234 |
+
." SYNOPSIS \n"
|
| 235 |
+
." process MODEL: BNG2.pl [OPTION]... MODEL... \n"
|
| 236 |
+
." start BNG console: BNG2.pl --console \n"
|
| 237 |
+
." display help: BNG2.pl -h \n"
|
| 238 |
+
." display version: BNG2.pl -v \n"
|
| 239 |
+
." \n"
|
| 240 |
+
." OPTIONS \n"
|
| 241 |
+
." --log write log to file MODEL.log (default is STDOUT) \n"
|
| 242 |
+
." --xml write XML output after processing MODEL \n"
|
| 243 |
+
." --mfile write MATLAB M-file output after processing MODEL\n"
|
| 244 |
+
." --sbml write SBML output after processing MODEL \n"
|
| 245 |
+
." --check read MODEL, but do not execute actions \n"
|
| 246 |
+
." --outdir PATH change default output path \n"
|
| 247 |
+
." \n"
|
| 248 |
+
." For more information, visit bionetgen.org \n"
|
| 249 |
+
."--------------------------------------------------------------------\n";
|
| 250 |
+
}
|
| 251 |
+
|
data/bionetgen/CHANGES.txt
ADDED
|
@@ -0,0 +1,467 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
CHANGES to BioNetGen
|
| 2 |
+
updated 25 May 2016
|
| 3 |
+
https://github.com/RuleWorld/bionetgen/
|
| 4 |
+
|
| 5 |
+
=======
|
| 6 |
+
== BioNetGen-2.3.0 (testing release) ==
|
| 7 |
+
'''''date tbd'''''
|
| 8 |
+
|
| 9 |
+
==== New Features ====
|
| 10 |
+
* Show graph automorphisms and statistical factor calculations for rules and reactions: BNG2.pl model.bngl --write_autos (or) BNG2.pl model.bngl --autos
|
| 11 |
+
|
| 12 |
+
==== SBML-to-BNGL Translator ====
|
| 13 |
+
* Atomizer will now query BioGrid and PathWay commons when determining the active or binding site in a complex. Include the 'pathwaycommons' flag during model import to active this option
|
| 14 |
+
* Several bugfixes to the lexical analysis engine
|
| 15 |
+
* The SBML-to-BNGL translator was moved to its own repository@https://github.com/RuleWorld/atomizer. The Atomizer source code can also be found in the XXX directory within the BioNetGen distribution
|
| 16 |
+
|
| 17 |
+
==== Bug Fixes ====
|
| 18 |
+
* Fixed a bug where <big><tt>resetParameters</tt></big> was not restoring parameters to their original values after calls to <big><tt>setParameter</tt></big>.
|
| 19 |
+
* Fixed a bug where a regex meant to remove the equality operator '=' in functions was inadvertently also removing the assignment operator '=='.
|
| 20 |
+
* Fixed a bug causing an error when reading a .net file with 'readFile' when multiple reactions with functional rate laws have identical stoichiometries.
|
| 21 |
+
* <big><tt>simulate_nf</tt></big> now throws an error if <big><tt>continue=>1</tt></big> is defined (previously threw a warning).
|
| 22 |
+
|
| 23 |
+
==== Visualization ====
|
| 24 |
+
* New styles for visualization.
|
| 25 |
+
* Updates to visualization algorithms.
|
| 26 |
+
* Supported types: conventional, compact, regulatory, opts, contactmap, reaction_network.
|
| 27 |
+
* Supported regulatory graph options: background, opts, groups, collapse, ruleNames, doNotUseContextWhenGrouping, doNotCollapseEdges.
|
| 28 |
+
|
| 29 |
+
==== Minor changes ===
|
| 30 |
+
* BioNetGen will now automatically run the generate_network command if one of simulate_pla/simulate_ode/simulate_ssa methods are called and a network wasn't loaded into the system otherwise
|
| 31 |
+
* Dangling bonds graph specifications of the kind A(b!1) are no longer allowed.
|
| 32 |
+
* Added support for the <big><tt>atomize</tt></big> and <big><tt>blocks</tt></big> arguments of the <big><tt>readFile</tt></big> action to the BNGConsole <big><tt>load</tt></big> command, e.g., <big><tt>load path_to_model/sbml_model.xml --atomize 1</tt></big>
|
| 33 |
+
|
| 34 |
+
== BioNetGen-2.2.6-stable ==
|
| 35 |
+
'''''2015 June 22'''''
|
| 36 |
+
|
| 37 |
+
==== New Language Conventions ====
|
| 38 |
+
* Whitespace is no longer allowed in rule names.
|
| 39 |
+
* All labels and BNG objects (except for bonds and states) must begin with a letter or underscore character.
|
| 40 |
+
* Labels must now be followed by a colon (':') with no intervening whitespace.
|
| 41 |
+
** Example: <big><tt>RuleX: A(s~0) -> A(s~1) k</tt></big>
|
| 42 |
+
* Leading indices in the <big><tt>molecule types</tt></big>, <big><tt>observables</tt></big>, and <big><tt>energy patterns</tt></big> blocks have been deprecated.
|
| 43 |
+
** '''Note''': These are not yet formally deprecated for the <big><tt>parameters</tt></big>, <big><tt>species</tt></big>, and <big><tt>functions</tt></big> blocks because they exist within BNG-generated NET files, which can be read in using <big><tt>readFile</tt></big>. Deprecating them completely will thus require changing the format of NET files.
|
| 44 |
+
* Unnamed rules are now given automatic names beginning with "<big><tt>_R</tt></big>" followed by a digit (e.g., "<big><tt>_R1</tt></big>", "<big><tt>_R2</tt></big>", etc.).
|
| 45 |
+
* Reverse rules are now named by prepending "<big><tt>_reverse_</tt></big>" to the forward rule name.
|
| 46 |
+
|
| 47 |
+
===== Actions & Arguments =====
|
| 48 |
+
* Added a new argument, <big><tt>par_scan_vals</tt></big>, to the <big><tt>parameter_scan</tt></big> action to allow parameter scans over unevenly spaced intervals.
|
| 49 |
+
** Example: <big><tt>parameter_scan({method=>"ode", t_end=>20, parameter=>"k1", par_scan_vals=>[1,5,20]})</tt></big>
|
| 50 |
+
** NOTE: If <big><tt>par_min</tt></big>, <big><tt>par_max</tt></big>, and <big><tt>n_scan_pts</tt></big>
|
| 51 |
+
are all defined, they will take precedence over <big><tt>par_scan_vals</tt></big> if it is defined.
|
| 52 |
+
|
| 53 |
+
==== Minor Changes ====
|
| 54 |
+
* Both the BioNetGen version and codename (e.g., "<big><tt>2.2.6-stable</tt></big>") are now included in the headers of files written with <big><tt>writeBNGL</tt></big> (e.g., NET files).
|
| 55 |
+
* validate_examples.pl now ignores trailing comments in file comparisons.
|
| 56 |
+
* Windows executables now contain the bitness of the architecture in their names
|
| 57 |
+
(e.g., <big><tt>run_network_MSWin32-64bit.exe</tt></big>).
|
| 58 |
+
* The run_network and sbmlTranslator executables no longer contain the architecture they are built for within the file name definition.
|
| 59 |
+
|
| 60 |
+
==== Bug Fixes ====
|
| 61 |
+
* An error is now thrown if an unrecognized block name is encountered.
|
| 62 |
+
* An error is now thrown if duplicate rule names are detected.
|
| 63 |
+
* Fixes a case where synthesis rules in cBNGL would fail if the product used the compartment prefix notation.
|
| 64 |
+
|
| 65 |
+
== BioNetGen-2.2.6-testing ==
|
| 66 |
+
'''''2015 March 3'''''
|
| 67 |
+
|
| 68 |
+
==== New Features ====
|
| 69 |
+
|
| 70 |
+
===== SBML-to-BNGL Translator =====
|
| 71 |
+
* The SBML-to-BNGL translator can perform both a flat (one-to-one) translation
|
| 72 |
+
of an SBML model in terms of unstructured species and an "atomized" translation
|
| 73 |
+
that recovers the implicit molecular structure (binding sites and states) of the
|
| 74 |
+
species within the model. The translator can be accessed in the following three ways:
|
| 75 |
+
# Using the readFile() BioNetGen action: The 'atomize' argument specifies whether a
|
| 76 |
+
flat or atomized translation is to be performed (default is flat, i.e.,
|
| 77 |
+
atomize). The translated model is written to [sbml_filename].bngl,
|
| 78 |
+
which is then read and loaded into memory. This allows additional actions [e.g., simulate(),
|
| 79 |
+
parameter_scan()] to be performed on the model if desired. See the
|
| 80 |
+
[[BioNetGen_Actions_and_Arguments | BioNetGen Actions & Arguments Guide]] for a comprehensive
|
| 81 |
+
listing of all actions and arguments, including readFile().
|
| 82 |
+
# Running the [BNGPATH]/bin/sbmlTranslator executable directly:
|
| 83 |
+
This provides the functionality described above along with additional customization flags.
|
| 84 |
+
Run ./sbmlTranslator --help> for a complete list of options with descriptions.
|
| 85 |
+
# As a standalone web application at [http://ratomizer.appspot.com/translate http://ratomizer.appspot.com/translate].
|
| 86 |
+
|
| 87 |
+
For further information, see the SBML-to-BNGL documentation.
|
| 88 |
+
|
| 89 |
+
===== Visualization Tools =====
|
| 90 |
+
* Visualization tools can be accessed by calling the visualize() action in a BNGL model file
|
| 91 |
+
or running the visualize.pl script included in
|
| 92 |
+
[BNGPATH]/Perl2/Visualization. The output is generated in Graph Modeling
|
| 93 |
+
Language (GML) format, which can be processed by graph editors such as yEd
|
| 94 |
+
([http://www.yworks.com/yed www.yworks.com/yed]) and Cytoscape
|
| 95 |
+
([http://www.cytoscape.org www.cytoscape.org]). Currently supported visualizations are:
|
| 96 |
+
** Model visualization as a contact map: >visualize({type=>"contactmap"})
|
| 97 |
+
** Model visualization as a regulatory graph: visualize({type=>"regulatory"})
|
| 98 |
+
** Rule visualization as a Petri net: visualize({type=>"ruleviz_pattern"})
|
| 99 |
+
** Rule visualization using graph operations: visualize({type=>"ruleviz_operation"})
|
| 100 |
+
|
| 101 |
+
For further information, call visualize({help=>1}) or run ./visualize.pl --help.
|
| 102 |
+
|
| 103 |
+
===== Actions & Arguments =====
|
| 104 |
+
* Added a 'reset_conc' argument to parameter_scan() that suppresses the call to resetConcentrations()
|
| 105 |
+
if set to 0 (default value is 1). This allows simulations in the scan to be started from the end point
|
| 106 |
+
of the previous simulation (used in bifurcate(); see below).
|
| 107 |
+
* Added a new bifurcate() action that takes the same arguments as parameter_scan() (except 'reset_conc').
|
| 108 |
+
The method automatically runs two scans, one from 'par_min' to 'par_max' and the other in the reverse
|
| 109 |
+
direction. Each simulation in the scans starts from the end point of the previous simulation by passing
|
| 110 |
+
<big><tt>reset_conc=>0</tt></big> to parameter_scan(). Output files are then generated for each observable
|
| 111 |
+
containing the parameter values vs. final observable values for both forward and reverse directions.
|
| 112 |
+
* Modified readFile() to allow specific model blocks to be read using the 'blocks' argument.
|
| 113 |
+
** Example: <big><tt>readFile({file=>"mymodel.bngl",blocks=>["parameters","seed species"]})</tt></big>
|
| 114 |
+
* Added support for <big><tt>method=>"nf"</tt></big> in simulate(). This allows NFsim to be used in
|
| 115 |
+
parameter_scan() and bifurcate() as well.
|
| 116 |
+
* Added support for compartments in writeSBML() and upgraded the supported version of SBML to Level 2 Version 3.
|
| 117 |
+
|
| 118 |
+
==== Minor Changes ====
|
| 119 |
+
* Upgraded muParser ([http://muparser.beltoforion.de http://muparser.beltoforion.de]) to version 2.2.4.
|
| 120 |
+
* Modified parameter_scan() to set <big><tt>get_final_state=>0</tt></big> if <big><tt>reset_conc=>1</tt></big>
|
| 121 |
+
(the default). This prevents BNG from unnecessarily reading in the final species populations at the end of
|
| 122 |
+
NFsim simulations if they are going to be reset anyway. This is important as the read step can be extremely
|
| 123 |
+
expensive for models with high degrees of symmetry.
|
| 124 |
+
* Modified setConcentration() to retain parameter names in expressions (rather than evaluating to a number).
|
| 125 |
+
This allows setConcentration() to be used with parameter_scan(). However, observables and functions are
|
| 126 |
+
still evaluated to numbers.
|
| 127 |
+
* Modified NET file output to list all rules that generate a given reaction in the comment following each
|
| 128 |
+
line of the <big><tt>reactions</tt></big> block. This is useful when a reaction is generated by multiple
|
| 129 |
+
different rules. Often this is unintentional and can be problematic since BNG multiplies the rate constant
|
| 130 |
+
by the number of duplicates generated. Listing all rules that generate a reaction can help identify and
|
| 131 |
+
debug situations like this.
|
| 132 |
+
* Added a default PLA configuration for <big><tt>simulate(method=>"pla")</tt></big>. If the 'pla_config'
|
| 133 |
+
argument is not defined, the configuration is set to <big><tt>fEuler|pre-neg:sb|eps=0.03</tt></big>, i.e.,
|
| 134 |
+
a standard tau-leaping method (1st order) with species-based preleap tau calculations, negative-population
|
| 135 |
+
postleap checking, and error control parameter 'eps' of 0.03.
|
| 136 |
+
* Modified <big><tt>validate_examples.pl</tt></big> to only report a stochastic validation failure if the
|
| 137 |
+
validation fails twice in a row.
|
| 138 |
+
* Added functionality to readFile() to convert forward slashes (/) to back slashes (\), and vice versa,
|
| 139 |
+
in '''''relative''''' paths, depending on the OS. This improves cross-platform portability and makes it
|
| 140 |
+
easier to share models.
|
| 141 |
+
|
| 142 |
+
==== Bug Fixes ====
|
| 143 |
+
* An error is now thrown if zero-order synthesis products do not have compartments.
|
| 144 |
+
* BNG will no longer switch to "compartmental" mode if the <big><tt>compartments</tt></big> block is empty.
|
| 145 |
+
* Expressions for compartment volumes are now correctly evaluated when generating a BNG-XML file.
|
| 146 |
+
* Fixed an inconsistency where forward referencing of parameters/observables was allowed for functions
|
| 147 |
+
defined in the <big><tt>functions</tt></big> block but not in the <big><tt>reaction rules</tt></big> block.
|
| 148 |
+
* Fixed a bug where in rare cases a function defined in the <big><tt>reaction rules</tt></big> block would
|
| 149 |
+
be typed as a 'ConstantExpression'. This would cause simulation to fail since it would be placed in the
|
| 150 |
+
<big><tt>parameters</tt></big> block of the generated NET file.
|
| 151 |
+
* Fixed a bug in the handling of 'max_stoich' constraints. In versions 2.2.3, 2.2.4, and 2.2.5, the
|
| 152 |
+
constraints were sometimes ignored during network generation and complexes larger than the maximum
|
| 153 |
+
specified could be constructed. Also added code to check that molecule names passed in the argument are
|
| 154 |
+
valid. This is useful since users often specify patterns, such as 'A()', rather than the actual molecule
|
| 155 |
+
name 'A'. Without an error message this can cause confusion.
|
| 156 |
+
* Fixed a bug where BNG was not passing to NFsim the random seed that it was generating when the 'seed'
|
| 157 |
+
argument was not explicitly set by the user. This made it difficult to debug problems in NFsim since it
|
| 158 |
+
was not outputting a random seed in the error messages.
|
| 159 |
+
|
| 160 |
+
== BioNetGen-2.2.5-stable ==
|
| 161 |
+
'''''2013 July 30'''''
|
| 162 |
+
|
| 163 |
+
==== New Features ====
|
| 164 |
+
|
| 165 |
+
===== BioNetGen-to-MCell Converter =====
|
| 166 |
+
The converter creates spatial MCell models from BioNetGen. It is called
|
| 167 |
+
by adding "<big><tt>writeMDL()</tt></big>" to the actions of a BioNetGen
|
| 168 |
+
model file. It also requires a geometry input file externally created using
|
| 169 |
+
CellBlender, an addon to the Blender software for creating MCell geometries.
|
| 170 |
+
Execution of a BioNetGen model integrates the reaction network and geometry
|
| 171 |
+
information and creates a MCell model file (.mdl). Alternatively,
|
| 172 |
+
"writeMDL()" enables direct execution and import of BioNetGen models from
|
| 173 |
+
CellBlender. The imported BioNetGen model can be integrated with geometries
|
| 174 |
+
created in CellBlender and exported from CellBlender as MCell model files.
|
| 175 |
+
|
| 176 |
+
===== AutoHPP =====
|
| 177 |
+
AutoHPP automates the construction and simulation of Hybrid Particle/Population
|
| 178 |
+
systems. AutoHPP profiles species populations during a test simulation,
|
| 179 |
+
identifies species with average population graater than a threshold, and then
|
| 180 |
+
constructs and simulates an HPP system where the identified species are treated
|
| 181 |
+
as lumped populations. Auto HPP is implemented in the "auto_hpp.pl" script
|
| 182 |
+
found in the "Perl2" subfolder (requires NFsim).
|
| 183 |
+
|
| 184 |
+
==== Minor changes ====
|
| 185 |
+
* If "BNG2.pl" is called without a model argument, the help menu is printed to
|
| 186 |
+
STDOUT. (In prior releases, BNG2.pl exited silently.)
|
| 187 |
+
* When parsing a global function ratelaw, BNG will not create a reference to
|
| 188 |
+
the function in the parameter table unless the function call is part of an
|
| 189 |
+
inline math expression. (Note that use of inline expressions within ratelaws is
|
| 190 |
+
advised against, since this is not supported by NFsim.)
|
| 191 |
+
* Modified the behavior of the '<big><tt>prefix</tt></big>' argument. Previously,
|
| 192 |
+
the argument was assumed to be an absolute path. Now, it is checked using
|
| 193 |
+
<big><tt>File::Spec->file_name_is_absolute()</tt></big> to determine whether or
|
| 194 |
+
not it is an absolute path. If it is not an absolute path, then the output
|
| 195 |
+
directory remains the current working directory and only the model name is
|
| 196 |
+
modified.
|
| 197 |
+
|
| 198 |
+
==== Bug Fixes ====
|
| 199 |
+
* Fixed bug in Network3 code that caused an error if an "if()" function was used
|
| 200 |
+
in the <big><tt>parameters</tt></big> block. This situation arises when a local
|
| 201 |
+
function is defined that includes an "if()" function. Thus, logical local functions
|
| 202 |
+
are now supported for network simulations.
|
| 203 |
+
* Fixed bug that caused simulations of HPP models containing global functions
|
| 204 |
+
to fail after loading from file. The problem was fixed by tracking global
|
| 205 |
+
functions directly rather than creating a reference in the parameter table.
|
| 206 |
+
* Fixed "--check" command line option (i.e., parse model, but do not execute
|
| 207 |
+
actions).
|
| 208 |
+
|
| 209 |
+
== BioNetGen-2.2.4-stable ==
|
| 210 |
+
'''''2013 May 16'''''
|
| 211 |
+
|
| 212 |
+
==== Errata ====
|
| 213 |
+
'''''2013 July 30''''' A bug was discovered in the handling of max_stoich
|
| 214 |
+
constraints. In some cases, the constraints will be ignored during network
|
| 215 |
+
generation, and complexes larger than the maximum specified may be constructed.
|
| 216 |
+
(Fixed in 2.2.6)
|
| 217 |
+
|
| 218 |
+
'''''2013 July 24''''' The "--check" command line switch is broken in this
|
| 219 |
+
version. BNG will parse the model and execute actions regardless of the switch.
|
| 220 |
+
|
| 221 |
+
'''''2013 July 22''''' HPP models with global functions fail to simulate in
|
| 222 |
+
NFsim after loading from file. The problem can be circumvented by simulating
|
| 223 |
+
the HPP model immediately after construction by passing the "execute=>1"
|
| 224 |
+
argument to "generate_hybrid_model()".
|
| 225 |
+
|
| 226 |
+
==== New Features ====
|
| 227 |
+
|
| 228 |
+
===== Modular model source files =====
|
| 229 |
+
BNG now supports multiple and recursive calls of the readFile() action. This
|
| 230 |
+
allows modular assembly of BNGL models from multiple source files. For example,
|
| 231 |
+
the model definitions can be stored in one file and parameter values in
|
| 232 |
+
a second file.
|
| 233 |
+
|
| 234 |
+
==== Changes to BNG action commands ====
|
| 235 |
+
* Complex bookkeeping option, "complex", is now enabled by default in the
|
| 236 |
+
simulate_nf() action, i.e. "complex=>1".
|
| 237 |
+
* Default value for option 'get_final_state' for simulate_nf() action has been
|
| 238 |
+
changed to TRUE. Consequently, the final state of a NF simulation will be
|
| 239 |
+
loaded into the BNG by default. However, to avoid the ''slow'' process of
|
| 240 |
+
canonically labeling massive complexes, any species composed of more than
|
| 241 |
+
20 molecules will be labeled using a quasi-canonical method. If this is still
|
| 242 |
+
too slow, set the option to FALSE (0).
|
| 243 |
+
|
| 244 |
+
==== New Example and Validation Models ====
|
| 245 |
+
* Added catalysis.bngl to Models2 directory. This model demonstrates
|
| 246 |
+
the implementation of energy consuming reactions in energy BNGL.
|
| 247 |
+
|
| 248 |
+
==== Bug Fixes ====
|
| 249 |
+
* Fixed minor bug that caused unnecessary retention of temporary labels in HPP
|
| 250 |
+
rules. This bug did not cause errors per se, but did result in a lot of
|
| 251 |
+
unnecessary warning messages.
|
| 252 |
+
* Fixed minor bug in HNauty labeling method that led to failure for species
|
| 253 |
+
graphs with bond wildcards. Note that this bug only affected pattern labels
|
| 254 |
+
(used in HPP) and not proper species.
|
| 255 |
+
|
| 256 |
+
==== Code refactoring ====
|
| 257 |
+
* Command line argument parsing in BNG2.pl is now handled by the core
|
| 258 |
+
module GetOpts::Long. This change should result in more robust parsing and
|
| 259 |
+
reduced maintaince in the future.
|
| 260 |
+
|
| 261 |
+
== BioNetGen-2.2.4-testing ==
|
| 262 |
+
'''''2013 March 31'''''
|
| 263 |
+
|
| 264 |
+
==== Errata ====
|
| 265 |
+
'''''2013 July 30''''' A bug was discovered in the handling of max_stoich
|
| 266 |
+
constraints. In some cases, the constraints will be ignored during network
|
| 267 |
+
generation, and complexes larger than the maximum specified may be constructed.
|
| 268 |
+
(Fixed in 2.2.6)
|
| 269 |
+
|
| 270 |
+
'''''2013 April 10''''' The original release notes for 2.2.4-testing stated that
|
| 271 |
+
the simulate_nf() action enabled complex bookkeeping by default. However, the
|
| 272 |
+
implementation of this change was flawed! 2.2.4-testing still defaults to
|
| 273 |
+
complex bookkeeping disabled. To enable complex bookkeeping, add the option
|
| 274 |
+
"complex=>1". This will be corrected in the next release.
|
| 275 |
+
|
| 276 |
+
'''''2013 April 10''''' The original release notes for 2.2.4-testing stated that
|
| 277 |
+
the time() function is available for use in any math expression. This is
|
| 278 |
+
incorrect. The time() function is only available in math expressions defined
|
| 279 |
+
in the functions block of BNGL model.
|
| 280 |
+
|
| 281 |
+
==== Hardware and Operating System Support ====
|
| 282 |
+
|
| 283 |
+
===== Mac OS/X run_network executable is now compiled for x86_64 =====
|
| 284 |
+
The run_network Mac executable distributed with BioNetGen was previously
|
| 285 |
+
compiled for i686 architecture (32-bit). In this and future distributions,
|
| 286 |
+
Mac OS/X executables will be compiled for x86_64 (64-bit). If a 32-bit
|
| 287 |
+
executable is required, browse to the "Network3" subdirectory and follow the
|
| 288 |
+
compilation instructions.
|
| 289 |
+
|
| 290 |
+
==== New Features ====
|
| 291 |
+
|
| 292 |
+
===== Empty species symbol "0" supported for compartmental BNGL =====
|
| 293 |
+
We introduced the new symbol "0" in 2.2.3 for representing an empty
|
| 294 |
+
pattern or species. This is useful anywhere BNG expects a pattern or
|
| 295 |
+
species but the modeler wants the empty set. For example, "0" may be
|
| 296 |
+
used on the LHS of a reaction rule for zero-order synthesis, or
|
| 297 |
+
the RHS for degradation rules. This feature is now supported in
|
| 298 |
+
compartmental BNGL
|
| 299 |
+
|
| 300 |
+
'''''NOTE:''''' compartmental BNGL adopts the convention that zero order
|
| 301 |
+
synthesis rate constants are given as intensive units (conc/time or
|
| 302 |
+
counts/vol/time). Hence, the total rate of synthesis depends on the rate
|
| 303 |
+
constant AND the volume of the compartment.
|
| 304 |
+
|
| 305 |
+
===== Energy BNGL (testing) =====
|
| 306 |
+
Energy modeling is a new approach to rule-based modeling where
|
| 307 |
+
kinetics are derived from changes in free-energy and activation barriers.
|
| 308 |
+
This approach was pioneered by J. Ollivier, et al. (PLoS Comp. Bio. 2010)
|
| 309 |
+
and generalized by Vincent Danos. Energy modeling has a number of advantages,
|
| 310 |
+
including: detailed balance is guaranteed, reaction rules are simplified,
|
| 311 |
+
and allostery/cooperativity easily implemented. A simple example of energy
|
| 312 |
+
modeling, 'energy_example1.bngl' was added to the Models2 directory. Keep an
|
| 313 |
+
eye out for more documentation and examples of energy modeling in BNG.
|
| 314 |
+
|
| 315 |
+
===== Time-dependent functions (testing) =====
|
| 316 |
+
Implemented a special function "time()" that refers to the current time
|
| 317 |
+
in a simulation. The time function may be used
|
| 318 |
+
in any mathematical expression. '''''CORRECTION:''''' ''The time() function is
|
| 319 |
+
only recognized in math expressions defined in the functions block.'' This is
|
| 320 |
+
useful for ratelaws or events that depend on time. Time is recognized by
|
| 321 |
+
run_network but not (presently) by NFsim.
|
| 322 |
+
|
| 323 |
+
'''''CAUTION:''''' Discontinuities in ratelaws may cause problems for
|
| 324 |
+
ODE integrators. If a timed event causes a discrete change
|
| 325 |
+
in a ratelaw, it is best to stop and restart the simulator.
|
| 326 |
+
|
| 327 |
+
'''''CAUTION:''''' Time-dependent rates in SSA simulations may introduce
|
| 328 |
+
substantial error if the relative rate change is fast in time. Advanced
|
| 329 |
+
methods exist for managing time-dependent rates accurately; however,
|
| 330 |
+
these methods are not currently implemented in run_network.
|
| 331 |
+
|
| 332 |
+
===== Molecule-scoped local functions =====
|
| 333 |
+
Added support for local functions evaluated on the scope of a tagged
|
| 334 |
+
molecule. This feature was already supported by NFsim, but is now
|
| 335 |
+
available for network generation and network simulation. See the NFsim
|
| 336 |
+
manual (chapter 7) for examples of molecule-scoped local functions.
|
| 337 |
+
|
| 338 |
+
==== Improvements to Existing Features ====
|
| 339 |
+
|
| 340 |
+
===== On-the-fly network generation is fixed =====
|
| 341 |
+
Run_network supports on-the-fly network generation again. However, the
|
| 342 |
+
implementation is not very efficient. NFsim is recommended for
|
| 343 |
+
applications with large networks.
|
| 344 |
+
|
| 345 |
+
===== Added support for functional rate laws in SBML export =====
|
| 346 |
+
Fixed SBML export for functional rate laws. Global functions are now
|
| 347 |
+
output in the same way as parameter expressions. Local functions are NOT
|
| 348 |
+
output to SBML because they are evaluated down to a number by BNG during
|
| 349 |
+
network generation so they're unnecessary. Note that the "Group_" prefix
|
| 350 |
+
has been removed from the SBML IDs of observables so that they can be
|
| 351 |
+
easily referenced in function expressions. This is not a problem because
|
| 352 |
+
parameters and observables occupy the same namespace so there is no
|
| 353 |
+
possibility of conflicts.
|
| 354 |
+
|
| 355 |
+
===== Better handling of mathematical expression in output =====
|
| 356 |
+
BioNetGen now exports mathematical expressions by default, rather than
|
| 357 |
+
evaluating to a number. This preserves the original math when models or
|
| 358 |
+
networks are written to file. Support for mathematical expressions in the
|
| 359 |
+
parameters block was added to run_network.
|
| 360 |
+
|
| 361 |
+
===== Upgrades to MATLAB export via writeMfile() =====
|
| 362 |
+
* Improved error capture when calling MATLAB's ODE23s integrator.
|
| 363 |
+
* Support for "if" functions: "if(cond,val1,val2)" is translated
|
| 364 |
+
to "(cond~=0)*val1 + (cond==0)*val2". This isn't a perfect solution since it
|
| 365 |
+
requires that val1 and val2 both evaluate to finite numbers. Unfortunately,
|
| 366 |
+
MATLAB does not support the ternary conditional (a better solution).
|
| 367 |
+
* Eliminated redundancy of expression evaluation, resulting in better
|
| 368 |
+
run-time efficiency.
|
| 369 |
+
|
| 370 |
+
==== Bug Notices ====
|
| 371 |
+
* run_network fails to parse math expressions properly if a parameter name in
|
| 372 |
+
the expression begins with a number. We recommend that parameter names begin
|
| 373 |
+
with a letter character. Parameter names beginning with numbers will likely
|
| 374 |
+
be deprecated in a future release.
|
| 375 |
+
|
| 376 |
+
==== Bug Fixes ====
|
| 377 |
+
* Fixed bug where parameters beginning with "and" or "or" were confused
|
| 378 |
+
with the logical operations. The problem was traced to the muParser
|
| 379 |
+
library. Upgrading to muParser v2.2.3 solved this problem.
|
| 380 |
+
* Fixed bug where setConcentration (and potentially other actions) fail to
|
| 381 |
+
parse arguments that contain species definitions with compartmental syntax.
|
| 382 |
+
* Fixed bug in BNG math expression parser where unary operators were parsed
|
| 383 |
+
incorrectly in some circumstances.
|
| 384 |
+
* Fixed bug where run_network reported incorrect line number in error message.
|
| 385 |
+
* Fixed potential bug in isomorphic detection method, where BNG attempts to
|
| 386 |
+
access undefined nodes if graphs have unequal size. This is prevented by
|
| 387 |
+
checking the size of the graphs prior to comparison.
|
| 388 |
+
* Fixed bug that caused generate_network() action to return an error if no
|
| 389 |
+
seed species are defined. This fix permits network generation for models with
|
| 390 |
+
0-order synthesis but no seed species.
|
| 391 |
+
* Fixed bug where scan_var.pl generated invalid scripts if the BNGL model file
|
| 392 |
+
does not end with a new line.
|
| 393 |
+
* Fixed bug where functions comprised of more than 512 characters could not
|
| 394 |
+
be read. There is now no limit to the number of characters.
|
| 395 |
+
|
| 396 |
+
==== Minor Syntax Changes ====
|
| 397 |
+
* Deprecated use of fixed quantity flag "$" within reactant rules.
|
| 398 |
+
The fixed quantity flag should only be used in the seed species block.
|
| 399 |
+
* Use of "fake" species such as "NULL", "TRASH", or "SINK" as placeholders
|
| 400 |
+
in reaction rules with zero reactants and products is now deprecated.
|
| 401 |
+
We advise the use of the special symbol "0" instead.
|
| 402 |
+
* Labels are now permitted before definitions in all BNGL blocks.
|
| 403 |
+
|
| 404 |
+
==== Changes to BNG action commands ====
|
| 405 |
+
* Added 'continue' option to generate_network() action. If this option
|
| 406 |
+
is enabled, BNG will continue generating a network from the last
|
| 407 |
+
completed iteration. If disabled, BNG will start reset the network
|
| 408 |
+
and generate from scratch. The option is enabled by default, i.e.'continue=>1'.
|
| 409 |
+
* Complex bookkeeping option, 'complex', is now enabled by default in the
|
| 410 |
+
simulate_nf() action, i.e. 'complex=>1'. '''''CORRECTION:''''' ''The
|
| 411 |
+
implementation of this change was flawed. The 2.2.4-testing release still
|
| 412 |
+
defaults to complex bookkeeping disabled. To enable complex bookkeeping, add
|
| 413 |
+
the option complex=>1''.
|
| 414 |
+
* The 'exact' option for generate_hybrid_model() was renamed to 'safe'. This
|
| 415 |
+
avoids confusion over whether the standard method is exact. Indeed, both
|
| 416 |
+
methods are exact if population lumping is instantaneous. However, only
|
| 417 |
+
the 'safe' method is exact for finite lumping rates. The default is
|
| 418 |
+
'safe=>0'. The old 'exact' option will be supported up to (and including) the
|
| 419 |
+
next stable release.
|
| 420 |
+
|
| 421 |
+
==== Error and Warning Message Changes ====
|
| 422 |
+
* Useless {MatchOnce} attribute in species definitions are now detected and
|
| 423 |
+
reported.
|
| 424 |
+
* Improved detection of illegal dangling bonds and wildcards in reaction rules.
|
| 425 |
+
* Improved clarity of error messages for unrecognized BNG version strings
|
| 426 |
+
and missing ratelaw arguments.
|
| 427 |
+
* scan_var.pl utility reports an error is the BNGL model does not contain an
|
| 428 |
+
"end model" directive.
|
| 429 |
+
* run_network will now allow commented lines in the functions block of the
|
| 430 |
+
NET file.
|
| 431 |
+
* run_network no longer complains is there are no parameters in the model.
|
| 432 |
+
|
| 433 |
+
==== New Example and Validation Models ====
|
| 434 |
+
* Added gene_expr_func.bngl and localfunc.bngl to Models2 directory.
|
| 435 |
+
NOTE: these models were previous distributed as validation models.
|
| 436 |
+
* A simple example of energy modeling, 'energy_example1.bngl' was added to
|
| 437 |
+
the Models2 directory.
|
| 438 |
+
* Adding two new validation files: (1) isingspin_energy.bngl implements an
|
| 439 |
+
ising spin model on a 3x3 toroidal lattice using the energy approach, (2)
|
| 440 |
+
isingspin_localfcn.bngl implements the ising spin model (same topology) using
|
| 441 |
+
local functions. Both models test the SSA equillibrium distribution. Model 2
|
| 442 |
+
also tests the NF equillibrium distribution. NOTE: the energy approach is
|
| 443 |
+
not supported in NFsim, hence this version won't scale to a larger lattice.
|
| 444 |
+
|
| 445 |
+
==== Code refactoring ====
|
| 446 |
+
* Enabled strict and warning pragmas in BNGModel.pm
|
| 447 |
+
* Migrated to muParser 2.2.3 (from v134) for parsing math expressions in
|
| 448 |
+
run_network. Implemented a static "If()" function in network.h that gets
|
| 449 |
+
called as "if()" in muParser [parser.DefineFun("if",If) in
|
| 450 |
+
network::read_functions_array()]. This should solve the problem of if()
|
| 451 |
+
being deprecated in the muparser_v2_2_3. Also modified run_network.cpp and
|
| 452 |
+
network.cpp to no longer replace "&&" with "and" and "||" with "or".
|
| 453 |
+
* Reformulated generate_network so that observables and energy patterns are
|
| 454 |
+
updated as species are generated, rather than after an iteration of
|
| 455 |
+
network generation completes.
|
| 456 |
+
* The Expression type "FUN" was renamed as "FunctionCall". The original type
|
| 457 |
+
name caused some confusion as to whether the expression was a function
|
| 458 |
+
definition or a function call. To clarify, the type was renamed FunctionCall.
|
| 459 |
+
The Function object holds the definition (RHS) for a function. For further
|
| 460 |
+
reference: the Param type Function associates a name to a Function object.
|
| 461 |
+
A function without an associated Param is anonymous (i.e. cannot be found in
|
| 462 |
+
the ParamList).
|
| 463 |
+
|
| 464 |
+
== BioNetGen-2.2.3-testing ==
|
| 465 |
+
See "Release Notes" at http://bionetgen.org for changes to older versions of
|
| 466 |
+
BioNetGen.
|
| 467 |
+
|
data/bionetgen/CREDITS.txt
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
The following people have contributed to BioNetGen code development:
|
| 2 |
+
|
| 3 |
+
Michael L. Blinov <blinov@uchc.edu>
|
| 4 |
+
* Original author.
|
| 5 |
+
* Testing and development of new ideas.
|
| 6 |
+
* Developed interface to Virtual Cell.
|
| 7 |
+
|
| 8 |
+
James R. Faeder <faeder@lanl.gov>
|
| 9 |
+
* Primary BioNetGen developer since version 1.0.
|
| 10 |
+
* Testing and development of new ideas.
|
| 11 |
+
* Code maintainer.
|
| 12 |
+
* Current project co-PI.
|
| 13 |
+
|
| 14 |
+
William S. Hlavacek <wish@lanl.gov>
|
| 15 |
+
* Driving force in the development.
|
| 16 |
+
* Testing and development of new ideas.
|
| 17 |
+
* Current project PI.
|
| 18 |
+
|
| 19 |
+
Byron Goldstein <bxg@lanl.gov>
|
| 20 |
+
* Pioneered concept of signaling models based on multivalent interactions.
|
| 21 |
+
* Original project PI.
|
| 22 |
+
|
| 23 |
+
Justin Hogg <justinshogg@gmail.com>
|
| 24 |
+
* Compartmental BNGL (cBNGL).
|
| 25 |
+
* General maintenance.
|
| 26 |
+
|
| 27 |
+
Leonard Harris <lh64@cornell.edu>
|
| 28 |
+
* Network3 development: global functions, accelerated stochastics (PLA)
|
| 29 |
+
|
| 30 |
+
Ilya Korsunsky
|
| 31 |
+
* Initial deployment of global functions for Network3.
|
| 32 |
+
|
| 33 |
+
John Sekar <johnarul.sekar@gmail.com>
|
| 34 |
+
* Visualization - rule visualization, regulatory graphs.
|
| 35 |
+
|
| 36 |
+
Jose Juan Tapia <jjtapia@pitt.edu>
|
| 37 |
+
* BioNetGen grammars development and implementation
|
| 38 |
+
* SBML2BNGL developer
|
| 39 |
+
|
| 40 |
+
Adam Smith
|
| 41 |
+
* RuleBender developer
|
| 42 |
+
|
| 43 |
+
Michael Sneddon <michael.sneddon@yale.edu>
|
| 44 |
+
* Author and maintainer of NFsim.
|
| 45 |
+
* Contributor to BNGXML and maintainer of BNG-NFsim interface.
|
| 46 |
+
|
| 47 |
+
Thierry Emonet <thierry.emonet@yale.edu>
|
| 48 |
+
* NFsim PI
|
| 49 |
+
|
| 50 |
+
Jeremy Kozdon
|
| 51 |
+
* Code for use of sparse Jacobian in CVODE calls, which greatly accelerates
|
| 52 |
+
ODE integration for large networks (sparse=>1 option).
|
| 53 |
+
|
| 54 |
+
Nathan Lemons
|
| 55 |
+
* HNauty code for canonical labeling of hierarchical graphs, which is (optionally) used
|
| 56 |
+
in network generation,.
|
| 57 |
+
|
| 58 |
+
Matthew Fricke <matthew@gofigure.org>
|
| 59 |
+
* Primary author of RuleBuilder.
|
| 60 |
+
|
| 61 |
+
Leigh Fanning <leigh@verseira.net>
|
| 62 |
+
* Contributor to RuleBuilder development.
|
| 63 |
+
* Developed RuleBuilder help system.
|
| 64 |
+
|
| 65 |
+
Robert Seletsky <robert1unm@yahoo.com>
|
| 66 |
+
* Testing of BioNetGen and RuleBuilder.
|
| 67 |
+
|
| 68 |
+
Sarah Faeder <smgfaeder@gmail.com>
|
| 69 |
+
* Contributor of PhiBPlot.
|
| 70 |
+
* Testing and bug fixes for RuleBuilder.
|
| 71 |
+
|
| 72 |
+
Nikolay Borisov <nikolay.borisov@jefferson.edu>
|
| 73 |
+
* Primary developer of Macro module.
|
| 74 |
+
* Testing of BioNetGen.
|
| 75 |
+
|
| 76 |
+
Mikhail Kravchenko <krmisha@rambler.ru>
|
| 77 |
+
* Implementation of macro code.
|
| 78 |
+
* Streamlining of BioNetGen interface.
|
| 79 |
+
|
| 80 |
+
Alexander S. Chistopolsky <eroxi@savelovo.net>
|
| 81 |
+
* Developer of macro algorithm
|
| 82 |
+
|
| 83 |
+
Marc Birtwistle <mrbirdy@udel.edu>
|
| 84 |
+
* Contributor of parameter sensitivity code.
|
| 85 |
+
|
| 86 |
+
Dipak Barua
|
| 87 |
+
* BNGL to MDL converter.
|
| 88 |
+
|
data/bionetgen/LICENSE.txt
ADDED
|
@@ -0,0 +1,674 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
GNU GENERAL PUBLIC LICENSE
|
| 2 |
+
Version 3, 29 June 2007
|
| 3 |
+
|
| 4 |
+
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
| 5 |
+
Everyone is permitted to copy and distribute verbatim copies
|
| 6 |
+
of this license document, but changing it is not allowed.
|
| 7 |
+
|
| 8 |
+
Preamble
|
| 9 |
+
|
| 10 |
+
The GNU General Public License is a free, copyleft license for
|
| 11 |
+
software and other kinds of works.
|
| 12 |
+
|
| 13 |
+
The licenses for most software and other practical works are designed
|
| 14 |
+
to take away your freedom to share and change the works. By contrast,
|
| 15 |
+
the GNU General Public License is intended to guarantee your freedom to
|
| 16 |
+
share and change all versions of a program--to make sure it remains free
|
| 17 |
+
software for all its users. We, the Free Software Foundation, use the
|
| 18 |
+
GNU General Public License for most of our software; it applies also to
|
| 19 |
+
any other work released this way by its authors. You can apply it to
|
| 20 |
+
your programs, too.
|
| 21 |
+
|
| 22 |
+
When we speak of free software, we are referring to freedom, not
|
| 23 |
+
price. Our General Public Licenses are designed to make sure that you
|
| 24 |
+
have the freedom to distribute copies of free software (and charge for
|
| 25 |
+
them if you wish), that you receive source code or can get it if you
|
| 26 |
+
want it, that you can change the software or use pieces of it in new
|
| 27 |
+
free programs, and that you know you can do these things.
|
| 28 |
+
|
| 29 |
+
To protect your rights, we need to prevent others from denying you
|
| 30 |
+
these rights or asking you to surrender the rights. Therefore, you have
|
| 31 |
+
certain responsibilities if you distribute copies of the software, or if
|
| 32 |
+
you modify it: responsibilities to respect the freedom of others.
|
| 33 |
+
|
| 34 |
+
For example, if you distribute copies of such a program, whether
|
| 35 |
+
gratis or for a fee, you must pass on to the recipients the same
|
| 36 |
+
freedoms that you received. You must make sure that they, too, receive
|
| 37 |
+
or can get the source code. And you must show them these terms so they
|
| 38 |
+
know their rights.
|
| 39 |
+
|
| 40 |
+
Developers that use the GNU GPL protect your rights with two steps:
|
| 41 |
+
(1) assert copyright on the software, and (2) offer you this License
|
| 42 |
+
giving you legal permission to copy, distribute and/or modify it.
|
| 43 |
+
|
| 44 |
+
For the developers' and authors' protection, the GPL clearly explains
|
| 45 |
+
that there is no warranty for this free software. For both users' and
|
| 46 |
+
authors' sake, the GPL requires that modified versions be marked as
|
| 47 |
+
changed, so that their problems will not be attributed erroneously to
|
| 48 |
+
authors of previous versions.
|
| 49 |
+
|
| 50 |
+
Some devices are designed to deny users access to install or run
|
| 51 |
+
modified versions of the software inside them, although the manufacturer
|
| 52 |
+
can do so. This is fundamentally incompatible with the aim of
|
| 53 |
+
protecting users' freedom to change the software. The systematic
|
| 54 |
+
pattern of such abuse occurs in the area of products for individuals to
|
| 55 |
+
use, which is precisely where it is most unacceptable. Therefore, we
|
| 56 |
+
have designed this version of the GPL to prohibit the practice for those
|
| 57 |
+
products. If such problems arise substantially in other domains, we
|
| 58 |
+
stand ready to extend this provision to those domains in future versions
|
| 59 |
+
of the GPL, as needed to protect the freedom of users.
|
| 60 |
+
|
| 61 |
+
Finally, every program is threatened constantly by software patents.
|
| 62 |
+
States should not allow patents to restrict development and use of
|
| 63 |
+
software on general-purpose computers, but in those that do, we wish to
|
| 64 |
+
avoid the special danger that patents applied to a free program could
|
| 65 |
+
make it effectively proprietary. To prevent this, the GPL assures that
|
| 66 |
+
patents cannot be used to render the program non-free.
|
| 67 |
+
|
| 68 |
+
The precise terms and conditions for copying, distribution and
|
| 69 |
+
modification follow.
|
| 70 |
+
|
| 71 |
+
TERMS AND CONDITIONS
|
| 72 |
+
|
| 73 |
+
0. Definitions.
|
| 74 |
+
|
| 75 |
+
"This License" refers to version 3 of the GNU General Public License.
|
| 76 |
+
|
| 77 |
+
"Copyright" also means copyright-like laws that apply to other kinds of
|
| 78 |
+
works, such as semiconductor masks.
|
| 79 |
+
|
| 80 |
+
"The Program" refers to any copyrightable work licensed under this
|
| 81 |
+
License. Each licensee is addressed as "you". "Licensees" and
|
| 82 |
+
"recipients" may be individuals or organizations.
|
| 83 |
+
|
| 84 |
+
To "modify" a work means to copy from or adapt all or part of the work
|
| 85 |
+
in a fashion requiring copyright permission, other than the making of an
|
| 86 |
+
exact copy. The resulting work is called a "modified version" of the
|
| 87 |
+
earlier work or a work "based on" the earlier work.
|
| 88 |
+
|
| 89 |
+
A "covered work" means either the unmodified Program or a work based
|
| 90 |
+
on the Program.
|
| 91 |
+
|
| 92 |
+
To "propagate" a work means to do anything with it that, without
|
| 93 |
+
permission, would make you directly or secondarily liable for
|
| 94 |
+
infringement under applicable copyright law, except executing it on a
|
| 95 |
+
computer or modifying a private copy. Propagation includes copying,
|
| 96 |
+
distribution (with or without modification), making available to the
|
| 97 |
+
public, and in some countries other activities as well.
|
| 98 |
+
|
| 99 |
+
To "convey" a work means any kind of propagation that enables other
|
| 100 |
+
parties to make or receive copies. Mere interaction with a user through
|
| 101 |
+
a computer network, with no transfer of a copy, is not conveying.
|
| 102 |
+
|
| 103 |
+
An interactive user interface displays "Appropriate Legal Notices"
|
| 104 |
+
to the extent that it includes a convenient and prominently visible
|
| 105 |
+
feature that (1) displays an appropriate copyright notice, and (2)
|
| 106 |
+
tells the user that there is no warranty for the work (except to the
|
| 107 |
+
extent that warranties are provided), that licensees may convey the
|
| 108 |
+
work under this License, and how to view a copy of this License. If
|
| 109 |
+
the interface presents a list of user commands or options, such as a
|
| 110 |
+
menu, a prominent item in the list meets this criterion.
|
| 111 |
+
|
| 112 |
+
1. Source Code.
|
| 113 |
+
|
| 114 |
+
The "source code" for a work means the preferred form of the work
|
| 115 |
+
for making modifications to it. "Object code" means any non-source
|
| 116 |
+
form of a work.
|
| 117 |
+
|
| 118 |
+
A "Standard Interface" means an interface that either is an official
|
| 119 |
+
standard defined by a recognized standards body, or, in the case of
|
| 120 |
+
interfaces specified for a particular programming language, one that
|
| 121 |
+
is widely used among developers working in that language.
|
| 122 |
+
|
| 123 |
+
The "System Libraries" of an executable work include anything, other
|
| 124 |
+
than the work as a whole, that (a) is included in the normal form of
|
| 125 |
+
packaging a Major Component, but which is not part of that Major
|
| 126 |
+
Component, and (b) serves only to enable use of the work with that
|
| 127 |
+
Major Component, or to implement a Standard Interface for which an
|
| 128 |
+
implementation is available to the public in source code form. A
|
| 129 |
+
"Major Component", in this context, means a major essential component
|
| 130 |
+
(kernel, window system, and so on) of the specific operating system
|
| 131 |
+
(if any) on which the executable work runs, or a compiler used to
|
| 132 |
+
produce the work, or an object code interpreter used to run it.
|
| 133 |
+
|
| 134 |
+
The "Corresponding Source" for a work in object code form means all
|
| 135 |
+
the source code needed to generate, install, and (for an executable
|
| 136 |
+
work) run the object code and to modify the work, including scripts to
|
| 137 |
+
control those activities. However, it does not include the work's
|
| 138 |
+
System Libraries, or general-purpose tools or generally available free
|
| 139 |
+
programs which are used unmodified in performing those activities but
|
| 140 |
+
which are not part of the work. For example, Corresponding Source
|
| 141 |
+
includes interface definition files associated with source files for
|
| 142 |
+
the work, and the source code for shared libraries and dynamically
|
| 143 |
+
linked subprograms that the work is specifically designed to require,
|
| 144 |
+
such as by intimate data communication or control flow between those
|
| 145 |
+
subprograms and other parts of the work.
|
| 146 |
+
|
| 147 |
+
The Corresponding Source need not include anything that users
|
| 148 |
+
can regenerate automatically from other parts of the Corresponding
|
| 149 |
+
Source.
|
| 150 |
+
|
| 151 |
+
The Corresponding Source for a work in source code form is that
|
| 152 |
+
same work.
|
| 153 |
+
|
| 154 |
+
2. Basic Permissions.
|
| 155 |
+
|
| 156 |
+
All rights granted under this License are granted for the term of
|
| 157 |
+
copyright on the Program, and are irrevocable provided the stated
|
| 158 |
+
conditions are met. This License explicitly affirms your unlimited
|
| 159 |
+
permission to run the unmodified Program. The output from running a
|
| 160 |
+
covered work is covered by this License only if the output, given its
|
| 161 |
+
content, constitutes a covered work. This License acknowledges your
|
| 162 |
+
rights of fair use or other equivalent, as provided by copyright law.
|
| 163 |
+
|
| 164 |
+
You may make, run and propagate covered works that you do not
|
| 165 |
+
convey, without conditions so long as your license otherwise remains
|
| 166 |
+
in force. You may convey covered works to others for the sole purpose
|
| 167 |
+
of having them make modifications exclusively for you, or provide you
|
| 168 |
+
with facilities for running those works, provided that you comply with
|
| 169 |
+
the terms of this License in conveying all material for which you do
|
| 170 |
+
not control copyright. Those thus making or running the covered works
|
| 171 |
+
for you must do so exclusively on your behalf, under your direction
|
| 172 |
+
and control, on terms that prohibit them from making any copies of
|
| 173 |
+
your copyrighted material outside their relationship with you.
|
| 174 |
+
|
| 175 |
+
Conveying under any other circumstances is permitted solely under
|
| 176 |
+
the conditions stated below. Sublicensing is not allowed; section 10
|
| 177 |
+
makes it unnecessary.
|
| 178 |
+
|
| 179 |
+
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
| 180 |
+
|
| 181 |
+
No covered work shall be deemed part of an effective technological
|
| 182 |
+
measure under any applicable law fulfilling obligations under article
|
| 183 |
+
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
| 184 |
+
similar laws prohibiting or restricting circumvention of such
|
| 185 |
+
measures.
|
| 186 |
+
|
| 187 |
+
When you convey a covered work, you waive any legal power to forbid
|
| 188 |
+
circumvention of technological measures to the extent such circumvention
|
| 189 |
+
is effected by exercising rights under this License with respect to
|
| 190 |
+
the covered work, and you disclaim any intention to limit operation or
|
| 191 |
+
modification of the work as a means of enforcing, against the work's
|
| 192 |
+
users, your or third parties' legal rights to forbid circumvention of
|
| 193 |
+
technological measures.
|
| 194 |
+
|
| 195 |
+
4. Conveying Verbatim Copies.
|
| 196 |
+
|
| 197 |
+
You may convey verbatim copies of the Program's source code as you
|
| 198 |
+
receive it, in any medium, provided that you conspicuously and
|
| 199 |
+
appropriately publish on each copy an appropriate copyright notice;
|
| 200 |
+
keep intact all notices stating that this License and any
|
| 201 |
+
non-permissive terms added in accord with section 7 apply to the code;
|
| 202 |
+
keep intact all notices of the absence of any warranty; and give all
|
| 203 |
+
recipients a copy of this License along with the Program.
|
| 204 |
+
|
| 205 |
+
You may charge any price or no price for each copy that you convey,
|
| 206 |
+
and you may offer support or warranty protection for a fee.
|
| 207 |
+
|
| 208 |
+
5. Conveying Modified Source Versions.
|
| 209 |
+
|
| 210 |
+
You may convey a work based on the Program, or the modifications to
|
| 211 |
+
produce it from the Program, in the form of source code under the
|
| 212 |
+
terms of section 4, provided that you also meet all of these conditions:
|
| 213 |
+
|
| 214 |
+
a) The work must carry prominent notices stating that you modified
|
| 215 |
+
it, and giving a relevant date.
|
| 216 |
+
|
| 217 |
+
b) The work must carry prominent notices stating that it is
|
| 218 |
+
released under this License and any conditions added under section
|
| 219 |
+
7. This requirement modifies the requirement in section 4 to
|
| 220 |
+
"keep intact all notices".
|
| 221 |
+
|
| 222 |
+
c) You must license the entire work, as a whole, under this
|
| 223 |
+
License to anyone who comes into possession of a copy. This
|
| 224 |
+
License will therefore apply, along with any applicable section 7
|
| 225 |
+
additional terms, to the whole of the work, and all its parts,
|
| 226 |
+
regardless of how they are packaged. This License gives no
|
| 227 |
+
permission to license the work in any other way, but it does not
|
| 228 |
+
invalidate such permission if you have separately received it.
|
| 229 |
+
|
| 230 |
+
d) If the work has interactive user interfaces, each must display
|
| 231 |
+
Appropriate Legal Notices; however, if the Program has interactive
|
| 232 |
+
interfaces that do not display Appropriate Legal Notices, your
|
| 233 |
+
work need not make them do so.
|
| 234 |
+
|
| 235 |
+
A compilation of a covered work with other separate and independent
|
| 236 |
+
works, which are not by their nature extensions of the covered work,
|
| 237 |
+
and which are not combined with it such as to form a larger program,
|
| 238 |
+
in or on a volume of a storage or distribution medium, is called an
|
| 239 |
+
"aggregate" if the compilation and its resulting copyright are not
|
| 240 |
+
used to limit the access or legal rights of the compilation's users
|
| 241 |
+
beyond what the individual works permit. Inclusion of a covered work
|
| 242 |
+
in an aggregate does not cause this License to apply to the other
|
| 243 |
+
parts of the aggregate.
|
| 244 |
+
|
| 245 |
+
6. Conveying Non-Source Forms.
|
| 246 |
+
|
| 247 |
+
You may convey a covered work in object code form under the terms
|
| 248 |
+
of sections 4 and 5, provided that you also convey the
|
| 249 |
+
machine-readable Corresponding Source under the terms of this License,
|
| 250 |
+
in one of these ways:
|
| 251 |
+
|
| 252 |
+
a) Convey the object code in, or embodied in, a physical product
|
| 253 |
+
(including a physical distribution medium), accompanied by the
|
| 254 |
+
Corresponding Source fixed on a durable physical medium
|
| 255 |
+
customarily used for software interchange.
|
| 256 |
+
|
| 257 |
+
b) Convey the object code in, or embodied in, a physical product
|
| 258 |
+
(including a physical distribution medium), accompanied by a
|
| 259 |
+
written offer, valid for at least three years and valid for as
|
| 260 |
+
long as you offer spare parts or customer support for that product
|
| 261 |
+
model, to give anyone who possesses the object code either (1) a
|
| 262 |
+
copy of the Corresponding Source for all the software in the
|
| 263 |
+
product that is covered by this License, on a durable physical
|
| 264 |
+
medium customarily used for software interchange, for a price no
|
| 265 |
+
more than your reasonable cost of physically performing this
|
| 266 |
+
conveying of source, or (2) access to copy the
|
| 267 |
+
Corresponding Source from a network server at no charge.
|
| 268 |
+
|
| 269 |
+
c) Convey individual copies of the object code with a copy of the
|
| 270 |
+
written offer to provide the Corresponding Source. This
|
| 271 |
+
alternative is allowed only occasionally and noncommercially, and
|
| 272 |
+
only if you received the object code with such an offer, in accord
|
| 273 |
+
with subsection 6b.
|
| 274 |
+
|
| 275 |
+
d) Convey the object code by offering access from a designated
|
| 276 |
+
place (gratis or for a charge), and offer equivalent access to the
|
| 277 |
+
Corresponding Source in the same way through the same place at no
|
| 278 |
+
further charge. You need not require recipients to copy the
|
| 279 |
+
Corresponding Source along with the object code. If the place to
|
| 280 |
+
copy the object code is a network server, the Corresponding Source
|
| 281 |
+
may be on a different server (operated by you or a third party)
|
| 282 |
+
that supports equivalent copying facilities, provided you maintain
|
| 283 |
+
clear directions next to the object code saying where to find the
|
| 284 |
+
Corresponding Source. Regardless of what server hosts the
|
| 285 |
+
Corresponding Source, you remain obligated to ensure that it is
|
| 286 |
+
available for as long as needed to satisfy these requirements.
|
| 287 |
+
|
| 288 |
+
e) Convey the object code using peer-to-peer transmission, provided
|
| 289 |
+
you inform other peers where the object code and Corresponding
|
| 290 |
+
Source of the work are being offered to the general public at no
|
| 291 |
+
charge under subsection 6d.
|
| 292 |
+
|
| 293 |
+
A separable portion of the object code, whose source code is excluded
|
| 294 |
+
from the Corresponding Source as a System Library, need not be
|
| 295 |
+
included in conveying the object code work.
|
| 296 |
+
|
| 297 |
+
A "User Product" is either (1) a "consumer product", which means any
|
| 298 |
+
tangible personal property which is normally used for personal, family,
|
| 299 |
+
or household purposes, or (2) anything designed or sold for incorporation
|
| 300 |
+
into a dwelling. In determining whether a product is a consumer product,
|
| 301 |
+
doubtful cases shall be resolved in favor of coverage. For a particular
|
| 302 |
+
product received by a particular user, "normally used" refers to a
|
| 303 |
+
typical or common use of that class of product, regardless of the status
|
| 304 |
+
of the particular user or of the way in which the particular user
|
| 305 |
+
actually uses, or expects or is expected to use, the product. A product
|
| 306 |
+
is a consumer product regardless of whether the product has substantial
|
| 307 |
+
commercial, industrial or non-consumer uses, unless such uses represent
|
| 308 |
+
the only significant mode of use of the product.
|
| 309 |
+
|
| 310 |
+
"Installation Information" for a User Product means any methods,
|
| 311 |
+
procedures, authorization keys, or other information required to install
|
| 312 |
+
and execute modified versions of a covered work in that User Product from
|
| 313 |
+
a modified version of its Corresponding Source. The information must
|
| 314 |
+
suffice to ensure that the continued functioning of the modified object
|
| 315 |
+
code is in no case prevented or interfered with solely because
|
| 316 |
+
modification has been made.
|
| 317 |
+
|
| 318 |
+
If you convey an object code work under this section in, or with, or
|
| 319 |
+
specifically for use in, a User Product, and the conveying occurs as
|
| 320 |
+
part of a transaction in which the right of possession and use of the
|
| 321 |
+
User Product is transferred to the recipient in perpetuity or for a
|
| 322 |
+
fixed term (regardless of how the transaction is characterized), the
|
| 323 |
+
Corresponding Source conveyed under this section must be accompanied
|
| 324 |
+
by the Installation Information. But this requirement does not apply
|
| 325 |
+
if neither you nor any third party retains the ability to install
|
| 326 |
+
modified object code on the User Product (for example, the work has
|
| 327 |
+
been installed in ROM).
|
| 328 |
+
|
| 329 |
+
The requirement to provide Installation Information does not include a
|
| 330 |
+
requirement to continue to provide support service, warranty, or updates
|
| 331 |
+
for a work that has been modified or installed by the recipient, or for
|
| 332 |
+
the User Product in which it has been modified or installed. Access to a
|
| 333 |
+
network may be denied when the modification itself materially and
|
| 334 |
+
adversely affects the operation of the network or violates the rules and
|
| 335 |
+
protocols for communication across the network.
|
| 336 |
+
|
| 337 |
+
Corresponding Source conveyed, and Installation Information provided,
|
| 338 |
+
in accord with this section must be in a format that is publicly
|
| 339 |
+
documented (and with an implementation available to the public in
|
| 340 |
+
source code form), and must require no special password or key for
|
| 341 |
+
unpacking, reading or copying.
|
| 342 |
+
|
| 343 |
+
7. Additional Terms.
|
| 344 |
+
|
| 345 |
+
"Additional permissions" are terms that supplement the terms of this
|
| 346 |
+
License by making exceptions from one or more of its conditions.
|
| 347 |
+
Additional permissions that are applicable to the entire Program shall
|
| 348 |
+
be treated as though they were included in this License, to the extent
|
| 349 |
+
that they are valid under applicable law. If additional permissions
|
| 350 |
+
apply only to part of the Program, that part may be used separately
|
| 351 |
+
under those permissions, but the entire Program remains governed by
|
| 352 |
+
this License without regard to the additional permissions.
|
| 353 |
+
|
| 354 |
+
When you convey a copy of a covered work, you may at your option
|
| 355 |
+
remove any additional permissions from that copy, or from any part of
|
| 356 |
+
it. (Additional permissions may be written to require their own
|
| 357 |
+
removal in certain cases when you modify the work.) You may place
|
| 358 |
+
additional permissions on material, added by you to a covered work,
|
| 359 |
+
for which you have or can give appropriate copyright permission.
|
| 360 |
+
|
| 361 |
+
Notwithstanding any other provision of this License, for material you
|
| 362 |
+
add to a covered work, you may (if authorized by the copyright holders of
|
| 363 |
+
that material) supplement the terms of this License with terms:
|
| 364 |
+
|
| 365 |
+
a) Disclaiming warranty or limiting liability differently from the
|
| 366 |
+
terms of sections 15 and 16 of this License; or
|
| 367 |
+
|
| 368 |
+
b) Requiring preservation of specified reasonable legal notices or
|
| 369 |
+
author attributions in that material or in the Appropriate Legal
|
| 370 |
+
Notices displayed by works containing it; or
|
| 371 |
+
|
| 372 |
+
c) Prohibiting misrepresentation of the origin of that material, or
|
| 373 |
+
requiring that modified versions of such material be marked in
|
| 374 |
+
reasonable ways as different from the original version; or
|
| 375 |
+
|
| 376 |
+
d) Limiting the use for publicity purposes of names of licensors or
|
| 377 |
+
authors of the material; or
|
| 378 |
+
|
| 379 |
+
e) Declining to grant rights under trademark law for use of some
|
| 380 |
+
trade names, trademarks, or service marks; or
|
| 381 |
+
|
| 382 |
+
f) Requiring indemnification of licensors and authors of that
|
| 383 |
+
material by anyone who conveys the material (or modified versions of
|
| 384 |
+
it) with contractual assumptions of liability to the recipient, for
|
| 385 |
+
any liability that these contractual assumptions directly impose on
|
| 386 |
+
those licensors and authors.
|
| 387 |
+
|
| 388 |
+
All other non-permissive additional terms are considered "further
|
| 389 |
+
restrictions" within the meaning of section 10. If the Program as you
|
| 390 |
+
received it, or any part of it, contains a notice stating that it is
|
| 391 |
+
governed by this License along with a term that is a further
|
| 392 |
+
restriction, you may remove that term. If a license document contains
|
| 393 |
+
a further restriction but permits relicensing or conveying under this
|
| 394 |
+
License, you may add to a covered work material governed by the terms
|
| 395 |
+
of that license document, provided that the further restriction does
|
| 396 |
+
not survive such relicensing or conveying.
|
| 397 |
+
|
| 398 |
+
If you add terms to a covered work in accord with this section, you
|
| 399 |
+
must place, in the relevant source files, a statement of the
|
| 400 |
+
additional terms that apply to those files, or a notice indicating
|
| 401 |
+
where to find the applicable terms.
|
| 402 |
+
|
| 403 |
+
Additional terms, permissive or non-permissive, may be stated in the
|
| 404 |
+
form of a separately written license, or stated as exceptions;
|
| 405 |
+
the above requirements apply either way.
|
| 406 |
+
|
| 407 |
+
8. Termination.
|
| 408 |
+
|
| 409 |
+
You may not propagate or modify a covered work except as expressly
|
| 410 |
+
provided under this License. Any attempt otherwise to propagate or
|
| 411 |
+
modify it is void, and will automatically terminate your rights under
|
| 412 |
+
this License (including any patent licenses granted under the third
|
| 413 |
+
paragraph of section 11).
|
| 414 |
+
|
| 415 |
+
However, if you cease all violation of this License, then your
|
| 416 |
+
license from a particular copyright holder is reinstated (a)
|
| 417 |
+
provisionally, unless and until the copyright holder explicitly and
|
| 418 |
+
finally terminates your license, and (b) permanently, if the copyright
|
| 419 |
+
holder fails to notify you of the violation by some reasonable means
|
| 420 |
+
prior to 60 days after the cessation.
|
| 421 |
+
|
| 422 |
+
Moreover, your license from a particular copyright holder is
|
| 423 |
+
reinstated permanently if the copyright holder notifies you of the
|
| 424 |
+
violation by some reasonable means, this is the first time you have
|
| 425 |
+
received notice of violation of this License (for any work) from that
|
| 426 |
+
copyright holder, and you cure the violation prior to 30 days after
|
| 427 |
+
your receipt of the notice.
|
| 428 |
+
|
| 429 |
+
Termination of your rights under this section does not terminate the
|
| 430 |
+
licenses of parties who have received copies or rights from you under
|
| 431 |
+
this License. If your rights have been terminated and not permanently
|
| 432 |
+
reinstated, you do not qualify to receive new licenses for the same
|
| 433 |
+
material under section 10.
|
| 434 |
+
|
| 435 |
+
9. Acceptance Not Required for Having Copies.
|
| 436 |
+
|
| 437 |
+
You are not required to accept this License in order to receive or
|
| 438 |
+
run a copy of the Program. Ancillary propagation of a covered work
|
| 439 |
+
occurring solely as a consequence of using peer-to-peer transmission
|
| 440 |
+
to receive a copy likewise does not require acceptance. However,
|
| 441 |
+
nothing other than this License grants you permission to propagate or
|
| 442 |
+
modify any covered work. These actions infringe copyright if you do
|
| 443 |
+
not accept this License. Therefore, by modifying or propagating a
|
| 444 |
+
covered work, you indicate your acceptance of this License to do so.
|
| 445 |
+
|
| 446 |
+
10. Automatic Licensing of Downstream Recipients.
|
| 447 |
+
|
| 448 |
+
Each time you convey a covered work, the recipient automatically
|
| 449 |
+
receives a license from the original licensors, to run, modify and
|
| 450 |
+
propagate that work, subject to this License. You are not responsible
|
| 451 |
+
for enforcing compliance by third parties with this License.
|
| 452 |
+
|
| 453 |
+
An "entity transaction" is a transaction transferring control of an
|
| 454 |
+
organization, or substantially all assets of one, or subdividing an
|
| 455 |
+
organization, or merging organizations. If propagation of a covered
|
| 456 |
+
work results from an entity transaction, each party to that
|
| 457 |
+
transaction who receives a copy of the work also receives whatever
|
| 458 |
+
licenses to the work the party's predecessor in interest had or could
|
| 459 |
+
give under the previous paragraph, plus a right to possession of the
|
| 460 |
+
Corresponding Source of the work from the predecessor in interest, if
|
| 461 |
+
the predecessor has it or can get it with reasonable efforts.
|
| 462 |
+
|
| 463 |
+
You may not impose any further restrictions on the exercise of the
|
| 464 |
+
rights granted or affirmed under this License. For example, you may
|
| 465 |
+
not impose a license fee, royalty, or other charge for exercise of
|
| 466 |
+
rights granted under this License, and you may not initiate litigation
|
| 467 |
+
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
| 468 |
+
any patent claim is infringed by making, using, selling, offering for
|
| 469 |
+
sale, or importing the Program or any portion of it.
|
| 470 |
+
|
| 471 |
+
11. Patents.
|
| 472 |
+
|
| 473 |
+
A "contributor" is a copyright holder who authorizes use under this
|
| 474 |
+
License of the Program or a work on which the Program is based. The
|
| 475 |
+
work thus licensed is called the contributor's "contributor version".
|
| 476 |
+
|
| 477 |
+
A contributor's "essential patent claims" are all patent claims
|
| 478 |
+
owned or controlled by the contributor, whether already acquired or
|
| 479 |
+
hereafter acquired, that would be infringed by some manner, permitted
|
| 480 |
+
by this License, of making, using, or selling its contributor version,
|
| 481 |
+
but do not include claims that would be infringed only as a
|
| 482 |
+
consequence of further modification of the contributor version. For
|
| 483 |
+
purposes of this definition, "control" includes the right to grant
|
| 484 |
+
patent sublicenses in a manner consistent with the requirements of
|
| 485 |
+
this License.
|
| 486 |
+
|
| 487 |
+
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
| 488 |
+
patent license under the contributor's essential patent claims, to
|
| 489 |
+
make, use, sell, offer for sale, import and otherwise run, modify and
|
| 490 |
+
propagate the contents of its contributor version.
|
| 491 |
+
|
| 492 |
+
In the following three paragraphs, a "patent license" is any express
|
| 493 |
+
agreement or commitment, however denominated, not to enforce a patent
|
| 494 |
+
(such as an express permission to practice a patent or covenant not to
|
| 495 |
+
sue for patent infringement). To "grant" such a patent license to a
|
| 496 |
+
party means to make such an agreement or commitment not to enforce a
|
| 497 |
+
patent against the party.
|
| 498 |
+
|
| 499 |
+
If you convey a covered work, knowingly relying on a patent license,
|
| 500 |
+
and the Corresponding Source of the work is not available for anyone
|
| 501 |
+
to copy, free of charge and under the terms of this License, through a
|
| 502 |
+
publicly available network server or other readily accessible means,
|
| 503 |
+
then you must either (1) cause the Corresponding Source to be so
|
| 504 |
+
available, or (2) arrange to deprive yourself of the benefit of the
|
| 505 |
+
patent license for this particular work, or (3) arrange, in a manner
|
| 506 |
+
consistent with the requirements of this License, to extend the patent
|
| 507 |
+
license to downstream recipients. "Knowingly relying" means you have
|
| 508 |
+
actual knowledge that, but for the patent license, your conveying the
|
| 509 |
+
covered work in a country, or your recipient's use of the covered work
|
| 510 |
+
in a country, would infringe one or more identifiable patents in that
|
| 511 |
+
country that you have reason to believe are valid.
|
| 512 |
+
|
| 513 |
+
If, pursuant to or in connection with a single transaction or
|
| 514 |
+
arrangement, you convey, or propagate by procuring conveyance of, a
|
| 515 |
+
covered work, and grant a patent license to some of the parties
|
| 516 |
+
receiving the covered work authorizing them to use, propagate, modify
|
| 517 |
+
or convey a specific copy of the covered work, then the patent license
|
| 518 |
+
you grant is automatically extended to all recipients of the covered
|
| 519 |
+
work and works based on it.
|
| 520 |
+
|
| 521 |
+
A patent license is "discriminatory" if it does not include within
|
| 522 |
+
the scope of its coverage, prohibits the exercise of, or is
|
| 523 |
+
conditioned on the non-exercise of one or more of the rights that are
|
| 524 |
+
specifically granted under this License. You may not convey a covered
|
| 525 |
+
work if you are a party to an arrangement with a third party that is
|
| 526 |
+
in the business of distributing software, under which you make payment
|
| 527 |
+
to the third party based on the extent of your activity of conveying
|
| 528 |
+
the work, and under which the third party grants, to any of the
|
| 529 |
+
parties who would receive the covered work from you, a discriminatory
|
| 530 |
+
patent license (a) in connection with copies of the covered work
|
| 531 |
+
conveyed by you (or copies made from those copies), or (b) primarily
|
| 532 |
+
for and in connection with specific products or compilations that
|
| 533 |
+
contain the covered work, unless you entered into that arrangement,
|
| 534 |
+
or that patent license was granted, prior to 28 March 2007.
|
| 535 |
+
|
| 536 |
+
Nothing in this License shall be construed as excluding or limiting
|
| 537 |
+
any implied license or other defenses to infringement that may
|
| 538 |
+
otherwise be available to you under applicable patent law.
|
| 539 |
+
|
| 540 |
+
12. No Surrender of Others' Freedom.
|
| 541 |
+
|
| 542 |
+
If conditions are imposed on you (whether by court order, agreement or
|
| 543 |
+
otherwise) that contradict the conditions of this License, they do not
|
| 544 |
+
excuse you from the conditions of this License. If you cannot convey a
|
| 545 |
+
covered work so as to satisfy simultaneously your obligations under this
|
| 546 |
+
License and any other pertinent obligations, then as a consequence you may
|
| 547 |
+
not convey it at all. For example, if you agree to terms that obligate you
|
| 548 |
+
to collect a royalty for further conveying from those to whom you convey
|
| 549 |
+
the Program, the only way you could satisfy both those terms and this
|
| 550 |
+
License would be to refrain entirely from conveying the Program.
|
| 551 |
+
|
| 552 |
+
13. Use with the GNU Affero General Public License.
|
| 553 |
+
|
| 554 |
+
Notwithstanding any other provision of this License, you have
|
| 555 |
+
permission to link or combine any covered work with a work licensed
|
| 556 |
+
under version 3 of the GNU Affero General Public License into a single
|
| 557 |
+
combined work, and to convey the resulting work. The terms of this
|
| 558 |
+
License will continue to apply to the part which is the covered work,
|
| 559 |
+
but the special requirements of the GNU Affero General Public License,
|
| 560 |
+
section 13, concerning interaction through a network will apply to the
|
| 561 |
+
combination as such.
|
| 562 |
+
|
| 563 |
+
14. Revised Versions of this License.
|
| 564 |
+
|
| 565 |
+
The Free Software Foundation may publish revised and/or new versions of
|
| 566 |
+
the GNU General Public License from time to time. Such new versions will
|
| 567 |
+
be similar in spirit to the present version, but may differ in detail to
|
| 568 |
+
address new problems or concerns.
|
| 569 |
+
|
| 570 |
+
Each version is given a distinguishing version number. If the
|
| 571 |
+
Program specifies that a certain numbered version of the GNU General
|
| 572 |
+
Public License "or any later version" applies to it, you have the
|
| 573 |
+
option of following the terms and conditions either of that numbered
|
| 574 |
+
version or of any later version published by the Free Software
|
| 575 |
+
Foundation. If the Program does not specify a version number of the
|
| 576 |
+
GNU General Public License, you may choose any version ever published
|
| 577 |
+
by the Free Software Foundation.
|
| 578 |
+
|
| 579 |
+
If the Program specifies that a proxy can decide which future
|
| 580 |
+
versions of the GNU General Public License can be used, that proxy's
|
| 581 |
+
public statement of acceptance of a version permanently authorizes you
|
| 582 |
+
to choose that version for the Program.
|
| 583 |
+
|
| 584 |
+
Later license versions may give you additional or different
|
| 585 |
+
permissions. However, no additional obligations are imposed on any
|
| 586 |
+
author or copyright holder as a result of your choosing to follow a
|
| 587 |
+
later version.
|
| 588 |
+
|
| 589 |
+
15. Disclaimer of Warranty.
|
| 590 |
+
|
| 591 |
+
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
| 592 |
+
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
| 593 |
+
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
| 594 |
+
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
| 595 |
+
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
| 596 |
+
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
| 597 |
+
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
| 598 |
+
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
| 599 |
+
|
| 600 |
+
16. Limitation of Liability.
|
| 601 |
+
|
| 602 |
+
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
| 603 |
+
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
| 604 |
+
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
| 605 |
+
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
| 606 |
+
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
| 607 |
+
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
| 608 |
+
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
| 609 |
+
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
| 610 |
+
SUCH DAMAGES.
|
| 611 |
+
|
| 612 |
+
17. Interpretation of Sections 15 and 16.
|
| 613 |
+
|
| 614 |
+
If the disclaimer of warranty and limitation of liability provided
|
| 615 |
+
above cannot be given local legal effect according to their terms,
|
| 616 |
+
reviewing courts shall apply local law that most closely approximates
|
| 617 |
+
an absolute waiver of all civil liability in connection with the
|
| 618 |
+
Program, unless a warranty or assumption of liability accompanies a
|
| 619 |
+
copy of the Program in return for a fee.
|
| 620 |
+
|
| 621 |
+
END OF TERMS AND CONDITIONS
|
| 622 |
+
|
| 623 |
+
How to Apply These Terms to Your New Programs
|
| 624 |
+
|
| 625 |
+
If you develop a new program, and you want it to be of the greatest
|
| 626 |
+
possible use to the public, the best way to achieve this is to make it
|
| 627 |
+
free software which everyone can redistribute and change under these terms.
|
| 628 |
+
|
| 629 |
+
To do so, attach the following notices to the program. It is safest
|
| 630 |
+
to attach them to the start of each source file to most effectively
|
| 631 |
+
state the exclusion of warranty; and each file should have at least
|
| 632 |
+
the "copyright" line and a pointer to where the full notice is found.
|
| 633 |
+
|
| 634 |
+
<one line to give the program's name and a brief idea of what it does.>
|
| 635 |
+
Copyright (C) <year> <name of author>
|
| 636 |
+
|
| 637 |
+
This program is free software: you can redistribute it and/or modify
|
| 638 |
+
it under the terms of the GNU General Public License as published by
|
| 639 |
+
the Free Software Foundation, either version 3 of the License, or
|
| 640 |
+
(at your option) any later version.
|
| 641 |
+
|
| 642 |
+
This program is distributed in the hope that it will be useful,
|
| 643 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 644 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 645 |
+
GNU General Public License for more details.
|
| 646 |
+
|
| 647 |
+
You should have received a copy of the GNU General Public License
|
| 648 |
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
| 649 |
+
|
| 650 |
+
Also add information on how to contact you by electronic and paper mail.
|
| 651 |
+
|
| 652 |
+
If the program does terminal interaction, make it output a short
|
| 653 |
+
notice like this when it starts in an interactive mode:
|
| 654 |
+
|
| 655 |
+
<program> Copyright (C) <year> <name of author>
|
| 656 |
+
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
| 657 |
+
This is free software, and you are welcome to redistribute it
|
| 658 |
+
under certain conditions; type `show c' for details.
|
| 659 |
+
|
| 660 |
+
The hypothetical commands `show w' and `show c' should show the appropriate
|
| 661 |
+
parts of the General Public License. Of course, your program's commands
|
| 662 |
+
might be different; for a GUI interface, you would use an "about box".
|
| 663 |
+
|
| 664 |
+
You should also get your employer (if you work as a programmer) or school,
|
| 665 |
+
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
| 666 |
+
For more information on this, and how to apply and follow the GNU GPL, see
|
| 667 |
+
<http://www.gnu.org/licenses/>.
|
| 668 |
+
|
| 669 |
+
The GNU General Public License does not permit incorporating your program
|
| 670 |
+
into proprietary programs. If your program is a subroutine library, you
|
| 671 |
+
may consider it more useful to permit linking proprietary applications with
|
| 672 |
+
the library. If this is what you want to do, use the GNU Lesser General
|
| 673 |
+
Public License instead of this License. But first, please read
|
| 674 |
+
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
data/bionetgen/Perl2/Aux2/MakeBin.pl
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/perl
|
| 2 |
+
|
| 3 |
+
$bindir="../PerlBin";
|
| 4 |
+
|
| 5 |
+
@scripts= qw(
|
| 6 |
+
BNG2.pl
|
| 7 |
+
);
|
| 8 |
+
|
| 9 |
+
@modules= qw(
|
| 10 |
+
BNGModel.pm
|
| 11 |
+
BNGUtils.pm
|
| 12 |
+
Component.pm
|
| 13 |
+
ComponentType.pm
|
| 14 |
+
Map.pm
|
| 15 |
+
Molecule.pm
|
| 16 |
+
MoleculeType.pm
|
| 17 |
+
MoleculeTypesList.pm
|
| 18 |
+
Observable.pm
|
| 19 |
+
Param.pm
|
| 20 |
+
ParamList.pm
|
| 21 |
+
RateLaw.pm
|
| 22 |
+
Rxn.pm
|
| 23 |
+
RxnList.pm
|
| 24 |
+
RxnRule.pm
|
| 25 |
+
Species.pm
|
| 26 |
+
SpeciesGraph.pm
|
| 27 |
+
SpeciesList.pm
|
| 28 |
+
);
|
| 29 |
+
|
| 30 |
+
#print join(" ", @modules),"\n";
|
| 31 |
+
print "Compiling modules.\n";
|
| 32 |
+
$n_compiled=0;
|
| 33 |
+
for my $module (@modules){
|
| 34 |
+
$modfile= "${bindir}/$module";
|
| 35 |
+
if (!-e $modfile || (-M $module < -M $modfile)){
|
| 36 |
+
print "Compiling module $module\n";
|
| 37 |
+
# Makes byte compiled version of each module
|
| 38 |
+
print `perlcc -B -o ${bindir}/$module $module`;
|
| 39 |
+
++$n_compiled;
|
| 40 |
+
} else {
|
| 41 |
+
print "Module $module up to date\n";
|
| 42 |
+
}
|
| 43 |
+
}
|
| 44 |
+
if (!$n_compiled){
|
| 45 |
+
print "All modules up to date.\n";
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
print "Compiling scripts.\n";
|
| 49 |
+
$n_compiled=0;
|
| 50 |
+
for my $script (@scripts){
|
| 51 |
+
$sfile= "${bindir}/$script";
|
| 52 |
+
$sfile=~ s/[.]pl$//;
|
| 53 |
+
if (!-e $sfile || (-M $script < -M $sfile)){
|
| 54 |
+
print "Compiling script $script\n";
|
| 55 |
+
# Makes byte compiled version of each module
|
| 56 |
+
print `perlcc -B -o ${bindir}/$sfile $script`;
|
| 57 |
+
++$n_compiled;
|
| 58 |
+
} else {
|
| 59 |
+
print "Script $script up to date\n";
|
| 60 |
+
}
|
| 61 |
+
}
|
| 62 |
+
if (!$n_compiled){
|
| 63 |
+
print "All scripts up to date.\n";
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
|
data/bionetgen/Perl2/Aux2/bnglstat.pl
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/perl
|
| 2 |
+
|
| 3 |
+
use FindBin;
|
| 4 |
+
use lib $FindBin::Bin;
|
| 5 |
+
use BNGModel;
|
| 6 |
+
use BNGUtils;
|
| 7 |
+
|
| 8 |
+
while (@ARGV){
|
| 9 |
+
my $file= shift(@ARGV);
|
| 10 |
+
my $model= BNGModel->new();
|
| 11 |
+
if ($err=$model->readFile($file,{no_exec=>1})){exit_error($err);}
|
| 12 |
+
}
|
data/bionetgen/Perl2/Aux2/count_blocks.pl
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/perl
|
| 2 |
+
|
| 3 |
+
for $file (@ARGV){
|
| 4 |
+
open(FILE,$file) || die "Couldn't open $file: $!\n";
|
| 5 |
+
print "$file:\n";
|
| 6 |
+
while(<FILE>){
|
| 7 |
+
if (/^s*begin\s+(\S.*)$/){
|
| 8 |
+
$bname= $1;
|
| 9 |
+
$bname=~ s/\s*$//;
|
| 10 |
+
$nentry=0;
|
| 11 |
+
while(<FILE>){
|
| 12 |
+
if (/^\s*end\s+(\S.*)$/){
|
| 13 |
+
my $ename= $1;
|
| 14 |
+
$ename=~ s/\s*$//;
|
| 15 |
+
if ($bname ne $ename){
|
| 16 |
+
die "end $ename not compatible with $bname\n";
|
| 17 |
+
}
|
| 18 |
+
last;
|
| 19 |
+
}
|
| 20 |
+
++$nentry;
|
| 21 |
+
}
|
| 22 |
+
printf "%7d %s\n", $nentry, $bname;
|
| 23 |
+
}
|
| 24 |
+
}
|
| 25 |
+
close(FILE);
|
| 26 |
+
}
|
data/bionetgen/Perl2/Aux2/count_lines.pl
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/perl
|
| 2 |
+
|
| 3 |
+
$source=<<"EOF";
|
| 4 |
+
BNGAgent.pm
|
| 5 |
+
BNGMessages.pm
|
| 6 |
+
BNGModel.pm
|
| 7 |
+
BNGOptions.pm
|
| 8 |
+
BNGUtils.pm
|
| 9 |
+
Compartment.pm
|
| 10 |
+
CompartmentList.pm
|
| 11 |
+
Component.pm
|
| 12 |
+
ComponentType.pm
|
| 13 |
+
Expression.pm
|
| 14 |
+
HNauty.pm
|
| 15 |
+
MacroBNGModel.pm
|
| 16 |
+
Map.pm
|
| 17 |
+
Molecule.pm
|
| 18 |
+
MoleculeType.pm
|
| 19 |
+
MoleculeTypesList.pm
|
| 20 |
+
Observable.pm
|
| 21 |
+
Param.pm
|
| 22 |
+
ParamList.pm
|
| 23 |
+
RateLaw.pm
|
| 24 |
+
Rxn.pm
|
| 25 |
+
RxnList.pm
|
| 26 |
+
RxnRule.pm
|
| 27 |
+
Species.pm
|
| 28 |
+
SpeciesGraph.pm
|
| 29 |
+
SpeciesList.pm
|
| 30 |
+
EOF
|
| 31 |
+
|
| 32 |
+
# count lines of source code by the number of ;'s
|
| 33 |
+
|
| 34 |
+
if (@ARGV){
|
| 35 |
+
@files=@ARGV;
|
| 36 |
+
} else {
|
| 37 |
+
@files= split(' ',$source);
|
| 38 |
+
}
|
| 39 |
+
my $n_lines_tot=0;
|
| 40 |
+
for my $file (@files){
|
| 41 |
+
my $n_lines=0;
|
| 42 |
+
open(IN,$file) || die "Couldn't open $file:$?\n";
|
| 43 |
+
while(<IN>){
|
| 44 |
+
if (/;\s*$/){
|
| 45 |
+
++$n_lines;
|
| 46 |
+
}
|
| 47 |
+
}
|
| 48 |
+
print "$file:$n_lines\n";
|
| 49 |
+
$n_lines_tot+= $n_lines;
|
| 50 |
+
}
|
| 51 |
+
print "TOTAL:$n_lines_tot\n";
|
data/bionetgen/Perl2/Aux2/countdown.pl
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/perl
|
| 2 |
+
|
| 3 |
+
# doesn't work
|
| 4 |
+
for $i (10..1){
|
| 5 |
+
print "$i\n";
|
| 6 |
+
}
|
data/bionetgen/Perl2/Aux2/diff_cdat.pl
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/perl
|
| 2 |
+
|
| 3 |
+
# Program verify.pl compares two time course files. For the
|
| 4 |
+
# purpose of computing the norm error, the second file is the reference.
|
| 5 |
+
#
|
| 6 |
+
# Usage verify.pl datafile1 [datafile2]
|
| 7 |
+
#
|
| 8 |
+
# If no second filename is given, the script will automatically look in the
|
| 9 |
+
# database of results in the $BioNetGenRoot/VERIFY directory.
|
| 10 |
+
#
|
| 11 |
+
# Outputs:
|
| 12 |
+
# NORMERR: The computed norm error is printed
|
| 13 |
+
# Either SUCCESSFUL BUILD or PROBLEM WITH BUILD depending upon magnitude of
|
| 14 |
+
# norm error. The configuration variable $BUILD_ERR_THRESH can be set in
|
| 15 |
+
# bngrc or the local .bngrc file.
|
| 16 |
+
#
|
| 17 |
+
# Thanks to Robert Seletsky, the original author of this script, and Stan
|
| 18 |
+
# Steinberg, who suggested using the norm error
|
| 19 |
+
# err= |m2-m1|/|m2|
|
| 20 |
+
# = sqrt( sum_{ij}((m2_{ij} - m1_{ij})**2)/ sum_{ij}(m2_{ij})**2),
|
| 21 |
+
# where m1 and m2 are the arrays containing the time course data at i time
|
| 22 |
+
# points for j variables.
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
$BUILD_ERR_THRESH= 1e-7;
|
| 26 |
+
$COLUMN_OFFSET=0;
|
| 27 |
+
|
| 28 |
+
# Read command line arguments
|
| 29 |
+
while ($ARGV[0] =~ /^-/){
|
| 30 |
+
$_ = shift;
|
| 31 |
+
if (/^-offset$/){
|
| 32 |
+
$COLUMN_OFFSET= shift;
|
| 33 |
+
}
|
| 34 |
+
else{
|
| 35 |
+
exit_error("Unrecognized command line option $_");
|
| 36 |
+
}
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
if (($#ARGV!= 1)) {
|
| 40 |
+
die "Usage: $0 filename filename2\n";
|
| 41 |
+
}
|
| 42 |
+
$rfilename = shift;
|
| 43 |
+
$rfilename2= shift;
|
| 44 |
+
|
| 45 |
+
#print "Comparing $rfilename $rfilename2\n";
|
| 46 |
+
|
| 47 |
+
open (RFILE, $rfilename) or die "Can't open $rfilename: $!\n";
|
| 48 |
+
$i=0;
|
| 49 |
+
@data=();
|
| 50 |
+
@times=();
|
| 51 |
+
while (<RFILE>){
|
| 52 |
+
s/\#.*$//; # remove comments
|
| 53 |
+
next unless /\S+/;
|
| 54 |
+
($time, @dat)= split(' ');
|
| 55 |
+
push @times, $time;
|
| 56 |
+
foreach $j (0..$#dat){
|
| 57 |
+
$data[$i][$j]= $dat[$j];
|
| 58 |
+
}
|
| 59 |
+
++$i;
|
| 60 |
+
}
|
| 61 |
+
close(RFILE);
|
| 62 |
+
|
| 63 |
+
open (RFILE, $rfilename2) or die "Can't open $rfilename2: $!\n";
|
| 64 |
+
$i=0;
|
| 65 |
+
@data2=();
|
| 66 |
+
@times2=();
|
| 67 |
+
while (<RFILE>){
|
| 68 |
+
s/\#.*$//; # remove comments
|
| 69 |
+
next unless /\S+/;
|
| 70 |
+
($time, @dat)= split(' ');
|
| 71 |
+
push @times2, $time;
|
| 72 |
+
foreach $j (0..$#dat){
|
| 73 |
+
$data2[$i][$j]= $dat[$j];
|
| 74 |
+
}
|
| 75 |
+
++$i;
|
| 76 |
+
}
|
| 77 |
+
close(RFILE);
|
| 78 |
+
|
| 79 |
+
# Check that the time points in the two files are the same
|
| 80 |
+
if ($#times != $#times2){
|
| 81 |
+
printf "Time points are incompatible\n";
|
| 82 |
+
printf "%d time point(s)in $rfilename.\n", $#times+1;
|
| 83 |
+
printf "%d time point(s)in $rfilename2.\n", $#times2+1;
|
| 84 |
+
exit(1);
|
| 85 |
+
}
|
| 86 |
+
for $i (0..$#times){
|
| 87 |
+
if ($times[$i]!= $times2[$i]){
|
| 88 |
+
printf "Time points are incompatible\n";
|
| 89 |
+
exit(1);
|
| 90 |
+
}
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
# Compute normerr
|
| 94 |
+
$sresult= &normerr(\@data, \@data2);
|
| 95 |
+
print "$sresult\n";
|
| 96 |
+
exit(0);
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
# Compute norm error between two data sets stored in two rectangular arrays m1
|
| 100 |
+
# and m2 of the same dimension (not checked)
|
| 101 |
+
sub normerr {
|
| 102 |
+
my $m1= shift;
|
| 103 |
+
my $m2= shift;
|
| 104 |
+
|
| 105 |
+
my $del2=0;
|
| 106 |
+
my $ref2=0;
|
| 107 |
+
|
| 108 |
+
my $ilast= $#$m1;
|
| 109 |
+
my $jlast= $#{$$m1[0]};
|
| 110 |
+
for my $i (0..$ilast){
|
| 111 |
+
for my $j (0..$jlast){
|
| 112 |
+
my $j2= $j+$COLUMN_OFFSET;
|
| 113 |
+
# print $$m2[$i][$j]," ", $$m1[$i][$j],"\n";
|
| 114 |
+
# printf "$j $j2 %.2e %.2e\n", $$m1[$i][$j], $$m2[$i][$j2];
|
| 115 |
+
$del2+= ($$m2[$i][$j2] - $$m1[$i][$j])**2;
|
| 116 |
+
$ref2+= ($$m2[$i][$j2])**2;
|
| 117 |
+
}
|
| 118 |
+
}
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/perl
|
| 2 |
+
|
| 3 |
+
use Data::Dumper;
|
| 4 |
+
|
| 5 |
+
$express= {
|
| 6 |
+
type=>'AND',
|
| 7 |
+
# type=>'OR',
|
| 8 |
+
# arg1=>{type=>'REF', arg1=>'a'},
|
| 9 |
+
arg1=>{type=>'NOT', arg1=>{type=>'REF', arg1=>'a'}},
|
| 10 |
+
arg2=>{type=>'REF', arg1=>'b'}
|
| 11 |
+
};
|
| 12 |
+
|
| 13 |
+
$list= ['a','b', 'ab','abc', 'ac', 'c','bc'];
|
| 14 |
+
|
| 15 |
+
#print Dumper($express);
|
| 16 |
+
#print Dumper($list);
|
| 17 |
+
|
| 18 |
+
# WARNING: NOT doesn't work properly unless it's surrounded by parenthesis
|
| 19 |
+
|
| 20 |
+
#$string= "a AND (NOT c) AND b";
|
| 21 |
+
#$string= "NOT (a AND b AND c)";
|
| 22 |
+
#$string= "(a AND (NOT b)) OR (b AND (NOT a))";
|
| 23 |
+
#$string= "(a OR b) AND (NOT (a AND b))";
|
| 24 |
+
$string= "(a) AND (b)";
|
| 25 |
+
$express= read_express(\$string);
|
| 26 |
+
print Dumper($express),"\n";
|
| 27 |
+
print join(" ",@{eval_express($express, $list)}),"\n";
|
| 28 |
+
|
| 29 |
+
sub eval_express{
|
| 30 |
+
my $express= shift;
|
| 31 |
+
my $list= shift;
|
| 32 |
+
|
| 33 |
+
my $type= $express->{type};
|
| 34 |
+
my $arg1= $express->{arg1};
|
| 35 |
+
my $arg2= $express->{arg2};
|
| 36 |
+
if ($type eq 'AND'){
|
| 37 |
+
return(eval_express($arg2, eval_express($arg1,$list)));
|
| 38 |
+
}
|
| 39 |
+
elsif ($type eq 'OR'){
|
| 40 |
+
my $list1= eval_express($arg1, $list);
|
| 41 |
+
my $list2= eval_express($arg2, $list);
|
| 42 |
+
return([@$list1,@$list2]);
|
| 43 |
+
}
|
| 44 |
+
elsif ($type eq 'XOR'){
|
| 45 |
+
my $list1= eval_express($arg1, $list);
|
| 46 |
+
my $list2= eval_express($arg2, $list);
|
| 47 |
+
my %remove=();
|
| 48 |
+
for my $item (@$list1){
|
| 49 |
+
$remove{$item}=1;
|
| 50 |
+
}
|
| 51 |
+
my @lnew=();
|
| 52 |
+
for my $item (@$list2){
|
| 53 |
+
push @lnew, $item if (!($remove{$item}));
|
| 54 |
+
}
|
| 55 |
+
return([@lnew]);
|
| 56 |
+
}
|
| 57 |
+
elsif ($type eq 'NOT'){
|
| 58 |
+
my $list1= eval_express($arg1, $list);
|
| 59 |
+
my %remove=();
|
| 60 |
+
for my $item (@$list1){
|
| 61 |
+
$remove{$item}=1;
|
| 62 |
+
}
|
| 63 |
+
my @lnew=();
|
| 64 |
+
for my $item (@$list){
|
| 65 |
+
push @lnew, $item if (!($remove{$item}));
|
| 66 |
+
}
|
| 67 |
+
return([@lnew]);
|
| 68 |
+
}
|
| 69 |
+
elsif ($type eq 'REF'){
|
| 70 |
+
my @lnew= ();
|
| 71 |
+
for my $item (@$list){
|
| 72 |
+
if ($item=~ /$arg1/){
|
| 73 |
+
push @lnew, $item;
|
| 74 |
+
}
|
| 75 |
+
}
|
| 76 |
+
return([@lnew]);
|
| 77 |
+
}
|
| 78 |
+
else {
|
| 79 |
+
return("");
|
| 80 |
+
}
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
{
|
| 84 |
+
my $open=0;
|
| 85 |
+
|
| 86 |
+
sub read_express {
|
| 87 |
+
my $string= shift;
|
| 88 |
+
my $express="";
|
| 89 |
+
my $expect_arg1=0;
|
| 90 |
+
my $expect_arg2=0;
|
| 91 |
+
while ($$string ne ""){
|
| 92 |
+
my $nh={};
|
| 93 |
+
$$string=~ s/^\s+//;
|
| 94 |
+
if ($$string=~ s/^\(// ){
|
| 95 |
+
++$open;
|
| 96 |
+
$nh= read_express($string);
|
| 97 |
+
}
|
| 98 |
+
elsif ($$string=~ s/^AND\s+//){
|
| 99 |
+
$nh->{type}= 'AND';
|
| 100 |
+
die "Null first operand for AND" unless ($express ne "");
|
| 101 |
+
$nh->{arg1}= $express;
|
| 102 |
+
$express= $nh;
|
| 103 |
+
$expect_arg2=1;
|
| 104 |
+
next;
|
| 105 |
+
}
|
| 106 |
+
elsif ($$string=~ s/^OR\s+//){
|
| 107 |
+
$nh->{type}= 'OR';
|
| 108 |
+
die "Null first operand for OR" unless ($express ne "");
|
| 109 |
+
$nh->{arg1}= $express;
|
| 110 |
+
$express= $nh;
|
| 111 |
+
$expect_arg2=1;
|
| 112 |
+
next;
|
| 113 |
+
}
|
| 114 |
+
elsif ($$string=~ s/^XOR\s+//){
|
| 115 |
+
die "XOR not yet implemented";
|
| 116 |
+
$nh->{type}= 'XOR';
|
| 117 |
+
die "Null first operand for XOR" unless ($express ne "");
|
| 118 |
+
$nh->{arg1}= $express;
|
| 119 |
+
$express= $nh;
|
| 120 |
+
$expect_arg2=1;
|
| 121 |
+
next;
|
| 122 |
+
}
|
| 123 |
+
elsif ($$string=~ s/^NOT\s+//){
|
| 124 |
+
$nh->{type}= 'NOT';
|
| 125 |
+
$express= $nh;
|
| 126 |
+
$expect_arg1=1;
|
| 127 |
+
next;
|
| 128 |
+
}
|
| 129 |
+
elsif ($$string=~ s/^([^\s\)]+)//){
|
| 130 |
+
$nh->{type}='REF';
|
| 131 |
+
$nh->{arg1}=$1;
|
| 132 |
+
}
|
| 133 |
+
elsif ($$string=~ s/^\)// ){
|
| 134 |
+
--$open;
|
| 135 |
+
die "Unmatched end parenthesis" if ($open<0);
|
| 136 |
+
die "Empty parenthesis" if ($express eq "");
|
| 137 |
+
return($express);
|
| 138 |
+
}
|
| 139 |
+
# print Dumper($nh),"\n";
|
| 140 |
+
if ($express eq ""){
|
| 141 |
+
$express= $nh;
|
| 142 |
+
}
|
| 143 |
+
elsif($expect_arg1){
|
| 144 |
+
$express->{arg1}=$nh;
|
| 145 |
+
$expect_arg1=0;
|
| 146 |
+
}
|
| 147 |
+
elsif($expect_arg2){
|
| 148 |
+
$express->{arg2}=$nh;
|
| 149 |
+
$expect_arg2=0;
|
| 150 |
+
}
|
| 151 |
+
else{
|
| 152 |
+
die "Expression without operator";
|
| 153 |
+
}
|
| 154 |
+
}
|
| 155 |
+
if ($expect_arg1){
|
| 156 |
+
die "Missing unary operand";
|
| 157 |
+
}
|
| 158 |
+
if ($expect_arg2){
|
| 159 |
+
die "Missing binary operand";
|
| 160 |
+
}
|
| 161 |
+
die "Missing end parenthesis" unless ($open==0);
|
| 162 |
+
return($express);
|
| 163 |
+
}
|
| 164 |
+
}
|
data/bionetgen/Perl2/Aux2/express_main.pl
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/perl
|
| 2 |
+
|
| 3 |
+
use FindBin;
|
| 4 |
+
use lib $FindBin::Bin;
|
| 5 |
+
use Param;
|
| 6 |
+
use ParamList;
|
| 7 |
+
use Expression;
|
| 8 |
+
|
| 9 |
+
$a1= Expression->new;
|
| 10 |
+
$a1->Type('NUM');
|
| 11 |
+
$a1->Arglist([5]);
|
| 12 |
+
|
| 13 |
+
$a2= Expression->new;
|
| 14 |
+
$a2->Type('NUM');
|
| 15 |
+
$a2->Arglist([12]);
|
| 16 |
+
|
| 17 |
+
#$a3= Expression->new;
|
| 18 |
+
|
| 19 |
+
$expr= Expression->new;
|
| 20 |
+
$expr->Type('-');
|
| 21 |
+
$expr->Arglist([($a1,$a2)]);
|
| 22 |
+
|
| 23 |
+
printf "a1 evaluates to %s\n", $a1->evaluate();
|
| 24 |
+
printf "a2 evaluates to %s\n", $a2->evaluate();
|
| 25 |
+
|
| 26 |
+
($val,$err) = $expr->evaluate();
|
| 27 |
+
if ($err){
|
| 28 |
+
die $err;
|
| 29 |
+
}
|
| 30 |
+
printf "expr evaluates to %s\n", $val;
|
| 31 |
+
|
| 32 |
+
$string="45e-26";
|
| 33 |
+
if (($number=getNumber(\$string)) ne ""){
|
| 34 |
+
printf "Number is %g\n", $number;
|
| 35 |
+
} else {
|
| 36 |
+
printf "%s does not start with a valid number\n", $string;
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
$plist= ParamList->new();
|
| 40 |
+
$plist->set("a",5);
|
| 41 |
+
$plist->set("b",10);
|
| 42 |
+
$plist->set("c",-10);
|
| 43 |
+
|
| 44 |
+
#$estring="1.01e-2*2-a/b+c^2";
|
| 45 |
+
$estring="-a^2 + b";
|
| 46 |
+
$estring_sav=$estring;
|
| 47 |
+
$expr= Expression->new();
|
| 48 |
+
if ($err=$expr->readString(\$estring,$plist)){
|
| 49 |
+
die $err;
|
| 50 |
+
}
|
| 51 |
+
printf "expr $estring_sav prints as %s\n", $expr->toString($plist);
|
| 52 |
+
($val,$err) = $expr->evaluate($plist);
|
| 53 |
+
if ($err){
|
| 54 |
+
die $err;
|
| 55 |
+
}
|
| 56 |
+
printf "expr $estring_sav evaluates to %g\n", $val;
|
| 57 |
+
|
| 58 |
+
printf "Before assignment, a=%d\n", $plist->evaluate("a");
|
| 59 |
+
$estring="a=a+5";
|
| 60 |
+
$err= ($expr=Expression->new())->readString(\$estring,$plist);
|
| 61 |
+
printf "After assignment, a=%d\n", $plist->evaluate("a");
|
| 62 |
+
|
| 63 |
+
$estring="x=(-a+5)/(c-10)";
|
| 64 |
+
#$estring="x=5";
|
| 65 |
+
$estring_sav=$estring;
|
| 66 |
+
$expr= Expression->new();
|
| 67 |
+
if ($err=$expr->readString(\$estring,$plist)){
|
| 68 |
+
die $err;
|
| 69 |
+
}
|
| 70 |
+
printf "expr $estring_sav prints as %s\n", $expr->toString($plist);
|
| 71 |
+
$val = $expr->evaluate($plist);
|
| 72 |
+
if ($expr->Err){
|
| 73 |
+
die $expr->Err;
|
| 74 |
+
}
|
| 75 |
+
printf "expr $estring_sav evaluates to %g\n", $val;
|
| 76 |
+
|
| 77 |
+
$estring="y=100^(d=1/2) g";
|
| 78 |
+
$estring_sav=$estring;
|
| 79 |
+
$expr= Expression->new();
|
| 80 |
+
if ($err=$expr->readString(\$estring,$plist,'\s')){
|
| 81 |
+
die $err;
|
| 82 |
+
}
|
| 83 |
+
printf "expr $estring_sav prints as %s\n", $expr->toString($plist);
|
| 84 |
+
$val = $expr->evaluate($plist);
|
| 85 |
+
if ($expr->Err){
|
| 86 |
+
die $expr->Err;
|
| 87 |
+
}
|
| 88 |
+
printf "expr $estring_sav evaluates to %g\n", $val;
|
| 89 |
+
|
| 90 |
+
print $plist->writeBNGL();
|
| 91 |
+
print $plist->toString();
|
| 92 |
+
|
| 93 |
+
#sub getNumber(){
|
| 94 |
+
sub getNumber{
|
| 95 |
+
my $string=shift;
|
| 96 |
+
my $number="";
|
| 97 |
+
|
| 98 |
+
# Decimal part
|
| 99 |
+
if ($$string=~ s/^([+-]?\d+[.]?\d*)//){
|
| 100 |
+
$number=$1;
|
| 101 |
+
}
|
| 102 |
+
elsif ($$string=~ s/^([+-]?[.]\d+)//){
|
| 103 |
+
$number=$1;
|
| 104 |
+
} else {
|
| 105 |
+
return("");
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
# Exponent part
|
| 109 |
+
if ($$string=~ s/^([DEFGdefg][+-]?\d+)//){
|
| 110 |
+
$number.=$1;
|
| 111 |
+
}
|
| 112 |
+
return($number);
|
| 113 |
+
}
|
| 114 |
+
|
data/bionetgen/Perl2/Aux2/group_size.pl
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/perl
|
| 2 |
+
# Count number of species matching a group
|
| 3 |
+
my @gnames;
|
| 4 |
+
my %gsize;
|
| 5 |
+
while(<>){
|
| 6 |
+
next unless (/^begin groups/);
|
| 7 |
+
while(<>){
|
| 8 |
+
last if (/^end groups/);
|
| 9 |
+
(my $index, my $name, my $glist)= split(' ');
|
| 10 |
+
my @specs= split(',',$glist);
|
| 11 |
+
push @gnames, $name;
|
| 12 |
+
$gsize{$name}=scalar(@specs);
|
| 13 |
+
}
|
| 14 |
+
}
|
| 15 |
+
foreach $group (@gnames){
|
| 16 |
+
printf "%s %d\n", $group, $gsize{$group};
|
| 17 |
+
}
|
data/bionetgen/Perl2/Aux2/runBNG.pl
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/perl
|
| 2 |
+
# $Id: runBNG.pl,v 1.2 2007/10/20 04:18:21 faeder Exp $
|
| 3 |
+
|
| 4 |
+
use FindBin;
|
| 5 |
+
use lib $FindBin::Bin;
|
| 6 |
+
use BNGModel;
|
| 7 |
+
use SpeciesList;
|
| 8 |
+
use BNGUtils;
|
| 9 |
+
use strict;
|
| 10 |
+
|
| 11 |
+
# Set to nonzero value to equilibrate model prior to introduction of one
|
| 12 |
+
# or more species. This is required for the fceri model because there is a
|
| 13 |
+
# constitutive (present without ligand) interaction between Lyn and FceRI.
|
| 14 |
+
my $t_equil=1000;
|
| 15 |
+
my $max_equil=100;
|
| 16 |
+
my @spec_equil=("Lig(l,l)");
|
| 17 |
+
|
| 18 |
+
# End point of production simulation and time point at which outputs will
|
| 19 |
+
# be reported.
|
| 20 |
+
my $t_end=600;
|
| 21 |
+
my $n_steps=1;
|
| 22 |
+
# Names of observables reported at integration end point
|
| 23 |
+
my @output_vars=("RecSykPS");
|
| 24 |
+
|
| 25 |
+
# Force regeneration of network prior to simulation
|
| 26 |
+
my $force_netgen=0;
|
| 27 |
+
|
| 28 |
+
#------ END OF USER DEFINED PARAMETERS -------
|
| 29 |
+
|
| 30 |
+
my $model= BNGModel->new();
|
| 31 |
+
my %params=();
|
| 32 |
+
while ($ARGV[0] =~ /^-/){
|
| 33 |
+
$_ = shift;
|
| 34 |
+
if (/^-g$/){
|
| 35 |
+
$force_netgen=1;
|
| 36 |
+
}
|
| 37 |
+
else{
|
| 38 |
+
exit_error("Unrecognized command line option $_");
|
| 39 |
+
}
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
# Get prefix and determine whether network has been generated
|
| 43 |
+
my $prefix= shift(@ARGV);
|
| 44 |
+
|
| 45 |
+
# Dup original STDOUT
|
| 46 |
+
open my $oldout, ">&STDOUT" or die "Can't dup STDOUT: $!";
|
| 47 |
+
|
| 48 |
+
# Redirect STDOUT to logfile
|
| 49 |
+
open(STDOUT,">${prefix}_runBNG.log");
|
| 50 |
+
|
| 51 |
+
# turn off output buffering on STDOUT
|
| 52 |
+
(select(*STDOUT), $|=1)[0];
|
| 53 |
+
|
| 54 |
+
printf "BioNetGen version %s\n", BNGversion();
|
| 55 |
+
|
| 56 |
+
if (!$force_netgen && -r "$prefix.net"){
|
| 57 |
+
# Read previously generate net file
|
| 58 |
+
my $file= "$prefix.net";
|
| 59 |
+
$params{file}=$file;
|
| 60 |
+
if (my $err=$model->readFile(\%params)){exit_error($err);}
|
| 61 |
+
} elsif (-r "$prefix.bngl") {
|
| 62 |
+
# Read BNGL file and generate network
|
| 63 |
+
my $file= "$prefix.bngl";
|
| 64 |
+
$params{file}=$file;
|
| 65 |
+
if (my $err=$model->readFile(\%params)){exit_error($err);}
|
| 66 |
+
if (my $err=$model->generate_network({overwrite=>1})){exit_error($err);}
|
| 67 |
+
} else {
|
| 68 |
+
exit_error("No BNGL or NET file could be found with prefix $prefix.");
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
# Hash indices of observables
|
| 72 |
+
my %obs_ind=();
|
| 73 |
+
my $oind=0;
|
| 74 |
+
for my $obs (@{$model->Observables}){
|
| 75 |
+
$obs_ind{$obs->Name}= $oind++;
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
# Set parameters to value of arguments
|
| 79 |
+
my $iparam=0;
|
| 80 |
+
for my $pvalue (@ARGV){
|
| 81 |
+
if (my $err=$model->ParamList->setIndex($iparam,$pvalue)){exit_error($err);}
|
| 82 |
+
++$iparam;
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
# Perform equilibration
|
| 86 |
+
if ($t_equil>0){
|
| 87 |
+
# Set equilibration variables to zero
|
| 88 |
+
my %val_equil=();
|
| 89 |
+
my $oldval;
|
| 90 |
+
for my $spec (@spec_equil){
|
| 91 |
+
# determine whether variable is species or concentration
|
| 92 |
+
(my $err, my $oldval)= $model->setConcentration($spec,0);
|
| 93 |
+
$err && exit_error($err);
|
| 94 |
+
$val_equil{$spec}= $oldval;
|
| 95 |
+
}
|
| 96 |
+
my $suff="runBNG_equil";
|
| 97 |
+
if (my $err=$model->simulate_ode({suffix=>$suff,t_end=>$t_equil,n_steps=>$max_equil,steady_state=>1,sparse=>1})){exit_error($err);}
|
| 98 |
+
# Reset equilibration variables
|
| 99 |
+
for my $spec (@spec_equil){
|
| 100 |
+
(my $err, my $oldval)= $model->setConcentration($spec,$val_equil{$spec});
|
| 101 |
+
$err && exit_error($err);
|
| 102 |
+
}
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
# Run simulation
|
| 106 |
+
my $suff="runBNG_run";
|
| 107 |
+
if (my $err=$model->simulate_ode({suffix=>$suff,t_end=>$t_end,n_steps=>$n_steps})){exit_error($err);}
|
| 108 |
+
|
| 109 |
+
# Report results
|
| 110 |
+
my $gdatfile= $prefix."_".$suff.".gdat";
|
| 111 |
+
my @output=();
|
| 112 |
+
if (-r "$gdatfile"){
|
| 113 |
+
print "Updating observable concentrations from $gdatfile\n";
|
| 114 |
+
open(GDAT, "$gdatfile");
|
| 115 |
+
my $last="";
|
| 116 |
+
while(<GDAT>){
|
| 117 |
+
$last=$_;
|
| 118 |
+
}
|
| 119 |
+
close(GDAT);
|
| 120 |
+
(my $time, my @gconc)= split(' ', $last);
|
| 121 |
+
for my $oname (@output_vars){
|
| 122 |
+
# push @output, "$oname:".$gconc[$obs_ind{$oname}];
|
| 123 |
+
push @output, $gconc[$obs_ind{$oname}];
|
| 124 |
+
}
|
| 125 |
+
}else {
|
| 126 |
+
exit_error("Could not find $gdatfile");
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
printf "CPU TIME: total %.1f s.\n", cpu_time(0);
|
| 130 |
+
|
| 131 |
+
open STDOUT, ">&", $oldout or die "Can't dup \$oldout: $!";
|
| 132 |
+
# Print results to real STDOUT (to be read by Matlab)
|
| 133 |
+
print join(" ",@output),"\n";
|
| 134 |
+
|
| 135 |
+
|
data/bionetgen/Perl2/Aux2/test.pl
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/perl
|
| 2 |
+
# $Id: BNG2.pl,v 1.5 2005/11/08 16:41:35 faeder Exp $
|
| 3 |
+
|
| 4 |
+
use FindBin;
|
| 5 |
+
use lib $FindBin::Bin;
|
| 6 |
+
use BNGModel;
|
| 7 |
+
use SpeciesList;
|
| 8 |
+
use BNGUtils;
|
| 9 |
+
use strict;
|
| 10 |
+
|
| 11 |
+
# turn off output buffering on STDOUT
|
| 12 |
+
#(select(*STDOUT), $|=1)[0];
|
| 13 |
+
|
| 14 |
+
#printf "BioNetGen version %s\n", BNGversion();
|
| 15 |
+
|
| 16 |
+
#$model= BNGModel->new();
|
| 17 |
+
my ($a, $b, $c);
|
| 18 |
+
|
| 19 |
+
my $s= \"111";
|
| 20 |
+
|
| 21 |
+
print $$s,"\n";
|
data/bionetgen/Perl2/Aux2/test_compartment.pl
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/perl
|
| 2 |
+
|
| 3 |
+
use FindBin;
|
| 4 |
+
use lib $FindBin::Bin;
|
| 5 |
+
use Compartment;
|
| 6 |
+
use CompartmentList;
|
| 7 |
+
|
| 8 |
+
my $clist= CompartmentList->new;
|
| 9 |
+
my $plist= ParamList->new;
|
| 10 |
+
$clist->setDefault();
|
| 11 |
+
# Check valid compartment setup/listing
|
| 12 |
+
print $clist->toString();
|
| 13 |
+
|
| 14 |
+
# Test adjacency function
|
| 15 |
+
for my $comp1 (@{$clist->Array}){
|
| 16 |
+
for my $comp2 (@{$clist->Array}){
|
| 17 |
+
if ($comp1->adjacent($comp2)){
|
| 18 |
+
printf "%s adjacent to %s\n", $comp1->Name, $comp2->Name;
|
| 19 |
+
}
|
| 20 |
+
}
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
# Check setting of compartment volume
|
| 25 |
+
my $x="100";
|
| 26 |
+
if ($err=$clist->lookup("PM")->setVolume($x,$plist)){
|
| 27 |
+
die $err;
|
| 28 |
+
}
|
| 29 |
+
print "After setting PM volume to $x\n";
|
| 30 |
+
print $clist->setVolumeStrings();
|
| 31 |
+
|
| 32 |
+
# Test connected function
|
| 33 |
+
|
| 34 |
+
if (!($clist->lookup("EC")->connected($clist->lookup("NM"), $clist->lookup("NU")))){
|
| 35 |
+
print "Connected PASSED test 1\n";
|
| 36 |
+
} else {
|
| 37 |
+
print "Connected FAILED test 1\n";
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
if (($clist->lookup("EC")->connected($clist->lookup("CP"), $clist->lookup("PM")))){
|
| 41 |
+
print "Connected PASSED test 2\n";
|
| 42 |
+
} else {
|
| 43 |
+
print "Connected FAILED test 2\n";
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
if (($clist->lookup("EC")->connected($clist->lookup("CP")))){
|
| 47 |
+
print "Connected FAILED test 3\n";
|
| 48 |
+
} else {
|
| 49 |
+
print "Connected PASSED test 3\n";
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
if (($clist->lookup("EC")->connected($clist->lookup("CP"), $clist->lookup("PM"), $clist->lookup("NM")))){
|
| 53 |
+
print "Connected PASSED test 4\n";
|
| 54 |
+
} else {
|
| 55 |
+
print "Connected FAILED test 4\n";
|
| 56 |
+
}
|
data/bionetgen/Perl2/Aux2/test_molorder.pl
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/perl
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
$perm= [3,1,2];
|
| 5 |
+
@molecules=("a","b","c");
|
| 6 |
+
print "before sort: ",join(" ",@molecules),"\n";
|
| 7 |
+
|
| 8 |
+
# Reorder Molecules according to canonical order
|
| 9 |
+
my @mol_perm=();
|
| 10 |
+
|
| 11 |
+
#$imol=0;
|
| 12 |
+
#for $mol (@molecules){
|
| 13 |
+
# push @mol_perm, [$$perm[$imol],$mol];
|
| 14 |
+
# ++$imol;
|
| 15 |
+
#}
|
| 16 |
+
@mol_perm= map {[$perm->[$_],$molecules[$_]]} (0..$#molecules);
|
| 17 |
+
@mol_perm= sort {$a->[0]<=>$b->[0]} @mol_perm;
|
| 18 |
+
@molecules= map {$_->[1]} @mol_perm;
|
| 19 |
+
print " after sort: ",join(" ",@molecules),"\n";
|
| 20 |
+
|
data/bionetgen/Perl2/Aux2/test_redirect.pl
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/perl
|
| 2 |
+
|
| 3 |
+
open my $oldout, ">&STDOUT" or die "Can't dup STDOUT: $!";
|
| 4 |
+
open OLDERR, ">&", \*STDERR or die "Can't dup STDERR: $!";
|
| 5 |
+
|
| 6 |
+
open STDOUT, '>', "$0.out" or die "Can't redirect STDOUT: $!";
|
| 7 |
+
open STDERR, ">&STDOUT" or die "Can't dup STDOUT: $!";
|
| 8 |
+
|
| 9 |
+
select STDERR; $| = 1; # make unbuffered
|
| 10 |
+
select STDOUT; $| = 1; # make unbuffered
|
| 11 |
+
|
| 12 |
+
print STDOUT "stdout 1\n"; # this works for
|
| 13 |
+
print STDERR "stderr 1\n"; # subprocesses too
|
| 14 |
+
|
| 15 |
+
open STDOUT, ">&", $oldout or die "Can't dup \$oldout: $!";
|
| 16 |
+
open STDERR, ">&OLDERR" or die "Can't dup OLDERR: $!";
|
| 17 |
+
|
| 18 |
+
print STDOUT "stdout 2\n";
|
| 19 |
+
print STDERR "stderr 2\n";
|
data/bionetgen/Perl2/Aux2/test_sub.pl
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/perl
|
| 2 |
+
|
| 3 |
+
use FindBin;
|
| 4 |
+
use lib $FindBin::Bin;
|
| 5 |
+
use SpeciesGraph;
|
| 6 |
+
|
| 7 |
+
while(<>){
|
| 8 |
+
next unless /S+/;
|
| 9 |
+
my $sg= SpeciesGraph->new;
|
| 10 |
+
chomp;
|
| 11 |
+
$err=$sg->readString(\$_);
|
| 12 |
+
if ($err){die($err);}
|
| 13 |
+
}
|
data/bionetgen/Perl2/BNGAction.pm
ADDED
|
@@ -0,0 +1,1931 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package BNGModel;
|
| 2 |
+
# BNGAction is part of the BNGModel package. This file contains Action commands
|
| 3 |
+
# including: simulate, simulate_nf, simulate_pla, generate_hybrid_model, ...
|
| 4 |
+
|
| 5 |
+
#
|
| 6 |
+
# pragmas
|
| 7 |
+
use strict;
|
| 8 |
+
use warnings;
|
| 9 |
+
|
| 10 |
+
###
|
| 11 |
+
###
|
| 12 |
+
###
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
sub simulate_ode
|
| 17 |
+
{
|
| 18 |
+
my $model = shift @_;
|
| 19 |
+
my $params = (@_) ? shift @_ : {};
|
| 20 |
+
|
| 21 |
+
$params->{method} = 'cvode';
|
| 22 |
+
my $err = $model->simulate( $params );
|
| 23 |
+
return $err;
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
sub simulate_ssa
|
| 28 |
+
{
|
| 29 |
+
my $model = shift @_;
|
| 30 |
+
my $params = (@_) ? shift @_ : {};
|
| 31 |
+
|
| 32 |
+
$params->{method} = 'ssa';
|
| 33 |
+
my $err = $model->simulate( $params );
|
| 34 |
+
return $err;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
sub simulate_pla
|
| 39 |
+
{
|
| 40 |
+
my $model = shift @_;
|
| 41 |
+
my $params = (@_) ? shift @_ : {};
|
| 42 |
+
|
| 43 |
+
$params->{method} = 'pla';
|
| 44 |
+
my $err = $model->simulate( $params );
|
| 45 |
+
return $err;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
###
|
| 51 |
+
###
|
| 52 |
+
###
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
# all purpose simulation method (supports NFsim by calling 'simulate_nf' if method = "nf")
|
| 56 |
+
sub simulate
|
| 57 |
+
{
|
| 58 |
+
use IPC::Open3;
|
| 59 |
+
use IO::Select;
|
| 60 |
+
|
| 61 |
+
my $model = shift @_;
|
| 62 |
+
my $params = (@_) ? shift @_ : {};
|
| 63 |
+
my $err;
|
| 64 |
+
|
| 65 |
+
my $METHODS =
|
| 66 |
+
{
|
| 67 |
+
cvode => { binary=>'run_network', type=>'Network', input=>'net',
|
| 68 |
+
options=>{ atol=>1, rtol=>1, sparse=>1, steady_state=>1 } },
|
| 69 |
+
ssa => { binary=>'run_network', type=>'Network', input=>'net',
|
| 70 |
+
options=>{ seed=>1 } },
|
| 71 |
+
pla => { binary=>'run_network', type=>'Network', input=>'net',
|
| 72 |
+
options=>{ seed=>1 } },
|
| 73 |
+
nf => { binary=>'NFsim', type=>'NetworkFree', input=>'xml',
|
| 74 |
+
options=>{ seed=>1 } }
|
| 75 |
+
};
|
| 76 |
+
|
| 77 |
+
return '' if $BNGModel::NO_EXEC;
|
| 78 |
+
|
| 79 |
+
# Read simulation arguments from file
|
| 80 |
+
my @sample_times;
|
| 81 |
+
my $argfile = defined $params->{argfile} ? $params->{argfile} : undef;
|
| 82 |
+
if ($argfile)
|
| 83 |
+
{
|
| 84 |
+
print "Reading simulation arguments from $argfile.\n";
|
| 85 |
+
open(ARGS, "<", $argfile) or return "Could not open argfile '$argfile'.";
|
| 86 |
+
my $lineCounter = 0;
|
| 87 |
+
while (my $line = <ARGS>)
|
| 88 |
+
{
|
| 89 |
+
++$lineCounter;
|
| 90 |
+
# trim comments
|
| 91 |
+
$line =~ s/#.*$//;
|
| 92 |
+
# skip empty lines
|
| 93 |
+
next unless ( $line =~ /\S/ );
|
| 94 |
+
# split tokens
|
| 95 |
+
my @args = split " ", $line;
|
| 96 |
+
|
| 97 |
+
unless (@args == 2)
|
| 98 |
+
{ return "Could not process line $lineCounter in $argfile: wrong number of arguments."; }
|
| 99 |
+
|
| 100 |
+
print "Processing argument: ";
|
| 101 |
+
# Check if Arg is already defined in action call
|
| 102 |
+
if ( !(defined $params->{$args[0]}) )
|
| 103 |
+
{
|
| 104 |
+
if ( $args[0] ne 'sample_times' ){
|
| 105 |
+
$params->{$args[0]} = $args[1];
|
| 106 |
+
printf "$args[0] => %s\n", (looks_like_number($args[1]) ? $args[1] : "'$args[1]'");
|
| 107 |
+
}
|
| 108 |
+
else
|
| 109 |
+
{ # Special handling for sample_times array
|
| 110 |
+
print "$args[0] => $args[1]\n";
|
| 111 |
+
# evaluate sample_times string to get array ref (hopefully)
|
| 112 |
+
my $sample_times = eval $args[1];
|
| 113 |
+
if ($@)
|
| 114 |
+
{ return "Problem parsing 'sample_times': Sample times must be comma-separated (no spaces) ints or floats "
|
| 115 |
+
. "(exponential format ok) enclosed in square brackets, e.g., [5e-1,1,5.0,1E1].";
|
| 116 |
+
}
|
| 117 |
+
@sample_times = @$sample_times;
|
| 118 |
+
foreach my $sample (@sample_times)
|
| 119 |
+
{ # check that sample time is a number
|
| 120 |
+
unless ( looks_like_number($sample) )
|
| 121 |
+
{ return "Problem parsing 'sample_times': Sample times must be comma-separated (no spaces) ints or floats "
|
| 122 |
+
. "(exponential format ok) enclosed in square brackets, e.g., [5e-1,1,5.0,1E1].";
|
| 123 |
+
}
|
| 124 |
+
}
|
| 125 |
+
}
|
| 126 |
+
}
|
| 127 |
+
else
|
| 128 |
+
{ # Args in the action call take precedence
|
| 129 |
+
if ( $args[0] ne 'sample_times' )
|
| 130 |
+
{ printf "'$args[0]' already defined with value %s, moving on...\n",
|
| 131 |
+
(looks_like_number($params->{$args[0]}) ? "$params->{$args[0]}" : "'$params->{$args[0]}'");
|
| 132 |
+
}
|
| 133 |
+
else
|
| 134 |
+
{ printf "'$args[0]' already defined in action call, moving on...\n"; }
|
| 135 |
+
}
|
| 136 |
+
}
|
| 137 |
+
close ARGS;
|
| 138 |
+
printf "Finished.\n";
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
# general options
|
| 142 |
+
my $method = defined $params->{method} ? $params->{method} : undef;
|
| 143 |
+
my $verbose = defined $params->{verbose} ? $params->{verbose} : 0;
|
| 144 |
+
my $prefix = defined $params->{prefix} ? $model->getOutputPrefix( $params->{prefix} ) : $model->getOutputPrefix();
|
| 145 |
+
my $suffix = defined $params->{suffix} ? $params->{suffix} : undef;
|
| 146 |
+
my $netfile = defined $params->{netfile} ? $params->{netfile} : undef;
|
| 147 |
+
my $print_end = defined $params->{print_end} ? $params->{print_end} : 0;
|
| 148 |
+
my $print_net = defined $params->{print_net} ? $params->{print_net} : 0;
|
| 149 |
+
my $save_progress = defined $params->{save_progress} ? $params->{save_progress} : 0; # Same as 'print_net'
|
| 150 |
+
my $continue = defined $params->{'continue'} ? $params->{'continue'} : 0;
|
| 151 |
+
my $print_active = defined $params->{print_n_species_active} ? $params->{print_n_species_active} : 0;
|
| 152 |
+
my $print_cdat = defined $params->{print_CDAT} ? $params->{print_CDAT} : 1; # Default is to print .cdat
|
| 153 |
+
my $print_fdat = defined $params->{print_functions} ? $params->{print_functions} : 0; # Default is to NOT print .fdat
|
| 154 |
+
my $stop_if = defined $params->{stop_if} ? $params->{stop_if} : undef; # stop condition
|
| 155 |
+
my $print_on_stop = defined $params->{print_on_stop} ? $params->{print_on_stop} : undef; # print at point that stop condition is met
|
| 156 |
+
my $max_sim_steps = defined $params->{max_sim_steps} ? $params->{max_sim_steps} : undef;
|
| 157 |
+
my $output_step_interval = defined $params->{output_step_interval} ? $params->{output_step_interval} : undef;
|
| 158 |
+
|
| 159 |
+
# continuous options
|
| 160 |
+
my $atol = defined $params->{atol} ? $params->{atol} : 1e-8;
|
| 161 |
+
my $rtol = defined $params->{rtol} ? $params->{rtol} : 1e-8;
|
| 162 |
+
my $sparse = defined $params->{sparse} ? $params->{sparse} : 0;
|
| 163 |
+
my $steady_state = defined $params->{steady_state} ? $params->{steady_state} : 0;
|
| 164 |
+
|
| 165 |
+
# stochastic options
|
| 166 |
+
# my $seed = defined $params->{seed} ? $params->{seed} : floor(rand 2**31);
|
| 167 |
+
if ( not defined $params->{seed} ){
|
| 168 |
+
# do this so that NFsim gets the seed generated by BNG --LAH
|
| 169 |
+
$params->{seed} = floor(rand 2**31);
|
| 170 |
+
}
|
| 171 |
+
my $seed = $params->{seed};
|
| 172 |
+
|
| 173 |
+
# check method
|
| 174 |
+
unless ( $method )
|
| 175 |
+
{ return "simulate() requires 'method' parameter (ode, ssa, pla, nf)."; }
|
| 176 |
+
if ($method =~ /^ode$/){ $method = 'cvode'; } # Support 'ode' as a valid method
|
| 177 |
+
unless ( exists $METHODS->{$method} )
|
| 178 |
+
{ return "Simulation method '$method' is not a valid option."; }
|
| 179 |
+
|
| 180 |
+
printf "ACTION: simulate( method=>\"%s\" )\n", $method;
|
| 181 |
+
|
| 182 |
+
# add optional suffix to output prefix
|
| 183 |
+
if ( defined $suffix )
|
| 184 |
+
{ $prefix .= "_" . $suffix; }
|
| 185 |
+
|
| 186 |
+
# If stop condition is defined add it to the list of functions
|
| 187 |
+
if ($stop_if){
|
| 188 |
+
(my $ref, $err) = $model->ParamList->lookup("_stop_if");
|
| 189 |
+
if (!$ref){
|
| 190 |
+
my $fun = Function->new();
|
| 191 |
+
if ( $err = $fun->readString( "_stop_if() " . $stop_if, $model ) ){ return $err; }
|
| 192 |
+
# check paramlist for unresolved dependency, etc
|
| 193 |
+
if ( $err = $model->ParamList->check() ){ return $err; }
|
| 194 |
+
# update netfile since new function was added
|
| 195 |
+
$model->UpdateNet(1)
|
| 196 |
+
}
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
# Find binary
|
| 200 |
+
my $binary = $METHODS->{$method}->{binary};
|
| 201 |
+
printf "%s simulation using %s\n", $METHODS->{$method}->{type}, $method;
|
| 202 |
+
my $program;
|
| 203 |
+
unless ( $program = findExec($binary) )
|
| 204 |
+
{ return "Could not find executable $binary"; }
|
| 205 |
+
|
| 206 |
+
# If method = "nf", call simulate_nf() and return
|
| 207 |
+
if ( $method eq 'nf' ){
|
| 208 |
+
return $model->simulate_nf( $params );
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
# Network simulation
|
| 212 |
+
# Find or Create netfile
|
| 213 |
+
my $netpre;
|
| 214 |
+
if ($netfile)
|
| 215 |
+
{
|
| 216 |
+
# user defined netfile
|
| 217 |
+
# Make sure NET file has proper suffix
|
| 218 |
+
($netpre = $netfile) =~ s/[.]([^.]+)$//;
|
| 219 |
+
unless ( $1 =~ /net/i )
|
| 220 |
+
{ return "File $netfile does not have .net suffix"; }
|
| 221 |
+
}
|
| 222 |
+
else
|
| 223 |
+
{
|
| 224 |
+
# default to [prefix].net
|
| 225 |
+
$netfile = "${prefix}.net";
|
| 226 |
+
$netpre = $prefix;
|
| 227 |
+
|
| 228 |
+
# Generate NET file if not already created or if updateNet flag is set
|
| 229 |
+
if ( !(-e $netfile) or $model->UpdateNet or defined $params->{prefix} or defined $suffix )
|
| 230 |
+
{
|
| 231 |
+
$err = $model->writeNetwork({include_model=>0, overwrite=>1, prefix=>"$netpre"});
|
| 232 |
+
if ($err) { return $err; }
|
| 233 |
+
}
|
| 234 |
+
}
|
| 235 |
+
|
| 236 |
+
# Begin writing command: start with program
|
| 237 |
+
my @command = ($program);
|
| 238 |
+
|
| 239 |
+
# add output prefix
|
| 240 |
+
push @command, "-o", "$prefix";
|
| 241 |
+
|
| 242 |
+
# add method to command
|
| 243 |
+
push @command, "-p", "$method";
|
| 244 |
+
|
| 245 |
+
# pla-specific arguments
|
| 246 |
+
if ($method eq 'pla')
|
| 247 |
+
{
|
| 248 |
+
if (!exists $params->{pla_config}){
|
| 249 |
+
$params->{pla_config} = "fEuler|pre-neg:sb|eps=0.03";
|
| 250 |
+
send_warning("'pla_config' not defined, using default: $params->{pla_config}");
|
| 251 |
+
}
|
| 252 |
+
push @command, $params->{pla_config};
|
| 253 |
+
if (defined $params->{pla_output}){
|
| 254 |
+
push @command, "--pla_output", $params->{pla_output};
|
| 255 |
+
}
|
| 256 |
+
}
|
| 257 |
+
|
| 258 |
+
# add method options
|
| 259 |
+
{
|
| 260 |
+
my $opts = $METHODS->{$method}->{options};
|
| 261 |
+
if ( exists $opts->{seed} )
|
| 262 |
+
{ # random seed
|
| 263 |
+
push @command, "-h", $seed;
|
| 264 |
+
}
|
| 265 |
+
if ( exists $opts->{atol} )
|
| 266 |
+
{ # absolute tolerance
|
| 267 |
+
push @command, "-a", $atol;
|
| 268 |
+
}
|
| 269 |
+
if ( exists $opts->{rtol} )
|
| 270 |
+
{ # absolute tolerance
|
| 271 |
+
push @command, "-r", $rtol;
|
| 272 |
+
}
|
| 273 |
+
if ( exists $opts->{sparse} )
|
| 274 |
+
{ # sparse methods
|
| 275 |
+
if ($sparse) { push @command, "-b"; }
|
| 276 |
+
}
|
| 277 |
+
if ( exists $opts->{steady_state} )
|
| 278 |
+
{ # check for steady state
|
| 279 |
+
if ($steady_state) { push @command, "-c"; }
|
| 280 |
+
}
|
| 281 |
+
}
|
| 282 |
+
|
| 283 |
+
# define update_interval
|
| 284 |
+
my $update_interval = defined $params->{update_interval} ? $params->{update_interval} : 1.0;
|
| 285 |
+
|
| 286 |
+
# define expand
|
| 287 |
+
my $expand = defined $params->{expand} ? $params->{expand} : 'lazy';
|
| 288 |
+
if ( $expand eq 'lazy' ) { }
|
| 289 |
+
elsif ( $expand eq 'layered' ) { }
|
| 290 |
+
else { return "Unrecognized expand method $expand"; }
|
| 291 |
+
|
| 292 |
+
# define maximum # of sim steps
|
| 293 |
+
if (defined $max_sim_steps)
|
| 294 |
+
{ push @command, "-M", $max_sim_steps; }
|
| 295 |
+
|
| 296 |
+
# define output step interval
|
| 297 |
+
if (defined $output_step_interval)
|
| 298 |
+
{ push @command, "-I", $output_step_interval; }
|
| 299 |
+
|
| 300 |
+
# stop condition
|
| 301 |
+
if ($stop_if){
|
| 302 |
+
push @command, "--stop_cond", $stop_if;
|
| 303 |
+
if ($print_on_stop){
|
| 304 |
+
push @command, $print_on_stop;
|
| 305 |
+
}
|
| 306 |
+
else{
|
| 307 |
+
push @command, "1"; # Default is to print on stop
|
| 308 |
+
}
|
| 309 |
+
}
|
| 310 |
+
|
| 311 |
+
# output concentrations data
|
| 312 |
+
push @command, "--cdat", $print_cdat;
|
| 313 |
+
# output function values
|
| 314 |
+
push @command, "--fdat", $print_fdat;
|
| 315 |
+
|
| 316 |
+
# define print_net (save_progress)
|
| 317 |
+
if (defined $params->{print_net} && defined $params->{save_progress}){ # Don't let them both be defined
|
| 318 |
+
return "'print_net' and 'save_progress' are the same thing, cannot define both. "
|
| 319 |
+
. "Please only define one ('save_progress' is preferred).";
|
| 320 |
+
}
|
| 321 |
+
if ($print_net || $save_progress) { push @command, "-n"; }
|
| 322 |
+
# define print_end
|
| 323 |
+
if ($print_end) { push @command, "-e"; }
|
| 324 |
+
# More detailed output
|
| 325 |
+
if ($verbose) { push @command, "-v"; }
|
| 326 |
+
# Continuation
|
| 327 |
+
if ($continue) { push @command, "-x"; }
|
| 328 |
+
# Print number of active species
|
| 329 |
+
if ($print_active) { push @command, "-j"; }
|
| 330 |
+
|
| 331 |
+
|
| 332 |
+
# Set start time for trajectory
|
| 333 |
+
my $t_start;
|
| 334 |
+
if ( defined $params->{t_start} )
|
| 335 |
+
{
|
| 336 |
+
$t_start = $params->{t_start};
|
| 337 |
+
# if this is a continuation, check that model time equals t_start
|
| 338 |
+
if ($continue)
|
| 339 |
+
{
|
| 340 |
+
unless ( defined($model->Time) and ($model->Time == $t_start) )
|
| 341 |
+
{ return "t_start must equal current model time for continuation."; }
|
| 342 |
+
}
|
| 343 |
+
}
|
| 344 |
+
else
|
| 345 |
+
{ # t_start defaults to 0
|
| 346 |
+
if ( $continue and defined($model->Time) )
|
| 347 |
+
{ $t_start = $model->Time; }
|
| 348 |
+
else
|
| 349 |
+
{ $t_start = 0.0; }
|
| 350 |
+
}
|
| 351 |
+
|
| 352 |
+
# Set the model time to t_start
|
| 353 |
+
$model->Time($t_start);
|
| 354 |
+
|
| 355 |
+
# To preserve backward compatibility: only output start time if != 0
|
| 356 |
+
unless ( $t_start == 0.0 )
|
| 357 |
+
{ push @command, "-i", "$t_start"; }
|
| 358 |
+
|
| 359 |
+
# Use program to compute observables
|
| 360 |
+
push @command, "-g", $netfile;
|
| 361 |
+
|
| 362 |
+
# Read network from $netfile
|
| 363 |
+
push @command, $netfile;
|
| 364 |
+
|
| 365 |
+
# define t_end and n_steps
|
| 366 |
+
my ($n_steps, $t_end);
|
| 367 |
+
if ( (defined $params->{n_steps} || defined $params->{n_output_steps}) &&
|
| 368 |
+
(defined $params->{sample_times} || @sample_times) ){
|
| 369 |
+
# Throw warning if both n_steps and sample_times are defined
|
| 370 |
+
my $x = ( defined $params->{n_steps} ) ? "n_steps" : "n_output_steps";
|
| 371 |
+
send_warning("$x and sample_times both defined. $x takes precedence.");
|
| 372 |
+
}
|
| 373 |
+
if ( defined $params->{n_steps} || defined $params->{n_output_steps} ||
|
| 374 |
+
( !defined $params->{sample_times} && !@sample_times) )
|
| 375 |
+
{
|
| 376 |
+
if ( defined $params->{n_steps} && defined $params->{n_output_steps} ){ # Don't let them both be defined
|
| 377 |
+
return "'n_steps' and 'n_output_steps' are the same thing, cannot define both. "
|
| 378 |
+
. "Please only define one ('n_output_steps' is preferred).";
|
| 379 |
+
}
|
| 380 |
+
|
| 381 |
+
if ( defined $params->{t_end} ){
|
| 382 |
+
$t_end = $params->{t_end};
|
| 383 |
+
}
|
| 384 |
+
else{
|
| 385 |
+
return "Parameter t_end must be defined.";
|
| 386 |
+
}
|
| 387 |
+
|
| 388 |
+
if ( ($t_end - $t_start) <= 0.0 )
|
| 389 |
+
{
|
| 390 |
+
send_warning("t_end (" . $t_end . ") is not greater than t_start (" . $t_start . "). " .
|
| 391 |
+
"Simulation won't run.");
|
| 392 |
+
}
|
| 393 |
+
|
| 394 |
+
if (defined $params->{n_steps}){
|
| 395 |
+
$n_steps = $params->{n_steps};
|
| 396 |
+
}
|
| 397 |
+
elsif (defined $params->{n_output_steps}){
|
| 398 |
+
$n_steps = $params->{n_output_steps};
|
| 399 |
+
}
|
| 400 |
+
else{
|
| 401 |
+
$n_steps = 1;
|
| 402 |
+
}
|
| 403 |
+
|
| 404 |
+
my $step_size = ($t_end - $t_start) / $n_steps;
|
| 405 |
+
push @command, $step_size, $n_steps;
|
| 406 |
+
}
|
| 407 |
+
else
|
| 408 |
+
{
|
| 409 |
+
if (defined $params->{sample_times})
|
| 410 |
+
{ @sample_times = @{$params->{sample_times}}; }
|
| 411 |
+
@sample_times = sort {$a <=> $b} @sample_times; # numeric sort
|
| 412 |
+
if ( @sample_times > 2 ){
|
| 413 |
+
# remove all sample times <= t_start --Do this in run_network (LAH)
|
| 414 |
+
# while ($sample_times[0] <= $t_start){
|
| 415 |
+
# shift @sample_times;
|
| 416 |
+
# }
|
| 417 |
+
if ( defined $params->{t_end} ){
|
| 418 |
+
$t_end = $params->{t_end};
|
| 419 |
+
# remove all sample times >= t_end --Do this in run_network (LAH)
|
| 420 |
+
# while ($sample_times[ $#sample_times ] >= $t_end){
|
| 421 |
+
# pop @sample_times;
|
| 422 |
+
# }
|
| 423 |
+
# push t_end as final sample time
|
| 424 |
+
push @sample_times, $t_end;
|
| 425 |
+
}
|
| 426 |
+
else{
|
| 427 |
+
$t_end = $sample_times[ $#sample_times ];
|
| 428 |
+
}
|
| 429 |
+
push @command, @sample_times; # add sample times to argument list
|
| 430 |
+
}
|
| 431 |
+
else{
|
| 432 |
+
return "'sample_times' array must contain 3 or more points.";
|
| 433 |
+
}
|
| 434 |
+
}
|
| 435 |
+
|
| 436 |
+
# Determine index of last rule iteration
|
| 437 |
+
my $n_iter = 0;
|
| 438 |
+
if ( $model->SpeciesList )
|
| 439 |
+
{
|
| 440 |
+
foreach my $spec ( @{$model->SpeciesList->Array} )
|
| 441 |
+
{
|
| 442 |
+
my $iter = $spec->RulesApplied;
|
| 443 |
+
$n_iter = ( $iter > $n_iter ) ? $iter : $n_iter;
|
| 444 |
+
}
|
| 445 |
+
}
|
| 446 |
+
|
| 447 |
+
|
| 448 |
+
### RUN SIMULATION ###
|
| 449 |
+
print "Running run_network on ", `hostname`;
|
| 450 |
+
printf "full command: %s\n", join(" ", @command);
|
| 451 |
+
|
| 452 |
+
# disable dospath warnings for Windows OS.
|
| 453 |
+
use Config;
|
| 454 |
+
if ( $Config{'osname'} eq 'MSWin32' )
|
| 455 |
+
{ $ENV{'CYGWIN'}='nodosfilewarning'; }
|
| 456 |
+
|
| 457 |
+
# start simulator as child process with communication pipes
|
| 458 |
+
local ( *Reader, *Writer, *Err );
|
| 459 |
+
my $pid = eval{ open3( \*Writer, \*Reader, \*Err, @command ) };
|
| 460 |
+
if ($@) { return sprintf("%s failed: $@", join(" ", @command)); }
|
| 461 |
+
|
| 462 |
+
# remember child PID
|
| 463 |
+
$::CHILD_PID = $pid;
|
| 464 |
+
print "[simulation PID is: $pid]\n";
|
| 465 |
+
|
| 466 |
+
# Wait for messages from the Simulator
|
| 467 |
+
my $last_msg = '';
|
| 468 |
+
my $steady_state_reached = 0;
|
| 469 |
+
my $edge_warning = 0;
|
| 470 |
+
my $otf = 0;
|
| 471 |
+
|
| 472 |
+
while ( my $message = <Reader> )
|
| 473 |
+
{
|
| 474 |
+
# If network generation is on-the-fly, look for signal that
|
| 475 |
+
# species at the edge of the network is newly populated
|
| 476 |
+
if ( $message =~ /Steady state reached/ )
|
| 477 |
+
{ # steady state message
|
| 478 |
+
$steady_state_reached = 1;
|
| 479 |
+
}
|
| 480 |
+
elsif ( $message =~ s/^edgepop:\s*// )
|
| 481 |
+
{
|
| 482 |
+
# remember that we've attempted On-the-fly!
|
| 483 |
+
$otf = 1;
|
| 484 |
+
|
| 485 |
+
unless ( $model->SpeciesList )
|
| 486 |
+
{ # Can't generate new species if running from netfile
|
| 487 |
+
# TODO: I don't think it's sufficient to check if SpeciesList is defined.
|
| 488 |
+
# It's possible that it exists but the Network generation infrastructure is missing --Justin
|
| 489 |
+
++$edge_warning;
|
| 490 |
+
print Writer "continue\n";
|
| 491 |
+
next;
|
| 492 |
+
}
|
| 493 |
+
|
| 494 |
+
# parse edgepop message
|
| 495 |
+
my (@newspec) = split /\s+/, $message;
|
| 496 |
+
|
| 497 |
+
my $species;
|
| 498 |
+
++$n_iter;
|
| 499 |
+
if ( $expand eq 'lazy' )
|
| 500 |
+
{
|
| 501 |
+
my (@sarray, $spec);
|
| 502 |
+
foreach my $sname (@newspec)
|
| 503 |
+
{
|
| 504 |
+
unless ( $spec = $model->SpeciesList->lookup_bystring($sname) )
|
| 505 |
+
{ return "Couldn't find species $sname."; }
|
| 506 |
+
push @sarray, $spec;
|
| 507 |
+
}
|
| 508 |
+
if ($verbose)
|
| 509 |
+
{ printf "Applying rules to %d species\n", scalar @sarray; }
|
| 510 |
+
$species = \@sarray;
|
| 511 |
+
}
|
| 512 |
+
else
|
| 513 |
+
{ # Do full next iteration of rule application
|
| 514 |
+
$species = $model->SpeciesList->Array;
|
| 515 |
+
}
|
| 516 |
+
|
| 517 |
+
# Apply reaction rules
|
| 518 |
+
my $nspec = $model->SpeciesList->size();
|
| 519 |
+
my $nrxn = $model->RxnList->size();
|
| 520 |
+
my $irule = 1;
|
| 521 |
+
my ($n_new, $t_off);
|
| 522 |
+
foreach my $rset ( @{$model->RxnRules} )
|
| 523 |
+
{
|
| 524 |
+
if ($verbose) { $t_off = cpu_time(0); }
|
| 525 |
+
$n_new = 0;
|
| 526 |
+
foreach my $rr (@$rset)
|
| 527 |
+
{
|
| 528 |
+
# expand rule
|
| 529 |
+
my ($err, $nr) = $rr->expand_rule( $species, $model, $params );
|
| 530 |
+
if (defined $err)
|
| 531 |
+
{ return "Some problem expanding rule (OTF): $err"; }
|
| 532 |
+
$n_new += $nr;
|
| 533 |
+
|
| 534 |
+
}
|
| 535 |
+
if ($verbose)
|
| 536 |
+
{
|
| 537 |
+
printf "Rule %3d: %3d new reactions %.2e s CPU time\n",
|
| 538 |
+
$irule, $n_new, cpu_time(0) - $t_off;
|
| 539 |
+
}
|
| 540 |
+
++$irule;
|
| 541 |
+
}
|
| 542 |
+
|
| 543 |
+
# Set RulesApplied attribute to everything in @$species
|
| 544 |
+
foreach my $spec (@$species)
|
| 545 |
+
{
|
| 546 |
+
$spec->RulesApplied($n_iter) unless ($spec->RulesApplied);
|
| 547 |
+
}
|
| 548 |
+
|
| 549 |
+
# Set RulesApplied attribute to everything in SpeciesList
|
| 550 |
+
my $new_species = [];
|
| 551 |
+
foreach my $spec ( @{$model->SpeciesList->Array} )
|
| 552 |
+
{
|
| 553 |
+
push @$new_species, $spec unless ($spec->RulesApplied);
|
| 554 |
+
}
|
| 555 |
+
|
| 556 |
+
# Print new species, reactions, and observable entries
|
| 557 |
+
if ( $model->RxnList->size() > $nrxn )
|
| 558 |
+
{
|
| 559 |
+
print Writer "read\n";
|
| 560 |
+
$model->SpeciesList->print( *Writer, $nspec );
|
| 561 |
+
$model->RxnList->print( *Writer, $nrxn );
|
| 562 |
+
print Writer "begin groups\n";
|
| 563 |
+
my $i = 1;
|
| 564 |
+
foreach my $obs ( @{$model->Observables} )
|
| 565 |
+
{
|
| 566 |
+
print Writer "$i ";
|
| 567 |
+
$obs->printGroup( *Writer, $model->SpeciesList->Array, $nspec );
|
| 568 |
+
++$i;
|
| 569 |
+
}
|
| 570 |
+
print Writer "end groups\n";
|
| 571 |
+
}
|
| 572 |
+
else
|
| 573 |
+
{
|
| 574 |
+
print Writer "continue\n";
|
| 575 |
+
}
|
| 576 |
+
}
|
| 577 |
+
else
|
| 578 |
+
{
|
| 579 |
+
print $message;
|
| 580 |
+
$last_msg = $message;
|
| 581 |
+
}
|
| 582 |
+
}
|
| 583 |
+
|
| 584 |
+
# Simulator is finished
|
| 585 |
+
my @err = <Err>;
|
| 586 |
+
close Writer;
|
| 587 |
+
close Reader;
|
| 588 |
+
close Err;
|
| 589 |
+
waitpid( $pid, 0 );
|
| 590 |
+
|
| 591 |
+
# clear child pid
|
| 592 |
+
$::CHILD_PID = undef;
|
| 593 |
+
|
| 594 |
+
# Report number of times edge species became populated without network expansion
|
| 595 |
+
if ($edge_warning)
|
| 596 |
+
{ send_warning("Edge species of truncated network became populated $edge_warning times."); }
|
| 597 |
+
|
| 598 |
+
if (@err)
|
| 599 |
+
{ # print any errors received from
|
| 600 |
+
print @err;
|
| 601 |
+
return sprintf("%s\n did not run successfully.", join(" ", @command));
|
| 602 |
+
}
|
| 603 |
+
|
| 604 |
+
unless ( $last_msg =~ /^Program times:/ )
|
| 605 |
+
{ return sprintf("%s\n did not run successfully.", join(" ", @command)); }
|
| 606 |
+
|
| 607 |
+
|
| 608 |
+
|
| 609 |
+
|
| 610 |
+
# At this point, the simulation seems to be ok.
|
| 611 |
+
# Go ahead and print out final netfile (if there are new reactions or species)
|
| 612 |
+
if ( $otf and $model->SpeciesList )
|
| 613 |
+
{ # TODO: I don't think it's sufficient to check if SpeciesList is defined.
|
| 614 |
+
# It's possible that it exists but the Network generation infrastructure is missing --Justin
|
| 615 |
+
$err = $model->writeNetwork({include_model=>0, overwrite=>1, prefix=>"$netpre"});
|
| 616 |
+
if ($err) { return $err; }
|
| 617 |
+
}
|
| 618 |
+
|
| 619 |
+
|
| 620 |
+
# Report steady state
|
| 621 |
+
if ($steady_state)
|
| 622 |
+
{
|
| 623 |
+
if ($steady_state_reached)
|
| 624 |
+
{ # let user know simulation reached steady state
|
| 625 |
+
print "Simulation reached steady state by t_end=${t_end}\n";
|
| 626 |
+
}
|
| 627 |
+
else
|
| 628 |
+
{ # warn user about failure to acheive steady state
|
| 629 |
+
send_warning("Steady_state status = $steady_state_reached.");
|
| 630 |
+
return "Simulation did not reach steady state by t_end=${t_end}";
|
| 631 |
+
}
|
| 632 |
+
}
|
| 633 |
+
|
| 634 |
+
# If there are no errors or flags so far, let's load output concentrations
|
| 635 |
+
if ( !($model->RxnList) )
|
| 636 |
+
{ # TODO: what does this accomplish? --Justin
|
| 637 |
+
send_warning("Not updating species concentrations because no model has been read.");
|
| 638 |
+
}
|
| 639 |
+
elsif ( -e "$prefix.cdat" )
|
| 640 |
+
{
|
| 641 |
+
print "Updating species concentrations from $prefix.cdat\n";
|
| 642 |
+
open CDAT, '<', "$prefix.cdat" ;
|
| 643 |
+
my $last_line = '';
|
| 644 |
+
while (my $line = <CDAT>) { $last_line = $line; }
|
| 645 |
+
close CDAT;
|
| 646 |
+
|
| 647 |
+
# Update Concentrations with concentrations from last line of CDAT file
|
| 648 |
+
my $conc;
|
| 649 |
+
($t_end, @$conc) = split ' ', $last_line;
|
| 650 |
+
my $species = $model->SpeciesList->Array;
|
| 651 |
+
unless ( $#$conc == $#$species )
|
| 652 |
+
{
|
| 653 |
+
$err = sprintf "Number of species in model (%d) and CDAT file (%d) differ", scalar @$species, scalar @$conc;
|
| 654 |
+
return $err;
|
| 655 |
+
}
|
| 656 |
+
$model->Concentrations( $conc );
|
| 657 |
+
$model->UpdateNet(1);
|
| 658 |
+
}
|
| 659 |
+
else
|
| 660 |
+
{ return "CDAT file is missing"; }
|
| 661 |
+
|
| 662 |
+
# Set model time to t_end
|
| 663 |
+
$model->Time($t_end);
|
| 664 |
+
|
| 665 |
+
# all finished!
|
| 666 |
+
return '';
|
| 667 |
+
}
|
| 668 |
+
|
| 669 |
+
|
| 670 |
+
|
| 671 |
+
###
|
| 672 |
+
###
|
| 673 |
+
###
|
| 674 |
+
|
| 675 |
+
|
| 676 |
+
|
| 677 |
+
sub simulate_nf
|
| 678 |
+
{
|
| 679 |
+
use IPC::Open3;
|
| 680 |
+
|
| 681 |
+
my $model = shift @_;
|
| 682 |
+
my $params = shift @_;
|
| 683 |
+
my $err;
|
| 684 |
+
|
| 685 |
+
printf "ACTION: simulate_nf( )\n";
|
| 686 |
+
|
| 687 |
+
# get simulation output prefix
|
| 688 |
+
my $prefix = defined $params->{prefix} ? $model->getOutputPrefix( $params->{prefix} ) : $model->getOutputPrefix();
|
| 689 |
+
my $suffix = defined $params->{suffix} ? $params->{suffix} : "";
|
| 690 |
+
|
| 691 |
+
unless ($suffix eq "")
|
| 692 |
+
{ $prefix .= "_${suffix}"; }
|
| 693 |
+
|
| 694 |
+
# TODO: detect unrecognized parameters
|
| 695 |
+
|
| 696 |
+
# map BNG options to NFsim flags
|
| 697 |
+
my %nfparams =
|
| 698 |
+
( # option name type defaults simulator flags (one or more)
|
| 699 |
+
binary_output => { type => 'switch', default_arg => 0, flags => ["-b"] },
|
| 700 |
+
complex => { type => 'switch', default_arg => 1, flags => ["-cb"] },
|
| 701 |
+
equil => { type => 'param', default_arg => undef, flags => ["-eq"] },
|
| 702 |
+
get_final_state => { type => 'switch', default_arg => 1, flags => ["-ss","${prefix}.species"] },
|
| 703 |
+
gml => { type => 'param', default_arg => undef, flags => ["-gml"] },
|
| 704 |
+
nocslf => { type => 'switch', default_arg => 0, flags => ["-nocslf"] },
|
| 705 |
+
notf => { type => 'switch', default_arg => 0, flags => ["-notf"] },
|
| 706 |
+
print_functions => { type => 'switch', default_arg => 0, flags => ["-ogf"] },
|
| 707 |
+
seed => { type => 'param', default_arg => undef, flags => ["-seed"] },
|
| 708 |
+
utl => { type => 'param', default_arg => undef, flags => ["-utl"] },
|
| 709 |
+
verbose => { type => 'switch', default_arg => 0, flags => ["-v"] }
|
| 710 |
+
);
|
| 711 |
+
|
| 712 |
+
# get nfsim arguments
|
| 713 |
+
my @args = ();
|
| 714 |
+
while ( my ($arg,$arg_hash) = each %nfparams )
|
| 715 |
+
{
|
| 716 |
+
if ($arg_hash->{type} eq "switch")
|
| 717 |
+
{
|
| 718 |
+
if (defined $params->{$arg})
|
| 719 |
+
{ # user switch
|
| 720 |
+
if ($params->{$arg})
|
| 721 |
+
{ push @args, @{$arg_hash->{flags}}; }
|
| 722 |
+
}
|
| 723 |
+
elsif (defined $arg_hash->{default_arg})
|
| 724 |
+
{ # default switch
|
| 725 |
+
$params->{$arg} = $arg_hash->{default_arg};
|
| 726 |
+
if ($arg_hash->{default_arg})
|
| 727 |
+
{ push @args, @{$arg_hash->{flags}}; }
|
| 728 |
+
|
| 729 |
+
}
|
| 730 |
+
}
|
| 731 |
+
elsif ($arg_hash->{type} eq "param")
|
| 732 |
+
{
|
| 733 |
+
if (defined $params->{$arg})
|
| 734 |
+
{ # user parameter
|
| 735 |
+
push @args, @{$arg_hash->{flags}}, $params->{$arg};
|
| 736 |
+
}
|
| 737 |
+
elsif (defined $arg_hash->{default_arg})
|
| 738 |
+
{ # user parameter
|
| 739 |
+
push @args, @{$arg_hash->{flags}}, $arg_hash->{default_arg};
|
| 740 |
+
$params->{$arg} = $arg_hash->{default_arg};
|
| 741 |
+
}
|
| 742 |
+
}
|
| 743 |
+
}
|
| 744 |
+
|
| 745 |
+
# append other command line arguments not recognized by BNG
|
| 746 |
+
if ( defined $params->{param} )
|
| 747 |
+
{ push @args, split " ", $params->{param}; }
|
| 748 |
+
|
| 749 |
+
# exit here if we're not executing
|
| 750 |
+
return '' if $BNGModel::NO_EXEC;
|
| 751 |
+
|
| 752 |
+
if ( $model->Params->{no_nfsim} )
|
| 753 |
+
{ # don't execute NFsim if no_nfsim parameter is true
|
| 754 |
+
send_warning( "simulate_nf(): skipping simulation, 'no-nfsim' flag is true.");
|
| 755 |
+
return '';
|
| 756 |
+
}
|
| 757 |
+
|
| 758 |
+
|
| 759 |
+
# continue with simulation...
|
| 760 |
+
# print "Netfree simulation using NFsim\n";
|
| 761 |
+
my $program;
|
| 762 |
+
unless ( $program = findExec("NFsim") )
|
| 763 |
+
{ return "Could not find executable NFsim"; }
|
| 764 |
+
my @command = ($program);
|
| 765 |
+
|
| 766 |
+
# Write BNG xml file
|
| 767 |
+
$model->writeXML( {'prefix'=>$prefix} );
|
| 768 |
+
|
| 769 |
+
# Define command line
|
| 770 |
+
push @command, "-xml", "${prefix}.xml", "-o", "${prefix}.gdat";
|
| 771 |
+
|
| 772 |
+
# Append the run time and output intervals
|
| 773 |
+
my $t_start;
|
| 774 |
+
if (defined $params->{t_start})
|
| 775 |
+
{
|
| 776 |
+
$t_start = $params->{t_start};
|
| 777 |
+
$model->Time($t_start);
|
| 778 |
+
}
|
| 779 |
+
else
|
| 780 |
+
{
|
| 781 |
+
$t_start = defined $model->Time ? $model->Time : 0;
|
| 782 |
+
}
|
| 783 |
+
|
| 784 |
+
|
| 785 |
+
unless ($t_start == 0)
|
| 786 |
+
{ # warn user if t_start > 0
|
| 787 |
+
send_warning("simulate_nf(): NFsim timepoints are reported as time elapsed since t_start=$t_start.");
|
| 788 |
+
}
|
| 789 |
+
|
| 790 |
+
if ($params->{continue})
|
| 791 |
+
{ # warn user that continue is not supported
|
| 792 |
+
# send_warning("simulate_nf(): NFsim does not support 'continue' option. NFsim will overwrite any existing trajectories.");
|
| 793 |
+
return "NFsim does not support 'continue' option.";
|
| 794 |
+
}
|
| 795 |
+
|
| 796 |
+
my $t_end;
|
| 797 |
+
if ( defined $params->{n_steps} )
|
| 798 |
+
{
|
| 799 |
+
my ($n_steps, $t_end);
|
| 800 |
+
$n_steps = $params->{n_steps};
|
| 801 |
+
if ( $n_steps < 1 )
|
| 802 |
+
{ return "No simulation output requested: set n_steps>0"; }
|
| 803 |
+
|
| 804 |
+
if ( defined $params->{t_end} )
|
| 805 |
+
{ $t_end = $params->{t_end}; }
|
| 806 |
+
else
|
| 807 |
+
{ return "Parameter t_end must be defined"; }
|
| 808 |
+
|
| 809 |
+
unless ( $t_end > $t_start )
|
| 810 |
+
{ return "t_end must be greater than t_start."; }
|
| 811 |
+
|
| 812 |
+
push @command, "-sim", ($t_end-$t_start), "-oSteps", $n_steps;
|
| 813 |
+
}
|
| 814 |
+
elsif ( defined $params->{sample_times} )
|
| 815 |
+
{
|
| 816 |
+
return "sample_times not supported in this version of NFsim";
|
| 817 |
+
}
|
| 818 |
+
else
|
| 819 |
+
{
|
| 820 |
+
return "No simulation output requested: set n_steps>0";
|
| 821 |
+
}
|
| 822 |
+
|
| 823 |
+
|
| 824 |
+
# Append the other command line arguments
|
| 825 |
+
push @command, @args;
|
| 826 |
+
|
| 827 |
+
|
| 828 |
+
# Run NFsim
|
| 829 |
+
print "Running NFsim on ", `hostname`;
|
| 830 |
+
printf "full command: %s\n", join(" ", @command);
|
| 831 |
+
|
| 832 |
+
# Compute timecourses using nfsim
|
| 833 |
+
# start simulator as child process with communication pipes
|
| 834 |
+
local ( *Reader, *Writer, *Err );
|
| 835 |
+
my $pid = eval{ open3( \*Writer, \*Reader, \*Err, @command ) };
|
| 836 |
+
if ($@) { return sprintf("%s failed: $@", join(" ", @command)); }
|
| 837 |
+
|
| 838 |
+
# remember child PID
|
| 839 |
+
$::CHILD_PID = $pid;
|
| 840 |
+
print "[simulation PID is: $pid]\n";
|
| 841 |
+
|
| 842 |
+
my $last = '';
|
| 843 |
+
while ( <Reader> )
|
| 844 |
+
{
|
| 845 |
+
print;
|
| 846 |
+
$last = $_;
|
| 847 |
+
}
|
| 848 |
+
( my @err = <Err> );
|
| 849 |
+
|
| 850 |
+
close Writer;
|
| 851 |
+
close Reader;
|
| 852 |
+
close Err;
|
| 853 |
+
waitpid( $pid, 0 );
|
| 854 |
+
|
| 855 |
+
# clear child pid
|
| 856 |
+
$::CHILD_PID = undef;
|
| 857 |
+
|
| 858 |
+
if (@err) {
|
| 859 |
+
print "Error log:\n", @err;
|
| 860 |
+
foreach my $e (@err){
|
| 861 |
+
unless ( $e =~ /^\s*WARNING/i ){
|
| 862 |
+
return sprintf("%s did not run successfully.", join(" ", @command));
|
| 863 |
+
}
|
| 864 |
+
}
|
| 865 |
+
}
|
| 866 |
+
|
| 867 |
+
if ( $params->{get_final_state} )
|
| 868 |
+
{ # Update final species concentrations to allow trajectory continuation
|
| 869 |
+
if (my $err = $model->readNFspecies("${prefix}.species"))
|
| 870 |
+
{ return $err; }
|
| 871 |
+
#if ( $params->{verbose} )
|
| 872 |
+
#{ print $model->SpeciesList->writeBNGL( $model->Concentrations, $model->ParamList ); }
|
| 873 |
+
}
|
| 874 |
+
else
|
| 875 |
+
{
|
| 876 |
+
send_warning( "system state was not retrieved following simulate_nf. "
|
| 877 |
+
."To retreive system state, call simulate_nf with option: get_final_state=>1." );
|
| 878 |
+
}
|
| 879 |
+
|
| 880 |
+
$model->Time($t_end);
|
| 881 |
+
return '';
|
| 882 |
+
}
|
| 883 |
+
|
| 884 |
+
|
| 885 |
+
|
| 886 |
+
###
|
| 887 |
+
###
|
| 888 |
+
###
|
| 889 |
+
|
| 890 |
+
|
| 891 |
+
|
| 892 |
+
sub readNFspecies
|
| 893 |
+
{
|
| 894 |
+
# This function reads a list of species strings from NFsim output to form a
|
| 895 |
+
# canonical species list with correct concentrations. Note that it overwrites
|
| 896 |
+
# any existing species.
|
| 897 |
+
my $model = shift @_;
|
| 898 |
+
my $fname = shift @_;
|
| 899 |
+
|
| 900 |
+
my $conc_vec;
|
| 901 |
+
if ($model->SpeciesList)
|
| 902 |
+
{
|
| 903 |
+
$conc_vec = [ (0) x scalar @{$model->SpeciesList->Array} ];
|
| 904 |
+
}
|
| 905 |
+
else
|
| 906 |
+
{
|
| 907 |
+
$conc_vec = [];
|
| 908 |
+
# create species list
|
| 909 |
+
$model->SpeciesList( SpeciesList->new );
|
| 910 |
+
}
|
| 911 |
+
my $slist = $model->SpeciesList;
|
| 912 |
+
|
| 913 |
+
# tell SpeciesLabel to use Quasi method for species w/ large number of molecules
|
| 914 |
+
my $maxMols = 20;
|
| 915 |
+
my $save_maxMols = SpeciesGraph::getSpeciesLabelMethod_MaxMols();
|
| 916 |
+
SpeciesGraph::setSpeciesLabel( SpeciesGraph::getSpeciesLabelMethod(), $maxMols );
|
| 917 |
+
|
| 918 |
+
# Read NFsim species file
|
| 919 |
+
print "readNFspecies::Reading from file $fname\n";
|
| 920 |
+
#my $FH;
|
| 921 |
+
open(my $FH, "<", $fname)
|
| 922 |
+
or return "Couldn't read from file $fname: $!";
|
| 923 |
+
|
| 924 |
+
my $n_spec_read = 0;
|
| 925 |
+
my $n_spec_new = 0;
|
| 926 |
+
my $line_num = 0;
|
| 927 |
+
while ( my $string = <$FH> )
|
| 928 |
+
{
|
| 929 |
+
++$line_num;
|
| 930 |
+
chomp $string; # remove line return
|
| 931 |
+
$string =~ s/^\s+//; # remove leading whitespace
|
| 932 |
+
$string =~ s/\#.*$//; # remove comments
|
| 933 |
+
next unless $string =~ /\S+/; # skip blank lines
|
| 934 |
+
|
| 935 |
+
# Read species string
|
| 936 |
+
my $sg = SpeciesGraph->new();
|
| 937 |
+
my $err = $sg->readString( \$string, $model->CompartmentList, 1, '^\s+',
|
| 938 |
+
$model->MoleculeTypesList );
|
| 939 |
+
if ($err) { return $err." at line $line_num of file $fname"; }
|
| 940 |
+
|
| 941 |
+
# Read species concentration - may only be integer value
|
| 942 |
+
my $conc;
|
| 943 |
+
if ( $string=~ /^\s*(\d+)\s*$/ )
|
| 944 |
+
{ $conc = $1; }
|
| 945 |
+
else
|
| 946 |
+
{ return "species concentration must be single integer at line $line_num of file $fname"; }
|
| 947 |
+
|
| 948 |
+
# Check if isomorphic to existing species
|
| 949 |
+
my $existing_sg = $model->SpeciesList->lookup( $sg );
|
| 950 |
+
if ($existing_sg)
|
| 951 |
+
{
|
| 952 |
+
# Add concentration to concentration of existing species
|
| 953 |
+
$conc_vec->[$existing_sg->Index - 1] += $conc;
|
| 954 |
+
}
|
| 955 |
+
else
|
| 956 |
+
{
|
| 957 |
+
# Create new Species entry in SpeciesList with zero default concentration
|
| 958 |
+
my $newspec = $model->SpeciesList->add( $sg, 0 );
|
| 959 |
+
$conc_vec->[ $newspec->Index - 1 ] = $conc;
|
| 960 |
+
++$n_spec_new;
|
| 961 |
+
}
|
| 962 |
+
++$n_spec_read;
|
| 963 |
+
}
|
| 964 |
+
close $FH;
|
| 965 |
+
|
| 966 |
+
$model->Concentrations( $conc_vec );
|
| 967 |
+
printf "Read %d unique species of %d total.\n", $n_spec_new, $n_spec_read;
|
| 968 |
+
|
| 969 |
+
# return SpeciesLable method to original setting
|
| 970 |
+
SpeciesGraph::setSpeciesLabel( SpeciesGraph::getSpeciesLabelMethod(), $save_maxMols );
|
| 971 |
+
|
| 972 |
+
return '';
|
| 973 |
+
}
|
| 974 |
+
|
| 975 |
+
|
| 976 |
+
|
| 977 |
+
###
|
| 978 |
+
###
|
| 979 |
+
###
|
| 980 |
+
|
| 981 |
+
|
| 982 |
+
|
| 983 |
+
# construct a hybrid particle population (HPP) model
|
| 984 |
+
# --Justin, 21mar2011
|
| 985 |
+
sub generate_hybrid_model
|
| 986 |
+
{
|
| 987 |
+
my $model = shift;
|
| 988 |
+
my $user_options = shift;
|
| 989 |
+
|
| 990 |
+
|
| 991 |
+
my $indent = ' ';
|
| 992 |
+
my $step_index = 0;
|
| 993 |
+
printf "ACTION: generate_hybrid_model( %s )\n", $model->Name;
|
| 994 |
+
|
| 995 |
+
|
| 996 |
+
# default options
|
| 997 |
+
my $options =
|
| 998 |
+
{ 'prefix' => undef,
|
| 999 |
+
'suffix' => 'hpp',
|
| 1000 |
+
'overwrite' => 0,
|
| 1001 |
+
'verbose' => 0,
|
| 1002 |
+
'actions' => ['writeXML()'],
|
| 1003 |
+
'execute' => 0,
|
| 1004 |
+
'safe' => 0
|
| 1005 |
+
};
|
| 1006 |
+
# get user options
|
| 1007 |
+
foreach my $opt (keys %$user_options)
|
| 1008 |
+
{
|
| 1009 |
+
my $val = $user_options->{$opt};
|
| 1010 |
+
if ($opt eq "exact")
|
| 1011 |
+
{ # TODO: temporary patch to allow the old "exact" option
|
| 1012 |
+
send_warning("The 'exact' option has been renamed 'safe', please use this in the future.");
|
| 1013 |
+
$opt = "safe";
|
| 1014 |
+
}
|
| 1015 |
+
|
| 1016 |
+
unless ( exists $options->{$opt} )
|
| 1017 |
+
{ return "Unrecognized option $opt in call to generate_hybrid_model"; }
|
| 1018 |
+
|
| 1019 |
+
# overwrite default option
|
| 1020 |
+
$options->{$opt} = $val;
|
| 1021 |
+
}
|
| 1022 |
+
# print options
|
| 1023 |
+
print "options = \n";
|
| 1024 |
+
while ( my ($par,$val) = each %$options )
|
| 1025 |
+
{
|
| 1026 |
+
next unless (defined $val);
|
| 1027 |
+
if ( ref $val eq 'ARRAY')
|
| 1028 |
+
{ printf( "%12s => %-60s\n", $par, "[array]" ); }
|
| 1029 |
+
elsif ( ref $val eq 'HASH')
|
| 1030 |
+
{ printf( "%12s => %-60s\n", $par, "{hash}" ); }
|
| 1031 |
+
elsif ( ref \$val eq 'SCALAR')
|
| 1032 |
+
{ printf( "%12s => %-60s\n", $par, $val ); }
|
| 1033 |
+
}
|
| 1034 |
+
|
| 1035 |
+
# do nothing if $NO_EXEC is true
|
| 1036 |
+
return '' if $BNGModel::NO_EXEC;
|
| 1037 |
+
|
| 1038 |
+
# determine HPP model name
|
| 1039 |
+
# (1) if prefix is defined, try to extract the file basename
|
| 1040 |
+
# (2) otherwise use the name of the parent model
|
| 1041 |
+
# my $modelname;
|
| 1042 |
+
# my $outdir;
|
| 1043 |
+
# if (defined $options->{prefix})
|
| 1044 |
+
# {
|
| 1045 |
+
# my ($vol,$dir,$filebase) = File::Spec->splitpath($options->{prefix});
|
| 1046 |
+
# if ($filebase eq '')
|
| 1047 |
+
# { return sprintf "Prefix value '%s' does not end with a file basename", $options->{prefix}; }
|
| 1048 |
+
# $outdir = File::Spec->catpath($vol, $dir);
|
| 1049 |
+
# $modelname = $filebase;
|
| 1050 |
+
# }
|
| 1051 |
+
# else
|
| 1052 |
+
# {
|
| 1053 |
+
# $outdir = defined $options->{output_dir} ? $options->{output_dir} : $model->getOutputDir();
|
| 1054 |
+
# $modelname = $model->Name;
|
| 1055 |
+
# }
|
| 1056 |
+
# add suffix
|
| 1057 |
+
# $modelname .= "_" . $options->{suffix};
|
| 1058 |
+
|
| 1059 |
+
|
| 1060 |
+
# define prefix
|
| 1061 |
+
# my $prefix = defined $options->{prefix} ? $options->{prefix} : File::Spec->catfile($outdir, $modelname);
|
| 1062 |
+
my $prefix = defined $options->{prefix} ? $model->getOutputPrefix( $options->{prefix} ) : $model->getOutputPrefix();
|
| 1063 |
+
$prefix .= "_" . $options->{suffix};
|
| 1064 |
+
|
| 1065 |
+
# define outdir and modelname
|
| 1066 |
+
my ($vol,$dir,$modelname) = File::Spec->splitpath($prefix);
|
| 1067 |
+
my $outdir = File::Spec->catpath($vol, $dir);
|
| 1068 |
+
|
| 1069 |
+
# define filename
|
| 1070 |
+
# my $modelfile = $modelname . ".bngl";
|
| 1071 |
+
my $modelfile = $prefix . ".bngl";
|
| 1072 |
+
|
| 1073 |
+
if ( -e $modelfile )
|
| 1074 |
+
{
|
| 1075 |
+
if ($options->{overwrite})
|
| 1076 |
+
{
|
| 1077 |
+
send_warning( "Overwriting older model file: $modelfile" );
|
| 1078 |
+
unlink $modelfile;
|
| 1079 |
+
}
|
| 1080 |
+
else
|
| 1081 |
+
{
|
| 1082 |
+
return "Model file $modelfile already exists. Set overwrite=>1 option to force overwrite.";
|
| 1083 |
+
}
|
| 1084 |
+
}
|
| 1085 |
+
|
| 1086 |
+
# check if a ParamList exists
|
| 1087 |
+
unless ( defined $model->ParamList )
|
| 1088 |
+
{ return sprintf "Cannot continue! Model %s does not have a parameter list.", $model->Name; }
|
| 1089 |
+
|
| 1090 |
+
# Check for MoleculeTypes
|
| 1091 |
+
unless ( defined $model->MoleculeTypesList and %{$model->MoleculeTypesList->MolTypes} )
|
| 1092 |
+
{ return sprintf "Nothing to do! Model %s has zero molecule type definitions.", $model->Name; }
|
| 1093 |
+
|
| 1094 |
+
# check if a SpeciesList exists
|
| 1095 |
+
unless ( defined $model->SpeciesList and @{$model->SpeciesList->Array} )
|
| 1096 |
+
{ return sprintf "Nothing to do! Model %s has zero seed species definitions.", $model->Name; }
|
| 1097 |
+
|
| 1098 |
+
# Check for RxnRules
|
| 1099 |
+
unless ( defined $model->RxnRules and @{$model->RxnRules} )
|
| 1100 |
+
{ return sprintf "Nothing to do! Model %s has zero reaction rule definitions.", $model->Name; }
|
| 1101 |
+
|
| 1102 |
+
# check if PopulationTypesList exists
|
| 1103 |
+
unless ( defined $model->PopulationTypesList and %{$model->PopulationTypesList->MolTypes} )
|
| 1104 |
+
{ return sprintf "Nothing to do! Model %s has zero population type definitions.", $model->Name; }
|
| 1105 |
+
|
| 1106 |
+
# check if PopulationList exists
|
| 1107 |
+
unless ( defined $model->PopulationList and @{$model->PopulationList->List} )
|
| 1108 |
+
{ return sprintf "Nothing to do! Model %s has zero population map definitions.", $model->Name; }
|
| 1109 |
+
|
| 1110 |
+
|
| 1111 |
+
# create new model!
|
| 1112 |
+
my $hybrid_model = BNGModel::new();
|
| 1113 |
+
|
| 1114 |
+
$hybrid_model->Name( $modelname );
|
| 1115 |
+
$hybrid_model->Version( $model->Version );
|
| 1116 |
+
$hybrid_model->SubstanceUnits( $model->SubstanceUnits );
|
| 1117 |
+
|
| 1118 |
+
# copy options
|
| 1119 |
+
%{$hybrid_model->Options} = %{$model->Options};
|
| 1120 |
+
# set prefix
|
| 1121 |
+
$hybrid_model->Options->{prefix} = $prefix;
|
| 1122 |
+
#set output_dir
|
| 1123 |
+
$hybrid_model->setOutputDir($outdir);
|
| 1124 |
+
|
| 1125 |
+
# copy the constants in the parameter list
|
| 1126 |
+
# NOTE: we'll add observable and functions later
|
| 1127 |
+
print $indent . "$step_index:Fetching model parameters.. "; ++$step_index;
|
| 1128 |
+
my $plist_new = $model->ParamList->copyConstant();
|
| 1129 |
+
$hybrid_model->ParamList( $plist_new );
|
| 1130 |
+
print sprintf "found %d constants and expressions.\n", scalar @{$plist_new->Array};
|
| 1131 |
+
|
| 1132 |
+
|
| 1133 |
+
# Copy compartments
|
| 1134 |
+
my $clist_new = undef;
|
| 1135 |
+
if ( defined $model->CompartmentList )
|
| 1136 |
+
{
|
| 1137 |
+
print $indent . "$step_index:Fetching compartments.. "; ++$step_index;
|
| 1138 |
+
$clist_new = $model->CompartmentList->copy( $plist_new );
|
| 1139 |
+
$hybrid_model->CompartmentList( $clist_new );
|
| 1140 |
+
print $indent . sprintf "found %d compartments.\n", scalar @{$clist_new->Array};
|
| 1141 |
+
send_warning( "generate_hybrid_model() does not support compartments at this time." ) if (@{$clist_new->Array});
|
| 1142 |
+
}
|
| 1143 |
+
|
| 1144 |
+
|
| 1145 |
+
|
| 1146 |
+
# Copying the moleculeTypesList and add population types
|
| 1147 |
+
print $indent . "$step_index:Fetching molecule types.. "; ++$step_index;
|
| 1148 |
+
my $mtlist_new = $model->MoleculeTypesList->copy();
|
| 1149 |
+
$hybrid_model->MoleculeTypesList( $mtlist_new );
|
| 1150 |
+
print sprintf "found %d molecule types.\n", scalar keys %{$mtlist_new->MolTypes};
|
| 1151 |
+
{
|
| 1152 |
+
# Add population types
|
| 1153 |
+
print $indent . "$step_index:Adding population types.. "; ++$step_index;
|
| 1154 |
+
foreach my $name ( keys %{$model->PopulationTypesList->MolTypes} )
|
| 1155 |
+
{
|
| 1156 |
+
my $mt = $model->PopulationTypesList->MolTypes->{$name};
|
| 1157 |
+
my $mt_copy = $mt->copy();
|
| 1158 |
+
$mt_copy->PopulationType(1);
|
| 1159 |
+
unless ( $mtlist_new->add($mt_copy) )
|
| 1160 |
+
{ return "PopulationType $name clashes with MoleculeType of the same name"; }
|
| 1161 |
+
}
|
| 1162 |
+
print sprintf "found %d population types.\n", scalar keys %{$model->PopulationTypesList->MolTypes};
|
| 1163 |
+
}
|
| 1164 |
+
|
| 1165 |
+
|
| 1166 |
+
# Copy seed species, replacing with populations if possible, and add empty populations
|
| 1167 |
+
my $slist_new = SpeciesList::new();
|
| 1168 |
+
$hybrid_model->SpeciesList( $slist_new );
|
| 1169 |
+
{
|
| 1170 |
+
print $indent . "$step_index:Fetching seed species..\n"; ++$step_index;
|
| 1171 |
+
|
| 1172 |
+
# loop over species in species list
|
| 1173 |
+
foreach my $species ( @{$model->SpeciesList->Array} )
|
| 1174 |
+
{
|
| 1175 |
+
my $sg = $species->SpeciesGraph;
|
| 1176 |
+
my $conc = $species->Concentration;
|
| 1177 |
+
|
| 1178 |
+
# check if this is isomorphic to any of our populations
|
| 1179 |
+
my $is_pop = 0;
|
| 1180 |
+
foreach my $pop ( @{$model->PopulationList->List} )
|
| 1181 |
+
{
|
| 1182 |
+
if ( SpeciesGraph::isomorphicTo($species->SpeciesGraph, $pop->SpeciesGraph) )
|
| 1183 |
+
{ # add the population instead of the speciesGraph
|
| 1184 |
+
my $sg_copy = $pop->Population->copy();
|
| 1185 |
+
$sg_copy->relinkCompartments( $hybrid_model->CompartmentList );
|
| 1186 |
+
$slist_new->add( $sg_copy, $species->Concentration );
|
| 1187 |
+
$is_pop = 1;
|
| 1188 |
+
if ( $options->{verbose} )
|
| 1189 |
+
{
|
| 1190 |
+
print $indent.$indent
|
| 1191 |
+
. sprintf "replaced species %s with population %s.\n", $sg->toString(), $sg_copy->toString();
|
| 1192 |
+
}
|
| 1193 |
+
last;
|
| 1194 |
+
}
|
| 1195 |
+
}
|
| 1196 |
+
unless ($is_pop)
|
| 1197 |
+
{ # this isn't a population, so add SpeciesGraph directly.
|
| 1198 |
+
my $sg_copy = $species->SpeciesGraph->copy();
|
| 1199 |
+
$sg_copy->relinkCompartments( $hybrid_model->CompartmentList );
|
| 1200 |
+
$slist_new->add( $sg_copy, $species->Concentration );
|
| 1201 |
+
}
|
| 1202 |
+
}
|
| 1203 |
+
print $indent . sprintf " ..found %d seed species.\n", scalar @{$slist_new->Array};
|
| 1204 |
+
}
|
| 1205 |
+
|
| 1206 |
+
|
| 1207 |
+
# Add population species to seed species
|
| 1208 |
+
{
|
| 1209 |
+
print $indent . "$step_index:Adding populations with zero counts to seed species..\n"; ++$step_index;
|
| 1210 |
+
my $zero_pops = 0;
|
| 1211 |
+
foreach my $pop ( @{$model->PopulationList->List} )
|
| 1212 |
+
{
|
| 1213 |
+
my ($sp) = $slist_new->lookup( $pop->Population );
|
| 1214 |
+
unless ( $sp )
|
| 1215 |
+
{
|
| 1216 |
+
my $sg_copy = $pop->Population->copy();
|
| 1217 |
+
$sg_copy->relinkCompartments( $hybrid_model->CompartmentList );
|
| 1218 |
+
$slist_new->add( $sg_copy, 0 );
|
| 1219 |
+
++$zero_pops;
|
| 1220 |
+
}
|
| 1221 |
+
}
|
| 1222 |
+
print $indent . sprintf " ..added %d populations to seed species list.\n", $zero_pops;
|
| 1223 |
+
}
|
| 1224 |
+
|
| 1225 |
+
|
| 1226 |
+
# Copy the observables and add matches to populations (also register observable names in parameter list)
|
| 1227 |
+
my $obslist_new = [];
|
| 1228 |
+
$hybrid_model->Observables( $obslist_new );
|
| 1229 |
+
{
|
| 1230 |
+
print $indent . "$step_index:Fetching observables and adding population matches..\n"; ++$step_index;
|
| 1231 |
+
# loop over observables
|
| 1232 |
+
foreach my $obs ( @{$model->Observables} )
|
| 1233 |
+
{
|
| 1234 |
+
my $obs_copy = $obs->copy();
|
| 1235 |
+
$obs_copy->relinkCompartments( $hybrid_model->CompartmentList );
|
| 1236 |
+
push @{$obslist_new}, $obs_copy;
|
| 1237 |
+
|
| 1238 |
+
# get a parameter that points to this observable
|
| 1239 |
+
if ( $plist_new->set( $obs_copy->Name, '0', 1, "Observable", $obs_copy) )
|
| 1240 |
+
{
|
| 1241 |
+
my $name = $obs_copy->Name;
|
| 1242 |
+
return "Observable name $name clashes with previously defined Observable or Parameter";
|
| 1243 |
+
}
|
| 1244 |
+
|
| 1245 |
+
# find populations to add to observable
|
| 1246 |
+
my @add_patterns = ();
|
| 1247 |
+
foreach my $pop ( @{$model->PopulationList->List} )
|
| 1248 |
+
{
|
| 1249 |
+
my $matches = $obs_copy->match( $pop->SpeciesGraph );
|
| 1250 |
+
|
| 1251 |
+
if ($matches)
|
| 1252 |
+
{
|
| 1253 |
+
my $ii = 0;
|
| 1254 |
+
while ( $ii < $matches )
|
| 1255 |
+
{
|
| 1256 |
+
push @add_patterns, $pop->Population->copy()->relinkCompartments( $hybrid_model->CompartmentList );
|
| 1257 |
+
++$ii
|
| 1258 |
+
}
|
| 1259 |
+
if ( $options->{verbose} )
|
| 1260 |
+
{
|
| 1261 |
+
print $indent.$indent . sprintf "observable '%s': +%d match%s to %s.\n",
|
| 1262 |
+
$obs_copy->Name, $matches, ($matches>1 ? 'es' : ''), $pop->Population->toString();
|
| 1263 |
+
}
|
| 1264 |
+
}
|
| 1265 |
+
}
|
| 1266 |
+
push @{$obs_copy->Patterns}, @add_patterns;
|
| 1267 |
+
}
|
| 1268 |
+
print $indent . sprintf " ..found %d observables.\n", scalar @{$obslist_new};
|
| 1269 |
+
}
|
| 1270 |
+
|
| 1271 |
+
|
| 1272 |
+
# Copy functions
|
| 1273 |
+
{
|
| 1274 |
+
print $indent . "$step_index:Fetching functions.. "; ++$step_index;
|
| 1275 |
+
my $fcn_copies = $model->ParamList->copyFunctions();
|
| 1276 |
+
foreach my $fcn ( @$fcn_copies )
|
| 1277 |
+
{
|
| 1278 |
+
$hybrid_model->ParamList->set( $fcn->Name, $fcn->Expr, 0, 'Function', $fcn );
|
| 1279 |
+
}
|
| 1280 |
+
print sprintf "found %d functions.\n", scalar @{$fcn_copies};
|
| 1281 |
+
}
|
| 1282 |
+
|
| 1283 |
+
|
| 1284 |
+
# Expand rules
|
| 1285 |
+
my $rxnrules_new = [];
|
| 1286 |
+
$hybrid_model->RxnRules( $rxnrules_new );
|
| 1287 |
+
{
|
| 1288 |
+
print $indent . "$step_index:Expanding rules with respect to population objects..\n"; ++$step_index;
|
| 1289 |
+
|
| 1290 |
+
# get the species graphs corresponding to each population
|
| 1291 |
+
my $pop_species = [];
|
| 1292 |
+
foreach my $pop ( @{$model->PopulationList->List} )
|
| 1293 |
+
{ push @$pop_species, $pop->SpeciesGraph; }
|
| 1294 |
+
my $n_popspec = scalar @$pop_species;
|
| 1295 |
+
|
| 1296 |
+
# loop over rules
|
| 1297 |
+
my $rule_count = 0;
|
| 1298 |
+
foreach my $rset ( @{$model->RxnRules} )
|
| 1299 |
+
{
|
| 1300 |
+
# NOTE: each element of @RxnRules is an array of rules.
|
| 1301 |
+
# If a rule is unidirectional, then the array has a single element.
|
| 1302 |
+
# If a rule is bidirectional, then the array has two elements (forward and reverse)
|
| 1303 |
+
foreach my $rr (@$rset)
|
| 1304 |
+
{
|
| 1305 |
+
# first copy the rule so we don't mess with the orginal model
|
| 1306 |
+
my $rr_copy = $rr->copy();
|
| 1307 |
+
$rr_copy->resetLabels();
|
| 1308 |
+
|
| 1309 |
+
# apply rule to population species
|
| 1310 |
+
my $child_rule_list = $rr_copy->expandRule( $pop_species, $model, $hybrid_model, $options );
|
| 1311 |
+
foreach my $child_rule ( @$child_rule_list )
|
| 1312 |
+
{
|
| 1313 |
+
push @$rxnrules_new, [$child_rule];
|
| 1314 |
+
}
|
| 1315 |
+
if ( $options->{verbose} )
|
| 1316 |
+
{
|
| 1317 |
+
print $indent.$indent . sprintf "Rule '%s': expanded to %d child rule%s.\n",
|
| 1318 |
+
$rr_copy->Name, scalar @$child_rule_list, ((scalar @$child_rule_list > 1)?'s':'');
|
| 1319 |
+
}
|
| 1320 |
+
++$rule_count;
|
| 1321 |
+
}
|
| 1322 |
+
}
|
| 1323 |
+
print $indent . sprintf " ..finished processing %d reaction rules.\n", $rule_count;
|
| 1324 |
+
}
|
| 1325 |
+
|
| 1326 |
+
|
| 1327 |
+
# Add population maps to the list of rules
|
| 1328 |
+
{
|
| 1329 |
+
print $indent . "$step_index:Fetching population maps.. "; ++$step_index;
|
| 1330 |
+
foreach my $pop ( @{$model->PopulationList->List} )
|
| 1331 |
+
{
|
| 1332 |
+
# write rule as string
|
| 1333 |
+
my $rr_string = $pop->MappingRule->toString();
|
| 1334 |
+
# remove the linebreak
|
| 1335 |
+
$rr_string =~ s/\\\s//;
|
| 1336 |
+
# parse string to create "copy" of rule
|
| 1337 |
+
my ($rrs, $err) = RxnRule::newRxnRule( $rr_string, $hybrid_model );
|
| 1338 |
+
push @$rxnrules_new, $rrs;
|
| 1339 |
+
}
|
| 1340 |
+
print sprintf "found %d maps.\n", scalar @{$model->PopulationList->List};
|
| 1341 |
+
}
|
| 1342 |
+
|
| 1343 |
+
|
| 1344 |
+
# create empty RxnList
|
| 1345 |
+
print $indent . "$step_index:Creating empty reaction list.\n"; ++$step_index;
|
| 1346 |
+
my $rxnlist_new = RxnList::new();
|
| 1347 |
+
$hybrid_model->RxnList( $rxnlist_new );
|
| 1348 |
+
|
| 1349 |
+
|
| 1350 |
+
# Print hybrid model to file
|
| 1351 |
+
my $FH;
|
| 1352 |
+
print $indent . "$step_index:Attempting to write hybrid BNGL.. "; ++$step_index;
|
| 1353 |
+
unless ( open $FH, '>', $modelfile ) { return "Couldn't write to $modelfile: $!\n"; }
|
| 1354 |
+
|
| 1355 |
+
print $FH $hybrid_model->writeBNGL( {'format'=>'bngl', 'include_model'=>1,'include_network'=>0,
|
| 1356 |
+
'pretty_formatting'=>1,'evaluate_expressions'=>0 } );
|
| 1357 |
+
# writing actions!
|
| 1358 |
+
if ( @{$options->{actions}} )
|
| 1359 |
+
{
|
| 1360 |
+
my $action_string = "\n\n## model actions ##\n";
|
| 1361 |
+
foreach my $action ( @{$options->{actions}} )
|
| 1362 |
+
{
|
| 1363 |
+
$action_string .= "$action\n";
|
| 1364 |
+
}
|
| 1365 |
+
$action_string .= "\n";
|
| 1366 |
+
print $FH $action_string;
|
| 1367 |
+
}
|
| 1368 |
+
close $FH;
|
| 1369 |
+
|
| 1370 |
+
|
| 1371 |
+
print "done.\n";
|
| 1372 |
+
print "Wrote hybrid model to file $modelfile.\n";
|
| 1373 |
+
|
| 1374 |
+
|
| 1375 |
+
if ( $options->{execute} )
|
| 1376 |
+
{ # execute actions
|
| 1377 |
+
$BNGModel::GLOBAL_MODEL = $hybrid_model;
|
| 1378 |
+
my $errors = [];
|
| 1379 |
+
foreach my $action ( @{$options->{actions}} )
|
| 1380 |
+
{
|
| 1381 |
+
my $action_string = "\$hybrid_model->$action";
|
| 1382 |
+
my $err = eval "$action_string";
|
| 1383 |
+
if ($@) { warn $@; }
|
| 1384 |
+
if ($err) { push @$errors, $err; }
|
| 1385 |
+
}
|
| 1386 |
+
$BNGModel::GLOBAL_MODEL = $model;
|
| 1387 |
+
if (@$errors) { return join "\n", $errors; }
|
| 1388 |
+
}
|
| 1389 |
+
|
| 1390 |
+
return '';
|
| 1391 |
+
}
|
| 1392 |
+
|
| 1393 |
+
|
| 1394 |
+
|
| 1395 |
+
###
|
| 1396 |
+
###
|
| 1397 |
+
###
|
| 1398 |
+
|
| 1399 |
+
|
| 1400 |
+
sub bifurcate
|
| 1401 |
+
{
|
| 1402 |
+
my $model = shift @_;
|
| 1403 |
+
my $params = @_ ? shift @_ : {};
|
| 1404 |
+
|
| 1405 |
+
my @scanfiles = ();
|
| 1406 |
+
my ($i,$j,$err);
|
| 1407 |
+
|
| 1408 |
+
# don't reset concentrations after each run
|
| 1409 |
+
$params->{reset_conc} = 0;
|
| 1410 |
+
|
| 1411 |
+
# update user
|
| 1412 |
+
printf "ACTION: bifurcate(par: %s, min: %s, max: %s, n_pts: %s, log: %s)\n",
|
| 1413 |
+
(exists $params->{parameter} ? $params->{parameter} : "UNKNOWN"),
|
| 1414 |
+
(exists $params->{par_min} ? $params->{par_min} : "UNKNOWN"),
|
| 1415 |
+
(exists $params->{par_max} ? $params->{par_max} : "UNKNOWN"),
|
| 1416 |
+
(exists $params->{n_scan_pts} ? $params->{n_scan_pts} : "UNKNOWN"),
|
| 1417 |
+
(exists $params->{log_scale} ? $params->{log_scale} : 0);
|
| 1418 |
+
|
| 1419 |
+
# forward scan
|
| 1420 |
+
if (exists $params->{suffix}){ $params->{suffix} .= "_forward"; }
|
| 1421 |
+
else{ $params->{suffix} = "forward"; }
|
| 1422 |
+
$err = $model->parameter_scan( $params );
|
| 1423 |
+
if ($err){ return $err }
|
| 1424 |
+
push @scanfiles, $params->{scanfile}; # 'outfile' param set in parameter_scan
|
| 1425 |
+
|
| 1426 |
+
# backwards scan
|
| 1427 |
+
$params->{suffix} =~ s/forward/backward/;
|
| 1428 |
+
my $par_min = $params->{par_min};
|
| 1429 |
+
$params->{par_min} = $params->{par_max};
|
| 1430 |
+
$params->{par_max} = $par_min;
|
| 1431 |
+
$err = $model->parameter_scan( $params );
|
| 1432 |
+
if ($err){ return $err }
|
| 1433 |
+
push @scanfiles, $params->{scanfile}; # 'outfile' param set in parameter_scan
|
| 1434 |
+
|
| 1435 |
+
# extract forward scan data
|
| 1436 |
+
my @forward;
|
| 1437 |
+
open FILE, $scanfiles[0] or die "Couldn't open file: $!";
|
| 1438 |
+
my $line = <FILE>; # first line
|
| 1439 |
+
chomp $line;
|
| 1440 |
+
$line =~ s/^\s*#\s+//; # remove leading # and whitespace
|
| 1441 |
+
my @header = split('\s+',$line); # scan param + observable names
|
| 1442 |
+
$i = 0;
|
| 1443 |
+
while ($line = <FILE>){
|
| 1444 |
+
chomp $line;
|
| 1445 |
+
$line =~ s/^\s*//; # remove leading whitespace
|
| 1446 |
+
my @tmp = split('\s+',$line);
|
| 1447 |
+
for ($j=0;$j < scalar(@tmp);$j++){
|
| 1448 |
+
$forward[$i][$j] = $tmp[$j];
|
| 1449 |
+
}
|
| 1450 |
+
$i++;
|
| 1451 |
+
}
|
| 1452 |
+
close FILE;
|
| 1453 |
+
|
| 1454 |
+
# extract backward scan data
|
| 1455 |
+
my @backward;
|
| 1456 |
+
open FILE, $scanfiles[1] or die "Couldn't open file: $!";
|
| 1457 |
+
$line = <FILE>; # first line
|
| 1458 |
+
$i = 0;
|
| 1459 |
+
while ($line = <FILE>){
|
| 1460 |
+
chomp $line;
|
| 1461 |
+
$line =~ s/^\s*//; # remove leading whitespace
|
| 1462 |
+
my @tmp = split('\s+',$line);
|
| 1463 |
+
for ($j=0;$j < scalar(@tmp);$j++){
|
| 1464 |
+
$backward[$i][$j] = $tmp[$j];
|
| 1465 |
+
}
|
| 1466 |
+
$i++;
|
| 1467 |
+
}
|
| 1468 |
+
close FILE;
|
| 1469 |
+
|
| 1470 |
+
# generate one output file for each observable
|
| 1471 |
+
my $prefix = $scanfiles[0];
|
| 1472 |
+
$prefix =~ s/_forward.scan$/_bifurcation_/;
|
| 1473 |
+
for (my $j=1;$j < scalar(@header);$j++){
|
| 1474 |
+
open FILE, '>', ($prefix . $header[$j] . ".scan") or die "Couldn't open file: $!";
|
| 1475 |
+
printf FILE "# %+14s %+16s %+16s\n",$header[0],"$header[$j]_fwd","$header[$j]_bwd";
|
| 1476 |
+
for (my $i=0;$i < scalar(@forward);$i++){
|
| 1477 |
+
printf FILE "%16.8e %16.8e %16.8e\n",$forward[$i][0],$forward[$i][$j],$backward[scalar(@forward)-1-$i][$j];
|
| 1478 |
+
}
|
| 1479 |
+
close FILE;
|
| 1480 |
+
}
|
| 1481 |
+
|
| 1482 |
+
# delete scan files and return
|
| 1483 |
+
unlink @scanfiles;
|
| 1484 |
+
return;
|
| 1485 |
+
}
|
| 1486 |
+
|
| 1487 |
+
|
| 1488 |
+
|
| 1489 |
+
###
|
| 1490 |
+
###
|
| 1491 |
+
###
|
| 1492 |
+
|
| 1493 |
+
|
| 1494 |
+
sub parameter_scan
|
| 1495 |
+
{
|
| 1496 |
+
my $model = shift @_;
|
| 1497 |
+
my $params = @_ ? shift @_ : {};
|
| 1498 |
+
|
| 1499 |
+
# define default params
|
| 1500 |
+
my $default_params = { 'prefix' => $model->getOutputPrefix(),
|
| 1501 |
+
'log_scale' => 0,
|
| 1502 |
+
'reset_conc' => 1
|
| 1503 |
+
};
|
| 1504 |
+
|
| 1505 |
+
# copy default values for undefined keys
|
| 1506 |
+
while ( my ($key, $val) = each %$default_params )
|
| 1507 |
+
{
|
| 1508 |
+
unless ( defined $params->{$key} )
|
| 1509 |
+
{ $params->{$key} = $val; }
|
| 1510 |
+
}
|
| 1511 |
+
|
| 1512 |
+
# If resetting concentrations, don't need to read in final state
|
| 1513 |
+
# (important for NFsim simulations, where read can be expensive)
|
| 1514 |
+
if ( $params->{'reset_conc'} ){
|
| 1515 |
+
$params->{'get_final_state'} = 0;
|
| 1516 |
+
}
|
| 1517 |
+
|
| 1518 |
+
# Output prefix
|
| 1519 |
+
$params->{prefix} = $model->getOutputPrefix($params->{prefix});
|
| 1520 |
+
|
| 1521 |
+
# check for required parameters
|
| 1522 |
+
unless ( defined $params->{parameter} )
|
| 1523 |
+
{ return "Error in parameter_scan: 'parameter' is not defined."; }
|
| 1524 |
+
|
| 1525 |
+
unless ( defined $params->{par_scan_vals} ){
|
| 1526 |
+
|
| 1527 |
+
unless ( defined $params->{par_min} )
|
| 1528 |
+
{ return "Error in parameter_scan: 'par_min' must be defined if 'par_scan_vals' is not."; }
|
| 1529 |
+
|
| 1530 |
+
unless ( defined $params->{par_max} )
|
| 1531 |
+
{ return "Error in parameter_scan: 'par_max' must be defined if 'par_scan_vals' is not."; }
|
| 1532 |
+
|
| 1533 |
+
unless ( defined $params->{n_scan_pts} )
|
| 1534 |
+
{ return "Error in parameter_scan: 'n_scan_pts' must be defined if 'par_scan_vals' is not."; }
|
| 1535 |
+
|
| 1536 |
+
if ($params->{par_max} == $params->{par_min}){
|
| 1537 |
+
if ($params->{n_scan_pts} < 1){
|
| 1538 |
+
return "Error in parameter_scan: 'n_scan_pts' must be >= 1 if 'par_max' = 'par_min'.";
|
| 1539 |
+
}
|
| 1540 |
+
}
|
| 1541 |
+
elsif ($params->{n_scan_pts} <= 1){
|
| 1542 |
+
return "Error in parameter_scan: 'n_scan_pts' must be > 1 if 'par_max' != 'par_min'.";
|
| 1543 |
+
}
|
| 1544 |
+
}
|
| 1545 |
+
|
| 1546 |
+
# defined min/max takes precedence over par_scan_vals
|
| 1547 |
+
if ( defined $params->{par_min} and defined $params->{par_max} and defined $params->{n_scan_pts} ){
|
| 1548 |
+
# define parameter scan range
|
| 1549 |
+
my $par_min = $params->{log_scale} ? log $params->{par_min} : $params->{par_min};
|
| 1550 |
+
my $par_max = $params->{log_scale} ? log $params->{par_max} : $params->{par_max};
|
| 1551 |
+
my $delta = ($par_max - $par_min) / ($params->{n_scan_pts} - 1); # note that this may be negative if par_max < par_min (not a problem)
|
| 1552 |
+
|
| 1553 |
+
# add parameter values to 'par_scan_vals'
|
| 1554 |
+
$params->{par_scan_vals} = ();
|
| 1555 |
+
for ( my $k = 0; $k < $params->{n_scan_pts}; ++$k ){
|
| 1556 |
+
my $par_value = $par_min + $k*$delta;
|
| 1557 |
+
if ( $params->{log_scale} )
|
| 1558 |
+
{ $par_value = exp $par_value; }
|
| 1559 |
+
push @{$params->{par_scan_vals}}, $par_value;
|
| 1560 |
+
}
|
| 1561 |
+
}
|
| 1562 |
+
|
| 1563 |
+
# array of parameter scan values
|
| 1564 |
+
my @par_scan_vals = @{$params->{par_scan_vals}};
|
| 1565 |
+
|
| 1566 |
+
# update user
|
| 1567 |
+
# printf "ACTION: parameter_scan(par: $params->{parameter}, min: $params->{par_min}, max: $params->{par_max}, ";
|
| 1568 |
+
# printf "n_pts: $params->{n_scan_pts}, log: $params->{log_scale})\n";
|
| 1569 |
+
printf "ACTION: parameter_scan( )";
|
| 1570 |
+
|
| 1571 |
+
# define basename for scan results
|
| 1572 |
+
my $basename = $params->{prefix};
|
| 1573 |
+
if ( $params->{suffix} )
|
| 1574 |
+
{ $basename .= "_" . $params->{suffix}; }
|
| 1575 |
+
else
|
| 1576 |
+
{ $basename .= "_" . $params->{parameter}; }
|
| 1577 |
+
|
| 1578 |
+
# define working directory for simulation data
|
| 1579 |
+
my $workdir = $basename;
|
| 1580 |
+
# define output file for parameter scan results
|
| 1581 |
+
my $outfile = $basename . ".scan";
|
| 1582 |
+
# define file prefix for output results
|
| 1583 |
+
my ($vol, $dir, $file_prefix) = File::Spec->splitpath( $basename );
|
| 1584 |
+
|
| 1585 |
+
# create working directory
|
| 1586 |
+
if (-d $workdir)
|
| 1587 |
+
{ # delete working directory
|
| 1588 |
+
my $all_files = File::Spec->catfile( ($workdir), '*' );
|
| 1589 |
+
unlink <$all_files>;
|
| 1590 |
+
#system "rm -r $workdir";
|
| 1591 |
+
}
|
| 1592 |
+
else
|
| 1593 |
+
{ mkdir $workdir; }
|
| 1594 |
+
|
| 1595 |
+
# remember concentrations!
|
| 1596 |
+
$model->saveConcentrations("SCAN");
|
| 1597 |
+
|
| 1598 |
+
# loop over scan points
|
| 1599 |
+
for ( my $k = 0; $k < @par_scan_vals; ++$k )
|
| 1600 |
+
{
|
| 1601 |
+
# define prefix
|
| 1602 |
+
my $local_prefix = File::Spec->catfile( ($workdir), sprintf("%s_%05d", $file_prefix, $k+1) );
|
| 1603 |
+
|
| 1604 |
+
# define parameter value
|
| 1605 |
+
my $par_value = $par_scan_vals[$k];
|
| 1606 |
+
|
| 1607 |
+
# set parameter
|
| 1608 |
+
$model->setParameter( $params->{parameter}, $par_value );
|
| 1609 |
+
|
| 1610 |
+
# reset concentrations
|
| 1611 |
+
if ( $params->{reset_conc} ){
|
| 1612 |
+
$model->resetConcentrations("SCAN");
|
| 1613 |
+
}
|
| 1614 |
+
|
| 1615 |
+
# define local params
|
| 1616 |
+
my $local_params;
|
| 1617 |
+
%$local_params = %$params;
|
| 1618 |
+
$local_params->{prefix} = $local_prefix;
|
| 1619 |
+
delete $local_params->{suffix};
|
| 1620 |
+
|
| 1621 |
+
# run simulation
|
| 1622 |
+
my $err = $model->simulate( $local_params );
|
| 1623 |
+
if ( $err )
|
| 1624 |
+
{ # return error message
|
| 1625 |
+
$err = "Error in parameter_scan (step " . ($k+1) . "): $err";
|
| 1626 |
+
return $err;
|
| 1627 |
+
}
|
| 1628 |
+
}
|
| 1629 |
+
|
| 1630 |
+
# recover concentrations
|
| 1631 |
+
if ( $params->{reset_conc} ){
|
| 1632 |
+
$model->resetConcentrations("SCAN");
|
| 1633 |
+
}
|
| 1634 |
+
|
| 1635 |
+
# Extract last timepoint from each simulation and write to outfile
|
| 1636 |
+
my $ofh;
|
| 1637 |
+
unless ( open $ofh, '>', $outfile )
|
| 1638 |
+
{ return "Error in parameter_scan: problem opening parameter scan output file $outfile"; }
|
| 1639 |
+
|
| 1640 |
+
for ( my $k = 0; $k < @par_scan_vals; ++$k )
|
| 1641 |
+
{
|
| 1642 |
+
my $par_value = $par_scan_vals[$k];
|
| 1643 |
+
|
| 1644 |
+
# Get data from gdat file
|
| 1645 |
+
my $data_file = File::Spec->catfile( ($workdir), sprintf("%s_%05d.gdat", $file_prefix, $k+1) );
|
| 1646 |
+
print "Extracting observable trajectory from $data_file\n";
|
| 1647 |
+
my $ifh;
|
| 1648 |
+
unless ( open $ifh,'<', $data_file )
|
| 1649 |
+
{ return "Error in parameter_scan: problem opening observable file $data_file"; }
|
| 1650 |
+
|
| 1651 |
+
# write header
|
| 1652 |
+
if ( $k == 0 )
|
| 1653 |
+
{
|
| 1654 |
+
my $headline = <$ifh>;
|
| 1655 |
+
$headline =~ s/^\s*\#//;
|
| 1656 |
+
my @headers = split ' ', $headline;
|
| 1657 |
+
shift @headers;
|
| 1658 |
+
printf $ofh "# %+14s", $params->{parameter};
|
| 1659 |
+
foreach my $header (@headers)
|
| 1660 |
+
{
|
| 1661 |
+
printf $ofh " %+16s", $header;
|
| 1662 |
+
}
|
| 1663 |
+
print $ofh "\n";
|
| 1664 |
+
}
|
| 1665 |
+
|
| 1666 |
+
# get last line
|
| 1667 |
+
my $lastline;
|
| 1668 |
+
while ( my $linein = <$ifh> )
|
| 1669 |
+
{ $lastline = $linein; }
|
| 1670 |
+
|
| 1671 |
+
# close input file
|
| 1672 |
+
close $ifh;
|
| 1673 |
+
|
| 1674 |
+
# extract data and write to output file
|
| 1675 |
+
my @data = split ' ', $lastline;
|
| 1676 |
+
my $time = shift @data;
|
| 1677 |
+
printf $ofh "%16.8e", $par_value;
|
| 1678 |
+
foreach my $data ( @data )
|
| 1679 |
+
{
|
| 1680 |
+
printf $ofh " %16.8e", $data;
|
| 1681 |
+
}
|
| 1682 |
+
print $ofh "\n";
|
| 1683 |
+
}
|
| 1684 |
+
close $ofh;
|
| 1685 |
+
|
| 1686 |
+
# return without error
|
| 1687 |
+
$params->{scanfile} = $outfile; # in case another method needs this (e.g. 'bifurcate')
|
| 1688 |
+
return;
|
| 1689 |
+
}
|
| 1690 |
+
|
| 1691 |
+
|
| 1692 |
+
|
| 1693 |
+
###
|
| 1694 |
+
###
|
| 1695 |
+
###
|
| 1696 |
+
|
| 1697 |
+
|
| 1698 |
+
|
| 1699 |
+
sub LinearParameterSensitivity
|
| 1700 |
+
{
|
| 1701 |
+
#This function will perform a brute force linear sensitivity analysis
|
| 1702 |
+
#bumping one parameter at a time according to a user specified bump
|
| 1703 |
+
#For each parameter, simulations are saved as:
|
| 1704 |
+
#'netfile_paramname_suffix.(c)(g)dat', where netfile is the .net model file
|
| 1705 |
+
#and paramname is the bumped parameter name, and c/gdat files have meaning as normal
|
| 1706 |
+
|
| 1707 |
+
######################
|
| 1708 |
+
# TODO: NOT IMPLEMENTED YET!!
|
| 1709 |
+
#Additional files are written containing the raw sensitivity coefficients
|
| 1710 |
+
#for each parameter bump
|
| 1711 |
+
#format: 'netfile_paramname_suffix.(c)(g)sc'
|
| 1712 |
+
#going across rows is increasing time
|
| 1713 |
+
#going down columns is increasing species/observable index
|
| 1714 |
+
#first row is time
|
| 1715 |
+
#first column is species/observable index
|
| 1716 |
+
######################
|
| 1717 |
+
|
| 1718 |
+
#Starting time assumed to be 0
|
| 1719 |
+
|
| 1720 |
+
#Input Hash Elements:
|
| 1721 |
+
#REQUIRED PARAMETERS
|
| 1722 |
+
#net_file: the base .net model to work with; string;
|
| 1723 |
+
#t_end: the end simulation time; real;
|
| 1724 |
+
#OPTIONAL PARAMETERS
|
| 1725 |
+
#bump: the percentage parameter bump; real; default 5%
|
| 1726 |
+
#inp_ppert: model input parameter perturbations; hash{pnames=>array,pvalues=>array};
|
| 1727 |
+
#default empty
|
| 1728 |
+
#inp_cpert: model input concentration perturbations; hash{cnames=>array,cvalues=>array};
|
| 1729 |
+
#default empty
|
| 1730 |
+
#stochast: simulate_ssa (1) or simulate_ode (0) is used; boolean; default 0 (ode)
|
| 1731 |
+
#CANNOT HANDLE simulate_ssa CURRENTLY
|
| 1732 |
+
#sparse: use sparse methods for integration?; boolean; 1
|
| 1733 |
+
#atol: absolute tolerance for simulate_ode; real; 1e-8
|
| 1734 |
+
#rtol: relative tolerance for simulate_ode; real; 1e-8
|
| 1735 |
+
#init_equil: equilibrate the base .net model; boolean; default 1 (true)
|
| 1736 |
+
#re_equil: equilibrate after each parameter bump but before simulation; boolean; default 1 (true)
|
| 1737 |
+
#n_steps: the number of evenly spaced time points for sensitivity measures; integer;
|
| 1738 |
+
#default 50
|
| 1739 |
+
#suffix: added to end of filename before extension; string; default ""
|
| 1740 |
+
|
| 1741 |
+
#Variable Declaration and Initialization
|
| 1742 |
+
use strict;
|
| 1743 |
+
my $model; #the BNG model
|
| 1744 |
+
my %params; #the input parameter hash table
|
| 1745 |
+
my $net_file = "";
|
| 1746 |
+
my %inp_pert;
|
| 1747 |
+
my $t_end;
|
| 1748 |
+
my %readFileinputs;
|
| 1749 |
+
my %simodeinputs;
|
| 1750 |
+
my $simname;
|
| 1751 |
+
my $basemodel = BNGModel->new();
|
| 1752 |
+
my $plist;
|
| 1753 |
+
my $param_name;
|
| 1754 |
+
my $param_value;
|
| 1755 |
+
my $new_param_value;
|
| 1756 |
+
my $pperts;
|
| 1757 |
+
my $cperts;
|
| 1758 |
+
my $pert_names;
|
| 1759 |
+
my $pert_values;
|
| 1760 |
+
# my $pert_names;
|
| 1761 |
+
# my $pert_values;
|
| 1762 |
+
my $newbumpmodel = BNGModel->new();
|
| 1763 |
+
my $foo;
|
| 1764 |
+
my $i;
|
| 1765 |
+
|
| 1766 |
+
#Initialize model and input parameters
|
| 1767 |
+
|
| 1768 |
+
$model = shift;
|
| 1769 |
+
my $params = shift;
|
| 1770 |
+
|
| 1771 |
+
#Required params
|
| 1772 |
+
if ( defined( $params->{net_file} ) ) {
|
| 1773 |
+
$net_file = $params->{net_file};
|
| 1774 |
+
}
|
| 1775 |
+
else {
|
| 1776 |
+
$net_file = $model->getOutputPrefix();
|
| 1777 |
+
}
|
| 1778 |
+
if ( defined( $params->{t_end} ) ) {
|
| 1779 |
+
$t_end = $params->{t_end};
|
| 1780 |
+
}
|
| 1781 |
+
else {
|
| 1782 |
+
return ("t_end not defined");
|
| 1783 |
+
}
|
| 1784 |
+
|
| 1785 |
+
#Optional params
|
| 1786 |
+
my $bump = ( defined( $params->{bump} ) ) ? $params->{bump} : 5;
|
| 1787 |
+
my $stochast = ( defined( $params->{stochast} ) ) ? $params->{stochast} : 0;
|
| 1788 |
+
my $sparse = ( defined( $params->{sparse} ) ) ? $params->{sparse} : 1;
|
| 1789 |
+
my $atol = ( defined( $params->{atol} ) ) ? $params->{atol} : 1e-8;
|
| 1790 |
+
my $rtol = ( defined( $params->{rtol} ) ) ? $params->{rtol} : 1e-8;
|
| 1791 |
+
my $init_equil =
|
| 1792 |
+
( defined( $params->{init_equil} ) ) ? $params->{init_equil} : 1;
|
| 1793 |
+
my $t_equil = ( defined( $params->{t_equil} ) ) ? $params->{t_equil} : 1e6;
|
| 1794 |
+
my $re_equil = ( defined( $params->{re_equil} ) ) ? $params->{re_equil} : 1;
|
| 1795 |
+
my $n_steps = ( defined( $params->{n_steps} ) ) ? $params->{n_steps} : 50;
|
| 1796 |
+
my $suffix = ( defined( $params->{suffix} ) ) ? $params->{suffix} : "";
|
| 1797 |
+
|
| 1798 |
+
#Run base case simulation
|
| 1799 |
+
%readFileinputs = ( file => "$net_file.net" );
|
| 1800 |
+
$basemodel->readFile( \%readFileinputs );
|
| 1801 |
+
|
| 1802 |
+
#if initial equilibration is required
|
| 1803 |
+
if ($init_equil) {
|
| 1804 |
+
$simname = "_baseequil_";
|
| 1805 |
+
%simodeinputs = (
|
| 1806 |
+
prefix => "$net_file$simname$suffix",
|
| 1807 |
+
t_end => $t_equil,
|
| 1808 |
+
sparse => $sparse,
|
| 1809 |
+
n_steps => $n_steps,
|
| 1810 |
+
steady_state => 1,
|
| 1811 |
+
atol => $atol,
|
| 1812 |
+
rtol => $rtol
|
| 1813 |
+
);
|
| 1814 |
+
$basemodel->simulate_ode( \%simodeinputs );
|
| 1815 |
+
}
|
| 1816 |
+
$simname = "_basecase_";
|
| 1817 |
+
%simodeinputs = (
|
| 1818 |
+
prefix => "$net_file$simname$suffix",
|
| 1819 |
+
t_end => $t_end,
|
| 1820 |
+
sparse => $sparse,
|
| 1821 |
+
n_steps => $n_steps,
|
| 1822 |
+
steady_state => 0,
|
| 1823 |
+
atol => $atol,
|
| 1824 |
+
rtol => $rtol
|
| 1825 |
+
);
|
| 1826 |
+
|
| 1827 |
+
#Implement input perturbations
|
| 1828 |
+
if ( defined( $params->{inp_ppert} ) ) {
|
| 1829 |
+
$pperts = $params->{inp_ppert};
|
| 1830 |
+
$pert_names = $pperts->{pnames};
|
| 1831 |
+
$pert_values = $pperts->{pvalues};
|
| 1832 |
+
$i = 0;
|
| 1833 |
+
while ( $pert_names->[$i] ) {
|
| 1834 |
+
$param_name = $pert_names->[$i];
|
| 1835 |
+
$param_value = $pert_values->[$i];
|
| 1836 |
+
$basemodel->setParameter( $param_name, $param_value );
|
| 1837 |
+
$i = $i + 1;
|
| 1838 |
+
}
|
| 1839 |
+
}
|
| 1840 |
+
if ( defined( $params->{inp_cpert} ) ) {
|
| 1841 |
+
$cperts = $params->{inp_cpert};
|
| 1842 |
+
$pert_names = $cperts->{cnames};
|
| 1843 |
+
$pert_values = $cperts->{cvalues};
|
| 1844 |
+
$i = 0;
|
| 1845 |
+
while ( $pert_names->[$i] ) {
|
| 1846 |
+
$param_name = $pert_names->[$i];
|
| 1847 |
+
$param_value = $pert_values->[$i];
|
| 1848 |
+
$basemodel->setConcentration( $param_name, $param_value );
|
| 1849 |
+
$i = $i + 1;
|
| 1850 |
+
}
|
| 1851 |
+
}
|
| 1852 |
+
$basemodel->simulate_ode( \%simodeinputs );
|
| 1853 |
+
|
| 1854 |
+
$plist = $basemodel->ParamList;
|
| 1855 |
+
|
| 1856 |
+
#For every parameter in the model
|
| 1857 |
+
foreach my $model_param ( @{ $plist->Array } )
|
| 1858 |
+
{
|
| 1859 |
+
$param_name = $model_param->Name;
|
| 1860 |
+
$param_value = $model_param->evaluate();
|
| 1861 |
+
$new_param_value = $param_value * ( 1 + $bump / 100 );
|
| 1862 |
+
|
| 1863 |
+
#Get fresh model and bump parameter
|
| 1864 |
+
$newbumpmodel->readFile( \%readFileinputs );
|
| 1865 |
+
$newbumpmodel->setParameter( $param_name, $new_param_value );
|
| 1866 |
+
|
| 1867 |
+
#Reequilibrate
|
| 1868 |
+
if ($re_equil) {
|
| 1869 |
+
$simname = "equil_${param_name}";
|
| 1870 |
+
%simodeinputs = ( prefix => "${net_file}_${simname}_${suffix}",
|
| 1871 |
+
t_end => $t_equil,
|
| 1872 |
+
sparse => $sparse,
|
| 1873 |
+
n_steps => $n_steps,
|
| 1874 |
+
steady_state => 1,
|
| 1875 |
+
atol => $atol,
|
| 1876 |
+
rtol => $rtol
|
| 1877 |
+
);
|
| 1878 |
+
$newbumpmodel->simulate_ode( \%simodeinputs );
|
| 1879 |
+
}
|
| 1880 |
+
|
| 1881 |
+
#Implement input and run simulation
|
| 1882 |
+
$simname = $param_name;
|
| 1883 |
+
%simodeinputs = (
|
| 1884 |
+
prefix => "${net_file}_${simname}_${suffix}",
|
| 1885 |
+
t_end => $t_end,
|
| 1886 |
+
sparse => $sparse,
|
| 1887 |
+
n_steps => $n_steps,
|
| 1888 |
+
steady_state => 0,
|
| 1889 |
+
atol => $atol,
|
| 1890 |
+
rtol => $rtol
|
| 1891 |
+
);
|
| 1892 |
+
if ( defined( $params->{inp_ppert} ) ) {
|
| 1893 |
+
$pperts = $params->{inp_ppert};
|
| 1894 |
+
$pert_names = $pperts->{pnames};
|
| 1895 |
+
$pert_values = $pperts->{pvalues};
|
| 1896 |
+
$i = 0;
|
| 1897 |
+
while ( $pert_names->[$i] ) {
|
| 1898 |
+
$param_name = $pert_names->[$i];
|
| 1899 |
+
$param_value = $pert_values->[$i];
|
| 1900 |
+
$newbumpmodel->setParameter( $param_name, $param_value );
|
| 1901 |
+
$i = $i + 1;
|
| 1902 |
+
}
|
| 1903 |
+
}
|
| 1904 |
+
if ( defined( $params->{inp_cpert} ) ) {
|
| 1905 |
+
$cperts = $params->{inp_cpert};
|
| 1906 |
+
$pert_names = $cperts->{cnames};
|
| 1907 |
+
$pert_values = $cperts->{cvalues};
|
| 1908 |
+
$i = 0;
|
| 1909 |
+
while ( $pert_names->[$i] ) {
|
| 1910 |
+
$param_name = $pert_names->[$i];
|
| 1911 |
+
$param_value = $pert_values->[$i];
|
| 1912 |
+
$newbumpmodel->setConcentration( $param_name, $param_value );
|
| 1913 |
+
$i = $i + 1;
|
| 1914 |
+
}
|
| 1915 |
+
}
|
| 1916 |
+
$newbumpmodel->simulate_ode( \%simodeinputs );
|
| 1917 |
+
|
| 1918 |
+
#Evaluate sensitivities and write to file
|
| 1919 |
+
|
| 1920 |
+
#Get ready for next bump
|
| 1921 |
+
$newbumpmodel = BNGModel->new();
|
| 1922 |
+
}
|
| 1923 |
+
|
| 1924 |
+
|
| 1925 |
+
}
|
| 1926 |
+
|
| 1927 |
+
###
|
| 1928 |
+
###
|
| 1929 |
+
###
|
| 1930 |
+
|
| 1931 |
+
1;
|
data/bionetgen/Perl2/BNGMessages.pm
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package BNGMessages;
|
| 2 |
+
use strict;
|
| 3 |
+
use warnings;
|
| 4 |
+
|
| 5 |
+
use Class::Struct;
|
| 6 |
+
|
| 7 |
+
use Exporter 'import';
|
| 8 |
+
our @EXPORT_OK = qw(error warning message);
|
| 9 |
+
|
| 10 |
+
struct BNGMessages => {
|
| 11 |
+
errors=> '%',
|
| 12 |
+
messages=> '%',
|
| 13 |
+
warnings=> '%',
|
| 14 |
+
lasterror=> '$'
|
| 15 |
+
};
|
| 16 |
+
|
| 17 |
+
#begin error
|
| 18 |
+
sub error{
|
| 19 |
+
my @msgs= @_;
|
| 20 |
+
print STDERR "ABORT: ";
|
| 21 |
+
for my $msg (@msgs){
|
| 22 |
+
print STDERR $msg,"\n";
|
| 23 |
+
}
|
| 24 |
+
exit(1);
|
| 25 |
+
}
|
| 26 |
+
#end error
|
| 27 |
+
|
| 28 |
+
#begin warning
|
| 29 |
+
sub warning{
|
| 30 |
+
my @msgs= @_;
|
| 31 |
+
print STDOUT "WARNING: ";
|
| 32 |
+
for my $msg (@msgs){
|
| 33 |
+
print STDOUT $msg,"\n";
|
| 34 |
+
}
|
| 35 |
+
}
|
| 36 |
+
#end warning
|
| 37 |
+
|
| 38 |
+
#begin message
|
| 39 |
+
sub message{
|
| 40 |
+
my @msgs= @_;
|
| 41 |
+
for my $msg (@msgs){
|
| 42 |
+
print STDOU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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package BNGModel;
|
| 2 |
+
|
| 3 |
+
# BioNetGen : rule-based modeling language and simulation platform
|
| 4 |
+
#
|
| 5 |
+
# Copyright (C) 2006,2009,2012,2014 by
|
| 6 |
+
#
|
| 7 |
+
# James R. Faeder (faeder at pitt dot edu)
|
| 8 |
+
# Justin S. Hogg (justinshogg at gmail dot com)
|
| 9 |
+
# Leonard A. Harris (lh64 at cornell dot com)
|
| 10 |
+
# John A. P. Sekar (johnarul dot sekar at gmail dot com)
|
| 11 |
+
# Jose Juan Tapia (jjtapia at gmail dot com)
|
| 12 |
+
# Arshi Arora
|
| 13 |
+
# Dipak Barua
|
| 14 |
+
#
|
| 15 |
+
# This program is free software: you can redistribute it and/or modify
|
| 16 |
+
# it under the terms of the GNU General Public License as published by
|
| 17 |
+
# the Free Software Foundation, either version 3 of the License, or
|
| 18 |
+
# (at your option) any later version.
|
| 19 |
+
#
|
| 20 |
+
# This program is distributed in the hope that it will be useful,
|
| 21 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 22 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 23 |
+
# GNU General Public License for more details.
|
| 24 |
+
#
|
| 25 |
+
# You should have received a copy of the GNU General Public License
|
| 26 |
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
# pragmas
|
| 30 |
+
use strict;
|
| 31 |
+
use warnings;
|
| 32 |
+
no warnings 'redefine';
|
| 33 |
+
|
| 34 |
+
# Perl Modules
|
| 35 |
+
use Class::Struct;
|
| 36 |
+
use FindBin;
|
| 37 |
+
use lib $FindBin::Bin;
|
| 38 |
+
use File::Spec;
|
| 39 |
+
use File::Spec::Win32;
|
| 40 |
+
use POSIX ("floor", "ceil");
|
| 41 |
+
use Scalar::Util ("looks_like_number");
|
| 42 |
+
use Config;
|
| 43 |
+
|
| 44 |
+
use Cwd;
|
| 45 |
+
|
| 46 |
+
# BNGOutput contains BNGModel methods related to third-party output
|
| 47 |
+
# e.g. writeXML, writeSBML, writeMfile, writeMexfile, toSSC...
|
| 48 |
+
# Note that .NET and .BNGL writer methods are contained in THIS file.
|
| 49 |
+
use BNGOutput;
|
| 50 |
+
|
| 51 |
+
# BNGAction contains BNGModel action methods
|
| 52 |
+
# e.g. simulate, simulate_pla, simulate_nf, parameter_scan, generate_hybrid_model...
|
| 53 |
+
# Note that some core actions are contained here: generate_network, setParameter, etc.
|
| 54 |
+
use BNGAction;
|
| 55 |
+
|
| 56 |
+
# BNG Modules
|
| 57 |
+
use Cache;
|
| 58 |
+
use BNGUtils;
|
| 59 |
+
use MoleculeTypesList;
|
| 60 |
+
use ParamList;
|
| 61 |
+
use Function;
|
| 62 |
+
use Compartment;
|
| 63 |
+
use CompartmentList;
|
| 64 |
+
use SpeciesList;
|
| 65 |
+
use RxnRule;
|
| 66 |
+
use EnergyPattern;
|
| 67 |
+
use Observable;
|
| 68 |
+
use PopulationList;
|
| 69 |
+
|
| 70 |
+
#Variables that determine whether the network has been generated
|
| 71 |
+
my $NetFlag = 0;
|
| 72 |
+
|
| 73 |
+
# A place to store a reference to the current active model.
|
| 74 |
+
# Useful when other classes need to find the model.
|
| 75 |
+
$BNGModel::GLOBAL_MODEL = undef;
|
| 76 |
+
|
| 77 |
+
# Global package variables
|
| 78 |
+
my $NO_EXEC = 0; # Prevents execution of functions to allow file syntax checking
|
| 79 |
+
my $HAVE_PS = 0; # Set to 0 for MS Windows systems with no ps command - disables
|
| 80 |
+
# reporting of memory usage at each iteration of network generation
|
| 81 |
+
|
| 82 |
+
# Structure containing BioNetGen model data
|
| 83 |
+
struct BNGModel =>
|
| 84 |
+
{
|
| 85 |
+
Name => '$',
|
| 86 |
+
Time => '$',
|
| 87 |
+
Concentrations => '@',
|
| 88 |
+
MoleculeTypesList => 'MoleculeTypesList',
|
| 89 |
+
SpeciesList => 'SpeciesList',
|
| 90 |
+
SeedSpeciesList => 'SpeciesList',
|
| 91 |
+
RxnList => 'RxnList',
|
| 92 |
+
RxnRules => '@',
|
| 93 |
+
ParamList => 'ParamList',
|
| 94 |
+
Observables => '@',
|
| 95 |
+
EnergyPatterns => '@', # for energy BNG only: Holds a list of energy patterns
|
| 96 |
+
CompartmentList => 'CompartmentList', # list of reaction compartments (volumes and surfaces)
|
| 97 |
+
PopulationTypesList => 'MoleculeTypesList', # list of population molecule types
|
| 98 |
+
PopulationList => 'PopulationList', # list of population species
|
| 99 |
+
SubstanceUnits => '$',
|
| 100 |
+
UpdateNet => '$', # This variable is set to force update of NET file before simulation.
|
| 101 |
+
Version => '$', # Indicates set of version requirements- output to BNGL and NET files
|
| 102 |
+
Options => '%', # Options used to control behavior of model and associated methods
|
| 103 |
+
Params => '%', # run-time parameters (not to be saved)
|
| 104 |
+
ParameterCache => 'Cache',
|
| 105 |
+
ConcentrationCache => 'Cache',
|
| 106 |
+
VizGraphs => '$',
|
| 107 |
+
};
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
###
|
| 112 |
+
###
|
| 113 |
+
###
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
# Initialize BNGModel data structures
|
| 118 |
+
sub initialize
|
| 119 |
+
{
|
| 120 |
+
my $model = shift @_;
|
| 121 |
+
|
| 122 |
+
$model->Name('');
|
| 123 |
+
$model->Version('');
|
| 124 |
+
$model->Time(0);
|
| 125 |
+
$model->UpdateNet(0);
|
| 126 |
+
$model->ParamList( ParamList->new() );
|
| 127 |
+
$model->MoleculeTypesList( MoleculeTypesList->new('StrictTyping'=>0) );
|
| 128 |
+
$model->PopulationTypesList( MoleculeTypesList->new('StrictTyping'=>0) );
|
| 129 |
+
$model->PopulationList( PopulationList->new() );
|
| 130 |
+
$model->CompartmentList( CompartmentList->new('Used'=>0) );
|
| 131 |
+
$model->SpeciesList( SpeciesList->new() );
|
| 132 |
+
$model->RxnList( RxnList->new('SpeciesList'=>$model->SpeciesList) );
|
| 133 |
+
$model->SubstanceUnits('');
|
| 134 |
+
$model->ConcentrationCache( Cache->new() );
|
| 135 |
+
$model->ParameterCache( Cache->new() );
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
# read Model from file
|
| 140 |
+
# $err = $model->readModel({file=>FILENAME})
|
| 141 |
+
sub readModel
|
| 142 |
+
{
|
| 143 |
+
my $model = shift @_;
|
| 144 |
+
my $user_args = @_ ? shift @_ : {};
|
| 145 |
+
|
| 146 |
+
my %args = ();
|
| 147 |
+
# copy user_params into pass_params structures
|
| 148 |
+
while ( my ($key,$val) = each %$user_args )
|
| 149 |
+
{ $args{$key} = $val; }
|
| 150 |
+
|
| 151 |
+
# writeFile will generate the output
|
| 152 |
+
return $model->readFile( \%args );
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
# read Network from file
|
| 157 |
+
# $err = $model->readModel({file=>FILENAME})
|
| 158 |
+
sub readNetwork
|
| 159 |
+
{
|
| 160 |
+
my $model = shift @_;
|
| 161 |
+
my $user_args = @_ ? shift @_ : {};
|
| 162 |
+
|
| 163 |
+
my %args = ();
|
| 164 |
+
# copy user_params into pass_params structures
|
| 165 |
+
while ( my ($key,$val) = each %$user_args )
|
| 166 |
+
{ $args{$key} = $val; }
|
| 167 |
+
|
| 168 |
+
# writeFile will generate the output
|
| 169 |
+
return $model->readFile( \%args );
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
sub readSBML
|
| 173 |
+
{
|
| 174 |
+
my $model = shift @_;
|
| 175 |
+
my $filepath = shift @_;
|
| 176 |
+
unless ( -e $filepath )
|
| 177 |
+
{ return 1, "Could not find '$filepath'"; }
|
| 178 |
+
my ($vol, $dir, $filename) = File::Spec->splitpath( $filepath );
|
| 179 |
+
$filename =~ s/\.xml//;
|
| 180 |
+
my $outfile = File::Spec->catpath('', $model->getOutputDir(), $filename.'.bngl');
|
| 181 |
+
my $user_args = @_ ? shift @_ : {};
|
| 182 |
+
|
| 183 |
+
# Collect user arguments
|
| 184 |
+
my %args = ();
|
| 185 |
+
while ( my ($key,$val) = each %$user_args )
|
| 186 |
+
{
|
| 187 |
+
$args{$key} = $val;
|
| 188 |
+
# printf "$key=>$val\n";
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
+
# Find program and save path to directory
|
| 192 |
+
my $program;
|
| 193 |
+
unless ( $program = findExec("sbmlTranslator") )
|
| 194 |
+
{ return 1, "Could not find executable 'sbmlTranslator'"; }
|
| 195 |
+
($vol, $dir, my $bin) = File::Spec->splitpath( $program );
|
| 196 |
+
my $bindir = File::Spec->catpath($vol, $dir);
|
| 197 |
+
|
| 198 |
+
# Begin writing command: start with 'program'
|
| 199 |
+
my $cmd = $program;
|
| 200 |
+
$cmd .= ' -i "' . $filepath .'"';
|
| 201 |
+
$cmd .= ' -o "' . $outfile . '"';
|
| 202 |
+
if ($args{"atomize"}){
|
| 203 |
+
$cmd .= ' -a';
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
+
# Run the translator
|
| 207 |
+
printf "SBML translation: $cmd\n";
|
| 208 |
+
system($cmd);
|
| 209 |
+
|
| 210 |
+
# Return full path to generated BNGL file
|
| 211 |
+
return 0, $outfile
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
|
| 215 |
+
# Read bionetgen data in blocks enclosed by begin param end param
|
| 216 |
+
# lines. Prevents overwriting of variables possible with eval.
|
| 217 |
+
#
|
| 218 |
+
# To do:
|
| 219 |
+
# 1. Receive a valid list of parameter names to be read
|
| 220 |
+
# 2. Check syntax of lines- this is currently done when parameter is
|
| 221 |
+
# handled. Some basic checks could be done here.
|
| 222 |
+
#
|
| 223 |
+
# Lines between begin and end commands are put into arrays with the name given
|
| 224 |
+
# by the block name
|
| 225 |
+
{
|
| 226 |
+
|
| 227 |
+
my ($filename, $line_number, $file_data);
|
| 228 |
+
my (@filename_stack, @line_number_stack, @file_data_stack, @params_stack);
|
| 229 |
+
my $level = -1;
|
| 230 |
+
my $MAX_LEVEL = 10; # Sets maximum level of allowed recursion
|
| 231 |
+
my %bngdata;
|
| 232 |
+
my $t_start;
|
| 233 |
+
my $stdout_handle;
|
| 234 |
+
|
| 235 |
+
sub readFile
|
| 236 |
+
{
|
| 237 |
+
# get arguments
|
| 238 |
+
my $model = shift @_;
|
| 239 |
+
my $params = @_ ? shift @_ : {};
|
| 240 |
+
|
| 241 |
+
# supported blocks
|
| 242 |
+
my %blocks = (
|
| 243 |
+
'parameters' => 1,
|
| 244 |
+
'compartments' => 1,
|
| 245 |
+
'molecule types' => 1,
|
| 246 |
+
'species' => 1,
|
| 247 |
+
'seed species' => 1,
|
| 248 |
+
'observables' => 1,
|
| 249 |
+
'functions' => 1,
|
| 250 |
+
'energy patterns' => 1,
|
| 251 |
+
'population types' => 1,
|
| 252 |
+
'population maps' => 1,
|
| 253 |
+
'reaction rules' => 1,
|
| 254 |
+
'reactions' => 1,
|
| 255 |
+
'groups' => 1,
|
| 256 |
+
'actions' => 1,
|
| 257 |
+
);
|
| 258 |
+
|
| 259 |
+
# user-specified list of blocks to read
|
| 260 |
+
if (exists $params->{blocks}){
|
| 261 |
+
my %tmp;
|
| 262 |
+
foreach my $block (@{$params->{blocks}}){
|
| 263 |
+
$tmp{$block} = 1;
|
| 264 |
+
}
|
| 265 |
+
foreach (keys %blocks){
|
| 266 |
+
unless (exists $tmp{$_}){
|
| 267 |
+
$blocks{$_} = 0;
|
| 268 |
+
}
|
| 269 |
+
}
|
| 270 |
+
}
|
| 271 |
+
|
| 272 |
+
# a place for error messages
|
| 273 |
+
my $err;
|
| 274 |
+
|
| 275 |
+
# get the filename
|
| 276 |
+
my $filename = exists $params->{file} ? $params->{file} : undef;
|
| 277 |
+
unless ( defined $filename )
|
| 278 |
+
{ # Filename argument is mandatory
|
| 279 |
+
$err = errgen( "'file' parameter is required for action readFile()" );
|
| 280 |
+
goto EXIT;
|
| 281 |
+
}
|
| 282 |
+
|
| 283 |
+
# if file path is relative, change Unix path to Windows path, and vice versa,
|
| 284 |
+
# based on OS (improves cross-platform portability --LAH)
|
| 285 |
+
if ( not File::Spec::Win32->file_name_is_absolute( $filename ) ){
|
| 286 |
+
if ($Config{myarchname} =~ /MSWin32/)
|
| 287 |
+
{ $filename =~ s/\//\\/g; }
|
| 288 |
+
else
|
| 289 |
+
{ $filename =~ s/\\/\//g; }
|
| 290 |
+
}
|
| 291 |
+
|
| 292 |
+
# increment level
|
| 293 |
+
++$level;
|
| 294 |
+
if ($level > $MAX_LEVEL)
|
| 295 |
+
{
|
| 296 |
+
$err = errgen( "Recursion level exceeds maximum of $MAX_LEVEL" );
|
| 297 |
+
goto EXIT;
|
| 298 |
+
}
|
| 299 |
+
|
| 300 |
+
# Top level stuff
|
| 301 |
+
if ($level==0)
|
| 302 |
+
{
|
| 303 |
+
# get start time
|
| 304 |
+
$t_start = cpu_time(0);
|
| 305 |
+
|
| 306 |
+
# set model update flag
|
| 307 |
+
$model->UpdateNet(1);
|
| 308 |
+
|
| 309 |
+
# set model name
|
| 310 |
+
if ($model->Name eq '')
|
| 311 |
+
{
|
| 312 |
+
if ( $params->{basename} )
|
| 313 |
+
{ # set model name to basename
|
| 314 |
+
$model->Name( $params->{basename} );
|
| 315 |
+
}
|
| 316 |
+
else
|
| 317 |
+
{ # determine model basename from filename
|
| 318 |
+
my ($vol, $dir, $fn) = File::Spec->splitpath( $filename );
|
| 319 |
+
|
| 320 |
+
my $basename;
|
| 321 |
+
# file = basename.ext
|
| 322 |
+
if ( $fn =~ /^(.+)\.([^\.]+)$/ )
|
| 323 |
+
{ $basename = $1; }
|
| 324 |
+
# file = basename
|
| 325 |
+
elsif ( $fn =~ /^([^\.]+)$/ )
|
| 326 |
+
{ $basename = $1; }
|
| 327 |
+
# file = ???
|
| 328 |
+
else
|
| 329 |
+
{ $basename = $fn; }
|
| 330 |
+
|
| 331 |
+
$model->Name($basename);
|
| 332 |
+
}
|
| 333 |
+
}
|
| 334 |
+
|
| 335 |
+
# set model parameters
|
| 336 |
+
$model->Params($params);
|
| 337 |
+
|
| 338 |
+
# set output directory
|
| 339 |
+
unless ( defined $model->Params->{output_dir} )
|
| 340 |
+
{ # default is current directory
|
| 341 |
+
$model->setOutputDir();
|
| 342 |
+
}
|
| 343 |
+
|
| 344 |
+
# set up log file, if needed
|
| 345 |
+
if ( $model->Params->{logging} )
|
| 346 |
+
{
|
| 347 |
+
# generate logfile name
|
| 348 |
+
my $logfilename = $model->getOutputPrefix() . ".log" ;
|
| 349 |
+
# remember where to find STDOUT
|
| 350 |
+
unless( open $stdout_handle, ">&STDOUT" )
|
| 351 |
+
{ $err = "Problem finding handle for STDOUT: $!"; goto EXIT; }
|
| 352 |
+
# redirect STDOUT to logfile
|
| 353 |
+
unless ( open STDOUT, '>', $logfilename )
|
| 354 |
+
{ $err = "Problem redirecting STDOUT to logfile: $!";; goto EXIT; }
|
| 355 |
+
}
|
| 356 |
+
|
| 357 |
+
# turn off output buffering on STDOUT
|
| 358 |
+
select STDOUT; $| = 1;
|
| 359 |
+
|
| 360 |
+
# Say Hello to the user
|
| 361 |
+
printf "BioNetGen version %s\n", BNGversion();
|
| 362 |
+
}
|
| 363 |
+
elsif ($level > 0)
|
| 364 |
+
{
|
| 365 |
+
# save state of previous level on stacks
|
| 366 |
+
push @filename_stack, $filename;
|
| 367 |
+
push @file_data_stack, $file_data;
|
| 368 |
+
push @line_number_stack, $line_number;
|
| 369 |
+
push @params_stack, $model->Params;
|
| 370 |
+
|
| 371 |
+
# inherit params from previous level
|
| 372 |
+
$model->Params( {%{$model->Params}} );
|
| 373 |
+
# overwrite any params that were explicitly changed
|
| 374 |
+
while ( my ($opt,$val) = each %$params )
|
| 375 |
+
{ $model->Params->{$opt} = $val; }
|
| 376 |
+
}
|
| 377 |
+
|
| 378 |
+
# SBML translator
|
| 379 |
+
if ( $filename =~ /\.xml$/ )
|
| 380 |
+
{
|
| 381 |
+
if ( $model->Params->{no_atomizer} )
|
| 382 |
+
{
|
| 383 |
+
send_warning( "readFile(): BNG processing was halted. Attempted to import XML file with 'no-atomizer' flag activated.");
|
| 384 |
+
exit(0);
|
| 385 |
+
}
|
| 386 |
+
my $out;
|
| 387 |
+
($err, $out) = $model->readSBML($filename,$model->Params);
|
| 388 |
+
if ($err){
|
| 389 |
+
$err = $out;
|
| 390 |
+
goto EXIT;
|
| 391 |
+
}
|
| 392 |
+
$filename = $out
|
| 393 |
+
# Generated BNGL file will now be read in below
|
| 394 |
+
}
|
| 395 |
+
|
| 396 |
+
# Read BNGL or NET file
|
| 397 |
+
if ( $filename =~ /\.bngl$/ || $filename =~ /\.net$/ )
|
| 398 |
+
{
|
| 399 |
+
# Read BNG model data
|
| 400 |
+
print "Reading from file $filename (level $level)\n";
|
| 401 |
+
unless( open FILE, '<', $filename )
|
| 402 |
+
{
|
| 403 |
+
unless (File::Spec->file_name_is_absolute( $filename )){
|
| 404 |
+
$filename = File::Spec->rel2abs( $filename );
|
| 405 |
+
}
|
| 406 |
+
$err = "Couldn't read from file $filename: $!";
|
| 407 |
+
goto EXIT;
|
| 408 |
+
}
|
| 409 |
+
# read all lines of the file into an array at $file_data
|
| 410 |
+
$file_data = [<FILE>];
|
| 411 |
+
# close file
|
| 412 |
+
close FILE;
|
| 413 |
+
|
| 414 |
+
|
| 415 |
+
# Read data from file into data hash
|
| 416 |
+
$line_number = 0;
|
| 417 |
+
my $begin_model = 0;
|
| 418 |
+
my $in_model = 1;
|
| 419 |
+
while ( my $string = get_line() )
|
| 420 |
+
{
|
| 421 |
+
# chop leading spaces
|
| 422 |
+
$string =~ s/^\s+//;
|
| 423 |
+
|
| 424 |
+
if ( $string =~ /^begin\s+model\s*$/ )
|
| 425 |
+
{
|
| 426 |
+
++$begin_model;
|
| 427 |
+
if ( $begin_model > 1 )
|
| 428 |
+
{
|
| 429 |
+
$err = errgen("Only one model definition allowed per file");
|
| 430 |
+
goto EXIT;
|
| 431 |
+
}
|
| 432 |
+
$in_model = 1;
|
| 433 |
+
next;
|
| 434 |
+
}
|
| 435 |
+
elsif ( $string =~ /^end\s+model\s*$/ )
|
| 436 |
+
{
|
| 437 |
+
unless ($in_model)
|
| 438 |
+
{
|
| 439 |
+
$err = errgen("end model encountered without enclosing begin model");
|
| 440 |
+
goto EXIT;
|
| 441 |
+
}
|
| 442 |
+
$in_model = 0;
|
| 443 |
+
next;
|
| 444 |
+
}
|
| 445 |
+
|
| 446 |
+
# Process multi-line block
|
| 447 |
+
if ( $string =~ s/^begin\s*// )
|
| 448 |
+
{
|
| 449 |
+
# get block name
|
| 450 |
+
my $name = $string;
|
| 451 |
+
# Remove trailing white space
|
| 452 |
+
$name =~ s/\s*$//;
|
| 453 |
+
# Remove repeated white space
|
| 454 |
+
$name =~ s/\s+/ /g;
|
| 455 |
+
|
| 456 |
+
unless ($in_model or ($name eq 'actions'))
|
| 457 |
+
{
|
| 458 |
+
$err = errgen("$name cannot be defined outside of a model");
|
| 459 |
+
goto EXIT;
|
| 460 |
+
}
|
| 461 |
+
|
| 462 |
+
# Read block data
|
| 463 |
+
my $block_dat;
|
| 464 |
+
( $block_dat, $err ) = read_block_array($name);
|
| 465 |
+
if ($err) { goto EXIT; }
|
| 466 |
+
# $bngdata{$name} = 1;
|
| 467 |
+
|
| 468 |
+
# Move on if block has been suppressed by the user
|
| 469 |
+
# (if the block name is not recognized, continue so an error will be thrown)
|
| 470 |
+
if (exists $blocks{$name} and $blocks{$name}==0) { next; }
|
| 471 |
+
|
| 472 |
+
### Read Parameters Block
|
| 473 |
+
if ( $name eq 'parameters' )
|
| 474 |
+
{
|
| 475 |
+
# Read model parameters
|
| 476 |
+
my $plast = $model->ParamList->getNumParams();
|
| 477 |
+
my ($entry, $lno);
|
| 478 |
+
foreach my $line ( @$block_dat )
|
| 479 |
+
{
|
| 480 |
+
($entry, $lno) = @$line;
|
| 481 |
+
$err = $model->ParamList->readString($entry);
|
| 482 |
+
if ($err) { $err = errgen( $err, $lno ); goto EXIT; }
|
| 483 |
+
}
|
| 484 |
+
# check parameter list
|
| 485 |
+
if ( $err = $model->ParamList->check() )
|
| 486 |
+
{
|
| 487 |
+
$err = errgen( $err, $lno );
|
| 488 |
+
goto EXIT;
|
| 489 |
+
}
|
| 490 |
+
# sort parameters
|
| 491 |
+
if ( $err = $model->ParamList->sort() )
|
| 492 |
+
{
|
| 493 |
+
$err = errgen( $err, $lno );
|
| 494 |
+
goto EXIT;
|
| 495 |
+
}
|
| 496 |
+
# update user
|
| 497 |
+
printf "Read %d $name.\n", $model->ParamList->getNumParams() - $plast;
|
| 498 |
+
}
|
| 499 |
+
|
| 500 |
+
|
| 501 |
+
### Read Functions Block
|
| 502 |
+
elsif ( $name eq 'functions' )
|
| 503 |
+
{
|
| 504 |
+
# Model functions
|
| 505 |
+
my $nread = 0;
|
| 506 |
+
my ($entry, $lno);
|
| 507 |
+
foreach my $line ( @$block_dat )
|
| 508 |
+
{
|
| 509 |
+
($entry, $lno) = @{$line};
|
| 510 |
+
my $fun = Function->new();
|
| 511 |
+
$err = $fun->readString( $entry, $model );
|
| 512 |
+
if ($err) { $err = errgen( $err, $lno ); goto EXIT; }
|
| 513 |
+
++$nread;
|
| 514 |
+
}
|
| 515 |
+
|
| 516 |
+
# check paramlist for unresolved dependency, etc
|
| 517 |
+
# GIVE warning here, don't terminate!
|
| 518 |
+
if ( $err = $model->ParamList->check() )
|
| 519 |
+
{
|
| 520 |
+
$err = errgen( $err, $lno );
|
| 521 |
+
print "Warning: $err\n"
|
| 522 |
+
." (if parameter is defined in a subsequent block,\n"
|
| 523 |
+
." then this warning can be safely ignored.)\n";
|
| 524 |
+
}
|
| 525 |
+
# update user
|
| 526 |
+
printf "Read %d ${name}.\n", $nread;
|
| 527 |
+
}
|
| 528 |
+
|
| 529 |
+
|
| 530 |
+
### Read Molecule Types block
|
| 531 |
+
elsif ( $name eq 'molecule types' )
|
| 532 |
+
{
|
| 533 |
+
# read MoleculeTypes
|
| 534 |
+
$model->MoleculeTypesList->StrictTyping(1);
|
| 535 |
+
foreach my $line ( @$block_dat )
|
| 536 |
+
{
|
| 537 |
+
my ( $entry, $lno ) = @$line;
|
| 538 |
+
$err = $model->MoleculeTypesList->readString($entry);
|
| 539 |
+
if ($err) { $err = errgen( $err, $lno ); goto EXIT; }
|
| 540 |
+
}
|
| 541 |
+
# update user
|
| 542 |
+
printf "Read %d molecule types.\n", $model->MoleculeTypesList->getNumMolTypes();
|
| 543 |
+
}
|
| 544 |
+
|
| 545 |
+
|
| 546 |
+
### Read Population Types block
|
| 547 |
+
elsif ( $name eq 'population types' )
|
| 548 |
+
{
|
| 549 |
+
# read PopulationTypes
|
| 550 |
+
$model->PopulationTypesList->StrictTyping(1);
|
| 551 |
+
foreach my $line ( @$block_dat )
|
| 552 |
+
{
|
| 553 |
+
my ( $entry, $lno ) = @$line;
|
| 554 |
+
$err = $model->PopulationTypesList->readString($entry);
|
| 555 |
+
if ($err) { $err = errgen( $err, $lno ); goto EXIT; }
|
| 556 |
+
}
|
| 557 |
+
# update user
|
| 558 |
+
printf "Read %d population types.\n", $model->PopulationTypesList->getNumMolTypes();
|
| 559 |
+
}
|
| 560 |
+
|
| 561 |
+
|
| 562 |
+
### Read Population Maps block
|
| 563 |
+
elsif ( $name eq 'population maps' )
|
| 564 |
+
{
|
| 565 |
+
unless ( $model->MoleculeTypesList->StrictTyping )
|
| 566 |
+
{
|
| 567 |
+
$err = errgen("A $name block cannot be defined unless molecule types are defined explicitly");
|
| 568 |
+
goto EXIT;
|
| 569 |
+
}
|
| 570 |
+
# read Population Maps
|
| 571 |
+
foreach my $line ( @$block_dat )
|
| 572 |
+
{
|
| 573 |
+
my ($entry, $lno) = @$line;
|
| 574 |
+
$err = $model->PopulationList->readString($entry,$model);
|
| 575 |
+
if ($err) { $err = errgen( $err, $lno ); goto EXIT; }
|
| 576 |
+
}
|
| 577 |
+
# update user
|
| 578 |
+
printf "Read %d population maps.\n", $model->PopulationList->getNumPopulations;
|
| 579 |
+
}
|
| 580 |
+
|
| 581 |
+
|
| 582 |
+
### Read Compartments Block
|
| 583 |
+
elsif ( $name eq 'compartments' )
|
| 584 |
+
{
|
| 585 |
+
# Read Compartments
|
| 586 |
+
my ($entry, $lno);
|
| 587 |
+
foreach my $line ( @$block_dat )
|
| 588 |
+
{
|
| 589 |
+
($entry, $lno) = @$line;
|
| 590 |
+
$err = $model->CompartmentList->readString( $entry, $model->ParamList );
|
| 591 |
+
if ($err) { $err = errgen( $err, $lno ); goto EXIT; }
|
| 592 |
+
}
|
| 593 |
+
# validate compartments
|
| 594 |
+
if ( $err = $model->CompartmentList->validate() )
|
| 595 |
+
{
|
| 596 |
+
$err = errgen( $err, $lno );
|
| 597 |
+
goto EXIT;
|
| 598 |
+
}
|
| 599 |
+
if ($model->CompartmentList->getNumCompartments() > 0){
|
| 600 |
+
# set flag to indicate compartments are being used
|
| 601 |
+
$model->CompartmentList->Used(1);
|
| 602 |
+
# update user
|
| 603 |
+
printf "Read %d compartments.\n", $model->CompartmentList->getNumCompartments;
|
| 604 |
+
}
|
| 605 |
+
}
|
| 606 |
+
|
| 607 |
+
|
| 608 |
+
### Read Species/Seed Species Block
|
| 609 |
+
elsif ( ($name eq 'species') or ($name eq 'seed species') )
|
| 610 |
+
{
|
| 611 |
+
# read Species
|
| 612 |
+
foreach my $line ( @$block_dat )
|
| 613 |
+
{
|
| 614 |
+
my ($entry, $lno) = @$line;
|
| 615 |
+
$err = $model->SpeciesList->readString( $entry, $model->ParamList,
|
| 616 |
+
$model->CompartmentList,
|
| 617 |
+
$model->MoleculeTypesList );
|
| 618 |
+
if ($err) { $err = errgen( $err, $lno ); goto EXIT; }
|
| 619 |
+
}
|
| 620 |
+
# update user
|
| 621 |
+
printf "Read %d species.\n", $model->SpeciesList->getNumSpecies();
|
| 622 |
+
}
|
| 623 |
+
|
| 624 |
+
|
| 625 |
+
### Read Reaction Rules Block
|
| 626 |
+
elsif ( $name eq 'reaction rules' )
|
| 627 |
+
{
|
| 628 |
+
# Read reaction rules
|
| 629 |
+
my $nerr = 0;
|
| 630 |
+
# my $rrules = [];
|
| 631 |
+
# $model->RxnRules( $rrules );
|
| 632 |
+
my $rrules = $model->RxnRules;
|
| 633 |
+
my $counter = 1;
|
| 634 |
+
foreach my $line ( @$block_dat )
|
| 635 |
+
{
|
| 636 |
+
my ($entry, $lno) = @$line;
|
| 637 |
+
# create new rule
|
| 638 |
+
(my $rrs, $err) = RxnRule::newRxnRule( $entry, $model, $lno );
|
| 639 |
+
if ($err)
|
| 640 |
+
{ # some error encountered
|
| 641 |
+
$err = errgen( $err, $lno );
|
| 642 |
+
printf "ERROR: $err\n";
|
| 643 |
+
++$nerr;
|
| 644 |
+
}
|
| 645 |
+
# check rule name (if given)
|
| 646 |
+
elsif ( $rrs->[0]->Name ){
|
| 647 |
+
foreach my $r (@$rrules){ # loop over all existing rules
|
| 648 |
+
foreach my $x (@$r){ # consider forward and reverse (if exists) for existing rule (just to be safe)
|
| 649 |
+
if ( $rrs->[0]->Name eq $x->Name ){ # duplicate rule name found
|
| 650 |
+
$err = "Duplicate rule name detected (\"" . $rrs->[0]->Name . "\").";
|
| 651 |
+
$err = errgen( $err, $lno );
|
| 652 |
+
printf "ERROR: $err\n";
|
| 653 |
+
++$nerr;
|
| 654 |
+
last;
|
| 655 |
+
}
|
| 656 |
+
}
|
| 657 |
+
}
|
| 658 |
+
}
|
| 659 |
+
unless ($err)
|
| 660 |
+
{
|
| 661 |
+
# rule is ok
|
| 662 |
+
push @$rrules, $rrs;
|
| 663 |
+
|
| 664 |
+
# give names, if not defined
|
| 665 |
+
unless ( $rrs->[0]->Name )
|
| 666 |
+
{
|
| 667 |
+
#$rrs->[0]->Name( 'Rule' . scalar @$rrules );
|
| 668 |
+
my $rname = '_R' . $counter++;
|
| 669 |
+
# avoid duplicate names (just to be safe)
|
| 670 |
+
for (my $i=0; $i < @$rrules-1; $i++){
|
| 671 |
+
if ($rname eq @$rrules[$i]->[0]->Name){ # duplicate rule name
|
| 672 |
+
$rname = '_R' . $counter++;
|
| 673 |
+
$i = -1; # start over
|
| 674 |
+
}
|
| 675 |
+
}
|
| 676 |
+
$rrs->[0]->Name( $rname );
|
| 677 |
+
}
|
| 678 |
+
if ( @$rrs > 1 )
|
| 679 |
+
{
|
| 680 |
+
unless ($rrs->[1]->Name)
|
| 681 |
+
{
|
| 682 |
+
#$rrs->[1]->Name( 'Rule' . scalar @$rrules . 'r' );
|
| 683 |
+
$rrs->[1]->Name( '_reverse_' . $rrs->[0]->Name);
|
| 684 |
+
}
|
| 685 |
+
}
|
| 686 |
+
}
|
| 687 |
+
if ($nerr)
|
| 688 |
+
{
|
| 689 |
+
$err = "Reaction rule list could not be read because of errors.";
|
| 690 |
+
goto EXIT;
|
| 691 |
+
}
|
| 692 |
+
}
|
| 693 |
+
# update user
|
| 694 |
+
printf "Read %d reaction rule(s).\n", scalar @{$model->RxnRules};
|
| 695 |
+
}
|
| 696 |
+
|
| 697 |
+
|
| 698 |
+
### Read Reactions Block
|
| 699 |
+
elsif ( $name eq 'reactions' )
|
| 700 |
+
{
|
| 701 |
+
# Reactions (when reading NET file)
|
| 702 |
+
my $rlist = RxnList->new;
|
| 703 |
+
foreach my $line ( @{$block_dat} )
|
| 704 |
+
{
|
| 705 |
+
my ( $entry, $lno ) = @{$line};
|
| 706 |
+
$err = $rlist->readString( $entry,
|
| 707 |
+
$model->SpeciesList,
|
| 708 |
+
$model->ParamList );
|
| 709 |
+
if ($err) { $err = errgen( $err, $lno ); goto EXIT; }
|
| 710 |
+
}
|
| 711 |
+
printf "Read %d reaction(s).\n", scalar( @{$block_dat} );
|
| 712 |
+
$model->RxnList($rlist);
|
| 713 |
+
}
|
| 714 |
+
|
| 715 |
+
|
| 716 |
+
### Read Groups Block
|
| 717 |
+
elsif ( $name eq 'groups' )
|
| 718 |
+
{
|
| 719 |
+
my $iobs = 0;
|
| 720 |
+
if ( @{$model->Observables} )
|
| 721 |
+
{ # Associate groups with exisiting observables
|
| 722 |
+
# my $iobs = 0;
|
| 723 |
+
foreach my $line ( @$block_dat )
|
| 724 |
+
{
|
| 725 |
+
my ($entry, $lno) = @$line;
|
| 726 |
+
|
| 727 |
+
# split into tokens (note: using ' ' is different than / /, see perlfunc)
|
| 728 |
+
my @tokens = split ' ', $entry;
|
| 729 |
+
|
| 730 |
+
# Skip first entry if it's an index
|
| 731 |
+
if ( $tokens[0] =~ /^\d+$/ ) { shift @tokens; }
|
| 732 |
+
|
| 733 |
+
if ( $iobs >= @{$model->Observables} )
|
| 734 |
+
{ # more groups than observables!
|
| 735 |
+
$err = errgen( "More groups than observables", $lno );
|
| 736 |
+
goto EXIT;
|
| 737 |
+
}
|
| 738 |
+
|
| 739 |
+
# get observable
|
| 740 |
+
my $obs = $model->Observables->[$iobs];
|
| 741 |
+
|
| 742 |
+
# Check that Observable and Group names match
|
| 743 |
+
my $group_name = @tokens ? shift @tokens : '';
|
| 744 |
+
unless ( $group_name eq $obs->Name )
|
| 745 |
+
{
|
| 746 |
+
$err = errgen("Group named '$tokens[0]' is not compatible with any observable", $lno );
|
| 747 |
+
goto EXIT;
|
| 748 |
+
}
|
| 749 |
+
|
| 750 |
+
# get group weights
|
| 751 |
+
my @group_weights = split (/,/, $tokens[0]);
|
| 752 |
+
|
| 753 |
+
# Zero the weights (TODO..)
|
| 754 |
+
@{$obs->Weights} = (0) x scalar @{$obs->Weights};
|
| 755 |
+
my ($weight, $species_idx);
|
| 756 |
+
foreach my $component (@group_weights)
|
| 757 |
+
{
|
| 758 |
+
if ( $component =~ m/^(\d+)\*(\d+)$/ )
|
| 759 |
+
{
|
| 760 |
+
$weight = $1;
|
| 761 |
+
$species_idx = $2;
|
| 762 |
+
}
|
| 763 |
+
elsif ( $component =~ m/^(\d+)$/ )
|
| 764 |
+
{
|
| 765 |
+
$weight = 1;
|
| 766 |
+
$species_idx = $1;
|
| 767 |
+
}
|
| 768 |
+
else
|
| 769 |
+
{
|
| 770 |
+
$err = errgen( "Invalid group entry: $component", $lno );
|
| 771 |
+
goto EXIT;
|
| 772 |
+
}
|
| 773 |
+
$obs->Weights->[$species_idx] += $weight;
|
| 774 |
+
}
|
| 775 |
+
++$iobs;
|
| 776 |
+
}
|
| 777 |
+
}
|
| 778 |
+
else
|
| 779 |
+
{ # create a dummy observable for each group
|
| 780 |
+
send_warning("Found 'groups' block before 'observables': creating observables.");
|
| 781 |
+
|
| 782 |
+
# get the number of species
|
| 783 |
+
my $n_species = $model->SpeciesList->getNumSpecies();
|
| 784 |
+
|
| 785 |
+
#my $iobs = 0;
|
| 786 |
+
foreach my $line ( @$block_dat )
|
| 787 |
+
{
|
| 788 |
+
my ($entry, $lno) = @$line;
|
| 789 |
+
|
| 790 |
+
# split into tokens (note: using ' ' is different than / /, see perlfunc)
|
| 791 |
+
my @tokens = split ' ', $entry;
|
| 792 |
+
|
| 793 |
+
# Skip first entry if it's an index
|
| 794 |
+
if ( $tokens[0] =~ /^\d+$/ ) { shift @tokens; }
|
| 795 |
+
|
| 796 |
+
# Group name is next token
|
| 797 |
+
my $group_name = @tokens ? shift @tokens : '';
|
| 798 |
+
unless ( $group_name =~ /^\w+$/ )
|
| 799 |
+
{
|
| 800 |
+
$err = errgen("Invalid group name '$group_name'", $lno );
|
| 801 |
+
goto EXIT;
|
| 802 |
+
}
|
| 803 |
+
|
| 804 |
+
# create dummy observable
|
| 805 |
+
my $obs = Observable->new( Name=>$group_name, Patterns=>[], Weights=>[], Type=>"Molecule", Output=>1 );
|
| 806 |
+
push @{$model->Observables}, $obs;
|
| 807 |
+
|
| 808 |
+
# Add paramter to observable list
|
| 809 |
+
if ( $model->ParamList->set( $obs->Name, "0", 1, "Observable", $obs) )
|
| 810 |
+
{
|
| 811 |
+
my $name = $obs->Name;
|
| 812 |
+
$err = errgen( "Observable name $name matches previously defined Observable or Parameter", $lno );
|
| 813 |
+
goto EXIT;
|
| 814 |
+
}
|
| 815 |
+
|
| 816 |
+
# get group weights
|
| 817 |
+
my @group_weights = ($tokens[0]) ? split( /,/ , $tokens[0] ) : ();
|
| 818 |
+
|
| 819 |
+
# Zero the weights
|
| 820 |
+
@{$obs->Weights} = (0) x ($n_species+1);
|
| 821 |
+
my ($weight, $species_idx);
|
| 822 |
+
foreach my $component (@group_weights)
|
| 823 |
+
{
|
| 824 |
+
if ( $component =~ /^(\d+)\*(\d+)$/ )
|
| 825 |
+
{
|
| 826 |
+
$weight = $1;
|
| 827 |
+
$species_idx = $2;
|
| 828 |
+
}
|
| 829 |
+
elsif ( $component =~ /^(\d+)$/ )
|
| 830 |
+
{
|
| 831 |
+
$weight = 1;
|
| 832 |
+
$species_idx = $1;
|
| 833 |
+
}
|
| 834 |
+
else
|
| 835 |
+
{
|
| 836 |
+
$err = errgen( "Invalid group entry: $component", $lno );
|
| 837 |
+
goto EXIT;
|
| 838 |
+
}
|
| 839 |
+
$obs->Weights->[$species_idx] += $weight;
|
| 840 |
+
}
|
| 841 |
+
++$iobs;
|
| 842 |
+
}
|
| 843 |
+
}
|
| 844 |
+
# update user
|
| 845 |
+
printf "Read %d group(s).\n", $iobs;
|
| 846 |
+
}
|
| 847 |
+
|
| 848 |
+
|
| 849 |
+
### Read Observables Block
|
| 850 |
+
elsif ( $name eq 'observables' )
|
| 851 |
+
{
|
| 852 |
+
# Read observables
|
| 853 |
+
my ($entry, $lno );
|
| 854 |
+
foreach my $line ( @$block_dat )
|
| 855 |
+
{
|
| 856 |
+
($entry, $lno ) = @$line;
|
| 857 |
+
my $obs = Observable->new();
|
| 858 |
+
$err = $obs->readString($entry, $model);
|
| 859 |
+
if ($err)
|
| 860 |
+
{
|
| 861 |
+
$err = errgen( $err, $lno );
|
| 862 |
+
goto EXIT;
|
| 863 |
+
}
|
| 864 |
+
push @{$model->Observables}, $obs;
|
| 865 |
+
}
|
| 866 |
+
|
| 867 |
+
# check paramlist for unresolved dependency, etc
|
| 868 |
+
# GIVE warning here, don't terminate!
|
| 869 |
+
if ( $err = $model->ParamList->check() )
|
| 870 |
+
{
|
| 871 |
+
$err = errgen( $err, $lno );
|
| 872 |
+
print "Warning: $err\n"
|
| 873 |
+
." (if parameter is defined in a subsequent block,\n"
|
| 874 |
+
." then this warning can be safely ignored.)\n";
|
| 875 |
+
}
|
| 876 |
+
# update user
|
| 877 |
+
printf "Read %d observable(s).\n", scalar @{$model->Observables};
|
| 878 |
+
}
|
| 879 |
+
|
| 880 |
+
|
| 881 |
+
### Read Energy Patterns Block
|
| 882 |
+
elsif ( $name eq 'energy patterns' )
|
| 883 |
+
{
|
| 884 |
+
# read energy patterns
|
| 885 |
+
foreach my $line ( @$block_dat )
|
| 886 |
+
{
|
| 887 |
+
my ($entry, $lno) = @$line;
|
| 888 |
+
my $epatt = EnergyPattern->new();
|
| 889 |
+
$err = $epatt->readString( $entry, $model );
|
| 890 |
+
if ($err) { $err = errgen($err, $lno); goto EXIT; }
|
| 891 |
+
push @{$model->EnergyPatterns}, $epatt;
|
| 892 |
+
}
|
| 893 |
+
# update
|
| 894 |
+
printf "Read %d energy patterns(s).\n", scalar @{$model->EnergyPatterns};
|
| 895 |
+
|
| 896 |
+
}
|
| 897 |
+
|
| 898 |
+
|
| 899 |
+
### Read Actions Block
|
| 900 |
+
elsif ( $name eq 'actions' )
|
| 901 |
+
{
|
| 902 |
+
if ($model->Params->{'skip_actions'})
|
| 903 |
+
{
|
| 904 |
+
unless ($model->Params->{'action_skip_warn'})
|
| 905 |
+
{ send_warning( err_gen("Skipping actions") ); }
|
| 906 |
+
next;
|
| 907 |
+
}
|
| 908 |
+
# Read actions
|
| 909 |
+
foreach my $line ( @$block_dat )
|
| 910 |
+
{
|
| 911 |
+
my ($entry, $lno) = @$line;
|
| 912 |
+
# Remove (and ignore) leading index from line
|
| 913 |
+
$entry =~ s/^\d+\s+//;
|
| 914 |
+
# Get action and options
|
| 915 |
+
my ($action, $options);
|
| 916 |
+
if ( $entry =~ /^\s*(\w+)\s*\((.*)\);?\s*$/ )
|
| 917 |
+
{
|
| 918 |
+
$action = $1;
|
| 919 |
+
$options = $2;
|
| 920 |
+
# replace double quotes with single quotes so that Perl won't
|
| 921 |
+
# try to interpret special characters.
|
| 922 |
+
$options =~ s/"/'/g;
|
| 923 |
+
}
|
| 924 |
+
else
|
| 925 |
+
{
|
| 926 |
+
$err = "Line $entry does not appear to contain a command";
|
| 927 |
+
$err = errgen( $err, $lno );
|
| 928 |
+
}
|
| 929 |
+
|
| 930 |
+
# TODO: validate action
|
| 931 |
+
# TODO: validate option syntax
|
| 932 |
+
|
| 933 |
+
# Perform self-consistency checks before operations are performed on model
|
| 934 |
+
if ( $err = $model->ParamList->check() )
|
| 935 |
+
{
|
| 936 |
+
$err = errgen($err);
|
| 937 |
+
goto EXIT;
|
| 938 |
+
}
|
| 939 |
+
|
| 940 |
+
# execute action
|
| 941 |
+
my $command = sprintf "\$model->%s(%s);", $action, $options;
|
| 942 |
+
my $t_start = cpu_time(0);
|
| 943 |
+
$err = eval $command;
|
| 944 |
+
if ($@) { $err = errgen($@); goto EXIT; }
|
| 945 |
+
if ($err) { $err = errgen($err); goto EXIT; }
|
| 946 |
+
my $t_elapsed = cpu_time($t_start);
|
| 947 |
+
printf "CPU TIME: %s %.2f s.\n", $action, $t_elapsed;
|
| 948 |
+
}
|
| 949 |
+
}
|
| 950 |
+
|
| 951 |
+
|
| 952 |
+
### Try to read any other Block type (probably an error)
|
| 953 |
+
else
|
| 954 |
+
{ # exit
|
| 955 |
+
$err = errgen("Could not process block type '$name'");
|
| 956 |
+
goto EXIT;
|
| 957 |
+
}
|
| 958 |
+
}
|
| 959 |
+
|
| 960 |
+
elsif ( $string =~ /^\s*(setOption)\s*\((.*)\);?\s*$/ )
|
| 961 |
+
{ # special action: setOption(opts)
|
| 962 |
+
my $action = $1;
|
| 963 |
+
my $options = $2;
|
| 964 |
+
|
| 965 |
+
# Perform self-consistency checks before operations are performed on model
|
| 966 |
+
if ( $err = $model->ParamList->check() )
|
| 967 |
+
{ $err = errgen($err); goto EXIT; }
|
| 968 |
+
|
| 969 |
+
# call to methods associated with $model
|
| 970 |
+
my $command = '$model->' . $action . '(' . $options . ');';
|
| 971 |
+
$err = eval $command;
|
| 972 |
+
if ($@) { $err = errgen($@); goto EXIT; }
|
| 973 |
+
if ($err) { $err = errgen($err); goto EXIT; }
|
| 974 |
+
}
|
| 975 |
+
|
| 976 |
+
elsif ( $string =~ s/^\s*(parameter|param|par)\s+//i )
|
| 977 |
+
{ # Define a parameter outside of the Parameter block
|
| 978 |
+
unless ($in_model)
|
| 979 |
+
{
|
| 980 |
+
$err = errgen("Parameter cannot be defined outside of a model");
|
| 981 |
+
goto EXIT;
|
| 982 |
+
}
|
| 983 |
+
# read parameter
|
| 984 |
+
$err = $model->ParamList->readString($string);
|
| 985 |
+
if ($err) { $err = errgen($err); goto EXIT; }
|
| 986 |
+
}
|
| 987 |
+
|
| 988 |
+
elsif ( $string =~ /^\s*(\w+)\s*\((.*)\);?\s*$/ )
|
| 989 |
+
{ # execute an Action: "action(options)"
|
| 990 |
+
my $action = $1;
|
| 991 |
+
my $options = $2;
|
| 992 |
+
# replace double quotes with single quotes so that Perl won't
|
| 993 |
+
# try to interpret special characters.
|
| 994 |
+
$options =~ s/"/'/g;
|
| 995 |
+
|
| 996 |
+
if ($model->Params->{'skip_actions'})
|
| 997 |
+
{
|
| 998 |
+
unless ($model->Params->{'action_skip_warn'})
|
| 999 |
+
{ send_warning( errgen("Skipping actions") ); }
|
| 1000 |
+
next;
|
| 1001 |
+
}
|
| 1002 |
+
|
| 1003 |
+
# Perform self-consistency checks before operations are performed on model
|
| 1004 |
+
if ( $err = $model->ParamList->check() )
|
| 1005 |
+
{
|
| 1006 |
+
$err = errgen($err);
|
| 1007 |
+
goto EXIT;
|
| 1008 |
+
}
|
| 1009 |
+
|
| 1010 |
+
# execute action
|
| 1011 |
+
my $command = sprintf "\$model->%s(%s);", $action, $options;
|
| 1012 |
+
|
| 1013 |
+
#Check if the network is being read from a file
|
| 1014 |
+
if($action eq "readFile")
|
| 1015 |
+
{
|
| 1016 |
+
my $file_name = $options;
|
| 1017 |
+
$file_name =~ s/(.*)file(\s*)=>(\s*)("|')//;
|
| 1018 |
+
$file_name =~ s/("|')(.*)//;
|
| 1019 |
+
$file_name =~ s/(.*)\.//;
|
| 1020 |
+
if($file_name eq 'net'){$NetFlag = 1;}
|
| 1021 |
+
}
|
| 1022 |
+
|
| 1023 |
+
#The user has generated the network
|
| 1024 |
+
if($action eq "generate_network"){$NetFlag = 1;}
|
| 1025 |
+
my $method_name;
|
| 1026 |
+
if ($action eq "simulate" && $NetFlag == 0)
|
| 1027 |
+
{
|
| 1028 |
+
#Extract method
|
| 1029 |
+
$method_name = $options;
|
| 1030 |
+
$method_name =~ s/(.*)method(\s*)=>(\s*)('|")//;
|
| 1031 |
+
$method_name =~ s/("|')(.*)//;
|
| 1032 |
+
if($method_name =~ /^(ode|ssa|pla)$/)
|
| 1033 |
+
{
|
| 1034 |
+
my $t_start = cpu_time(0);
|
| 1035 |
+
#The simulation method requires a network
|
| 1036 |
+
#The user has not supplied a command. Use defaults
|
| 1037 |
+
my $cmd = sprintf "\$model->%s(%s);", "generate_network", "({overwrite=>1})";
|
| 1038 |
+
$err = eval $cmd;
|
| 1039 |
+
if ($@) { $err = errgen($@); goto EXIT; }
|
| 1040 |
+
if ($err) { $err = errgen($err); goto EXIT; }
|
| 1041 |
+
my $t_elapsed = cpu_time($t_start);
|
| 1042 |
+
printf "CPU TIME: %s %.2f s.\n","generate_network", $t_elapsed;
|
| 1043 |
+
$NetFlag = 1;
|
| 1044 |
+
}
|
| 1045 |
+
|
| 1046 |
+
}
|
| 1047 |
+
|
| 1048 |
+
if ($action =~ /^(simulate_ode|simulate_ssa|simulate_pla)$/ && $NetFlag == 0)
|
| 1049 |
+
{
|
| 1050 |
+
#The simulation method requires a network and the user has not generated one
|
| 1051 |
+
my $t_start = cpu_time(0);
|
| 1052 |
+
my $cmd = sprintf "\$model->%s(%s);", "generate_network", "({overwrite=>1})";
|
| 1053 |
+
$err = eval $cmd;
|
| 1054 |
+
if ($@) { $err = errgen($@); goto EXIT; }
|
| 1055 |
+
if ($err) { $err = errgen($err); goto EXIT; }
|
| 1056 |
+
my $t_elapsed = cpu_time($t_start);
|
| 1057 |
+
printf "CPU TIME: %s %.2f s.\n","generate_network", $t_elapsed;
|
| 1058 |
+
$NetFlag = 1;
|
| 1059 |
+
}
|
| 1060 |
+
|
| 1061 |
+
my $t_start = cpu_time(0);
|
| 1062 |
+
$err = eval $command;
|
| 1063 |
+
if ($@) { $err = errgen($@); goto EXIT; }
|
| 1064 |
+
if ($err) { $err = errgen($err); goto EXIT; }
|
| 1065 |
+
my $t_elapsed = cpu_time($t_start);
|
| 1066 |
+
printf "CPU TIME: %s %.2f s.\n", $action, $t_elapsed;
|
| 1067 |
+
|
| 1068 |
+
}
|
| 1069 |
+
else
|
| 1070 |
+
{ # Try to execute general PERL code (Dangerous!!)
|
| 1071 |
+
if ( $model->Params->{allow_perl} )
|
| 1072 |
+
{
|
| 1073 |
+
# General Perl code
|
| 1074 |
+
eval $string;
|
| 1075 |
+
if ($@) { $err = errgen($@); goto EXIT; }
|
| 1076 |
+
}
|
| 1077 |
+
else
|
| 1078 |
+
{
|
| 1079 |
+
send_warning( errgen("Unidentified input! Will not attempt to execute as Perl.") );
|
| 1080 |
+
next;
|
| 1081 |
+
}
|
| 1082 |
+
}
|
| 1083 |
+
}
|
| 1084 |
+
} # end read BNGL or NET
|
| 1085 |
+
else{
|
| 1086 |
+
printf "$filename\n";
|
| 1087 |
+
$filename =~ /(\.\w+)$/;
|
| 1088 |
+
$err = errgen("Cannot read file $filename. Unknown file extension '$1'.");
|
| 1089 |
+
goto EXIT;
|
| 1090 |
+
}
|
| 1091 |
+
|
| 1092 |
+
EXIT:
|
| 1093 |
+
unless ($err)
|
| 1094 |
+
{
|
| 1095 |
+
# if we're back at level 0, perform any required actions
|
| 1096 |
+
if ($level == 0)
|
| 1097 |
+
{
|
| 1098 |
+
if ( $model->Params->{'write_xml'} )
|
| 1099 |
+
{ $model->writeXML(); }
|
| 1100 |
+
|
| 1101 |
+
if ( $model->Params->{'generate_network'} )
|
| 1102 |
+
{ $model->generate_network({'overwrite'=>1}); }
|
| 1103 |
+
|
| 1104 |
+
if ( $model->Params->{'write_mfile'} )
|
| 1105 |
+
{ $model->writeMfile(); }
|
| 1106 |
+
|
| 1107 |
+
if ( $model->Params->{'write_sbml'} )
|
| 1108 |
+
{ $model->writeSBML(); }
|
| 1109 |
+
}
|
| 1110 |
+
|
| 1111 |
+
# indicate that we're finished
|
| 1112 |
+
print "Finished processing file $filename.\n";
|
| 1113 |
+
if ($level == 0)
|
| 1114 |
+
{ # write time info
|
| 1115 |
+
printf "CPU TIME: total %.2f s.\n", cpu_time($t_start);
|
| 1116 |
+
# restore STDOUT
|
| 1117 |
+
if ($params->{logging})
|
| 1118 |
+
{
|
| 1119 |
+
unless( open STDOUT, ">&", $stdout_handle )
|
| 1120 |
+
{ $err = "Problem restoring STDOUT: $!\n"; }
|
| 1121 |
+
}
|
| 1122 |
+
}
|
| 1123 |
+
}
|
| 1124 |
+
|
| 1125 |
+
if ($level > 0)
|
| 1126 |
+
{ # retrieve state of previous level from stack
|
| 1127 |
+
$filename = pop @filename_stack;
|
| 1128 |
+
$file_data = pop @file_data_stack;
|
| 1129 |
+
$line_number = pop @line_number_stack;
|
| 1130 |
+
$model->Params( pop @params_stack );
|
| 1131 |
+
}
|
| 1132 |
+
# drop a level
|
| 1133 |
+
--$level;
|
| 1134 |
+
# return with any error messages
|
| 1135 |
+
return $err;
|
| 1136 |
+
}
|
| 1137 |
+
|
| 1138 |
+
###
|
| 1139 |
+
###
|
| 1140 |
+
|
| 1141 |
+
sub read_block_array
|
| 1142 |
+
{
|
| 1143 |
+
my $name = shift @_;
|
| 1144 |
+
my @array = ();
|
| 1145 |
+
|
| 1146 |
+
my $got_end = 0;
|
| 1147 |
+
while ( $_ = get_line() )
|
| 1148 |
+
{
|
| 1149 |
+
# Look for end of block or errors
|
| 1150 |
+
if ( s/^\s*end\s+// )
|
| 1151 |
+
{
|
| 1152 |
+
my $ename = $_;
|
| 1153 |
+
$ename =~ s/\s*$//;
|
| 1154 |
+
$ename =~ s/\s+/ /g;
|
| 1155 |
+
if ( $ename ne $name )
|
| 1156 |
+
{
|
| 1157 |
+
return ( [], errgen("end $ename does not match begin $name") );
|
| 1158 |
+
}
|
| 1159 |
+
else
|
| 1160 |
+
{
|
| 1161 |
+
$got_end = 1;
|
| 1162 |
+
#print "end at $line_number\n";
|
| 1163 |
+
last;
|
| 1164 |
+
}
|
| 1165 |
+
}
|
| 1166 |
+
elsif ( /^\s*begin\s*/ )
|
| 1167 |
+
{
|
| 1168 |
+
return [], errgen("begin block before end of previous block $name");
|
| 1169 |
+
}
|
| 1170 |
+
|
| 1171 |
+
# Add declarations from current line
|
| 1172 |
+
push @array, [$_, $line_number];
|
| 1173 |
+
|
| 1174 |
+
#print "$_ $line_number\n";
|
| 1175 |
+
}
|
| 1176 |
+
|
| 1177 |
+
unless ($got_end)
|
| 1178 |
+
{ return [], errgen("begin $name has no matching end $name"); }
|
| 1179 |
+
|
| 1180 |
+
return [@array];
|
| 1181 |
+
}
|
| 1182 |
+
|
| 1183 |
+
###
|
| 1184 |
+
###
|
| 1185 |
+
|
| 1186 |
+
sub errgen
|
| 1187 |
+
{
|
| 1188 |
+
my $err = shift @_;
|
| 1189 |
+
my $lno = @_ ? shift @_ : $line_number;
|
| 1190 |
+
$err =~ s/[*]/\*/g;
|
| 1191 |
+
my $reterr = sprintf "%s\n at line $lno", $err;
|
| 1192 |
+
if (defined $filename) { $reterr .= " of file '$filename'"; }
|
| 1193 |
+
return $reterr;
|
| 1194 |
+
}
|
| 1195 |
+
|
| 1196 |
+
###
|
| 1197 |
+
###
|
| 1198 |
+
|
| 1199 |
+
sub get_line
|
| 1200 |
+
{
|
| 1201 |
+
my $line;
|
| 1202 |
+
while ( $line = shift @$file_data )
|
| 1203 |
+
{
|
| 1204 |
+
++$line_number;
|
| 1205 |
+
chomp $line; # remove newline character
|
| 1206 |
+
$line =~ s/\#.*$//; # remove comments
|
| 1207 |
+
next unless ($line =~ /\S+/); # skip blank lines
|
| 1208 |
+
while ( $line =~ s/\\\s*$// )
|
| 1209 |
+
{ # line continuations "\"
|
| 1210 |
+
last unless (@$file_data); # end if there are no more lines
|
| 1211 |
+
++$line_number;
|
| 1212 |
+
my $nline = shift @$file_data;
|
| 1213 |
+
chomp $nline;
|
| 1214 |
+
$nline =~ s/\#.*$//; # remove comments
|
| 1215 |
+
$line .= $nline; # append to previous line
|
| 1216 |
+
}
|
| 1217 |
+
last;
|
| 1218 |
+
}
|
| 1219 |
+
return $line;
|
| 1220 |
+
}
|
| 1221 |
+
|
| 1222 |
+
# END of readFile method
|
| 1223 |
+
}
|
| 1224 |
+
|
| 1225 |
+
|
| 1226 |
+
|
| 1227 |
+
###
|
| 1228 |
+
###
|
| 1229 |
+
###
|
| 1230 |
+
|
| 1231 |
+
|
| 1232 |
+
|
| 1233 |
+
# write Model to file (default is BNGL format)
|
| 1234 |
+
# $err = $model->writeModel({opt=>val,..})
|
| 1235 |
+
sub writeModel
|
| 1236 |
+
{
|
| 1237 |
+
use strict;
|
| 1238 |
+
use warnings;
|
| 1239 |
+
|
| 1240 |
+
my $model = shift @_;
|
| 1241 |
+
my $user_params = @_ ? shift @_ : {};
|
| 1242 |
+
|
| 1243 |
+
my %params = (
|
| 1244 |
+
'evaluate_expressions' => 0,
|
| 1245 |
+
'format' => 'bngl',
|
| 1246 |
+
'include_model' => 1,
|
| 1247 |
+
'include_network' => 0,
|
| 1248 |
+
'overwrite' => 0,
|
| 1249 |
+
'pretty_formatting' => 1,
|
| 1250 |
+
);
|
| 1251 |
+
|
| 1252 |
+
# copy user_params into pass_params structures
|
| 1253 |
+
while ( my ($key,$val) = each %$user_params )
|
| 1254 |
+
{ $params{$key} = $val; }
|
| 1255 |
+
|
| 1256 |
+
# writeFile will generate the output
|
| 1257 |
+
return $model->writeFile( \%params );
|
| 1258 |
+
}
|
| 1259 |
+
|
| 1260 |
+
|
| 1261 |
+
# write Network in NET format
|
| 1262 |
+
# $err = $model->writeNetwork({opt=>val,..})
|
| 1263 |
+
sub writeNetwork
|
| 1264 |
+
{
|
| 1265 |
+
use strict;
|
| 1266 |
+
use warnings;
|
| 1267 |
+
|
| 1268 |
+
my $model = shift @_;
|
| 1269 |
+
my $user_params = @_ ? shift @_ : {};
|
| 1270 |
+
|
| 1271 |
+
my %params = (
|
| 1272 |
+
'evaluate_expressions' => 0,
|
| 1273 |
+
'format' => 'net',
|
| 1274 |
+
'include_model' => 0,
|
| 1275 |
+
'include_network' => 1,
|
| 1276 |
+
'overwrite' => 0,
|
| 1277 |
+
'pretty_formatting' => 0,
|
| 1278 |
+
);
|
| 1279 |
+
|
| 1280 |
+
# copy user_params into pass_params structures
|
| 1281 |
+
while ( my ($key,$val) = each %$user_params )
|
| 1282 |
+
{ $params{$key} = $val; }
|
| 1283 |
+
|
| 1284 |
+
# writeFile will generate the output
|
| 1285 |
+
return $model->writeFile( \%params );
|
| 1286 |
+
}
|
| 1287 |
+
|
| 1288 |
+
|
| 1289 |
+
# Write Reaction Network to .NET file
|
| 1290 |
+
# This action will be Deprecated! writeModel and writeNetwork should be used instead
|
| 1291 |
+
sub writeNET
|
| 1292 |
+
{
|
| 1293 |
+
my $model = shift @_;
|
| 1294 |
+
my $user_params = @_ ? shift @_ : {};
|
| 1295 |
+
|
| 1296 |
+
# default parameters
|
| 1297 |
+
my %params = (
|
| 1298 |
+
'evaluate_expressions' => 1,
|
| 1299 |
+
'format' => 'net',
|
| 1300 |
+
'include_model' => 1,
|
| 1301 |
+
'include_network' => 1,
|
| 1302 |
+
'overwrite' => 1,
|
| 1303 |
+
'pretty_formatting' => 0,
|
| 1304 |
+
'TextReaction' => 0,
|
| 1305 |
+
'TextSpecies' => 1,
|
| 1306 |
+
);
|
| 1307 |
+
|
| 1308 |
+
# get any user parameters
|
| 1309 |
+
while ( my ($key,$val) = each %$user_params )
|
| 1310 |
+
{ $params{$key} = $val; }
|
| 1311 |
+
|
| 1312 |
+
# call writeFile to output the network
|
| 1313 |
+
return $model->writeFile( \%params );
|
| 1314 |
+
}
|
| 1315 |
+
|
| 1316 |
+
|
| 1317 |
+
# This is a general method for writing the model and/or network to a file in various formats.
|
| 1318 |
+
# (This method does the heavy lifting for writeModel and writeNetwork)
|
| 1319 |
+
#
|
| 1320 |
+
# $err = $model->writeFile({OPT=>VAL,..})
|
| 1321 |
+
#
|
| 1322 |
+
# OPTIONS:
|
| 1323 |
+
# evaluate_expressions => 0,1 : evaluate math expressions output as numbers (default=0).
|
| 1324 |
+
# format => "FORMAT" : select output format, where FORMAT=bngl,net,xml,sbml,ssc (default=net).
|
| 1325 |
+
# include_model => 0,1 : include model blocks in output file (default=1).
|
| 1326 |
+
# include_network => 0,1 : include network blocks in output file (default=1).
|
| 1327 |
+
# overwrite => 0,1 : allow writeFile to overwrite exisiting files (default=0).
|
| 1328 |
+
# prefix => "string" : set prefix of output file name (default=outdir/MODELNAME).
|
| 1329 |
+
# pretty_formatting => 0,1 : write output in "pretty" form (default=0).
|
| 1330 |
+
# suffix => "string" : set suffix of output file name (default=NONE).
|
| 1331 |
+
# TextReaction => 0,1 : write reactions as BNGL strings (default=0).
|
| 1332 |
+
# TextSpecies => 0,1 : write species as BNGL string (default=1).
|
| 1333 |
+
#
|
| 1334 |
+
# TODO: set up additional formats: SBML, SSC, etc.
|
| 1335 |
+
sub writeFile
|
| 1336 |
+
{
|
| 1337 |
+
use strict;
|
| 1338 |
+
use warnings;
|
| 1339 |
+
|
| 1340 |
+
my $model = shift @_;
|
| 1341 |
+
my $user_params = @_ ? shift @_ : {};
|
| 1342 |
+
|
| 1343 |
+
my %params = (
|
| 1344 |
+
'evaluate_expressions' => 0,
|
| 1345 |
+
'format' => 'net',
|
| 1346 |
+
'include_model' => 1,
|
| 1347 |
+
'include_network' => 1,
|
| 1348 |
+
'overwrite' => 1,
|
| 1349 |
+
'prefix' => $model->getOutputPrefix(),
|
| 1350 |
+
'pretty_formatting' => 1,
|
| 1351 |
+
'suffix' => '',
|
| 1352 |
+
'TextReaction' => 0,
|
| 1353 |
+
'TextSpecies' => 1,
|
| 1354 |
+
);
|
| 1355 |
+
|
| 1356 |
+
# change this to a constant?
|
| 1357 |
+
my %allowed_formats = ( 'net'=>1, 'bngl'=>1, 'sbml'=>0, 'xml'=>1, 'ssc'=>0 );
|
| 1358 |
+
|
| 1359 |
+
# copy user_params into params and pass_params structures
|
| 1360 |
+
foreach my $key ( keys %$user_params )
|
| 1361 |
+
{
|
| 1362 |
+
my $val = $user_params->{$key};
|
| 1363 |
+
if ( exists $params{$key} )
|
| 1364 |
+
{ $params{$key} = $val; }
|
| 1365 |
+
else
|
| 1366 |
+
{ die "writeFile(): Unrecognized option parameter $key."; }
|
| 1367 |
+
}
|
| 1368 |
+
|
| 1369 |
+
# check if format is allowed
|
| 1370 |
+
unless ( $allowed_formats{ $params{'format'} } )
|
| 1371 |
+
{
|
| 1372 |
+
return sprintf( "writeFile() does not currently support '%s' format.", $params{'format'} );
|
| 1373 |
+
}
|
| 1374 |
+
|
| 1375 |
+
# check if there's anything to write
|
| 1376 |
+
unless ( $params{'include_model'} or $params{'include_network'} )
|
| 1377 |
+
{
|
| 1378 |
+
return "writeFile() has nothing to write! Include model or network and try again.";
|
| 1379 |
+
}
|
| 1380 |
+
|
| 1381 |
+
# check for reactions if we're writing the network
|
| 1382 |
+
if ( $params{include_network} )
|
| 1383 |
+
{
|
| 1384 |
+
if ( @{$model->RxnList->Array} == 0 )
|
| 1385 |
+
{
|
| 1386 |
+
return "writeFile() was asked to write the network, but no reactions were found.\n"
|
| 1387 |
+
."Did you remember to call generate_network() before writing network output?\n";
|
| 1388 |
+
}
|
| 1389 |
+
}
|
| 1390 |
+
|
| 1391 |
+
# do nothing if we're not executing actions
|
| 1392 |
+
return undef if $NO_EXEC;
|
| 1393 |
+
|
| 1394 |
+
## Execute the Action ##
|
| 1395 |
+
# first, build output filename
|
| 1396 |
+
my $file = $params{prefix};
|
| 1397 |
+
unless ( $params{suffix} eq '' )
|
| 1398 |
+
{ $file .= "_$params{suffix}"; }
|
| 1399 |
+
$file .= ".$params{format}";
|
| 1400 |
+
|
| 1401 |
+
# now check if we're overwriting an existing file
|
| 1402 |
+
if ( -e $file )
|
| 1403 |
+
{
|
| 1404 |
+
if ( $params{overwrite} )
|
| 1405 |
+
{
|
| 1406 |
+
send_warning("writeFile(): Overwriting existing file $file.");
|
| 1407 |
+
unlink $file;
|
| 1408 |
+
}
|
| 1409 |
+
else
|
| 1410 |
+
{ return "writeFile(): file $file exists. Set option overwrite=>1 to overwrite."; }
|
| 1411 |
+
}
|
| 1412 |
+
|
| 1413 |
+
# make a string that describes outputs to user
|
| 1414 |
+
my @outputs;
|
| 1415 |
+
if ( $params{'include_model'} )
|
| 1416 |
+
{ push @outputs, "model"; }
|
| 1417 |
+
if ( $params{'include_network'} )
|
| 1418 |
+
{ push @outputs, "network"; }
|
| 1419 |
+
my $output = join " and ", @outputs;
|
| 1420 |
+
|
| 1421 |
+
# get file output in string format
|
| 1422 |
+
my $file_string;
|
| 1423 |
+
if ( $params{'format'} eq 'net' )
|
| 1424 |
+
{ # write NET format
|
| 1425 |
+
$file_string = $model->writeBNGL( \%params );
|
| 1426 |
+
}
|
| 1427 |
+
elsif ( $params{'format'} eq 'bngl' )
|
| 1428 |
+
{ # write BNGL format
|
| 1429 |
+
$file_string = $model->writeBNGL( \%params );
|
| 1430 |
+
}
|
| 1431 |
+
elsif ( $params{'format'} eq 'xml' )
|
| 1432 |
+
{ # write XML format
|
| 1433 |
+
$file_string = $model->toXML( \%params );
|
| 1434 |
+
}
|
| 1435 |
+
|
| 1436 |
+
# write the string to file
|
| 1437 |
+
my $FH;
|
| 1438 |
+
open($FH, '>', $file) or return "Couldn't write to $file: $!\n";
|
| 1439 |
+
print $FH $file_string;
|
| 1440 |
+
close $FH;
|
| 1441 |
+
|
| 1442 |
+
# all done
|
| 1443 |
+
print sprintf( "Wrote %s in %s format to %s.\n", $output, $params{'format'}, $file);
|
| 1444 |
+
return undef;
|
| 1445 |
+
}
|
| 1446 |
+
|
| 1447 |
+
|
| 1448 |
+
# Write Model to a BNGL formatted string.
|
| 1449 |
+
# This method returns a string and does NOT write to file.
|
| 1450 |
+
# (also writes reaction network, if it exists)
|
| 1451 |
+
sub writeBNGL
|
| 1452 |
+
{
|
| 1453 |
+
use strict;
|
| 1454 |
+
use warnings;
|
| 1455 |
+
|
| 1456 |
+
my $model = shift @_;
|
| 1457 |
+
my $user_params = @_ ? shift @_ : {};
|
| 1458 |
+
|
| 1459 |
+
# Default parameters required by this method.
|
| 1460 |
+
# NOTE: since this method is not a user action, we don't need to check parameters.
|
| 1461 |
+
# Instead, we assume the programmers call this method with valid options.
|
| 1462 |
+
my %params = (
|
| 1463 |
+
'convert_intensive_to_extensive_units' => 1,
|
| 1464 |
+
'evaluate_expressions' => 0,
|
| 1465 |
+
'format' => 'net',
|
| 1466 |
+
'include_model' => 1,
|
| 1467 |
+
'include_network' => 1,
|
| 1468 |
+
'pretty_formatting' => 1,
|
| 1469 |
+
'TextReaction' => 0,
|
| 1470 |
+
'TextSpecies' => 1,
|
| 1471 |
+
);
|
| 1472 |
+
|
| 1473 |
+
# get any user parameters
|
| 1474 |
+
while ( my ($key,$val) = each %$user_params )
|
| 1475 |
+
{ $params{$key} = $val; }
|
| 1476 |
+
|
| 1477 |
+
return '' if $NO_EXEC;
|
| 1478 |
+
|
| 1479 |
+
|
| 1480 |
+
# !!! Begin writing file !!!
|
| 1481 |
+
my $out = '';
|
| 1482 |
+
|
| 1483 |
+
# Header
|
| 1484 |
+
my $version = BNGversion();
|
| 1485 |
+
my $codename = BNGcodename();
|
| 1486 |
+
$out .= "# Created by BioNetGen ${version}-${codename}\n";
|
| 1487 |
+
|
| 1488 |
+
# Version requirements
|
| 1489 |
+
unless ( $model->Version eq '' )
|
| 1490 |
+
{ $out .= sprintf "version(\"%s\")\n", $model->Version; }
|
| 1491 |
+
|
| 1492 |
+
# Options
|
| 1493 |
+
while ( my ($opt,$val) = each %{$model->Options} )
|
| 1494 |
+
{
|
| 1495 |
+
next if ( $opt eq 'prefix' ); # don't write prefix
|
| 1496 |
+
next if ( $opt eq 'suffix' ); # don't write suffix
|
| 1497 |
+
$out .= "setOption(\"$opt\",\"$val\")\n";
|
| 1498 |
+
}
|
| 1499 |
+
|
| 1500 |
+
# Units
|
| 1501 |
+
unless ($model->SubstanceUnits eq '')
|
| 1502 |
+
{ $out .= sprintf "substanceUnits(\"%s\")\n", $model->SubstanceUnits; }
|
| 1503 |
+
|
| 1504 |
+
# Begin Model (BNGL only)
|
| 1505 |
+
$out .= "\nbegin model\n" if ( $params{'format'} eq 'bngl' and $params{'pretty_formatting'} );
|
| 1506 |
+
|
| 1507 |
+
# Parameters
|
| 1508 |
+
$out .= $model->ParamList->writeBNGL( \%params );
|
| 1509 |
+
|
| 1510 |
+
# Model blocks
|
| 1511 |
+
if ( $params{'include_model'} )
|
| 1512 |
+
{
|
| 1513 |
+
# Compartments
|
| 1514 |
+
if ( defined $model->CompartmentList and @{$model->CompartmentList->Array} )
|
| 1515 |
+
{ $out .= $model->CompartmentList->toString( $model->ParamList ); }
|
| 1516 |
+
|
| 1517 |
+
# MoleculeTypes
|
| 1518 |
+
if ( $model->MoleculeTypesList->StrictTyping )
|
| 1519 |
+
{ $out .= $model->MoleculeTypesList->writeBNGL( \%params ); }
|
| 1520 |
+
|
| 1521 |
+
# Observables
|
| 1522 |
+
if ( @{$model->Observables} )
|
| 1523 |
+
{
|
| 1524 |
+
# find max length of observable name
|
| 1525 |
+
my $max_length = 0;
|
| 1526 |
+
foreach my $obs ( @{$model->Observables} )
|
| 1527 |
+
{
|
| 1528 |
+
$max_length = ( length $obs->Name > $max_length ) ? length $obs->Name : $max_length;
|
| 1529 |
+
}
|
| 1530 |
+
|
| 1531 |
+
$out .= "begin observables\n";
|
| 1532 |
+
my $io = 1;
|
| 1533 |
+
foreach my $obs ( @{$model->Observables} )
|
| 1534 |
+
{
|
| 1535 |
+
if ( $params{'pretty_formatting'} )
|
| 1536 |
+
{ # no observable index
|
| 1537 |
+
$out .= sprintf " %s\n", $obs->toString($max_length);
|
| 1538 |
+
}
|
| 1539 |
+
else
|
| 1540 |
+
{ # include index
|
| 1541 |
+
$out .= sprintf "%5d %s\n", $io, $obs->toString();
|
| 1542 |
+
}
|
| 1543 |
+
++$io;
|
| 1544 |
+
}
|
| 1545 |
+
$out .= "end observables\n";
|
| 1546 |
+
}
|
| 1547 |
+
|
| 1548 |
+
# Energy Patterns
|
| 1549 |
+
if ( @{$model->EnergyPatterns} )
|
| 1550 |
+
{
|
| 1551 |
+
$out .= "begin energy patterns\n";
|
| 1552 |
+
my $io = 1;
|
| 1553 |
+
foreach my $epatt ( @{ $model->EnergyPatterns } )
|
| 1554 |
+
{
|
| 1555 |
+
if ( $params{'pretty_formatting'} )
|
| 1556 |
+
{ # no energy pattern index
|
| 1557 |
+
$out .= sprintf " %s\n", $epatt->toString($model->ParamList);
|
| 1558 |
+
}
|
| 1559 |
+
else
|
| 1560 |
+
{ # include index
|
| 1561 |
+
$out .= sprintf "%5d %s\n", $io, $epatt->toString($model->ParamList);
|
| 1562 |
+
}
|
| 1563 |
+
|
| 1564 |
+
++$io;
|
| 1565 |
+
};
|
| 1566 |
+
$out .= "end energy patterns\n";
|
| 1567 |
+
}
|
| 1568 |
+
}
|
| 1569 |
+
|
| 1570 |
+
# Functions
|
| 1571 |
+
$out .= $model->ParamList->writeFunctions( \%params );
|
| 1572 |
+
|
| 1573 |
+
# Species
|
| 1574 |
+
$out .= $model->SpeciesList->writeBNGL( $model->Concentrations, $model->ParamList, \%params );
|
| 1575 |
+
|
| 1576 |
+
|
| 1577 |
+
# Model Blocks
|
| 1578 |
+
if ( $params{include_model} )
|
| 1579 |
+
{
|
| 1580 |
+
# Reaction rules
|
| 1581 |
+
$out .= "begin reaction rules\n";
|
| 1582 |
+
{
|
| 1583 |
+
my $irxn = 1;
|
| 1584 |
+
foreach my $rset ( @{$model->RxnRules} )
|
| 1585 |
+
{
|
| 1586 |
+
my $rreverse = ( @$rset > 1 ) ? $rset->[1] : undef;
|
| 1587 |
+
|
| 1588 |
+
# write BNGL rule
|
| 1589 |
+
$out .= sprintf " %s\n", $rset->[0]->toString($rreverse);
|
| 1590 |
+
|
| 1591 |
+
# write actions
|
| 1592 |
+
if ( $params{'pretty_formatting'} )
|
| 1593 |
+
{ # pretty, don't write actions
|
| 1594 |
+
# do nothing!
|
| 1595 |
+
}
|
| 1596 |
+
else
|
| 1597 |
+
{ # write actions
|
| 1598 |
+
$out .= $rset->[0]->listActions();
|
| 1599 |
+
if ( defined $rreverse )
|
| 1600 |
+
{
|
| 1601 |
+
$out .= " # Reverse\n";
|
| 1602 |
+
$out .= $rset->[1]->listActions();
|
| 1603 |
+
}
|
| 1604 |
+
}
|
| 1605 |
+
++$irxn;
|
| 1606 |
+
}
|
| 1607 |
+
}
|
| 1608 |
+
$out .= "end reaction rules\n";
|
| 1609 |
+
}
|
| 1610 |
+
|
| 1611 |
+
# Network blocks
|
| 1612 |
+
if ( $params{'include_network'} )
|
| 1613 |
+
{
|
| 1614 |
+
# Reactions
|
| 1615 |
+
if ( $params{'TextReaction'} )
|
| 1616 |
+
{ print "Writing full species names in reactions.\n"; }
|
| 1617 |
+
$out .= $model->RxnList->writeBNGL( \%params, $model->ParamList );
|
| 1618 |
+
|
| 1619 |
+
# Groups
|
| 1620 |
+
if ( @{$model->Observables} )
|
| 1621 |
+
{
|
| 1622 |
+
$out .= "begin groups\n";
|
| 1623 |
+
my $io = 1;
|
| 1624 |
+
foreach my $obs ( @{$model->Observables} )
|
| 1625 |
+
{
|
| 1626 |
+
$out .= sprintf "%5d %s\n", $io, $obs->toGroupString( $model->SpeciesList );
|
| 1627 |
+
++$io;
|
| 1628 |
+
}
|
| 1629 |
+
$out .= "end groups\n";
|
| 1630 |
+
}
|
| 1631 |
+
}
|
| 1632 |
+
|
| 1633 |
+
# End Model (BNGL only)
|
| 1634 |
+
$out .= "end model\n" if ( $params{'format'} eq 'bngl' and $params{'pretty_formatting'} );
|
| 1635 |
+
|
| 1636 |
+
return $out;
|
| 1637 |
+
}
|
| 1638 |
+
|
| 1639 |
+
|
| 1640 |
+
|
| 1641 |
+
###
|
| 1642 |
+
###
|
| 1643 |
+
###
|
| 1644 |
+
|
| 1645 |
+
|
| 1646 |
+
|
| 1647 |
+
# Syntax
|
| 1648 |
+
# setOption(name,value,name,value,...) Set option value pairs
|
| 1649 |
+
# First call will cause initialization with default values.
|
| 1650 |
+
sub setOption
|
| 1651 |
+
{
|
| 1652 |
+
my $model = shift @_;
|
| 1653 |
+
my $err = '';
|
| 1654 |
+
|
| 1655 |
+
# Process options
|
| 1656 |
+
while (@_)
|
| 1657 |
+
{
|
| 1658 |
+
my $arg = shift @_;
|
| 1659 |
+
unless (@_) { return "No value specified for option $arg"; }
|
| 1660 |
+
my $val = shift @_;
|
| 1661 |
+
|
| 1662 |
+
# TODO: print arg and val to user?
|
| 1663 |
+
|
| 1664 |
+
if ( $arg eq "SpeciesLabel" )
|
| 1665 |
+
{
|
| 1666 |
+
# SpeciesLabel method can only be changed prior to reading species.
|
| 1667 |
+
# Otherwise, inconsistent behavior could arise from changing the
|
| 1668 |
+
# labeling method.
|
| 1669 |
+
if ( $model->SpeciesList->size() )
|
| 1670 |
+
{ return "$arg option can only be changed prior to defining species."; }
|
| 1671 |
+
$err = SpeciesGraph::setSpeciesLabel($val);
|
| 1672 |
+
if ($err) { return $err; }
|
| 1673 |
+
$model->Options->{$arg} = $val;
|
| 1674 |
+
}
|
| 1675 |
+
elsif ( $arg eq "energyBNG" )
|
| 1676 |
+
{ # enable energy mode
|
| 1677 |
+
send_warning("The energyBNG option is now deprecated (energy features available by default).");
|
| 1678 |
+
}
|
| 1679 |
+
elsif ( $arg eq "NumberPerQuantityUnit" )
|
| 1680 |
+
{ # set conversion from quantity units to pure numbers
|
| 1681 |
+
# TODO: allow this to be a parameter?
|
| 1682 |
+
$model->Options->{$arg} = $val;
|
| 1683 |
+
}
|
| 1684 |
+
elsif ( $arg eq "MoleculesObservables" )
|
| 1685 |
+
{ # set molecules observables mode
|
| 1686 |
+
unless ($val eq "CountUnique" or $val eq "CountAll")
|
| 1687 |
+
{ return "Invalid option for or $arg (valid options are 'CountUnique' and 'CountAll')"; }
|
| 1688 |
+
$model->Options->{$arg} = $val;
|
| 1689 |
+
}
|
| 1690 |
+
elsif ( $arg eq "SpeciesObservables" )
|
| 1691 |
+
{ # set species observables mode
|
| 1692 |
+
unless ($val eq "CountUnique" or $val eq "CountAll")
|
| 1693 |
+
{ return "Invalid option for or $arg (valid options are 'CountUnique' and 'CountAll')"; }
|
| 1694 |
+
$model->Options->{$arg} = $val;
|
| 1695 |
+
}
|
| 1696 |
+
else
|
| 1697 |
+
{
|
| 1698 |
+
return "Unrecognized option $arg in setOption";
|
| 1699 |
+
}
|
| 1700 |
+
}
|
| 1701 |
+
|
| 1702 |
+
return '';
|
| 1703 |
+
}
|
| 1704 |
+
|
| 1705 |
+
|
| 1706 |
+
sub substanceUnits
|
| 1707 |
+
{
|
| 1708 |
+
my $model = shift @_;
|
| 1709 |
+
my $units = shift @_;
|
| 1710 |
+
|
| 1711 |
+
my $ucommand = "";
|
| 1712 |
+
if ( $units =~ /^conc/i ) {
|
| 1713 |
+
$ucommand = "Concentration";
|
| 1714 |
+
}
|
| 1715 |
+
elsif ( $units =~ /^num/i ) {
|
| 1716 |
+
$ucommand = "Number";
|
| 1717 |
+
}
|
| 1718 |
+
else {
|
| 1719 |
+
return "Invalid argument to subtanceUnits $units: valid arguments are Number and Concentration";
|
| 1720 |
+
}
|
| 1721 |
+
|
| 1722 |
+
print "SubstanceUnits set to $ucommand.\n";
|
| 1723 |
+
$model->SubstanceUnits($ucommand);
|
| 1724 |
+
return '';
|
| 1725 |
+
}
|
| 1726 |
+
|
| 1727 |
+
|
| 1728 |
+
sub setVolume
|
| 1729 |
+
{
|
| 1730 |
+
my $model = shift @_;
|
| 1731 |
+
my $compartment_name = shift @_;
|
| 1732 |
+
my $value = shift @_;
|
| 1733 |
+
|
| 1734 |
+
return $model->CompartmentList->setVolume( $compartment_name, $value );
|
| 1735 |
+
}
|
| 1736 |
+
|
| 1737 |
+
|
| 1738 |
+
|
| 1739 |
+
###
|
| 1740 |
+
###
|
| 1741 |
+
###
|
| 1742 |
+
|
| 1743 |
+
|
| 1744 |
+
|
| 1745 |
+
sub setParameter
|
| 1746 |
+
{
|
| 1747 |
+
my $model = shift @_;
|
| 1748 |
+
my $pname = shift @_;
|
| 1749 |
+
my $value = shift @_;
|
| 1750 |
+
|
| 1751 |
+
return '' if $NO_EXEC;
|
| 1752 |
+
|
| 1753 |
+
my $plist = $model->ParamList;
|
| 1754 |
+
my ($param, $err);
|
| 1755 |
+
|
| 1756 |
+
# Error if parameter doesn't exist
|
| 1757 |
+
( $param, $err ) = $plist->lookup($pname);
|
| 1758 |
+
if ($err) { return ($err) }
|
| 1759 |
+
|
| 1760 |
+
# Read expression
|
| 1761 |
+
my $expr = Expression->new();
|
| 1762 |
+
my $estring = "$pname=$value";
|
| 1763 |
+
if ( $err = $expr->readString( \$estring, $plist ) ) { return $err; }
|
| 1764 |
+
|
| 1765 |
+
# Set flag to update netfile when it's used
|
| 1766 |
+
$model->UpdateNet(1);
|
| 1767 |
+
|
| 1768 |
+
printf "Set parameter %s to value %s\n", $pname, $expr->evaluate($plist);
|
| 1769 |
+
return '';
|
| 1770 |
+
}
|
| 1771 |
+
|
| 1772 |
+
|
| 1773 |
+
# Save the current parameter definitions.
|
| 1774 |
+
# Optionally specify a label to associate with the saved parameters.
|
| 1775 |
+
sub saveParameters
|
| 1776 |
+
{
|
| 1777 |
+
my $model = shift @_;
|
| 1778 |
+
my $label = @_ ? shift @_ : Cache::DEFAULT_LABEL;
|
| 1779 |
+
|
| 1780 |
+
return '' if $NO_EXEC;
|
| 1781 |
+
|
| 1782 |
+
# copy paramList (exclude non-constant types)
|
| 1783 |
+
my $paramlist = $model->ParamList->copyConstant();
|
| 1784 |
+
|
| 1785 |
+
# put saved concentration into cache
|
| 1786 |
+
$model->ParameterCache->cache($paramlist,$label);
|
| 1787 |
+
# Send message to user
|
| 1788 |
+
printf "Saved current parameters with label '%s'\n", $label;
|
| 1789 |
+
return undef;
|
| 1790 |
+
}
|
| 1791 |
+
|
| 1792 |
+
|
| 1793 |
+
# Reset parameters to saved defintions.
|
| 1794 |
+
# Optionally specify a label used to find the saved parameters
|
| 1795 |
+
sub resetParameters
|
| 1796 |
+
{
|
| 1797 |
+
my $model = shift @_;
|
| 1798 |
+
my $label = @_ ? shift @_ : Cache::DEFAULT_LABEL;
|
| 1799 |
+
|
| 1800 |
+
return '' if $NO_EXEC;
|
| 1801 |
+
|
| 1802 |
+
# get a COPY so that subsequent 'setParameter' calls don't modify the saved list
|
| 1803 |
+
my $saved_paramlist = $model->ParameterCache->browse($label)->copyConstant();
|
| 1804 |
+
|
| 1805 |
+
unless (defined $saved_paramlist)
|
| 1806 |
+
{ return "resetParameters(): cannot find saved parameters"; }
|
| 1807 |
+
|
| 1808 |
+
unless (ref $saved_paramlist eq 'ParamList')
|
| 1809 |
+
{ return "resetParameters(): problem retrieving saved parameters"; }
|
| 1810 |
+
|
| 1811 |
+
# copy saved parameters into main ParamList
|
| 1812 |
+
my $err;
|
| 1813 |
+
foreach my $param ( @{$saved_paramlist->Array} )
|
| 1814 |
+
{
|
| 1815 |
+
$err = $model->ParamList->add( $param );
|
| 1816 |
+
if ($err) { return "resetParameters(): problem resetting parameters ($err)"; }
|
| 1817 |
+
}
|
| 1818 |
+
|
| 1819 |
+
# Set flag to update netfile when it's used
|
| 1820 |
+
$model->UpdateNet(1);
|
| 1821 |
+
|
| 1822 |
+
# Send message to user
|
| 1823 |
+
printf "Reloaded parameters saved with label '%s'\n", $label;
|
| 1824 |
+
# all done
|
| 1825 |
+
return undef;
|
| 1826 |
+
}
|
| 1827 |
+
|
| 1828 |
+
|
| 1829 |
+
|
| 1830 |
+
###
|
| 1831 |
+
###
|
| 1832 |
+
###
|
| 1833 |
+
|
| 1834 |
+
|
| 1835 |
+
|
| 1836 |
+
# Set the concentration of a species to specified value.
|
| 1837 |
+
# Value may be a number or a parameter.
|
| 1838 |
+
sub setConcentration
|
| 1839 |
+
{
|
| 1840 |
+
my $model = shift @_;
|
| 1841 |
+
my $sname = shift @_;
|
| 1842 |
+
my $value = shift @_;
|
| 1843 |
+
|
| 1844 |
+
return '' if $NO_EXEC;
|
| 1845 |
+
|
| 1846 |
+
my $plist = $model->ParamList;
|
| 1847 |
+
my $err;
|
| 1848 |
+
|
| 1849 |
+
# SpeciesGraph specified by $sname
|
| 1850 |
+
my $sg = SpeciesGraph->new;
|
| 1851 |
+
$err = $sg->readString( \$sname, $model->CompartmentList, 1, '', $model->MoleculeTypesList );
|
| 1852 |
+
if ($err) { return $err; }
|
| 1853 |
+
|
| 1854 |
+
# Should check that this SG specifies a complete species, otherwise
|
| 1855 |
+
# may match a number of species.
|
| 1856 |
+
|
| 1857 |
+
# Find matching species
|
| 1858 |
+
my $spec;
|
| 1859 |
+
unless ( $spec = $model->SpeciesList->lookup($sg) )
|
| 1860 |
+
{
|
| 1861 |
+
$err = sprintf "Species %s not found in SpeciesList", $sg->toString();
|
| 1862 |
+
return $err;
|
| 1863 |
+
}
|
| 1864 |
+
|
| 1865 |
+
# Read expression
|
| 1866 |
+
my $expr = Expression->new();
|
| 1867 |
+
my $estring = $value;
|
| 1868 |
+
if ( my $err = $expr->readString( \$estring, $plist ) ){
|
| 1869 |
+
return '', $err;
|
| 1870 |
+
}
|
| 1871 |
+
|
| 1872 |
+
# Evaluate observable and function names to values and reset
|
| 1873 |
+
# the expression. Don't do this for parameters so that parameter
|
| 1874 |
+
# scans can be run.
|
| 1875 |
+
my $estring2 = $value;
|
| 1876 |
+
my $variables = $expr->getVariables($plist);
|
| 1877 |
+
foreach my $var ($variables->{'Observable'}){ # Observables
|
| 1878 |
+
foreach my $name (keys %{$var}){
|
| 1879 |
+
my $val = $plist->evaluate($name);
|
| 1880 |
+
$estring2 =~ (s/$name/$val/g);
|
| 1881 |
+
}
|
| 1882 |
+
}
|
| 1883 |
+
foreach my $var ($variables->{'Function'}){ # Functions
|
| 1884 |
+
foreach my $name (keys %{$var}){
|
| 1885 |
+
my $val = $plist->evaluate($name);
|
| 1886 |
+
$estring2 =~ (s/$name(\(\))?/$val/g);
|
| 1887 |
+
}
|
| 1888 |
+
}
|
| 1889 |
+
if ( my $err = $expr->readString( \$estring2, $plist ) ){
|
| 1890 |
+
return '', $err;
|
| 1891 |
+
}
|
| 1892 |
+
|
| 1893 |
+
# Either evaluate expression or create a new one with prefix 'NewConc'
|
| 1894 |
+
my $conc; # = $expr->evaluate($plist);
|
| 1895 |
+
if ( $expr->Type eq 'NUM' ){
|
| 1896 |
+
$conc = $expr->evaluate();
|
| 1897 |
+
}
|
| 1898 |
+
else{
|
| 1899 |
+
$conc = $expr->getName( $plist, 'NewConc' );
|
| 1900 |
+
}
|
| 1901 |
+
|
| 1902 |
+
# load Concentration array (if not already done)
|
| 1903 |
+
$model->SpeciesList->checkOrInitConcentrations( $model->Concentrations );
|
| 1904 |
+
|
| 1905 |
+
# set concentration
|
| 1906 |
+
$model->Concentrations->[$spec->Index - 1] = $conc;
|
| 1907 |
+
|
| 1908 |
+
# Set flag to update netfile when it's used
|
| 1909 |
+
$model->UpdateNet(1);
|
| 1910 |
+
|
| 1911 |
+
printf "Set concentration of species %s to value %s\n", $spec->SpeciesGraph->StringExact,
|
| 1912 |
+
($expr->Type eq 'NUM' ? $conc : $expr->toString());
|
| 1913 |
+
return undef;
|
| 1914 |
+
}
|
| 1915 |
+
|
| 1916 |
+
|
| 1917 |
+
# Add concentration to a species.
|
| 1918 |
+
# Value may be a number or a parameter.
|
| 1919 |
+
sub addConcentration
|
| 1920 |
+
{
|
| 1921 |
+
my $model = shift @_;
|
| 1922 |
+
my $sname = shift @_;
|
| 1923 |
+
my $value = shift @_;
|
| 1924 |
+
|
| 1925 |
+
return '' if $NO_EXEC;
|
| 1926 |
+
|
| 1927 |
+
my $plist = $model->ParamList;
|
| 1928 |
+
my $err;
|
| 1929 |
+
|
| 1930 |
+
# SpeciesGraph specified by $sname
|
| 1931 |
+
my $sg = SpeciesGraph->new;
|
| 1932 |
+
$err = $sg->readString( \$sname, $model->CompartmentList, 1, '', $model->MoleculeTypesList );
|
| 1933 |
+
if ($err) { return $err; }
|
| 1934 |
+
|
| 1935 |
+
# Should check that this SG specifies a complete species, otherwise
|
| 1936 |
+
# may match a number of species.
|
| 1937 |
+
|
| 1938 |
+
# Find matching species
|
| 1939 |
+
my $spec;
|
| 1940 |
+
unless ( $spec = $model->SpeciesList->lookup($sg) )
|
| 1941 |
+
{
|
| 1942 |
+
$err = sprintf "Species %s not found in SpeciesList", $sg->toString();
|
| 1943 |
+
return $err;
|
| 1944 |
+
}
|
| 1945 |
+
|
| 1946 |
+
# Read expression
|
| 1947 |
+
my $expr = Expression->new();
|
| 1948 |
+
my $estring = $value;
|
| 1949 |
+
if ( my $err = $expr->readString( \$estring, $plist ) )
|
| 1950 |
+
{
|
| 1951 |
+
return ( '', $err );
|
| 1952 |
+
}
|
| 1953 |
+
my $add_conc = $expr->evaluate($plist);
|
| 1954 |
+
|
| 1955 |
+
# load Concentration array (if not already done)
|
| 1956 |
+
$model->SpeciesList->checkOrInitConcentrations( $model->Concentrations );
|
| 1957 |
+
|
| 1958 |
+
# Add original concentration
|
| 1959 |
+
my $orig_conc = $model->Concentrations->[$spec->Index - 1];
|
| 1960 |
+
unless ( isReal($orig_conc) )
|
| 1961 |
+
{ # evaluate parameter
|
| 1962 |
+
$orig_conc = $plist->evaluate($spec->Concentration);
|
| 1963 |
+
}
|
| 1964 |
+
my $conc = $add_conc + $orig_conc;
|
| 1965 |
+
|
| 1966 |
+
# set new concentration
|
| 1967 |
+
$model->Concentrations->[$spec->Index - 1] = $conc;
|
| 1968 |
+
|
| 1969 |
+
# Set flag to update netfile when it's used
|
| 1970 |
+
$model->UpdateNet(1);
|
| 1971 |
+
|
| 1972 |
+
printf "Add %s counts (or concentration units) to species %s for total of %s\n",
|
| 1973 |
+
$add_conc, $spec->SpeciesGraph->StringExact, $conc;
|
| 1974 |
+
return undef;
|
| 1975 |
+
}
|
| 1976 |
+
|
| 1977 |
+
|
| 1978 |
+
# Save the current species concentrations.
|
| 1979 |
+
# Optionally specify a label to associate with the saved state.
|
| 1980 |
+
sub saveConcentrations
|
| 1981 |
+
{
|
| 1982 |
+
my $model = shift @_;
|
| 1983 |
+
my $label = @_ ? shift @_ : Cache::DEFAULT_LABEL;
|
| 1984 |
+
|
| 1985 |
+
return '' if $NO_EXEC;
|
| 1986 |
+
|
| 1987 |
+
# create new concentration array
|
| 1988 |
+
my $conc = [];
|
| 1989 |
+
if (@{$model->Concentrations})
|
| 1990 |
+
{ # copy concentration from primary concentration array
|
| 1991 |
+
@$conc = @{$model->Concentrations};
|
| 1992 |
+
}
|
| 1993 |
+
else
|
| 1994 |
+
{ # if that's not defined, copy directly from SpeciesList
|
| 1995 |
+
@$conc = map {$_->Concentration} @{$model->SpeciesList->Array};
|
| 1996 |
+
}
|
| 1997 |
+
# put saved concentration into cache
|
| 1998 |
+
$model->ConcentrationCache->cache($conc,$label);
|
| 1999 |
+
print "Saved current species concentrations with label \"$label\"\n";
|
| 2000 |
+
return undef;
|
| 2001 |
+
}
|
| 2002 |
+
|
| 2003 |
+
|
| 2004 |
+
# Reset species concentrations to saved values.
|
| 2005 |
+
# Optionally specify a label used to find the saved concentrations
|
| 2006 |
+
sub resetConcentrations
|
| 2007 |
+
{
|
| 2008 |
+
my $model = shift @_;
|
| 2009 |
+
my $label = @_ ? shift @_ : Cache::DEFAULT_LABEL;
|
| 2010 |
+
|
| 2011 |
+
return '' if $NO_EXEC;
|
| 2012 |
+
|
| 2013 |
+
# lookup up concentrations in the cashe
|
| 2014 |
+
my $saved_conc = $model->ConcentrationCache->browse($label);
|
| 2015 |
+
|
| 2016 |
+
my $conc;
|
| 2017 |
+
if ( (defined $saved_conc) and (ref $saved_conc eq 'ARRAY') )
|
| 2018 |
+
{ # get a copy of the values (don't want to mess with originals)
|
| 2019 |
+
@$conc = @$saved_conc;
|
| 2020 |
+
}
|
| 2021 |
+
elsif ( !(defined $saved_conc) )
|
| 2022 |
+
{ # didn't find anything in the cache ...
|
| 2023 |
+
if ( $label eq Cache::DEFAULT_LABEL )
|
| 2024 |
+
{ # if we were looking for default values, get them directly from the species objects ...
|
| 2025 |
+
@$conc = map {$_->Concentration} @{$model->SpeciesList->Array};
|
| 2026 |
+
}
|
| 2027 |
+
else
|
| 2028 |
+
{ # otherwise return an error
|
| 2029 |
+
return "resetConcentrations(): cannot find saved concentrations with label \"$label\"";
|
| 2030 |
+
}
|
| 2031 |
+
}
|
| 2032 |
+
else
|
| 2033 |
+
{ # cache returned unexpected reference type
|
| 2034 |
+
return "resetConcentrations(): some problem retrieving saved concentrations";
|
| 2035 |
+
}
|
| 2036 |
+
|
| 2037 |
+
if ( @$conc > @{$model->SpeciesList->Array} )
|
| 2038 |
+
{ # this case is not well-defined
|
| 2039 |
+
return "resetConcentrations(): length of concentration vector is larger than the number of species";
|
| 2040 |
+
}
|
| 2041 |
+
elsif ( @$conc < @{$model->SpeciesList->Array} )
|
| 2042 |
+
{ # pad with zeros
|
| 2043 |
+
my $n_zeros = @{$model->SpeciesList->Array} - @$conc;
|
| 2044 |
+
push @$conc, (0) x $n_zeros;
|
| 2045 |
+
}
|
| 2046 |
+
|
| 2047 |
+
# finally, set concentrations to the saved values
|
| 2048 |
+
$model->Concentrations($conc);
|
| 2049 |
+
# Set flag to update netfile when it's used
|
| 2050 |
+
$model->UpdateNet(1);
|
| 2051 |
+
# all done
|
| 2052 |
+
print "Reset species concentrations to \"$label\" saved values.\n";
|
| 2053 |
+
return undef;
|
| 2054 |
+
}
|
| 2055 |
+
|
| 2056 |
+
|
| 2057 |
+
|
| 2058 |
+
###
|
| 2059 |
+
###
|
| 2060 |
+
###
|
| 2061 |
+
|
| 2062 |
+
|
| 2063 |
+
|
| 2064 |
+
sub setModelName
|
| 2065 |
+
{
|
| 2066 |
+
my $model = shift @_;
|
| 2067 |
+
my $name = shift @_;
|
| 2068 |
+
|
| 2069 |
+
$model->Name($name);
|
| 2070 |
+
return '';
|
| 2071 |
+
}
|
| 2072 |
+
|
| 2073 |
+
|
| 2074 |
+
###
|
| 2075 |
+
###
|
| 2076 |
+
###
|
| 2077 |
+
|
| 2078 |
+
|
| 2079 |
+
|
| 2080 |
+
# Function to require the version conform to specified requirement
|
| 2081 |
+
# Syntax: version(string);
|
| 2082 |
+
# string = major[.minor][.dist][+-][codename]
|
| 2083 |
+
#
|
| 2084 |
+
# major, minor, and dist. indicate the major, minor, and distribution number
|
| 2085 |
+
# respectively against which the BioNetGen version numbers will be compared.
|
| 2086 |
+
# + indicates version should be the specified version or later (default)
|
| 2087 |
+
# - indicates version should be the specified version or earlier
|
| 2088 |
+
sub version
|
| 2089 |
+
{
|
| 2090 |
+
my $model = shift @_;
|
| 2091 |
+
my $vstring = shift @_;
|
| 2092 |
+
|
| 2093 |
+
return '' if $NO_EXEC;
|
| 2094 |
+
|
| 2095 |
+
if (@_)
|
| 2096 |
+
{ # complain about too many arguments
|
| 2097 |
+
return "Version called with too many arguments.";
|
| 2098 |
+
}
|
| 2099 |
+
|
| 2100 |
+
# extract version and codename
|
| 2101 |
+
my ($version, $relation, $codename) = ( $vstring =~ /^(\d+\.\d+\.\d+)([+-]?)\s*(\w*)/ );
|
| 2102 |
+
|
| 2103 |
+
unless ( defined $version )
|
| 2104 |
+
{ # complain that version is invalid
|
| 2105 |
+
return "version argument '$vstring' has invalid format (make sure argument is enclosed in double quotes \"\").";
|
| 2106 |
+
}
|
| 2107 |
+
|
| 2108 |
+
if ( $relation eq "" )
|
| 2109 |
+
{ # default relation is "+"
|
| 2110 |
+
$relation = "+";
|
| 2111 |
+
}
|
| 2112 |
+
|
| 2113 |
+
my $bng_version = BNGversion();
|
| 2114 |
+
if ( $bng_version eq 'UNKNOWN' )
|
| 2115 |
+
{ # complain that BNG version is unknown
|
| 2116 |
+
return "BNG version is UNKNOWN!";
|
| 2117 |
+
}
|
| 2118 |
+
|
| 2119 |
+
# compare versions (returns -1 if version < bng_version)
|
| 2120 |
+
my $comp = compareVersions($version,$bng_version);
|
| 2121 |
+
|
| 2122 |
+
# is active BNG version suitable?
|
| 2123 |
+
if ( $relation eq '+' and $comp == 1 )
|
| 2124 |
+
{ # BNG version is less than minimum required!
|
| 2125 |
+
return "Requested BioNetGen version $version or greater. Active version is $bng_version.";
|
| 2126 |
+
}
|
| 2127 |
+
elsif ( $relation eq '-' and $comp == -1 )
|
| 2128 |
+
{ # BNG version is greater than maximum allowed!
|
| 2129 |
+
return "Requested BioNetGen version $version or lesser. Active version is $bng_version.";
|
| 2130 |
+
}
|
| 2131 |
+
|
| 2132 |
+
# check codename
|
| 2133 |
+
unless ($codename eq "")
|
| 2134 |
+
{
|
| 2135 |
+
my $bng_codename = BNGcodename();
|
| 2136 |
+
unless ( $codename eq $bng_codename )
|
| 2137 |
+
{
|
| 2138 |
+
return "Requested BioNetGen codename '${codename}'. Active codename is '${bng_codename}'.";
|
| 2139 |
+
}
|
| 2140 |
+
}
|
| 2141 |
+
|
| 2142 |
+
# Set version requirement
|
| 2143 |
+
$model->Version( $vstring );
|
| 2144 |
+
|
| 2145 |
+
# everything is good
|
| 2146 |
+
return undef;
|
| 2147 |
+
}
|
| 2148 |
+
|
| 2149 |
+
sub codename
|
| 2150 |
+
{
|
| 2151 |
+
my $model = shift @_;
|
| 2152 |
+
my $codename = shift @_;
|
| 2153 |
+
|
| 2154 |
+
return '' if $NO_EXEC;
|
| 2155 |
+
|
| 2156 |
+
if (@_)
|
| 2157 |
+
{ # complain about too many arguments
|
| 2158 |
+
return "Codename called with too many arguments.";
|
| 2159 |
+
}
|
| 2160 |
+
|
| 2161 |
+
unless ( $codename )
|
| 2162 |
+
{ # complaiin about empty codename
|
| 2163 |
+
return "codename argument is empty.";
|
| 2164 |
+
}
|
| 2165 |
+
|
| 2166 |
+
# get BNG codename
|
| 2167 |
+
my $bng_codename = BNGcodename();
|
| 2168 |
+
if ( $bng_codename eq 'UNKNOWN' )
|
| 2169 |
+
{ # complain that BNG codename is unknown
|
| 2170 |
+
return "BNG version is UNKNOWN!";
|
| 2171 |
+
}
|
| 2172 |
+
|
| 2173 |
+
# compare codename
|
| 2174 |
+
unless ($codename eq $bng_codename)
|
| 2175 |
+
{ # BNG codename is not correct
|
| 2176 |
+
return "Requested BioNetGen codename $codename. Active version is $bng_codename.";
|
| 2177 |
+
}
|
| 2178 |
+
|
| 2179 |
+
# Add current version requirement to the model
|
| 2180 |
+
push @{$model->Codename}, $codename;
|
| 2181 |
+
|
| 2182 |
+
# everything is good
|
| 2183 |
+
return undef;
|
| 2184 |
+
}
|
| 2185 |
+
|
| 2186 |
+
|
| 2187 |
+
###
|
| 2188 |
+
###
|
| 2189 |
+
###
|
| 2190 |
+
|
| 2191 |
+
|
| 2192 |
+
|
| 2193 |
+
sub quit
|
| 2194 |
+
{
|
| 2195 |
+
# quick exit. no cleanup. no error messages
|
| 2196 |
+
# This is useful when the user desires to exit before
|
| 2197 |
+
# performing a set of actions and it would be tedious to
|
| 2198 |
+
# comment out all those actions.
|
| 2199 |
+
print "quitting BioNetGen!\n";
|
| 2200 |
+
exit(0);
|
| 2201 |
+
}
|
| 2202 |
+
|
| 2203 |
+
|
| 2204 |
+
|
| 2205 |
+
###
|
| 2206 |
+
###
|
| 2207 |
+
###
|
| 2208 |
+
|
| 2209 |
+
|
| 2210 |
+
|
| 2211 |
+
# Add equilibrate option, which uses additional parameters
|
| 2212 |
+
# t_equil and spec_nonequil. If spec_nonequil is set, these
|
| 2213 |
+
# species are not used in equilibration of the network and are only
|
| 2214 |
+
# added after equilibration is performed. Network generation should
|
| 2215 |
+
# re-commence after equilibration is performed if spec_nonequil has
|
| 2216 |
+
# been set.
|
| 2217 |
+
|
| 2218 |
+
sub generate_network
|
| 2219 |
+
{
|
| 2220 |
+
my $model = shift @_;
|
| 2221 |
+
my $user_params = @_ ? shift @_ : {};
|
| 2222 |
+
|
| 2223 |
+
printf "ACTION: generate_network( %s )\n", $model->Name;
|
| 2224 |
+
|
| 2225 |
+
# default params
|
| 2226 |
+
my %params = (
|
| 2227 |
+
'continue' => 1,
|
| 2228 |
+
'max_iter' => 100,
|
| 2229 |
+
'max_agg' => 1e9,
|
| 2230 |
+
'max_stoich' => {},
|
| 2231 |
+
'check_iso' => 1,
|
| 2232 |
+
'prefix' => $model->getOutputPrefix(),
|
| 2233 |
+
'suffix' => undef,
|
| 2234 |
+
'overwrite' => 0,
|
| 2235 |
+
'print_iter' => 0,
|
| 2236 |
+
'TextSpecies' => 1,
|
| 2237 |
+
'TextReaction' => 0,
|
| 2238 |
+
'verbose' => 0,
|
| 2239 |
+
'write' => 1
|
| 2240 |
+
);
|
| 2241 |
+
|
| 2242 |
+
# overwrite default params with user params
|
| 2243 |
+
foreach my $key (keys %$user_params)
|
| 2244 |
+
{
|
| 2245 |
+
my $val = $user_params->{$key};
|
| 2246 |
+
unless ( exists $params{$key} )
|
| 2247 |
+
{ return "Unrecognized parameter $key in generate_network"; }
|
| 2248 |
+
|
| 2249 |
+
$params{$key} = $val;
|
| 2250 |
+
}
|
| 2251 |
+
|
| 2252 |
+
return '' if $NO_EXEC;
|
| 2253 |
+
|
| 2254 |
+
# Output prefix
|
| 2255 |
+
if (defined $user_params->{prefix}){
|
| 2256 |
+
$params{prefix} = $model->getOutputPrefix($user_params->{prefix});
|
| 2257 |
+
}
|
| 2258 |
+
|
| 2259 |
+
# add optional suffix to output prefix
|
| 2260 |
+
if ( $params{suffix} )
|
| 2261 |
+
{ $params{prefix} .= "_" . $params{suffix}; }
|
| 2262 |
+
|
| 2263 |
+
# default params for calling writeNetwork
|
| 2264 |
+
# (only need to change if we want non-default)
|
| 2265 |
+
my $params_writeNetwork = {
|
| 2266 |
+
'include_model' => 0,
|
| 2267 |
+
'overwrite' => 1,
|
| 2268 |
+
'prefix' => $params{prefix},
|
| 2269 |
+
'TextSpecies' => $params{TextSpecies},
|
| 2270 |
+
'TextReaction' => $params{TextReaction}
|
| 2271 |
+
};
|
| 2272 |
+
|
| 2273 |
+
# default params for calling expand_rule
|
| 2274 |
+
my $params_expand_rule = {
|
| 2275 |
+
'check_iso' => $params{check_iso},
|
| 2276 |
+
'max_agg' => $params{max_agg},
|
| 2277 |
+
'max_stoich' => $params{max_stoich},
|
| 2278 |
+
'verbose' => $params{verbose},
|
| 2279 |
+
};
|
| 2280 |
+
|
| 2281 |
+
# make sure 'max_stoich' molecules are valid names
|
| 2282 |
+
foreach my $mol ( keys %{$params{'max_stoich'}} ){
|
| 2283 |
+
if ( not $mol =~ /^[A-Za-z_]\w*$/ ){
|
| 2284 |
+
return "Error in max_stoich: '$mol' is not a valid molecule name.";
|
| 2285 |
+
}
|
| 2286 |
+
}
|
| 2287 |
+
|
| 2288 |
+
# check verbose option
|
| 2289 |
+
my $verbose = $params{verbose};
|
| 2290 |
+
|
| 2291 |
+
# Check if existing net file has been created since last modification time of .bngl file
|
| 2292 |
+
my $prefix = $params{prefix};
|
| 2293 |
+
if ( -e "$prefix.net" and -e "$prefix.bngl" )
|
| 2294 |
+
{
|
| 2295 |
+
if ($params{overwrite})
|
| 2296 |
+
{
|
| 2297 |
+
send_warning("Removing old network file $prefix.net.");
|
| 2298 |
+
unlink "$prefix.net";
|
| 2299 |
+
}
|
| 2300 |
+
elsif ( -M "$prefix.net" < -M "$prefix.bngl" )
|
| 2301 |
+
{
|
| 2302 |
+
send_warning("$prefix.net is newer than $prefix.bngl so reading NET file.");
|
| 2303 |
+
my $err = $model->readFile({file=>"${prefix}.net"});
|
| 2304 |
+
return $err;
|
| 2305 |
+
}
|
| 2306 |
+
else
|
| 2307 |
+
{
|
| 2308 |
+
return "Previously generated $prefix.net exists. Set overwrite=>1 option to overwrite.";
|
| 2309 |
+
}
|
| 2310 |
+
}
|
| 2311 |
+
|
| 2312 |
+
if ( $model->SpeciesList->size() == 0 )
|
| 2313 |
+
{ # warn user if the seed species list is empty.
|
| 2314 |
+
send_warning("The seed species block is empty: reaction network will be empty "
|
| 2315 |
+
."unless zero-order synthesis rules are defined.");
|
| 2316 |
+
}
|
| 2317 |
+
|
| 2318 |
+
# nothing to do if no rules are defined
|
| 2319 |
+
if ( @{$model->RxnRules} == 0 )
|
| 2320 |
+
{ return "Nothing to do: no reaction rules defined."; }
|
| 2321 |
+
|
| 2322 |
+
# if no reactions have been generated previously, then we have to initialize some things...
|
| 2323 |
+
if ( $model->RxnList->size()==0 or $params{'continue'}==0 )
|
| 2324 |
+
{
|
| 2325 |
+
# initialize rules
|
| 2326 |
+
foreach my $rset ( @{$model->RxnRules} )
|
| 2327 |
+
{
|
| 2328 |
+
foreach my $rr (@$rset)
|
| 2329 |
+
{ $rr->initializeRule(); }
|
| 2330 |
+
}
|
| 2331 |
+
# Initialize observables
|
| 2332 |
+
foreach my $obs ( @{$model->Observables} )
|
| 2333 |
+
{
|
| 2334 |
+
$obs->reset_weights( $model->SpeciesList->size() );
|
| 2335 |
+
$obs->update( $model->SpeciesList->Array );
|
| 2336 |
+
}
|
| 2337 |
+
# Initialize energy patterns (for energy BNG only)
|
| 2338 |
+
foreach my $epatt ( @{$model->EnergyPatterns} )
|
| 2339 |
+
{
|
| 2340 |
+
$epatt->reset_weights($model->SpeciesList->size());
|
| 2341 |
+
$epatt->update($model->SpeciesList->Array);
|
| 2342 |
+
}
|
| 2343 |
+
# remember that we applied the observables
|
| 2344 |
+
foreach my $sp ( @{$model->SpeciesList->Array} )
|
| 2345 |
+
{ $sp->ObservablesApplied(1); }
|
| 2346 |
+
}
|
| 2347 |
+
else
|
| 2348 |
+
{ # friendly warning that we're continuing network generation
|
| 2349 |
+
send_warning("Reaction list is already populated. Continuing network generation from where we last left off.");
|
| 2350 |
+
}
|
| 2351 |
+
|
| 2352 |
+
|
| 2353 |
+
my @rule_timing = ();
|
| 2354 |
+
my @rule_nrxn = ();
|
| 2355 |
+
|
| 2356 |
+
# update user with initial report
|
| 2357 |
+
report_iter( 0, $model->SpeciesList->size(), $model->RxnList->size() );
|
| 2358 |
+
|
| 2359 |
+
# now perform network generation steps
|
| 2360 |
+
foreach my $niter ( 1 .. $params{max_iter} )
|
| 2361 |
+
{
|
| 2362 |
+
my $t_start_iter = cpu_time(0);
|
| 2363 |
+
my @species = @{$model->SpeciesList->Array};
|
| 2364 |
+
|
| 2365 |
+
# Apply reaction rules
|
| 2366 |
+
my $irule = 0;
|
| 2367 |
+
my ($n_new, $t_off, $n_new_tot);
|
| 2368 |
+
$n_new_tot = 0;
|
| 2369 |
+
# NOTE: each element of @{$model->RxnRules} is an array of reactions.
|
| 2370 |
+
# If a rule is unidirectional, then the array has a single element.
|
| 2371 |
+
# If a rule is bidirectional, then the array has two elements (forward and reverse)
|
| 2372 |
+
foreach my $rset ( @{$model->RxnRules} )
|
| 2373 |
+
{
|
| 2374 |
+
if ($verbose) { printf "Rule %d:\n", $irule + 1; }
|
| 2375 |
+
$n_new = 0;
|
| 2376 |
+
$t_off = cpu_time(0);
|
| 2377 |
+
my $dir = 0;
|
| 2378 |
+
foreach my $rr (@$rset)
|
| 2379 |
+
{
|
| 2380 |
+
if ($verbose)
|
| 2381 |
+
{
|
| 2382 |
+
if ($dir == 0) { print " forward:\n"; }
|
| 2383 |
+
else { print " reverse:\n"; }
|
| 2384 |
+
}
|
| 2385 |
+
# expand rule
|
| 2386 |
+
my ($err, $nr) = $rr->expand_rule( \@species, $model, $params_expand_rule );
|
| 2387 |
+
if (defined $err) { return "Some problem expanding rule: $err"; }
|
| 2388 |
+
$n_new += $nr;
|
| 2389 |
+
++$dir;
|
| 2390 |
+
}
|
| 2391 |
+
|
| 2392 |
+
my $time = cpu_time(0) - $t_off;
|
| 2393 |
+
$rule_timing[$irule] += $time;
|
| 2394 |
+
$rule_nrxn[$irule] += $n_new;
|
| 2395 |
+
|
| 2396 |
+
if ($verbose)
|
| 2397 |
+
{ printf "Result: %5d new reactions %.2e CPU s\n", $n_new, $time; }
|
| 2398 |
+
|
| 2399 |
+
$n_new_tot += $n_new;
|
| 2400 |
+
++$irule;
|
| 2401 |
+
}
|
| 2402 |
+
|
| 2403 |
+
# update RulesApplied for species processed in this interation
|
| 2404 |
+
foreach my $spec (@species)
|
| 2405 |
+
{ $spec->RulesApplied($niter) unless ($spec->RulesApplied); }
|
| 2406 |
+
|
| 2407 |
+
# report iteration to user
|
| 2408 |
+
report_iter( $niter, $model->SpeciesList->size(), $model->RxnList->size(), $t_start_iter );
|
| 2409 |
+
|
| 2410 |
+
# Free memory associated with RxnList hash
|
| 2411 |
+
$model->RxnList->resetHash();
|
| 2412 |
+
|
| 2413 |
+
# Stop iteration if no new species were generated
|
| 2414 |
+
last if ( $model->SpeciesList->size() == scalar @species );
|
| 2415 |
+
|
| 2416 |
+
# Print network after current iteration to netfile
|
| 2417 |
+
if ( $params{print_iter} and $params{write} )
|
| 2418 |
+
{
|
| 2419 |
+
$params_writeNetwork->{prefix} = "${prefix}_${niter}";
|
| 2420 |
+
my $err = $model->writeNetwork($params_writeNetwork);
|
| 2421 |
+
if ($err) { return $err; }
|
| 2422 |
+
$params_writeNetwork->{prefix} = $prefix;
|
| 2423 |
+
}
|
| 2424 |
+
}
|
| 2425 |
+
|
| 2426 |
+
|
| 2427 |
+
# Print rule timing information
|
| 2428 |
+
printf "Cumulative CPU time for each rule\n";
|
| 2429 |
+
my $t_tot = 0;
|
| 2430 |
+
my $n_tot = 0;
|
| 2431 |
+
foreach my $irule ( 0 .. $#{$model->RxnRules} )
|
| 2432 |
+
{
|
| 2433 |
+
my $eff = ( $rule_nrxn[$irule] ) ? $rule_timing[$irule] / $rule_nrxn[$irule] : 0.0;
|
| 2434 |
+
printf "Rule %3d: %5d reactions %.2e CPU s %.2e CPU s/rxn\n",
|
| 2435 |
+
$irule + 1, $rule_nrxn[$irule], $rule_timing[$irule], $eff;
|
| 2436 |
+
$t_tot += $rule_timing[$irule];
|
| 2437 |
+
$n_tot += $rule_nrxn[$irule];
|
| 2438 |
+
}
|
| 2439 |
+
my $eff = ($n_tot) ? $t_tot / $n_tot : 0.0;
|
| 2440 |
+
printf "Total : %5d reactions %.2e CPU s %.2e CPU s/rxn\n", $n_tot, $t_tot, $eff;
|
| 2441 |
+
|
| 2442 |
+
|
| 2443 |
+
# this is used in visualization, where a network is generated, but not written.
|
| 2444 |
+
return if ($params{write}==0);
|
| 2445 |
+
|
| 2446 |
+
# Print result to netfile
|
| 2447 |
+
my $err = $model->writeNetwork($params_writeNetwork);
|
| 2448 |
+
if ($err) { return $err; }
|
| 2449 |
+
|
| 2450 |
+
# STATISTICAL FACTOR FOR REACTIONS- DEBUGGING
|
| 2451 |
+
# OUTPUTS A FILE FOR EACH RULE
|
| 2452 |
+
# SHOWING REACTION INSTANCES AND LUMPING
|
| 2453 |
+
# DURING generate_network()
|
| 2454 |
+
# NAME YOUR RULES FIRST!
|
| 2455 |
+
# - JOHN SEKAR
|
| 2456 |
+
|
| 2457 |
+
my $aut = $BNGModel::GLOBAL_MODEL->Params->{'write_autos'};
|
| 2458 |
+
if($aut==1)
|
| 2459 |
+
{
|
| 2460 |
+
foreach my $rxn(@{$model->RxnList->Array})
|
| 2461 |
+
{
|
| 2462 |
+
my $str = $rxn->toString(1);
|
| 2463 |
+
my %inst = %{$rxn->InstanceHash};
|
| 2464 |
+
my @k = keys %inst;
|
| 2465 |
+
foreach my $rule(@k)
|
| 2466 |
+
{
|
| 2467 |
+
my $modelname = $BNGModel::GLOBAL_MODEL->Name;
|
| 2468 |
+
my $rulename = $rule;
|
| 2469 |
+
my $filename = join("_",($modelname,$rulename,"StatFactorCalculation")).".txt";
|
| 2470 |
+
open(my $autfile,">>",$filename) or die "Not found!";
|
| 2471 |
+
print $autfile "\nReaction\n".$str;
|
| 2472 |
+
print $autfile "\nLumpFactor ".$inst{$rule};
|
| 2473 |
+
print $autfile "\nReactionStatFactor: RuleStatFactor*LumpFactor = ".$rxn->StatFactor."\n";
|
| 2474 |
+
close($autfile);
|
| 2475 |
+
}
|
| 2476 |
+
}
|
| 2477 |
+
}
|
| 2478 |
+
|
| 2479 |
+
return '';
|
| 2480 |
+
|
| 2481 |
+
|
| 2482 |
+
###
|
| 2483 |
+
###
|
| 2484 |
+
|
| 2485 |
+
|
| 2486 |
+
sub report_iter
|
| 2487 |
+
{
|
| 2488 |
+
my $niter = shift @_;
|
| 2489 |
+
my $nspec = shift @_;
|
| 2490 |
+
my $nrxn = shift @_;
|
| 2491 |
+
my $t_start_iter = @_ ? shift @_ : undef;
|
| 2492 |
+
|
| 2493 |
+
printf "Iteration %3d: %5d species %6d rxns", $niter, $nspec, $nrxn;
|
| 2494 |
+
my $t_cpu = defined $t_start_iter ? cpu_time(0) - $t_start_iter : 0;
|
| 2495 |
+
printf " %.2e CPU s", $t_cpu;
|
| 2496 |
+
if ($HAVE_PS) {
|
| 2497 |
+
my ( $rhead, $vhead, $rmem, $vmem ) = split ' ', `ps -o rss,vsz -p $$`;
|
| 2498 |
+
printf " %.2e (%.2e) Mb real (virtual) memory.",
|
| 2499 |
+
$t_cpu, $rmem / 1000, $vmem / 1000;
|
| 2500 |
+
}
|
| 2501 |
+
printf "\n";
|
| 2502 |
+
}
|
| 2503 |
+
|
| 2504 |
+
}
|
| 2505 |
+
|
| 2506 |
+
|
| 2507 |
+
|
| 2508 |
+
###
|
| 2509 |
+
###
|
| 2510 |
+
###
|
| 2511 |
+
|
| 2512 |
+
|
| 2513 |
+
|
| 2514 |
+
# given a generic program name, returns the specific executable binary.
|
| 2515 |
+
# returns empty string if binary can't be found
|
| 2516 |
+
sub findExec
|
| 2517 |
+
{
|
| 2518 |
+
use Config;
|
| 2519 |
+
my $prog = shift @_;
|
| 2520 |
+
|
| 2521 |
+
my $base = BNGpath( "bin", $prog );
|
| 2522 |
+
my $arch = $Config{myarchname};
|
| 2523 |
+
|
| 2524 |
+
# First look for generic binary in BNGpath
|
| 2525 |
+
my $exec = $base;
|
| 2526 |
+
if ($arch =~ /MSWin32/) { $exec .= ".exe"; }
|
| 2527 |
+
if (-x $exec) { return $exec; }
|
| 2528 |
+
|
| 2529 |
+
# Then look for OS-specific binary
|
| 2530 |
+
$exec = "${base}_${arch}";
|
| 2531 |
+
if ($arch =~ /MSWin32/){
|
| 2532 |
+
my $bitness = $Config{longsize}*8;
|
| 2533 |
+
$exec .= "-${bitness}bit" . ".exe";
|
| 2534 |
+
}
|
| 2535 |
+
|
| 2536 |
+
if (-x $exec) { return $exec; }
|
| 2537 |
+
else
|
| 2538 |
+
{
|
| 2539 |
+
print "findExec: $exec not found.\n";
|
| 2540 |
+
return '';
|
| 2541 |
+
}
|
| 2542 |
+
}
|
| 2543 |
+
|
| 2544 |
+
|
| 2545 |
+
|
| 2546 |
+
###
|
| 2547 |
+
###
|
| 2548 |
+
###
|
| 2549 |
+
|
| 2550 |
+
|
| 2551 |
+
|
| 2552 |
+
# get output prefix = outputDir/modelName[_outputSuffix]
|
| 2553 |
+
sub getOutputPrefix
|
| 2554 |
+
{
|
| 2555 |
+
my $model = shift @_;
|
| 2556 |
+
my $file_prefix = @_ ? shift @_ : $model->Name;
|
| 2557 |
+
|
| 2558 |
+
my $is_absolute = File::Spec->file_name_is_absolute( $file_prefix );
|
| 2559 |
+
|
| 2560 |
+
if ( $model->Params->{suffix} )
|
| 2561 |
+
{ $file_prefix .= '_' . $model->Params->{output_suffix}; }
|
| 2562 |
+
|
| 2563 |
+
if ($is_absolute or $model->getOutputDir() eq "")
|
| 2564 |
+
{
|
| 2565 |
+
return $file_prefix;
|
| 2566 |
+
}
|
| 2567 |
+
else
|
| 2568 |
+
{
|
| 2569 |
+
return File::Spec->catfile( ($model->getOutputDir()), $file_prefix );
|
| 2570 |
+
}
|
| 2571 |
+
}
|
| 2572 |
+
|
| 2573 |
+
###
|
| 2574 |
+
###
|
| 2575 |
+
|
| 2576 |
+
# set the output directory, defaults to curdir if no argument is provided
|
| 2577 |
+
sub setOutputDir
|
| 2578 |
+
{
|
| 2579 |
+
my $model = shift @_;
|
| 2580 |
+
my $dir = @_ ? shift @_ : undef;
|
| 2581 |
+
|
| 2582 |
+
unless (defined $dir)
|
| 2583 |
+
{ # default to current directory
|
| 2584 |
+
$dir = File::Spec->curdir();
|
| 2585 |
+
}
|
| 2586 |
+
|
| 2587 |
+
# set output directory
|
| 2588 |
+
$model->Params->{output_dir} = $dir;
|
| 2589 |
+
}
|
| 2590 |
+
|
| 2591 |
+
###
|
| 2592 |
+
###
|
| 2593 |
+
|
| 2594 |
+
# get the output directory
|
| 2595 |
+
sub getOutputDir
|
| 2596 |
+
{
|
| 2597 |
+
my $model = shift @_;
|
| 2598 |
+
|
| 2599 |
+
unless ( defined $model->Params->{output_dir} )
|
| 2600 |
+
{ # output directory not defined, set to default
|
| 2601 |
+
$model->setOutputDir();
|
| 2602 |
+
}
|
| 2603 |
+
|
| 2604 |
+
return $model->Params->{output_dir};
|
| 2605 |
+
}
|
| 2606 |
+
|
| 2607 |
+
|
| 2608 |
+
|
| 2609 |
+
###
|
| 2610 |
+
###
|
| 2611 |
+
###
|
| 2612 |
+
|
| 2613 |
+
1;
|
| 2614 |
+
|
data/bionetgen/Perl2/BNGOptions.pm
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package BNGOptions;
|
| 2 |
+
use strict;
|
| 3 |
+
use warnings;
|
| 4 |
+
|
| 5 |
+
use Getopt::Long;
|
| 6 |
+
use Class::Struct;
|
| 7 |
+
|
| 8 |
+
use BNGMessages qw(error warning message);
|
| 9 |
+
|
| 10 |
+
struct BNGOptions => {
|
| 11 |
+
config=> '%',
|
| 12 |
+
nored=> '@',
|
| 13 |
+
};
|
| 14 |
+
|
| 15 |
+
#begin GetBNGOptions
|
| 16 |
+
sub GetBNGOptions
|
| 17 |
+
{
|
| 18 |
+
my $self = shift;
|
| 19 |
+
$self->config->{macro}=''; #default value (false) - enable macromodel
|
| 20 |
+
$self->config->{silent}=''; #default value (false) - disable all (my only) messages
|
| 21 |
+
$self->config->{debug}= 1; #default value (false) - enable debug mode (debug output files)
|
| 22 |
+
$self->config->{bnglfile}='';
|
| 23 |
+
$self->config->{filetype}='';
|
| 24 |
+
$self->config->{prefix}='';
|
| 25 |
+
$self->config->{ModelID}='';
|
| 26 |
+
$self->config->{MAX_LEVEL}=5; #sets maximum level of allowed recursion
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
GetOptions ('silent' => \$self->config->{silent},
|
| 30 |
+
'macro' => \$self->config->{macro},
|
| 31 |
+
'debug' => \$self->config->{debug},
|
| 32 |
+
'nored=s'=> \@{$self->nored});
|
| 33 |
+
|
| 34 |
+
if ($self->config->{macro})
|
| 35 |
+
{
|
| 36 |
+
$self->config->{ModelID}="BNGModels::MacroBNGModel";
|
| 37 |
+
}
|
| 38 |
+
else
|
| 39 |
+
{
|
| 40 |
+
$self->config->{ModelID}="BNGModels::MicroBNGModel";
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
local $SIG{'__DIE__'} = sub { };
|
| 44 |
+
local $SIG{'__WARN__'} = sub { };
|
| 45 |
+
eval 'use '.$self->config->{ModelID};
|
| 46 |
+
if ($@) {
|
| 47 |
+
@_ = split( "\n", $@ );
|
| 48 |
+
$_ = join( "\n\t", @_ );
|
| 49 |
+
error("Module $self->config->{ModelID} not loaded because: \n\t$_");
|
| 50 |
+
}
|
| 51 |
+
else
|
| 52 |
+
{
|
| 53 |
+
eval 'use '.$self->config->{ModelID};
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
for my $file(@ARGV)
|
| 57 |
+
{
|
| 58 |
+
error("File $file does not have required .bngl extension.") unless ( ($file=~ /[.]bngl/));
|
| 59 |
+
$self->config->{bnglfile}=$file;
|
| 60 |
+
$self->config->{prefix}=$file;
|
| 61 |
+
$self->config->{prefix}=~ s/[.]([^.]+)$//;
|
| 62 |
+
$self->config->{filetype}=uc("bngl");
|
| 63 |
+
}
|
| 64 |
+
}
|
| 65 |
+
#end GetBNGOptions
|
| 66 |
+
1;
|
data/bionetgen/Perl2/BNGOutput.pm
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
data/bionetgen/Perl2/BNGUtils.pm
ADDED
|
@@ -0,0 +1,599 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package BNGUtils;
|
| 2 |
+
# TODO use strict;
|
| 3 |
+
|
| 4 |
+
# Perl Modules
|
| 5 |
+
use FindBin;
|
| 6 |
+
use lib $FindBin::Bin;
|
| 7 |
+
use File::Spec;
|
| 8 |
+
use Cwd;
|
| 9 |
+
use List::Util ("sum");
|
| 10 |
+
|
| 11 |
+
use constant VERSION_FILENAME => "VERSION";
|
| 12 |
+
use constant DEFAULT_VERSION => "UNKNOWN";
|
| 13 |
+
use constant DEFAULT_CODENAME => "";
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
require Exporter;
|
| 17 |
+
our @ISA = qw( Exporter );
|
| 18 |
+
our @EXPORT = qw( BNGversion BNGcodename compareVersions isReal booleanToInt BNGroot BNGpath exit_error send_warning cpu_time average_runs create_sbml
|
| 19 |
+
head split_obj split_comp verify_pattern process_val_string
|
| 20 |
+
validate_rate_law MIN MAX SQR log10 );
|
| 21 |
+
|
| 22 |
+
# Jim Faeder 3/13/2005.
|
| 23 |
+
{
|
| 24 |
+
my $BNG_VERSION;
|
| 25 |
+
my $BNG_CODENAME;
|
| 26 |
+
my $BNG_ROOT;
|
| 27 |
+
|
| 28 |
+
# find the BNG root directory
|
| 29 |
+
sub BNGroot
|
| 30 |
+
{
|
| 31 |
+
unless ($BNG_ROOT)
|
| 32 |
+
{ # Determine BNG root directory
|
| 33 |
+
|
| 34 |
+
# Use environment variable BNGPATH, if defined and valid
|
| 35 |
+
if ( exists $ENV{BNGPATH} )
|
| 36 |
+
{
|
| 37 |
+
my $bin_dir = File::Spec->catdir( ($ENV{BNGPATH}) );
|
| 38 |
+
if ( -d $bin_dir )
|
| 39 |
+
{ $BNG_ROOT = $bin_dir; }
|
| 40 |
+
else
|
| 41 |
+
{ send_warning( "While looking for BNG root: environment variable 'BNGPATH' does not point to a valid directory!" ); }
|
| 42 |
+
}
|
| 43 |
+
# Use environment variable BioNetGenRoot, if defined and valid
|
| 44 |
+
elsif ( exists $ENV{BioNetGenRoot} )
|
| 45 |
+
{
|
| 46 |
+
my $bin_dir = File::Spec->catdir( ($ENV{BioNetGenRoot}) );
|
| 47 |
+
if ( -d $bin_dir )
|
| 48 |
+
{ $BNG_ROOT = $bin_dir; }
|
| 49 |
+
else
|
| 50 |
+
{ send_warning( "While looking for BNG root: environment variable 'BioNetGenRoot' does not point to a valid directory!" ); }
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
# Otherwise, try the same
|
| 55 |
+
unless ( defined $BNG_ROOT )
|
| 56 |
+
{
|
| 57 |
+
if (-d $FindBin::RealBin)
|
| 58 |
+
{ $BNG_ROOT = $FindBin::RealBin; }
|
| 59 |
+
else
|
| 60 |
+
{ send_warning( "While looking for BNG root: could not get RealBin directory!" ); }
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
# As last resort, try current working directory
|
| 64 |
+
unless ( defined $BNG_ROOT )
|
| 65 |
+
{
|
| 66 |
+
$BNG_ROOT = Cwd::getcwd();
|
| 67 |
+
send_warning( "While looking for BNG_ROOT: defaulting to current working directory!" );
|
| 68 |
+
}
|
| 69 |
+
}
|
| 70 |
+
return $BNG_ROOT;
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
sub BNGpath
|
| 74 |
+
{
|
| 75 |
+
unless ($BNG_ROOT)
|
| 76 |
+
{ # find BNG root directory
|
| 77 |
+
BNGroot();
|
| 78 |
+
}
|
| 79 |
+
return File::Spec->catdir( ($BNG_ROOT, @_) );
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
# extract BNG_VERSION and BNG_CODENAME from the version file located
|
| 83 |
+
# at BNG_ROOT/VERSION.
|
| 84 |
+
sub readVersionFile
|
| 85 |
+
{
|
| 86 |
+
unless ($BNG_ROOT)
|
| 87 |
+
{ # find BNG root directory
|
| 88 |
+
BNGroot();
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
# Get BioNetGen version number
|
| 92 |
+
unless (defined $BNG_VERSION)
|
| 93 |
+
{
|
| 94 |
+
# read version info from VERSION file
|
| 95 |
+
if ( open my $fh, '<', File::Spec->catfile($BNG_ROOT, VERSION_FILENAME) )
|
| 96 |
+
{
|
| 97 |
+
# get first line of file
|
| 98 |
+
my $version_string = <$fh>;
|
| 99 |
+
close $fh;
|
| 100 |
+
|
| 101 |
+
# extract version number
|
| 102 |
+
$version_string =~ s/^\s*(\d+\.\d+\.\d+)\s*//;
|
| 103 |
+
|
| 104 |
+
$BNG_VERSION = $1;
|
| 105 |
+
unless ( defined $BNG_VERSION )
|
| 106 |
+
{ $BNG_VERSION = DEFAULT_VERSION; }
|
| 107 |
+
|
| 108 |
+
# extract codename (if any)
|
| 109 |
+
$version_string =~ s/^(\w+)//;
|
| 110 |
+
$BNG_CODENAME = $1;
|
| 111 |
+
unless ( defined $BNG_VERSION )
|
| 112 |
+
{ $BNG_CODENAME = DEFAULT_CODENAME; }
|
| 113 |
+
}
|
| 114 |
+
else
|
| 115 |
+
{
|
| 116 |
+
$BNG_VERSION = DEFAULT_VERSION;
|
| 117 |
+
$BNG_CODENAME = '';
|
| 118 |
+
}
|
| 119 |
+
}
|
| 120 |
+
return;
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
# get BNG_VERSION
|
| 124 |
+
sub BNGversion
|
| 125 |
+
{
|
| 126 |
+
unless (defined $BNG_VERSION)
|
| 127 |
+
{ # find BNG root directory
|
| 128 |
+
readVersionFile();
|
| 129 |
+
}
|
| 130 |
+
return $BNG_VERSION;
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
# get BNG_CODENAME
|
| 134 |
+
sub BNGcodename
|
| 135 |
+
{
|
| 136 |
+
unless (defined $BNG_CODENAME)
|
| 137 |
+
{ # find BNG root directory
|
| 138 |
+
readVersionFile();
|
| 139 |
+
}
|
| 140 |
+
return $BNG_CODENAME;
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
# compare versions: returns -1 if version1 < version2,
|
| 144 |
+
# 1 if version1 > version2,
|
| 145 |
+
# 0 if version1 == version2
|
| 146 |
+
sub compareVersions
|
| 147 |
+
{
|
| 148 |
+
my ($version1, $version2) = @_;
|
| 149 |
+
|
| 150 |
+
my (@version1) = split (/\./, $version1);
|
| 151 |
+
my (@version2) = split (/\./, $version2);
|
| 152 |
+
|
| 153 |
+
# compare major, minor and release numbers
|
| 154 |
+
while (@version1 and @version2)
|
| 155 |
+
{
|
| 156 |
+
my $comp = ( shift @version1 <=> shift @version2 );
|
| 157 |
+
if ($comp) { return $comp; }
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
# if versions are equal so far, the version with finer defintion
|
| 161 |
+
# is greater than the other.
|
| 162 |
+
# (e.g. 2.1.7 is greater than 2.1)
|
| 163 |
+
return ( @version1 ? 1 : (@version2 ? -1 : 0) );
|
| 164 |
+
}
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
|
| 168 |
+
# Determine if a string corresponds to a float or a double
|
| 169 |
+
sub isReal{
|
| 170 |
+
my $string=shift;
|
| 171 |
+
my $isdec=0;
|
| 172 |
+
|
| 173 |
+
if ($string=~ s/^[+-]?\d+[.]?\d*//){
|
| 174 |
+
$isdec=1;
|
| 175 |
+
}
|
| 176 |
+
elsif ($string=~ s/^[+-]?[.]\d+//){
|
| 177 |
+
$isdec=1;
|
| 178 |
+
} else {
|
| 179 |
+
return(0);
|
| 180 |
+
}
|
| 181 |
+
if ($string eq ""){return(1);}
|
| 182 |
+
|
| 183 |
+
if ($string=~ s/^[DEFGdefg][+-]?\d+$//){
|
| 184 |
+
return(1);
|
| 185 |
+
}
|
| 186 |
+
return(0);
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
# Determine if a string is a Boolean
|
| 190 |
+
sub isBoolean{
|
| 191 |
+
my $string=shift;
|
| 192 |
+
my $isboo;
|
| 193 |
+
|
| 194 |
+
if ($string=~/^true$/i){
|
| 195 |
+
$isboo=1;
|
| 196 |
+
} elsif ($string=~/^false$/i){
|
| 197 |
+
$isboo=1;
|
| 198 |
+
} else {
|
| 199 |
+
$isboo=0;
|
| 200 |
+
}
|
| 201 |
+
return($isboo);
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
# Convert boolean to integer False=0 True=1 notBoolean=-1
|
| 205 |
+
sub booleanToInt{
|
| 206 |
+
my $string=shift;
|
| 207 |
+
my $intval;
|
| 208 |
+
|
| 209 |
+
if ($string=~/^true$/i){
|
| 210 |
+
$intval=1;
|
| 211 |
+
}
|
| 212 |
+
elsif ($string=~/^false$/i){
|
| 213 |
+
$intval=0;
|
| 214 |
+
}
|
| 215 |
+
# Boolean that is not a assigned a value is True by default
|
| 216 |
+
elsif ($string eq ""){
|
| 217 |
+
$intval=1;
|
| 218 |
+
}
|
| 219 |
+
else {
|
| 220 |
+
$intval=-1;
|
| 221 |
+
}
|
| 222 |
+
return($intval);
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
+
##---------------------------------------------------------------------------
|
| 226 |
+
# Check that a pattern referring to species objects is valid.
|
| 227 |
+
|
| 228 |
+
sub verify_pattern{
|
| 229 |
+
my $pattern= shift;
|
| 230 |
+
my $is_spec= shift;
|
| 231 |
+
my $mol_ncomp= shift;
|
| 232 |
+
|
| 233 |
+
$patt=$pattern;
|
| 234 |
+
# remove valid termination characters
|
| 235 |
+
$patt=~s/\.\*$//;
|
| 236 |
+
$patt=~s/\*$//;
|
| 237 |
+
|
| 238 |
+
# split pattern into molecules and check that each is valid
|
| 239 |
+
my @molecules= split('\.',$patt);
|
| 240 |
+
for my $mol (@molecules){
|
| 241 |
+
my ($head, @components)= split_obj($mol);
|
| 242 |
+
if ($head eq $mol){
|
| 243 |
+
if ($#molecules>0){
|
| 244 |
+
return(1, "Single state species $head may not appear in a complex.")
|
| 245 |
+
}
|
| 246 |
+
elsif (!defined($$is_spec{$mol})){
|
| 247 |
+
return(0, "Species not declared: $pattern");
|
| 248 |
+
}
|
| 249 |
+
} else {
|
| 250 |
+
# Check that number of components matches species declaration
|
| 251 |
+
if (!defined($$mol_ncomp{$head})){
|
| 252 |
+
return(1, "Molecule $head not defined.");
|
| 253 |
+
} elsif ($$mol_ncomp{$head}!= $#components){
|
| 254 |
+
return(1, "Number of components for molecule $head doesn't match species declaration.");
|
| 255 |
+
}
|
| 256 |
+
|
| 257 |
+
# Check that each component is valid
|
| 258 |
+
for my $comp (@components){
|
| 259 |
+
if ($comp=~/[^0-9\*]/){
|
| 260 |
+
return(1, "Invalid component state $comp: May only use integers or wildcard.",$entry);
|
| 261 |
+
}
|
| 262 |
+
# if ($comp=~/[^A-Za-z0-9_\-\*]/){
|
| 263 |
+
# return(1, "Invalid component state $comp in pattern $pattern: May only use alphanumeric characters, '-','_', or '*'.");
|
| 264 |
+
# }
|
| 265 |
+
}
|
| 266 |
+
}
|
| 267 |
+
}
|
| 268 |
+
|
| 269 |
+
if ($#molecules<0){
|
| 270 |
+
return(1, "No molecules specified in matching string\n");
|
| 271 |
+
}
|
| 272 |
+
return(0,"");
|
| 273 |
+
}
|
| 274 |
+
|
| 275 |
+
##---------------------------------------------------------------------------
|
| 276 |
+
# Handle a value that is either a number, a parameter name, or a
|
| 277 |
+
# product of a number and a parameter name.
|
| 278 |
+
|
| 279 |
+
sub process_val_string{
|
| 280 |
+
my $val_string= shift;
|
| 281 |
+
my $entry= shift;
|
| 282 |
+
my $parameters= shift;
|
| 283 |
+
|
| 284 |
+
my ($fac,$val, $value);
|
| 285 |
+
|
| 286 |
+
$value=$val_string;
|
| 287 |
+
if ($value=~/(\S+)[*](\S+)/){
|
| 288 |
+
$fac= $1;
|
| 289 |
+
$val=$2;
|
| 290 |
+
} else {
|
| 291 |
+
$fac= 1;
|
| 292 |
+
$val=$value;
|
| 293 |
+
}
|
| 294 |
+
|
| 295 |
+
# Make sure val is valid parameter if it is not a number.
|
| 296 |
+
# NOTE: The checking here would be much easier with a perl routine
|
| 297 |
+
# isnum(string) (which is part of Acme::Utils) that returns true if the
|
| 298 |
+
# string is a number (in the C/Fortran sense). I didn't use this routine
|
| 299 |
+
# because it requires installation of additional perl modules, which might
|
| 300 |
+
# be beyond the capabilities of our target user.
|
| 301 |
+
if ($val=~/^[a-zA-Z]/){
|
| 302 |
+
# Determine if parameters are allowed
|
| 303 |
+
($parameters) || exit_error("Parameter not allowed for value.",$entry);
|
| 304 |
+
# Make sure parameter is valid
|
| 305 |
+
defined($$parameters{$val}) || exit_error("Parameter $val is not defined.",$entry);
|
| 306 |
+
# Make sure value is non-negative
|
| 307 |
+
if ($$parameters{$val}{val}<0){exit_error("Parameter value must be non-negative.",$entry);}
|
| 308 |
+
$value= $fac*$$parameters{$val}{val};
|
| 309 |
+
} else {
|
| 310 |
+
# Substitute numerical value
|
| 311 |
+
$value= $fac*$val;
|
| 312 |
+
# Make sure value is non-negative
|
| 313 |
+
if ($value<0){&exit_error("Parameter value must be non-negative",$entry);}
|
| 314 |
+
}
|
| 315 |
+
|
| 316 |
+
# print "fac:$fac val:$val value:$value\n";
|
| 317 |
+
return($value);
|
| 318 |
+
}
|
| 319 |
+
|
| 320 |
+
|
| 321 |
+
# Send error message to STDERR and exit.
|
| 322 |
+
sub exit_error
|
| 323 |
+
{
|
| 324 |
+
my @msgs = @_;
|
| 325 |
+
print STDERR "ABORT: ";
|
| 326 |
+
foreach my $msg (@msgs)
|
| 327 |
+
{
|
| 328 |
+
print STDERR $msg, "\n";
|
| 329 |
+
}
|
| 330 |
+
exit(1);
|
| 331 |
+
}
|
| 332 |
+
|
| 333 |
+
|
| 334 |
+
# Send error message to STDERR, but do not exit.
|
| 335 |
+
sub send_error
|
| 336 |
+
{
|
| 337 |
+
my @msgs = @_;
|
| 338 |
+
print STDERR "ERROR: ";
|
| 339 |
+
foreach my $msg (@msgs)
|
| 340 |
+
{ print STDERR $msg, "\n"; }
|
| 341 |
+
return 0;
|
| 342 |
+
}
|
| 343 |
+
|
| 344 |
+
|
| 345 |
+
# send warning to STDOUT
|
| 346 |
+
sub send_warning
|
| 347 |
+
{
|
| 348 |
+
my @msgs = @_;
|
| 349 |
+
print STDOUT "WARNING: ";
|
| 350 |
+
foreach my $msg (@msgs)
|
| 351 |
+
{ print STDOUT $msg,"\n"; }
|
| 352 |
+
# Could have $STRICT flag to force exit
|
| 353 |
+
return 0;
|
| 354 |
+
}
|
| 355 |
+
|
| 356 |
+
|
| 357 |
+
# send error message with line number
|
| 358 |
+
sub line_error
|
| 359 |
+
{
|
| 360 |
+
my ($msg, $lno) = @_;
|
| 361 |
+
print STDERR sprintf( "ABORT: [at line %s] %s\n", $lno, $msg );
|
| 362 |
+
exit 1;
|
| 363 |
+
}
|
| 364 |
+
|
| 365 |
+
# send warning message with line number
|
| 366 |
+
sub line_warning
|
| 367 |
+
{
|
| 368 |
+
my ($msg, $lno) = @_;
|
| 369 |
+
print STDOUT sprintf( "WARNING: [at line %s] %s\n", $lno, $msg );
|
| 370 |
+
}
|
| 371 |
+
|
| 372 |
+
|
| 373 |
+
##------------------------------------------------------------------------
|
| 374 |
+
# Used to create list of all multi-state objects from a list of
|
| 375 |
+
# dimensions. It returns an array containing all elements of the
|
| 376 |
+
# multidimensional array named $name.
|
| 377 |
+
# e.g. expand_object("R", 2,2) returns the array
|
| 378 |
+
# (R(0,0), R(1,0), R(0,1), R(1,1)
|
| 379 |
+
# Earlier indices vary faster than later ones.
|
| 380 |
+
|
| 381 |
+
sub expand_object{
|
| 382 |
+
my $name= shift;
|
| 383 |
+
my @lengths=@{$t=shift};
|
| 384 |
+
my @equiv=@{$t=shift};
|
| 385 |
+
my @olist=("");
|
| 386 |
+
|
| 387 |
+
for my $i (0..$#lengths){
|
| 388 |
+
my @new_olist=();
|
| 389 |
+
my $sep= ($i==$#lengths) ? "" : ",";
|
| 390 |
+
# array of earlier indices that are equivalent to index $i
|
| 391 |
+
my @eq=();
|
| 392 |
+
if (my $class= $equiv[$i]){
|
| 393 |
+
for $j (0..$i-1){
|
| 394 |
+
($equiv[$j]==$class) && push @eq,$j;
|
| 395 |
+
}
|
| 396 |
+
}
|
| 397 |
+
for $state (0..($lengths[$i]-1)){
|
| 398 |
+
OBJ:
|
| 399 |
+
for $obj (@olist){
|
| 400 |
+
# Skip this object if the current state is greater
|
| 401 |
+
# than the state of index equivalent to the current one.
|
| 402 |
+
if (@eq){
|
| 403 |
+
my @states=split(',',$obj);
|
| 404 |
+
for $j (@eq){
|
| 405 |
+
($state>$states[$j]) && next OBJ;
|
| 406 |
+
}
|
| 407 |
+
}
|
| 408 |
+
push @new_olist, $obj.$state.$sep;
|
| 409 |
+
}
|
| 410 |
+
}
|
| 411 |
+
@olist= @new_olist;
|
| 412 |
+
}
|
| 413 |
+
|
| 414 |
+
# Enclose indices in parentheses and prepend spcies name
|
| 415 |
+
for $obj (@olist){
|
| 416 |
+
$obj= $name."(".$obj.")";
|
| 417 |
+
}
|
| 418 |
+
|
| 419 |
+
return(@olist);
|
| 420 |
+
}
|
| 421 |
+
|
| 422 |
+
##---------------------------------------------------------------------------
|
| 423 |
+
# Create aggregates from lists of species in rows of matrix a.
|
| 424 |
+
# This subroutine uses a depth first algoritm, meaning here that the
|
| 425 |
+
# most distant index changes fastest.
|
| 426 |
+
# The second subroutine uses a breadth first algoritm, meaning here that the
|
| 427 |
+
# most nearest index changes fastest.
|
| 428 |
+
##---------------------------------------------------------------------------
|
| 429 |
+
|
| 430 |
+
sub make_aggregates{
|
| 431 |
+
my @a= @{$t= shift};
|
| 432 |
+
|
| 433 |
+
my $idepth=0;
|
| 434 |
+
my $max_depth=$#a;
|
| 435 |
+
my @olist=();
|
| 436 |
+
my @agg=();
|
| 437 |
+
my %agg_hash=();
|
| 438 |
+
|
| 439 |
+
for $i (0..$#a){$iptrs[$i]=0;}
|
| 440 |
+
push @olist, $a[0][0];
|
| 441 |
+
|
| 442 |
+
while(1){
|
| 443 |
+
#descend until idepth==max_depth
|
| 444 |
+
while($idepth<$max_depth){
|
| 445 |
+
++$idepth;
|
| 446 |
+
last if ($idepth==$max_depth);
|
| 447 |
+
# set ptr at new depth to start of array
|
| 448 |
+
$iptrs[$idepth]=0;
|
| 449 |
+
push @olist, $a[$idepth][0];
|
| 450 |
+
}
|
| 451 |
+
|
| 452 |
+
# loop over ptrs at lowest depth
|
| 453 |
+
my @obj_low= @{$a[$max_depth]};
|
| 454 |
+
# my $eq=$equiv[$idepth];
|
| 455 |
+
for $obj (@obj_low){
|
| 456 |
+
push @olist, $obj;
|
| 457 |
+
my $new_agg= join(".", sort by_obj @olist);
|
| 458 |
+
my $new_agg_sort= join(".", sort by_obj @olist);
|
| 459 |
+
# Only add aggregate that is in sort order
|
| 460 |
+
#($new_agg eq $new_agg_sort) && push @agg, $new_agg;
|
| 461 |
+
# Another way is to add aggregate first time it is encountered
|
| 462 |
+
($agg_hash{$new_agg}++==0) && push @agg, $new_agg;
|
| 463 |
+
pop @olist;
|
| 464 |
+
}
|
| 465 |
+
|
| 466 |
+
# go back up to depth where elements are not exhausted
|
| 467 |
+
# stop when no more elements at any level
|
| 468 |
+
while($idepth>=0){
|
| 469 |
+
--$idepth;
|
| 470 |
+
last if ($idepth<0);
|
| 471 |
+
pop @olist;
|
| 472 |
+
if (($iptr=++$iptrs[$idepth])<=$#{$a[$idepth]}){
|
| 473 |
+
push @olist, $a[$idepth][$iptr];
|
| 474 |
+
last;
|
| 475 |
+
}
|
| 476 |
+
}
|
| 477 |
+
last if ($idepth<0);
|
| 478 |
+
}
|
| 479 |
+
# print join("\n", @agg),"\n";
|
| 480 |
+
return(@agg);
|
| 481 |
+
}
|
| 482 |
+
|
| 483 |
+
##------------------------------------------------------------------------
|
| 484 |
+
# Returns the total cputime (user+system) of the current process and
|
| 485 |
+
# all children since the last call to cpu_time.
|
| 486 |
+
# Optional argument can be used to reset the offset.
|
| 487 |
+
# Call cpu_time(0) to tare (i.e. "zero") the clock.
|
| 488 |
+
{
|
| 489 |
+
my $store_time=0;
|
| 490 |
+
sub cpu_time
|
| 491 |
+
{
|
| 492 |
+
my $prev_time = @_ ? shift @_ : $store_time;
|
| 493 |
+
my $curr_time = sum times;
|
| 494 |
+
$store_time = $curr_time;
|
| 495 |
+
return $curr_time - $prev_time;
|
| 496 |
+
}
|
| 497 |
+
}
|
| 498 |
+
|
| 499 |
+
# Compute average and standard deviation over a set of data in
|
| 500 |
+
# format
|
| 501 |
+
# time1 y1 ... yN
|
| 502 |
+
# ...
|
| 503 |
+
# timeM y1 ... yN
|
| 504 |
+
#
|
| 505 |
+
|
| 506 |
+
# This routine returns data sets in xmgrace format.
|
| 507 |
+
# Sets are written separately, in format time val dval, where dval
|
| 508 |
+
# is the standard deviation of the average over all runs.
|
| 509 |
+
|
| 510 |
+
sub average_runs{
|
| 511 |
+
my $outfile=shift;
|
| 512 |
+
|
| 513 |
+
my $nfile=0;
|
| 514 |
+
my @t=();
|
| 515 |
+
my $ng;
|
| 516 |
+
for my $file (@_){
|
| 517 |
+
open(IN, $file);
|
| 518 |
+
my $i_t=0;
|
| 519 |
+
while(<IN>){
|
| 520 |
+
next if (/^\#/);
|
| 521 |
+
my($time, @dat)=split(' ');
|
| 522 |
+
if ($nfile==1){
|
| 523 |
+
push @t, $time;
|
| 524 |
+
$ng= $#dat;
|
| 525 |
+
}
|
| 526 |
+
for my $j(0..$#dat){
|
| 527 |
+
$y[$i_t][$j][$nfile]= $dat[$j];
|
| 528 |
+
}
|
| 529 |
+
++$i_t;
|
| 530 |
+
}
|
| 531 |
+
close(IN);
|
| 532 |
+
++$nfile;
|
| 533 |
+
}
|
| 534 |
+
|
| 535 |
+
# Write results to outfile
|
| 536 |
+
open(OUT,">$outfile");
|
| 537 |
+
for $j (0..$ng){
|
| 538 |
+
for my $i (0..$#t){
|
| 539 |
+
print OUT $t[$i];
|
| 540 |
+
my ($sig, $avg)= &stddev(@{$y[$i][$j]});
|
| 541 |
+
print OUT " ", $avg;
|
| 542 |
+
print OUT " ", $sig;
|
| 543 |
+
print OUT "\n";
|
| 544 |
+
}
|
| 545 |
+
print OUT "&\n";
|
| 546 |
+
}
|
| 547 |
+
close(OUT);
|
| 548 |
+
}
|
| 549 |
+
|
| 550 |
+
sub average{
|
| 551 |
+
return -1 unless $#_>=0;
|
| 552 |
+
local($sum)=0.0;
|
| 553 |
+
foreach $val (@_){
|
| 554 |
+
$sum+=$val;
|
| 555 |
+
}
|
| 556 |
+
return $sum/($#_+1);
|
| 557 |
+
}
|
| 558 |
+
|
| 559 |
+
sub stddev{
|
| 560 |
+
return -1 unless $#_>=0;
|
| 561 |
+
local($sum)=0.0;
|
| 562 |
+
local($average)= &average(@_);
|
| 563 |
+
foreach $val (@_){
|
| 564 |
+
$sum+=SQR($val-$average);
|
| 565 |
+
}
|
| 566 |
+
return (sqrt($sum/$#_), $average); # This is the correct formula for the
|
| 567 |
+
# variance---denom contains (n-1)
|
| 568 |
+
}
|
| 569 |
+
|
| 570 |
+
# Basic utilities
|
| 571 |
+
|
| 572 |
+
sub SQR{
|
| 573 |
+
local($x)=shift;
|
| 574 |
+
return ($x*$x);
|
| 575 |
+
}
|
| 576 |
+
|
| 577 |
+
|
| 578 |
+
sub log10 {
|
| 579 |
+
my $x=shift;
|
| 580 |
+
return log($x)/log(10);
|
| 581 |
+
}
|
| 582 |
+
|
| 583 |
+
sub MAX{
|
| 584 |
+
my $a=shift;
|
| 585 |
+
my $b=shift;
|
| 586 |
+
|
| 587 |
+
return(($a>=$b)? $a : $b);
|
| 588 |
+
}
|
| 589 |
+
|
| 590 |
+
sub MIN{
|
| 591 |
+
my $a=shift;
|
| 592 |
+
my $b=shift;
|
| 593 |
+
|
| 594 |
+
return(($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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/perl
|
| 2 |
+
|
| 3 |
+
use strict;
|
| 4 |
+
use warnings;
|
| 5 |
+
use File::Spec;
|
| 6 |
+
|
| 7 |
+
my @NODES = ();
|
| 8 |
+
|
| 9 |
+
my @parameters = ();
|
| 10 |
+
my @molecule_types = ();
|
| 11 |
+
my @seed_species = ();
|
| 12 |
+
my @observables = ();
|
| 13 |
+
my @functions = ();
|
| 14 |
+
my @reaction_rules = ();
|
| 15 |
+
|
| 16 |
+
my $file = shift @ARGV;
|
| 17 |
+
|
| 18 |
+
my $update_mode = (@ARGV) ? shift @ARGV : 'GSP'; # ROA, GA, GSP
|
| 19 |
+
$update_mode =~ tr/a-z/A-Z/; # make upper case
|
| 20 |
+
if ( $update_mode eq 'ROA' || $update_mode eq 'GA' || $update_mode eq 'GSP' ){
|
| 21 |
+
printf "Boolean update mode: '$update_mode'\n";
|
| 22 |
+
}
|
| 23 |
+
else{
|
| 24 |
+
printf "Boolean update mode '$update_mode' not recognized. Allowed modes are 'ROA', 'GA', and 'GSP'.\n";
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
my $include_reset = ($update_mode eq 'GSP') ? 0 : 1;
|
| 28 |
+
|
| 29 |
+
# determine output filename
|
| 30 |
+
if (not File::Spec->file_name_is_absolute( $file )){
|
| 31 |
+
$file = File::Spec->rel2abs($file);
|
| 32 |
+
}
|
| 33 |
+
my ($vol, $dir, $filename) = File::Spec->splitpath( $file );
|
| 34 |
+
my $outfile = $filename;
|
| 35 |
+
$outfile =~ s/\.\w+$/_$update_mode\.bngl/;
|
| 36 |
+
$outfile = File::Spec->catfile( $vol, $dir, $outfile );
|
| 37 |
+
|
| 38 |
+
# read entire file as a string
|
| 39 |
+
local $/ = undef;
|
| 40 |
+
open FILE, $file or die "Couldn't open file: $!";
|
| 41 |
+
binmode FILE;
|
| 42 |
+
my $text = <FILE>;
|
| 43 |
+
close FILE;
|
| 44 |
+
$text =~ s/\r\n*/\n/g; # remove Windows-style carriage returns
|
| 45 |
+
my @lines = split('\n', $text);
|
| 46 |
+
|
| 47 |
+
# read line-by-line
|
| 48 |
+
my $n_rules = 0;
|
| 49 |
+
foreach my $line (@lines)
|
| 50 |
+
{
|
| 51 |
+
$line =~ tr/A-Z/a-z/; # Make everything lower case
|
| 52 |
+
if ( $line =~ /^\s*(\w+)\s*=\s*([t|f])/ )
|
| 53 |
+
{
|
| 54 |
+
# MOLECULE TYPES
|
| 55 |
+
my $mt = $1;
|
| 56 |
+
$mt .= "(state~0~1";
|
| 57 |
+
if ($include_reset){ $mt .= ",reset~N~Y" }
|
| 58 |
+
$mt .= ")";
|
| 59 |
+
push @molecule_types, $mt;
|
| 60 |
+
|
| 61 |
+
# SEED SPECIES
|
| 62 |
+
my $ss = $1;
|
| 63 |
+
my $state = ($2 eq 't') ? '1' : '0';
|
| 64 |
+
$ss .= "(state~$state";
|
| 65 |
+
if ($include_reset){ $ss .= ",reset~N"; }
|
| 66 |
+
$ss .= ") 1";
|
| 67 |
+
push @seed_species, $ss;
|
| 68 |
+
|
| 69 |
+
# OBSERVABLES
|
| 70 |
+
my $obs = $1;
|
| 71 |
+
$obs =~ tr/a-z/A-Z/; # Make observable names all upper case
|
| 72 |
+
$obs = "Molecules " . $obs . " " . $1 . "(state~1)";
|
| 73 |
+
push @observables, $obs;
|
| 74 |
+
}
|
| 75 |
+
elsif( $line =~ /^\s*(\d+):\s*(\w+)\*\s*=\s*(.+)/ )
|
| 76 |
+
{
|
| 77 |
+
my $rank = $1;
|
| 78 |
+
my $node = $2;
|
| 79 |
+
my $func = $3;
|
| 80 |
+
|
| 81 |
+
push @NODES, $node;
|
| 82 |
+
|
| 83 |
+
# FUNCTIONS
|
| 84 |
+
my $fname = "${node}_func()";
|
| 85 |
+
|
| 86 |
+
$func =~ tr/a-z/A-Z/; # make everything upper case
|
| 87 |
+
$func =~ s/\(\s+/\(/g; # remove whitespace after '(' character
|
| 88 |
+
$func =~ s/\s+\)/\)/g; # remove whitespace before ')' character
|
| 89 |
+
$func =~ s/\s+or\s+/ \|\| /ig; # replace 'or' with '||'
|
| 90 |
+
$func =~ s/\s+and\s+/ \&\& /ig; # replace 'and' with '&&'
|
| 91 |
+
$func =~ s/(\s*)not\s+/$1!/ig; # replace 'not' with '!' (also remove trailing whitespace)
|
| 92 |
+
$func =~ s/(\w+)/$1>0.5/g; # replace all 'ABC' with 'ABC>0.5'
|
| 93 |
+
$func =~ s/!(\w+)>0.5/$1<0.5/g; # replace all '!ABC>0.5' with 'ABC<0.5'
|
| 94 |
+
|
| 95 |
+
$func = "$fname if($func, 1, 0)";
|
| 96 |
+
push @functions, $func;
|
| 97 |
+
|
| 98 |
+
# RULES
|
| 99 |
+
my $rate = "1";
|
| 100 |
+
if ($rank > 1){ $rate .= "/$rank"; }
|
| 101 |
+
|
| 102 |
+
$n_rules++;
|
| 103 |
+
my $rule_f = "R" . $n_rules . ": $node(state";
|
| 104 |
+
if ($include_reset){ $rule_f .= ",reset~N"; }
|
| 105 |
+
$rule_f .= ") -> $node(state~1";
|
| 106 |
+
if ($include_reset){ $rule_f .= ",reset~Y"; }
|
| 107 |
+
$rule_f .= ") if($fname>0.5,$rate,0)";
|
| 108 |
+
push @reaction_rules, $rule_f;
|
| 109 |
+
|
| 110 |
+
$n_rules++;
|
| 111 |
+
my $rule_r = "R" . $n_rules . ": $node(state";
|
| 112 |
+
if ($include_reset){ $rule_r .= ",reset~N"; }
|
| 113 |
+
$rule_r .= ") -> $node(state~0";
|
| 114 |
+
if ($include_reset){ $rule_r .= ",reset~Y"; }
|
| 115 |
+
$rule_r .= ") if($fname<0.5,$rate,0)";
|
| 116 |
+
push @reaction_rules, $rule_r;
|
| 117 |
+
}
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
if ($update_mode eq 'GA'){
|
| 121 |
+
push @reaction_rules, "\n # reset rules";
|
| 122 |
+
foreach my $node (@NODES){
|
| 123 |
+
$n_rules++;
|
| 124 |
+
my $rule = "R" . $n_rules . ": $node(reset~Y) -> $node(reset~N) 1e10";
|
| 125 |
+
push @reaction_rules, $rule;
|
| 126 |
+
}
|
| 127 |
+
}
|
| 128 |
+
elsif ($update_mode eq 'ROA'){
|
| 129 |
+
push @parameters, "N_NODES " . scalar(@NODES);
|
| 130 |
+
unshift @molecule_types, "RESET(reset~N~Y)\n #";
|
| 131 |
+
unshift @seed_species, "RESET(reset~N) 1\n #";
|
| 132 |
+
my $obs = "Molecules N_FIRED";
|
| 133 |
+
foreach my $node (@NODES){
|
| 134 |
+
$obs .= " $node(reset~Y)"
|
| 135 |
+
}
|
| 136 |
+
unshift @observables, $obs . "\n #";
|
| 137 |
+
push @reaction_rules, "\n # reset rules";
|
| 138 |
+
$n_rules++;
|
| 139 |
+
push @reaction_rules, "R" . $n_rules . ": RESET(reset~N) <-> RESET(reset~Y) 1e10*if(N_FIRED>(N_NODES-0.5),1,0), 1e10*if(N_FIRED<0.5,1,0)";
|
| 140 |
+
foreach my $node (@NODES){
|
| 141 |
+
$n_rules++;
|
| 142 |
+
my $rule = "R" . $n_rules . ": $node(reset~Y) + RESET(reset~Y) -> $node(reset~N) + RESET(reset~Y) 1e10";
|
| 143 |
+
push @reaction_rules, $rule;
|
| 144 |
+
}
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
# Print to file
|
| 148 |
+
open FILE, ">", $outfile or die "Couldn't open file: $!";
|
| 149 |
+
|
| 150 |
+
print FILE "# Translation of Boolean model in " . $filename . " to BNGL format within the " . $update_mode . " (" .
|
| 151 |
+
( ($update_mode eq 'ROA') ? "random-order asynchronous" : ($update_mode eq 'GA') ? "general asynchronous" :
|
| 152 |
+
($update_mode eq 'GSP') ? "Gillespie" : "UNKNOWN" ) . ") update mode.\n";
|
| 153 |
+
|
| 154 |
+
print FILE "begin model\n";
|
| 155 |
+
|
| 156 |
+
print FILE "begin parameters\n";
|
| 157 |
+
foreach my $i (@parameters){
|
| 158 |
+
print FILE " $i\n";
|
| 159 |
+
}
|
| 160 |
+
print FILE "end parameters\n";
|
| 161 |
+
|
| 162 |
+
print FILE "begin molecule types\n";
|
| 163 |
+
foreach my $i (@molecule_types){
|
| 164 |
+
print FILE " $i\n";
|
| 165 |
+
}
|
| 166 |
+
print FILE "end molecule types\n";
|
| 167 |
+
|
| 168 |
+
print FILE "begin seed species\n";
|
| 169 |
+
foreach my $i (@seed_species){
|
| 170 |
+
print FILE " $i\n";
|
| 171 |
+
}
|
| 172 |
+
print FILE "end seed species\n";
|
| 173 |
+
|
| 174 |
+
print FILE "begin observables\n";
|
| 175 |
+
foreach my $i (@observables){
|
| 176 |
+
print FILE " $i\n";
|
| 177 |
+
}
|
| 178 |
+
print FILE "end observables\n";
|
| 179 |
+
|
| 180 |
+
print FILE "begin functions\n";
|
| 181 |
+
foreach my $i (@functions){
|
| 182 |
+
print FILE " $i\n";
|
| 183 |
+
}
|
| 184 |
+
print FILE "end functions\n";
|
| 185 |
+
|
| 186 |
+
print FILE "begin reaction rules\n";
|
| 187 |
+
foreach my $i (@reaction_rules){
|
| 188 |
+
print FILE " $i\n";
|
| 189 |
+
}
|
| 190 |
+
print FILE "end reaction rules\n";
|
| 191 |
+
|
| 192 |
+
print FILE "end model\n";
|
| 193 |
+
|
| 194 |
+
# actions
|
| 195 |
+
print FILE "\n";
|
| 196 |
+
print FILE "# generate_network({overwrite=>1})\n\n";
|
| 197 |
+
|
| 198 |
+
my $n_nodes = scalar(@NODES);
|
| 199 |
+
|
| 200 |
+
if ($update_mode eq 'ROA'){
|
| 201 |
+
my $n_rounds = 15;
|
| 202 |
+
print FILE "# Simulate for N_ROUNDS = 15 update rounds, outputting every round. Note that with N_NODES = $n_nodes, the\n";
|
| 203 |
+
print FILE "# average time for each update round is 1 + 1/2 + 1/3 + ... + 1/$n_nodes < $n_nodes. Thus, 't_end' is set to\n";
|
| 204 |
+
print FILE "# $n_nodes*$n_rounds*100 (N_NODES*N_ROUNDS*100), a number large enough to ensure that 'max_sim_steps' is reached first.\n";
|
| 205 |
+
print FILE "#\n";
|
| 206 |
+
print FILE "# simulate({method=>\"ssa\",t_end=>($n_nodes*$n_rounds*100),output_step_interval=>($n_nodes*2+2),max_sim_steps=>(($n_nodes*2+2)*$n_rounds),print_CDAT=>0,verbose=>1})\n";
|
| 207 |
+
}
|
| 208 |
+
elsif ($update_mode eq 'GA'){
|
| 209 |
+
print FILE "# Simulate for 30 time units, outputting every time unit.\n";
|
| 210 |
+
print FILE "#\n";
|
| 211 |
+
print FILE "# simulate({method=>\"ssa\",t_end=>30,n_steps=>30,print_CDAT=>0,verbose=>1})\n\n";
|
| 212 |
+
|
| 213 |
+
print FILE "# Simulate for 30 \"update rounds\", outputting every round. This allows for a comparison with the ROA update scheme.\n";
|
| 214 |
+
print FILE "# With N_NODES = $n_nodes, each round corresponds to $n_nodes*2 reaction firings (one state-change and one reset rule per node).\n";
|
| 215 |
+
print FILE "# On average, this takes one time unit. Thus, 't_end' is set to 30*100 to ensure that 'max_sim_steps' is reached first.\n";
|
| 216 |
+
print FILE "#\n";
|
| 217 |
+
print FILE "# simulate({method=>\"ssa\",t_end=>(30*100),output_step_interval=>($n_nodes*2),max_sim_steps=>(($n_nodes*2)*30),print_CDAT=>0,verbose=>1})\n";
|
| 218 |
+
}
|
| 219 |
+
elsif ($update_mode eq 'GSP'){
|
| 220 |
+
print FILE "# Simulate for 30 time units, outputting every time unit.\n";
|
| 221 |
+
print FILE "# simulate({method=>\"ssa\",t_end=>30,n_steps=>30,print_CDAT=>0,verbose=>1})\n";
|
| 222 |
+
}
|
data/bionetgen/Perl2/Boolean2BNGL/Tcell_model_Nov2013_LAH.txt
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FLUSH = False
|
| 2 |
+
TCR = False
|
| 3 |
+
TCR_LOW = False
|
| 4 |
+
TCR_HIGH = True
|
| 5 |
+
CD28 = True
|
| 6 |
+
TGFBETA = False
|
| 7 |
+
IL2 = False
|
| 8 |
+
IL2R = False
|
| 9 |
+
AP1 = False
|
| 10 |
+
FOS = False
|
| 11 |
+
FOS_D =False
|
| 12 |
+
FOS_DD = False
|
| 13 |
+
FOS_DDD = False
|
| 14 |
+
JUN = False
|
| 15 |
+
ERK = False
|
| 16 |
+
MEK2 = False
|
| 17 |
+
TAK1 = False
|
| 18 |
+
MKK7 = False
|
| 19 |
+
JNK = False
|
| 20 |
+
RAF = False
|
| 21 |
+
RAS = False
|
| 22 |
+
CA = False
|
| 23 |
+
NFAT = False
|
| 24 |
+
PKCTHETA = False
|
| 25 |
+
NFKAPPAB = False
|
| 26 |
+
PI3K_LOW = False
|
| 27 |
+
PI3K_HIGH = False
|
| 28 |
+
PI3K = False
|
| 29 |
+
PIP3_LOW = False
|
| 30 |
+
PIP3_HIGH = False
|
| 31 |
+
PIP3 = False
|
| 32 |
+
PTEN = True
|
| 33 |
+
PDK1 = False
|
| 34 |
+
AKT = False
|
| 35 |
+
MTORC1 = False
|
| 36 |
+
MTORC2 = False
|
| 37 |
+
MTOR = False
|
| 38 |
+
MTORC1_D = False
|
| 39 |
+
MTORC2_D = False
|
| 40 |
+
MTORC2_DD = False
|
| 41 |
+
MTOR_D = False
|
| 42 |
+
MTOR_DD = False
|
| 43 |
+
MTOR_DDD = False
|
| 44 |
+
MTOR_DDDD = False
|
| 45 |
+
RHEB = False
|
| 46 |
+
TSC = True
|
| 47 |
+
S6K1 = False
|
| 48 |
+
PS6 = False
|
| 49 |
+
SMAD3 = False
|
| 50 |
+
JAK3 = False
|
| 51 |
+
STAT5 = False
|
| 52 |
+
STAT5_D = False
|
| 53 |
+
STAT5_DD = False
|
| 54 |
+
STAT5_DDD = False
|
| 55 |
+
FOXP3 = False
|
| 56 |
+
CD25 = False
|
| 57 |
+
CD122 = True
|
| 58 |
+
CD132 = True
|
| 59 |
+
IL2_EX = False
|
| 60 |
+
AKT_OFF = False
|
| 61 |
+
MTORC1_OFF = False
|
| 62 |
+
NFAT_OFF = False
|
| 63 |
+
|
| 64 |
+
1: TCR_HIGH* = not FLUSH
|
| 65 |
+
1: TCR* = TCR_LOW or TCR_HIGH
|
| 66 |
+
1: RAS* = (TCR and CD28) or (RAS and IL2_EX and IL2R)
|
| 67 |
+
1: RAF* = RAS
|
| 68 |
+
1: MEK2* = RAF
|
| 69 |
+
1: ERK* = MEK2
|
| 70 |
+
1: FOS* = ERK
|
| 71 |
+
1: PKCTHETA* = TCR_HIGH or (TCR_LOW and CD28 and MTORC2)
|
| 72 |
+
1: TAK1* = PKCTHETA
|
| 73 |
+
1: MKK7* = TAK1
|
| 74 |
+
1: JNK* = MKK7
|
| 75 |
+
1: JUN* = JNK
|
| 76 |
+
1: FOS_D* = FOS
|
| 77 |
+
1: FOS_DD* = FOS_D
|
| 78 |
+
1: AP1* = FOS_DD and JUN
|
| 79 |
+
1: CA* = TCR
|
| 80 |
+
1: NFKAPPAB* = PKCTHETA or AKT
|
| 81 |
+
1: NFAT* = CA and not NFAT_OFF
|
| 82 |
+
1: IL2* = ((AP1 and NFAT and NFKAPPAB) or IL2) and not FOXP3
|
| 83 |
+
1: IL2R* = CD25 and CD122 and CD132
|
| 84 |
+
1: PI3K_LOW* = (TCR_LOW and CD28) or (PI3K_LOW and IL2_EX and IL2R)
|
| 85 |
+
1: PI3K_HIGH* = (TCR_HIGH and CD28) or (PI3K_HIGH and IL2_EX and IL2R)
|
| 86 |
+
1: PI3K* = PI3K_LOW or PI3K_HIGH
|
| 87 |
+
1: PIP3_HIGH* = PI3K_HIGH and not PTEN
|
| 88 |
+
1: PIP3_LOW* = PI3K_LOW and not PTEN
|
| 89 |
+
1: PIP3* = PIP3_LOW or PIP3_HIGH
|
| 90 |
+
1: PDK1* = PIP3
|
| 91 |
+
1: AKT* = PDK1 and MTORC2 and not AKT_OFF
|
| 92 |
+
1: TSC* = not AKT
|
| 93 |
+
1: RHEB* = not TSC
|
| 94 |
+
1: MTORC1* = RHEB and not MTORC1_OFF
|
| 95 |
+
1: MTORC2* = PI3K_HIGH or (PI3K_LOW and not S6K1)
|
| 96 |
+
1: MTORC1_D* = MTORC1
|
| 97 |
+
1: MTORC2_D* = MTORC2
|
| 98 |
+
1: MTOR* = MTORC1_D and MTORC2_D
|
| 99 |
+
1: MTOR_D* = MTOR
|
| 100 |
+
1: MTOR_DD* = MTOR_D
|
| 101 |
+
1: S6K1* = MTORC1
|
| 102 |
+
1: PS6* = S6K1
|
| 103 |
+
1: SMAD3* = TGFBETA
|
| 104 |
+
1: JAK3* = IL2R and IL2_EX
|
| 105 |
+
1: STAT5* = JAK3
|
| 106 |
+
1: STAT5_D* = STAT5
|
| 107 |
+
1: FOXP3* = (not MTOR_DD and STAT5) or (NFAT and SMAD3)
|
| 108 |
+
1: CD25* = FOXP3 or (AP1 and NFAT and NFKAPPAB) or STAT5
|
| 109 |
+
1: PTEN* = (not TCR_HIGH and PTEN) or (not TCR_HIGH and FOXP3)
|
| 110 |
+
1: IL2_EX* = IL2 or IL2_EX
|
data/bionetgen/Perl2/Boolean2BNGL/Tcell_model_Oct2013.txt
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
TCR = False
|
| 2 |
+
TCR_LOW = False
|
| 3 |
+
TCR_HIGH = True
|
| 4 |
+
CD28 = True
|
| 5 |
+
TGFBETA = False
|
| 6 |
+
IL2 = False
|
| 7 |
+
IL2R = False
|
| 8 |
+
AP1 = False
|
| 9 |
+
FOS = False
|
| 10 |
+
FOS_D =False
|
| 11 |
+
FOS_DD = False
|
| 12 |
+
FOS_DDD = False
|
| 13 |
+
JUN = False
|
| 14 |
+
ERK = False
|
| 15 |
+
MEK2 = False
|
| 16 |
+
TAK1 = False
|
| 17 |
+
MKK7 = False
|
| 18 |
+
JNK = False
|
| 19 |
+
RAF = False
|
| 20 |
+
RAS = False
|
| 21 |
+
CA = False
|
| 22 |
+
NFAT = False
|
| 23 |
+
PKCTHETA = False
|
| 24 |
+
NFKAPPAB = False
|
| 25 |
+
PI3K_LOW = False
|
| 26 |
+
PI3K_HIGH = False
|
| 27 |
+
PI3K = False
|
| 28 |
+
PIP3_LOW = False
|
| 29 |
+
PIP3_HIGH = False
|
| 30 |
+
PIP3 = False
|
| 31 |
+
PTEN = True
|
| 32 |
+
PDK1 = False
|
| 33 |
+
AKT = False
|
| 34 |
+
MTORC1 = False
|
| 35 |
+
MTORC2 = False
|
| 36 |
+
MTOR = False
|
| 37 |
+
MTORC1_D = False
|
| 38 |
+
MTORC2_D = False
|
| 39 |
+
MTORC2_DD = False
|
| 40 |
+
MTOR_D = False
|
| 41 |
+
MTOR_DD = False
|
| 42 |
+
MTOR_DDD = False
|
| 43 |
+
MTOR_DDDD = False
|
| 44 |
+
RHEB = False
|
| 45 |
+
TSC = True
|
| 46 |
+
S6K1 = False
|
| 47 |
+
PS6 = False
|
| 48 |
+
SMAD3 = False
|
| 49 |
+
JAK3 = False
|
| 50 |
+
STAT5 = False
|
| 51 |
+
STAT5_D = False
|
| 52 |
+
STAT5_DD = False
|
| 53 |
+
STAT5_DDD = False
|
| 54 |
+
FOXP3 = False
|
| 55 |
+
CD25 = False
|
| 56 |
+
CD122 = True
|
| 57 |
+
CD132 = True
|
| 58 |
+
IL2_EX = False
|
| 59 |
+
AKT_OFF = False
|
| 60 |
+
MTORC1_OFF = False
|
| 61 |
+
NFAT_OFF = False
|
| 62 |
+
|
| 63 |
+
1: TCR* = TCR_LOW or TCR_HIGH
|
| 64 |
+
1: RAS* = ( TCR and CD28 ) or (RAS and IL2_EX and IL2R)
|
| 65 |
+
1: RAF* = RAS
|
| 66 |
+
1: MEK2* = RAF
|
| 67 |
+
1: ERK* = MEK2
|
| 68 |
+
1: FOS* = ERK
|
| 69 |
+
1: PKCTHETA* = TCR_HIGH or (TCR_LOW and CD28 and MTORC2)
|
| 70 |
+
1: TAK1* = PKCTHETA
|
| 71 |
+
1: MKK7* = TAK1
|
| 72 |
+
1: JNK* = MKK7
|
| 73 |
+
1: JUN* = JNK
|
| 74 |
+
1: FOS_D* = FOS
|
| 75 |
+
1: FOS_DD* = FOS_D
|
| 76 |
+
1: AP1* = FOS_DD and JUN
|
| 77 |
+
1: CA* = TCR
|
| 78 |
+
1: NFKAPPAB* = PKCTHETA or AKT
|
| 79 |
+
1: NFAT* = CA and not NFAT_OFF
|
| 80 |
+
1: IL2* = ((AP1 and NFAT and NFKAPPAB) or IL2) and not FOXP3
|
| 81 |
+
1: IL2R* = CD25 and CD122 and CD132
|
| 82 |
+
1: PI3K_LOW* = (TCR_LOW and CD28) or (PI3K_LOW and IL2_EX and IL2R)
|
| 83 |
+
1: PI3K_HIGH* = (TCR_HIGH and CD28) or (PI3K_HIGH and IL2_EX and IL2R)
|
| 84 |
+
1: PI3K* = PI3K_LOW or PI3K_HIGH
|
| 85 |
+
1: PIP3_HIGH* = PI3K_HIGH and not PTEN
|
| 86 |
+
1: PIP3_LOW* = PI3K_LOW and not PTEN
|
| 87 |
+
1: PIP3* = PIP3_LOW or PIP3_HIGH
|
| 88 |
+
1: PDK1* = PIP3
|
| 89 |
+
1: AKT* = PDK1 and MTORC2 and not AKT_OFF
|
| 90 |
+
1: TSC* = not AKT
|
| 91 |
+
1: RHEB* = not TSC
|
| 92 |
+
1: MTORC1* = RHEB and not MTORC1_OFF
|
| 93 |
+
1: MTORC2* = PI3K_HIGH or (PI3K_LOW and not S6K1)
|
| 94 |
+
1: MTORC1_D* = MTORC1
|
| 95 |
+
1: MTORC2_D* = MTORC2
|
| 96 |
+
1: MTOR* = MTORC1_D and MTORC2_D
|
| 97 |
+
1: MTOR_D* = MTOR
|
| 98 |
+
1: MTOR_DD* = MTOR_D
|
| 99 |
+
1: S6K1* = MTORC1
|
| 100 |
+
1: PS6* = S6K1
|
| 101 |
+
1: SMAD3* = TGFBETA
|
| 102 |
+
1: JAK3* = IL2R and IL2_EX
|
| 103 |
+
1: STAT5* = JAK3
|
| 104 |
+
1: STAT5_D* = STAT5
|
| 105 |
+
1: FOXP3* = (not MTOR_DD and STAT5) or (NFAT and SMAD3)
|
| 106 |
+
1: CD25* = FOXP3 or (AP1 and NFAT and NFKAPPAB) or STAT5
|
| 107 |
+
1: PTEN* = (not TCR_HIGH and PTEN) or (not TCR_HIGH and FOXP3)
|
| 108 |
+
1: IL2_EX* = IL2 or IL2_EX
|
data/bionetgen/Perl2/Boolean2BNGL/Tcell_model_v16.txt
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
| 0 |
-
|
| 1 |
-
TCR_HIGH = True
|
| 2 |
-
CD28 = True
|
| 3 |
-
TGFBETA = False
|
| 4 |
-
IL2 = False
|
| 5 |
-
IL2R = False
|
| 6 |
-
AP1 = False
|
| 7 |
-
FOS = False
|
| 8 |
-
FOS_D =False
|
| 9 |
-
FOS_DD = False
|
| 10 |
-
FOS_DDD = False
|
| 11 |
-
JUN = False
|
| 12 |
-
ERK = False
|
| 13 |
-
MEK2 = False
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
PIP3_LOW = False
|
| 27 |
-
PIP3_HIGH = False
|
| 28 |
-
PIP3 = False
|
| 29 |
-
PTEN = True
|
| 30 |
-
PDK1 = False
|
| 31 |
-
AKT = False
|
| 32 |
-
MTORC1 = False
|
| 33 |
-
MTORC2 = False
|
| 34 |
-
MTOR = False
|
| 35 |
-
MTORC1_D = False
|
| 36 |
-
MTORC2_D = False
|
| 37 |
-
MTORC2_DD = False
|
| 38 |
-
MTOR_D = False
|
| 39 |
-
MTOR_DD = False
|
| 40 |
-
MTOR_DDD = False
|
| 41 |
-
MTOR_DDDD = False
|
| 42 |
-
RHEB = False
|
| 43 |
-
TSC = True
|
| 44 |
-
S6K1 = False
|
| 45 |
-
PS6 = False
|
| 46 |
-
SMAD3 = False
|
| 47 |
-
JAK3 = False
|
| 48 |
-
STAT5 = False
|
| 49 |
-
STAT5_D = False
|
| 50 |
-
STAT5_DD = False
|
| 51 |
-
STAT5_DDD = False
|
| 52 |
-
FOXP3 = False
|
| 53 |
-
CD25 = False
|
| 54 |
-
CD122 = True
|
| 55 |
-
CD132 = True
|
| 56 |
-
IL2_EX = False
|
| 57 |
-
1:
|
| 58 |
-
1:
|
| 59 |
-
1: RAF* = RAS
|
| 60 |
-
1: MEK2* = RAF
|
| 61 |
-
1:
|
| 62 |
-
1:
|
| 63 |
-
1: PKCTHETA* = TCR_HIGH or (TCR_LOW and CD28 and MTORC2)
|
| 64 |
-
1: TAK1* = PKCTHETA
|
| 65 |
-
1: MKK7* = TAK1
|
| 66 |
-
1: JNK* = MKK7
|
| 67 |
-
1: JUN* = JNK
|
| 68 |
-
1: FOS_D* = FOS
|
| 69 |
-
1: FOS_DD* = FOS_D
|
| 70 |
-
1: AP1* = FOS and JUN
|
| 71 |
-
1: CA* = TCR
|
| 72 |
-
1: NFKAPPAB* = PKCTHETA or AKT
|
| 73 |
-
1: NFAT* = CA and not NFAT_OFF
|
| 74 |
-
1: IL2* = ((AP1 and NFAT and NFKAPPAB) or IL2) and not FOXP3
|
| 75 |
-
1: IL2R* = CD25 and CD122 and CD132
|
| 76 |
-
1:
|
| 77 |
-
1: PI3K_HIGH* = (TCR_HIGH and CD28) or (PI3K_HIGH and IL2RA_D)
|
| 78 |
-
1: PI3K* = PI3K_LOW or PI3K_HIGH
|
| 79 |
-
1: PIP3_HIGH* = PI3K_HIGH and not PTEN
|
| 80 |
-
1: PIP3_LOW* = PI3K_LOW and not PTEN
|
| 81 |
-
1: PIP3* = PIP3_LOW or PIP3_HIGH
|
| 82 |
-
1: PDK1* = PIP3
|
| 83 |
-
1: AKT* = (PDK1 and MTORC2) and not AKT_OFF
|
| 84 |
-
1: TSC* = not AKT
|
| 85 |
-
1: RHEB* = not TSC
|
| 86 |
-
1: MTORC1* = RHEB and not MTORC1_OFF
|
| 87 |
-
1: MTORC2* = PI3K_HIGH or (PI3K_LOW and not S6K1)
|
| 88 |
-
1: MTORC1_D* = MTORC1
|
| 89 |
-
1: MTORC2_D* = MTORC2
|
| 90 |
-
1: MTOR* = MTORC1_D and MTORC2_D
|
| 91 |
-
1: MTOR_D* = MTOR
|
| 92 |
-
1: MTOR_DD* = MTOR_D
|
| 93 |
-
1:
|
| 94 |
-
1: PS6* = S6K1
|
| 95 |
-
1: SMAD3* = TGFBETA
|
| 96 |
-
1: JAK3* = IL2R and IL2_EX
|
| 97 |
-
1: STAT5* = JAK3
|
| 98 |
-
1: STAT5_D* = STAT5
|
| 99 |
-
1: FOXP3* = (not MTOR_DD and (STAT5 or (NFAT and AP1 and STAT5 and FOXO1))) or (NFAT and SMAD3)
|
| 100 |
-
1: CD25* = FOXP3 or (AP1 and NFAT and NFKAPPAB) or STAT5
|
| 101 |
-
1: PTEN* = (FOXO1 and MEK1) and not CK2
|
| 102 |
-
1: IL2_EX* = IL2 or IL2_EX
|
|
|
|
| 1 |
+
TCR = False
|
| 2 |
+
MEK1 = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
+
FOXO1 = True
|
| 4 |
+
FOXO1_P = False
|
| 5 |
+
FOXO1_P_D = False
|
| 6 |
+
FOXO1_P_DD = False
|
| 7 |
+
FOXO1_P_DDD = False
|
| 8 |
+
CK2 = False
|
| 9 |
+
AKT_OFF = False
|
| 10 |
+
MTORC1_OFF = False
|
| 11 |
+
NFAT_OFF = False
|
| 12 |
+
IL2RA = False
|
| 13 |
+
IL2RA_D = False
|
| 14 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
+
1: CK2* = TCR_HIGH
|
| 16 |
+
1: MEK1* = RAF
|
|
|
|
|
|
|
| 17 |
+
1: IL2RA* = IL2 and IL2R
|
| 18 |
+
1: IL2RA_D* = IL2RA
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
+
1: MTOR_DDD* = MTOR_DD
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
+
1: FOXO1* = not AKT
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data/bionetgen/Perl2/Cache.pm
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package Cache;
|
| 2 |
+
# a simple class for stowing and fetching things by label
|
| 3 |
+
|
| 4 |
+
# pragmas
|
| 5 |
+
use strict;
|
| 6 |
+
use warnings;
|
| 7 |
+
|
| 8 |
+
use constant DEFAULT_LABEL => 'DEFAULT';
|
| 9 |
+
|
| 10 |
+
# Structure containing BioNetGen model data
|
| 11 |
+
sub new
|
| 12 |
+
{
|
| 13 |
+
my ($class) = @_;
|
| 14 |
+
my $cache = {};
|
| 15 |
+
bless ($cache, $class);
|
| 16 |
+
return $cache;
|
| 17 |
+
};
|
| 18 |
+
|
| 19 |
+
# copy cache (this will NOT copy objects contained in cache)
|
| 20 |
+
sub copy
|
| 21 |
+
{
|
| 22 |
+
my ($cache) = @_;
|
| 23 |
+
my $copy = {};
|
| 24 |
+
%$copy = %$cache;
|
| 25 |
+
bless ($copy, ref $cache);
|
| 26 |
+
return $copy;
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
# stow an item in cache
|
| 30 |
+
sub cache
|
| 31 |
+
{
|
| 32 |
+
my ($cache, $item, $label) = @_;
|
| 33 |
+
|
| 34 |
+
unless (defined $label)
|
| 35 |
+
{ $label = DEFAULT_LABEL; }
|
| 36 |
+
|
| 37 |
+
$cache->{$label} = $item;
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
# browse an item in cache (get item reference, but do not remove from cache)
|
| 41 |
+
sub browse
|
| 42 |
+
{
|
| 43 |
+
my ($cache, $label) = @_;
|
| 44 |
+
|
| 45 |
+
unless (defined $label)
|
| 46 |
+
{ $label = DEFAULT_LABEL; }
|
| 47 |
+
|
| 48 |
+
return (exists $cache->{$label} ? $cache->{$label} : undef);
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
# fetch an item from cache (item is removed from cache!)
|
| 52 |
+
sub fetch
|
| 53 |
+
{
|
| 54 |
+
my ($cache, $label) = @_;
|
| 55 |
+
|
| 56 |
+
unless (defined $label)
|
| 57 |
+
{ $label = DEFAULT_LABEL; }
|
| 58 |
+
|
| 59 |
+
my $item = undef;
|
| 60 |
+
if (exists $cache->{$label})
|
| 61 |
+
{
|
| 62 |
+
$item = $cache->{$label};
|
| 63 |
+
delete $cache->{$label};
|
| 64 |
+
}
|
| 65 |
+
return $item;
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
# check if a label is defined
|
| 69 |
+
sub is_label_defined
|
| 70 |
+
{
|
| 71 |
+
my ($cache, $label) = @_;
|
| 72 |
+
|
| 73 |
+
unless (defined $label)
|
| 74 |
+
{ $label = DEFAULT_LABEL; }
|
| 75 |
+
|
| 76 |
+
return exists $cache->{$label};
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
# get the number of items in the cache
|
| 80 |
+
sub size
|
| 81 |
+
{
|
| 82 |
+
my ($cache) = @_;
|
| 83 |
+
return (scalar keys %$cache);
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
# empty the cache
|
| 87 |
+
sub empty
|
| 88 |
+
{
|
| 89 |
+
my ($cache) = @_;
|
| 90 |
+
$cache = {};
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
1;
|
data/bionetgen/Perl2/CartesianProduct.pm
ADDED
|
@@ -0,0 +1,309 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package CartesianProduct;
|
| 2 |
+
### A class for iterating over elements of a cartesian product
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
use Class::Struct;
|
| 6 |
+
use FindBin;
|
| 7 |
+
use lib $FindBin::Bin;
|
| 8 |
+
|
| 9 |
+
use warnings;
|
| 10 |
+
use strict;
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
### Members
|
| 14 |
+
struct CartesianProduct =>
|
| 15 |
+
{
|
| 16 |
+
Lists => '@', # a list of references to lists
|
| 17 |
+
NumLists => '$', # the number of lists participating in this CartesianProduct
|
| 18 |
+
ListPosition => '$', # minimum of list indices that were changed in last advance
|
| 19 |
+
FirstIdx => '@', # a list of indices corresponding to the minimum element to iterate over
|
| 20 |
+
CurrentIdx => '@', # a list of indices corresponding to the current element of the Cartesian product
|
| 21 |
+
LastIdx => '@', # a list of indices corresponding to the end of each list
|
| 22 |
+
MoreElements => '$' # a boolean value: 1 if there are more elements in the Cartesian product, 0 otherwise.
|
| 23 |
+
};
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
### Methods:
|
| 27 |
+
###
|
| 28 |
+
### (public)
|
| 29 |
+
### $cp = CartesianProduct::new();
|
| 30 |
+
### $cp_copy = $cp->copy();
|
| 31 |
+
### bool = $cp->initialize( \@lists );
|
| 32 |
+
### bool = $cp->getNext( \@elem );
|
| 33 |
+
### bool = $cp->update( \@new_items, $list_idx );
|
| 34 |
+
### bool = $cp->validate( );
|
| 35 |
+
###
|
| 36 |
+
### (private)
|
| 37 |
+
### void = $cp->advance( );
|
| 38 |
+
###
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
# Copy the Cartesian Product
|
| 43 |
+
sub copy
|
| 44 |
+
{
|
| 45 |
+
my $cp = shift @_;
|
| 46 |
+
|
| 47 |
+
my $cp_copy = CartesianProduct::new();
|
| 48 |
+
$cp_copy->Lists( [@{$cp->Lists}] );
|
| 49 |
+
$cp_copy->NumLists( $cp->NumLists );
|
| 50 |
+
$cp_copy->ListPosition( $cp->ListPosition );
|
| 51 |
+
$cp_copy->FirstIdx( [@{$cp->FirstIdx}] );
|
| 52 |
+
$cp_copy->CurrentIdx( [@{$cp->CurrentIdx}] );
|
| 53 |
+
$cp_copy->LastIdx( [@{$cp->LastIdx}] );
|
| 54 |
+
$cp_copy->MoreElements( $cp->MoreElements );
|
| 55 |
+
|
| 56 |
+
return $cp_copy;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
###
|
| 62 |
+
###
|
| 63 |
+
###
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
# Call this method to initialize a new CartesianProduct with a reference
|
| 68 |
+
# to a set of lists provided as the first argument. Returns true if the CartesianProduct
|
| 69 |
+
# is initialized correctly.
|
| 70 |
+
sub initialize
|
| 71 |
+
{
|
| 72 |
+
my $cp = shift;
|
| 73 |
+
my $lists = shift;
|
| 74 |
+
|
| 75 |
+
# get item lists
|
| 76 |
+
unless ( ref $lists eq 'ARRAY' )
|
| 77 |
+
{ return 0; }
|
| 78 |
+
|
| 79 |
+
$cp->Lists( $lists );
|
| 80 |
+
$cp->NumLists( scalar @$lists );
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
# setup index vectors
|
| 84 |
+
my $current_idx = [];
|
| 85 |
+
my $first_idx = [];
|
| 86 |
+
my $last_idx = [];
|
| 87 |
+
|
| 88 |
+
my $elem_exist = 1;
|
| 89 |
+
my $ii = 0;
|
| 90 |
+
while ( $ii < $cp->NumLists )
|
| 91 |
+
{
|
| 92 |
+
push @$current_idx, 0;
|
| 93 |
+
push @$first_idx, 0;
|
| 94 |
+
push @$last_idx, scalar @{$cp->Lists->[$ii]};
|
| 95 |
+
$elem_exist *= scalar @{$cp->Lists->[$ii]};
|
| 96 |
+
++$ii;
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
$cp->ListPosition( 0 );
|
| 100 |
+
$cp->FirstIdx( $first_idx );
|
| 101 |
+
$cp->CurrentIdx( $current_idx );
|
| 102 |
+
$cp->LastIdx( $last_idx );
|
| 103 |
+
$cp->MoreElements( $elem_exist );
|
| 104 |
+
|
| 105 |
+
return 1;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
###
|
| 111 |
+
###
|
| 112 |
+
###
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
# call this method to load the next element of the CartesianProduct
|
| 117 |
+
# into the reference provided as the first argument. Returns true if next
|
| 118 |
+
# element was loaded into array at pointer $elem; returns false if no more elements
|
| 119 |
+
# are available.
|
| 120 |
+
sub getNext
|
| 121 |
+
{
|
| 122 |
+
my $cp = shift; # this CartesianProduct object
|
| 123 |
+
my $elem = shift; # pointer to array that store elements
|
| 124 |
+
|
| 125 |
+
if ( $cp->MoreElements )
|
| 126 |
+
{ # load current element and return true
|
| 127 |
+
my $ii = $cp->ListPosition;
|
| 128 |
+
while ( $ii < $cp->NumLists )
|
| 129 |
+
{
|
| 130 |
+
$elem->[$ii] = $cp->Lists->[$ii]->[ $cp->CurrentIdx->[$ii] ];
|
| 131 |
+
++$ii;
|
| 132 |
+
}
|
| 133 |
+
$cp->advance();
|
| 134 |
+
return 1;
|
| 135 |
+
}
|
| 136 |
+
else
|
| 137 |
+
{ # no more elements, return false
|
| 138 |
+
return 0;
|
| 139 |
+
}
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
###
|
| 144 |
+
###
|
| 145 |
+
###
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
# After iterating through all elements of the CartesianProduct,
|
| 150 |
+
# add @$new_items to the list at index $list_idx.
|
| 151 |
+
# Continue calling getNext to iterate over new elements of the cartesian product
|
| 152 |
+
# NOTE: must iterate through all new elements before calling update again
|
| 153 |
+
sub update
|
| 154 |
+
{
|
| 155 |
+
my $cp = shift;
|
| 156 |
+
my $list_idx = shift;
|
| 157 |
+
my $new_items = shift;
|
| 158 |
+
|
| 159 |
+
if ( $cp->MoreElements
|
| 160 |
+
or $cp->NumLists != scalar @{$cp->Lists}
|
| 161 |
+
or $list_idx < 0
|
| 162 |
+
or $list_idx >= $cp->NumLists
|
| 163 |
+
or ref $new_items ne 'ARRAY' )
|
| 164 |
+
{ # invalid update!
|
| 165 |
+
return 0;
|
| 166 |
+
}
|
| 167 |
+
else
|
| 168 |
+
{
|
| 169 |
+
# update FirstIdx: point to first element in each list, except the updated list
|
| 170 |
+
# that will point to the first new element.
|
| 171 |
+
$cp->FirstIdx( [(0) x $cp->NumLists] );
|
| 172 |
+
$cp->FirstIdx->[$list_idx] = @{$cp->Lists->[$list_idx]};
|
| 173 |
+
|
| 174 |
+
# CurrentIdx is the same as FirstIdx
|
| 175 |
+
$cp->CurrentIdx( [@{$cp->FirstIdx}] );
|
| 176 |
+
|
| 177 |
+
# add new_items to list
|
| 178 |
+
push @{$cp->Lists->[$list_idx]}, @$new_items;
|
| 179 |
+
|
| 180 |
+
# update lastIdx
|
| 181 |
+
my $ii = 0;
|
| 182 |
+
my $elem_exist = $cp->NumLists ? 1 : 0;
|
| 183 |
+
while ( $ii < $cp->NumLists )
|
| 184 |
+
{
|
| 185 |
+
$cp->LastIdx->[$ii] = scalar @{$cp->Lists->[$ii]};
|
| 186 |
+
$elem_exist *= scalar @{$cp->Lists->[$ii]};
|
| 187 |
+
++$ii;
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
$cp->ListPosition( 0 );
|
| 191 |
+
|
| 192 |
+
if ( scalar @$new_items and $elem_exist )
|
| 193 |
+
{ $cp->MoreElements(1); }
|
| 194 |
+
|
| 195 |
+
return 1;
|
| 196 |
+
}
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
###
|
| 202 |
+
###
|
| 203 |
+
###
|
| 204 |
+
|
| 205 |
+
|
| 206 |
+
|
| 207 |
+
# This private method advances the index vector
|
| 208 |
+
sub advance
|
| 209 |
+
{
|
| 210 |
+
my $cp = shift;
|
| 211 |
+
|
| 212 |
+
if ( $cp->MoreElements )
|
| 213 |
+
{
|
| 214 |
+
my $ii = $cp->NumLists - 1;
|
| 215 |
+
while ( $ii >= 0 )
|
| 216 |
+
{
|
| 217 |
+
++($cp->CurrentIdx->[$ii]);
|
| 218 |
+
last if ( $cp->CurrentIdx->[$ii] < $cp->LastIdx->[$ii] );
|
| 219 |
+
$cp->CurrentIdx->[$ii] = $cp->FirstIdx->[$ii];
|
| 220 |
+
--$ii;
|
| 221 |
+
}
|
| 222 |
+
|
| 223 |
+
$cp->ListPosition($ii);
|
| 224 |
+
if ( $ii < 0 ) { $cp->MoreElements(0); }
|
| 225 |
+
}
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
|
| 230 |
+
|
| 231 |
+
|
| 232 |
+
|
| 233 |
+
###
|
| 234 |
+
###
|
| 235 |
+
###
|
| 236 |
+
|
| 237 |
+
|
| 238 |
+
|
| 239 |
+
# This method validates the CartesianProduct state.
|
| 240 |
+
# Returns true if everything looks good, false otherwise.
|
| 241 |
+
sub validate
|
| 242 |
+
{
|
| 243 |
+
my $cp = shift;
|
| 244 |
+
my $elem = (@_) ? shift : undef;
|
| 245 |
+
|
| 246 |
+
# check for correct number of lists
|
| 247 |
+
unless ( defined $cp->NumLists
|
| 248 |
+
and @{$cp->Lists} == $cp->NumLists )
|
| 249 |
+
{ return 0; }
|
| 250 |
+
|
| 251 |
+
# check that ListPosition is correctly defined
|
| 252 |
+
unless ( defined $cp->ListPosition
|
| 253 |
+
and $cp->ListPosition >= 0
|
| 254 |
+
and $cp->ListPosition < $cp->NumLists )
|
| 255 |
+
{ return 0; }
|
| 256 |
+
|
| 257 |
+
# check that CurrentIdx is defined
|
| 258 |
+
unless ( defined $cp->CurrentIdx )
|
| 259 |
+
{ return 0; }
|
| 260 |
+
|
| 261 |
+
# check that LastIdx is defined
|
| 262 |
+
unless ( defined $cp->LastIdx )
|
| 263 |
+
{ return 0; }
|
| 264 |
+
|
| 265 |
+
# If we were passed $elem, check that its the correct size
|
| 266 |
+
if ( defined $elem )
|
| 267 |
+
{
|
| 268 |
+
unless ( @$elem == @{$cp->Lists} ) { return 0; }
|
| 269 |
+
}
|
| 270 |
+
|
| 271 |
+
# loop over lists and check that everything is in order
|
| 272 |
+
my $ii = 0;
|
| 273 |
+
while ( $ii < $cp->NumLists )
|
| 274 |
+
{
|
| 275 |
+
# make sure things are defined
|
| 276 |
+
unless ( defined $cp->Lists->[$ii]
|
| 277 |
+
and defined $cp->CurrentIdx->[$ii]
|
| 278 |
+
and defined $cp->LastIdx->[$ii] )
|
| 279 |
+
{ return 0; }
|
| 280 |
+
|
| 281 |
+
# check that lastIndex is correct
|
| 282 |
+
unless ( $cp->LastIdx->[$ii] == @{$cp->Lists->[$ii]} )
|
| 283 |
+
{ return 0; }
|
| 284 |
+
|
| 285 |
+
# check that currentIndex has a valid range
|
| 286 |
+
unless ( $cp->CurrentIdx->[$ii] >= 0
|
| 287 |
+
and $cp->CurrentIdx->[$ii] < @{$cp->Lists->[$ii]} )
|
| 288 |
+
{ return 0; }
|
| 289 |
+
|
| 290 |
+
# If we were passed $elem check that its defined correctly up to ListPosition
|
| 291 |
+
if ( defined $elem and $ii < $cp->ListPosition )
|
| 292 |
+
{
|
| 293 |
+
unless ( $elem->[$ii] == $cp->Lists->[$ii]->[ $cp->CurrentIdx->[$ii] ] )
|
| 294 |
+
{ return 0; }
|
| 295 |
+
}
|
| 296 |
+
++$ii;
|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
use Class::Struct;
|
| 11 |
+
use FindBin;
|
| 12 |
+
use lib $FindBin::Bin;
|
| 13 |
+
|
| 14 |
+
# BNG Modules
|
| 15 |
+
use Expression;
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
struct Compartment => {
|
| 20 |
+
Name => '$', # name of compartment (valid chars: \w).
|
| 21 |
+
SpatialDimensions => '$', # dimension of compartment: 0-3.
|
| 22 |
+
Size => 'Expression', # volume/area/length expression.
|
| 23 |
+
Outside => 'Compartment', # ref to compartment (if any) that contains this.
|
| 24 |
+
Inside => '@', # list of compartments contained by Compartment. [JSH]
|
| 25 |
+
};
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
# get copy of compartment
|
| 29 |
+
# (careful here.. the Outside and Inside continue pointing to the same old place.
|
| 30 |
+
# If copying an entire compartment list, these references need to be updated after copy!)
|
| 31 |
+
sub copy
|
| 32 |
+
{
|
| 33 |
+
my $comp = shift;
|
| 34 |
+
my $plist = (@_) ? shift : undef;
|
| 35 |
+
|
| 36 |
+
my $comp_copy = Compartment::new();
|
| 37 |
+
$comp_copy->Name( $comp->Name );
|
| 38 |
+
$comp_copy->SpatialDimensions( $comp->SpatialDimensions );
|
| 39 |
+
|
| 40 |
+
$comp_copy->Size( $comp->Size->clone($plist) ) if ( defined $comp->Size );
|
| 41 |
+
$comp_copy->Outside( $comp->Outside ) if ( defined $comp->Outside );
|
| 42 |
+
|
| 43 |
+
@{ $comp_copy->Inside } = @{ $comp->Inside };
|
| 44 |
+
|
| 45 |
+
return $comp_copy;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
###
|
| 51 |
+
###
|
| 52 |
+
###
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
# after copying a compartment list, we need to relink the inside and outside neighbors
|
| 57 |
+
# the arguments should be the copied compartment and list
|
| 58 |
+
sub relinkNeighbors
|
| 59 |
+
{
|
| 60 |
+
my $comp = shift;
|
| 61 |
+
my $clist = shift;
|
| 62 |
+
|
| 63 |
+
# relink outside
|
| 64 |
+
$comp->Outside = $clist->lookup( $comp->Outside->Name );
|
| 65 |
+
# relink inside
|
| 66 |
+
foreach my $inside_comp ( @{$comp->Inside} )
|
| 67 |
+
{
|
| 68 |
+
$inside_comp = $clist->lookup( $inside_comp->Name );
|
| 69 |
+
}
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
###
|
| 75 |
+
###
|
| 76 |
+
###
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
sub newCompartment
|
| 80 |
+
# ($comp_ref, $err) = Compartment->newCompartment(name,dim,size[,outside]);
|
| 81 |
+
# creates a new compartment object
|
| 82 |
+
# sub added by justinshogg@gmail.com 18feb09
|
| 83 |
+
{
|
| 84 |
+
my ($class, $name, $dim, $size, $outside) = @_;
|
| 85 |
+
|
| 86 |
+
$name =~ /^[\w]+$/ or return( undef, "newCompartment: attempt to define compartment with invalid name: '$name'." );
|
| 87 |
+
$dim =~ /^[2-3]$/ or return( undef, "newCompartment: spatialDimension '$dim' must be integer in [2,3]." );
|
| 88 |
+
ref $size eq 'Expression' or return( undef, "newCompartment: size parameter '$size' must be an expression." );
|
| 89 |
+
|
| 90 |
+
my $err = '';
|
| 91 |
+
my $comp = Compartment->new(Name=>$name,SpatialDimensions=>$dim,Size=>$size);
|
| 92 |
+
$err = $comp->put_inside($outside) if ( defined $outside );
|
| 93 |
+
|
| 94 |
+
return($comp, $err);
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
###
|
| 99 |
+
###
|
| 100 |
+
###
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
sub put_inside
|
| 104 |
+
# $err = $comp->put_inside( $outside );
|
| 105 |
+
# set $comp1->Outside = $comp;
|
| 106 |
+
{
|
| 107 |
+
my ($comp, $outside) = @_;
|
| 108 |
+
|
| 109 |
+
# check that $outside is a compartment!
|
| 110 |
+
ref $outside eq 'Compartment'
|
| 111 |
+
|| return("Compartment->put_inside > Outside parameter '$outside' must be a Compartment.");
|
| 112 |
+
|
| 113 |
+
!defined($comp->Outside)
|
| 114 |
+
|| return("Compartment->put_inside: compartment is already contained by another compartment.");
|
| 115 |
+
|
| 116 |
+
# enforce topology. (1) alternating dimensions: ..->volume->surface->volume->surface->..
|
| 117 |
+
abs( $comp->SpatialDimensions - $outside->SpatialDimensions ) == 1
|
| 118 |
+
|| return("Compartment->put_inside: Outside has same dimension as compartment.");
|
| 119 |
+
|
| 120 |
+
# enforce topology. (2) only one volume inside a surface
|
| 121 |
+
if ($comp->SpatialDimensions == 3 && $outside->SpatialDimensions == 2)
|
| 122 |
+
{
|
| 123 |
+
(@{$outside->Inside} == 0)
|
| 124 |
+
|| return("Compartment->put_inside: Outside 2-D compartment already contains a 3-D compartment.");
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
# all good, do the operation.
|
| 128 |
+
$comp->Outside($outside);
|
| 129 |
+
push @{$outside->Inside}, $comp;
|
| 130 |
+
return '';
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
|
| 136 |
+
sub adjacent
|
| 137 |
+
# int = $comp1->adjacent( $comp2 )
|
| 138 |
+
# return +1 if $comp1 is Outside of Comp2
|
| 139 |
+
# return -1 if $comp2 is Outside of Comp1
|
| 140 |
+
# return 0 if compartments are not adjacent
|
| 141 |
+
{
|
| 142 |
+
my $comp1 = shift;
|
| 143 |
+
my $comp2 = shift;
|
| 144 |
+
|
| 145 |
+
# Compartment 1 contains Compartment 2
|
| 146 |
+
if ( defined $comp2->Outside )
|
| 147 |
+
{
|
| 148 |
+
if ( $comp2->Outside == $comp1 )
|
| 149 |
+
{ return 1; }
|
| 150 |
+
}
|
| 151 |
+
# Compartment 2 contains Compartment 1
|
| 152 |
+
if ( defined $comp1->Outside )
|
| 153 |
+
{
|
| 154 |
+
if ( $comp1->Outside == $comp2 )
|
| 155 |
+
{ return -1; }
|
| 156 |
+
}
|
| 157 |
+
return 0;
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
|
| 163 |
+
sub is_surface_of
|
| 164 |
+
# int = $comp1->is_surface_of($comp2)
|
| 165 |
+
# return 1 if $comp1 is a surface facing volume $comp2
|
| 166 |
+
# return -1 if $comp2 is a surface facing volume $comp1
|
| 167 |
+
# else return 0.
|
| 168 |
+
# justinshogg@gmail.com 16feb2009
|
| 169 |
+
{
|
| 170 |
+
my ($comp1,$comp2) = @_;
|
| 171 |
+
my $adj = $comp1->adjacent($comp2);
|
| 172 |
+
if ($adj)
|
| 173 |
+
{ return($comp2->SpatialDimensions - $comp1->SpatialDimensions); }
|
| 174 |
+
else
|
| 175 |
+
{ return 0; }
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
|
| 179 |
+
|
| 180 |
+
sub separated_by_surface
|
| 181 |
+
# int = Compartment1->separated_by_surface(Compartment2)
|
| 182 |
+
# return 1 if Compartment1 and Compartment2 are volumes
|
| 183 |
+
# separated by a surface and Comp1 is outer-most compartment.
|
| 184 |
+
# return -1 if Compartment1 and Compartment2 are volumes
|
| 185 |
+
# separated by a surface and Comp2 is outer-most compartment.
|
| 186 |
+
# return 0 otherwise.
|
| 187 |
+
#
|
| 188 |
+
# Note: assumes alternating tree topology
|
| 189 |
+
{
|
| 190 |
+
my ($comp1, $comp2) = @_;
|
| 191 |
+
|
| 192 |
+
# comp1 and comp2 must be volumes
|
| 193 |
+
return 0 unless ( ($comp1->SpatialDimensions==3) and ($comp2->SpatialDimensions==3) );
|
| 194 |
+
|
| 195 |
+
# check if comp1 and comp2 are separated by a membrane
|
| 196 |
+
# and comp1 is outer-most:
|
| 197 |
+
return -1 if ( defined $comp1->Outside
|
| 198 |
+
and defined $comp1->Outside->Outside
|
| 199 |
+
and ($comp1->Outside->Outside == $comp2) );
|
| 200 |
+
|
| 201 |
+
# and comp2 is outer-most:
|
| 202 |
+
return 1 if ( defined $comp2->Outside
|
| 203 |
+
and defined $comp2->Outside->Outside
|
| 204 |
+
and ($comp2->Outside->Outside == $comp1) );
|
| 205 |
+
|
| 206 |
+
return 0;
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
|
| 210 |
+
sub separated_by_volume
|
| 211 |
+
# int = Compartment1->separated_by_surface(Compartment2)
|
| 212 |
+
# return 1 if Compartment1 and Compartment2 are surfaces
|
| 213 |
+
# separated by a volume and the volume does not contain both surfaces.
|
| 214 |
+
# return -1 if Compartment1 and Compartment2 are surfaces
|
| 215 |
+
# separated by a volume and the volume contains both surfaces.
|
| 216 |
+
# return 0 otherwise.
|
| 217 |
+
#
|
| 218 |
+
# NOTE: assumes alternating tree topology
|
| 219 |
+
# for endocytosis: Both the Outside volume of the outermost surface
|
| 220 |
+
# and Inside volume of the innermost surface MUST EXIST.
|
| 221 |
+
# for exocytosis: Both of the Surfaces must have an Inside volume defined.
|
| 222 |
+
{
|
| 223 |
+
my ($comp1, $comp2) = @_;
|
| 224 |
+
|
| 225 |
+
# comp1 and comp2 must be surfaces
|
| 226 |
+
return 0 unless ( ($comp1->SpatialDimensions==2) and ($comp2->SpatialDimensions==2) );
|
| 227 |
+
|
| 228 |
+
# exocytosis
|
| 229 |
+
# check if comp1 and comp2 have the same Outside (and both contain some volume)
|
| 230 |
+
return -1 if ( defined $comp1->Outside
|
| 231 |
+
and defined $comp2->Outside
|
| 232 |
+
and ($comp1->Outside == $comp2->Outside)
|
| 233 |
+
and exists $comp1->Inside->[0]
|
| 234 |
+
and exists $comp2->Inside->[0]
|
| 235 |
+
);
|
| 236 |
+
|
| 237 |
+
# endocytosis
|
| 238 |
+
# Check if comp1 Outside == comp2 Inside
|
| 239 |
+
return 1 if ( defined $comp1->Outside
|
| 240 |
+
and defined $comp1->Outside->Outside
|
| 241 |
+
and ($comp1->Outside->Outside == $comp2)
|
| 242 |
+
and exists $comp1->Inside->[0]
|
| 243 |
+
and defined $comp2->Inside
|
| 244 |
+
);
|
| 245 |
+
|
| 246 |
+
# endocytosis
|
| 247 |
+
# Check if comp2 Outside == comp1 Inside
|
| 248 |
+
return 1 if ( defined $comp2->Outside
|
| 249 |
+
and defined $comp2->Outside->Outside
|
| 250 |
+
and ($comp2->Outside->Outside == $comp1)
|
| 251 |
+
and exists $comp2->Inside->[0]
|
| 252 |
+
and defined $comp1->Outside
|
| 253 |
+
);
|
| 254 |
+
|
| 255 |
+
return 0;
|
| 256 |
+
}
|
| 257 |
+
|
| 258 |
+
|
| 259 |
+
|
| 260 |
+
|
| 261 |
+
sub connected {
|
| 262 |
+
# $bool = connected( $comp1, $comp2, .. $comp3 );
|
| 263 |
+
# check if a list of compartments are connected
|
| 264 |
+
my @nodes_conn= (shift);
|
| 265 |
+
my @nodes_left= @_;
|
| 266 |
+
|
| 267 |
+
my $link_found;
|
| 268 |
+
while(@nodes_left){
|
| 269 |
+
$link_found=0;
|
| 270 |
+
for my $n1 (@nodes_conn){
|
| 271 |
+
for my $i (0..$#nodes_left){
|
| 272 |
+
if ($n1->adjacent($nodes_left[$i])){
|
| 273 |
+
push @nodes_conn, $nodes_left[$i];
|
| 274 |
+
splice @nodes_left, $i, 1;
|
| 275 |
+
$link_found=1;
|
| 276 |
+
last;
|
| 277 |
+
}
|
| 278 |
+
}
|
| 279 |
+
last if $link_found;
|
| 280 |
+
}
|
| 281 |
+
last unless $link_found;
|
| 282 |
+
}
|
| 283 |
+
# Compartment graph is not connected unless link was found on last loop
|
| 284 |
+
return($link_found)
|
| 285 |
+
}
|
| 286 |
+
|
| 287 |
+
|
| 288 |
+
|
| 289 |
+
|
| 290 |
+
sub toString{
|
| 291 |
+
my $comp=shift;
|
| 292 |
+
my $plist=(@_) ? shift : "";
|
| 293 |
+
|
| 294 |
+
my $string="";
|
| 295 |
+
|
| 296 |
+
$string.=$comp->Name;
|
| 297 |
+
$string.=" ".$comp->SpatialDimensions;
|
| 298 |
+
if ($plist){
|
| 299 |
+
$string.=" ".$comp->Size->toString($plist);
|
| 300 |
+
}
|
| 301 |
+
if (my $ccomp=$comp->Outside){
|
| 302 |
+
$string.=" ".$ccomp->Name;
|
| 303 |
+
}
|
| 304 |
+
return($string);
|
| 305 |
+
}
|
| 306 |
+
|
| 307 |
+
|
| 308 |
+
|
| 309 |
+
|
| 310 |
+
sub toXML{
|
| 311 |
+
my $comp=shift;
|
| 312 |
+
my $indent=shift;
|
| 313 |
+
my $plist = (@_) ? shift : undef;
|
| 314 |
+
|
| 315 |
+
my $string=$indent."<compartment";
|
| 316 |
+
|
| 317 |
+
# Attributes
|
| 318 |
+
# id
|
| 319 |
+
$string.=" id=\"".$comp->Name."\"";
|
| 320 |
+
# spatialDimensions
|
| 321 |
+
$string.= " spatialDimensions=\"".$comp->SpatialDimensions."\"";
|
| 322 |
+
# size
|
| 323 |
+
my $size = $comp->Size->toString();
|
| 324 |
+
unless ( BNGUtils::isReal($size) )
|
| 325 |
+
{ $size = $comp->Size->evaluate($plist); } # evaluate to a number
|
| 326 |
+
# $string.= " size=\"".$comp->Size->toString()."\"";
|
| 327 |
+
$string.= " size=\"".$size."\"";
|
| 328 |
+
# outside
|
| 329 |
+
if ($comp->Outside){
|
| 330 |
+
$string.= " outside=\"".$comp->Outside->Name."\"";
|
| 331 |
+
}
|
| 332 |
+
|
| 333 |
+
$string.="/>\n"; # short tag termination
|
| 334 |
+
|
| 335 |
+
return($string);
|
| 336 |
+
}
|
| 337 |
+
|
| 338 |
+
############DB###################
|
| 339 |
+
# This function calculates scaling factor for the compartment volumes/areas of compartments based on the user-specified volumes
|
| 340 |
+
#provided in the BNGL file. The scaling is determined by the ration of the user-specified volume and the default volume of a
|
| 341 |
+
# M-cell produced geometry, which in this case is a sphere. The default size of a MCell/Blender-created is r = 1 micron (volume
|
| 342 |
+
# = 4.19 cubic micron, and surface area is 12.57 sq. micron. The function first determines size of a sphere based on the sum of
|
| 343 |
+
# all nested compartment volumes (by calling the getMDLSize function). It then determines the linear scaling factor, which is the
|
| 344 |
+
# ratio from the volume of the sphere and the volume of the MCell/Blender-created default sphere. In addition, the function
|
| 345 |
+
# stores the first word from the first line into a hash called %shape. The first word referes to the name of the geometry object itself (in this
|
| 346 |
+
# case it is "Sphere".
|
| 347 |
+
|
| 348 |
+
|
| 349 |
+
sub getMDLgeometry
|
| 350 |
+
{
|
| 351 |
+
my $comp = shift;
|
| 352 |
+
my $plist = shift;
|
| 353 |
+
my $geometry = shift;
|
| 354 |
+
my $object = shift;
|
| 355 |
+
my $shape = shift;
|
| 356 |
+
my $scale = shift;
|
| 357 |
+
my $string = "";
|
| 358 |
+
|
| 359 |
+
my $surf;
|
| 360 |
+
my $i=0;
|
| 361 |
+
foreach (@{$geometry}){
|
| 362 |
+
if ($_ =~ /POLYGON_LIST/){
|
| 363 |
+
$object->{$comp->Name} = $_;
|
| 364 |
+
$object->{$comp->Name} =~ s/POLYGON_LIST//;
|
| 365 |
+
$object->{$comp->Name} =~ s/^\s*//;
|
| 366 |
+
$object->{$comp->Name} =~ s/\s*$//;
|
| 367 |
+
$object->{$comp->Name} = $comp->Name."_".$object->{$comp->Name};
|
| 368 |
+
}
|
| 369 |
+
|
| 370 |
+
if ($_ =~ /DEFINE_SURFACE_REGIONS/){
|
| 371 |
+
$surf = $geometry->[$i+2];
|
| 372 |
+
$surf =~ s/^\s*//;
|
| 373 |
+
$surf =~ s/\s*$//;
|
| 374 |
+
}
|
| 375 |
+
++$i;
|
| 376 |
+
}
|
| 377 |
+
|
| 378 |
+
my $volume_mcell;
|
| 379 |
+
my $area_mcell;
|
| 380 |
+
my $volume;
|
| 381 |
+
my $area;
|
| 382 |
+
|
| 383 |
+
if ($object->{$comp->Name} =~ /Sphere/){
|
| 384 |
+
$volume_mcell = 4.1904762; # Default volume of sphere in Blender;
|
| 385 |
+
$area_mcell = 12.571429; # Default surface area of sphere in Blender;
|
| 386 |
+
$volume = getMDLSize($comp, $plist); # Volume of sphere inclosing the compartment and nested inside compartments
|
| 387 |
+
$area = 4.836624601*($volume)**(2/3); # Surface area of sphere
|
| 388 |
+
}
|
| 389 |
+
|
| 390 |
+
|
| 391 |
+
if ((!$comp->Outside) || ($comp->SpatialDimensions == 2)){ # Write geometries defined by 2D surfaces
|
| 392 |
+
$string = join "", map {$_=~ /POLYGON_LIST/ ? $comp->Name."_".$_ : $_ } (@{$geometry});
|
| 393 |
+
$shape->{$comp->Name} .= $object->{$comp->Name}."[$surf]";
|
| 394 |
+
my ($volume, $area) = ($comp->SpatialDimensions == 3) ? ($volume, undef) : (undef, $area);
|
| 395 |
+
# $volume is relevant only in the case of the outermost space if it has no defined boundary (in BNGL).
|
| 396 |
+
$scale->{$comp->Name} = (defined $volume) ? ($volume/$volume_mcell)**(1/3) : sqrt($area/$area_mcell);
|
| 397 |
+
}
|
| 398 |
+
|
| 399 |
+
if (@{$comp->Inside}){
|
| 400 |
+
foreach my $incomp (@{$comp->Inside}){
|
| 401 |
+
$string .= getMDLgeometry($incomp,$plist,$geometry,$object,$shape,$scale); # Recursive call
|
| 402 |
+
}
|
| 403 |
+
}
|
| 404 |
+
return $string;
|
| 405 |
+
}
|
| 406 |
+
|
| 407 |
+
# This function returns a reference to an array. The first array element is a compartment name. Subsequent elements are the names of nested compartments.
|
| 408 |
+
sub getMDLRelSite
|
| 409 |
+
{
|
| 410 |
+
my $comp = shift;
|
| 411 |
+
my @array;
|
| 412 |
+
if ($comp->SpatialDimensions == 2){
|
| 413 |
+
push(@array, $comp->Name); # The array contains a single element because membrane compartment does not hold any nested compartments.
|
| 414 |
+
return \@array;
|
| 415 |
+
}
|
| 416 |
+
|
| 417 |
+
push (@array, $comp->Outside ? $comp->Outside->Name : $comp->Name); # If outermost 3D space, then name the 'hypothetical' outer membrane with the same name as the compartment
|
| 418 |
+
foreach (@{$comp->Inside}){
|
| 419 |
+
push (@array, $_->Name); # First element is the primary compartment. Subsequent elements are nested compartments.
|
| 420 |
+
}
|
| 421 |
+
return \@array;
|
| 422 |
+
}
|
| 423 |
+
|
| 424 |
+
# This function calculates total volume of a sphere (i.e., volume of (compartment + all inside compartments).
|
| 425 |
+
# Membrane volume is assumed zero regardless of the user-assigned value
|
| 426 |
+
# because potential contradiction can arise from independently assigning both the membrane and enclosed volume size
|
| 427 |
+
# Size of a sphere is only based on the assigned 3D volumes.
|
| 428 |
+
|
| 429 |
+
sub getMDLSize
|
| 430 |
+
{
|
| 431 |
+
my $comp = shift;
|
| 432 |
+
my $plist = shift;
|
| 433 |
+
my $custom_geometry = shift;
|
| 434 |
+
my $volume = 0;
|
| 435 |
+
my $childvolume = 0;
|
| 436 |
+
|
| 437 |
+
$volume = $comp->Size->evaluate($plist);
|
| 438 |
+
return $volume if ($custom_geometry);
|
| 439 |
+
|
| 440 |
+
$volume = 0 if ($comp->SpatialDimensions == 2);
|
| 441 |
+
|
| 442 |
+
foreach my $child (@{$comp->Inside}){ # Calculate volume of all nested compartments inside the current compartment
|
| 443 |
+
$childvolume = $childvolume + $child->getMDLSize($plist, $custom_geometry);
|
| 444 |
+
}
|
| 445 |
+
$volume = $volume + $childvolume; # Sphere volume = volume of (current compartment + all nested compartments inside)
|
| 446 |
+
return ($volume);
|
| 447 |
+
}
|
| 448 |
+
|
| 449 |
+
1;
|
data/bionetgen/Perl2/CompartmentList.pm
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# $Id:$
|
| 2 |
+
|
| 3 |
+
package CompartmentList;
|
| 4 |
+
|
| 5 |
+
# pragmas
|
| 6 |
+
use strict;
|
| 7 |
+
use warnings;
|
| 8 |
+
|
| 9 |
+
# Perl Modules
|
| 10 |
+
use Class::Struct;
|
| 11 |
+
use FindBin;
|
| 12 |
+
use lib $FindBin::Bin;
|
| 13 |
+
|
| 14 |
+
# BNG Modules
|
| 15 |
+
use Compartment;
|
| 16 |
+
use ParamList;
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
struct CompartmentList =>
|
| 22 |
+
{
|
| 23 |
+
Array => '@', # list of Compartments
|
| 24 |
+
Hash => '%', # map from Compartment name to compartment object ref.
|
| 25 |
+
Used => '$' # Flag to indicate that compartment attribute is set in 1 or more species in model
|
| 26 |
+
};
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
# copy the entire CompartmentList and all Compartments it contains
|
| 30 |
+
sub copy
|
| 31 |
+
{
|
| 32 |
+
my $clist = shift @_;
|
| 33 |
+
my $plist = @_ ? shift @_ : undef;
|
| 34 |
+
|
| 35 |
+
# create copy of list
|
| 36 |
+
my $clist_copy = CompartmentList->new();
|
| 37 |
+
foreach my $comp ( @{$clist->Array} )
|
| 38 |
+
{
|
| 39 |
+
my $comp_copy = $comp->copy( $plist );
|
| 40 |
+
push @{$clist_copy->Array}, $comp_copy;
|
| 41 |
+
$clist_copy->Hash->{$comp_copy->Name} = $comp_copy;
|
| 42 |
+
}
|
| 43 |
+
$clist_copy->Used($clist->Used); # TODO: is this the best assumption?
|
| 44 |
+
|
| 45 |
+
# fix links to inside and outside neighbors
|
| 46 |
+
foreach my $comp ( @{$clist_copy->Array} )
|
| 47 |
+
{
|
| 48 |
+
$comp->relinkNeighbors( $clist_copy );
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
return $clist_copy;
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
###
|
| 56 |
+
###
|
| 57 |
+
###
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
sub getNumCompartments
|
| 62 |
+
{
|
| 63 |
+
my $clist = shift;
|
| 64 |
+
return scalar @{$clist->Array};
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
###
|
| 69 |
+
###
|
| 70 |
+
###
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
# lookup a compartment by name. Returns reference or empty string
|
| 74 |
+
sub lookup
|
| 75 |
+
{
|
| 76 |
+
my $clist = shift;
|
| 77 |
+
my $name = shift;
|
| 78 |
+
|
| 79 |
+
if ( exists $clist->Hash->{$name} )
|
| 80 |
+
{
|
| 81 |
+
return $clist->Hash->{$name};
|
| 82 |
+
}
|
| 83 |
+
else
|
| 84 |
+
{
|
| 85 |
+
return '';
|
| 86 |
+
}
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
###
|
| 91 |
+
###
|
| 92 |
+
###
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
sub add
|
| 96 |
+
# '' = @clist->add( cref1, cref2, ... crefN )
|
| 97 |
+
# add compartment to a compartment list
|
| 98 |
+
# updated by justinshogg@gmail.com 17feb2009
|
| 99 |
+
# overloaded method to add compartments by
|
| 100 |
+
# reference.
|
| 101 |
+
{
|
| 102 |
+
my $clist = shift; # CompartmentList ref
|
| 103 |
+
my $comp = shift;
|
| 104 |
+
|
| 105 |
+
ref $comp eq 'Compartment'
|
| 106 |
+
|| return "CompartmentList: Attempt to add non-compartment object $comp to CompartmentList.";
|
| 107 |
+
|
| 108 |
+
if ( exists $clist->Hash->{ $comp->Name } )
|
| 109 |
+
{ # compartment with same name is already in list
|
| 110 |
+
# swap old compartment for the new one
|
| 111 |
+
my $cref = $clist->Hash->{ $comp->Name };
|
| 112 |
+
%{$cref} = %{$comp};
|
| 113 |
+
}
|
| 114 |
+
else
|
| 115 |
+
{ # add new compartment
|
| 116 |
+
$clist->Hash->{ $comp->Name } = $comp;
|
| 117 |
+
push @{$clist->Array}, $comp;
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
# continue adding compartments (recursive)
|
| 121 |
+
if ( @_ )
|
| 122 |
+
{ return $clist->add(@_); }
|
| 123 |
+
else
|
| 124 |
+
{ return ''; }
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
sub toString
|
| 131 |
+
{
|
| 132 |
+
my $clist = shift;
|
| 133 |
+
my $plist = (@_) ? shift : undef;
|
| 134 |
+
|
| 135 |
+
my $string = "begin compartments\n";
|
| 136 |
+
foreach my $comp (@{$clist->Array}){
|
| 137 |
+
$string .= ' ' . $comp->toString($plist) . "\n";
|
| 138 |
+
}
|
| 139 |
+
$string .= "end compartments\n";
|
| 140 |
+
|
| 141 |
+
return $string;
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
sub readString
|
| 148 |
+
# $err = $clist->readString(compartment_string,param_list)
|
| 149 |
+
# Reads a single compartment specification from a string with the following format:
|
| 150 |
+
# name type volume [outside compartments]
|
| 151 |
+
# updates by justinshogg@gmail.com 17feb2009
|
| 152 |
+
{
|
| 153 |
+
my $clist = shift; # CompartmentList
|
| 154 |
+
my $string = shift; # compartment string to parse
|
| 155 |
+
my $plist = shift; # parameter list
|
| 156 |
+
|
| 157 |
+
# Remove leading whitespace
|
| 158 |
+
$string =~ s/^\s*//;
|
| 159 |
+
|
| 160 |
+
# Remove leading label, if any
|
| 161 |
+
if ($string =~ s/^\s*(\w+)\s*:\s+//)
|
| 162 |
+
{
|
| 163 |
+
# Check label for leading number
|
| 164 |
+
my $label = $1;
|
| 165 |
+
if ($label =~ /^\d/) { return "Syntax error (label begins with a number) at '$label'"; }
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
# Read name (required argument), check for starting number
|
| 169 |
+
$string =~ s/^([A-Za-z_]\w*)// or return "Invalid compartment name in '$string' (must begin with a letter or underscore)";
|
| 170 |
+
my $name = $1;
|
| 171 |
+
|
| 172 |
+
# Read spatialDimensions (required argument)
|
| 173 |
+
$string =~ s/^\s*(\d+)// or return "Invalid Spatial Dimensions for Compartment in '$string'";
|
| 174 |
+
my $spatialDimensions = $1;
|
| 175 |
+
# moved spatial dimension check to newCompartment sub in Compartment module
|
| 176 |
+
|
| 177 |
+
# Read size expression (required argument, expression created on the fly)
|
| 178 |
+
my $size = Expression->new();
|
| 179 |
+
$size->setAllowForward(1);
|
| 180 |
+
$size->readString(\$string, $plist) and return $_;
|
| 181 |
+
|
| 182 |
+
# Read outside compartment (optional argument, but compartment must be in list if specified)
|
| 183 |
+
my $outside = undef;
|
| 184 |
+
if ( $string =~ s/^([A-Za-z_0-9]+)\s*// )
|
| 185 |
+
{
|
| 186 |
+
my $cname = $1;
|
| 187 |
+
# Get compartment reference
|
| 188 |
+
$outside = $clist->Hash->{$cname}
|
| 189 |
+
|| return("Outside compartment $cname is not in CompartmentList");
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
# check for extraneous arguments
|
| 193 |
+
if ( $string =~ /\S+/ )
|
| 194 |
+
{ return "Unrecognized trailing syntax in compartment specification"; }
|
| 195 |
+
|
| 196 |
+
# create compartment
|
| 197 |
+
my ($comp, $err) = Compartment->newCompartment($name, $spatialDimensions, $size, $outside);
|
| 198 |
+
return $err if ($err);
|
| 199 |
+
|
| 200 |
+
# add compartment to list
|
| 201 |
+
return $clist->add($comp);
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
|
| 206 |
+
|
| 207 |
+
sub toXML
|
| 208 |
+
{
|
| 209 |
+
my $clist = shift;
|
| 210 |
+
my $indent = shift;
|
| 211 |
+
my $plist = (@_) ? shift : undef;
|
| 212 |
+
|
| 213 |
+
my $string = $indent."<ListOfCompartments>\n";
|
| 214 |
+
|
| 215 |
+
foreach my $comp (@{$clist->Array}){
|
| 216 |
+
$string .= $comp->toXML(" ".$indent, $plist);
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
$string .= $indent."</ListOfCompartments>\n";
|
| 220 |
+
return $string;
|
| 221 |
+
}
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
|
| 225 |
+
|
| 226 |
+
sub validate
|
| 227 |
+
{
|
| 228 |
+
my $clist = shift;
|
| 229 |
+
|
| 230 |
+
foreach my $comp (@{$clist->Array})
|
| 231 |
+
{
|
| 232 |
+
if ($comp->SpatialDimensions eq '')
|
| 233 |
+
{
|
| 234 |
+
my $err = sprintf "Compartment %s referred to but not defined", $comp->Name;
|
| 235 |
+
}
|
| 236 |
+
}
|
| 237 |
+
return '';
|
| 238 |
+
}
|
| 239 |
+
|
| 240 |
+
1;
|
data/bionetgen/Perl2/Component.pm
ADDED
|
@@ -0,0 +1,453 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# $Id: Component.pm,v 1.10 2007/01/22 19:22:48 faeder Exp $
|
| 2 |
+
|
| 3 |
+
package Component;
|
| 4 |
+
|
| 5 |
+
# pragmas
|
| 6 |
+
use strict;
|
| 7 |
+
use warnings;
|
| 8 |
+
|
| 9 |
+
# Perl Modules
|
| 10 |
+
use Class::Struct;
|
| 11 |
+
use FindBin;
|
| 12 |
+
use lib $FindBin::Bin;
|
| 13 |
+
|
| 14 |
+
# BNG Modules
|
| 15 |
+
use BNGUtils;
|
| 16 |
+
use Compartment;
|
| 17 |
+
|
| 18 |
+
# constants
|
| 19 |
+
use constant { TRUE => 1,
|
| 20 |
+
FALSE => 0
|
| 21 |
+
};
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
struct Component => {
|
| 25 |
+
Name => '$',
|
| 26 |
+
State => '$',
|
| 27 |
+
#Type => 'ComponentType',
|
| 28 |
+
Edges => '@',
|
| 29 |
+
Label => '$',
|
| 30 |
+
Compartment => 'Compartment'
|
| 31 |
+
};
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
###
|
| 36 |
+
###
|
| 37 |
+
###
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
sub newComponent
|
| 42 |
+
{
|
| 43 |
+
my $strptr = shift;
|
| 44 |
+
|
| 45 |
+
my $comp = Component->new();
|
| 46 |
+
my $err = $comp->readString($strptr);
|
| 47 |
+
|
| 48 |
+
return ($comp, $err);
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
###
|
| 54 |
+
###
|
| 55 |
+
###
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
sub readString
|
| 60 |
+
{
|
| 61 |
+
my $comp = shift @_;
|
| 62 |
+
my $strptr = shift @_;
|
| 63 |
+
my $clist = @_ ? shift @_ : undef;
|
| 64 |
+
|
| 65 |
+
my $string_left = $$strptr;
|
| 66 |
+
|
| 67 |
+
# Get component name (cannot start with a number)
|
| 68 |
+
if ( $string_left =~ s/^([A-Za-z_]\w*)// )
|
| 69 |
+
{
|
| 70 |
+
$comp->Name($1);
|
| 71 |
+
}
|
| 72 |
+
else
|
| 73 |
+
{
|
| 74 |
+
return undef, "Invalid component name in '$string_left' (must begin with a letter or underscore).";
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
# Get component state (marked by ~) edges (marked by !) and label (marked by %)
|
| 78 |
+
my $edge_wildcard = 0;
|
| 79 |
+
my $edge_labels = 0;
|
| 80 |
+
while ($string_left)
|
| 81 |
+
{
|
| 82 |
+
if ( $string_left =~ s/^([~%!@])(\w+|\+|\?)// )
|
| 83 |
+
{
|
| 84 |
+
my $type = $1;
|
| 85 |
+
my $arg = $2;
|
| 86 |
+
if ($type eq '~')
|
| 87 |
+
{
|
| 88 |
+
# State label
|
| 89 |
+
if (defined $comp->State)
|
| 90 |
+
{ return undef, "Multiple state definitions"; }
|
| 91 |
+
$comp->State($arg);
|
| 92 |
+
}
|
| 93 |
+
elsif ($type eq '!')
|
| 94 |
+
{
|
| 95 |
+
# Bond label or wildcard
|
| 96 |
+
if ( $arg =~ /^[+?]$/ )
|
| 97 |
+
{
|
| 98 |
+
if ($edge_wildcard or $edge_labels)
|
| 99 |
+
{ return undef, "Multiple edge wildcards in component"; }
|
| 100 |
+
$edge_wildcard=1;
|
| 101 |
+
}
|
| 102 |
+
else
|
| 103 |
+
{
|
| 104 |
+
if ($edge_wildcard)
|
| 105 |
+
{ return undef, "Labeled edges mixed with wildcard"; }
|
| 106 |
+
}
|
| 107 |
+
push @{$comp->Edges}, $arg;
|
| 108 |
+
}
|
| 109 |
+
elsif ($type eq '%')
|
| 110 |
+
{
|
| 111 |
+
# Tag label
|
| 112 |
+
if (defined $comp->Label)
|
| 113 |
+
{ return undef, "Multiple label definitions"; }
|
| 114 |
+
$comp->Label($arg);
|
| 115 |
+
}
|
| 116 |
+
elsif ($type eq '@')
|
| 117 |
+
{
|
| 118 |
+
# Compartment label
|
| 119 |
+
if (defined $comp->Compartment)
|
| 120 |
+
{ return undef, "Multiple compartment definitions"; }
|
| 121 |
+
|
| 122 |
+
if ( defined $clist )
|
| 123 |
+
{
|
| 124 |
+
if ( my $compart = $clist->lookup($arg) )
|
| 125 |
+
{ $comp->Compartment($compart); }
|
| 126 |
+
}
|
| 127 |
+
else
|
| 128 |
+
{
|
| 129 |
+
return undef, "Undefined compartment $arg";
|
| 130 |
+
}
|
| 131 |
+
}
|
| 132 |
+
}
|
| 133 |
+
elsif ( $string_left =~ /^[,)]/ )
|
| 134 |
+
{ # Terminator characters for component
|
| 135 |
+
last;
|
| 136 |
+
}
|
| 137 |
+
else
|
| 138 |
+
{ return undef, "Invalid syntax at $string_left"; }
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
$$strptr = $string_left;
|
| 142 |
+
return '';
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
###
|
| 148 |
+
###
|
| 149 |
+
###
|
| 150 |
+
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
sub toString
|
| 154 |
+
{
|
| 155 |
+
my $comp = shift @_;
|
| 156 |
+
my $print_edges = @_ ? shift @_ : TRUE;
|
| 157 |
+
my $print_attributes = @_ ? shift @_ : TRUE;
|
| 158 |
+
|
| 159 |
+
my $string .= $comp->Name;
|
| 160 |
+
|
| 161 |
+
if (defined $comp->State )
|
| 162 |
+
{ $string .= sprintf "~%s", $comp->State; }
|
| 163 |
+
|
| 164 |
+
if ($print_attributes)
|
| 165 |
+
{ $string .= sprintf("%%%s", $comp->Label) if (defined $comp->Label); }
|
| 166 |
+
|
| 167 |
+
if ( defined $comp->Compartment )
|
| 168 |
+
{ $string .= sprintf "@%s", $comp->Compartment->Name; }
|
| 169 |
+
|
| 170 |
+
if (defined $comp->Edges )
|
| 171 |
+
{
|
| 172 |
+
if ($print_edges)
|
| 173 |
+
{
|
| 174 |
+
my $wildcard='';
|
| 175 |
+
foreach my $edge (@{$comp->Edges})
|
| 176 |
+
{
|
| 177 |
+
if ($edge=~ /^\d+$/)
|
| 178 |
+
{ $string .= sprintf "!%d", $edge+1; }
|
| 179 |
+
else
|
| 180 |
+
{ $wildcard = "!$edge"; }
|
| 181 |
+
}
|
| 182 |
+
$string .= $wildcard;
|
| 183 |
+
}
|
| 184 |
+
else
|
| 185 |
+
{ $string .= "!" x @{$comp->Edges}; }
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
return $string;
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
+
|
| 192 |
+
|
| 193 |
+
###
|
| 194 |
+
###
|
| 195 |
+
###
|
| 196 |
+
|
| 197 |
+
|
| 198 |
+
|
| 199 |
+
sub toStringSSC
|
| 200 |
+
{
|
| 201 |
+
my $comp = shift @_;
|
| 202 |
+
my $comp_label = @_ ? shift @_: 0;
|
| 203 |
+
my $print_edges = @_ ? shift @_ : TRUE;
|
| 204 |
+
|
| 205 |
+
my $string = $comp->Name;
|
| 206 |
+
if ( $comp_label != 0 ) { $string .= $comp_label; } # for checking components with same name
|
| 207 |
+
# if comp_label != 0 same component exists
|
| 208 |
+
|
| 209 |
+
if (defined $comp->Label)
|
| 210 |
+
{ printf STDERR "ERROR: SSC Does not implement Label \n"; }
|
| 211 |
+
|
| 212 |
+
if (defined $comp->Compartment)
|
| 213 |
+
{ printf STDERR "ERROR: Compartments not implemented \n"; }
|
| 214 |
+
|
| 215 |
+
if (defined $comp->State)
|
| 216 |
+
{
|
| 217 |
+
$string.= sprintf "=\"%s\"", $comp->State;
|
| 218 |
+
if ($comp_label ==0 )
|
| 219 |
+
{ # just appends <component name>Binds, as SSC doesnt allow states to bind
|
| 220 |
+
$string .= ", " . $comp->Name . "Binds";
|
| 221 |
+
}
|
| 222 |
+
else
|
| 223 |
+
{
|
| 224 |
+
$string .= ", " . $comp->Name . $comp_label ."Binds";
|
| 225 |
+
}
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
if (defined $comp->Edges)
|
| 229 |
+
{
|
| 230 |
+
$string .= "#"; #As SSC considers every non-bound component as empty, so attaching #
|
| 231 |
+
if ($print_edges)
|
| 232 |
+
{
|
| 233 |
+
my $wildcard="";
|
| 234 |
+
foreach my $edge (@{$comp->Edges})
|
| 235 |
+
{
|
| 236 |
+
if ($edge=~ /^\d+$/)
|
| 237 |
+
{
|
| 238 |
+
$string.= sprintf "%d", $edge+1;
|
| 239 |
+
}
|
| 240 |
+
else
|
| 241 |
+
{
|
| 242 |
+
$wildcard="$edge";
|
| 243 |
+
}
|
| 244 |
+
$string.=$wildcard;
|
| 245 |
+
}
|
| 246 |
+
}
|
| 247 |
+
else
|
| 248 |
+
{
|
| 249 |
+
$string.= ""x scalar(@{$comp->Edges});
|
| 250 |
+
}
|
| 251 |
+
}
|
| 252 |
+
$string =~ s/\+/_/; # SSC equivalent of '+' is '_', substituting that
|
| 253 |
+
return $string;
|
| 254 |
+
}
|
| 255 |
+
|
| 256 |
+
|
| 257 |
+
|
| 258 |
+
###
|
| 259 |
+
###
|
| 260 |
+
###
|
| 261 |
+
|
| 262 |
+
|
| 263 |
+
|
| 264 |
+
sub toXML
|
| 265 |
+
{
|
| 266 |
+
my $comp = shift @_;
|
| 267 |
+
my $indent = shift @_;
|
| 268 |
+
my $id = shift @_;
|
| 269 |
+
my $index = (@_) ? shift @_ : '';
|
| 270 |
+
|
| 271 |
+
my $string = $indent . "<Component";
|
| 272 |
+
|
| 273 |
+
# Attributes
|
| 274 |
+
# id
|
| 275 |
+
my $cid = sprintf "${id}_C%d", $index;
|
| 276 |
+
$string .= " id=\"".$cid."\"";
|
| 277 |
+
# type
|
| 278 |
+
$string .= " name=\"" . $comp->Name . "\"";
|
| 279 |
+
# state
|
| 280 |
+
if (defined $comp->State)
|
| 281 |
+
{
|
| 282 |
+
$string .= " state=\"" . $comp->State . "\"";
|
| 283 |
+
}
|
| 284 |
+
if (defined $comp->Label)
|
| 285 |
+
{
|
| 286 |
+
$string .= " label=\"" . $comp->Label . "\"";
|
| 287 |
+
}
|
| 288 |
+
if ($comp->Compartment)
|
| 289 |
+
{
|
| 290 |
+
$string .= " compartment=\"" . $comp->Compartment->Name . "\"";
|
| 291 |
+
}
|
| 292 |
+
|
| 293 |
+
# NumberOfBonds
|
| 294 |
+
my $nbonds = 0;
|
| 295 |
+
my $wildcard = '';
|
| 296 |
+
foreach my $edge (@{$comp->Edges})
|
| 297 |
+
{
|
| 298 |
+
if ($edge=~ /^[?+]$/)
|
| 299 |
+
{
|
| 300 |
+
$wildcard = $edge;
|
| 301 |
+
}
|
| 302 |
+
else
|
| 303 |
+
{
|
| 304 |
+
++$nbonds;
|
| 305 |
+
}
|
| 306 |
+
}
|
| 307 |
+
if ($wildcard)
|
| 308 |
+
{
|
| 309 |
+
$nbonds = ($nbonds>0) ? $nbonds.$wildcard : $wildcard;
|
| 310 |
+
}
|
| 311 |
+
$string .= " numberOfBonds=\"" . $nbonds . "\"";
|
| 312 |
+
|
| 313 |
+
# Objects contained
|
| 314 |
+
my $indent2 = ' ' . $indent;
|
| 315 |
+
my $ostring = '';
|
| 316 |
+
|
| 317 |
+
# Termination
|
| 318 |
+
if ($ostring)
|
| 319 |
+
{ # terminate tag opening
|
| 320 |
+
$string .= ">\n";
|
| 321 |
+
$string .= $ostring;
|
| 322 |
+
$string .= $indent . "</Component>\n";
|
| 323 |
+
}
|
| 324 |
+
else
|
| 325 |
+
{ # short tag termination
|
| 326 |
+
$string .= "/>\n";
|
| 327 |
+
}
|
| 328 |
+
}
|
| 329 |
+
|
| 330 |
+
|
| 331 |
+
|
| 332 |
+
###
|
| 333 |
+
###
|
| 334 |
+
###
|
| 335 |
+
|
| 336 |
+
|
| 337 |
+
|
| 338 |
+
# Make an exact copy of a component.
|
| 339 |
+
sub copy
|
| 340 |
+
{
|
| 341 |
+
# get component that we want to copy
|
| 342 |
+
my $comp = shift @_;
|
| 343 |
+
# should we copy labels?
|
| 344 |
+
my $copy_labels = (@_) ? shift @_ : 1;
|
| 345 |
+
# prefix for edge names?
|
| 346 |
+
my $prefix = (@_) ? shift @_ : '';
|
| 347 |
+
|
| 348 |
+
# create a new component
|
| 349 |
+
my $comp_copy = Component->new();
|
| 350 |
+
|
| 351 |
+
# copy scalar attributes
|
| 352 |
+
$comp_copy->Name( $comp->Name );
|
| 353 |
+
$comp_copy->Label( $comp->Label ) if ($copy_labels);
|
| 354 |
+
$comp_copy->State( $comp->State );
|
| 355 |
+
$comp_copy->Compartment( $comp->Compartment ) if (defined $comp->Compartment);
|
| 356 |
+
|
| 357 |
+
# copy edges
|
| 358 |
+
if ( @{$comp->Edges} )
|
| 359 |
+
{
|
| 360 |
+
# add prefix to edge label, unless its a wildcard
|
| 361 |
+
$comp_copy->Edges( [map {$_=~/^[*+?]$/ ? $_ : $prefix.$_} @{$comp->Edges}] );
|
| 362 |
+
}
|
| 363 |
+
|
| 364 |
+
# return the copy component
|
| 365 |
+
return $comp_copy;
|
| 366 |
+
}
|
| 367 |
+
|
| 368 |
+
|
| 369 |
+
|
| 370 |
+
###
|
| 371 |
+
###
|
| 372 |
+
###
|
| 373 |
+
|
| 374 |
+
|
| 375 |
+
|
| 376 |
+
# call this method to link Compartments to a new CompartmentList
|
| 377 |
+
sub relinkCompartments
|
| 378 |
+
{
|
| 379 |
+
my $comp = shift @_;
|
| 380 |
+
my $clist = shift @_;
|
| 381 |
+
|
| 382 |
+
my $err;
|
| 383 |
+
unless ( ref $clist eq 'CompartmentList' )
|
| 384 |
+
{ return "Component->relinkCompartments: Error!! Method called without CompartmentList object"; }
|
| 385 |
+
|
| 386 |
+
if ( defined $comp->Compartment )
|
| 387 |
+
{
|
| 388 |
+
my $new_compart = $clist->lookup( $comp->Compartment->Name );
|
| 389 |
+
unless ($new_compart)
|
| 390 |
+
{ return "Molecule->relinkCompartments: Error!! could not find compartment name in list"; }
|
| 391 |
+
$comp->Compartment( $new_compart );
|
| 392 |
+
}
|
| 393 |
+
|
| 394 |
+
return undef;
|
| 395 |
+
}
|
| 396 |
+
|
| 397 |
+
|
| 398 |
+
|
| 399 |
+
###
|
| 400 |
+
###
|
| 401 |
+
###
|
| 402 |
+
|
| 403 |
+
|
| 404 |
+
|
| 405 |
+
# Component comparison for isomorphism
|
| 406 |
+
sub compare_local
|
| 407 |
+
{
|
| 408 |
+
my $a = shift;
|
| 409 |
+
my $b = shift;
|
| 410 |
+
|
| 411 |
+
my $cmp;
|
| 412 |
+
# Component name
|
| 413 |
+
if ( $cmp = ($a->Name cmp $b->Name) )
|
| 414 |
+
{ return $cmp; }
|
| 415 |
+
|
| 416 |
+
# Component state
|
| 417 |
+
if ( defined $a->State )
|
| 418 |
+
{
|
| 419 |
+
unless (defined $a->State) { return 1; }
|
| 420 |
+
if ( $cmp = ($a->State cmp $b->State) )
|
| 421 |
+
{ return $cmp; }
|
| 422 |
+
}
|
| 423 |
+
elsif ( defined $b->State )
|
| 424 |
+
{
|
| 425 |
+
return -1;
|
| 426 |
+
}
|
| 427 |
+
|
| 428 |
+
# Component compartment
|
| 429 |
+
if ( defined $a->Compartment )
|
| 430 |
+
{
|
| 431 |
+
unless (defined $b->Compartment) { return 1; }
|
| 432 |
+
if ( $cmp = ($a->Compartment <=> $b->Compartment) )
|
| 433 |
+
{ return $cmp; }
|
| 434 |
+
}
|
| 435 |
+
elsif ( defined $b->Compartment )
|
| 436 |
+
{
|
| 437 |
+
return -1;
|
| 438 |
+
}
|
| 439 |
+
|
| 440 |
+
# Number of edges
|
| 441 |
+
if ( $cmp = (@{$a->Edges} <=> @{$b->Edges}) )
|
| 442 |
+
{ return $cmp; }
|
| 443 |
+
|
| 444 |
+
return 0;
|
| 445 |
+
}
|
| 446 |
+
|
| 447 |
+
|
| 448 |
+
|
| 449 |
+
###
|
| 450 |
+
###
|
| 451 |
+
###
|
| 452 |
+
|
| 453 |
+
1;
|
data/b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/01 03:32:43 faeder Exp $
|
| 2 |
+
|
| 3 |
+
# Objects for typing and checking Components of Molecules
|
| 4 |
+
package ComponentType;
|
| 5 |
+
|
| 6 |
+
use Class::Struct;
|
| 7 |
+
use FindBin;
|
| 8 |
+
use lib $FindBin::Bin;
|
| 9 |
+
|
| 10 |
+
struct ComponentType=> {
|
| 11 |
+
Name=> '$',
|
| 12 |
+
States=> '@', # First element of States array is the default state, which
|
| 13 |
+
# is used in creating new molecules that don't have user-specified
|
| 14 |
+
# state attributes.
|
| 15 |
+
Edges=> '@', # Last two are not currently used in checking
|
| 16 |
+
Compartments=> '@'
|
| 17 |
+
};
|
| 18 |
+
sub readString{
|
| 19 |
+
my $ctype= shift;
|
| 20 |
+
my $strptr= shift;
|
| 21 |
+
|
| 22 |
+
my $string_left=$$strptr;
|
| 23 |
+
|
| 24 |
+
# Get component name (cannot start with a number)
|
| 25 |
+
if ( $string_left =~ s/^([A-Za-z_]\w*)// )
|
| 26 |
+
{
|
| 27 |
+
$ctype->Name($1);
|
| 28 |
+
}
|
| 29 |
+
else
|
| 30 |
+
{
|
| 31 |
+
return undef, "Invalid component name in '$string_left' (must begin with a letter or underscore).";
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
# Get component state (marked by ~) edges (marked by !)
|
| 35 |
+
my @states=();
|
| 36 |
+
my @compartments=();
|
| 37 |
+
my @elabels=();
|
| 38 |
+
while ($string_left){
|
| 39 |
+
if ($string_left=~ s/^([~!@])([A-Za-z0-9_]+)//){
|
| 40 |
+
my $type=$1;
|
| 41 |
+
my $arg=$2;
|
| 42 |
+
if ($type eq '~'){
|
| 43 |
+
push @states, $arg;
|
| 44 |
+
}
|
| 45 |
+
elsif ($type eq '!'){
|
| 46 |
+
push @elabels, $arg;
|
| 47 |
+
}
|
| 48 |
+
elsif ($type eq '@'){
|
| 49 |
+
push @compartments, $arg;
|
| 50 |
+
}
|
| 51 |
+
}
|
| 52 |
+
elsif ($string_left=~ /^[,)]/){ # Terminator characters for component
|
| 53 |
+
last;
|
| 54 |
+
}
|
| 55 |
+
else {
|
| 56 |
+
return("Invalid syntax at $string_left");
|
| 57 |
+
}
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
if (@states){
|
| 61 |
+
$ctype->States([@states]);
|
| 62 |
+
}
|
| 63 |
+
if (@elabels){
|
| 64 |
+
$ctype->Edges([@elabels]);
|
| 65 |
+
}
|
| 66 |
+
if (@compartments){
|
| 67 |
+
$ctype->Compartments([@compartments]);
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
$$strptr= $string_left;
|
| 71 |
+
return("");
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
sub copy
|
| 76 |
+
{
|
| 77 |
+
my $comp = shift;
|
| 78 |
+
|
| 79 |
+
my $comp_copy = ComponentType::new();
|
| 80 |
+
$comp_copy->Name( $comp->Name );
|
| 81 |
+
$comp_copy->States( [@{$comp->States}] );
|
| 82 |
+
$comp_copy->Edges( [@{$comp->Edges}] );
|
| 83 |
+
$comp_copy->Compartments( [@{$comp->Compartments}] );
|
| 84 |
+
|
| 85 |
+
return $comp_copy;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
sub toString{
|
| 89 |
+
my $ctype= shift;
|
| 90 |
+
my $string="";
|
| 91 |
+
|
| 92 |
+
$string.= $ctype->Name;
|
| 93 |
+
for my $state (@{$ctype->States}){
|
| 94 |
+
$string.= "~$state";
|
| 95 |
+
}
|
| 96 |
+
return($string);
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
sub toStringSSC{
|
| 100 |
+
my $ctype= shift;
|
| 101 |
+
my $string="";
|
| 102 |
+
$string.= $ctype->Name;
|
| 103 |
+
$string .= "#";
|
| 104 |
+
for my $state (@{$ctype->States}){
|
| 105 |
+
$string.= "=\"$state\"";
|
| 106 |
+
}
|
| 107 |
+
return($string);
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
sub toXML{
|
| 111 |
+
my $ctype= shift;
|
| 112 |
+
my $indent= shift;
|
| 113 |
+
my $string=$indent."<ComponentType";
|
| 114 |
+
|
| 115 |
+
# Attributes
|
| 116 |
+
# id
|
| 117 |
+
$string.=" id=\"".$ctype->Name."\"";
|
| 118 |
+
|
| 119 |
+
# Objects
|
| 120 |
+
my $indent2= " ".$indent;
|
| 121 |
+
my $ostring="";
|
| 122 |
+
if (@{$ctype->States}){
|
| 123 |
+
$ostring.= $indent2."<ListOfAllowedStates>\n";
|
| 124 |
+
for my $state (@{$ctype->States}){
|
| 125 |
+
$ostring.=$indent2." <AllowedState";
|
| 126 |
+
$ostring.=" id=\"".$state."\"";
|
| 127 |
+
$ostring.="/>\n";
|
| 128 |
+
}
|
| 129 |
+
$ostring.= $indent2."</ListOfAllowedStates>\n";
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
if ($ostring){
|
| 133 |
+
$string.=">\n";
|
| 134 |
+
$string.=$ostring;
|
| 135 |
+
$string.=$indent."</ComponentType>\n";
|
| 136 |
+
} else {
|
| 137 |
+
$string.="/>\n";
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
return($string);
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
sub writeMDL
|
| 144 |
+
{
|
| 145 |
+
my $ctype = shift;
|
| 146 |
+
my $string = $ctype->Name;
|
| 147 |
+
|
| 148 |
+
if (@{$ctype->States}){
|
| 149 |
+
foreach my $state (@{$ctype->States}){
|
| 150 |
+
$string .= "~".$state;
|
| 151 |
+
}
|
| 152 |
+
}
|
| 153 |
+
return $string;
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
1;
|
data/bionetgen/Perl2/Console.pm
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This package contains routines for running BNG as an interactive console
|
| 2 |
+
package Console;
|
| 3 |
+
|
| 4 |
+
# pragmas
|
| 5 |
+
use strict;
|
| 6 |
+
use warnings;
|
| 7 |
+
|
| 8 |
+
# Perl Modules
|
| 9 |
+
use FindBin;
|
| 10 |
+
use lib $FindBin::Bin;
|
| 11 |
+
use File::Spec;
|
| 12 |
+
|
| 13 |
+
require Exporter;
|
| 14 |
+
our @ISA = qw( Exporter );
|
| 15 |
+
our @EXPORT = qw( BNGconsole );
|
| 16 |
+
|
| 17 |
+
# BNG Modules
|
| 18 |
+
use BNGUtils;
|
| 19 |
+
use BNGModel;
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
# global variables
|
| 24 |
+
my $BNG_PROMPT = 'BNG> ';
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
sub BNGconsole
|
| 28 |
+
{ # take actions from interactive console!
|
| 29 |
+
my $params = (@_) ? shift : {};
|
| 30 |
+
|
| 31 |
+
# TODO:
|
| 32 |
+
# + differentiate between STDIN from console and file?
|
| 33 |
+
# + add more model query commands
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
# Am I interacting with a user, or a pipeline?
|
| 37 |
+
my $interactive = ( -t STDIN ) ? 1 : 0;
|
| 38 |
+
|
| 39 |
+
# turn off output buffering on STDOUT
|
| 40 |
+
select STDOUT; $| = 1;
|
| 41 |
+
|
| 42 |
+
# say hello!
|
| 43 |
+
printf "BioNetGen version %s\n", BNGversion();
|
| 44 |
+
print "Entering BNG console mode.\n";
|
| 45 |
+
print $BNG_PROMPT;
|
| 46 |
+
|
| 47 |
+
# model begins as undefined
|
| 48 |
+
my $model = undef;
|
| 49 |
+
|
| 50 |
+
# read input
|
| 51 |
+
while ( my $linein = <STDIN> )
|
| 52 |
+
{
|
| 53 |
+
unless ($interactive) { print $linein; }
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
# trim leading and trailing white space
|
| 57 |
+
$linein =~ s/^\s+//;
|
| 58 |
+
$linein =~ s/\s+$//;
|
| 59 |
+
|
| 60 |
+
PROCESS_INPUT:
|
| 61 |
+
{
|
| 62 |
+
# READ a model
|
| 63 |
+
if ( $linein =~ s/^load\s+// )
|
| 64 |
+
{
|
| 65 |
+
if (defined $model)
|
| 66 |
+
{
|
| 67 |
+
send_warning( "Attempted to load model while another model is active." );
|
| 68 |
+
last PROCESS_INPUT;
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
# get filename
|
| 72 |
+
$linein =~ s/^(\S+)\s*//;
|
| 73 |
+
my $filename = $1;
|
| 74 |
+
unless ($filename and -e $filename)
|
| 75 |
+
{
|
| 76 |
+
send_warning( "Attempted to load model, but file '$filename' was not found." );
|
| 77 |
+
last PROCESS_INPUT;
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
# initialize parameters
|
| 81 |
+
my $local_params = { %$params };
|
| 82 |
+
# add filename to params
|
| 83 |
+
$local_params->{file} = $filename;
|
| 84 |
+
|
| 85 |
+
# process long args ('atomize' and 'blocks')
|
| 86 |
+
while ( $linein ){
|
| 87 |
+
my ($key, $val);
|
| 88 |
+
# --atomize INT
|
| 89 |
+
if ( $linein =~ s/\s*--(\w+)\s+(\w+)// ){
|
| 90 |
+
$key = $1;
|
| 91 |
+
$val = $2;
|
| 92 |
+
}
|
| 93 |
+
# --blocks ["STRING", "STRING", ...]
|
| 94 |
+
elsif( $linein =~ s/\s*--(\w+)\s+\[(.+)\]// ){
|
| 95 |
+
$key = $1;
|
| 96 |
+
$val = [ split( '\s*,\s*', $2 ) ];
|
| 97 |
+
foreach my $v (@$val){
|
| 98 |
+
$v = eval $v; # need to evaluate each entry to a string
|
| 99 |
+
}
|
| 100 |
+
}
|
| 101 |
+
else{
|
| 102 |
+
send_warning( "Error processing command line arguments: " . $linein );
|
| 103 |
+
last PROCESS_INPUT;
|
| 104 |
+
}
|
| 105 |
+
$local_params->{$key} = $val;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
# create BNGModel object
|
| 109 |
+
$model = BNGModel->new();
|
| 110 |
+
$model->initialize();
|
| 111 |
+
$BNGModel::GLOBAL_MODEL = $model;
|
| 112 |
+
{ # read model file
|
| 113 |
+
my $err = $model->readFile($local_params);
|
| 114 |
+
if ($err)
|
| 115 |
+
{ # undefine model and send warning
|
| 116 |
+
%$model = (); undef %$model; $model = undef;
|
| 117 |
+
$BNGModel::GLOBAL_MODEL = undef;
|
| 118 |
+
send_warning( "Some problem processing '$filename': $err" );
|
| 119 |
+
last PROCESS_INPUT;
|
| 120 |
+
}
|
| 121 |
+
}
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
# EXECUTE an action
|
| 125 |
+
elsif ( $linein =~ s/^action\s+// )
|
| 126 |
+
{
|
| 127 |
+
unless (defined $model)
|
| 128 |
+
{
|
| 129 |
+
send_warning( "Attempt to execute action without loading model." );
|
| 130 |
+
last PROCESS_INPUT;
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
my ($action, $options);
|
| 134 |
+
if ( $linein =~ /^\s*(\w+)\s*\((.*)\);?\s*$/ )
|
| 135 |
+
{ # syntax: "action(options)"
|
| 136 |
+
$action = $1;
|
| 137 |
+
$options = $2;
|
| 138 |
+
}
|
| 139 |
+
else
|
| 140 |
+
{
|
| 141 |
+
send_warning( "Invalid action syntax. Try: action actionName(options)." );
|
| 142 |
+
last PROCESS_INPUT;
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
# define action
|
| 146 |
+
my $command = '$model->' . $action . '(' . $options . ');';
|
| 147 |
+
print "Begin action $action\n";
|
| 148 |
+
|
| 149 |
+
# Perform self-consistency checks before operations are performed on model
|
| 150 |
+
{
|
| 151 |
+
my $err = $model->ParamList->check();
|
| 152 |
+
if ($err)
|
| 153 |
+
{
|
| 154 |
+
send_warning( "Problem executing action: paramlist failed consistency check." );
|
| 155 |
+
last PROCESS_INPUT;
|
| 156 |
+
}
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
# execute action
|
| 160 |
+
my $t_start = cpu_time(0);
|
| 161 |
+
{
|
| 162 |
+
my $err = eval $command;
|
| 163 |
+
if ($@)
|
| 164 |
+
{
|
| 165 |
+
send_warning("Problem executing action: $@.");
|
| 166 |
+
last PROCESS_INPUT;
|
| 167 |
+
}
|
| 168 |
+
if ($err)
|
| 169 |
+
{
|
| 170 |
+
send_warning("Problem executing action: $err.");
|
| 171 |
+
last PROCESS_INPUT;
|
| 172 |
+
}
|
| 173 |
+
my $t_elapsed = cpu_time($t_start);
|
| 174 |
+
printf "CPU TIME: %s %.2f s.\n", $action, $t_elapsed;
|
| 175 |
+
}
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
# CLEAR model
|
| 179 |
+
elsif ( $linein =~ m/clear/ )
|
| 180 |
+
{
|
| 181 |
+
unless (defined $model)
|
| 182 |
+
{
|
| 183 |
+
send_warning( "Attempt to clear model without loaded model." );
|
| 184 |
+
last PROCESS_INPUT;
|
| 185 |
+
}
|
| 186 |
+
# undefine model
|
| 187 |
+
%$model = ();
|
| 188 |
+
undef %$model;
|
| 189 |
+
$model = undef;
|
| 190 |
+
$BNGModel::GLOBAL_MODEL = undef;
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
# DONE
|
| 194 |
+
elsif ( $linein =~ m/done/ )
|
| 195 |
+
{
|
| 196 |
+
undef $model;
|
| 197 |
+
print "Leaving BNG console.\n";
|
| 198 |
+
exit(0);
|
| 199 |
+
}
|
| 200 |
+
|
| 201 |
+
elsif ( $linein =~ m/help/ )
|
| 202 |
+
{
|
| 203 |
+
print "HELP menu for BNG console\n";
|
| 204 |
+
print "/-----------------------------------------------\n";
|
| 205 |
+
print " load MODEL [OPTS] : load a BNG model file \n";
|
| 206 |
+
print " done : leave BNG console \n";
|
| 207 |
+
print " clear : clear BNG model \n";
|
| 208 |
+
print " action ACTION : execute ACTION on loaded model\n";
|
| 209 |
+
print "\n";
|
| 210 |
+
print " OPTS:\n";
|
| 211 |
+
print " --atomize INT\n";
|
| 212 |
+
print " --blocks [\"STRING\", \"STRING\", ...]\n";
|
| 213 |
+
print "-----------------------------------------------/\n";
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
# unrecognized command
|
| 217 |
+
else
|
| 218 |
+
{
|
| 219 |
+
send_warning( "Unrecognized input. Type 'help' for information" );
|
| 220 |
+
}
|
| 221 |
+
}
|
| 222 |
+
|
| 223 |
+
print $BNG_PROMPT;
|
| 224 |
+
}
|
| 225 |
+
|
| 226 |
+
# stdin close
|
| 227 |
+
return 0;
|
| 228 |
+
}
|
data/bionetgen/Perl2/EnergyPattern.pm
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
| 1 |
+
package EnergyPattern;
|
| 2 |
+
# This class defines an energy pattern which contributes to the overall
|
| 3 |
+
# energy of a Species and influences reaction rates. --Justin
|
| 4 |
+
|
| 5 |
+
# pragmas
|
| 6 |
+
use strict;
|
| 7 |
+
use warnings;
|
| 8 |
+
no warnings 'redefine';
|
| 9 |
+
|
| 10 |
+
# Perl Modules
|
| 11 |
+
use Class::Struct;
|
| 12 |
+
use FindBin;
|
| 13 |
+
use lib $FindBin::Bin;
|
| 14 |
+
|
| 15 |
+
# BNG Modules
|
| 16 |
+
use BNGUtils;
|
| 17 |
+
use BNGModel;
|
| 18 |
+
use SpeciesGraph;
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
struct EnergyPattern =>
|
| 23 |
+
{
|
| 24 |
+
Pattern => 'SpeciesGraph', # pattern graph
|
| 25 |
+
Gf => 'Expression', # free-energy parameter (per match)
|
| 26 |
+
Weights => '@' # number of matches to each species
|
| 27 |
+
};
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
###
|
| 31 |
+
###
|
| 32 |
+
###
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
sub readString
|
| 36 |
+
{
|
| 37 |
+
my ($epatt, $string, $model) = @_;
|
| 38 |
+
|
| 39 |
+
my $err;
|
| 40 |
+
|
| 41 |
+
# strip any leading whitesace
|
| 42 |
+
$string =~ s/^\s+//;
|
| 43 |
+
|
| 44 |
+
# Check if first token is an index (This index will be ignored)
|
| 45 |
+
# DEPRECATED as of BNG 2.2.6
|
| 46 |
+
if($string =~ s/^\s*\d+\s+//)
|
| 47 |
+
{
|
| 48 |
+
return "Leading index detected at '$string'. This is deprecated as of BNG 2.2.6.";
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
# Remove leading label, if exists
|
| 52 |
+
if ($string =~ s/^\s*(\w+)\s*:\s+//)
|
| 53 |
+
{
|
| 54 |
+
# Check label for leading number
|
| 55 |
+
my $label = $1;
|
| 56 |
+
if ($label =~ /^\d/) { return "Syntax error (label begins with a number) at '$label'"; }
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
# Check name for leading number
|
| 60 |
+
my $string_left = $string;
|
| 61 |
+
unless ( $string_left =~ s/^([A-Za-z_]\w*)// )
|
| 62 |
+
{
|
| 63 |
+
return "Syntax error (pattern name begins with a number) at $string.";
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
# Next read the SpeciesGraph that will define the Energy Pattern
|
| 67 |
+
my $sep = '^\s+';
|
| 68 |
+
my $sg = SpeciesGraph->new();
|
| 69 |
+
$err = $sg->readString( \$string, $model->CompartmentList, 0, $sep, $model->MoleculeTypesList, 1 );
|
| 70 |
+
if ($err) { return "While reading Energy Pattern: $err"; }
|
| 71 |
+
|
| 72 |
+
$epatt->Pattern($sg);
|
| 73 |
+
|
| 74 |
+
# Look for free-energy of formation expression (Gf)
|
| 75 |
+
# and construct equillibrium factor
|
| 76 |
+
my $Gf_expr = Expression->new();
|
| 77 |
+
if ( $string =~ /\S+/ )
|
| 78 |
+
{
|
| 79 |
+
# Read expression
|
| 80 |
+
$err = $Gf_expr->readString( \$string, $model->ParamList );
|
| 81 |
+
if ($err) { return undef, $err; }
|
| 82 |
+
}
|
| 83 |
+
else
|
| 84 |
+
{
|
| 85 |
+
$err = sprintf "Missing free-energy token for energy pattern %s", $epatt->Pattern->toString();
|
| 86 |
+
return $err;
|
| 87 |
+
}
|
| 88 |
+
# set Keq expression
|
| 89 |
+
$epatt->Gf($Gf_expr);
|
| 90 |
+
|
| 91 |
+
# set Weights and RxnStoich to empty array
|
| 92 |
+
$epatt->Weights([]);
|
| 93 |
+
|
| 94 |
+
# return with error (if defined)
|
| 95 |
+
return $err;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
sub toString
|
| 101 |
+
{
|
| 102 |
+
my $epatt = shift;
|
| 103 |
+
my $plist = (@_) ? shift : undef;
|
| 104 |
+
my $string = '';
|
| 105 |
+
|
| 106 |
+
$string .= $epatt->Pattern->toString() . " "
|
| 107 |
+
. $epatt->Gf->toString($plist);
|
| 108 |
+
|
| 109 |
+
return $string;
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
sub toMatlabString
|
| 115 |
+
{
|
| 116 |
+
my $epatt = shift;
|
| 117 |
+
my $string = '';
|
| 118 |
+
|
| 119 |
+
# TODO
|
| 120 |
+
|
| 121 |
+
return $string, '';
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
sub toMexString
|
| 127 |
+
{
|
| 128 |
+
my $epatt = shift;
|
| 129 |
+
my $string = '';
|
| 130 |
+
|
| 131 |
+
# TODO
|
| 132 |
+
|
| 133 |
+
return $string, '';
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
sub toXML
|
| 139 |
+
{
|
| 140 |
+
my $epatt = shift;
|
| 141 |
+
my $indent = shift;
|
| 142 |
+
my $index = shift;
|
| 143 |
+
|
| 144 |
+
my $string = '';
|
| 145 |
+
|
| 146 |
+
# TODO
|
| 147 |
+
|
| 148 |
+
return $string, '';
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
sub toMathMLString
|
| 154 |
+
{
|
| 155 |
+
my $epatt = shift;
|
| 156 |
+
my $string = '';
|
| 157 |
+
|
| 158 |
+
# TODO
|
| 159 |
+
|
| 160 |
+
return $string, '';
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
|
| 164 |
+
# reset the observable weights to zero
|
| 165 |
+
sub reset_weights
|
| 166 |
+
{
|
| 167 |
+
my $epatt = shift @_;
|
| 168 |
+
my $alloc = @_ ? shift @_ : 0;
|
| 169 |
+
$epatt->Weights( [(0) x ($alloc+1)] );
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
|
| 173 |
+
|
| 174 |
+
sub update
|
| 175 |
+
{
|
| 176 |
+
my $epatt = shift @_;
|
| 177 |
+
my $species = shift @_;
|
| 178 |
+
my $idx_start = @_ ? shift @_ : 0;
|
| 179 |
+
|
| 180 |
+
my $err = undef;
|
| 181 |
+
for ( my $ii = $idx_start; $ii < @$species; ++$ii )
|
| 182 |
+
{
|
| 183 |
+
my $spec = $species->[$ii];
|
| 184 |
+
next if ($spec->ObservablesApplied);
|
| 185 |
+
my @matches = $epatt->Pattern->isomorphicToSubgraph($spec->SpeciesGraph);
|
| 186 |
+
$epatt->Weights->[$spec->Index] = (scalar @matches)/($epatt->Pattern->Automorphisms);
|
| 187 |
+
}
|
| 188 |
+
return $err;
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
+
|
| 192 |
+
|
| 193 |
+
sub getStoich
|
| 194 |
+
# returns an integer value corresponding to the stoichiometry of
|
| 195 |
+
# this pattern w.r.t. a given reaction.
|
| 196 |
+
{
|
| 197 |
+
my ($epatt, $rxn) = @_;
|
| 198 |
+
|
| 199 |
+
my $err;
|
| 200 |
+
my $stoich = 0;
|
| 201 |
+
foreach my $reactant (@{$rxn->Reactants})
|
| 202 |
+
{
|
| 203 |
+
if ( $epatt->Weights->[$reactant->Index] )
|
| 204 |
+
{ $stoich -= $epatt->Weights->[$reactant->Index]; }
|
| 205 |
+
}
|
| 206 |
+
foreach my $product (@{$rxn->Products})
|
| 207 |
+
{
|
| 208 |
+
if ( $epatt->Weights->[$product->Index] )
|
| 209 |
+
{ $stoich += $epatt->Weights->[$product->Index]; }
|
| 210 |
+
}
|
| 211 |
+
return $stoich, $err;
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
|
| 215 |
+
|
| 216 |
+
sub getDeltaEnergy
|
| 217 |
+
{
|
| 218 |
+
my ($epatt, $rxn, $plist) = @_;
|
| 219 |
+
|
| 220 |
+
my $err;
|
| 221 |
+
my $stoich;
|
| 222 |
+
|
| 223 |
+
# get stoichiometry of this pattern w.r.t. this rxn
|
| 224 |
+
($stoich, $err) = $epatt->getStoich($rxn);
|
| 225 |
+
if ( $err ) { return undef, $err; }
|
| 226 |
+
|
| 227 |
+
# construct a rate constant expression
|
| 228 |
+
my $rate_expr = undef;
|
| 229 |
+
if ( $stoich!=0 )
|
| 230 |
+
{
|
| 231 |
+
if ( $stoich == 1 )
|
| 232 |
+
{
|
| 233 |
+
$rate_expr = $epatt->Gf;
|
| 234 |
+
}
|
| 235 |
+
elsif ( $stoich == -1 )
|
| 236 |
+
{
|
| 237 |
+
$rate_expr = Expression::operate("-", [$epatt->Gf], $plist);
|
| 238 |
+
}
|
| 239 |
+
else
|
| 240 |
+
{
|
| 241 |
+
$rate_expr = Expression::operate("*", [$stoich, $epatt->Gf], $plist);
|
| 242 |
+
}
|
| 243 |
+
}
|
| 244 |
+
|
| 245 |
+
return $rate_expr, $err;
|
| 246 |
+
}
|
| 247 |
+
|
| 248 |
+
###
|
| 249 |
+
###
|
| 250 |
+
###
|
| 251 |
+
|
| 252 |
+
1;
|
data/bionetgen/Perl2/Expression.pm
ADDED
|
@@ -0,0 +1,1987 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# $Id: Expression.pm,v 1.7 2007/02/20 17:39:38 faeder Exp $
|
| 2 |
+
|
| 3 |
+
# updated by msneddon, 2009/11/04
|
| 4 |
+
# -added if statement as built in function
|
| 5 |
+
# -added binary logical operators, <,>.<=,>=,==,!=,~=,&&,||
|
| 6 |
+
# to the basic functional parser, the toString function, and
|
| 7 |
+
# to the evaluate function
|
| 8 |
+
|
| 9 |
+
# -todo: add binary operators to method toMathMLString function
|
| 10 |
+
# -todo: add the unary operator not: '!' (this is implemented, but not tested. --JSH)
|
| 11 |
+
|
| 12 |
+
package Expression;
|
| 13 |
+
|
| 14 |
+
# pragmas
|
| 15 |
+
use strict;
|
| 16 |
+
use warnings;
|
| 17 |
+
no warnings 'redefine';
|
| 18 |
+
|
| 19 |
+
# Perl Modules
|
| 20 |
+
use Class::Struct;
|
| 21 |
+
use FindBin;
|
| 22 |
+
use lib $FindBin::Bin;
|
| 23 |
+
use Scalar::Util ("looks_like_number");
|
| 24 |
+
|
| 25 |
+
# BNG Modules
|
| 26 |
+
use Param;
|
| 27 |
+
use ParamList;
|
| 28 |
+
|
| 29 |
+
#use POSIX qw/floor ceil/; # safer to use 'floor' and 'ceil' instead of 'int'
|
| 30 |
+
use POSIX qw/floor/; # 'floor' and 'ceil' not supported by muParser. Use 'floor' for 'rint'.
|
| 31 |
+
use Math::Trig qw(tan asin acos atan sinh cosh tanh asinh acosh atanh pi);
|
| 32 |
+
use List::Util qw(min max sum);
|
| 33 |
+
|
| 34 |
+
struct Expression =>
|
| 35 |
+
{
|
| 36 |
+
Type => '$', # Valid types are 'NUM', 'VAR', 'FunctionCall', '+', '-', '*', '/', '^', '**',
|
| 37 |
+
# '>','<','>=','<=','==','!=','~=','&&','||','!','~'
|
| 38 |
+
Arglist => '@',
|
| 39 |
+
Err => '$',
|
| 40 |
+
};
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
# NOTE: it's weird that some built-in functions with names (like exp, cos, etc) are handled
|
| 44 |
+
# differently thant built-ins with operator symbols (like +, -, etc). We could really simplify this.
|
| 45 |
+
# --Justin
|
| 46 |
+
# Supported most muParser built-in functions. --LAH
|
| 47 |
+
# See http://muparser.sourceforge.net/mup_features.html#idDef2 for the complete list.
|
| 48 |
+
my %functions =
|
| 49 |
+
(
|
| 50 |
+
"_pi" => { FPTR => sub { pi }, NARGS => 0 }, # <pi>
|
| 51 |
+
"_e" => { FPTR => sub { exp(1) }, NARGS => 0 }, # <exponentiale> (MathML 2.0)
|
| 52 |
+
"time" => { FPTR => sub
|
| 53 |
+
{
|
| 54 |
+
if (defined($BNGModel::GLOBAL_MODEL->time))
|
| 55 |
+
{$BNGModel::GLOBAL_MODEL->time}
|
| 56 |
+
else {0}
|
| 57 |
+
}, NARGS => 0 }, # ???
|
| 58 |
+
"exp" => { FPTR => sub { exp( $_[0] ) }, NARGS => 1 }, # <exp/> (MathML 2.0)
|
| 59 |
+
"ln" => { FPTR => sub { log( $_[0] ) }, NARGS => 1 }, # <ln/>
|
| 60 |
+
"log10" => { FPTR => sub { log($_[0])/log(10) }, NARGS => 1 }, # <log/>
|
| 61 |
+
"log2" => { FPTR => sub { log($_[0])/log(2) }, NARGS => 1 }, # <log/><logbase><cn>2</cn></logbase>
|
| 62 |
+
"abs" => { FPTR => sub { abs( $_[0] ) }, NARGS => 1 }, # <abs/>
|
| 63 |
+
# "int" => { FPTR => sub { int( $_[0] ) }, NARGS => 1 }, # deprecated!
|
| 64 |
+
# "floor" => { FPTR => sub { floor( $_[0] ) }, NARGS => 1 }, # not supported by muParser
|
| 65 |
+
# "ceil" => { FPTR => sub { ceil( $_[0] ) }, NARGS => 1 }, # not supported by muParser
|
| 66 |
+
"rint" => { FPTR => sub { floor( $_[0] + 0.5 ) }, NARGS => 1 }, # requires special handling (see toMathMLString)
|
| 67 |
+
"sqrt" => { FPTR => sub { sqrt( $_[0] ) }, NARGS => 1 }, # <root/>
|
| 68 |
+
"cos" => { FPTR => sub { cos( $_[0] ) }, NARGS => 1 }, # <cos/>
|
| 69 |
+
"sin" => { FPTR => sub { sin( $_[0] ) }, NARGS => 1 }, # <sin/>
|
| 70 |
+
"tan" => { FPTR => sub { tan( $_[0] ) }, NARGS => 1 }, # <tan/>
|
| 71 |
+
"asin" => { FPTR => sub { asin( $_[0] ) }, NARGS => 1 }, # <arcsin/>
|
| 72 |
+
"acos" => { FPTR => sub { acos( $_[0] ) }, NARGS => 1 }, # <arccos/>
|
| 73 |
+
"atan" => { FPTR => sub { atan( $_[0] ) }, NARGS => 1 }, # <arctan/>
|
| 74 |
+
"sinh" => { FPTR => sub { sinh( $_[0] ) }, NARGS => 1 }, # <sinh/>
|
| 75 |
+
"cosh" => { FPTR => sub { cosh( $_[0] ) }, NARGS => 1 }, # <cosh/>
|
| 76 |
+
"tanh" => { FPTR => sub { tanh( $_[0] ) }, NARGS => 1 }, # <tanh/>
|
| 77 |
+
"asinh" => { FPTR => sub { asinh( $_[0] ) }, NARGS => 1 }, # <arcsinh/> (MathML 2.0)
|
| 78 |
+
"acosh" => { FPTR => sub { acosh( $_[0] ) }, NARGS => 1 }, # <arccosh/> (MathML 2.0)
|
| 79 |
+
"atanh" => { FPTR => sub { atanh( $_[0] ) }, NARGS => 1 }, # <arctanh/> (MathML 2.0)
|
| 80 |
+
"if" => { FPTR => sub { if($_[0]) { $_[1] } else { $_[2] } }, NARGS => 3 }, # requires special handling (see toMathMLString)
|
| 81 |
+
"min" => { FPTR => sub { min(@_) }, NARGS => scalar(@_) }, # <min/>
|
| 82 |
+
"max" => { FPTR => sub { max(@_) }, NARGS => scalar(@_) }, # <max/>
|
| 83 |
+
"sum" => { FPTR => sub { sum(@_) }, NARGS => scalar(@_) }, # <sum/>
|
| 84 |
+
"avg" => { FPTR => sub { sum(@_)/scalar(@_) }, NARGS => scalar(@_) }, # <mean/>
|
| 85 |
+
);
|
| 86 |
+
|
| 87 |
+
my $MAX_LEVEL = 500; # Prevent infinite loop due to dependency loops
|
| 88 |
+
|
| 89 |
+
# this hash maps operators to the min and max number of arguments
|
| 90 |
+
my %NARGS = ( '+' => { 'min'=>2 }, # <plus/>
|
| 91 |
+
'-' => { 'min'=>1 }, # <minus/>
|
| 92 |
+
'*' => { 'min'=>2 }, # <times/>
|
| 93 |
+
'/' => { 'min'=>2 }, # <divide/>
|
| 94 |
+
'^' => { 'min'=>2, 'max'=>2 }, # <power/>
|
| 95 |
+
'**' => { 'min'=>2, 'max'=>2 }, # Not supported by muParser
|
| 96 |
+
'&&' => { 'min'=>2 }, # <and/>
|
| 97 |
+
'||' => { 'min'=>2 }, # <or/>
|
| 98 |
+
'<' => { 'min'=>2, 'max'=>2 }, # <lt/>
|
| 99 |
+
'>' => { 'min'=>2, 'max'=>2 }, # <gt/>
|
| 100 |
+
'<=' => { 'min'=>2, 'max'=>2 }, # <leq/>
|
| 101 |
+
'>=' => { 'min'=>2, 'max'=>2 }, # <geq/>
|
| 102 |
+
'!=' => { 'min'=>2, 'max'=>2 }, # <neq/>
|
| 103 |
+
'~=' => { 'min'=>2, 'max'=>2 }, # Not supported by muParser
|
| 104 |
+
'==' => { 'min'=>2, 'max'=>2 }, # <equivalent/> (MathML 2.0)
|
| 105 |
+
'!' => { 'min'=>1, 'max'=>1 }, # Not supported by muParser
|
| 106 |
+
'~' => { 'min'=>1, 'max'=>1 } # Not supported by muParser
|
| 107 |
+
);
|
| 108 |
+
|
| 109 |
+
# muParser operators
|
| 110 |
+
# ------------------
|
| 111 |
+
# + addition
|
| 112 |
+
# - subtraction
|
| 113 |
+
# * multiplication
|
| 114 |
+
# / division
|
| 115 |
+
# ^ raise x to the power of y
|
| 116 |
+
# && logical and
|
| 117 |
+
# || logical or
|
| 118 |
+
# < less than
|
| 119 |
+
# > greater than
|
| 120 |
+
# <= less or equal
|
| 121 |
+
# >= greater or equal
|
| 122 |
+
# != not equal
|
| 123 |
+
# == equal
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
# this regex matches param names (letter followed optional by word characters)
|
| 127 |
+
my $PARAM_REGEX = '^\w+$';
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
###
|
| 131 |
+
###
|
| 132 |
+
###
|
| 133 |
+
|
| 134 |
+
sub isBuiltIn
|
| 135 |
+
{
|
| 136 |
+
my $name = shift @_;
|
| 137 |
+
return (exists $functions{$name} ? 1 : 0);
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
###
|
| 141 |
+
###
|
| 142 |
+
###
|
| 143 |
+
|
| 144 |
+
|
| 145 |
+
# get a recursive copy of an expression.
|
| 146 |
+
# Note that the recursion does not descend past VAR and FunctionCall type expressions.
|
| 147 |
+
# Returns a reference to the clone and any error messages.
|
| 148 |
+
sub clone
|
| 149 |
+
{
|
| 150 |
+
my $expr = shift;
|
| 151 |
+
my $plist = (@_) ? shift : undef;
|
| 152 |
+
my $level = (@_) ? shift : 0;
|
| 153 |
+
|
| 154 |
+
if ( $level > $MAX_LEVEL ) { die "Max recursion depth $MAX_LEVEL exceeded."; }
|
| 155 |
+
|
| 156 |
+
my $err = '';
|
| 157 |
+
|
| 158 |
+
# create a new array for cloned argument
|
| 159 |
+
my $clone_args = [];
|
| 160 |
+
# create clone
|
| 161 |
+
my $clone = Expression->new();
|
| 162 |
+
$clone->Type( $expr->Type );
|
| 163 |
+
$clone->Arglist( $clone_args );
|
| 164 |
+
$clone->Err( '' );
|
| 165 |
+
|
| 166 |
+
# clone argument expressions
|
| 167 |
+
foreach my $arg ( @{$expr->Arglist} )
|
| 168 |
+
{
|
| 169 |
+
my $clone_arg;
|
| 170 |
+
if ( ref $arg eq 'Expression' )
|
| 171 |
+
{
|
| 172 |
+
# recursively expand expressions
|
| 173 |
+
my $clone_arg;
|
| 174 |
+
($clone_arg, $err) = $arg->clone($plist,$level+1);
|
| 175 |
+
push @$clone_args, $clone_arg;
|
| 176 |
+
}
|
| 177 |
+
else
|
| 178 |
+
{
|
| 179 |
+
push @$clone_args, $arg;
|
| 180 |
+
}
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
return ($clone, $err);
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
# TODO: simplify method
|
| 188 |
+
# eliminate 1's from mulitplications and divisions
|
| 189 |
+
# eliminate 0's from additions and subtractions.
|
| 190 |
+
# cancel terms in basic arthimetic operations.
|
| 191 |
+
|
| 192 |
+
|
| 193 |
+
###
|
| 194 |
+
###
|
| 195 |
+
###
|
| 196 |
+
|
| 197 |
+
|
| 198 |
+
# create a new expression from a number or a param name
|
| 199 |
+
sub newNumOrVar
|
| 200 |
+
{
|
| 201 |
+
my $value = shift @_;
|
| 202 |
+
my $plist = (@_) ? shift @_ : undef;
|
| 203 |
+
|
| 204 |
+
my $expr;
|
| 205 |
+
my $err;
|
| 206 |
+
# is this a number?
|
| 207 |
+
if ( looks_like_number($value) )
|
| 208 |
+
{ # create a new number expression
|
| 209 |
+
$expr = Expression->new();
|
| 210 |
+
$expr->Type('NUM');
|
| 211 |
+
$expr->Arglist( [$value] );
|
| 212 |
+
$expr->Err( undef );
|
| 213 |
+
}
|
| 214 |
+
# or possibly a parameter name?
|
| 215 |
+
elsif ( $value =~ /$PARAM_REGEX/ )
|
| 216 |
+
{
|
| 217 |
+
# we need a paramlist to continue
|
| 218 |
+
if ( ref $plist eq "ParamList" )
|
| 219 |
+
{
|
| 220 |
+
# check that parameter exists
|
| 221 |
+
(my $param, $err) = $plist->lookup( $value );
|
| 222 |
+
if (defined $param)
|
| 223 |
+
{ # create a new number expression
|
| 224 |
+
$expr = Expression->new();
|
| 225 |
+
$expr->Type('VAR');
|
| 226 |
+
$expr->Arglist( [$value] );
|
| 227 |
+
$expr->Err( undef );
|
| 228 |
+
}
|
| 229 |
+
}
|
| 230 |
+
}
|
| 231 |
+
|
| 232 |
+
unless (defined $expr)
|
| 233 |
+
{ die "Expression::newNumOrVar() - Attempted but failed to create number or variable expression"; }
|
| 234 |
+
|
| 235 |
+
# return expression or undefined
|
| 236 |
+
return $expr;
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
|
| 240 |
+
###
|
| 241 |
+
###
|
| 242 |
+
###
|
| 243 |
+
|
| 244 |
+
|
| 245 |
+
# Creates a new expression from a list of existing expressions.
|
| 246 |
+
# The type argument indicates the operation used to combine the expressions.
|
| 247 |
+
# E.g. '+', '-', 'FunctionCall'.
|
| 248 |
+
# If the type is 'FunctionCall', then the first argument should be the name of
|
| 249 |
+
# a built-in or user-defined function.
|
| 250 |
+
sub operate
|
| 251 |
+
{
|
| 252 |
+
my ($type, $args, $plist) = @_;
|
| 253 |
+
|
| 254 |
+
# can't do anything without arguments!
|
| 255 |
+
unless (@$args) { return undef; }
|
| 256 |
+
|
| 257 |
+
# operate is unhappy without a paramlist!
|
| 258 |
+
unless (ref $plist eq 'ParamList') { return undef; }
|
| 259 |
+
|
| 260 |
+
my $err;
|
| 261 |
+
my $args_copy;
|
| 262 |
+
|
| 263 |
+
# copy the arguments
|
| 264 |
+
@$args_copy = @$args;
|
| 265 |
+
|
| 266 |
+
# Check for the right number of arguments..
|
| 267 |
+
|
| 268 |
+
# is this a function?
|
| 269 |
+
if ( $type eq 'FunctionCall' )
|
| 270 |
+
{
|
| 271 |
+
# get function name (first argument)
|
| 272 |
+
my $fcn_name = $args_copy->[0];
|
| 273 |
+
|
| 274 |
+
# is this a built-in function?
|
| 275 |
+
if ( defined $fcn_name and exists $functions{$fcn_name} )
|
| 276 |
+
{ # correct number of arguments?
|
| 277 |
+
return undef unless ( $functions{$fcn_name}->{NARGS} == (@$args_copy - 1) );
|
| 278 |
+
}
|
| 279 |
+
# or is this custom?
|
| 280 |
+
else
|
| 281 |
+
{
|
| 282 |
+
# lookup function in parameter list
|
| 283 |
+
(my $fcn_param, $err) = $plist->lookup( $fcn_name );
|
| 284 |
+
if ( $err or !defined($fcn_param) ) { return undef; }
|
| 285 |
+
|
| 286 |
+
if ( ref $fcn_param ne 'Param' or $fcn_param->Type ne 'Function' )
|
| 287 |
+
{ return undef; }
|
| 288 |
+
|
| 289 |
+
# correct number of arguments?
|
| 290 |
+
unless ( @{$fcn_param->Ref->Args} == (@$args_copy - 1) )
|
| 291 |
+
{ return undef; }
|
| 292 |
+
}
|
| 293 |
+
|
| 294 |
+
# clone arguments (not first argument, which is the fcn name)
|
| 295 |
+
foreach my $arg ( @$args_copy[1..$#$args_copy] )
|
| 296 |
+
{
|
| 297 |
+
# clone argument, if it's an expression
|
| 298 |
+
if ( ref $arg eq 'Expression' )
|
| 299 |
+
{ ($arg, $err) = $arg->clone($plist); }
|
| 300 |
+
|
| 301 |
+
# if arg isn't an expression, try to create one
|
| 302 |
+
else
|
| 303 |
+
{ $arg = Expression::newNumOrVar( $arg ); }
|
| 304 |
+
|
| 305 |
+
# check that are is still defined
|
| 306 |
+
unless (defined $arg) { return undef; }
|
| 307 |
+
}
|
| 308 |
+
}
|
| 309 |
+
# or an operator?
|
| 310 |
+
else
|
| 311 |
+
{
|
| 312 |
+
# check that the operator exists and has the right number of arguments
|
| 313 |
+
unless ( exists $NARGS{$type} )
|
| 314 |
+
{ return undef; }
|
| 315 |
+
if ( (exists $NARGS{$type}->{min}) and (($NARGS{$type}->{min}) > (@$args_copy)) )
|
| 316 |
+
{ return undef; }
|
| 317 |
+
if ( (exists $NARGS{$type}->{max}) and (($NARGS{$type}->{max}) < (@$args_copy)) )
|
| 318 |
+
{ return undef; }
|
| 319 |
+
|
| 320 |
+
# clone arguments
|
| 321 |
+
foreach my $arg ( @$args_copy )
|
| 322 |
+
{
|
| 323 |
+
# clone argument, if it's an expression
|
| 324 |
+
if ( ref $arg eq 'Expression' )
|
| 325 |
+
{ ($arg, $err) = $arg->clone($plist); }
|
| 326 |
+
|
| 327 |
+
# if arg isn't an expression, try to create one
|
| 328 |
+
else
|
| 329 |
+
{ $arg = Expression::newNumOrVar($arg,$plist); }
|
| 330 |
+
|
| 331 |
+
# check that are is still defined
|
| 332 |
+
unless (defined $arg) { return undef; }
|
| 333 |
+
}
|
| 334 |
+
}
|
| 335 |
+
|
| 336 |
+
# return undefined if there were any errors
|
| 337 |
+
if ($err) { return undef; }
|
| 338 |
+
|
| 339 |
+
# create the new expression
|
| 340 |
+
my $expr = Expression->new();
|
| 341 |
+
$expr->Type( $type );
|
| 342 |
+
$expr->Arglist( $args_copy );
|
| 343 |
+
$expr->Err( undef );
|
| 344 |
+
|
| 345 |
+
# return reference to expression!
|
| 346 |
+
return $expr;
|
| 347 |
+
}
|
| 348 |
+
|
| 349 |
+
|
| 350 |
+
###
|
| 351 |
+
###
|
| 352 |
+
###
|
| 353 |
+
|
| 354 |
+
|
| 355 |
+
# load an expression by parsing a string
|
| 356 |
+
{
|
| 357 |
+
my $string_sav;
|
| 358 |
+
my $variables = {};
|
| 359 |
+
my $allowForward = 0;
|
| 360 |
+
|
| 361 |
+
|
| 362 |
+
sub setAllowForward
|
| 363 |
+
{
|
| 364 |
+
my $expr = shift @_;
|
| 365 |
+
$allowForward = shift @_;
|
| 366 |
+
}
|
| 367 |
+
|
| 368 |
+
|
| 369 |
+
sub readString
|
| 370 |
+
{
|
| 371 |
+
# get arguments
|
| 372 |
+
my $expr = shift @_;
|
| 373 |
+
my $sptr = shift @_;
|
| 374 |
+
my $plist = @_ ? shift @_ : undef;
|
| 375 |
+
my $end_chars = @_ ? shift @_ : '';
|
| 376 |
+
my $level = @_ ? shift @_ : 0;
|
| 377 |
+
|
| 378 |
+
my $err = '';
|
| 379 |
+
my $ops_bi = '\*\*|[+\-*/^]|>=|<=|[<>]|==|!=|~=|&&|\|\|';
|
| 380 |
+
my $ops_un = '[+\-!~]';
|
| 381 |
+
|
| 382 |
+
if ( $level==0 )
|
| 383 |
+
{
|
| 384 |
+
$string_sav = $$sptr;
|
| 385 |
+
%$variables = ();
|
| 386 |
+
}
|
| 387 |
+
|
| 388 |
+
# parse string into form expr op expr op ...
|
| 389 |
+
# a+b*(c+d)
|
| 390 |
+
# -5.0e+3/4
|
| 391 |
+
my $last_read = '';
|
| 392 |
+
my $expr_new = '';
|
| 393 |
+
my @list = ();
|
| 394 |
+
my $expect_op = 0;
|
| 395 |
+
my $assign_var_name = '';
|
| 396 |
+
while ( $$sptr ne '' )
|
| 397 |
+
{
|
| 398 |
+
# OPERATORS
|
| 399 |
+
if ($expect_op)
|
| 400 |
+
{
|
| 401 |
+
# Binary operator
|
| 402 |
+
if ( $$sptr =~ s/^\s*($ops_bi)// )
|
| 403 |
+
{
|
| 404 |
+
my $express = Expression->new( Type=>$1 );
|
| 405 |
+
push @list, $express;
|
| 406 |
+
$expect_op = 0;
|
| 407 |
+
next;
|
| 408 |
+
}
|
| 409 |
+
|
| 410 |
+
# Assignment using '='. Valid syntax is PARAM = EXPRESSION
|
| 411 |
+
# NOTE: this really stops the current expression (which should be a PARAM) and
|
| 412 |
+
# starts parsing a RHS expression which will be assigned to PARAM.
|
| 413 |
+
elsif ( $$sptr =~ s/^\s*=// )
|
| 414 |
+
{
|
| 415 |
+
# Check that only preceding argument is variable
|
| 416 |
+
unless ( @list==1 )
|
| 417 |
+
{ return "Invalid assignment syntax (VAR = EXPRESSION) in $string_sav at $$sptr"; }
|
| 418 |
+
|
| 419 |
+
my $param = $list[0];
|
| 420 |
+
my $param_name = $param->Arglist->[0];
|
| 421 |
+
|
| 422 |
+
# Make sure parameter name not the same as built-in functions --Leonard
|
| 423 |
+
if ( exists $functions{ $param_name } ){
|
| 424 |
+
return "Cannot use built-in function name '$param_name' as a parameter name.";
|
| 425 |
+
}
|
| 426 |
+
|
| 427 |
+
unless ( $param->Type eq 'VAR' )
|
| 428 |
+
{ return "Attempted assignment to non-variable type in $string_sav at $$sptr."; }
|
| 429 |
+
|
| 430 |
+
# save old variables
|
| 431 |
+
my $old_variables;
|
| 432 |
+
%{$old_variables} = %{$variables};
|
| 433 |
+
%{$variables} = ();
|
| 434 |
+
# save old string_sav
|
| 435 |
+
my $old_string_sav = $string_sav;
|
| 436 |
+
|
| 437 |
+
# Read remainder as expression
|
| 438 |
+
my $rhs = Expression->new();
|
| 439 |
+
$err = $rhs->readString( $sptr, $plist, $end_chars, $level + 1 );
|
| 440 |
+
if ($err) { return $err; }
|
| 441 |
+
|
| 442 |
+
# check for recursive definitions
|
| 443 |
+
if ( exists $variables->{$param_name} )
|
| 444 |
+
{ return "Parameter $param_name is defined recursively."; }
|
| 445 |
+
|
| 446 |
+
# fetch old variables and string_sav
|
| 447 |
+
%{$variables} = %{$old_variables};
|
| 448 |
+
$string_sav = $old_string_sav;
|
| 449 |
+
|
| 450 |
+
# assign the rhs expression to the parameter $vname
|
| 451 |
+
$plist->set( $param_name, $rhs );
|
| 452 |
+
last;
|
| 453 |
+
}
|
| 454 |
+
|
| 455 |
+
# Look for end characters
|
| 456 |
+
elsif ( $end_chars and ( $$sptr =~ /^\s*${end_chars}/ ) )
|
| 457 |
+
{ # end of expression
|
| 458 |
+
last;
|
| 459 |
+
}
|
| 460 |
+
else
|
| 461 |
+
{ # nothing more to do
|
| 462 |
+
# TODO: add warning for trailing characters?
|
| 463 |
+
$$sptr =~ s/^\s*//;
|
| 464 |
+
last;
|
| 465 |
+
}
|
| 466 |
+
}
|
| 467 |
+
|
| 468 |
+
# Chop leading whitespace
|
| 469 |
+
$$sptr =~ s/^\s*//;
|
| 470 |
+
|
| 471 |
+
# look for a NUMBER
|
| 472 |
+
if ( my $num_expr = getNumber($sptr) )
|
| 473 |
+
{
|
| 474 |
+
push @list, $num_expr;
|
| 475 |
+
$expect_op = 1;
|
| 476 |
+
next;
|
| 477 |
+
}
|
| 478 |
+
|
| 479 |
+
# look for a function call
|
| 480 |
+
if ( $$sptr =~ s/^($ops_un)?\s*(\w+)\s*\(// )
|
| 481 |
+
{
|
| 482 |
+
my $express_u;
|
| 483 |
+
if ( my $op = $1 )
|
| 484 |
+
{ # (optional) UNARY OP at start of expression, as in -a + b, or -a^2
|
| 485 |
+
$express_u = Expression->new( Type=>$1 );
|
| 486 |
+
}
|
| 487 |
+
|
| 488 |
+
my $name = $2;
|
| 489 |
+
my @fargs = ();
|
| 490 |
+
my $type = '';
|
| 491 |
+
my $nargs;
|
| 492 |
+
my ($param, $err);
|
| 493 |
+
if ($plist)
|
| 494 |
+
{
|
| 495 |
+
($param, $err) = $plist->lookup($name);
|
| 496 |
+
}
|
| 497 |
+
if ( exists $functions{$name} )
|
| 498 |
+
{
|
| 499 |
+
$type = "B";
|
| 500 |
+
$nargs = $functions{$name}->{NARGS};
|
| 501 |
+
}
|
| 502 |
+
# elsif ( $param and ($param->Type eq 'Observable') )
|
| 503 |
+
elsif ( $param and defined $param->Type and ($param->Type eq 'Observable') )
|
| 504 |
+
{
|
| 505 |
+
$type = "O";
|
| 506 |
+
# number of args may be zero or one.
|
| 507 |
+
}
|
| 508 |
+
# elsif ( $param and ($param->Type eq 'Function') )
|
| 509 |
+
elsif ( $param and defined $param->Type and ($param->Type eq 'Function') )
|
| 510 |
+
{
|
| 511 |
+
$type = "F";
|
| 512 |
+
$nargs = scalar( @{ $param->Ref->Args } );
|
| 513 |
+
}
|
| 514 |
+
else
|
| 515 |
+
{
|
| 516 |
+
unless ( defined $param )
|
| 517 |
+
{
|
| 518 |
+
if ($allowForward)
|
| 519 |
+
{ $plist->set($name); }
|
| 520 |
+
else
|
| 521 |
+
{
|
| 522 |
+
return "Function $name is not a built-in function, Observable, or defined Function";
|
| 523 |
+
}
|
| 524 |
+
}
|
| 525 |
+
}
|
| 526 |
+
|
| 527 |
+
# Read arguments to function
|
| 528 |
+
while (1)
|
| 529 |
+
{
|
| 530 |
+
my $express = Expression->new();
|
| 531 |
+
$err = $express->readString( $sptr, $plist, ',\)', $level + 1 );
|
| 532 |
+
if ($err) { return $err; }
|
| 533 |
+
if ($express->Type) { push @fargs, $express; }
|
| 534 |
+
|
| 535 |
+
if ( $$sptr =~ s/^\)// )
|
| 536 |
+
{ last; }
|
| 537 |
+
elsif ( $$sptr =~ s/^,// )
|
| 538 |
+
{ next; }
|
| 539 |
+
}
|
| 540 |
+
|
| 541 |
+
# Check Argument list for consistency with function
|
| 542 |
+
if ( $type eq "O" )
|
| 543 |
+
{
|
| 544 |
+
$nargs= scalar(@fargs);
|
| 545 |
+
if ($nargs>1){
|
| 546 |
+
return ("Observables $name is called with too many arguments");
|
| 547 |
+
}
|
| 548 |
+
elsif ($nargs==1)
|
| 549 |
+
{
|
| 550 |
+
# Argument must be VAR
|
| 551 |
+
if ($fargs[0]->Type ne "VAR"){
|
| 552 |
+
return("Argument to observable must be a variable");
|
| 553 |
+
}
|
| 554 |
+
# Argument to Observable must be Local type
|
| 555 |
+
(my $lv) = $plist->lookup($fargs[0]->Arglist->[0]);
|
| 556 |
+
if ($lv->Type ne "Local"){
|
| 557 |
+
return( "Argument to observable must be a local variable" );
|
| 558 |
+
}
|
| 559 |
+
}
|
| 560 |
+
}
|
| 561 |
+
else
|
| 562 |
+
{
|
| 563 |
+
# if ( $param and ($nargs != @fargs) )
|
| 564 |
+
if ( $type ne '' and $param and ($nargs != @fargs) )
|
| 565 |
+
{ return "Incorrect number of arguments to function $name"; }
|
| 566 |
+
}
|
| 567 |
+
my $express = Expression->new( Type=>'FunctionCall', Arglist=>[$name, @fargs] );
|
| 568 |
+
|
| 569 |
+
if (defined $express_u)
|
| 570 |
+
{
|
| 571 |
+
push @{$express_u->Arglist}, $express;
|
| 572 |
+
push @list, $express_u;
|
| 573 |
+
}
|
| 574 |
+
else
|
| 575 |
+
{ push @list, $express; }
|
| 576 |
+
|
| 577 |
+
$expect_op = 1;
|
| 578 |
+
next;
|
| 579 |
+
}
|
| 580 |
+
|
| 581 |
+
# VARIABLE
|
| 582 |
+
elsif ( $$sptr =~ s/^($ops_un)?\s*(\w+)// )
|
| 583 |
+
{
|
| 584 |
+
my $express_u;
|
| 585 |
+
if ( my $op = $1 )
|
| 586 |
+
{ # (optional) UNARY OP at start of expression, as in -a + b, or -a^2
|
| 587 |
+
$express_u = Expression->new( Type=>$1 );
|
| 588 |
+
}
|
| 589 |
+
my $name = $2;
|
| 590 |
+
|
| 591 |
+
# Validate against ParamList, if present
|
| 592 |
+
if ($plist)
|
| 593 |
+
{
|
| 594 |
+
# Create and set variable if next token is '='
|
| 595 |
+
# otherwise create referenced variable but leave its Expr unset
|
| 596 |
+
unless ( $$sptr =~ /^\s*=/ )
|
| 597 |
+
{
|
| 598 |
+
my ( $param, $err ) = $plist->lookup($name);
|
| 599 |
+
unless ( defined $param )
|
| 600 |
+
{
|
| 601 |
+
if ($allowForward)
|
| 602 |
+
{ $plist->set($name); }
|
| 603 |
+
else
|
| 604 |
+
{ return "Can't reference undefined parameter $name"; }
|
| 605 |
+
}
|
| 606 |
+
}
|
| 607 |
+
}
|
| 608 |
+
else
|
| 609 |
+
{ return "No parameter list provided"; }
|
| 610 |
+
|
| 611 |
+
my $express = Expression->new( Type=>'VAR', Arglist=>[$name] );
|
| 612 |
+
++($variables->{$name});
|
| 613 |
+
|
| 614 |
+
if (defined $express_u)
|
| 615 |
+
{
|
| 616 |
+
push @{$express_u->Arglist}, $express;
|
| 617 |
+
push @list, $express_u;
|
| 618 |
+
}
|
| 619 |
+
else
|
| 620 |
+
{ push @list, $express; }
|
| 621 |
+
|
| 622 |
+
$expect_op = 1;
|
| 623 |
+
next;
|
| 624 |
+
}
|
| 625 |
+
|
| 626 |
+
# Get expression enclosed in parentheses
|
| 627 |
+
elsif ( $$sptr =~ s/^($ops_un)?\s*\(// )
|
| 628 |
+
{
|
| 629 |
+
my $express_u;
|
| 630 |
+
if ( my $op = $1 )
|
| 631 |
+
{ # (optional) UNARY OP at start of expression, as in -a + b, or -a^2
|
| 632 |
+
$express_u = Expression->new( Type=>$1 );
|
| 633 |
+
}
|
| 634 |
+
my $express = Expression->new();
|
| 635 |
+
$err = $express->readString( $sptr, $plist, '\)', $level + 1 );
|
| 636 |
+
if ($err) { return ($err); }
|
| 637 |
+
unless ( $$sptr =~ s/^\s*\)// )
|
| 638 |
+
{ return "Missing end parentheses in $string_sav at $$sptr"; }
|
| 639 |
+
|
| 640 |
+
#printf "express=%s %s\n", $express->toString($plist), $$sptr;
|
| 641 |
+
if (defined $express_u)
|
| 642 |
+
{
|
| 643 |
+
push @{$express_u->Arglist}, $express;
|
| 644 |
+
push @list, $express_u;
|
| 645 |
+
}
|
| 646 |
+
else
|
| 647 |
+
{ push @list, $express; }
|
| 648 |
+
|
| 649 |
+
$expect_op = 1;
|
| 650 |
+
next;
|
| 651 |
+
}
|
| 652 |
+
elsif ( $end_chars and ($$sptr =~ /^\s*[${end_chars}]/) )
|
| 653 |
+
{ last; }
|
| 654 |
+
|
| 655 |
+
# ERROR
|
| 656 |
+
else
|
| 657 |
+
{ return "Expecting operator argument in $string_sav at $$sptr"; }
|
| 658 |
+
}
|
| 659 |
+
|
| 660 |
+
# Transform list into expression preserving operator precedence
|
| 661 |
+
if (@list) { $expr->copy(arrayToExpression(@list)); }
|
| 662 |
+
|
| 663 |
+
return $err;
|
| 664 |
+
}
|
| 665 |
+
}
|
| 666 |
+
|
| 667 |
+
|
| 668 |
+
###
|
| 669 |
+
###
|
| 670 |
+
###
|
| 671 |
+
|
| 672 |
+
|
| 673 |
+
|
| 674 |
+
|
| 675 |
+
# check if expression depends on parameter "varname"
|
| 676 |
+
sub depends
|
| 677 |
+
{
|
| 678 |
+
my $expr = shift;
|
| 679 |
+
my $plist = shift;
|
| 680 |
+
my $varname = shift;
|
| 681 |
+
my $level = (@_) ? shift : 0;
|
| 682 |
+
my $dep = (@_) ? shift : {};
|
| 683 |
+
|
| 684 |
+
my $retval = '';
|
| 685 |
+
my $err = '';
|
| 686 |
+
|
| 687 |
+
my $type = $expr->Type;
|
| 688 |
+
if ( $type eq 'NUM' )
|
| 689 |
+
{
|
| 690 |
+
# this expression is a number: no dependency on varname
|
| 691 |
+
}
|
| 692 |
+
elsif ( $type eq 'VAR' )
|
| 693 |
+
{
|
| 694 |
+
# this expression is a parameter name: check if parameter depends on varname
|
| 695 |
+
my $param_name = $expr->Arglist->[0];
|
| 696 |
+
|
| 697 |
+
if ( exists $dep->{$param_name} and $dep->{$param_name} )
|
| 698 |
+
{
|
| 699 |
+
# cyclic dependency detected
|
| 700 |
+
$err = sprintf "Cycle in parameter $param_name looking for dep in %s", $varname;
|
| 701 |
+
print "$err\n";
|
| 702 |
+
$retval = $param_name;
|
| 703 |
+
}
|
| 704 |
+
else
|
| 705 |
+
{
|
| 706 |
+
if ( $varname eq $param_name )
|
| 707 |
+
{
|
| 708 |
+
# the parameter is varname: we found a dependency!
|
| 709 |
+
$retval = $param_name;
|
| 710 |
+
}
|
| 711 |
+
elsif ($plist)
|
| 712 |
+
{
|
| 713 |
+
# lookup parameter and see what it depends on..
|
| 714 |
+
(my $param) = $plist->lookup($param_name);
|
| 715 |
+
if ( defined $param )
|
| 716 |
+
{
|
| 717 |
+
# copy dependency hash and pass it down
|
| 718 |
+
my $new_dep = { %$dep };
|
| 719 |
+
$new_dep->{$param_name} = 1;
|
| 720 |
+
(my $ret, $err) = $param->Expr->depends($plist, $varname, $level+1, $new_dep);
|
| 721 |
+
if ($ret)
|
| 722 |
+
{
|
| 723 |
+
$retval = $param_name . '->' . $ret;
|
| 724 |
+
}
|
| 725 |
+
}
|
| 726 |
+
}
|
| 727 |
+
}
|
| 728 |
+
}
|
| 729 |
+
else
|
| 730 |
+
{
|
| 731 |
+
# this expression is an operator, function or observable
|
| 732 |
+
# ..check if this depends on varname
|
| 733 |
+
my @arglist = @{ $expr->Arglist };
|
| 734 |
+
# Skip function name if this is a function
|
| 735 |
+
if ( $type eq 'FunctionCall' ) { shift @arglist; }
|
| 736 |
+
foreach my $expr (@arglist)
|
| 737 |
+
{
|
| 738 |
+
($retval, $err) = $expr->depends($plist, $varname, $level + 1, $dep);
|
| 739 |
+
last if $retval;
|
| 740 |
+
}
|
| 741 |
+
}
|
| 742 |
+
|
| 743 |
+
return ($retval, $err);
|
| 744 |
+
}
|
| 745 |
+
|
| 746 |
+
|
| 747 |
+
|
| 748 |
+
###
|
| 749 |
+
###
|
| 750 |
+
###
|
| 751 |
+
|
| 752 |
+
|
| 753 |
+
|
| 754 |
+
# copy the contents of this expression into a second expression.
|
| 755 |
+
# NOTE: this is not recursive!! use the clone method to get a recursive copy
|
| 756 |
+
sub copy
|
| 757 |
+
{
|
| 758 |
+
my $edest = shift;
|
| 759 |
+
my $esource = shift;
|
| 760 |
+
|
| 761 |
+
$edest->Type( $esource->Type );
|
| 762 |
+
$edest->Arglist( [ @{ $esource->Arglist } ] );
|
| 763 |
+
return ($edest);
|
| 764 |
+
}
|
| 765 |
+
|
| 766 |
+
|
| 767 |
+
|
| 768 |
+
###
|
| 769 |
+
###
|
| 770 |
+
###
|
| 771 |
+
|
| 772 |
+
|
| 773 |
+
# evaluate an expression and return a numerical value
|
| 774 |
+
sub evaluate
|
| 775 |
+
{
|
| 776 |
+
my $expr = shift;
|
| 777 |
+
my $plist = (@_) ? shift : undef;
|
| 778 |
+
my $level = (@_) ? shift : 0;
|
| 779 |
+
|
| 780 |
+
if ( $level > $MAX_LEVEL ) { die "Max recursion depth $MAX_LEVEL exceeded."; }
|
| 781 |
+
|
| 782 |
+
my $val = undef;
|
| 783 |
+
if ( $expr->Type eq 'NUM' )
|
| 784 |
+
{
|
| 785 |
+
$val = $expr->Arglist->[0];
|
| 786 |
+
}
|
| 787 |
+
elsif ( $expr->Type eq 'VAR' )
|
| 788 |
+
{
|
| 789 |
+
unless (defined $plist)
|
| 790 |
+
{ die "Expression->evaluate: Error! Cannot evaluate VAR type without ParamList."; }
|
| 791 |
+
|
| 792 |
+
my $name = $expr->Arglist->[0];
|
| 793 |
+
$val = $plist->evaluate( $name, [], $level+1 );
|
| 794 |
+
unless (defined $val)
|
| 795 |
+
{ die "Expression->evaluate: Error! Parameter $name is not defined!\n"; }
|
| 796 |
+
}
|
| 797 |
+
elsif ( $expr->Type eq 'FunctionCall' )
|
| 798 |
+
{
|
| 799 |
+
# first argument is function name
|
| 800 |
+
my $name = $expr->Arglist->[0];
|
| 801 |
+
|
| 802 |
+
if ( ref $name eq "Function" )
|
| 803 |
+
{ # anonymous function (TODO: double-check that its ok to be lazy about evaluating the args
|
| 804 |
+
$val = $name->evaluate( $expr->Arglist, $plist, $level+1);
|
| 805 |
+
}
|
| 806 |
+
elsif ( exists $functions{$name} )
|
| 807 |
+
{ # built-in function
|
| 808 |
+
my $f = $functions{$name}->{FPTR};
|
| 809 |
+
# evaluate all the remaining arguments
|
| 810 |
+
my $eval_args = [];
|
| 811 |
+
my $ii=1;
|
| 812 |
+
while ( $ii < @{$expr->Arglist} )
|
| 813 |
+
{
|
| 814 |
+
push @$eval_args, $expr->Arglist->[$ii]->evaluate($plist, $level+1);
|
| 815 |
+
++$ii;
|
| 816 |
+
}
|
| 817 |
+
$val = $f->(@$eval_args);
|
| 818 |
+
}
|
| 819 |
+
|
| 820 |
+
else
|
| 821 |
+
{ # lookup user-defined function in paramlist
|
| 822 |
+
unless (defined $plist)
|
| 823 |
+
{ die "Expression->evaluate: Error! Cannot evaluate user Function without ParamList."; }
|
| 824 |
+
|
| 825 |
+
$val = $plist->evaluate( $name, $expr->Arglist, $level+1 );
|
| 826 |
+
}
|
| 827 |
+
}
|
| 828 |
+
else
|
| 829 |
+
{
|
| 830 |
+
my $eval_string;
|
| 831 |
+
my $operator = $expr->Type;
|
| 832 |
+
|
| 833 |
+
# replace non-perl operators with the perl equivalents
|
| 834 |
+
if ( $operator eq '~=' ) { $operator = '!='; }
|
| 835 |
+
elsif ( $operator eq '^' ) { $operator = '**'; }
|
| 836 |
+
elsif ( $operator eq '~' ) { $operator = '!'; }
|
| 837 |
+
|
| 838 |
+
if ( @{$expr->Arglist} == 1 )
|
| 839 |
+
{ # handle unary operators
|
| 840 |
+
if ( $operator eq "/" )
|
| 841 |
+
{
|
| 842 |
+
$eval_string = "1.0/(\$expr->Arglist->[0]->evaluate(\$plist,\$level+1))";
|
| 843 |
+
}
|
| 844 |
+
else
|
| 845 |
+
{
|
| 846 |
+
$eval_string = "$operator(\$expr->Arglist->[0]->evaluate(\$plist,\$level+1))";
|
| 847 |
+
}
|
| 848 |
+
|
| 849 |
+
}
|
| 850 |
+
else
|
| 851 |
+
{
|
| 852 |
+
my $last = @{$expr->Arglist} - 1;
|
| 853 |
+
$eval_string = join "$operator", map {"(\$expr->Arglist->[$_]->evaluate(\$plist,\$level+1))"} (0..$last);
|
| 854 |
+
}
|
| 855 |
+
|
| 856 |
+
# check if this is boolean type
|
| 857 |
+
if ( $operator =~ /[<>|&!=]/ )
|
| 858 |
+
{
|
| 859 |
+
# evaluate the expression
|
| 860 |
+
local $SIG{__WARN__} = sub {};
|
| 861 |
+
$val = eval "$eval_string" ? 1 : 0;
|
| 862 |
+
if ($@) { die $@; }
|
| 863 |
+
}
|
| 864 |
+
else
|
| 865 |
+
{
|
| 866 |
+
# evaluate the expression
|
| 867 |
+
local $SIG{__WARN__} = sub {};
|
| 868 |
+
$val = eval "$eval_string";
|
| 869 |
+
if ($@) { die $@; }
|
| 870 |
+
}
|
| 871 |
+
}
|
| 872 |
+
|
| 873 |
+
return $val;
|
| 874 |
+
}
|
| 875 |
+
|
| 876 |
+
|
| 877 |
+
|
| 878 |
+
###
|
| 879 |
+
###
|
| 880 |
+
###
|
| 881 |
+
|
| 882 |
+
|
| 883 |
+
|
| 884 |
+
# Call this method to clone an expression and then descend into the expression
|
| 885 |
+
# and evaluate any local observables. The method returns the cloned variable
|
| 886 |
+
# with local observables evaluated as numbers. NOTE: this method will not
|
| 887 |
+
# work correctly if observables haven't been computed prior to the call.
|
| 888 |
+
sub evaluate_local
|
| 889 |
+
{
|
| 890 |
+
my $expr = shift @_;
|
| 891 |
+
my $plist = @_ ? shift @_ : undef;
|
| 892 |
+
my $level = @_ ? shift @_ : 0;
|
| 893 |
+
|
| 894 |
+
if ( $level > $MAX_LEVEL ) { return (undef, "Max recursion depth $MAX_LEVEL exceeded."); }
|
| 895 |
+
unless (defined $plist) { die "Expression->evaluate_local: Error! Function called without required ParamList."; }
|
| 896 |
+
|
| 897 |
+
# local variables
|
| 898 |
+
my $local_expr = undef;
|
| 899 |
+
my $err = '';
|
| 900 |
+
|
| 901 |
+
# clone expression
|
| 902 |
+
($local_expr, $err) = $expr->clone( $plist, $level+1 );
|
| 903 |
+
|
| 904 |
+
# evaluate local dependencies in arguments
|
| 905 |
+
foreach my $arg ( @{$local_expr->Arglist} )
|
| 906 |
+
{
|
| 907 |
+
# only need to do this for expression arguments
|
| 908 |
+
if ( ref $arg eq 'Expression' )
|
| 909 |
+
{ $arg = $arg->evaluate_local($plist, $level+1); }
|
| 910 |
+
}
|
| 911 |
+
|
| 912 |
+
# some additional handling for Function expressions!
|
| 913 |
+
if ( $expr->Type eq 'FunctionCall' )
|
| 914 |
+
{
|
| 915 |
+
# if local arguments are passed to this function, then we
|
| 916 |
+
# must go into the function and evaluate the local bits. Then
|
| 917 |
+
# we need to create a clone of the function that has the local bits evaluated.
|
| 918 |
+
# Yuck!
|
| 919 |
+
|
| 920 |
+
# First argument is the function name
|
| 921 |
+
my $name = $expr->Arglist->[0];
|
| 922 |
+
|
| 923 |
+
if ( ref $name eq "Function" )
|
| 924 |
+
{ # anonymous function..
|
| 925 |
+
my $fcn = $name;
|
| 926 |
+
# get locally evaluated function
|
| 927 |
+
my ($local_fcn, $elim_args) = $fcn->evaluate_local( $local_expr->Arglist, $plist, $level+1 );
|
| 928 |
+
|
| 929 |
+
# if the local_fcn does not refer to observables of named functions,
|
| 930 |
+
# then we can convert it to a constant expression
|
| 931 |
+
my $dependencies = $local_fcn->Expr->getVariables($plist);
|
| 932 |
+
if ( @{$local_fcn->Args}==0
|
| 933 |
+
and not exists $dependencies->{'Observable'}
|
| 934 |
+
and not exists $dependencies->{'Function'} )
|
| 935 |
+
{ # replace this fcn call with the localfcn expression
|
| 936 |
+
$local_expr = $local_fcn->Expr;
|
| 937 |
+
}
|
| 938 |
+
else
|
| 939 |
+
{ # point this fcn call to the local expr
|
| 940 |
+
$local_expr->Arglist->[0] = $local_fcn;
|
| 941 |
+
# eliminate unused arguments
|
| 942 |
+
foreach my $iarg (@$elim_args)
|
| 943 |
+
{ splice @{$local_expr->Arglist}, $iarg, 1; }
|
| 944 |
+
}
|
| 945 |
+
}
|
| 946 |
+
elsif ( exists $functions{$name} )
|
| 947 |
+
{
|
| 948 |
+
# nothing to do
|
| 949 |
+
}
|
| 950 |
+
else
|
| 951 |
+
{ # custom, named function
|
| 952 |
+
# lookup function parameter:
|
| 953 |
+
(my $fcn_param) = $plist->lookup( $name );
|
| 954 |
+
|
| 955 |
+
# Is this a true function or an observable??
|
| 956 |
+
if ( $fcn_param->Type eq 'Function' )
|
| 957 |
+
{
|
| 958 |
+
# get locally evaluated function
|
| 959 |
+
my ($local_fcn, $elim_args) = $fcn_param->Ref->evaluate_local( $local_expr->Arglist, $plist, $level+1 );
|
| 960 |
+
|
| 961 |
+
# if the local_fcn does not refer to observables of named functions,
|
| 962 |
+
# then we can convert it to a constant expression
|
| 963 |
+
my $dependencies = $local_fcn->Expr->getVariables($plist);
|
| 964 |
+
if ( @{$local_fcn->Args}==0
|
| 965 |
+
and not exists $dependencies->{'Observable'}
|
| 966 |
+
and not exists $dependencies->{'Function'} )
|
| 967 |
+
{ # replace this fcn call with the localfcn expression
|
| 968 |
+
$local_expr = $local_fcn->Expr;
|
| 969 |
+
}
|
| 970 |
+
else
|
| 971 |
+
{ # point this fcn call to the local expr
|
| 972 |
+
$local_expr->Arglist->[0] = $local_fcn;
|
| 973 |
+
# eliminate unused arguments
|
| 974 |
+
foreach my $iarg (@$elim_args)
|
| 975 |
+
{ splice @{$local_expr->Arglist}, $iarg, 1; }
|
| 976 |
+
}
|
| 977 |
+
}
|
| 978 |
+
# This function is Really an Observable!!
|
| 979 |
+
elsif ( $fcn_param->Type eq 'Observable' )
|
| 980 |
+
{
|
| 981 |
+
if ( @{$expr->Arglist} > 1 )
|
| 982 |
+
{
|
| 983 |
+
# get locally evaluated function
|
| 984 |
+
my $val = $fcn_param->Ref->evaluate( $local_expr->Arglist, $plist, $level+1 );
|
| 985 |
+
|
| 986 |
+
# replace local expression with the evaluation
|
| 987 |
+
my $args = [ $val ];
|
| 988 |
+
$local_expr->Type('NUM');
|
| 989 |
+
$local_expr->Arglist($args);
|
| 990 |
+
$local_expr->Err(undef);
|
| 991 |
+
}
|
| 992 |
+
}
|
| 993 |
+
# The reference type is not known, abort with error!
|
| 994 |
+
else
|
| 995 |
+
{ $err = "ERROR in Expression->evaluate_local(): expression is a function, but ref type is unknown!"; }
|
| 996 |
+
}
|
| 997 |
+
}
|
| 998 |
+
|
| 999 |
+
return $local_expr;
|
| 1000 |
+
}
|
| 1001 |
+
|
| 1002 |
+
|
| 1003 |
+
|
| 1004 |
+
###
|
| 1005 |
+
###
|
| 1006 |
+
###
|
| 1007 |
+
|
| 1008 |
+
|
| 1009 |
+
# check for local observable dependency, return true if found
|
| 1010 |
+
sub checkLocalDependency
|
| 1011 |
+
{
|
| 1012 |
+
my $expr = shift;
|
| 1013 |
+
my $plist = shift;
|
| 1014 |
+
my $level = (@_) ? shift : 0;
|
| 1015 |
+
|
| 1016 |
+
unless ( defined $plist )
|
| 1017 |
+
{ die "Expression->checkLocalDependency: Error! Missing argument ParamList!"; }
|
| 1018 |
+
|
| 1019 |
+
|
| 1020 |
+
# check dependence of arguments
|
| 1021 |
+
foreach my $arg ( @{$expr->Arglist} )
|
| 1022 |
+
{
|
| 1023 |
+
if ( ref $arg eq 'Expression' )
|
| 1024 |
+
{
|
| 1025 |
+
return 1 if ( $arg->checkLocalDependency( $plist, $level+1 ) );
|
| 1026 |
+
}
|
| 1027 |
+
}
|
| 1028 |
+
|
| 1029 |
+
if ( $expr->Type eq 'FunctionCall' )
|
| 1030 |
+
{
|
| 1031 |
+
my $name = $expr->Arglist->[0];
|
| 1032 |
+
|
| 1033 |
+
if ( ref $name eq "Function" )
|
| 1034 |
+
{ # anonymous function..
|
| 1035 |
+
my $fcn = $name;
|
| 1036 |
+
return 1 if ( $fcn->checkLocalDependency( $plist, $level+1 ) );
|
| 1037 |
+
}
|
| 1038 |
+
elsif ( exists $functions{$name} )
|
| 1039 |
+
{
|
| 1040 |
+
# nothing to do
|
| 1041 |
+
}
|
| 1042 |
+
else
|
| 1043 |
+
{ # lookup custom function by name
|
| 1044 |
+
my ($fcn_param) = $plist->lookup( $expr->Arglist->[0] );
|
| 1045 |
+
# is this a true function or an observable?
|
| 1046 |
+
if ( $fcn_param->Type eq 'Function' )
|
| 1047 |
+
{
|
| 1048 |
+
my $fcn = $fcn_param->Ref;
|
| 1049 |
+
return 1 if ( $fcn->checkLocalDependency( $plist, $level+1 ) );
|
| 1050 |
+
}
|
| 1051 |
+
elsif ( $fcn_param->Type eq 'Observable' )
|
| 1052 |
+
{
|
| 1053 |
+
# function observables are locally dependent!!
|
| 1054 |
+
return (@{$expr->Arglist} > 1 ? 1 : 0);
|
| 1055 |
+
}
|
| 1056 |
+
}
|
| 1057 |
+
}
|
| 1058 |
+
|
| 1059 |
+
return 0;
|
| 1060 |
+
}
|
| 1061 |
+
|
| 1062 |
+
|
| 1063 |
+
###
|
| 1064 |
+
###
|
| 1065 |
+
###
|
| 1066 |
+
|
| 1067 |
+
|
| 1068 |
+
# check if two expressions are equivalent
|
| 1069 |
+
sub equivalent
|
| 1070 |
+
{
|
| 1071 |
+
my $expr1 = shift @_;
|
| 1072 |
+
my $expr2 = shift @_;
|
| 1073 |
+
my $plist = (@_) ? shift : undef;
|
| 1074 |
+
my $level = (@_) ? shift : 0;
|
| 1075 |
+
|
| 1076 |
+
# make sure we have defined expressions!
|
| 1077 |
+
return 0 unless ( defined $expr1 and ref $expr1 eq 'Expression' );
|
| 1078 |
+
return 0 unless ( defined $expr2 and ref $expr2 eq 'Expression' );
|
| 1079 |
+
|
| 1080 |
+
# shortcut: first check if we're looking at the same object
|
| 1081 |
+
return 1 if ( $expr1 == $expr2 );
|
| 1082 |
+
|
| 1083 |
+
# check type equivalence
|
| 1084 |
+
return 0 unless ( $expr1->Type eq $expr2->Type );
|
| 1085 |
+
|
| 1086 |
+
# check for equal number of arguments
|
| 1087 |
+
return 0 unless ( @{$expr1->Arglist} == @{$expr2->Arglist} );
|
| 1088 |
+
|
| 1089 |
+
# now we have to look deeper into the arguments
|
| 1090 |
+
if ( $expr1->Type eq 'NUM' )
|
| 1091 |
+
{
|
| 1092 |
+
# compare numbers
|
| 1093 |
+
return ( $expr1->Arglist->[0] == $expr2->Arglist->[0] );
|
| 1094 |
+
}
|
| 1095 |
+
elsif ( $expr2->Type eq 'VAR' )
|
| 1096 |
+
{
|
| 1097 |
+
# compare var names
|
| 1098 |
+
return ( $expr1->Arglist->[0] eq $expr2->Arglist->[0] );
|
| 1099 |
+
}
|
| 1100 |
+
elsif ( $expr2->Type eq 'FunctionCall' )
|
| 1101 |
+
{
|
| 1102 |
+
# compare function names (or refs)
|
| 1103 |
+
return 0 unless ( ref $expr1->Arglist->[0] eq ref $expr2->Arglist->[0] );
|
| 1104 |
+
return 0 unless ( $expr1->Arglist->[0] eq $expr2->Arglist->[0] );
|
| 1105 |
+
|
| 1106 |
+
# check argument equivalence
|
| 1107 |
+
for ( my $i = 1; $i < @{$expr1->Arglist}; ++$i )
|
| 1108 |
+
{
|
| 1109 |
+
return 0
|
| 1110 |
+
unless ( Expression::equivalent($expr1->Arglist->[$i], $expr2->Arglist->[$i], $plist, $level+1) );
|
| 1111 |
+
}
|
| 1112 |
+
}
|
| 1113 |
+
else
|
| 1114 |
+
{
|
| 1115 |
+
# check argument equivalence
|
| 1116 |
+
for ( my $i = 0; $i < @{$expr1->Arglist}; ++$i )
|
| 1117 |
+
{
|
| 1118 |
+
return 0
|
| 1119 |
+
unless ( Expression::equivalent($expr1->Arglist->[$i], $expr2->Arglist->[$i], $plist, $level+1) );
|
| 1120 |
+
}
|
| 1121 |
+
}
|
| 1122 |
+
|
| 1123 |
+
# return true if no differences have been found
|
| 1124 |
+
return 1;
|
| 1125 |
+
}
|
| 1126 |
+
|
| 1127 |
+
|
| 1128 |
+
|
| 1129 |
+
|
| 1130 |
+
# write this expression as a string.
|
| 1131 |
+
# The expression is expanded up to the named Parameters and Functions.
|
| 1132 |
+
sub toString
|
| 1133 |
+
{
|
| 1134 |
+
my $expr = shift;
|
| 1135 |
+
my $plist = (@_) ? shift : undef;
|
| 1136 |
+
my $level = (@_) ? shift : 0;
|
| 1137 |
+
my $expand = (@_) ? shift : 0;
|
| 1138 |
+
|
| 1139 |
+
# simple error checking
|
| 1140 |
+
if ( $level > $MAX_LEVEL ) { die "Max recursion depth $MAX_LEVEL exceeded."; }
|
| 1141 |
+
if ( $expand and !$plist ) { die "Can't expand expression past parameters without a parameter list."; }
|
| 1142 |
+
|
| 1143 |
+
# local variables
|
| 1144 |
+
my $err;
|
| 1145 |
+
my $string;
|
| 1146 |
+
|
| 1147 |
+
# different handling depending on the type
|
| 1148 |
+
my $type = $expr->Type;
|
| 1149 |
+
if ( $type eq 'NUM' )
|
| 1150 |
+
{
|
| 1151 |
+
# if number, print the numerical value!
|
| 1152 |
+
$string = $expr->Arglist->[0];
|
| 1153 |
+
#print "NUM=$string\n";
|
| 1154 |
+
}
|
| 1155 |
+
elsif ( $type eq 'VAR' )
|
| 1156 |
+
{
|
| 1157 |
+
if ( $expand )
|
| 1158 |
+
{ # descend recursively into parameter!
|
| 1159 |
+
( my $param, $err ) = $plist->lookup( $expr->Arglist->[0] );
|
| 1160 |
+
$string = $param->toString( $plist, $level+1, $expand );
|
| 1161 |
+
}
|
| 1162 |
+
else
|
| 1163 |
+
{ # just write the parameter name
|
| 1164 |
+
$string = $expr->Arglist->[0];
|
| 1165 |
+
}
|
| 1166 |
+
#$string= $expr->evaluate($plist);
|
| 1167 |
+
#print "VAR=$string\n";
|
| 1168 |
+
}
|
| 1169 |
+
elsif ( $type eq 'FunctionCall' )
|
| 1170 |
+
{
|
| 1171 |
+
my $name = $expr->Arglist->[0];
|
| 1172 |
+
if ( $expand or (ref $name eq "Function") )
|
| 1173 |
+
{ # expand the function
|
| 1174 |
+
my @sarr = ($expr->Arglist->[0]);
|
| 1175 |
+
foreach my $i ( 1 .. $#{$expr->Arglist} )
|
| 1176 |
+
{ push @sarr, $expr->Arglist->[$i]->toString($plist, $level+1, $expand); }
|
| 1177 |
+
|
| 1178 |
+
if (ref $name eq "Function")
|
| 1179 |
+
{ # anonymous function
|
| 1180 |
+
my $fcn = $name;
|
| 1181 |
+
(my $local_fcn) = $fcn->evaluate_local( \@sarr, $plist, $level+1 );
|
| 1182 |
+
$string = $local_fcn->Expr->toString( $plist, $level+1, $expand );
|
| 1183 |
+
}
|
| 1184 |
+
elsif ( exists $functions{$name} )
|
| 1185 |
+
{ # built-in function
|
| 1186 |
+
$string = $expr->Arglist->[0] . "(" . join(",", @sarr[1..$#sarr]) . ")";
|
| 1187 |
+
}
|
| 1188 |
+
else
|
| 1189 |
+
{ # lookup custom function by name and expand
|
| 1190 |
+
( my $param, $err ) = $plist->lookup($name);
|
| 1191 |
+
(my $local_fcn) = $param->Ref->evaluate_local( \@sarr, $plist, $level+1 );
|
| 1192 |
+
$string = $local_fcn->Expr->toString( $plist, $level+1, $expand );
|
| 1193 |
+
}
|
| 1194 |
+
}
|
| 1195 |
+
else
|
| 1196 |
+
{ # just write the function and its argument values
|
| 1197 |
+
my @sarr = ();
|
| 1198 |
+
foreach my $i ( 1 .. $#{$expr->Arglist} )
|
| 1199 |
+
{
|
| 1200 |
+
push @sarr, $expr->Arglist->[$i]->toString( $plist, $level + 1 );
|
| 1201 |
+
}
|
| 1202 |
+
$string = $name . '(' . join( ',', @sarr ) . ')';
|
| 1203 |
+
}
|
| 1204 |
+
}
|
| 1205 |
+
else
|
| 1206 |
+
{
|
| 1207 |
+
if ( $expand )
|
| 1208 |
+
{
|
| 1209 |
+
my @sarr = ();
|
| 1210 |
+
foreach my $e ( @{ $expr->Arglist } ) {
|
| 1211 |
+
push @sarr, $e->toString( $plist, $level+1, $expand );
|
| 1212 |
+
}
|
| 1213 |
+
if ( $#sarr > 0 )
|
| 1214 |
+
{ $string = join( $type, @sarr ); }
|
| 1215 |
+
else
|
| 1216 |
+
{ $string = $type . $sarr[0]; }
|
| 1217 |
+
|
| 1218 |
+
# enclose in brackets if not at top level
|
| 1219 |
+
# print "level=$level\n";
|
| 1220 |
+
if ($level)
|
| 1221 |
+
{ $string = '(' . $string . ')'; }
|
| 1222 |
+
}
|
| 1223 |
+
else
|
| 1224 |
+
{
|
| 1225 |
+
my @sarr = ();
|
| 1226 |
+
foreach my $e ( @{ $expr->Arglist } ) {
|
| 1227 |
+
push @sarr, $e->toString( $plist, $level + 1 );
|
| 1228 |
+
}
|
| 1229 |
+
if ( $#sarr > 0 )
|
| 1230 |
+
{
|
| 1231 |
+
$string = join( $type, @sarr );
|
| 1232 |
+
}
|
| 1233 |
+
else {
|
| 1234 |
+
$string = $type . $sarr[0];
|
| 1235 |
+
}
|
| 1236 |
+
|
| 1237 |
+
# enclose in brackets if not at top level
|
| 1238 |
+
# print "level=$level\n";
|
| 1239 |
+
if ($level) {
|
| 1240 |
+
$string = '(' . $string . ')';
|
| 1241 |
+
}
|
| 1242 |
+
#printf "%s=$string\n", $expr->Type;
|
| 1243 |
+
}
|
| 1244 |
+
}
|
| 1245 |
+
|
| 1246 |
+
return $string;
|
| 1247 |
+
}
|
| 1248 |
+
|
| 1249 |
+
|
| 1250 |
+
|
| 1251 |
+
# write this expression as an XML string.
|
| 1252 |
+
# Same as toString, except a few operators are replaced to avoid clashes with XML
|
| 1253 |
+
sub toXML
|
| 1254 |
+
{
|
| 1255 |
+
my $expr = shift;
|
| 1256 |
+
my $plist = (@_) ? shift : undef;
|
| 1257 |
+
my $level = (@_) ? shift : 0;
|
| 1258 |
+
my $expand = (@_) ? shift : 0;
|
| 1259 |
+
|
| 1260 |
+
# simple error checking
|
| 1261 |
+
if ( $level > $MAX_LEVEL ) { die "Max recursion depth $MAX_LEVEL exceeded."; }
|
| 1262 |
+
if ( $expand and !$plist ) { die "Can't expand expression past parameters without a parameter list."; }
|
| 1263 |
+
|
| 1264 |
+
# local variables
|
| 1265 |
+
my $err;
|
| 1266 |
+
my $string;
|
| 1267 |
+
|
| 1268 |
+
# different handling depending on the type
|
| 1269 |
+
my $type = $expr->Type;
|
| 1270 |
+
if ( $type eq 'NUM' )
|
| 1271 |
+
{
|
| 1272 |
+
# if number, print the numerical value!
|
| 1273 |
+
$string = $expr->Arglist->[0];
|
| 1274 |
+
}
|
| 1275 |
+
elsif ( $type eq 'VAR' )
|
| 1276 |
+
{
|
| 1277 |
+
if ( $expand )
|
| 1278 |
+
{
|
| 1279 |
+
# descend recursively into parameter!
|
| 1280 |
+
( my $param, $err ) = $plist->lookup( $expr->Arglist->[0] );
|
| 1281 |
+
$string = $param->toXML( $plist, $level+1, $expand );
|
| 1282 |
+
}
|
| 1283 |
+
else
|
| 1284 |
+
{
|
| 1285 |
+
# just write the parameter name
|
| 1286 |
+
$string = $expr->Arglist->[0];
|
| 1287 |
+
}
|
| 1288 |
+
}
|
| 1289 |
+
elsif ( $type eq 'FunctionCall' )
|
| 1290 |
+
{
|
| 1291 |
+
if ( $expand )
|
| 1292 |
+
{
|
| 1293 |
+
# TODO
|
| 1294 |
+
my @sarr = ();
|
| 1295 |
+
foreach my $i ( 1 .. $#{$expr->Arglist} )
|
| 1296 |
+
{
|
| 1297 |
+
push @sarr, $expr->Arglist->[$i]->toXML( $plist, $level + 1 );
|
| 1298 |
+
}
|
| 1299 |
+
$string = $expr->Arglist->[0] . '(' . join( ',', @sarr ) . ')';
|
| 1300 |
+
}
|
| 1301 |
+
else
|
| 1302 |
+
{
|
| 1303 |
+
my @sarr = ();
|
| 1304 |
+
foreach my $i ( 1 .. $#{$expr->Arglist} )
|
| 1305 |
+
{
|
| 1306 |
+
push @sarr, $expr->Arglist->[$i]->toXML( $plist, $level + 1 );
|
| 1307 |
+
}
|
| 1308 |
+
$string = $expr->Arglist->[0] . '(' . join( ',', @sarr ) . ')';
|
| 1309 |
+
}
|
| 1310 |
+
}
|
| 1311 |
+
else
|
| 1312 |
+
{
|
| 1313 |
+
if ( $expand )
|
| 1314 |
+
{
|
| 1315 |
+
my @sarr = ();
|
| 1316 |
+
foreach my $e ( @{$expr->Arglist} )
|
| 1317 |
+
{
|
| 1318 |
+
push @sarr, $e->toXML( $plist, $level+1, $expand );
|
| 1319 |
+
}
|
| 1320 |
+
if ( $#sarr > 0 )
|
| 1321 |
+
{ $string = join( $type, @sarr ); }
|
| 1322 |
+
else
|
| 1323 |
+
{ $string = $type . $sarr[0]; }
|
| 1324 |
+
|
| 1325 |
+
# enclose in brackets if not at top level
|
| 1326 |
+
# print "level=$level\n";
|
| 1327 |
+
if ($level)
|
| 1328 |
+
{ $string = '(' . $string . ')'; }
|
| 1329 |
+
}
|
| 1330 |
+
else
|
| 1331 |
+
{
|
| 1332 |
+
my @sarr = ();
|
| 1333 |
+
foreach my $e ( @{ $expr->Arglist } ) {
|
| 1334 |
+
push @sarr, $e->toXML( $plist, $level + 1 );
|
| 1335 |
+
}
|
| 1336 |
+
if ( $#sarr > 0 )
|
| 1337 |
+
{
|
| 1338 |
+
$string = join( $type, @sarr );
|
| 1339 |
+
}
|
| 1340 |
+
else {
|
| 1341 |
+
$string = $type . $sarr[0];
|
| 1342 |
+
}
|
| 1343 |
+
|
| 1344 |
+
# enclose in brackets if not at top level
|
| 1345 |
+
# print "level=$level\n";
|
| 1346 |
+
if ($level) {
|
| 1347 |
+
$string = '(' . $string . ')';
|
| 1348 |
+
}
|
| 1349 |
+
#printf "%s=$string\n", $expr->Type;
|
| 1350 |
+
}
|
| 1351 |
+
}
|
| 1352 |
+
|
| 1353 |
+
# TODO: special handling for XML output should be handled by a special option
|
| 1354 |
+
# or a toXML sub. --Justin
|
| 1355 |
+
|
| 1356 |
+
#BEGIN edit, msneddon
|
| 1357 |
+
# for outputting to XML, we need to make sure we put in some special
|
| 1358 |
+
# characters and operators to match the muParser library and to allow
|
| 1359 |
+
# the XML parser to work.<" with "<", ">" with ">", and
|
| 1360 |
+
#"&" with "&
|
| 1361 |
+
#print "before XML replacement: $string\n";
|
| 1362 |
+
$string =~ s/</<\;/;
|
| 1363 |
+
$string =~ s/>/>\;/;
|
| 1364 |
+
$string =~ s/&&/and/;
|
| 1365 |
+
$string =~ s/\|\|/or/;
|
| 1366 |
+
#print "after XML replacement: $string\n";
|
| 1367 |
+
#END edit, msneddon
|
| 1368 |
+
|
| 1369 |
+
return ($string);
|
| 1370 |
+
}
|
| 1371 |
+
|
| 1372 |
+
|
| 1373 |
+
|
| 1374 |
+
|
| 1375 |
+
# write expression as a string suitable for
|
| 1376 |
+
# export to CVode. This is the same as toString,
|
| 1377 |
+
# except variable names are replaced with pointers into
|
| 1378 |
+
# arrays.
|
| 1379 |
+
sub toCVodeString
|
| 1380 |
+
{
|
| 1381 |
+
my $expr = shift;
|
| 1382 |
+
my $plist = (@_) ? shift : '';
|
| 1383 |
+
my $level = (@_) ? shift : 0;
|
| 1384 |
+
my $expand = (@_) ? shift : 0;
|
| 1385 |
+
|
| 1386 |
+
if ( $level > $MAX_LEVEL ) { die "Max recursion depth $MAX_LEVEL exceeded."; }
|
| 1387 |
+
|
| 1388 |
+
my $string;
|
| 1389 |
+
my $err;
|
| 1390 |
+
|
| 1391 |
+
my $type = $expr->Type;
|
| 1392 |
+
|
| 1393 |
+
if ( $type eq 'NUM' )
|
| 1394 |
+
{
|
| 1395 |
+
$string = $expr->Arglist->[0];
|
| 1396 |
+
# if this is a pure integer,
|
| 1397 |
+
# add a decimal place to make sure C knows this has type double
|
| 1398 |
+
$string =~ s/^(\d+)$/$1.0/;
|
| 1399 |
+
}
|
| 1400 |
+
elsif ( $type eq 'VAR' )
|
| 1401 |
+
{
|
| 1402 |
+
# lookup corresponding parameter ...
|
| 1403 |
+
(my $param, $err) = $plist->lookup( $expr->Arglist->[0] );
|
| 1404 |
+
if ($param)
|
| 1405 |
+
{ # return cvode ref
|
| 1406 |
+
$string = $param->getCVodeName();
|
| 1407 |
+
}
|
| 1408 |
+
else
|
| 1409 |
+
{ # parameter not defined, assume it's a local argument and write its name
|
| 1410 |
+
$string = $expr->Arglist->[0];
|
| 1411 |
+
}
|
| 1412 |
+
}
|
| 1413 |
+
elsif ( $type eq 'FunctionCall' )
|
| 1414 |
+
{
|
| 1415 |
+
# the first argument is the function name
|
| 1416 |
+
my $fcn_name = $expr->Arglist->[0];
|
| 1417 |
+
|
| 1418 |
+
if ( ref $fcn_name eq "Function" )
|
| 1419 |
+
{ # anonymous function
|
| 1420 |
+
my $fcn = $fcn_name;
|
| 1421 |
+
# we can't call function by name, so we have to expand the function expression with args in place
|
| 1422 |
+
(my $local_fcn) = $fcn->evaluate_local( [@{$expr->Arglist}], $plist, $level+1 );
|
| 1423 |
+
unless (defined $local_fcn) { die "Error in Expression->toMatlabString(): some problem evaluating anonymous function"; }
|
| 1424 |
+
$string = $local_fcn->Expr->toCVodeString($plist, $level+1, $expand);
|
| 1425 |
+
}
|
| 1426 |
+
elsif ( exists $functions{ $expr->Arglist->[0] } )
|
| 1427 |
+
{ # this is a built-in function
|
| 1428 |
+
# handle built-ins with 1 argument that have the same name in the C library
|
| 1429 |
+
if ( $fcn_name =~ /^(sin|cos|exp|log|abs|sqrt|floor|ceil)$/ )
|
| 1430 |
+
{
|
| 1431 |
+
my @sarr = ( map {$_->toCVodeString($plist, $level+1, $expand)} @{$expr->Arglist}[1..$#{$expr->Arglist}] );
|
| 1432 |
+
$string = $fcn_name .'('. join( ',', @sarr ) .')';
|
| 1433 |
+
}
|
| 1434 |
+
# handle the 'if' built-in with 3 arguments
|
| 1435 |
+
elsif ( $fcn_name eq 'if' )
|
| 1436 |
+
{
|
| 1437 |
+
# substitute the "?" operator for the if function
|
| 1438 |
+
my @sarr = ( map {$_->toCVodeString($plist, $level+1)} @{$expr->Arglist}[1..$#{$expr->Arglist}] );
|
| 1439 |
+
|
| 1440 |
+
if ( @sarr == 3)
|
| 1441 |
+
{ $string = '('. $sarr[0] .' ? '. $sarr[1] .' : '. $sarr[2] .')'; }
|
| 1442 |
+
else
|
| 1443 |
+
{ die "Error in Expression->toCVodeString(): built-in function 'if' must have three arguments!"; }
|
| 1444 |
+
}
|
| 1445 |
+
# fatal error if the built-in is not handled above
|
| 1446 |
+
else
|
| 1447 |
+
{ die "Error in Expression->toCVodeString(): don't know how to handle built-in function $fcn_name!"; }
|
| 1448 |
+
}
|
| 1449 |
+
else
|
| 1450 |
+
{ # user-defined function or observable
|
| 1451 |
+
# lookup function parameter:
|
| 1452 |
+
(my $fcn_param) = $plist->lookup( $fcn_name );
|
| 1453 |
+
unless ($fcn_param)
|
| 1454 |
+
{ die "Error in Expression->toCVodeString: could not find function parameter!"; }
|
| 1455 |
+
|
| 1456 |
+
# Is this a true function or an observable??
|
| 1457 |
+
if ( $fcn_param->Type eq 'Function' )
|
| 1458 |
+
{ # Handling a true Function!
|
| 1459 |
+
# expand argument expressions up until named entities
|
| 1460 |
+
my @sarr = ( map {$_->toCVodeString($plist, $level+1, $expand)} @{$expr->Arglist}[1..$#{$expr->Arglist}] );
|
| 1461 |
+
# pass arguments pointing to the expressions array and observables array
|
| 1462 |
+
push @sarr, 'expressions', 'observables';
|
| 1463 |
+
$string = $fcn_name . '(' . join( ',', @sarr ) . ')';
|
| 1464 |
+
}
|
| 1465 |
+
elsif ( $fcn_param->Type eq 'Observable' )
|
| 1466 |
+
{
|
| 1467 |
+
# TODO: if there are arguments, then we should warn the user that we can't evaluate a local
|
| 1468 |
+
# observables in a CVode function!!
|
| 1469 |
+
$string = $fcn_param->getCVodeName();
|
| 1470 |
+
}
|
| 1471 |
+
else
|
| 1472 |
+
{ die "Error in Expression->toCVodeString(): don't know how to process function expression of non-function type!"; }
|
| 1473 |
+
|
| 1474 |
+
}
|
| 1475 |
+
|
| 1476 |
+
}
|
| 1477 |
+
elsif ( ($type eq '**') or ($type eq '^') )
|
| 1478 |
+
{
|
| 1479 |
+
# substitute the "pow" function for the exponentiation operator
|
| 1480 |
+
my @sarr = ( map {$_->toCVodeString($plist, $level+1)} @{$expr->Arglist} );
|
| 1481 |
+
|
| 1482 |
+
if ( @sarr == 2 )
|
| 1483 |
+
{ $string = 'pow(' . $sarr[0] . ',' . $sarr[1] . ')'; }
|
| 1484 |
+
else
|
| 1485 |
+
{ die "Error in Expression->toCVodeString(): Exponentiation must have exactly two arguments!"; }
|
| 1486 |
+
}
|
| 1487 |
+
else
|
| 1488 |
+
{
|
| 1489 |
+
# handling some other operator (+,-,*,/)
|
| 1490 |
+
# enclose in brackets (always. just to be safe)
|
| 1491 |
+
my @sarr = ( map {$_->toCVodeString($plist, $level+1, $expand)} @{$expr->Arglist} );
|
| 1492 |
+
if ( @sarr > 1 )
|
| 1493 |
+
{ # binary or higher order
|
| 1494 |
+
$string = '(' . join( $type, @sarr ) . ')';
|
| 1495 |
+
}
|
| 1496 |
+
else
|
| 1497 |
+
{ # unary operator
|
| 1498 |
+
$string = '(' . $type . $sarr[0] . ')';
|
| 1499 |
+
}
|
| 1500 |
+
}
|
| 1501 |
+
|
| 1502 |
+
return ($string);
|
| 1503 |
+
}
|
| 1504 |
+
|
| 1505 |
+
|
| 1506 |
+
|
| 1507 |
+
|
| 1508 |
+
# write expression as a string suitable for
|
| 1509 |
+
# export to a Matlab M-file.
|
| 1510 |
+
sub toMatlabString
|
| 1511 |
+
{
|
| 1512 |
+
my $expr = shift @_;
|
| 1513 |
+
my $plist = @_ ? shift @_ : undef;
|
| 1514 |
+
my $level = @_ ? shift @_ : 0;
|
| 1515 |
+
my $expand = @_ ? shift @_ : 0;
|
| 1516 |
+
|
| 1517 |
+
if ( $level > $MAX_LEVEL ) { die "Max recursion depth $MAX_LEVEL exceeded."; }
|
| 1518 |
+
|
| 1519 |
+
my $string;
|
| 1520 |
+
my $err;
|
| 1521 |
+
|
| 1522 |
+
my $type = $expr->Type;
|
| 1523 |
+
|
| 1524 |
+
if ( $type eq 'NUM' )
|
| 1525 |
+
{
|
| 1526 |
+
$string = $expr->Arglist->[0];
|
| 1527 |
+
}
|
| 1528 |
+
elsif ( $type eq 'VAR' )
|
| 1529 |
+
{
|
| 1530 |
+
# lookup corresponding parameter ...
|
| 1531 |
+
(my $param, $err) = $plist->lookup( $expr->Arglist->[0] );
|
| 1532 |
+
if ($param)
|
| 1533 |
+
{ # return matlab ref
|
| 1534 |
+
$string = $param->getMatlabName();
|
| 1535 |
+
}
|
| 1536 |
+
else
|
| 1537 |
+
{ # parameter not defined, assume it's a local argument and write its name
|
| 1538 |
+
$string = $expr->Arglist->[0];
|
| 1539 |
+
}
|
| 1540 |
+
}
|
| 1541 |
+
elsif ( $type eq 'FunctionCall' )
|
| 1542 |
+
{
|
| 1543 |
+
# the first argument is the function name
|
| 1544 |
+
my $fcn_name = $expr->Arglist->[0];
|
| 1545 |
+
|
| 1546 |
+
if ( ref $fcn_name eq "Function" )
|
| 1547 |
+
{ # anonymous function!
|
| 1548 |
+
my $fcn = $fcn_name;
|
| 1549 |
+
# we can't call function by name, so we have to expand the function expression with args in place
|
| 1550 |
+
(my $local_fcn) = $fcn->evaluate_local( [@{$expr->Arglist}], $plist, $level+1 );
|
| 1551 |
+
unless (defined $local_fcn) { die "Error in Expression->toMatlabString(): some problem evaluating anonymous function"; }
|
| 1552 |
+
$string = $local_fcn->Expr->toMatlabString($plist, $level+1, $expand);
|
| 1553 |
+
}
|
| 1554 |
+
elsif ( exists $functions{ $expr->Arglist->[0] } )
|
| 1555 |
+
{
|
| 1556 |
+
# handle built-ins with 1 argument that have the same name in Matlab
|
| 1557 |
+
if ( $fcn_name =~ /^(sin|cos|exp|log|abs|sqrt|floor|ceil)$/ )
|
| 1558 |
+
{
|
| 1559 |
+
my @sarr = ( map {$_->toMatlabString($plist, $level+1, $expand)} @{$expr->Arglist}[1..$#{$expr->Arglist}] );
|
| 1560 |
+
$string = $fcn_name .'('. join( ',', @sarr ) .')';
|
| 1561 |
+
}
|
| 1562 |
+
# handle the 'if' built-in with 3 arguments
|
| 1563 |
+
elsif ( $fcn_name eq 'if' )
|
| 1564 |
+
{
|
| 1565 |
+
# substitute the "?" operator for the if function
|
| 1566 |
+
my @sarr = ( map {$_->toMatlabString($plist, $level+1)} @{$expr->Arglist}[1..$#{$expr->Arglist}] );
|
| 1567 |
+
|
| 1568 |
+
if ( @sarr == 3)
|
| 1569 |
+
{ # TODO: find better solution here. this version will return NaN if either return value is Inf.
|
| 1570 |
+
$string = sprintf( "((%s~=0)*%s + (%s==0)*%s)", $sarr[0], $sarr[1], $sarr[0], $sarr[2]);
|
| 1571 |
+
}
|
| 1572 |
+
else
|
| 1573 |
+
{ die "Error in Expression->toMatlabString(): built-in function 'if' must have three arguments!"; }
|
| 1574 |
+
}
|
| 1575 |
+
# fatal error if the built-in is not handled above
|
| 1576 |
+
else
|
| 1577 |
+
{ die "Error in Expression->toMatlabString(): don't know how to handle built-in function $fcn_name!"; }
|
| 1578 |
+
}
|
| 1579 |
+
else
|
| 1580 |
+
{ # this is a user-defined function or observable
|
| 1581 |
+
# lookup function parameter:
|
| 1582 |
+
(my $fcn_param) = $plist->lookup( $fcn_name );
|
| 1583 |
+
unless ($fcn_param)
|
| 1584 |
+
{ die "Error in Expression->toMatlabString: could not find function parameter!"; }
|
| 1585 |
+
|
| 1586 |
+
# Is this a true function or an observable??
|
| 1587 |
+
if ( $fcn_param->Type eq 'Function' )
|
| 1588 |
+
{ # Handling a true Function!
|
| 1589 |
+
# expand argument expressions up until named entities
|
| 1590 |
+
my @sarr = ( map {$_->toMatlabString($plist, $level+1, $expand)} @{$expr->Arglist}[1..$#{$expr->Arglist}] );
|
| 1591 |
+
# pass arguments pointing to the expressions array and observables array
|
| 1592 |
+
push @sarr, 'expressions', 'observables';
|
| 1593 |
+
$string = $fcn_name . '(' . join( ',', @sarr ) . ')';
|
| 1594 |
+
}
|
| 1595 |
+
elsif ( $fcn_param->Type eq 'Observable' )
|
| 1596 |
+
{
|
| 1597 |
+
# TODO: if there are arguments, then we should warn the user that we can't evaluate a local
|
| 1598 |
+
# observables in a CVode function!!
|
| 1599 |
+
$string = $fcn_param->getMatlabName();
|
| 1600 |
+
}
|
| 1601 |
+
else
|
| 1602 |
+
{ die "Error in Expression->toMatlabString(): don't know how to process function expression of non-function type!"; }
|
| 1603 |
+
}
|
| 1604 |
+
|
| 1605 |
+
}
|
| 1606 |
+
else
|
| 1607 |
+
{
|
| 1608 |
+
# handling some other operator (+,-,*,/)
|
| 1609 |
+
# enclose in brackets (always. just to be safe)
|
| 1610 |
+
my @sarr = ( map {$_->toMatlabString($plist, $level+1, $expand)} @{$expr->Arglist} );
|
| 1611 |
+
if ( @sarr > 1 )
|
| 1612 |
+
{ # binary or higher order
|
| 1613 |
+
$string = '(' . join( $type, @sarr ) . ')';
|
| 1614 |
+
}
|
| 1615 |
+
else
|
| 1616 |
+
{ # unary operator
|
| 1617 |
+
$string = '(' . $type . $sarr[0] . ')';
|
| 1618 |
+
}
|
| 1619 |
+
}
|
| 1620 |
+
|
| 1621 |
+
return $string;
|
| 1622 |
+
}
|
| 1623 |
+
|
| 1624 |
+
|
| 1625 |
+
###
|
| 1626 |
+
###
|
| 1627 |
+
###
|
| 1628 |
+
|
| 1629 |
+
|
| 1630 |
+
{
|
| 1631 |
+
my %ophash =
|
| 1632 |
+
(
|
| 1633 |
+
'+' => 'plus',
|
| 1634 |
+
'-' => 'minus',
|
| 1635 |
+
'*' => 'times',
|
| 1636 |
+
'/' => 'divide',
|
| 1637 |
+
'**' => 'power',
|
| 1638 |
+
'^' => 'power',
|
| 1639 |
+
'&&' => 'and',
|
| 1640 |
+
'||' => 'or',
|
| 1641 |
+
'<' => 'lt',
|
| 1642 |
+
'>' => 'gt',
|
| 1643 |
+
'<=' => 'leq',
|
| 1644 |
+
'>=' => 'geq',
|
| 1645 |
+
'!=' => 'neq',
|
| 1646 |
+
'==' => 'equivalent'
|
| 1647 |
+
);
|
| 1648 |
+
|
| 1649 |
+
my %fnhash =
|
| 1650 |
+
(
|
| 1651 |
+
'_pi' => 'pi',
|
| 1652 |
+
'_e' => 'exponentiale',
|
| 1653 |
+
'exp' => 'exp',
|
| 1654 |
+
'ln' => 'ln',
|
| 1655 |
+
'log10' => 'log',
|
| 1656 |
+
# 'log2' => Requires special handling (see below)
|
| 1657 |
+
'abs' => 'abs',
|
| 1658 |
+
# 'rint' => Requires special handling (see below)
|
| 1659 |
+
'sqrt' => 'root',
|
| 1660 |
+
'cos' => 'cos',
|
| 1661 |
+
'sin' => 'sin',
|
| 1662 |
+
'tan' => 'tan',
|
| 1663 |
+
'asin' => 'arcsin',
|
| 1664 |
+
'acos' => 'arccos',
|
| 1665 |
+
'atan' => 'arctan',
|
| 1666 |
+
'sinh' => 'sinh',
|
| 1667 |
+
'cosh' => 'cosh',
|
| 1668 |
+
'tanh' => 'tanh',
|
| 1669 |
+
'asinh' => 'arcsinh',
|
| 1670 |
+
'acosh' => 'arccosh',
|
| 1671 |
+
'atanh' => 'arctanh',
|
| 1672 |
+
# 'if' => Requires special handling (see below)
|
| 1673 |
+
'min' => 'min',
|
| 1674 |
+
'max' => 'max',
|
| 1675 |
+
'sum' => 'sum',
|
| 1676 |
+
'avg' => 'mean'
|
| 1677 |
+
);
|
| 1678 |
+
|
| 1679 |
+
sub toMathMLString
|
| 1680 |
+
{
|
| 1681 |
+
my $expr = shift;
|
| 1682 |
+
my $plist = (@_) ? shift : '';
|
| 1683 |
+
my $indent = (@_) ? shift : '';
|
| 1684 |
+
my $level = (@_) ? shift : 0;
|
| 1685 |
+
|
| 1686 |
+
if ( $level > $MAX_LEVEL ) { die "Max recursion depth $MAX_LEVEL exceeded."; }
|
| 1687 |
+
|
| 1688 |
+
my $string = "";
|
| 1689 |
+
my $indentp = $indent;
|
| 1690 |
+
if ( $level == 0 )
|
| 1691 |
+
{
|
| 1692 |
+
$string .=
|
| 1693 |
+
$indent . "<math xmlns=\"http://www.w3.org/1998/Math/MathML\">\n";
|
| 1694 |
+
$indentp .= " ";
|
| 1695 |
+
}
|
| 1696 |
+
|
| 1697 |
+
my $type = $expr->Type;
|
| 1698 |
+
if ( $type eq 'NUM' )
|
| 1699 |
+
{
|
| 1700 |
+
$string .= sprintf "%s<cn> %s </cn>\n", $indentp, $expr->Arglist->[0];
|
| 1701 |
+
}
|
| 1702 |
+
elsif ( $type eq 'VAR' )
|
| 1703 |
+
{
|
| 1704 |
+
$string .= sprintf "%s<ci> %s </ci>\n", $indentp, $expr->Arglist->[0];
|
| 1705 |
+
}
|
| 1706 |
+
elsif ( $type eq 'FunctionCall' ) {
|
| 1707 |
+
my @arglist = @{ $expr->Arglist };
|
| 1708 |
+
my $func_name = shift(@arglist); # Get function name
|
| 1709 |
+
|
| 1710 |
+
# Built-in functions
|
| 1711 |
+
if (isBuiltIn($func_name)){
|
| 1712 |
+
|
| 1713 |
+
# Special handling for log2(x)
|
| 1714 |
+
if ($func_name eq 'log2'){
|
| 1715 |
+
$string .= $indentp . "<apply>\n";
|
| 1716 |
+
$string .= $indentp . " <log/><logbase><cn>2</cn></logbase>\n";
|
| 1717 |
+
$string .= $arglist[0]->toMathMLString( $plist, $indentp . " ", $level + 1 );
|
| 1718 |
+
$string .= $indentp . "</apply>\n";
|
| 1719 |
+
}
|
| 1720 |
+
# Special handling for rint(x)
|
| 1721 |
+
elsif ($func_name eq 'rint'){
|
| 1722 |
+
$string .= $indentp . "<apply>\n";
|
| 1723 |
+
$string .= $indentp . " <floor/>\n";
|
| 1724 |
+
$string .= $indentp . " <apply>\n";
|
| 1725 |
+
$string .= $indentp . " <plus/>\n";
|
| 1726 |
+
$string .= $indentp . " <cn> 0.5 </cn>\n";
|
| 1727 |
+
$string .= $arglist[0]->toMathMLString( $plist, $indentp . " ", $level + 1 );
|
| 1728 |
+
$string .= $indentp . " </apply>\n";
|
| 1729 |
+
$string .= $indentp . "</apply>\n";
|
| 1730 |
+
}
|
| 1731 |
+
# Special handling for if(x,y,z)
|
| 1732 |
+
elsif ($func_name eq 'if'){
|
| 1733 |
+
$string .= $indentp . "<piecewise>\n";
|
| 1734 |
+
$string .= $indentp . " <piece>\n";
|
| 1735 |
+
$string .= $arglist[1]->toMathMLString( $plist, $indentp . " ", $level + 1 );
|
| 1736 |
+
$string .= $arglist[0]->toMathMLString( $plist, $indentp . " ", $level + 1 );
|
| 1737 |
+
$string .= $indentp . " </piece>\n";
|
| 1738 |
+
$string .= $indentp . " <otherwise>\n";
|
| 1739 |
+
$string .= $arglist[2]->toMathMLString( $plist, $indentp . " ", $level + 1 );
|
| 1740 |
+
$string .= $indentp . " </otherwise>\n";
|
| 1741 |
+
$string .= $indentp . "</piecewise>\n";
|
| 1742 |
+
}
|
| 1743 |
+
# All other built-ins
|
| 1744 |
+
else{
|
| 1745 |
+
$string .= $indentp . "<apply>\n";
|
| 1746 |
+
my $indentpp = $indentp . " ";
|
| 1747 |
+
$string .= sprintf "%s<%s/>\n", $indentpp, $fnhash{ $func_name }; #shift(@arglist);
|
| 1748 |
+
foreach my $e (@arglist)
|
| 1749 |
+
{
|
| 1750 |
+
$string .= $e->toMathMLString( $plist, $indentpp, $level + 1 );
|
| 1751 |
+
}
|
| 1752 |
+
$string .= $indentp . "</apply>\n";
|
| 1753 |
+
}
|
| 1754 |
+
}
|
| 1755 |
+
# User-defined functions
|
| 1756 |
+
else{
|
| 1757 |
+
if (@arglist){ # There better not be any arguments
|
| 1758 |
+
die "Expression::toMathMLString: User-defined functions should not have arguments.";
|
| 1759 |
+
}
|
| 1760 |
+
$string .= sprintf "%s<ci> %s </ci>\n", $indentp, $func_name;
|
| 1761 |
+
}
|
| 1762 |
+
}
|
| 1763 |
+
else
|
| 1764 |
+
{
|
| 1765 |
+
$string .= $indentp . "<apply>\n";
|
| 1766 |
+
my $indentpp = $indentp . " ";
|
| 1767 |
+
$string .= sprintf "%s<%s/>\n", $indentpp, $ophash{ $expr->Type };
|
| 1768 |
+
foreach my $e ( @{ $expr->Arglist } )
|
| 1769 |
+
{
|
| 1770 |
+
$string .= $e->toMathMLString( $plist, $indentpp, $level + 1 );
|
| 1771 |
+
}
|
| 1772 |
+
$string .= $indentp . "</apply>\n";
|
| 1773 |
+
}
|
| 1774 |
+
|
| 1775 |
+
if ( $level == 0 )
|
| 1776 |
+
{
|
| 1777 |
+
$string .= $indent . "</math>\n";
|
| 1778 |
+
}
|
| 1779 |
+
return $string;
|
| 1780 |
+
}
|
| 1781 |
+
}
|
| 1782 |
+
|
| 1783 |
+
# Convert an array of type EXPR OP EXPR OP ... to a single Expression.
|
| 1784 |
+
sub arrayToExpression
|
| 1785 |
+
{
|
| 1786 |
+
my @earr = @_;
|
| 1787 |
+
|
| 1788 |
+
# list of optypes in order of precedence
|
| 1789 |
+
my @operators = ('\*\*|\^', '[*/]', '[+-]', '[<>]|==|!=|~=|>=|<=', '&&|\|\|');
|
| 1790 |
+
my $optype = shift @operators;
|
| 1791 |
+
while ($optype)
|
| 1792 |
+
{
|
| 1793 |
+
my $i = 0;
|
| 1794 |
+
# Consolidate EXPR OP EXPR into EXPR
|
| 1795 |
+
while ($i < $#earr)
|
| 1796 |
+
{
|
| 1797 |
+
my $expr = $earr[$i];
|
| 1798 |
+
if ( $expr->Type =~ /$optype/ and !@{$expr->Arglist} )
|
| 1799 |
+
{
|
| 1800 |
+
if ( $i > 0 )
|
| 1801 |
+
{
|
| 1802 |
+
$expr->Arglist->[0] = $earr[ $i - 1 ];
|
| 1803 |
+
$expr->Arglist->[1] = $earr[ $i + 1 ];
|
| 1804 |
+
splice @earr, $i - 1, 3, $expr;
|
| 1805 |
+
next;
|
| 1806 |
+
}
|
| 1807 |
+
else
|
| 1808 |
+
{
|
| 1809 |
+
# Handle leading unary op, as in -a + b
|
| 1810 |
+
$expr->Arglist->[0] = $earr[ $i + 1 ];
|
| 1811 |
+
splice @earr, $i, 2, $expr;
|
| 1812 |
+
++$i;
|
| 1813 |
+
next;
|
| 1814 |
+
}
|
| 1815 |
+
}
|
| 1816 |
+
++$i;
|
| 1817 |
+
}
|
| 1818 |
+
# Finished with current optype
|
| 1819 |
+
$optype = shift @operators;
|
| 1820 |
+
}
|
| 1821 |
+
|
| 1822 |
+
return $earr[0];
|
| 1823 |
+
}
|
| 1824 |
+
|
| 1825 |
+
|
| 1826 |
+
|
| 1827 |
+
# extract a number expression from a BNG string.
|
| 1828 |
+
# NOTE: the method newNumOrVar is appropriate when
|
| 1829 |
+
# the string ONLY contains a number or param name. This
|
| 1830 |
+
# method, however, is suitable for cases where the string
|
| 1831 |
+
# contains additional content.
|
| 1832 |
+
sub getNumber
|
| 1833 |
+
{
|
| 1834 |
+
my $string = shift;
|
| 1835 |
+
|
| 1836 |
+
my $number = '';
|
| 1837 |
+
# Decimal part
|
| 1838 |
+
if ( $$string =~ s/^([+-]?\d+)([.]?\d*)// )
|
| 1839 |
+
{
|
| 1840 |
+
$number = $1;
|
| 1841 |
+
if ($2 eq '.')
|
| 1842 |
+
{ # pad number ending in decimal point
|
| 1843 |
+
$number .= ".0";
|
| 1844 |
+
}
|
| 1845 |
+
else
|
| 1846 |
+
{
|
| 1847 |
+
$number .= $2;
|
| 1848 |
+
}
|
| 1849 |
+
}
|
| 1850 |
+
elsif ( $$string =~ s/^([+-]?[.]\d+)// )
|
| 1851 |
+
{
|
| 1852 |
+
$number = $1;
|
| 1853 |
+
}
|
| 1854 |
+
else
|
| 1855 |
+
{
|
| 1856 |
+
return '';
|
| 1857 |
+
}
|
| 1858 |
+
|
| 1859 |
+
# Exponent part
|
| 1860 |
+
if ( $$string =~ s/^([DEFGdefg][+-]?\d+)// )
|
| 1861 |
+
{
|
| 1862 |
+
$number .= $1;
|
| 1863 |
+
}
|
| 1864 |
+
elsif ( $$string =~ /^[A-Za-z_]/ )
|
| 1865 |
+
{
|
| 1866 |
+
# String is non a number; restore value of string
|
| 1867 |
+
$$string = $number . $$string;
|
| 1868 |
+
return '';
|
| 1869 |
+
}
|
| 1870 |
+
|
| 1871 |
+
# create number expression and return
|
| 1872 |
+
my $express = Expression->new();
|
| 1873 |
+
$express->Type('NUM');
|
| 1874 |
+
$express->Arglist( [$number] );
|
| 1875 |
+
return $express;
|
| 1876 |
+
}
|
| 1877 |
+
|
| 1878 |
+
|
| 1879 |
+
|
| 1880 |
+
# Returns name of VAR if expression is an existing VAR or
|
| 1881 |
+
# creates a new VAR with name derived from $basename and
|
| 1882 |
+
# returns name of new VAR containing expression.
|
| 1883 |
+
sub getName
|
| 1884 |
+
{
|
| 1885 |
+
my $expr = shift @_;
|
| 1886 |
+
my $plist = shift @_;
|
| 1887 |
+
my $basename = @_ ? shift @_ : "k";
|
| 1888 |
+
my $force_fcn = @_ ? shift @_ : 0;
|
| 1889 |
+
|
| 1890 |
+
my $name;
|
| 1891 |
+
if ( $expr->Type eq 'VAR' and !$force_fcn )
|
| 1892 |
+
{
|
| 1893 |
+
$name = $expr->Arglist->[0];
|
| 1894 |
+
}
|
| 1895 |
+
elsif ( $expr->Type eq "FunctionCall"
|
| 1896 |
+
and @{$expr->Arglist}==1
|
| 1897 |
+
and ref $expr->Arglist->[0] ne "Function" )
|
| 1898 |
+
{ # function call without arguments, no need to create a new parameter
|
| 1899 |
+
$name = $expr->Arglist->[0];
|
| 1900 |
+
}
|
| 1901 |
+
else
|
| 1902 |
+
{
|
| 1903 |
+
# Find unused name
|
| 1904 |
+
my $index = 1;
|
| 1905 |
+
while (1)
|
| 1906 |
+
{
|
| 1907 |
+
my ($param, $err) = $plist->lookup($basename . $index);
|
| 1908 |
+
last unless $param;
|
| 1909 |
+
++$index;
|
| 1910 |
+
}
|
| 1911 |
+
$name = $basename . $index;
|
| 1912 |
+
# set parameter in list (with type Function, if force)
|
| 1913 |
+
$plist->set( $name, $expr, 0, ($force_fcn ? 'Function' : '') );
|
| 1914 |
+
}
|
| 1915 |
+
|
| 1916 |
+
return $name;
|
| 1917 |
+
}
|
| 1918 |
+
|
| 1919 |
+
|
| 1920 |
+
|
| 1921 |
+
# Return a hash of all the variable names referenced in the current expression.
|
| 1922 |
+
sub getVariables
|
| 1923 |
+
{
|
| 1924 |
+
my $expr = shift @_;
|
| 1925 |
+
my $plist = shift @_;
|
| 1926 |
+
my $level = @_ ? shift @_ : 0;
|
| 1927 |
+
my $rethash = @_ ? shift @_ : {};
|
| 1928 |
+
|
| 1929 |
+
if ($level > $MAX_LEVEL) { die "Max recursion depth $MAX_LEVEL exceeded."; }
|
| 1930 |
+
|
| 1931 |
+
my $type = $expr->Type;
|
| 1932 |
+
if ( $type eq 'NUM' )
|
| 1933 |
+
{
|
| 1934 |
+
# nothing to do
|
| 1935 |
+
}
|
| 1936 |
+
elsif ( $type eq 'VAR' )
|
| 1937 |
+
{
|
| 1938 |
+
my ($param, $err) = $plist->lookup( $expr->Arglist->[0] );
|
| 1939 |
+
if ($err) { die $err }; # Shouldn't be an undefined variable name here
|
| 1940 |
+
if ( defined $param->Type )
|
| 1941 |
+
{ # add parameter name to type hash
|
| 1942 |
+
$rethash->{$param->Type}->{$param->Name} = $param;
|
| 1943 |
+
}
|
| 1944 |
+
else
|
| 1945 |
+
{ # this parameter has undefined type!
|
| 1946 |
+
$rethash->{'UNDEF'}->{$param->Name} = $param;
|
| 1947 |
+
}
|
| 1948 |
+
}
|
| 1949 |
+
elsif ( $type eq 'FunctionCall' )
|
| 1950 |
+
{
|
| 1951 |
+
if ( ref $expr->Arglist->[0] eq "Function" )
|
| 1952 |
+
{ # anonymous function
|
| 1953 |
+
# we have to descend into the function expression to see what it may reference
|
| 1954 |
+
$expr->Arglist->[0]->Expr->getVariables($plist, $level+1, $rethash);
|
| 1955 |
+
}
|
| 1956 |
+
elsif ( exists $functions{$expr->Arglist->[0]} )
|
| 1957 |
+
{ # built-in function..
|
| 1958 |
+
# nothing to do
|
| 1959 |
+
}
|
| 1960 |
+
else
|
| 1961 |
+
{ # named function
|
| 1962 |
+
my ($param, $err) = $plist->lookup( $expr->Arglist->[0] );
|
| 1963 |
+
# if (defined $param)
|
| 1964 |
+
if (defined $param && defined $param->Type)
|
| 1965 |
+
{ # add named function to rethash
|
| 1966 |
+
$rethash->{$param->Type}->{$param->Name} = $param;
|
| 1967 |
+
}
|
| 1968 |
+
}
|
| 1969 |
+
|
| 1970 |
+
# handle the function arguments
|
| 1971 |
+
foreach my $i ( 1 .. $#{$expr->Arglist} )
|
| 1972 |
+
{
|
| 1973 |
+
$expr->Arglist->[$i]->getVariables($plist, $level+1, $rethash);
|
| 1974 |
+
}
|
| 1975 |
+
}
|
| 1976 |
+
else
|
| 1977 |
+
{
|
| 1978 |
+
foreach my $e ( @{$expr->Arglist} )
|
| 1979 |
+
{
|
| 1980 |
+
$e->getVariables($plist, $level + 1, $rethash);
|
| 1981 |
+
}
|
| 1982 |
+
}
|
| 1983 |
+
|
| 1984 |
+
return $rethash;
|
| 1985 |
+
}
|
| 1986 |
+
|
| 1987 |
+
1;
|
data/bionetgen/Perl2/Function.pm
ADDED
|
@@ -0,0 +1,543 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package Function;
|
| 2 |
+
|
| 3 |
+
# pragmas
|
| 4 |
+
use strict;
|
| 5 |
+
use warnings;
|
| 6 |
+
|
| 7 |
+
# Perl Modules
|
| 8 |
+
use Class::Struct;
|
| 9 |
+
use FindBin;
|
| 10 |
+
use lib $FindBin::Bin;
|
| 11 |
+
|
| 12 |
+
# BNG Modules
|
| 13 |
+
use ParamList;
|
| 14 |
+
use Expression;
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
struct Function =>
|
| 19 |
+
{
|
| 20 |
+
Name => '$',
|
| 21 |
+
Args => '@',
|
| 22 |
+
Expr => 'Expression',
|
| 23 |
+
LocalHash => '%',
|
| 24 |
+
};
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
###
|
| 28 |
+
###
|
| 29 |
+
###
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
# create a copy of this function.
|
| 33 |
+
#
|
| 34 |
+
sub clone
|
| 35 |
+
{
|
| 36 |
+
my $fcn = shift @_;
|
| 37 |
+
my $plist = @_ ? shift @_ : undef;
|
| 38 |
+
my $level = @_ ? shift @_ : 0;
|
| 39 |
+
my $named = @_ ? shift @_ : 0;
|
| 40 |
+
|
| 41 |
+
# if the clone doesn't have a name, it will be anonymous
|
| 42 |
+
my $clone_name = $named ? $fcn->Name : undef;
|
| 43 |
+
|
| 44 |
+
my $err = '';
|
| 45 |
+
(my $clone_expr, $err) = $fcn->Expr->clone( $plist, $level+1 );
|
| 46 |
+
|
| 47 |
+
my $clone = Function->new( Name=>$clone_name, Expr=>$clone_expr, Args=>[@{$fcn->Args}] );
|
| 48 |
+
return $clone, $err;
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
###
|
| 53 |
+
###
|
| 54 |
+
###
|
| 55 |
+
|
| 56 |
+
sub evaluate
|
| 57 |
+
{
|
| 58 |
+
my $fcn = shift @_;
|
| 59 |
+
my $args = @_ ? shift @_ : [];
|
| 60 |
+
my $plist = @_ ? shift @_ : undef;
|
| 61 |
+
my $level = @_ ? shift @_ : 0;
|
| 62 |
+
|
| 63 |
+
# create local parameterList
|
| 64 |
+
my $local_plist = $plist->getChildList();
|
| 65 |
+
|
| 66 |
+
# set local variables equal to the arguments
|
| 67 |
+
my $ii=1; # first arg is function name
|
| 68 |
+
while ( $ii < @$args )
|
| 69 |
+
{
|
| 70 |
+
$local_plist->set( $fcn->Args->[$ii-1], $args->[$ii], 1, $args->[$ii]->Type );
|
| 71 |
+
++$ii;
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
# evaluate function expression
|
| 75 |
+
return $fcn->Expr->evaluate($local_plist, $level+1);
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
###
|
| 80 |
+
###
|
| 81 |
+
###
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
# return a cloned function with local elements evaluated
|
| 86 |
+
sub evaluate_local
|
| 87 |
+
{
|
| 88 |
+
my $fcn = shift;
|
| 89 |
+
my $args = (@_) ? shift : [];
|
| 90 |
+
my $plist = (@_) ? shift : undef;
|
| 91 |
+
my $level = (@_) ? shift : 0;
|
| 92 |
+
|
| 93 |
+
my ($local_fcn, $err) = $fcn->clone( $plist, $level+1 );
|
| 94 |
+
|
| 95 |
+
# create local parameterList
|
| 96 |
+
my $local_plist = $plist->getChildList();
|
| 97 |
+
# set local variables equal to the arguments
|
| 98 |
+
my $ii=1; # first arg is function name
|
| 99 |
+
while ( $ii < @$args )
|
| 100 |
+
{
|
| 101 |
+
$local_plist->set( $fcn->Args->[$ii-1], $args->[$ii], 1 );
|
| 102 |
+
++$ii;
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
# locally evaluate function expression
|
| 106 |
+
my $expr = $local_fcn->Expr->evaluate_local($local_plist, $level+1);
|
| 107 |
+
$local_fcn->Expr($expr);
|
| 108 |
+
|
| 109 |
+
# check if local variables are unused
|
| 110 |
+
my $bad_args = [];
|
| 111 |
+
$ii=0;
|
| 112 |
+
while ( $ii < @{$local_fcn->Args} )
|
| 113 |
+
{
|
| 114 |
+
my ($dep, $err) = $expr->depends( $plist, $fcn->Args->[$ii] );
|
| 115 |
+
if ($dep)
|
| 116 |
+
{
|
| 117 |
+
# do nothing
|
| 118 |
+
++$ii;
|
| 119 |
+
}
|
| 120 |
+
else
|
| 121 |
+
{
|
| 122 |
+
# remove argument
|
| 123 |
+
splice @{$local_fcn->Args}, $ii, 1;
|
| 124 |
+
push @$bad_args, $ii+1;
|
| 125 |
+
}
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
return $local_fcn, $bad_args;
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
###
|
| 133 |
+
###
|
| 134 |
+
###
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
# check for local observable dependency, return true if found
|
| 138 |
+
sub checkLocalDependency
|
| 139 |
+
{
|
| 140 |
+
my $fcn = shift;
|
| 141 |
+
my $plist = (@_) ? shift : undef;
|
| 142 |
+
my $level = (@_) ? shift : 0;
|
| 143 |
+
|
| 144 |
+
return $fcn->Expr->checkLocalDependency( $plist, $level+1 );
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
###
|
| 149 |
+
###
|
| 150 |
+
###
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
# check function equivalence
|
| 154 |
+
sub equivalent
|
| 155 |
+
{
|
| 156 |
+
my $fcn1 = shift;
|
| 157 |
+
my $fcn2 = shift;
|
| 158 |
+
my $plist = (@_) ? shift : undef;
|
| 159 |
+
|
| 160 |
+
# make sure we have defined expressions!
|
| 161 |
+
return 0 unless ( defined $fcn1 and ref $fcn1 eq 'Function' );
|
| 162 |
+
return 0 unless ( defined $fcn2 and ref $fcn2 eq 'Function' );
|
| 163 |
+
|
| 164 |
+
# check if this is the same function object!
|
| 165 |
+
return 0 if ( $fcn1 == $fcn2 );
|
| 166 |
+
|
| 167 |
+
# don't compare names!!!
|
| 168 |
+
|
| 169 |
+
# check for same number of arguments
|
| 170 |
+
return 0 unless ( @{$fcn1->Args} == @{$fcn2->Args} );
|
| 171 |
+
|
| 172 |
+
# compare arguments
|
| 173 |
+
for ( my $i = 0; $i < @{$fcn1->Args}; ++$i )
|
| 174 |
+
{
|
| 175 |
+
return 0 unless ( $fcn1->Args->[$i] eq $fcn2->Args->[$i] );
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
# check Expr equivalence
|
| 179 |
+
return 0 unless ( Expression::equivalent($fcn1->Expr, $fcn2->Expr, $plist) );
|
| 180 |
+
|
| 181 |
+
# no differences found, return true!
|
| 182 |
+
return 1;
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
|
| 186 |
+
###
|
| 187 |
+
###
|
| 188 |
+
###
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
sub readString
|
| 192 |
+
{
|
| 193 |
+
my $fun = shift;
|
| 194 |
+
my $string = shift;
|
| 195 |
+
my $model = shift;
|
| 196 |
+
my $err = '';
|
| 197 |
+
|
| 198 |
+
my $plist = $model->ParamList;
|
| 199 |
+
|
| 200 |
+
# Remove leading whitespace
|
| 201 |
+
$string =~ s/^\s*//;
|
| 202 |
+
|
| 203 |
+
# Check if first token is an index
|
| 204 |
+
$string =~ s/^\s*\d+\s+//; # Can't deprecate this because indices used in NET files
|
| 205 |
+
|
| 206 |
+
# Remove leading label, if exists
|
| 207 |
+
if ( $string =~ s/^\s*(\w+)\s*:\s+// )
|
| 208 |
+
{
|
| 209 |
+
# Check label for leading number
|
| 210 |
+
my $label = $1;
|
| 211 |
+
if ($label =~ /^\d/) { return "Syntax error (label begins with a number) at '$label'"; }
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
# Check name for leading number
|
| 215 |
+
my $string_left = $string;
|
| 216 |
+
unless ( $string_left =~ s/^([A-Za-z_]\w*)// )
|
| 217 |
+
{
|
| 218 |
+
return "Syntax error (function name begins with a number) at '$string'";
|
| 219 |
+
}
|
| 220 |
+
|
| 221 |
+
# Next token is function Name
|
| 222 |
+
if ( $string =~ s/^\s*([A-Za-z0-9_]+)\s*// )
|
| 223 |
+
{
|
| 224 |
+
my $name = $1;
|
| 225 |
+
$fun->Name($name);
|
| 226 |
+
|
| 227 |
+
# Make sure function name not the same as built-in functions --Leonard
|
| 228 |
+
if ( Expression::isBuiltIn($name) ){
|
| 229 |
+
return "Cannot use built-in function name '$name' as a user-defined function name.";
|
| 230 |
+
}
|
| 231 |
+
}
|
| 232 |
+
else
|
| 233 |
+
{
|
| 234 |
+
my ($name) = split( ' ', $string );
|
| 235 |
+
return ("Invalid function name '$name': may contain only alphanumeric characters and underscore");
|
| 236 |
+
}
|
| 237 |
+
|
| 238 |
+
# Process arguments to function (if any)
|
| 239 |
+
my @Args = ();
|
| 240 |
+
if ( $string =~ s/^[(]\s*// )
|
| 241 |
+
{
|
| 242 |
+
while (1)
|
| 243 |
+
{
|
| 244 |
+
if ( $string =~ s/^\s*([A-Za-z0-9_]+)\s*// )
|
| 245 |
+
{
|
| 246 |
+
my $arg = $1;
|
| 247 |
+
# Define argument as an allowed local variable in $plist
|
| 248 |
+
if ( $plist->set( $arg, '0', 1, 'Local' ) )
|
| 249 |
+
{
|
| 250 |
+
my $name = $fun->Name;
|
| 251 |
+
return ("Local argument $arg to Function $name matches previously defined variable");
|
| 252 |
+
}
|
| 253 |
+
#printf "Added argument %s to function %s\n", $arg, $fun->Name;
|
| 254 |
+
push @Args, $arg;
|
| 255 |
+
}
|
| 256 |
+
elsif ( $string =~ s/^[,]\s*// )
|
| 257 |
+
{
|
| 258 |
+
next;
|
| 259 |
+
}
|
| 260 |
+
elsif ( $string =~ s/^[)]\s*// )
|
| 261 |
+
{
|
| 262 |
+
last;
|
| 263 |
+
}
|
| 264 |
+
else
|
| 265 |
+
{
|
| 266 |
+
my $name= $fun->Name;
|
| 267 |
+
return ("Unrecognized argument at $string in declaration of function $name.");
|
| 268 |
+
}
|
| 269 |
+
}
|
| 270 |
+
$fun->Args( [@Args] );
|
| 271 |
+
}
|
| 272 |
+
|
| 273 |
+
# Remove '=' if present (but NOT '==')
|
| 274 |
+
$string=~ s/(?<!=)[=](?!=)\s*//;# use lookarounds to avoid matching '=='
|
| 275 |
+
|
| 276 |
+
# Read expression defining function. Function arguments are "local" variables
|
| 277 |
+
my $expr = Expression->new();
|
| 278 |
+
$expr->setAllowForward(1); # don't complain if expression refers to undefined parameters
|
| 279 |
+
if ( my $err = $expr->readString( \$string, $plist ) ) { return ($err); }
|
| 280 |
+
if ($string) { return ("Syntax error at $string"); }
|
| 281 |
+
$expr->setAllowForward(0);
|
| 282 |
+
|
| 283 |
+
$fun->Expr($expr);
|
| 284 |
+
|
| 285 |
+
# Define parameter with name of the Function
|
| 286 |
+
if ( $plist->set( $fun->Name, $expr, 1, "Function", $fun ) )
|
| 287 |
+
{
|
| 288 |
+
my $name = $fun->Name;
|
| 289 |
+
return ("Function name $name matches previously defined variable");
|
| 290 |
+
}
|
| 291 |
+
|
| 292 |
+
$fun->unsetArgs($plist);
|
| 293 |
+
|
| 294 |
+
return '';
|
| 295 |
+
}
|
| 296 |
+
|
| 297 |
+
|
| 298 |
+
###
|
| 299 |
+
###
|
| 300 |
+
###
|
| 301 |
+
|
| 302 |
+
|
| 303 |
+
sub toString
|
| 304 |
+
{
|
| 305 |
+
my $fun = shift @_;
|
| 306 |
+
my $plist = @_ ? shift @_ : undef;
|
| 307 |
+
my $include_equal = (@_) ? shift : 0;
|
| 308 |
+
# used for aligning columns nicely
|
| 309 |
+
my $max_length = (@_) ? shift : 0;
|
| 310 |
+
|
| 311 |
+
my $name = defined $fun->Name ? $fun->Name : "anon";
|
| 312 |
+
my $string = $name . '(' . join(',', @{$fun->Args}) . ')';
|
| 313 |
+
if ( $fun->Expr )
|
| 314 |
+
{
|
| 315 |
+
$string .= ($include_equal) ? ' = ' : ' ';
|
| 316 |
+
$string .= $fun->Expr->toString($plist);
|
| 317 |
+
}
|
| 318 |
+
|
| 319 |
+
if ($include_equal and $max_length)
|
| 320 |
+
{ # align equal signs
|
| 321 |
+
$string =~ /=/g;
|
| 322 |
+
my $n_spaces = $max_length - pos $string;
|
| 323 |
+
if ($n_spaces > 0)
|
| 324 |
+
{
|
| 325 |
+
my $spaces = ' ' x $n_spaces;
|
| 326 |
+
$string =~ s/=/$spaces=/;
|
| 327 |
+
}
|
| 328 |
+
}
|
| 329 |
+
|
| 330 |
+
return $string;
|
| 331 |
+
}
|
| 332 |
+
|
| 333 |
+
|
| 334 |
+
###
|
| 335 |
+
###
|
| 336 |
+
###
|
| 337 |
+
|
| 338 |
+
|
| 339 |
+
sub toCVodeString
|
| 340 |
+
# construct a call, declaration or definition for this function in CVode.
|
| 341 |
+
{
|
| 342 |
+
my $fcn = shift; # this function
|
| 343 |
+
my $plist = (@_) ? shift : undef; # reference to ParamList
|
| 344 |
+
my $arghash = (@_) ? shift : {}; # reference to argument hash
|
| 345 |
+
|
| 346 |
+
# set default mode
|
| 347 |
+
unless ( exists $arghash->{fcn_mode} )
|
| 348 |
+
{ $arghash->{fcn_mode} = 'call'; }
|
| 349 |
+
|
| 350 |
+
# set default indent
|
| 351 |
+
unless ( exists $arghash->{indent} )
|
| 352 |
+
{ $arghash->{indent} = ''; }
|
| 353 |
+
|
| 354 |
+
my $string = '';
|
| 355 |
+
if ( $arghash->{fcn_mode} eq 'call' )
|
| 356 |
+
{
|
| 357 |
+
# generate the function call
|
| 358 |
+
my @args = ( @{$fcn->Args}, 'expressions', 'observables' );
|
| 359 |
+
$string = $arghash->{indent} . $fcn->Name . '(' . join(',', @args) . ')';
|
| 360 |
+
}
|
| 361 |
+
elsif ( $arghash->{fcn_mode} eq 'declare' )
|
| 362 |
+
{
|
| 363 |
+
# generate a declaration string
|
| 364 |
+
my @args = ( (map { "double $_" } @{$fcn->Args}), 'N_Vector expressions', 'N_Vector observables' );
|
| 365 |
+
$string = $arghash->{indent} . "double " . $fcn->Name . " ( " . join(', ', @args) . " );\n";
|
| 366 |
+
}
|
| 367 |
+
elsif ( $arghash->{fcn_mode} eq 'define' )
|
| 368 |
+
{
|
| 369 |
+
# generate a definition string
|
| 370 |
+
my @args = ( (map { "double $_" } @{$fcn->Args}), 'N_Vector expressions', 'N_Vector observables' );
|
| 371 |
+
|
| 372 |
+
$string .= $arghash->{indent} . "/* user-defined function " . $fcn->Name . " */\n";
|
| 373 |
+
$string .= $arghash->{indent} . "double " . $fcn->Name . " ( " . join(', ', @args) . " )\n";
|
| 374 |
+
$string .= $arghash->{indent} . "{\n";
|
| 375 |
+
$string .= $arghash->{indent} . " return " . $fcn->Expr->toCVodeString($plist) . ";\n";
|
| 376 |
+
$string .= $arghash->{indent} . "}\n";
|
| 377 |
+
}
|
| 378 |
+
else
|
| 379 |
+
{ die "Error in Function->toCVodeString(): did not recognize fcn_mode argument!"; }
|
| 380 |
+
|
| 381 |
+
return $string;
|
| 382 |
+
}
|
| 383 |
+
|
| 384 |
+
|
| 385 |
+
|
| 386 |
+
###
|
| 387 |
+
###
|
| 388 |
+
###
|
| 389 |
+
|
| 390 |
+
|
| 391 |
+
|
| 392 |
+
sub toMatlabString
|
| 393 |
+
# construct a call, declaration or definition for this function in CVode.
|
| 394 |
+
{
|
| 395 |
+
my $fcn = shift @_; # this function
|
| 396 |
+
my $plist = @_ ? shift @_ : undef; # reference to ParamList
|
| 397 |
+
my $arghash = @_ ? shift @_ : {}; # reference to argument hash
|
| 398 |
+
|
| 399 |
+
# set default mode
|
| 400 |
+
unless ( exists $arghash->{fcn_mode} )
|
| 401 |
+
{ $arghash->{fcn_mode} = 'call'; }
|
| 402 |
+
|
| 403 |
+
# set default indent
|
| 404 |
+
unless ( exists $arghash->{indent} )
|
| 405 |
+
{ $arghash->{indent} = ''; }
|
| 406 |
+
|
| 407 |
+
my $string = '';
|
| 408 |
+
if ( $arghash->{fcn_mode} eq 'call' )
|
| 409 |
+
{
|
| 410 |
+
# generate the function call
|
| 411 |
+
my @args = ( @{$fcn->Args}, 'expressions', 'observables' );
|
| 412 |
+
$string = $arghash->{indent} . $fcn->Name . '(' . join(',', @args) . ')';
|
| 413 |
+
}
|
| 414 |
+
elsif ( $arghash->{fcn_mode} eq 'declare' )
|
| 415 |
+
{
|
| 416 |
+
# generate a declaration string
|
| 417 |
+
# NOTHING TO DO: Matlab does not require function declarations
|
| 418 |
+
$string = '';
|
| 419 |
+
}
|
| 420 |
+
elsif ( $arghash->{fcn_mode} eq 'define' )
|
| 421 |
+
{
|
| 422 |
+
# generate a definition string
|
| 423 |
+
my @args = ( @{$fcn->Args}, 'expressions', 'observables' );
|
| 424 |
+
$string .= $arghash->{indent} . '% function ' . $fcn->Name . "\n";
|
| 425 |
+
$string .= $arghash->{indent} . 'function [val] = ' . $fcn->Name . '(' . join(', ', @args) . ")\n"
|
| 426 |
+
. ' val = ' . $fcn->Expr->toMatlabString($plist) . ";\n"
|
| 427 |
+
. "end\n";
|
| 428 |
+
}
|
| 429 |
+
else
|
| 430 |
+
{ die "Error in Function->toMatlabString(): did not recognize fcn_mode argument!"; }
|
| 431 |
+
|
| 432 |
+
return $string;
|
| 433 |
+
}
|
| 434 |
+
|
| 435 |
+
|
| 436 |
+
|
| 437 |
+
###
|
| 438 |
+
###
|
| 439 |
+
###
|
| 440 |
+
|
| 441 |
+
|
| 442 |
+
|
| 443 |
+
sub setArgs
|
| 444 |
+
{
|
| 445 |
+
my $fun= shift;
|
| 446 |
+
my $plist= shift;
|
| 447 |
+
|
| 448 |
+
foreach my $arg ( @{$fun->Args} )
|
| 449 |
+
{
|
| 450 |
+
$plist->set( $arg, '0', 1, 'Local' );
|
| 451 |
+
}
|
| 452 |
+
return '';
|
| 453 |
+
}
|
| 454 |
+
|
| 455 |
+
|
| 456 |
+
|
| 457 |
+
###
|
| 458 |
+
###
|
| 459 |
+
###
|
| 460 |
+
|
| 461 |
+
|
| 462 |
+
|
| 463 |
+
sub unsetArgs
|
| 464 |
+
{
|
| 465 |
+
my $fun = shift;
|
| 466 |
+
my $plist = shift;
|
| 467 |
+
|
| 468 |
+
# Delete ParamList entries for Local arguments
|
| 469 |
+
foreach my $arg ( @{$fun->Args} )
|
| 470 |
+
{
|
| 471 |
+
$plist->deleteLocal($arg);
|
| 472 |
+
}
|
| 473 |
+
return '';
|
| 474 |
+
}
|
| 475 |
+
|
| 476 |
+
|
| 477 |
+
|
| 478 |
+
###
|
| 479 |
+
###
|
| 480 |
+
###
|
| 481 |
+
|
| 482 |
+
|
| 483 |
+
|
| 484 |
+
sub toXML
|
| 485 |
+
{
|
| 486 |
+
my $fun = shift;
|
| 487 |
+
my $plist = (@_) ? shift : '';
|
| 488 |
+
my $indent = (@_) ? shift : '';
|
| 489 |
+
|
| 490 |
+
$fun->setArgs($plist);
|
| 491 |
+
|
| 492 |
+
my $indent2 = ' ' . $indent;
|
| 493 |
+
my $indent3 = ' ' . $indent2;
|
| 494 |
+
my $string = $indent . "<Function";
|
| 495 |
+
|
| 496 |
+
# Attributes
|
| 497 |
+
# id
|
| 498 |
+
$string .= " id=\"".$fun->Name."\"";
|
| 499 |
+
$string .= ">\n";
|
| 500 |
+
|
| 501 |
+
# Arguments
|
| 502 |
+
if ( @{$fun->Args} )
|
| 503 |
+
{
|
| 504 |
+
$string.= $indent2 . "<ListOfArguments>\n";
|
| 505 |
+
foreach my $arg (@{$fun->Args})
|
| 506 |
+
{
|
| 507 |
+
$string .= $indent3 . "<Argument";
|
| 508 |
+
$string .= " id=" . "\"" . $arg . "\"";
|
| 509 |
+
$string .= "/>\n"
|
| 510 |
+
}
|
| 511 |
+
$string .= $indent2 . "</ListOfArguments>\n";
|
| 512 |
+
}
|
| 513 |
+
|
| 514 |
+
# References
|
| 515 |
+
$string.= $indent2."<ListOfReferences>\n";
|
| 516 |
+
my $vhash= $fun->Expr->getVariables($plist);
|
| 517 |
+
|
| 518 |
+
foreach my $type (sort keys %{$vhash})
|
| 519 |
+
{
|
| 520 |
+
foreach my $var (sort keys %{$vhash->{$type}})
|
| 521 |
+
{
|
| 522 |
+
#print "$type $var\n";
|
| 523 |
+
$string .= $indent3 . ($vhash->{$type}->{$var})->toXMLReference('Reference', '', $plist);
|
| 524 |
+
}
|
| 525 |
+
}
|
| 526 |
+
$string .= $indent2 . "</ListOfReferences>\n";
|
| 527 |
+
|
| 528 |
+
$string .= $indent2 . "<Expression> ";
|
| 529 |
+
$string .= $fun->Expr->toXML($plist);
|
| 530 |
+
$string .= " </Expression>\n";
|
| 531 |
+
|
| 532 |
+
$string .= $indent."</Function>\n";
|
| 533 |
+
|
| 534 |
+
$fun->unsetArgs($plist);
|
| 535 |
+
|
| 536 |
+
return ($string);
|
| 537 |
+
}
|
| 538 |
+
|
| 539 |
+
|
| 540 |
+
|
| 541 |
+
|
| 542 |
+
|
| 543 |
+
1;
|