Skip to content

Commit

Permalink
merge: pull request #6 from brsynth/GetCids
Browse files Browse the repository at this point in the history
chore(rp2erxn): handle different cmp IDs
  • Loading branch information
tduigou authored Oct 16, 2023
2 parents 8af76cb + 8914f83 commit 3b35f03
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
6 changes: 5 additions & 1 deletion rp2paths/rp2erxn.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import sys
import csv
import argparse
from re import match as re_match
from rdkit import Chem
from rp2paths.IDsHandler import IDsHandler

Expand Down Expand Up @@ -86,7 +87,10 @@ def SortCids(cids):
break
# Sort IDs
if mnx_case:
return sorted(cids, key=lambda x: int(x[4:]))
try:
return sorted(cids, key=lambda x: int(re_match(r'MNXM(\d+)\w*', x).group(1)))
except ValueError:
return sorted(cids)
else:
return sorted(cids)

Expand Down
3 changes: 2 additions & 1 deletion tests/_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@

from unittest import TestCase

from pathlib import Path
from os import stat as os_stat
from os import path as os_path

from rp2paths.rp2erxn import Compound


class Main(TestCase):
__test__ = False
Expand Down
36 changes: 36 additions & 0 deletions tests/test_rp2erxn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""
Created on Oct 16 2023
@author: Joan Hérisson
"""

from unittest import TestCase

from os import stat as os_stat
from os import path as os_path

from rp2paths.rp2erxn import Compound


class Test_rp2erxn(TestCase):

def test_SortCidsMNXM_1(self):
mnx_cids = ['MNXM03', 'MNXM02', 'MNXM5', 'MNXM1']
self.assertListEqual(
Compound.SortCids(mnx_cids),
['MNXM1', 'MNXM02', 'MNXM03', 'MNXM5']
)

def test_SortCidsMNXM_2(self):
mnx_cids = ['MNXM03', 'MNXM02', 'MNXM5__64__MNXC3', 'MNXM1']
self.assertListEqual(
Compound.SortCids(mnx_cids),
['MNXM1', 'MNXM02', 'MNXM03', 'MNXM5__64__MNXC3']
)

def test_SortCidsNotMNXM(self):
mnx_cids = ['M_2agpg181_c', 'M_2agpg161_c', 'M_2ahbut_c', 'M_2agpg180_c', 'MNXM1']
self.assertListEqual(
Compound.SortCids(mnx_cids),
['MNXM1', 'M_2agpg161_c', 'M_2agpg180_c', 'M_2agpg181_c', 'M_2ahbut_c']
)

0 comments on commit 3b35f03

Please sign in to comment.