pyCSRML 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pycsrml-0.1.0/.gitignore +181 -0
- pycsrml-0.1.0/CHANGELOG.md +18 -0
- pycsrml-0.1.0/LICENSE +21 -0
- pycsrml-0.1.0/PKG-INFO +276 -0
- pycsrml-0.1.0/README.md +204 -0
- pycsrml-0.1.0/pyCSRML/__init__.py +42 -0
- pycsrml-0.1.0/pyCSRML/_csrml.py +913 -0
- pycsrml-0.1.0/pyCSRML/convert_xml_to_json.py +152 -0
- pycsrml-0.1.0/pyCSRML/data/TxP_PFAS_v1.0.4.json +913 -0
- pycsrml-0.1.0/pyCSRML/data/TxP_PFAS_v1.0.4.xml +25529 -0
- pycsrml-0.1.0/pyCSRML/data/toxprint_V2.0_r711.json +5120 -0
- pycsrml-0.1.0/pyCSRML/data/toxprint_V2.0_r711.xml +165757 -0
- pycsrml-0.1.0/pyCSRML/embedding.py +813 -0
- pycsrml-0.1.0/pyCSRML/fingerprinter.py +401 -0
- pycsrml-0.1.0/pyproject.toml +141 -0
- pycsrml-0.1.0/tests/__init__.py +0 -0
- pycsrml-0.1.0/tests/_check_tsv_alignment.py +37 -0
- pycsrml-0.1.0/tests/concordance_report.md +107 -0
- pycsrml-0.1.0/tests/test_chemotyper_concordance.py +565 -0
- pycsrml-0.1.0/tests/test_smoke.py +175 -0
pycsrml-0.1.0/.gitignore
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py,cover
|
|
50
|
+
.hypothesis/
|
|
51
|
+
.pytest_cache/
|
|
52
|
+
cover/
|
|
53
|
+
|
|
54
|
+
# Translations
|
|
55
|
+
*.mo
|
|
56
|
+
*.pot
|
|
57
|
+
|
|
58
|
+
# Django stuff:
|
|
59
|
+
*.log
|
|
60
|
+
local_settings.py
|
|
61
|
+
db.sqlite3
|
|
62
|
+
db.sqlite3-journal
|
|
63
|
+
|
|
64
|
+
# Flask stuff:
|
|
65
|
+
instance/
|
|
66
|
+
.webassets-cache
|
|
67
|
+
|
|
68
|
+
# Scrapy stuff:
|
|
69
|
+
.scrapy
|
|
70
|
+
|
|
71
|
+
# Sphinx documentation
|
|
72
|
+
docs/_build/
|
|
73
|
+
|
|
74
|
+
# PyBuilder
|
|
75
|
+
.pybuilder/
|
|
76
|
+
target/
|
|
77
|
+
|
|
78
|
+
# Jupyter Notebook
|
|
79
|
+
.ipynb_checkpoints
|
|
80
|
+
|
|
81
|
+
# IPython
|
|
82
|
+
profile_default/
|
|
83
|
+
ipython_config.py
|
|
84
|
+
|
|
85
|
+
# pyenv
|
|
86
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
87
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
88
|
+
# .python-version
|
|
89
|
+
|
|
90
|
+
# pipenv
|
|
91
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
92
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
93
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
94
|
+
# install all needed dependencies.
|
|
95
|
+
#Pipfile.lock
|
|
96
|
+
|
|
97
|
+
# UV
|
|
98
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
99
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
100
|
+
# commonly ignored for libraries.
|
|
101
|
+
#uv.lock
|
|
102
|
+
|
|
103
|
+
# poetry
|
|
104
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
105
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
106
|
+
# commonly ignored for libraries.
|
|
107
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
108
|
+
#poetry.lock
|
|
109
|
+
|
|
110
|
+
# pdm
|
|
111
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
112
|
+
#pdm.lock
|
|
113
|
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
|
114
|
+
# in version control.
|
|
115
|
+
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
|
|
116
|
+
.pdm.toml
|
|
117
|
+
.pdm-python
|
|
118
|
+
.pdm-build/
|
|
119
|
+
|
|
120
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
121
|
+
__pypackages__/
|
|
122
|
+
|
|
123
|
+
# Celery stuff
|
|
124
|
+
celerybeat-schedule
|
|
125
|
+
celerybeat.pid
|
|
126
|
+
|
|
127
|
+
# SageMath parsed files
|
|
128
|
+
*.sage.py
|
|
129
|
+
|
|
130
|
+
# Environments
|
|
131
|
+
.env
|
|
132
|
+
.venv
|
|
133
|
+
env/
|
|
134
|
+
venv/
|
|
135
|
+
ENV/
|
|
136
|
+
env.bak/
|
|
137
|
+
venv.bak/
|
|
138
|
+
|
|
139
|
+
# Spyder project settings
|
|
140
|
+
.spyderproject
|
|
141
|
+
.spyproject
|
|
142
|
+
|
|
143
|
+
# Rope project settings
|
|
144
|
+
.ropeproject
|
|
145
|
+
|
|
146
|
+
# mkdocs documentation
|
|
147
|
+
/site
|
|
148
|
+
|
|
149
|
+
# mypy
|
|
150
|
+
.mypy_cache/
|
|
151
|
+
.dmypy.json
|
|
152
|
+
dmypy.json
|
|
153
|
+
|
|
154
|
+
# Pyre type checker
|
|
155
|
+
.pyre/
|
|
156
|
+
|
|
157
|
+
# pytype static type analyzer
|
|
158
|
+
.pytype/
|
|
159
|
+
|
|
160
|
+
# Cython debug symbols
|
|
161
|
+
cython_debug/
|
|
162
|
+
|
|
163
|
+
# PyCharm
|
|
164
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
165
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
166
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
167
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
168
|
+
#.idea/
|
|
169
|
+
|
|
170
|
+
# Ruff stuff:
|
|
171
|
+
.ruff_cache/
|
|
172
|
+
|
|
173
|
+
# PyPI configuration file
|
|
174
|
+
.pypirc
|
|
175
|
+
|
|
176
|
+
# Cursor
|
|
177
|
+
# Cursor is an AI-powered code editor.`.cursorignore` specifies files/directories to
|
|
178
|
+
# exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
|
|
179
|
+
# refer to https://docs.cursor.com/context/ignore-files
|
|
180
|
+
.cursorignore
|
|
181
|
+
.cursorindexingignore
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
## [0.1.0] — 2026-03-20
|
|
6
|
+
|
|
7
|
+
Initial public release.
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
- Parse CSRML XML (ToxPrint v2 and TxP_PFAS v1) to SMARTS
|
|
11
|
+
- Bundled fingerprint definitions: ToxPrint v2.0 (729 bits), TxP_PFAS v1.0.4 (129 bits)
|
|
12
|
+
- `PFASFingerprinter` and `ToxPrintFingerprinter` classes using RDKit
|
|
13
|
+
- `Embedding` and `EmbeddingSet` containers for multi-compound analysis
|
|
14
|
+
- Full support for all key CSRML atom features (pseudo-elements G/Z/Q/X, negated atomList,
|
|
15
|
+
H-count ranges, combineAtomFeatures OR-of-AND trees, matchingQueryAtom folding,
|
|
16
|
+
atomHeteroAttachedCount via recursive SMARTS)
|
|
17
|
+
- JSON and YAML input support in `Fingerprinter` (in addition to XML)
|
|
18
|
+
- 99.4 % concordance with ChemoTyper reference (Richard *et al.*, 2023); all 129 bits now ≥ 90 % accuracy
|
pycsrml-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Luc Miaz
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
pycsrml-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pyCSRML
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python implementation of CSRML chemotype fingerprints (ToxPrint v2 and TxP_PFAS v1)
|
|
5
|
+
Project-URL: Homepage, https://github.com/luc-miaz/pyCSRML
|
|
6
|
+
Project-URL: Documentation, https://pycsrml.readthedocs.io
|
|
7
|
+
Project-URL: Repository, https://github.com/luc-miaz/pyCSRML
|
|
8
|
+
Project-URL: Bug Tracker, https://github.com/luc-miaz/pyCSRML/issues
|
|
9
|
+
Project-URL: Changelog, https://github.com/luc-miaz/pyCSRML/blob/main/CHANGELOG.md
|
|
10
|
+
Author: Luc Miaz
|
|
11
|
+
License: MIT License
|
|
12
|
+
|
|
13
|
+
Copyright (c) 2026 Luc Miaz
|
|
14
|
+
|
|
15
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
16
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
17
|
+
in the Software without restriction, including without limitation the rights
|
|
18
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
19
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
20
|
+
furnished to do so, subject to the following conditions:
|
|
21
|
+
|
|
22
|
+
The above copyright notice and this permission notice shall be included in all
|
|
23
|
+
copies or substantial portions of the Software.
|
|
24
|
+
|
|
25
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
26
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
27
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
28
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
29
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
30
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
31
|
+
SOFTWARE.
|
|
32
|
+
License-File: LICENSE
|
|
33
|
+
Keywords: CSRML,PFAS,RDKit,SMARTS,ToxPrint,cheminformatics,chemotype,fingerprint
|
|
34
|
+
Classifier: Development Status :: 3 - Alpha
|
|
35
|
+
Classifier: Intended Audience :: Science/Research
|
|
36
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
37
|
+
Classifier: Operating System :: OS Independent
|
|
38
|
+
Classifier: Programming Language :: Python :: 3
|
|
39
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
40
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
41
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
42
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
43
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
44
|
+
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
|
|
45
|
+
Classifier: Topic :: Scientific/Engineering :: Chemistry
|
|
46
|
+
Requires-Python: >=3.10
|
|
47
|
+
Requires-Dist: numpy>=1.23
|
|
48
|
+
Requires-Dist: rdkit>=2022.3
|
|
49
|
+
Provides-Extra: analysis
|
|
50
|
+
Requires-Dist: matplotlib>=3.6; extra == 'analysis'
|
|
51
|
+
Requires-Dist: pandas>=1.5; extra == 'analysis'
|
|
52
|
+
Provides-Extra: dev
|
|
53
|
+
Requires-Dist: matplotlib>=3.6; extra == 'dev'
|
|
54
|
+
Requires-Dist: myst-parser; extra == 'dev'
|
|
55
|
+
Requires-Dist: pandas>=1.5; extra == 'dev'
|
|
56
|
+
Requires-Dist: pylint>=3; extra == 'dev'
|
|
57
|
+
Requires-Dist: pytest-cov; extra == 'dev'
|
|
58
|
+
Requires-Dist: pytest>=7; extra == 'dev'
|
|
59
|
+
Requires-Dist: sphinx-autodoc-typehints; extra == 'dev'
|
|
60
|
+
Requires-Dist: sphinx-rtd-theme>=2; extra == 'dev'
|
|
61
|
+
Requires-Dist: sphinx>=7; extra == 'dev'
|
|
62
|
+
Provides-Extra: full
|
|
63
|
+
Requires-Dist: matplotlib>=3.6; extra == 'full'
|
|
64
|
+
Requires-Dist: pandas>=1.5; extra == 'full'
|
|
65
|
+
Requires-Dist: pyyaml>=6; extra == 'full'
|
|
66
|
+
Requires-Dist: umap-learn>=0.5; extra == 'full'
|
|
67
|
+
Provides-Extra: umap
|
|
68
|
+
Requires-Dist: umap-learn>=0.5; extra == 'umap'
|
|
69
|
+
Provides-Extra: yaml
|
|
70
|
+
Requires-Dist: pyyaml>=6; extra == 'yaml'
|
|
71
|
+
Description-Content-Type: text/markdown
|
|
72
|
+
|
|
73
|
+
# pyCSRML
|
|
74
|
+
|
|
75
|
+
[](https://github.com/luc-miaz/pyCSRML/actions/workflows/ci.yml)
|
|
76
|
+
[](https://pypi.org/project/pyCSRML/)
|
|
77
|
+
[](https://pypi.org/project/pyCSRML/)
|
|
78
|
+
[](LICENSE)
|
|
79
|
+
[](https://pycsrml.readthedocs.io)
|
|
80
|
+
|
|
81
|
+
**pyCSRML** is a pure-Python re-implementation of the
|
|
82
|
+
[Chemical Subgraph Representation Markup Language (CSRML)](https://www.molecular-networks.com/products/chemotyper).
|
|
83
|
+
It parses CSRML XML files, converts the subgraph patterns to SMARTS, and computes
|
|
84
|
+
binary chemotype fingerprints for molecules using [RDKit](https://www.rdkit.org/).
|
|
85
|
+
|
|
86
|
+
The module is not an exact replicate of the original CSRML (see [performance section](#performance)). the original software should be preferred.
|
|
87
|
+
|
|
88
|
+
The module was implemented from two fingerprints descriptions:
|
|
89
|
+
|
|
90
|
+
| Fingerprint | Bits | Description | Sourcde |
|
|
91
|
+
|---|---|---|----|
|
|
92
|
+
| **ToxPrint v2.0** | 729 | General toxicologically relevant substructures | Yang *et al.* 2015 |
|
|
93
|
+
| **TxP_PFAS v1.0** | 129 | Per- and polyfluoroalkyl substance (PFAS) chemotypes | Richard *et al.* 2023
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
## Performance
|
|
98
|
+
|
|
99
|
+
Accuracy is measured by comparing pyCSRML bit vectors against the reference
|
|
100
|
+
[ChemoTyper](https://www.molecular-networks.com/products/chemotyper) tool output.
|
|
101
|
+
Run `pytest tests/test_chemotyper_concordance.py -v -s` to reproduce; the full
|
|
102
|
+
per-bit breakdown is written to `tests/concordance_report.md`.
|
|
103
|
+
|
|
104
|
+
| Dataset | Compounds | Fingerprint | Overall accuracy | Bits ≥ 90 % acc |
|
|
105
|
+
|---|---|---|---|---|
|
|
106
|
+
| Richard *et al.* 2023 (PFAS set) | 14 710 | TxP_PFAS v1 | **99.4 %** | — |
|
|
107
|
+
| ToxCast (full) | 9 014 | ToxPrint v2 | **98.17 %** | 711 / 729 |
|
|
108
|
+
| ToxCast (CF-containing subset) | 808 | TxP_PFAS v1 | **99.98 %** | 129 / 129 |
|
|
109
|
+
|
|
110
|
+
> **Reading the table:** "CF-containing subset" means only the 808 ToxCast compounds
|
|
111
|
+
> for which ChemoTyper sets at least one TxP_PFAS bit — the meaningful subset for
|
|
112
|
+
> PFAS accuracy benchmarking. Full-dataset TxP_PFAS accuracy appears inflated (100 %)
|
|
113
|
+
> because the vast majority of compounds are all-zero for every PFAS bit.
|
|
114
|
+
|
|
115
|
+
### Known discrepancies
|
|
116
|
+
|
|
117
|
+
The 18 bits below 90 % accuracy in ToxPrint v2 are all in the metal / inorganic
|
|
118
|
+
chemotype groups; TxP_PFAS v1 has 4 bits below 100 % (all above 98.9 %).
|
|
119
|
+
Root causes (see `tests/_check_tsv_alignment.py` and `tests/concordance_report.md`):
|
|
120
|
+
|
|
121
|
+
| Bit / category | Fingerprint | Accuracy | Direction | Root cause |
|
|
122
|
+
|---|---|---|---|---|
|
|
123
|
+
| `atom:element_noble_gas` | ToxPrint | 0.0 % | False positives | Noble-gas SMARTS approximated as `[*]` — matches every atom |
|
|
124
|
+
| `atom:element_metal_group_III`, `atom:element_metal_poor_metal`, etc. | ToxPrint | 0.1 – 5 % | False positives | Metal / metalloid element-group patterns use G/Q pseudo-elements that are approximated as `[*]`, causing widespread false positives |
|
|
125
|
+
| `ring:hetero_[6]_N_tetrazine_generic`, `ring:hetero_[6]_N_triazine_generic` | ToxPrint | 30 – 32 % | False positives | Nitrogen-count constraints in 6-membered heteroaromatic rings use atom-count SMARTS that over-match similar rings |
|
|
126
|
+
| `pfas_chain:alkeneLinear_mono-ene_ethylene_generic_F` | TxP_PFAS | 98.9 % | False negatives (recall 40 %) | RDKit perceives the C=C of tautomeric fluoropyrimidines (5-fluorouracil) as aromatic; the SMARTS `[#9]-[#6;A]=[#6;A]` requires aliphatic atoms and misses them |
|
|
127
|
+
| `pfas_bond:C=N_imine_FCN` | TxP_PFAS | 99.5 % | False negatives (recall 33 %) | Same aromaticity issue: the C=N bond in fluorinated heterocycles is perceived as aromatic by RDKit, so the aliphatic imine SMARTS does not match |
|
|
128
|
+
| `pfas_bond:aromatic_FCc1c` | TxP_PFAS | 99.5 % | Slight false positives (precision 97.2 %) | Aromatic F-C pattern slightly over-matches due to SMARTS approximation of the exception clause |
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
## Installation
|
|
133
|
+
|
|
134
|
+
The module needs RDKit installed. If necessary, start by installing a environment manager first (e.g. Conda/Mamba, like [Miniforge3](https://github.com/conda-forge/miniforge)) and creating an environment, e.g.:
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
mamba create -n rdkit pytho
|
|
138
|
+
mamba activate rdkit
|
|
139
|
+
mamba install -y -c rdkit rdkit
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Then install pyCSRML via PyPI:
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
pip install pyCSRML
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
## Quick start
|
|
152
|
+
|
|
153
|
+
### Single molecule
|
|
154
|
+
|
|
155
|
+
```python
|
|
156
|
+
from pyCSRML import PFASFingerprinter
|
|
157
|
+
from rdkit import Chem
|
|
158
|
+
|
|
159
|
+
fp = PFASFingerprinter()
|
|
160
|
+
|
|
161
|
+
mol = Chem.MolFromSmiles("FC(F)(F)C(F)(F)C(F)(F)C(F)(F)C(F)(F)C(F)(F)C(F)(F)C(=O)O") # PFOA
|
|
162
|
+
arr, names = fp.fingerprint(mol)
|
|
163
|
+
|
|
164
|
+
print(f"Bits set: {arr.sum()} / {fp.n_bits}")
|
|
165
|
+
on_bits = [names[i] for i in range(len(arr)) if arr[i]]
|
|
166
|
+
print(on_bits[:5])
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### Multiple molecules with analysis
|
|
170
|
+
|
|
171
|
+
```python
|
|
172
|
+
from pyCSRML import PFASFingerprinter, from_fingerprinter
|
|
173
|
+
|
|
174
|
+
fp = PFASFingerprinter()
|
|
175
|
+
|
|
176
|
+
smiles = [
|
|
177
|
+
"FC(F)(F)C(F)(F)C(F)(F)C(F)(F)C(F)(F)C(F)(F)C(F)(F)C(=O)O", # PFOA
|
|
178
|
+
"FC(F)(F)C(F)(F)C(F)(F)C(F)(F)C(F)(F)C(F)(F)C(F)(F)C(F)(F)S(=O)(=O)O", # PFOS
|
|
179
|
+
"FCCCF", # simple difluoro
|
|
180
|
+
"CCO", # negative control
|
|
181
|
+
]
|
|
182
|
+
|
|
183
|
+
eset = from_fingerprinter(fp, smiles_list=smiles, names=["PFOA", "PFOS", "4F-propane", "EtOH"])
|
|
184
|
+
eset.plot(kind="heatmap")
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### ToxPrint fingerprints (729 bits)
|
|
188
|
+
|
|
189
|
+
```python
|
|
190
|
+
from pyCSRML import ToxPrintFingerprinter
|
|
191
|
+
from rdkit import Chem
|
|
192
|
+
|
|
193
|
+
fp = ToxPrintFingerprinter()
|
|
194
|
+
mol = Chem.MolFromSmiles("c1ccccc1")
|
|
195
|
+
arr, names = fp.fingerprint(mol)
|
|
196
|
+
print(f"Benzene: {arr.sum()} bits set")
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### Low-level CSRML parsing
|
|
200
|
+
|
|
201
|
+
```python
|
|
202
|
+
from pyCSRML._csrml import parse_csrml_xml, ordered_bit_list
|
|
203
|
+
|
|
204
|
+
data = parse_csrml_xml("path/to/my_fingerprints.xml")
|
|
205
|
+
bits = ordered_bit_list(data)
|
|
206
|
+
for bit in bits[:3]:
|
|
207
|
+
print(bit["id"], bit["smarts"])
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
---
|
|
211
|
+
|
|
212
|
+
## API overview
|
|
213
|
+
|
|
214
|
+
| Class / function | Module | Description |
|
|
215
|
+
|---|---|---|
|
|
216
|
+
| `PFASFingerprinter` | `pyCSRML` | 129-bit TxP_PFAS fingerprinter |
|
|
217
|
+
| `ToxPrintFingerprinter` | `pyCSRML` | 729-bit ToxPrint v2 fingerprinter |
|
|
218
|
+
| `Fingerprinter` | `pyCSRML` | Base class; load any CSRML XML or JSON |
|
|
219
|
+
| `Embedding` | `pyCSRML` | Single-compound fingerprint container with metadata |
|
|
220
|
+
| `EmbeddingSet` | `pyCSRML` | Multi-compound container with heatmap / UMAP / clustering |
|
|
221
|
+
| `from_fingerprinter` | `pyCSRML` | Convenience factory: list of SMILES → `EmbeddingSet` |
|
|
222
|
+
| `parse_csrml_xml` | `pyCSRML._csrml` | Parse raw CSRML XML → Python dict |
|
|
223
|
+
| `ordered_bit_list` | `pyCSRML._csrml` | Return all bits in order from a parsed dict |
|
|
224
|
+
|
|
225
|
+
Full API reference: **[pycsrml.readthedocs.io](https://pycsrml.readthedocs.io)**
|
|
226
|
+
|
|
227
|
+
---
|
|
228
|
+
|
|
229
|
+
## CSRML features supported
|
|
230
|
+
|
|
231
|
+
| Feature | Status |
|
|
232
|
+
|---|---|
|
|
233
|
+
| `substructureMatch` → SMARTS | ✅ Full |
|
|
234
|
+
| `substructureException` (global) | ✅ Full |
|
|
235
|
+
| `matchingQueryAtom` → `[!$(...)]` folding | ✅ Full |
|
|
236
|
+
| `combineAtomFeatures` (OR-of-AND trees) | ✅ Full |
|
|
237
|
+
| `atomList` with `negate="true"` | ✅ Full |
|
|
238
|
+
| `attachedHydrogenCount` ranges | ✅ Full |
|
|
239
|
+
| `ringCountAtom` / `ringAtom` / `chainAtom` | ✅ Full |
|
|
240
|
+
| Pseudo-elements G, Z, Q, X | ✅ Full |
|
|
241
|
+
| `mustMatch` / `mustNotMatch` (test cases) | parsed, not used for matching |
|
|
242
|
+
|
|
243
|
+
---
|
|
244
|
+
|
|
245
|
+
## Development
|
|
246
|
+
|
|
247
|
+
```bash
|
|
248
|
+
git clone https://github.com/luc-miaz/pyCSRML
|
|
249
|
+
cd pyCSRML
|
|
250
|
+
pip install -e ".[dev]"
|
|
251
|
+
|
|
252
|
+
# Run tests (fast)
|
|
253
|
+
pytest -m "not slow"
|
|
254
|
+
|
|
255
|
+
# Run concordance test (~45 s)
|
|
256
|
+
pytest tests/test_chemotyper_concordance.py -v -s
|
|
257
|
+
|
|
258
|
+
# Pylint
|
|
259
|
+
pylint pyCSRML/
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
---
|
|
263
|
+
|
|
264
|
+
## Citation
|
|
265
|
+
|
|
266
|
+
If you use pyCSRML in academic work, please cite the original ToxPrint / ChemoTyper paper and the TxP_PFAS reference:
|
|
267
|
+
|
|
268
|
+
- Yang, C., *et al.* (2015). New publicly available chemical query language, CSRML, to support chemotype representations for application to data mining and modelling. *J. Chem. Inf. Model.* **55**, 510–528.
|
|
269
|
+
- Richard, A.M., *et al.* (2023). ToxPrint chemotypes and ChemoTyper portal. *Chem. Res. Toxicol.* **36**, 488–510.
|
|
270
|
+
|
|
271
|
+
---
|
|
272
|
+
|
|
273
|
+
## License
|
|
274
|
+
|
|
275
|
+
MIT © 2026 Luc Miaz
|
|
276
|
+
|
pycsrml-0.1.0/README.md
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
# pyCSRML
|
|
2
|
+
|
|
3
|
+
[](https://github.com/luc-miaz/pyCSRML/actions/workflows/ci.yml)
|
|
4
|
+
[](https://pypi.org/project/pyCSRML/)
|
|
5
|
+
[](https://pypi.org/project/pyCSRML/)
|
|
6
|
+
[](LICENSE)
|
|
7
|
+
[](https://pycsrml.readthedocs.io)
|
|
8
|
+
|
|
9
|
+
**pyCSRML** is a pure-Python re-implementation of the
|
|
10
|
+
[Chemical Subgraph Representation Markup Language (CSRML)](https://www.molecular-networks.com/products/chemotyper).
|
|
11
|
+
It parses CSRML XML files, converts the subgraph patterns to SMARTS, and computes
|
|
12
|
+
binary chemotype fingerprints for molecules using [RDKit](https://www.rdkit.org/).
|
|
13
|
+
|
|
14
|
+
The module is not an exact replicate of the original CSRML (see [performance section](#performance)). the original software should be preferred.
|
|
15
|
+
|
|
16
|
+
The module was implemented from two fingerprints descriptions:
|
|
17
|
+
|
|
18
|
+
| Fingerprint | Bits | Description | Sourcde |
|
|
19
|
+
|---|---|---|----|
|
|
20
|
+
| **ToxPrint v2.0** | 729 | General toxicologically relevant substructures | Yang *et al.* 2015 |
|
|
21
|
+
| **TxP_PFAS v1.0** | 129 | Per- and polyfluoroalkyl substance (PFAS) chemotypes | Richard *et al.* 2023
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
## Performance
|
|
26
|
+
|
|
27
|
+
Accuracy is measured by comparing pyCSRML bit vectors against the reference
|
|
28
|
+
[ChemoTyper](https://www.molecular-networks.com/products/chemotyper) tool output.
|
|
29
|
+
Run `pytest tests/test_chemotyper_concordance.py -v -s` to reproduce; the full
|
|
30
|
+
per-bit breakdown is written to `tests/concordance_report.md`.
|
|
31
|
+
|
|
32
|
+
| Dataset | Compounds | Fingerprint | Overall accuracy | Bits ≥ 90 % acc |
|
|
33
|
+
|---|---|---|---|---|
|
|
34
|
+
| Richard *et al.* 2023 (PFAS set) | 14 710 | TxP_PFAS v1 | **99.4 %** | — |
|
|
35
|
+
| ToxCast (full) | 9 014 | ToxPrint v2 | **98.17 %** | 711 / 729 |
|
|
36
|
+
| ToxCast (CF-containing subset) | 808 | TxP_PFAS v1 | **99.98 %** | 129 / 129 |
|
|
37
|
+
|
|
38
|
+
> **Reading the table:** "CF-containing subset" means only the 808 ToxCast compounds
|
|
39
|
+
> for which ChemoTyper sets at least one TxP_PFAS bit — the meaningful subset for
|
|
40
|
+
> PFAS accuracy benchmarking. Full-dataset TxP_PFAS accuracy appears inflated (100 %)
|
|
41
|
+
> because the vast majority of compounds are all-zero for every PFAS bit.
|
|
42
|
+
|
|
43
|
+
### Known discrepancies
|
|
44
|
+
|
|
45
|
+
The 18 bits below 90 % accuracy in ToxPrint v2 are all in the metal / inorganic
|
|
46
|
+
chemotype groups; TxP_PFAS v1 has 4 bits below 100 % (all above 98.9 %).
|
|
47
|
+
Root causes (see `tests/_check_tsv_alignment.py` and `tests/concordance_report.md`):
|
|
48
|
+
|
|
49
|
+
| Bit / category | Fingerprint | Accuracy | Direction | Root cause |
|
|
50
|
+
|---|---|---|---|---|
|
|
51
|
+
| `atom:element_noble_gas` | ToxPrint | 0.0 % | False positives | Noble-gas SMARTS approximated as `[*]` — matches every atom |
|
|
52
|
+
| `atom:element_metal_group_III`, `atom:element_metal_poor_metal`, etc. | ToxPrint | 0.1 – 5 % | False positives | Metal / metalloid element-group patterns use G/Q pseudo-elements that are approximated as `[*]`, causing widespread false positives |
|
|
53
|
+
| `ring:hetero_[6]_N_tetrazine_generic`, `ring:hetero_[6]_N_triazine_generic` | ToxPrint | 30 – 32 % | False positives | Nitrogen-count constraints in 6-membered heteroaromatic rings use atom-count SMARTS that over-match similar rings |
|
|
54
|
+
| `pfas_chain:alkeneLinear_mono-ene_ethylene_generic_F` | TxP_PFAS | 98.9 % | False negatives (recall 40 %) | RDKit perceives the C=C of tautomeric fluoropyrimidines (5-fluorouracil) as aromatic; the SMARTS `[#9]-[#6;A]=[#6;A]` requires aliphatic atoms and misses them |
|
|
55
|
+
| `pfas_bond:C=N_imine_FCN` | TxP_PFAS | 99.5 % | False negatives (recall 33 %) | Same aromaticity issue: the C=N bond in fluorinated heterocycles is perceived as aromatic by RDKit, so the aliphatic imine SMARTS does not match |
|
|
56
|
+
| `pfas_bond:aromatic_FCc1c` | TxP_PFAS | 99.5 % | Slight false positives (precision 97.2 %) | Aromatic F-C pattern slightly over-matches due to SMARTS approximation of the exception clause |
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## Installation
|
|
61
|
+
|
|
62
|
+
The module needs RDKit installed. If necessary, start by installing a environment manager first (e.g. Conda/Mamba, like [Miniforge3](https://github.com/conda-forge/miniforge)) and creating an environment, e.g.:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
mamba create -n rdkit pytho
|
|
66
|
+
mamba activate rdkit
|
|
67
|
+
mamba install -y -c rdkit rdkit
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Then install pyCSRML via PyPI:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
pip install pyCSRML
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
## Quick start
|
|
80
|
+
|
|
81
|
+
### Single molecule
|
|
82
|
+
|
|
83
|
+
```python
|
|
84
|
+
from pyCSRML import PFASFingerprinter
|
|
85
|
+
from rdkit import Chem
|
|
86
|
+
|
|
87
|
+
fp = PFASFingerprinter()
|
|
88
|
+
|
|
89
|
+
mol = Chem.MolFromSmiles("FC(F)(F)C(F)(F)C(F)(F)C(F)(F)C(F)(F)C(F)(F)C(F)(F)C(=O)O") # PFOA
|
|
90
|
+
arr, names = fp.fingerprint(mol)
|
|
91
|
+
|
|
92
|
+
print(f"Bits set: {arr.sum()} / {fp.n_bits}")
|
|
93
|
+
on_bits = [names[i] for i in range(len(arr)) if arr[i]]
|
|
94
|
+
print(on_bits[:5])
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Multiple molecules with analysis
|
|
98
|
+
|
|
99
|
+
```python
|
|
100
|
+
from pyCSRML import PFASFingerprinter, from_fingerprinter
|
|
101
|
+
|
|
102
|
+
fp = PFASFingerprinter()
|
|
103
|
+
|
|
104
|
+
smiles = [
|
|
105
|
+
"FC(F)(F)C(F)(F)C(F)(F)C(F)(F)C(F)(F)C(F)(F)C(F)(F)C(=O)O", # PFOA
|
|
106
|
+
"FC(F)(F)C(F)(F)C(F)(F)C(F)(F)C(F)(F)C(F)(F)C(F)(F)C(F)(F)S(=O)(=O)O", # PFOS
|
|
107
|
+
"FCCCF", # simple difluoro
|
|
108
|
+
"CCO", # negative control
|
|
109
|
+
]
|
|
110
|
+
|
|
111
|
+
eset = from_fingerprinter(fp, smiles_list=smiles, names=["PFOA", "PFOS", "4F-propane", "EtOH"])
|
|
112
|
+
eset.plot(kind="heatmap")
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### ToxPrint fingerprints (729 bits)
|
|
116
|
+
|
|
117
|
+
```python
|
|
118
|
+
from pyCSRML import ToxPrintFingerprinter
|
|
119
|
+
from rdkit import Chem
|
|
120
|
+
|
|
121
|
+
fp = ToxPrintFingerprinter()
|
|
122
|
+
mol = Chem.MolFromSmiles("c1ccccc1")
|
|
123
|
+
arr, names = fp.fingerprint(mol)
|
|
124
|
+
print(f"Benzene: {arr.sum()} bits set")
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Low-level CSRML parsing
|
|
128
|
+
|
|
129
|
+
```python
|
|
130
|
+
from pyCSRML._csrml import parse_csrml_xml, ordered_bit_list
|
|
131
|
+
|
|
132
|
+
data = parse_csrml_xml("path/to/my_fingerprints.xml")
|
|
133
|
+
bits = ordered_bit_list(data)
|
|
134
|
+
for bit in bits[:3]:
|
|
135
|
+
print(bit["id"], bit["smarts"])
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
---
|
|
139
|
+
|
|
140
|
+
## API overview
|
|
141
|
+
|
|
142
|
+
| Class / function | Module | Description |
|
|
143
|
+
|---|---|---|
|
|
144
|
+
| `PFASFingerprinter` | `pyCSRML` | 129-bit TxP_PFAS fingerprinter |
|
|
145
|
+
| `ToxPrintFingerprinter` | `pyCSRML` | 729-bit ToxPrint v2 fingerprinter |
|
|
146
|
+
| `Fingerprinter` | `pyCSRML` | Base class; load any CSRML XML or JSON |
|
|
147
|
+
| `Embedding` | `pyCSRML` | Single-compound fingerprint container with metadata |
|
|
148
|
+
| `EmbeddingSet` | `pyCSRML` | Multi-compound container with heatmap / UMAP / clustering |
|
|
149
|
+
| `from_fingerprinter` | `pyCSRML` | Convenience factory: list of SMILES → `EmbeddingSet` |
|
|
150
|
+
| `parse_csrml_xml` | `pyCSRML._csrml` | Parse raw CSRML XML → Python dict |
|
|
151
|
+
| `ordered_bit_list` | `pyCSRML._csrml` | Return all bits in order from a parsed dict |
|
|
152
|
+
|
|
153
|
+
Full API reference: **[pycsrml.readthedocs.io](https://pycsrml.readthedocs.io)**
|
|
154
|
+
|
|
155
|
+
---
|
|
156
|
+
|
|
157
|
+
## CSRML features supported
|
|
158
|
+
|
|
159
|
+
| Feature | Status |
|
|
160
|
+
|---|---|
|
|
161
|
+
| `substructureMatch` → SMARTS | ✅ Full |
|
|
162
|
+
| `substructureException` (global) | ✅ Full |
|
|
163
|
+
| `matchingQueryAtom` → `[!$(...)]` folding | ✅ Full |
|
|
164
|
+
| `combineAtomFeatures` (OR-of-AND trees) | ✅ Full |
|
|
165
|
+
| `atomList` with `negate="true"` | ✅ Full |
|
|
166
|
+
| `attachedHydrogenCount` ranges | ✅ Full |
|
|
167
|
+
| `ringCountAtom` / `ringAtom` / `chainAtom` | ✅ Full |
|
|
168
|
+
| Pseudo-elements G, Z, Q, X | ✅ Full |
|
|
169
|
+
| `mustMatch` / `mustNotMatch` (test cases) | parsed, not used for matching |
|
|
170
|
+
|
|
171
|
+
---
|
|
172
|
+
|
|
173
|
+
## Development
|
|
174
|
+
|
|
175
|
+
```bash
|
|
176
|
+
git clone https://github.com/luc-miaz/pyCSRML
|
|
177
|
+
cd pyCSRML
|
|
178
|
+
pip install -e ".[dev]"
|
|
179
|
+
|
|
180
|
+
# Run tests (fast)
|
|
181
|
+
pytest -m "not slow"
|
|
182
|
+
|
|
183
|
+
# Run concordance test (~45 s)
|
|
184
|
+
pytest tests/test_chemotyper_concordance.py -v -s
|
|
185
|
+
|
|
186
|
+
# Pylint
|
|
187
|
+
pylint pyCSRML/
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
---
|
|
191
|
+
|
|
192
|
+
## Citation
|
|
193
|
+
|
|
194
|
+
If you use pyCSRML in academic work, please cite the original ToxPrint / ChemoTyper paper and the TxP_PFAS reference:
|
|
195
|
+
|
|
196
|
+
- Yang, C., *et al.* (2015). New publicly available chemical query language, CSRML, to support chemotype representations for application to data mining and modelling. *J. Chem. Inf. Model.* **55**, 510–528.
|
|
197
|
+
- Richard, A.M., *et al.* (2023). ToxPrint chemotypes and ChemoTyper portal. *Chem. Res. Toxicol.* **36**, 488–510.
|
|
198
|
+
|
|
199
|
+
---
|
|
200
|
+
|
|
201
|
+
## License
|
|
202
|
+
|
|
203
|
+
MIT © 2026 Luc Miaz
|
|
204
|
+
|