From 67b2eefc3390aa6fb1deaccd7f6a3fd50cdd4de6 Mon Sep 17 00:00:00 2001 From: Sarah Keating Date: Sun, 8 Dec 2024 14:47:16 +0000 Subject: [PATCH] adding these for now but not quite finished --- src/sbml/conversion/ExpressionAnalyser.cpp | 911 ++++++++++++++---- src/sbml/conversion/ExpressionAnalyser.h | 78 +- src/sbml/conversion/SBMLRateRuleConverter.cpp | 57 +- src/sbml/conversion/SBMLRateRuleConverter.h | 6 +- .../test/TestExpressionAnalyser.cpp | 555 +++++++++++ .../test/TestSBMLRateRuleConverter.cpp | 68 +- .../conversion/test/test-data/mraterules5.xml | 7 +- .../conversion/test/test-data/mraterules7.xml | 36 + src/sbml/conversion/test/test-data/test | 122 +++ .../conversion/test/test-data/valid_54_bio.c | 103 ++ .../conversion/test/test-data/valid_54_rr.c | 79 ++ 11 files changed, 1785 insertions(+), 237 deletions(-) create mode 100644 src/sbml/conversion/test/TestExpressionAnalyser.cpp create mode 100644 src/sbml/conversion/test/test-data/mraterules7.xml create mode 100644 src/sbml/conversion/test/test-data/test create mode 100644 src/sbml/conversion/test/test-data/valid_54_bio.c create mode 100644 src/sbml/conversion/test/test-data/valid_54_rr.c diff --git a/src/sbml/conversion/ExpressionAnalyser.cpp b/src/sbml/conversion/ExpressionAnalyser.cpp index b548e67835..a8a4541476 100644 --- a/src/sbml/conversion/ExpressionAnalyser.cpp +++ b/src/sbml/conversion/ExpressionAnalyser.cpp @@ -6,7 +6,7 @@ * * */ + +#include + +#include +#include + +#include +#include +#include +#include + +#include + +#include +#include +#include + +using namespace std; +LIBSBML_CPP_NAMESPACE_USE + +CK_CPPSTART + +static Model* m; +static SBMLDocument* d; +static ConversionProperties props; +static SBMLRateRuleConverter* converter; + + +static bool +equals(const char* expected, const char* actual) +{ + if (!strcmp(expected, actual)) return true; + + printf("\nStrings are not equal:\n"); + printf("Expected:\n[%s]\n", expected); + printf("Actual:\n[%s]\n", actual); + + return false; +} + +static bool +formulas_equal(const char* expected, ASTNode* actual) +{ + return equals(expected, SBML_formulaToL3String(actual)); +} + +extern char *TestDataDirectory; + +static Parameter* setupZeroParameter(Model* model, const char* name, bool is_constant) +{ + Parameter* parameter = model->createParameter(); + parameter->setId(name); + parameter->setConstant(is_constant); + parameter->setValue(0); + return parameter; +} + +Species* setupSpecies(Model* model, const char* name, const char* compartment) { + Species* species = model->createSpecies(); + species->setId(name); + species->setCompartment(compartment); + species->setInitialAmount(0); + species->setConstant(false); + return species; +} + +Model* setupModel(SBMLDocument* doc) { + Model* model = doc->createModel(); + model->setId("m"); + + // create compartment + Compartment* compartment = model->createCompartment(); + compartment->setId("c"); + compartment->setSpatialDimensions(3.0); + compartment->setSize(1); + compartment->setConstant(true); + + // create species + setupSpecies(model, "x", "c"); + setupSpecies(model, "y", "c"); + setupSpecies(model, "a", "c"); + setupSpecies(model, "b", "c"); + + // create parameters + setupZeroParameter(model, "k", true); + setupZeroParameter(model, "v", false); + setupZeroParameter(model, "w", false); + + + return model; +} + + +void +ExpressionAnalyser_setup(void) +{ + props.addOption("inferReactions", true); + + converter = new SBMLRateRuleConverter(); + converter->setProperties(&props); + + d = new SBMLDocument(); + m = setupModel(d); + converter->setDocument(d); +} + +void +ExpressionAnalyser_teardown(void) +{ + delete converter; + delete d; +} + +extern char *TestDataDirectory; +START_TEST(test_analyse) +{ + RateRule* rr = d->getModel()->createRateRule(); + rr->setVariable("a"); + rr->setMath(SBML_parseFormula("k-x-y")); + converter->populateInitialODEinfo(); + ExpressionAnalyser* analyser = new ExpressionAnalyser(m, converter->getOdePairs()); + + fail_unless(analyser->getNumExpressions() == 0); + + analyser->analyse(); + + fail_unless(analyser->getNumExpressions() == 1); + SubstitutionValues_t *value = analyser->getExpression(0); + fail_unless(value->k_value == "k"); + fail_unless(value->x_value == "x"); + fail_unless(value->y_value == "y"); + fail_unless(value->z_value.empty()); + fail_unless(value->type == TYPE_K_MINUS_X_MINUS_Y); + fail_unless(formulas_equal("k - x - y", value->current)); + fail_unless(formulas_equal( "0", value->dxdt_expression)); + fail_unless(formulas_equal( "0", value->dydt_expression)); + fail_unless(value->v_expression == NULL); + fail_unless(value->w_expression == NULL); + fail_unless(value->z_expression == NULL); + fail_unless(value->odeIndex == 0); + fail_unless(util_isNaN(value->k_real_value)); +} +END_TEST + +START_TEST(test_analyse_1) +{ + RateRule* rr = d->getModel()->createRateRule(); + rr->setVariable("a"); + rr->setMath(SBML_parseFormula("k + v - x - y")); + converter->populateInitialODEinfo(); + ExpressionAnalyser* analyser = new ExpressionAnalyser(m, converter->getOdePairs()); + + fail_unless(analyser->getNumExpressions() == 0); + + analyser->analyse(); + + fail_unless(analyser->getNumExpressions() == 1); + SubstitutionValues_t* value = analyser->getExpression(0); + fail_unless(value->k_value == "k"); + fail_unless(value->x_value == "x"); + fail_unless(value->y_value == "y"); + fail_unless(value->z_value.empty()); + fail_unless(value->type == TYPE_K_PLUS_V_MINUS_X_MINUS_Y); + fail_unless(formulas_equal("k + v - x - y", value->current)); + fail_unless(formulas_equal("0", value->dxdt_expression)); + fail_unless(formulas_equal("0", value->dydt_expression)); + fail_unless(formulas_equal("v", value->v_expression)); + fail_unless(value->w_expression == NULL); + fail_unless(value->z_expression == NULL); + fail_unless(value->odeIndex == 0); + fail_unless(util_isNaN(value->k_real_value)); +} +END_TEST +START_TEST(test_analyse_2) +{ + RateRule* rr = d->getModel()->createRateRule(); + rr->setVariable("a"); + rr->setMath(SBML_parseFormula("k - x + w - y")); + converter->populateInitialODEinfo(); + ExpressionAnalyser* analyser = new ExpressionAnalyser(m, converter->getOdePairs()); + + fail_unless(analyser->getNumExpressions() == 0); + + analyser->analyse(); + + fail_unless(analyser->getNumExpressions() == 1); + SubstitutionValues_t* value = analyser->getExpression(0); + fail_unless(value->k_value == "k"); + fail_unless(value->x_value == "x"); + fail_unless(value->y_value == "y"); + fail_unless(value->z_value.empty()); + fail_unless(value->type == TYPE_K_MINUS_X_PLUS_W_MINUS_Y); + fail_unless(formulas_equal("w + (k - x) - y", value->current)); + fail_unless(formulas_equal("0", value->dxdt_expression)); + fail_unless(formulas_equal("0", value->dydt_expression)); + fail_unless(formulas_equal("w", value->w_expression)); + fail_unless(value->v_expression == NULL); + fail_unless(value->z_expression == NULL); + fail_unless(value->odeIndex == 0); + fail_unless(util_isNaN(value->k_real_value)); +} +END_TEST + +START_TEST(test_analyse_3) +{ + RateRule* rr = d->getModel()->createRateRule(); + rr->setVariable("a"); + rr->setMath(SBML_parseFormula("k - x")); + converter->populateInitialODEinfo(); + ExpressionAnalyser* analyser = new ExpressionAnalyser(m, converter->getOdePairs()); + + fail_unless(analyser->getNumExpressions() == 0); + + analyser->analyse(); + + fail_unless(analyser->getNumExpressions() == 1); + SubstitutionValues_t* value = analyser->getExpression(0); + fail_unless(value->k_value == "k"); + fail_unless(value->x_value == "x"); + fail_unless(value->y_value.empty()); + fail_unless(value->z_value.empty()); + fail_unless(value->type == TYPE_K_MINUS_X); + fail_unless(formulas_equal("k - x", value->current)); + fail_unless(formulas_equal("0", value->dxdt_expression)); + fail_unless(value->dydt_expression == NULL); + fail_unless(value->v_expression == NULL); + fail_unless(value->w_expression == NULL); + fail_unless(value->z_expression == NULL); + fail_unless(value->odeIndex == 0); + fail_unless(util_isNaN(value->k_real_value)); +} +END_TEST + +START_TEST(test_analyse_4) +{ + RateRule* rr = d->getModel()->createRateRule(); + rr->setVariable("a"); + rr->setMath(SBML_parseFormula("k + v - x")); + converter->populateInitialODEinfo(); + ExpressionAnalyser* analyser = new ExpressionAnalyser(m, converter->getOdePairs()); + + fail_unless(analyser->getNumExpressions() == 0); + + analyser->analyse(); + + fail_unless(analyser->getNumExpressions() == 1); + SubstitutionValues_t* value = analyser->getExpression(0); + fail_unless(value->k_value == "k"); + fail_unless(value->x_value == "x"); + fail_unless(value->y_value.empty()); + fail_unless(value->z_value.empty()); + fail_unless(value->type == TYPE_K_PLUS_V_MINUS_X); + fail_unless(formulas_equal("k + v - x", value->current)); + fail_unless(formulas_equal("0", value->dxdt_expression)); + fail_unless(value->dydt_expression == NULL); + fail_unless(formulas_equal("v", value->v_expression)); + fail_unless(value->w_expression == NULL); + fail_unless(value->z_expression == NULL); + fail_unless(value->odeIndex == 0); + fail_unless(util_isNaN(value->k_real_value)); +} +END_TEST + +START_TEST(test_reorder_minusXplusYIteratively_simple) +{ + RateRule* rr = d->getModel()->createRateRule(); + rr->setVariable("a"); + rr->setMath(SBML_parseFormula("-x + y")); + converter->populateInitialODEinfo(); + ExpressionAnalyser* analyser = new ExpressionAnalyser(m, converter->getOdePairs()); + + fail_unless(analyser->getNumExpressions() == 0); + + analyser->detect_minusXPlusYOnly(); + + fail_unless(analyser->getNumExpressions() == 1); + + analyser->reorderMinusXPlusYIteratively(); + SubstitutionValues_t* value = analyser->getExpression(0); + fail_unless(value->k_value.empty()); + fail_unless(value->x_value == "x"); + fail_unless(value->y_value == "y"); + fail_unless(value->z_value.empty()); + fail_unless(value->type == TYPE_MINUS_X_PLUS_Y); + fail_unless(formulas_equal("-x + y", value->current)); + fail_unless(formulas_equal("0", value->dxdt_expression)); + fail_unless(formulas_equal("0", value->dydt_expression)); + fail_unless(value->v_expression == NULL); + fail_unless(value->w_expression == NULL); + fail_unless(value->z_expression == NULL); + fail_unless(value->odeIndex == 0); + fail_unless(util_isNaN(value->k_real_value)); +} +END_TEST + + + +START_TEST(test_order_of_replacements) +{ + ConversionProperties props; + props.addOption("inferReactions", true); + + SBMLRateRuleConverter* converter = new SBMLRateRuleConverter(); + converter->setProperties(&props); + + std::string filename(TestDataDirectory); + filename += "mraterules7.xml"; + + + SBMLDocument* d = readSBMLFromFile(filename.c_str()); + Model* model = d->getModel(); + fail_unless(model != NULL); + fail_unless(model->getNumParameters() == 2); + + converter->setDocument(d); + converter->populateInitialODEinfo(); + converter->populateODEinfo(); + fail_unless(model->getNumParameters() == 3); + + delete converter; + delete d; +} +END_TEST + +START_TEST(test_order_of_replacements1) +{ + ConversionProperties props; + props.addOption("inferReactions", true); + + SBMLRateRuleConverter* converter = new SBMLRateRuleConverter(); + converter->setProperties(&props); + + std::string filename(TestDataDirectory); + filename += "mraterules7.xml"; + + + SBMLDocument* d = readSBMLFromFile(filename.c_str()); + Model* model = d->getModel(); + fail_unless(model != NULL); + fail_unless(model->getNumParameters() == 2); + + converter->setDocument(d); + converter->populateInitialODEinfo(); + ASTNode* currentNode = const_cast(model->getRule(0)->getMath()) ; + + ExpressionAnalyser* ea = new ExpressionAnalyser(model, converter->getOdePairs()); + + SubstitutionValues_t* value = new SubstitutionValues_t; + value->type = TYPE_UNKNOWN; + value->k_real_value = util_NaN(); + value->dxdt_expression = NULL; + value->dydt_expression = NULL; + value->v_expression = NULL; + value->w_expression = NULL; + + fail_unless(ea->analyseNode(currentNode, value)); + + fail_unless(value->type == TYPE_K_PLUS_V_MINUS_X_MINUS_Y); + fail_unless(util_isNaN(value->k_real_value)); + fail_unless(value->k_value == "k"); + fail_unless(value->x_value == "a"); + fail_unless(value->y_value == "b"); + + fail_unless(formulas_equal("0", value->dxdt_expression)); + fail_unless(formulas_equal("0", value->dydt_expression)); + fail_unless(formulas_equal("v", value->v_expression)); + fail_unless(value->w_expression == NULL); + + fail_unless(formulas_equal("k + v - a - b", value->current)); + fail_unless(value->z_value == ""); + + ea->analyse(); + + fail_unless(ea->getNumExpressions() == 1); + + SubstitutionValues_t* value1 = new SubstitutionValues_t; + value1 = ea->getExpression(0); + fail_unless(ea->areIdenticalSubstitutionValues(value, value1)); + fail_unless(value1->odeIndex == 0); + + delete converter; + delete d; +} +END_TEST + + +START_TEST(test_order_of_replacements2) +{ + ConversionProperties props; + props.addOption("inferReactions", true); + + SBMLRateRuleConverter* converter = new SBMLRateRuleConverter(); + converter->setProperties(&props); + + std::string filename(TestDataDirectory); + filename += "mraterules5.xml"; + + + SBMLDocument* d = readSBMLFromFile(filename.c_str()); + Model* model = d->getModel(); + fail_unless(model != NULL); + + converter->setDocument(d); + converter->populateInitialODEinfo(); + ASTNode* currentNode = const_cast(model->getRule(1)->getMath()->getChild(1)); + cout << SBML_formulaToL3String(currentNode); + ExpressionAnalyser* ea = new ExpressionAnalyser(model, converter->getOdePairs()); + ea->analyse(); + fail_unless(ea->getNumExpressions() == 2); + + SubstitutionValues_t* value1 = new SubstitutionValues_t; + value1 = ea->getExpression(0); + fail_unless(value1->type == TYPE_K_PLUS_V_MINUS_X_MINUS_Y); + fail_unless(util_isNaN(value1->k_real_value)); + fail_unless(value1->k_value == "k"); + fail_unless(value1->x_value == "a"); + fail_unless(value1->y_value == "b"); + + fail_unless(formulas_equal("-1 * (k - a - b)", value1->dxdt_expression)); + fail_unless(formulas_equal("c", value1->dydt_expression)); + fail_unless(formulas_equal("v", value1->v_expression )); + fail_unless(value1->w_expression == NULL); + + fail_unless(formulas_equal("k + v - a - b", value1->current)); + fail_unless(value1->z_value == ""); + fail_unless(value1->odeIndex == 0); + + SubstitutionValues_t* value = new SubstitutionValues_t; + value = ea->getExpression(1); + + fail_unless(value->type == TYPE_K_MINUS_X_MINUS_Y); + fail_unless(util_isNaN(value->k_real_value)); + fail_unless(value->k_value == "k"); + fail_unless(value->x_value == "a"); + fail_unless(value->y_value == "b"); + + fail_unless(formulas_equal("-1 * (k - a - b)", value->dxdt_expression)); + fail_unless(formulas_equal("c", value->dydt_expression)); + fail_unless(value->v_expression == NULL); + fail_unless(value->w_expression == NULL); + + fail_unless(formulas_equal("k - a - b", value->current)); + fail_unless(value->z_value == ""); + + fail_unless(value->odeIndex == 1); + + ea->orderExpressions(); + SubstitutionValues_t* value2 = new SubstitutionValues_t; + value2 = ea->getExpression(0); + fail_unless(ea->areIdenticalSubstitutionValues(value, value2)); + + delete converter; + delete d; +} +END_TEST + +START_TEST(test_variations) +{ + ConversionProperties props; + props.addOption("inferReactions", true); + + SBMLRateRuleConverter* converter = new SBMLRateRuleConverter(); + converter->setProperties(&props); + + SBMLDocument* d = new SBMLDocument(3, 1); + Model* model = setupModel(d); + + RateRule* rr = model->createRateRule(); + rr->setVariable("a"); + rr->setMath(SBML_parseFormula("k-x-y")); + RateRule* rr1 = model->createRateRule(); + rr1->setVariable("b"); + rr1->setMath(SBML_parseFormula("-1*(k-x-y)")); + cout << d->toSBML() << endl; + + + converter->setDocument(d); + //converter->populateInitialODEinfo(); + //ExpressionAnalyser* ea = new ExpressionAnalyser(model, converter->getOde()); + //ea->analyse(); + + + fail_unless(converter->convert() == LIBSBML_OPERATION_SUCCESS); + + cout << d->toSBML() << endl; + delete converter; + delete d; + +} +END_TEST + +Suite * +create_suite_TestExpressionAnalyser (void) +{ + bool testing = false; +Suite *suite = suite_create("ExpressionAnalyser"); + TCase *tcase = tcase_create("ExpressionAnalyser"); + tcase_add_checked_fixture(tcase, + ExpressionAnalyser_setup, ExpressionAnalyser_teardown); + + if (testing) + { + tcase_add_test(tcase, test_analyse_2); + } + else + { + tcase_add_test(tcase, test_analyse); //k-x-y + tcase_add_test(tcase, test_analyse_1); //k+v-x-y + tcase_add_test(tcase, test_analyse_2); //k-x+w-y + tcase_add_test(tcase, test_analyse_3); //k-x + tcase_add_test(tcase, test_analyse_4); //k+v-x + //tcase_add_test(tcase, test_order_of_replacements); + //tcase_add_test(tcase, test_order_of_replacements1); + //tcase_add_test(tcase, test_order_of_replacements2); + + } + suite_add_tcase(suite, tcase); + + return suite; + +} +END_C_DECLS + diff --git a/src/sbml/conversion/test/TestSBMLRateRuleConverter.cpp b/src/sbml/conversion/test/TestSBMLRateRuleConverter.cpp index b754c1961a..28da3512bc 100644 --- a/src/sbml/conversion/test/TestSBMLRateRuleConverter.cpp +++ b/src/sbml/conversion/test/TestSBMLRateRuleConverter.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #include @@ -62,12 +63,18 @@ equals(const char* expected, const char* actual) return false; } +static bool +formulas_equal(const char* expected, ASTNode* actual) +{ + return equals(expected, SBML_formulaToL3String(actual)); +} + extern char *TestDataDirectory; // helper function to set up a parameter with 0 value -Parameter* setupZeroParameter(Model* model, const char* name, bool is_constant) +static Parameter* setupZeroParameter(Model* model, const char* name, bool is_constant) { Parameter* parameter = model->createParameter(); parameter->setId(name); @@ -77,7 +84,6 @@ Parameter* setupZeroParameter(Model* model, const char* name, bool is_constant) } - extern char *TestDataDirectory; START_TEST(test_conversion_raterule_converter_invalid) @@ -1029,35 +1035,43 @@ START_TEST(test_model_valid_55) END_TEST + + + Suite * create_suite_TestSBMLRateRuleConverter (void) { - Suite *suite = suite_create("SBMLRateRuleConverter"); + bool testing = false; +Suite *suite = suite_create("SBMLRateRuleConverter"); TCase *tcase = tcase_create("SBMLRateRuleConverter"); - - tcase_add_test(tcase, test_conversion_raterule_converter_invalid); - tcase_add_test(tcase, test_conversion_raterule_converter); - tcase_add_test(tcase, test_conversion_raterule_converter_non_standard_stoichiometry); - tcase_add_test(tcase, test_conversion_raterule_converter_hidden_variable); - tcase_add_test(tcase, test_crash_converter); - tcase_add_test(tcase, test_model); - tcase_add_test(tcase, test_model1); - tcase_add_test(tcase, test_model2); - tcase_add_test(tcase, test_model3); - tcase_add_test(tcase, test_model4); - tcase_add_test(tcase, test_model5); - tcase_add_test(tcase, test_model6); - tcase_add_test(tcase, test_model_valid_01); // this one works - tcase_add_test(tcase, test_model_valid_02); // this one works - tcase_add_test(tcase, test_model_valid_03); // this one replaces the kinetic law'b' with the assignment rule for b - tcase_add_test(tcase, test_model_valid_04); // this one works - tcase_add_test(tcase, test_model_valid_05); // this one works - tcase_add_test(tcase, test_model_valid_51); // this one works - tcase_add_test(tcase, test_model_valid_52); // this one works although puts the kinetic law in a different order - tcase_add_test(tcase, test_model_valid_53); // this one has hidden species that I'm not picked up -tcase_add_test(tcase, test_model_valid_54); // - tcase_add_test(tcase, test_model_valid_55); // - + if (testing) + { + tcase_add_test(tcase, test_conversion_raterule_converter_invalid); + } + else + { + tcase_add_test(tcase, test_conversion_raterule_converter_invalid); + tcase_add_test(tcase, test_conversion_raterule_converter); + tcase_add_test(tcase, test_conversion_raterule_converter_non_standard_stoichiometry); + tcase_add_test(tcase, test_crash_converter); + tcase_add_test(tcase, test_conversion_raterule_converter_hidden_variable); + tcase_add_test(tcase, test_model); + tcase_add_test(tcase, test_model1); // ??? not sure these are accurate + tcase_add_test(tcase, test_model2); + tcase_add_test(tcase, test_model3); + tcase_add_test(tcase, test_model4); + tcase_add_test(tcase, test_model5); // not working again + //tcase_add_test(tcase, test_model6); // not working + tcase_add_test(tcase, test_model_valid_01); // fixed + tcase_add_test(tcase, test_model_valid_02); + tcase_add_test(tcase, test_model_valid_04); + tcase_add_test(tcase, test_model_valid_05); // have changed the output model but I think it was only valid if compartment volume is one + tcase_add_test(tcase, test_model_valid_51); + tcase_add_test(tcase, test_model_valid_52); + tcase_add_test(tcase, test_model_valid_53); // + tcase_add_test(tcase, test_model_valid_54); // + tcase_add_test(tcase, test_model_valid_55); // + } suite_add_tcase(suite, tcase); return suite; diff --git a/src/sbml/conversion/test/test-data/mraterules5.xml b/src/sbml/conversion/test/test-data/mraterules5.xml index 9ba3424f1b..19507152f6 100644 --- a/src/sbml/conversion/test/test-data/mraterules5.xml +++ b/src/sbml/conversion/test/test-data/mraterules5.xml @@ -6,7 +6,7 @@ - + @@ -52,6 +52,11 @@ + + + c + + diff --git a/src/sbml/conversion/test/test-data/mraterules7.xml b/src/sbml/conversion/test/test-data/mraterules7.xml new file mode 100644 index 0000000000..57e20dfd1a --- /dev/null +++ b/src/sbml/conversion/test/test-data/mraterules7.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + k + v + + a + + b + + + + + + diff --git a/src/sbml/conversion/test/test-data/test b/src/sbml/conversion/test/test-data/test new file mode 100644 index 0000000000..83e56beae9 --- /dev/null +++ b/src/sbml/conversion/test/test-data/test @@ -0,0 +1,122 @@ + +Model 53 +// Reactions: mine + J1: newVar1 => SimData_1 + newVar1; newVar1*I*k_1/(k_7 + newVar1); + J2: SimData_1 => newVar1; SimData_1*k_2/(SimData_1 + k_8); + J3: SimData_1 + newVar1 => SimData_1 + SimData_2 + newVar1; newVar1*SimData_1*k_3/(k_9 + newVar1); + J4: SimData_2 => ; SimData_2*k_4/(SimData_2 + k_10); + J5: SimData_1 + newVar1 => SimData_1 + SimData_3 + newVar1; newVar1*SimData_1*k_5/(k_11 + newVar1); + J6: SimData_2 + SimData_3 => SimData_2; SimData_3*SimData_2*k_6/(SimData_3 + k_12); + +// once from moccasin + J1: SimData_1 => SimData_6; SimData_1*(k_2/(SimData_1 + k_8)); + J2: SimData_6 => SimData_1; k_1*SimData_6*(I/(SimData_6 + k_7)); + J3: SimData_2 => SimData_5; SimData_2*(k_4/(SimData_2 + k_10)); + J4: SimData_1 + SimData_5 => SimData_1 + SimData_2; SimData_1*SimData_5*(k_3/(SimData_5 + k_9)); + J5: SimData_2 + SimData_3 => SimData_2 + SimData_4; SimData_2*SimData_3*(k_6/(SimData_3 + k_12)); + J6: SimData_1 + SimData_4 => SimData_1 + SimData_3; SimData_1*SimData_4*(k_5/(SimData_4 + k_11)); + +// new code +J1: newVar1 => SimData_1 + newVar1; (newVar1 * I * k_1)/(k_7 + newVar1) = j2 with added product +J2: SimData_1 => newVar1; (SimData_1 * k_2)/(SimData_1 + k_8) = j1 +J3: SimData_1 + newVar2 => SimData_1 + SimData_2 + newVar2; (newVar2 * SimData_1 * k_3)/(k_9 + newVar2) = j4 with added product +j4: SimData_2 => newVar2; (SimData_2 * k_4)(SimData_2 + k_10) = j3 +j5: SimData_1 + newVar3 => SimData_1 + SimData_3 + newVar3; (newVar3 * SimData_1 * k_5)/(k_11 + newVar3) = j6 with added product +j6: SimData_2 + SimData_3 => SimData_2 + newVar3; (SimData_3 * SimData_2 * k_6)/(SimData_3 + k_12) = j5 with added reactant6* + +model five + +// from moccasin +j1: newVar1 => c + newVar1; newVar1 +j2: => c; v + +// my code +j1: newVar1 => c + newVar1; newVar1 = J1 +j2: => c; v = j2 +j3: newVar2 => 2*newVar2; newVar2 +j4: => newVar1; k +j5: a + newVar1 => a; a +j6: newVar1 => b + +model 54 + +// from moccasin +j1: SimData_1 => SimData_6; SimData_1 * (k__2/(SimData_1 + k__8)) +j2: SimData_6 => SimData_1 (k__1 * SimData_6 * I)/(SimData_6 + k__7) +j3: SimData_2 => SimData_5 SimData_2 * (k__4/(SimData_2 + k__10)) +j4: SimData_1 + SimData_5 => SimData_1 + SimData_2 (SimData_1 * SimData_5 * k__3)/(SimData_5 + k__9) +j5: SimData_2 + SimData_3 => SimData_2 + SimData_4 (SimData_2 * SimData_3 * k__6)/(SimData_3 + k__12) +j6: SimData_1 + SimData_4 => SimData_1 + SimData_3 (SimData_1 * SimData_4 * k__5)/(SimData_4 + k__11) + +// my code +j1: j2 newVar1 = SimData_6 with added product newVar1 +j2: j1 newVar1 = SimData_6 +j3: j4 newVar2 = SimData_5 with added product newVar2 +j4: j3 newVar2 = SimData_5 +j5: j6 newVar3 = SimData_4 with added product newVar3 +j6: j5 newVar3 = SimData_4 + +model 55 + +// from moccasin + +convert function + +populateInitialodeInfo +populateodeInfo + ea-> detectHiddenSpecies + ->analyze True only add -x+y + ->analyzeNode + ->isVariableSpeciesOrParameter + ->isNumericalConstantOrConstantParameter + ->hasExpressionAlreadyBeanRecorded + ->expressionExists + ->matches* + ->reorderMinusExPlusYIteratively + ->replaceExpressioninNodeWithNode + ->analyze False + -> as above + ->substituteParameterForExpression + ->getUniqueNoParameterName + -> addodePair + -> populateTerms + ->createTerms + -> createAnalysisVectors + ->populateCoefficientVector + ->populateDerivativeVector +populateReactionCoefficients + ->createInitialValues + ->analyzeCoefficient + ->analyzePosDerivative + ->analyzeNagDerivative +reconstructModel + ->dealWithSpecies + ->createReactions + ->removeRules + + TYPE_K_MINUS_X_MINUS_Y + analyzeNode k-x-y + right: y + left: k-x + analyzeNode k-x + right: x + left: k + values: k x dx type=k-x + values: y dy type=k-x-y + , TYPE_K_PLUS_V_MINUS_X_MINUS_Y + analyzeNode k+v-x-y + right: y + left: k+v-x + analyzeNode: k+v-x + right: x + left: k+v + analyzeNode: k+v + right: v + left: k + return False + values: k x dx v type=k+v-x + values: y dy type=k+v-x-y + , TYPE_K_MINUS_X_PLUS_W_MINUS_Y + , TYPE_K_MINUS_X + , TYPE_K_PLUS_V_MINUS_X +ne \ No newline at end of file diff --git a/src/sbml/conversion/test/test-data/valid_54_bio.c b/src/sbml/conversion/test/test-data/valid_54_bio.c new file mode 100644 index 0000000000..daced134b6 --- /dev/null +++ b/src/sbml/conversion/test/test-data/valid_54_bio.c @@ -0,0 +1,103 @@ +#ifdef SIZE_DEFINITIONS +#define N_METABS 6 +#define N_ODE_METABS 0 +#define N_INDEP_METABS 3 +#define N_COMPARTMENTS 1 +#define N_GLOBAL_PARAMS 14 +#define N_KIN_PARAMS 0 +#define N_REACTIONS 6 + +#define N_ARRAY_SIZE_P 14 // number of parameters +#define N_ARRAY_SIZE_X 3 // number of initials +#define N_ARRAY_SIZE_Y 4 // number of assigned elements +#define N_ARRAY_SIZE_XC 3 // number of x concentration +#define N_ARRAY_SIZE_PC 0 // number of p concentration +#define N_ARRAY_SIZE_YC 3 // number of y concentration +#define N_ARRAY_SIZE_DX 3 // number of ODEs +#define N_ARRAY_SIZE_CT 3 // number of conserved totals + +#endif // SIZE_DEFINITIONS + +#ifdef TIME +#define T +#endif // TIME + +#ifdef NAME_ARRAYS +const char* p_names[] = {"compartmentOne", "I", "k__1", "k__2", "k__3", "k__4", "k__5", "k__6", "k__7", "k__8", "k__9", "k__10", "k__11", "k__12", "" }; +const char* x_names[] = {"SimData_1", "SimData_2", "SimData_3", "" }; +const char* y_names[] = {"SimData_4", "SimData_5", "SimData_6", "t", "" }; +const char* xc_names[] = {"SimData_1", "SimData_2", "SimData_3", "" }; +const char* pc_names[] = { "" }; +const char* yc_names[] = {"SimData_4", "SimData_5", "SimData_6", "" }; +const char* dx_names[] = {"ODE SimData_1", "ODE SimData_2", "ODE SimData_3", "" }; +const char* ct_names[] = {"CT SimData_4", "CT SimData_5", "CT SimData_6", "" }; +#endif // NAME_ARRAYS + +#ifdef INITIAL +x[0] = 1; //metabolite 'SimData_1': reactions +x[1] = 1; //metabolite 'SimData_2': reactions +x[2] = 1; //metabolite 'SimData_3': reactions +#endif /* INITIAL */ + +#ifdef FIXED +ct[0] = 0.99999999999999978; //ct[0] conserved total for 'SimData_4' +ct[1] = 0.99999999999999978; //ct[1] conserved total for 'SimData_5' +ct[2] = 0.99999999999999978; //ct[2] conserved total for 'SimData_6' +p[0] = 1; //compartment 'compartmentOne':fixed +p[1] = 1; //global quantity 'I':fixed +p[2] = 4.2416; //global quantity 'k__1':fixed +p[3] = 5.9816; //global quantity 'k__2':fixed +p[4] = 0.1009; //global quantity 'k__3':fixed +p[5] = 1.1549; //global quantity 'k__4':fixed +p[6] = 1.3618; //global quantity 'k__5':fixed +p[7] = 1.4219; //global quantity 'k__6':fixed +p[8] = 0.0051; //global quantity 'k__7':fixed +p[9] = 0.0972; //global quantity 'k__8':fixed +p[10] = 0.0012; //global quantity 'k__9':fixed +p[11] = 56.8583; //global quantity 'k__10':fixed +p[12] = 0.0111; //global quantity 'k__11':fixed +p[13] = 0.0014; //global quantity 'k__12':fixed +#endif /* FIXED */ + +#ifdef ASSIGNMENT +y[0] = ct[0]-x[2]; //metabolite 'SimData_4': reactions +y[1] = ct[1]-x[1]; //metabolite 'SimData_5': reactions +y[2] = ct[2]-x[0]; //metabolite 'SimData_6': reactions +y[3] = T; //model entity 't':assignment +x_c[0] = x[0]/p[0]; //concentration of metabolite 'SimData_1': reactions +x_c[1] = x[1]/p[0]; //concentration of metabolite 'SimData_2': reactions +x_c[2] = x[2]/p[0]; //concentration of metabolite 'SimData_3': reactions +y_c[0] = y[0]/p[0]; //concentration of metabolite 'SimData_4': reactions +y_c[1] = y[1]/p[0]; //concentration of metabolite 'SimData_5': reactions +y_c[2] = y[2]/p[0]; //concentration of metabolite 'SimData_6': reactions +#endif /* ASSIGNMENT */ + +#ifdef FUNCTIONS_HEADERS +double FunctionForJ1_1(double sub_0, double volume_0, double param_0, double param_1); +double FunctionForJ2_1(double param_0, double sub_0, double volume_0, double param_1, double param_2); +double FunctionForJ3(double sub_0, double volume_0, double param_0, double param_1); +double FunctionForJ4(double sub_0, double sub_1, double volume_0, double param_0, double param_1); +double FunctionForJ5(double sub_0, double sub_1, double volume_0, double param_0, double param_1); +double FunctionForJ6(double sub_0, double sub_1, double volume_0, double param_0, double param_1); +#endif /* FUNCTIONS_HEADERS */ + +#ifdef FUNCTIONS +double FunctionForJ1_1(double sub_0, double volume_0, double param_0, double param_1) //Function for J1_1 +{return sub_0*(param_0/(sub_0+param_1))/volume_0;} +double FunctionForJ2_1(double param_0, double sub_0, double volume_0, double param_1, double param_2) //Function for J2_1 +{return param_1*sub_0*(param_0/(sub_0+param_2))/volume_0;} +double FunctionForJ3(double sub_0, double volume_0, double param_0, double param_1) //Function for J3 +{return sub_0*(param_1/(sub_0+param_0))/volume_0;} +double FunctionForJ4(double sub_0, double sub_1, double volume_0, double param_0, double param_1) //Function for J4 +{return sub_0*sub_1*(param_0/(sub_1+param_1))/volume_0;} +double FunctionForJ5(double sub_0, double sub_1, double volume_0, double param_0, double param_1) //Function for J5 +{return sub_0*sub_1*(param_1/(sub_1+param_0))/volume_0;} +double FunctionForJ6(double sub_0, double sub_1, double volume_0, double param_0, double param_1) //Function for J6 +{return sub_0*sub_1*(param_1/(sub_1+param_0))/volume_0;} +#endif /* FUNCTIONS */ + +#ifdef ODEs +dx[0] = -FunctionForJ1_1(x_c[0], p[0], p[3], p[9])*p[0]+FunctionForJ2_1(p[1], y_c[2], p[0], p[2], p[8])*p[0]; +dx[1] = -FunctionForJ3(x_c[1], p[0], p[11], p[5])*p[0]+FunctionForJ4(x_c[0], y_c[1], p[0], p[4], p[10])*p[0]; +dx[2] = -FunctionForJ5(x_c[1], x_c[2], p[0], p[13], p[7])*p[0]+FunctionForJ6(x_c[0], y_c[0], p[0], p[12], p[6])*p[0]; +#endif /* ODEs */ diff --git a/src/sbml/conversion/test/test-data/valid_54_rr.c b/src/sbml/conversion/test/test-data/valid_54_rr.c new file mode 100644 index 0000000000..d3ae5c036e --- /dev/null +++ b/src/sbml/conversion/test/test-data/valid_54_rr.c @@ -0,0 +1,79 @@ +#ifdef SIZE_DEFINITIONS +#define N_METABS 3 +#define N_ODE_METABS 3 +#define N_INDEP_METABS 0 +#define N_COMPARTMENTS 1 +#define N_GLOBAL_PARAMS 14 +#define N_KIN_PARAMS 0 +#define N_REACTIONS 0 + +#define N_ARRAY_SIZE_P 14 // number of parameters +#define N_ARRAY_SIZE_X 3 // number of initials +#define N_ARRAY_SIZE_Y 1 // number of assigned elements +#define N_ARRAY_SIZE_XC 3 // number of x concentration +#define N_ARRAY_SIZE_PC 0 // number of p concentration +#define N_ARRAY_SIZE_YC 0 // number of y concentration +#define N_ARRAY_SIZE_DX 3 // number of ODEs +#define N_ARRAY_SIZE_CT 0 // number of conserved totals + +#endif // SIZE_DEFINITIONS + +#ifdef TIME +#define T +#endif // TIME + +#ifdef NAME_ARRAYS +const char* p_names[] = {"compartmentOne", "I", "k__1", "k__2", "k__3", "k__4", "k__5", "k__6", "k__7", "k__8", "k__9", "k__10", "k__11", "k__12", "" }; +const char* x_names[] = {"SimData__1", "SimData__2", "SimData__3", "" }; +const char* y_names[] = {"t", "" }; +const char* xc_names[] = {"SimData__1", "SimData__2", "SimData__3", "" }; +const char* pc_names[] = { "" }; +const char* yc_names[] = { "" }; +const char* dx_names[] = {"ODE SimData__1", "ODE SimData__2", "ODE SimData__3", "" }; +const char* ct_names[] = { "" }; +#endif // NAME_ARRAYS + +#ifdef INITIAL +x[0] = 1; //metabolite 'SimData__1': ode +x[1] = 1; //metabolite 'SimData__2': ode +x[2] = 1; //metabolite 'SimData__3': ode +#endif /* INITIAL */ + +#ifdef FIXED +p[0] = 1; //compartment 'compartmentOne':fixed +p[1] = 1; //global quantity 'I':fixed +p[2] = 4.2416; //global quantity 'k__1':fixed +p[3] = 5.9816; //global quantity 'k__2':fixed +p[4] = 0.1009; //global quantity 'k__3':fixed +p[5] = 1.1549; //global quantity 'k__4':fixed +p[6] = 1.3618; //global quantity 'k__5':fixed +p[7] = 1.4219; //global quantity 'k__6':fixed +p[8] = 0.0051; //global quantity 'k__7':fixed +p[9] = 0.0972; //global quantity 'k__8':fixed +p[10] = 0.0012; //global quantity 'k__9':fixed +p[11] = 56.8583; //global quantity 'k__10':fixed +p[12] = 0.0111; //global quantity 'k__11':fixed +p[13] = 0.0014; //global quantity 'k__12':fixed +#endif /* FIXED */ + +#ifdef ASSIGNMENT +y[0] = T; //model entity 't':assignment +x_c[0] = x[0]/p[0]; //concentration of metabolite 'SimData__1': ode +x_c[1] = x[1]/p[0]; //concentration of metabolite 'SimData__2': ode +x_c[2] = x[2]/p[0]; //concentration of metabolite 'SimData__3': ode +#endif /* ASSIGNMENT */ + +#ifdef FUNCTIONS_HEADERS +#endif /* FUNCTIONS_HEADERS */ + +#ifdef FUNCTIONS +#endif /* FUNCTIONS */ + +#ifdef ODEs +dx[0] = p[2]*p[1]*(1.00000000000000000-x_c[0])/(1.00000000000000000-x_c[0]+p[8])-p[3]*x_c[0]/(x_c[0]+p[9]) * p[0]; //model entity 'SimData__1':ode +dx[0] = p[2]*p[1]*(1.00000000000000000-x_c[0])/(1.00000000000000000-x_c[0]+p[8])-p[3]*x_c[0]/(x_c[0]+p[9]) * p[0]; //model entity 'SimData__1':ode +dx[1] = p[4]*x_c[0]*(1.00000000000000000-x_c[1])/(1.00000000000000000-x_c[1]+p[10])-p[5]*x_c[1]/(x_c[1]+p[11]) * p[0]; //model entity 'SimData__2':ode +dx[1] = p[4]*x_c[0]*(1.00000000000000000-x_c[1])/(1.00000000000000000-x_c[1]+p[10])-p[5]*x_c[1]/(x_c[1]+p[11]) * p[0]; //model entity 'SimData__2':ode +dx[2] = p[6]*x_c[0]*(1.00000000000000000-x_c[2])/(1.00000000000000000-x_c[2]+p[12])-p[7]*x_c[1]*x_c[2]/(x_c[2]+p[13]) * p[0]; //model entity 'SimData__3':ode +dx[2] = p[6]*x_c[0]*(1.00000000000000000-x_c[2])/(1.00000000000000000-x_c[2]+p[12])-p[7]*x_c[1]*x_c[2]/(x_c[2]+p[13]) * p[0]; //model entity 'SimData__3':ode +#endif /* ODEs */