Repository: fbergmann/libSEDML (language: python)

Issue:
Can't call DependentVariable functions
A DependentVariable differs from a Variable in that it also has the attributes 'symbol2', 'target2', and 'term'.

However, when I read it in and call getVariable from its parent DataGenerator, I am unable to interact with those attributes.  Here's a small python script that demonstrates the problem:

```
import libsedml

doc = libsedml.readSedMLFromFile("rateOfChange.sedml")
dg = doc.getDataGenerator(3)
var = dg.getVariable(0)
print("SedVariable:", libsedml.SEDML_VARIABLE)
print("SedDependentVariable:", libsedml.SEDML_DEPENDENTVARIABLE)
print("Var type code: ", var.getTypeCode())

print("symbol: ", var.getSymbol())

try:
    print("symbol2:", var.getSymbol2())
except:
    print("unable to call 'getSymbol2'.")

[rateOfChange.sedml.txt](https://github.com/fbergmann/libSEDML/files/6534906/rateOfChange.sedml.txt)



Discussion / hints:
thanks for the report, looking at this now. 
By the way, i would have expected dependentVariable to be used differently. In this case i would expect instead of: 

```
    <dependentVariable id="S1" symbol="urn:sedml:symbol:rateOfChange" target="/sbml:sbml/sbml:model/sbml:listOfSpecies/sbml:species[@id=&apos;S1&apos;]" taskReference="task0" modelReference="model0" symbol2="urn:sedml:symbol:time"/>
```

i would want: 

```
    <dependentVariable id="S1" 
      taskReference="task0" <-- really only this one as the model becomes aparent from there
      modelReference="model0" <-- but ok 
      term="urn:sedml:symbol:rateOfChange" <-- rather than symbol1
      target="/sbml:sbml/sbml:model/sbml:listOfSpecies/sbml:species[@id=&apos;S1&apos;]"
      symbol2="urn:sedml:symbol:time"
    />
