schymane / RChemMass

Various Cheminformatic, Curation and Mass Spectrometry Functions
13 stars 8 forks source link

trimBuiltSmiles should not be used for de-duplication #11

Closed adelenelai closed 4 years ago

adelenelai commented 4 years ago

trimBuiltSmiles() deduplicates a set of SMILES by comparing their molecular formulae via the helper function MolFormFromSmiles.rcdk.

However, some structural isomers get 'trimmed' in this way...and they shouldn't be.

Minimal example:

las_gensmiles <- "OS(=O)(=O)c1ccc(cc1)C([R1])[R2]"
r1ton <- "{C,C}"
nr1ton <- "{9-13}"
split <- splitRrange(las_gensmiles,nR1toN = nr1ton)  #"(5-7,4-6)"
las_series <- buildSmiles(las_gensmiles,R1toN = r1ton, nR1toN = split)

gives

las_series
[1] "OS(=O)(=O)c1ccc(cc1)C(CCCCC)CCCC"     "OS(=O)(=O)c1ccc(cc1)C(CCCCC)CCCCC"   
[3] "OS(=O)(=O)c1ccc(cc1)C(CCCCC)CCCCCC"   "OS(=O)(=O)c1ccc(cc1)C(CCCCCC)CCCC"   
[5] "OS(=O)(=O)c1ccc(cc1)C(CCCCCC)CCCCC"   "OS(=O)(=O)c1ccc(cc1)C(CCCCCC)CCCCCC" 
[7] "OS(=O)(=O)c1ccc(cc1)C(CCCCCCC)CCCC"   "OS(=O)(=O)c1ccc(cc1)C(CCCCCCC)CCCCC" 
[9] "OS(=O)(=O)c1ccc(cc1)C(CCCCCCC)CCCCCC"

corresponding to

sapply(las_series,MolFormFromSmiles.rcdk)
    OS(=O)(=O)c1ccc(cc1)C(CCCCC)CCCC    OS(=O)(=O)c1ccc(cc1)C(CCCCC)CCCCC 
                         "C16H26O3S"                          "C17H28O3S" 
  OS(=O)(=O)c1ccc(cc1)C(CCCCC)CCCCCC    OS(=O)(=O)c1ccc(cc1)C(CCCCCC)CCCC 
                         "C18H30O3S"                          "C17H28O3S" 
  OS(=O)(=O)c1ccc(cc1)C(CCCCCC)CCCCC  OS(=O)(=O)c1ccc(cc1)C(CCCCCC)CCCCCC 
                         "C18H30O3S"                          "C19H32O3S" 
  OS(=O)(=O)c1ccc(cc1)C(CCCCCCC)CCCC  OS(=O)(=O)c1ccc(cc1)C(CCCCCCC)CCCCC 
                         "C18H30O3S"                          "C19H32O3S" 
OS(=O)(=O)c1ccc(cc1)C(CCCCCCC)CCCCCC 
                         "C20H34O3S" 
trimBuiltSmiles(las_series)
[1] "OS(=O)(=O)c1ccc(cc1)C(CCCCC)CCCC"     "OS(=O)(=O)c1ccc(cc1)C(CCCCC)CCCCC"   
[3] "OS(=O)(=O)c1ccc(cc1)C(CCCCC)CCCCCC"   "OS(=O)(=O)c1ccc(cc1)C(CCCCCC)CCCCCC" 
[5] "OS(=O)(=O)c1ccc(cc1)C(CCCCCCC)CCCCCC"

where SMILES with R1,R2 as 6,5; 6,4; 7,4; and 7,5 are trimmed off. The latter 3 should not be trimmed as they are structurally different from 5,5; 5,6; and 6,6 resp. although having the same MF.

Ideally, should eliminate potential duplicates at earlier stage even before they are generated, somewhere within buildSmiles or splitRrange (?)

Alternatively, could deduplicate by comparing canonical smiles instead of comparing MFs. Probably faster than doing isomorphism check.

schymane commented 4 years ago

The function was designed to return only one example per formula (for mass spec screening, for instance, one only needs one representative structure per formula, which was the intended use case) - a parallel function could be added to trim by InChIKey if you need trimming that retains all structural isomers?

adelenelai commented 4 years ago

hmm...makes sense in the context of intended use-case.

Trimming by InChiKey requires lookup in Cactus/CTS? Concerned it will be slow.