Porthmeus / MeMoMe

Metabolic Model Merging - a semiautomated way to merge genome scale metabolic models
Apache License 2.0
0 stars 0 forks source link

RDKIT Error #86

Closed Unaimend closed 4 months ago

Unaimend commented 7 months ago
    def test_adlercreutzia_equolifaciens_bigg_id_chebi(self):
        # load the e.coli core model and bulk annotate the metabolites. Check if any annoation tkes place (Chebi should cover all metabolites)
        mod_path = self.dat.joinpath("Adlercreutzia_equolifaciens_DSM_19450.xml")
        mod = MeMoModel.fromPath(mod_path)
        exp = AnnotationResult(0,577,196)
        res1 = AnnotationResult.fromTuple(annotateBiGG_id(mod.metabolites))
        res2 = AnnotationResult.fromTuple(annotateChEBI(mod.metabolites))
        add_test_case_to_table(self.test_adlercreutzia_equolifaciens_bigg_id_chebi.__name__, res1 + res2, exp)   
        self.assertLessEqual(exp, res1 + res2, msg=f"Expected amount of annotated metabolites: {exp}, calculated amount of annotated metabolites: {res1 + res2}. All three must be >=")

results in

ERROR: test_adlercreutzia_equolifaciens_bigg_id_chebi (__main__.Test_annotateBulkRoutines.test_adlercreutzia_equolifaciens_bigg_id_chebi)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/td/Projects/MeMoMe/tests/test_bulkPerformance.py", line 162, in test_adlercreutzia_equolifaciens_bigg_id_chebi
    res2 = AnnotationResult.fromTuple(annotateChEBI(mod.metabolites))
                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/td/Projects/MeMoMe/src/annotateChEBI.py", line 40, in annotateChEBI
    inchi = findOptimalInchi(inchis)
            ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/td/Projects/MeMoMe/src/annotateInchiRoutines.py", line 66, in findOptimalInchi
    k = k + int(matchMetsByInchi(inchis[i], inchis[j], verbose = verbose)[0])
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/td/Projects/MeMoMe/src/matchMets.py", line 46, in matchMetsByInchi
    same = compareInchiByStereoIsomer0(m1,m2, verbose = verbose)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/td/Projects/MeMoMe/src/matchInchiRoutines.py", line 165, in compareInchiByStereoIsomer0
    stereo1 = [Chem.MolToInchi(x) for x in EnumerateStereoisomers(m1, options=opts)]
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/td/mambaforge/envs/MeMoMe/lib/python3.12/site-packages/rdkit/Chem/EnumerateStereoisomers.py", line 328, in EnumerateStereoisomers
    flippers[i].flip(flag)
  File "/home/td/mambaforge/envs/MeMoMe/lib/python3.12/site-packages/rdkit/Chem/EnumerateStereoisomers.py", line 49, in flip
    self.bond.SetStereo(Chem.BondStereo.STEREOTRANS)
RuntimeError: Pre-condition Violation
    Stereo atoms should be specified before specifying CIS/TRANS bond stereochemistry
    Violation occurred on line 321 in file Code/GraphMol/Bond.h
    Failed Expression: what <= STEREOE || getStereoAtoms().size() == 2
    RDKIT: 2023.09.5
    BOOST: 1_82
Porthmeus commented 7 months ago

Did you already address that? Looks to me like a misdefined InChI - we could catch this with the precalculations of the metabolites in the matching process.

Unaimend commented 7 months ago

I did not look into it at all, maybe we can do this together

Unaimend commented 6 months ago

Issue still persists on the main branch

Unaimend commented 6 months ago

For now I will implement a try-catch that just ignores the error

Porthmeus commented 5 months ago

Ok I understand now how this error arises, but I have not yet solution to it. It happens if we try to evaluate stereoisomers after we neutralize charges from the molecule. This seems to be related to the conversion between SMILE and rdkit.Mol and InChI. I currently tried implement a solution, but it broke more, than it helped. Will stay on the poblem.

Porthmeus commented 4 months ago

Has been fixed in #133