```

especially, since term would be a required attribute, so it does get flagged as invalid sedml (though the error message does require rewording, to indicate that variable attributes would have been allowed):

```
A <dependentVariable> object must have the required attribute 'sedml:term', and may have the optional attributes 'sedml:targetTwo' and 'sedml:symbolTwo'. No other attributes from the SBML Level 3 SED-ML namespaces are permitted on a <dependentVariable> object. 
```

Fix patch:
diff --git a/VERSION.txt b/VERSION.txt
index ed2af5c1..d17d1f3b 100755
--- a/VERSION.txt
+++ b/VERSION.txt
@@ -1,1 +1,1 @@
-2.0.19
+2.0.20
diff --git a/src/bindings/python/local.i b/src/bindings/python/local.i
index 340289b7..4412e2d3 100755
--- a/src/bindings/python/local.i
+++ b/src/bindings/python/local.i
@@ -273,13 +273,7 @@ namespace std
                                $owner | %newpointer_flags);
 }
 
-%typemap(out) SedBase*, SedSimulation*, SedAbstractTask*, SedTask*, SedOutput*, SedChange*, SedRange*, SedAbstractCurve*
-{
-  $result = SWIG_NewPointerObj(SWIG_as_voidptr($1), GetDowncastSwigType($1),
-                               $owner | %newpointer_flags);
-}
-
-%typemap(out) SedBase*, SedSimulation*, SedAbstractTask*, SedTask*, SedOutput*, SedChange*, SedRange*, SedAbstractCurve*
+%typemap(out) SedBase*, SedSimulation*, SedAbstractTask*, SedTask*, SedOutput*, SedChange*, SedRange*, SedAbstractCurve*, SedVariable*
 {
   $result = SWIG_NewPointerObj(SWIG_as_voidptr($1), GetDowncastSwigType($1),
                                $owner | %newpointer_flags);
diff --git a/src/bindings/ruby/local.i b/src/bindings/ruby/local.i
index 3cd8a498..d57023aa 100755
--- a/src/bindings/ruby/local.i
+++ b/src/bindings/ruby/local.i
@@ -220,7 +220,7 @@ namespace std
 /**
  * Convert objects into the most specific type possible.
  */
-%typemap(out) SedBase*, SedSimulation*, SedAbstractTask*, SedTask*, SedOutput*, SedChange*, SedRange*, SedAbstractCurve*
+%typemap(out) SedBase*, SedSimulation*, SedAbstractTask*, SedTask*, SedOutput*, SedChange*, SedRange*, SedAbstractCurve*, SedVariable*
 {
   $result = SWIG_NewPointerObj(SWIG_as_voidptr($1), GetDowncastSwigType($1),
                                $owner | %newpointer_flags);


Test patch:
diff --git a/tests/TestIssues.cpp b/tests/TestIssues.cpp
index b5d2dec0..1cc63f2e 100644
--- a/tests/TestIssues.cpp
+++ b/tests/TestIssues.cpp
@@ -871,4 +871,26 @@ TEST_CASE("Add reverse to axis", "[sedml]")
 }
 
 
+TEST_CASE("Reading dependent variable", "[sedml]")
+{
+  std::string fileName = getTestFile("/test-data/issue_140.sedml");
+  SedDocument* doc = readSedMLFromFile(fileName.c_str());
+  // 2 dependent variables are invalid here (missing term)
+  REQUIRE(doc->getNumErrors(LIBSEDML_SEV_ERROR) == 2); 
+
+  {
+    REQUIRE(doc->getNumDataGenerators() > 3);
+    auto* dg = doc->getDataGenerator(3);
+    REQUIRE(dg != NULL);
+    REQUIRE(dg->getNumVariables() > 0);
+    auto* var = dynamic_cast<SedDependentVariable*> (dg->getVariable(0));
+    REQUIRE(var != NULL);
+
+    REQUIRE(var->getTarget() == "/sbml:sbml/sbml:model/sbml:listOfSpecies/sbml:species[@id='S1']");
+    REQUIRE(var->getSymbol2() == "urn:sedml:symbol:time");
+
+  }
+
+  delete doc;
 
+}
\ No newline at end of file
diff --git a/tests/test-data/issue_140.sedml b/tests/test-data/issue_140.sedml
new file mode 100644
index 00000000..df1935ca
--- /dev/null
+++ b/tests/test-data/issue_140.sedml
@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<sedML xmlns="http://sed-ml.org/sed-ml/level1/version4" level="1" version="4">
+  <listOfModels>
+    <model id="model0" language="urn:sedml:language:sbml.level-3.version-1" source="case_01.xml"/>
+  </listOfModels>
+  <listOfSimulations>
+    <uniformTimeCourse id="sim0" initialTime="0" outputStartTime="0" outputEndTime="10" numberOfSteps="10">
+      <algorithm kisaoID="KISAO:0000019"/>
+    </uniformTimeCourse>
+  </listOfSimulations>
+  <listOfTasks>
+    <task id="task0" modelReference="model0" simulationReference="sim0"/>
+  </listOfTasks>
+  <listOfDataGenerators>
+    <dataGenerator id="plot_0_0_0" name="time">
+      <math xmlns="http://www.w3.org/1998/Math/MathML">
+        <ci> time </ci>
+      </math>
+      <listOfVariables>
+        <variable id="time" symbol="urn:sedml:symbol:time" taskReference="task0" modelReference="model0"/>
+      </listOfVariables>
+    </dataGenerator>
+    <dataGenerator id="plot_0_0_1" name="S1">
+      <math xmlns="http://www.w3.org/1998/Math/MathML">
+        <ci> S1 </ci>
+      </math>
+      <listOfVariables>
+        <variable id="S1" target="/sbml:sbml/sbml:model/sbml:listOfSpecies/sbml:species[@id=&apos;S1&apos;]" taskReference="task0" modelReference="model0"/>
+      </listOfVariables>
+    </dataGenerator>
+    <dataGenerator id="plot_0_1_1" name="S2">
+      <math xmlns="http://www.w3.org/1998/Math/MathML">
+        <ci> S2 </ci>
+      </math>
+      <listOfVariables>
+        <variable id="S2" target="/sbml:sbml/sbml:model/sbml:listOfSpecies/sbml:species[@id=&apos;S2&apos;]" taskReference="task0" modelReference="model0"/>
+      </listOfVariables>
+    </dataGenerator>
+    <dataGenerator id="S1_roc" name="S1">
+      <math xmlns="http://www.w3.org/1998/Math/MathML">
+        <ci> S1 </ci>
+      </math>
+      <listOfVariables>
+        <dependentVariable id="S1" symbol="urn:sedml:symbol:rateOfChange" target="/sbml:sbml/sbml:model/sbml:listOfSpecies/sbml:species[@id=&apos;S1&apos;]" taskReference="task0" modelReference="model0" symbol2="urn:sedml:symbol:time"/>
+      </listOfVariables>
+    </dataGenerator>
+    <dataGenerator id="S2_roc" name="S2">
+      <math xmlns="http://www.w3.org/1998/Math/MathML">
+        <ci> S2 </ci>
+      </math>
+      <listOfVariables>
+        <dependentVariable id="S2" symbol="urn:sedml:symbol:rateOfChange" target="/sbml:sbml/sbml:model/sbml:listOfSpecies/sbml:species[@id=&apos;S2&apos;]" taskReference="task0" modelReference="model0" symbol2="urn:sedml:symbol:time"/>
+      </listOfVariables>
+    </dataGenerator>
+  </listOfDataGenerators>
+  <listOfOutputs>
+    <plot2D id="plot_0" name="UniformTimecourse default">
+      <listOfCurves>
+        <curve id="plot_0__plot_0_0_0__plot_0_0_1" logX="false" xDataReference="plot_0_0_0" logY="false" yDataReference="plot_0_0_1"/>
+        <curve id="plot_0__plot_0_0_0__plot_0_1_1" logX="false" xDataReference="plot_0_0_0" logY="false" yDataReference="plot_0_1_1"/>
+      </listOfCurves>
+    </plot2D>
+    <plot2D id="plot_1" name="UniformTimecourse rateOfChange">
+      <listOfCurves>
+        <curve id="plot_1__plot_0_0_0__plot_0_0_1" logX="false" xDataReference="plot_0_0_0" logY="false" yDataReference="S1_roc"/>
+        <curve id="plot_1__plot_0_0_0__plot_0_1_1" logX="false" xDataReference="plot_0_0_0" logY="false" yDataReference="S2_roc"/>
+      </listOfCurves>
+    </plot2D>
+  </listOfOutputs>
+</sedML>