EnzymeML / PyEnzyme

🧬 - Data management and modeling framework based on EnzymeML.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Measurement.exportData() no longer works

jmrohwer opened this issue · comments

After the reaction hierarchy has been removed from the Measurement class, the exportData() method no longer works:

m1 = enzmldoc.getMeasurementDict()['m1']

m1.exportData()

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-4-f873839397e7> in <module>
----> 1 m1.exportData()

~/src/git/EnzymeML/PyEnzyme/pyenzyme/enzymeml/core/measurement.py in exportData(self, enzmldoc)
     84 
     85             proteins = self.__combineReplicates(
---> 86                 measurementSpecies=reaction['proteins'],
     87                 reactionID=reactionID,
     88                 enzmldoc=enzmldoc,

KeyError: 'proteins'

It would be fixed by the following diff:

diff --git a/pyenzyme/enzymeml/core/measurement.py b/pyenzyme/enzymeml/core/measurement.py
index bd53a83..b86fd8f 100644
--- a/pyenzyme/enzymeml/core/measurement.py
+++ b/pyenzyme/enzymeml/core/measurement.py
@@ -79,33 +79,28 @@ class Measurement(EnzymeMLBase):
 
         measurements = dict()
 
-        # Combine Replicate objects for each reaction
-        for reactionID, reaction in self.__speciesDict.items():
-
-            proteins = self.__combineReplicates(
-                measurementSpecies=reaction['proteins'],
-                reactionID=reactionID,
-                enzmldoc=enzmldoc,
-                speciesType='proteins'
-            )
-            reactants = self.__combineReplicates(
-                measurementSpecies=reaction['reactants'],
-                reactionID=reactionID,
-                enzmldoc=enzmldoc,
-                speciesType='reactants'
-            )
+        # Combine Replicate objects
+        proteins = self.__combineReplicates(
+            measurementSpecies=self.__speciesDict['proteins'],
+            enzmldoc=enzmldoc,
+            speciesType='proteins'
+        )
+        reactants = self.__combineReplicates(
+            measurementSpecies=self.__speciesDict['reactants'],
+            enzmldoc=enzmldoc,
+            speciesType='reactants'
+        )
 
-            measurements[reactionID] = {
-                "proteins": proteins,
-                "reactants": reactants
-            }
+        measurements = {
+            "proteins": proteins,
+            "reactants": reactants
+        }
 
         return measurements
 
     def __combineReplicates(
         self,
         measurementSpecies,
-        reactionID,
         enzmldoc,
         speciesType
     ):
@@ -114,7 +109,6 @@ class Measurement(EnzymeMLBase):
         columns = [self.__globalTime]
         header = [f"time/{self.__globalTimeUnit}"]
         initConcs = dict()
-        stoichiometries = dict()
 
         # Iterate over measurementData to fill columns
         for speciesID, data in measurementSpecies.items():
@@ -133,19 +127,12 @@ class Measurement(EnzymeMLBase):
             # Fetch initial concentration
             initConcs[speciesID] = (data.getInitConc(), data.getUnit())
 
-            # Fetch the stoichiometry of the reactant
-            if speciesType == 'reactants' and enzmldoc is not None:
-                stoichiometries[speciesID] = self.__getStoichiometry(
-                    reaction=enzmldoc.getReaction(reactionID),
-                    speciesID=speciesID
-                )
-
-        if len(columns) > 1:
-            return {
-                "data": pd.DataFrame(np.array(columns).T, columns=header),
-                "initConc": initConcs,
-                "stoichiometries": stoichiometries
-            }
+        return {
+            'data': pd.DataFrame(np.array(columns).T, columns=header)
+            if len(columns) > 1
+            else None,
+            'initConc': initConcs,
+        }
 
     def __getStoichiometry(self, reaction, speciesID):

Thanks for bringing this up! The function was fixed in cc7929c.