|
8 | 8 | from __future__ import annotations |
9 | 9 |
|
10 | 10 | from functools import partial |
11 | | -import math |
12 | 11 | from pathlib import Path |
13 | 12 | import re |
14 | 13 |
|
|
19 | 18 | ChemicalEntity, |
20 | 19 | DirectionQualifierEnum, |
21 | 20 | Gene, |
22 | | - GeneFamily, |
| 21 | + ProteinFamily, |
23 | 22 | MacromolecularComplex, |
24 | 23 | MolecularActivity, |
25 | 24 | MolecularEntity, |
26 | 25 | NamedThing, |
27 | 26 | NucleicAcidEntity, |
28 | 27 | OrganismTaxon, |
29 | 28 | Protein, |
30 | | - QuantityValue, |
31 | 29 | RNAProduct, |
32 | 30 | slots, |
33 | 31 | ) |
34 | | -from omnipath_core.measurements import Measurement |
35 | 32 | from omnipath_core.naming import Namespace |
36 | 33 |
|
| 34 | +from pypath.inputs_v2._measurements import measurement as _measurement |
37 | 35 | from pypath.inputs_v2.base import Dataset, Download, Resource, ResourceConfig |
38 | 36 | from pypath.inputs_v2.parsers.chembl import ( |
39 | 37 | activities_parser, |
|
54 | 52 | from pypath.share import cache |
55 | 53 |
|
56 | 54 |
|
57 | | -def _measurement(value, unit=None, source_field=None, comparator=None): |
58 | | - """Keep numeric source observations, units and comparison bounds together.""" |
59 | | - if value is None: |
60 | | - return None |
61 | | - match = re.fullmatch( |
62 | | - '\\s*(<=|>=|<|>|=|~)?\\s*([+-]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(?:[eE][+-]?\\d+)?)\\s*', |
63 | | - str(value), |
64 | | - ) |
65 | | - if match is None: |
66 | | - return None |
67 | | - original_comparator = comparator or match.group(1) |
68 | | - if original_comparator not in {None, '<', '>', '=', '<=', '>=', '~', '≈'}: |
69 | | - return None |
70 | | - relation = {'<': 'less_than', '>': 'greater_than', '=': 'equal_to'}.get( |
71 | | - original_comparator |
72 | | - ) |
73 | | - number = float(match.group(2)) |
74 | | - if not math.isfinite(number): |
75 | | - return None |
76 | | - quantity = QuantityValue( |
77 | | - has_numeric_value=number, |
78 | | - has_unit=unit or None, |
79 | | - has_binary_relation=relation, |
80 | | - ) |
81 | | - return Measurement( |
82 | | - quantity=quantity, |
83 | | - source_field=source_field, |
84 | | - comparator=original_comparator, |
85 | | - ) |
86 | | - |
87 | | - |
88 | 55 | VERSION = 36 |
89 | 56 | DB_REL_PATH = f'chembl_{VERSION}/chembl_{VERSION}_sqlite/chembl_{VERSION}.db' |
90 | 57 | SQLITE_PATH = Path(cache.get_cachedir()) / f'ChEMBL_SQLite_{VERSION}.sqlite' |
@@ -133,7 +100,7 @@ def _files_needed(version: int = VERSION, **_kwargs: object) -> list[str]: |
133 | 100 | TARGET_TYPE_MAP = { |
134 | 101 | 'SINGLE PROTEIN': Protein, |
135 | 102 | 'PROTEIN COMPLEX': MacromolecularComplex, |
136 | | - 'PROTEIN FAMILY': GeneFamily, |
| 103 | + 'PROTEIN FAMILY': ProteinFamily, |
137 | 104 | 'PROTEIN-PROTEIN INTERACTION': MolecularActivity, |
138 | 105 | 'SELECTIVITY GROUP': NamedThing, |
139 | 106 | 'NUCLEIC-ACID': NucleicAcidEntity, |
@@ -333,6 +300,8 @@ def chembl_predicate(row): |
333 | 300 | predicate=chembl_predicate, |
334 | 301 | object=target_builder, |
335 | 302 | annotations=AnnotationsBuilder( |
| 303 | + CV(term=slots.source_record_urls, value=f('assay_chembl_id', transform=lambda v: f'https://www.ebi.ac.uk/chembl/explore/assay/{v}')), |
| 304 | + CV(term=slots.source_record_urls, value=f('document_chembl_id', transform=lambda v: f'https://www.ebi.ac.uk/chembl/explore/document/{v}')), |
336 | 305 | CV( |
337 | 306 | term=slots.has_quantitative_value, |
338 | 307 | value=f( |
@@ -388,7 +357,10 @@ def chembl_predicate(row): |
388 | 357 | ), |
389 | 358 | CV(term=slots.chembl_confidence_score, value=f('confidence_score')), |
390 | 359 | ), |
391 | | - identifiers=IdentifiersBuilder(), |
| 360 | + identifiers=IdentifiersBuilder( |
| 361 | + CV(term=Namespace.CHEMBL_ACTIVITY, value=f('activity_id')), |
| 362 | + CV(term=Namespace.CHEMBL_MECHANISM, value=f('mec_id')), |
| 363 | + ), |
392 | 364 | ) |
393 | 365 | resource = Resource( |
394 | 366 | config=config, |
|
0 commit comments