sapiopycommons 2024.11.8a355__py3-none-any.whl → 2024.11.9a360__py3-none-any.whl
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.
Potentially problematic release.
This version of sapiopycommons might be problematic. Click here for more details.
- sapiopycommons/callbacks/callback_util.py +83 -532
- sapiopycommons/chem/IndigoMolecules.py +0 -2
- sapiopycommons/chem/Molecules.py +18 -77
- sapiopycommons/datatype/attachment_util.py +10 -11
- sapiopycommons/eln/experiment_handler.py +70 -272
- sapiopycommons/files/complex_data_loader.py +4 -5
- sapiopycommons/files/file_bridge.py +24 -31
- sapiopycommons/files/file_data_handler.py +5 -2
- sapiopycommons/files/file_util.py +9 -59
- sapiopycommons/files/file_validator.py +6 -92
- sapiopycommons/files/file_writer.py +15 -44
- sapiopycommons/general/aliases.py +6 -207
- sapiopycommons/general/custom_report_util.py +37 -212
- sapiopycommons/general/exceptions.py +8 -21
- sapiopycommons/general/popup_util.py +0 -21
- sapiopycommons/general/time_util.py +2 -8
- sapiopycommons/processtracking/endpoints.py +22 -22
- sapiopycommons/recordmodel/record_handler.py +97 -481
- sapiopycommons/rules/eln_rule_handler.py +25 -34
- sapiopycommons/rules/on_save_rule_handler.py +31 -34
- sapiopycommons/webhook/webhook_handlers.py +42 -201
- {sapiopycommons-2024.11.8a355.dist-info → sapiopycommons-2024.11.9a360.dist-info}/METADATA +2 -4
- sapiopycommons-2024.11.9a360.dist-info/RECORD +38 -0
- sapiopycommons/callbacks/field_builder.py +0 -537
- sapiopycommons/customreport/__init__.py +0 -0
- sapiopycommons/customreport/column_builder.py +0 -60
- sapiopycommons/customreport/custom_report_builder.py +0 -130
- sapiopycommons/customreport/term_builder.py +0 -299
- sapiopycommons/datatype/data_fields.py +0 -61
- sapiopycommons/datatype/pseudo_data_types.py +0 -440
- sapiopycommons/eln/experiment_report_util.py +0 -653
- sapiopycommons/files/file_bridge_handler.py +0 -340
- sapiopycommons/flowcyto/flow_cyto.py +0 -77
- sapiopycommons/flowcyto/flowcyto_data.py +0 -75
- sapiopycommons/general/accession_service.py +0 -375
- sapiopycommons/general/audit_log.py +0 -189
- sapiopycommons/general/sapio_links.py +0 -50
- sapiopycommons/multimodal/multimodal.py +0 -146
- sapiopycommons/multimodal/multimodal_data.py +0 -489
- sapiopycommons/processtracking/custom_workflow_handler.py +0 -406
- sapiopycommons/sftpconnect/__init__.py +0 -0
- sapiopycommons/sftpconnect/sftp_builder.py +0 -69
- sapiopycommons/webhook/webhook_context.py +0 -39
- sapiopycommons/webhook/webservice_handlers.py +0 -67
- sapiopycommons-2024.11.8a355.dist-info/RECORD +0 -59
- {sapiopycommons-2024.11.8a355.dist-info → sapiopycommons-2024.11.9a360.dist-info}/WHEEL +0 -0
- {sapiopycommons-2024.11.8a355.dist-info → sapiopycommons-2024.11.9a360.dist-info}/licenses/LICENSE +0 -0
|
@@ -6,10 +6,8 @@ indigo = Indigo()
|
|
|
6
6
|
renderer = IndigoRenderer(indigo)
|
|
7
7
|
indigo.setOption("render-output-format", "svg")
|
|
8
8
|
indigo.setOption("ignore-stereochemistry-errors", True)
|
|
9
|
-
indigo.setOption("render-stereo-style", "ext")
|
|
10
9
|
indigo.setOption("aromaticity-model", "generic")
|
|
11
10
|
indigo.setOption("render-coloring", True)
|
|
12
|
-
indigo.setOption("molfile-saving-mode", "3000")
|
|
13
11
|
indigo_inchi = IndigoInchi(indigo);
|
|
14
12
|
|
|
15
13
|
|
sapiopycommons/chem/Molecules.py
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
# Author Yechen Qiao
|
|
2
2
|
# Common Molecule Utilities for Molecule Transfers with Sapio
|
|
3
|
-
from typing import cast
|
|
4
3
|
|
|
5
4
|
from rdkit import Chem
|
|
6
5
|
from rdkit.Chem import Crippen, MolToInchi
|
|
@@ -21,25 +20,6 @@ tautomer_params.tautomerReassignStereo = False
|
|
|
21
20
|
tautomer_params.tautomerRemoveIsotopicHs = True
|
|
22
21
|
enumerator = rdMolStandardize.TautomerEnumerator(tautomer_params)
|
|
23
22
|
|
|
24
|
-
|
|
25
|
-
def get_enhanced_stereo_reg_hash(mol: Mol, enhanced_stereo: bool) -> str:
|
|
26
|
-
"""
|
|
27
|
-
Get the Registration Hash for the molecule by the current registration configuration.
|
|
28
|
-
When we are running if we are canonicalization of tautomers or cleaning up any other way, do they first before calling.
|
|
29
|
-
:param mol: The molecule to obtain hash for.
|
|
30
|
-
:param canonical_tautomer: Whether the registry system canonicalize the tautomers.
|
|
31
|
-
:param enhanced_stereo: Whether we are computing enhanced stereo at all.
|
|
32
|
-
:return: The enhanced stereo hash.
|
|
33
|
-
"""
|
|
34
|
-
if enhanced_stereo:
|
|
35
|
-
from rdkit.Chem.RegistrationHash import GetMolLayers, GetMolHash, HashScheme
|
|
36
|
-
layers = GetMolLayers(mol, enable_tautomer_hash_v2=True)
|
|
37
|
-
hash_scheme: HashScheme = HashScheme.TAUTOMER_INSENSITIVE_LAYERS
|
|
38
|
-
return GetMolHash(layers, hash_scheme=hash_scheme)
|
|
39
|
-
else:
|
|
40
|
-
return ""
|
|
41
|
-
|
|
42
|
-
|
|
43
23
|
def neutralize_atoms(mol) -> Mol:
|
|
44
24
|
"""
|
|
45
25
|
Neutralize atoms per https://baoilleach.blogspot.com/2019/12/no-charge-simple-approach-to.html
|
|
@@ -106,6 +86,7 @@ def mol_to_img(mol_str: str) -> str:
|
|
|
106
86
|
return renderer.renderToString(mol)
|
|
107
87
|
|
|
108
88
|
|
|
89
|
+
|
|
109
90
|
def mol_to_sapio_partial_pojo(mol: Mol):
|
|
110
91
|
"""
|
|
111
92
|
Get the minimum information about molecule to Sapio, just its SMILES, V3000, and image data.
|
|
@@ -115,7 +96,7 @@ def mol_to_sapio_partial_pojo(mol: Mol):
|
|
|
115
96
|
Chem.SanitizeMol(mol)
|
|
116
97
|
mol.UpdatePropertyCache()
|
|
117
98
|
smiles = Chem.MolToSmiles(mol)
|
|
118
|
-
molBlock = Chem.MolToMolBlock(mol
|
|
99
|
+
molBlock = Chem.MolToMolBlock(mol)
|
|
119
100
|
img = mol_to_img(mol)
|
|
120
101
|
molecule = dict()
|
|
121
102
|
molecule["smiles"] = smiles
|
|
@@ -124,52 +105,23 @@ def mol_to_sapio_partial_pojo(mol: Mol):
|
|
|
124
105
|
return molecule
|
|
125
106
|
|
|
126
107
|
|
|
127
|
-
def
|
|
128
|
-
"""
|
|
129
|
-
Return the SHA1 CXS Smiles hash for the canonical, isomeric CXS SMILES of the molecule.
|
|
130
|
-
"""
|
|
131
|
-
if not enhanced_stereo:
|
|
132
|
-
return ""
|
|
133
|
-
import hashlib
|
|
134
|
-
return hashlib.sha1(Chem.MolToCXSmiles(mol, canonical=True, isomericSmiles=True).encode()).hexdigest()
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
def get_has_or_group(mol: Mol, enhanced_stereo: bool) -> bool:
|
|
138
|
-
"""
|
|
139
|
-
Return true if and only if: enhanced stereochemistry is enabled and there is at least one OR group in mol.
|
|
140
|
-
"""
|
|
141
|
-
if not enhanced_stereo:
|
|
142
|
-
return False
|
|
143
|
-
from rdkit.Chem import StereoGroup_vect, STEREO_OR
|
|
144
|
-
stereo_groups: StereoGroup_vect = mol.GetStereoGroups()
|
|
145
|
-
for stereo_group in stereo_groups:
|
|
146
|
-
if stereo_group.GetGroupType() == STEREO_OR:
|
|
147
|
-
return True
|
|
148
|
-
return False
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
def mol_to_sapio_substance(mol: Mol, include_stereoisomers=False,
|
|
108
|
+
def mol_to_sapio_substance(mol: Mol, include_stereoisomers: bool = False,
|
|
152
109
|
normalize: bool = False, remove_salt: bool = False, make_images: bool = False,
|
|
153
|
-
salt_def: str | None = None, canonical_tautomer: bool = True
|
|
154
|
-
enhanced_stereo: bool = False, remove_atom_map: bool = True):
|
|
110
|
+
salt_def: str | None = None, canonical_tautomer: bool = True):
|
|
155
111
|
"""
|
|
156
112
|
Convert a molecule in RDKit to a molecule POJO in Sapio.
|
|
157
113
|
|
|
158
114
|
:param mol: The molecule in RDKit.
|
|
115
|
+
:param include_stereoisomers: If true, will compute all stereoisomer permutations of this molecule.
|
|
159
116
|
:param normalize If true, will normalize the functional groups and return normalized result.
|
|
160
117
|
:param remove_salt If true, we will remove salts iteratively from the molecule before returning their data.
|
|
161
118
|
We will also populate desaltedList with molecules we deleted.
|
|
162
|
-
:param make_images Whether to make images as part of the result without having another script to resolve it.
|
|
163
119
|
:param salt_def: if not none, specifies custom salt to be used during the desalt process.
|
|
164
120
|
:param canonical_tautomer: if True, we will attempt to compute canonical tautomer for the molecule. Slow!
|
|
165
121
|
This is needed for a registry. Note it stops after enumeration of 1000.
|
|
166
|
-
:param enhanced_stereo: If enabled, enhanced stereo hash will be produced.
|
|
167
|
-
:param remove_atom_map: When set, clear all atom AAM maps that were set had it been merged into some reactions earlier.
|
|
168
122
|
:return: The molecule POJO for Sapio.
|
|
169
123
|
"""
|
|
170
124
|
molecule = dict()
|
|
171
|
-
if remove_atom_map:
|
|
172
|
-
[a.SetAtomMapNum(0) for a in mol.GetAtoms()]
|
|
173
125
|
Chem.SanitizeMol(mol)
|
|
174
126
|
mol.UpdatePropertyCache()
|
|
175
127
|
Chem.GetSymmSSSR(mol)
|
|
@@ -205,7 +157,7 @@ def mol_to_sapio_substance(mol: Mol, include_stereoisomers=False,
|
|
|
205
157
|
exactMass = Descriptors.ExactMolWt(mol)
|
|
206
158
|
molFormula = rdMolDescriptors.CalcMolFormula(mol)
|
|
207
159
|
charge = Chem.GetFormalCharge(mol)
|
|
208
|
-
molBlock = Chem.MolToMolBlock(mol
|
|
160
|
+
molBlock = Chem.MolToMolBlock(mol)
|
|
209
161
|
|
|
210
162
|
molecule["cLogP"] = cLogP
|
|
211
163
|
molecule["tpsa"] = tpsa
|
|
@@ -229,38 +181,27 @@ def mol_to_sapio_substance(mol: Mol, include_stereoisomers=False,
|
|
|
229
181
|
# We need to test the INCHI can be loaded back to indigo.
|
|
230
182
|
indigo_mol = indigo.loadMolecule(molBlock)
|
|
231
183
|
indigo_mol.aromatize()
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
molecule["inchi"] = Chem.MolToInchi(mol_copy)
|
|
237
|
-
molecule["inchiKey"] = Chem.MolToInchiKey(mol_copy)
|
|
238
|
-
else:
|
|
239
|
-
indigo_inchi.resetOptions()
|
|
240
|
-
indigo_inchi_str = indigo_inchi.getInchi(indigo_mol)
|
|
241
|
-
molecule["inchi"] = indigo_inchi_str
|
|
242
|
-
indigo_inchi_key_str = indigo_inchi.getInchiKey(indigo_inchi_str)
|
|
243
|
-
molecule["inchiKey"] = indigo_inchi_key_str
|
|
184
|
+
indigo_inchi_str = indigo_inchi.getInchi(indigo_mol)
|
|
185
|
+
molecule["inchi"] = indigo_inchi_str
|
|
186
|
+
indigo_inchi_key_str = indigo_inchi.getInchiKey(indigo_inchi_str)
|
|
187
|
+
molecule["inchiKey"] = indigo_inchi_key_str
|
|
244
188
|
molecule["smiles"] = indigo_mol.smiles()
|
|
245
|
-
molecule["reg_hash"] = get_enhanced_stereo_reg_hash(mol, enhanced_stereo=enhanced_stereo)
|
|
246
|
-
molecule["cxsmiles_hash"] = get_cxs_smiles_hash(mol, enhanced_stereo=enhanced_stereo)
|
|
247
|
-
molecule["has_or_group"] = get_has_or_group(mol, enhanced_stereo=enhanced_stereo)
|
|
248
189
|
|
|
190
|
+
if include_stereoisomers and has_chiral_centers(mol):
|
|
191
|
+
stereoisomers = find_all_possible_stereoisomers(mol, only_unassigned=False, try_embedding=False, unique=True)
|
|
192
|
+
molecule["stereoisomers"] = [mol_to_sapio_partial_pojo(x) for x in stereoisomers]
|
|
249
193
|
return molecule
|
|
250
194
|
|
|
251
195
|
|
|
252
|
-
def mol_to_sapio_compound(mol: Mol, include_stereoisomers
|
|
196
|
+
def mol_to_sapio_compound(mol: Mol, include_stereoisomers: bool = False,
|
|
253
197
|
salt_def: str | None = None, resolve_canonical: bool = True,
|
|
254
|
-
make_images: bool = False, canonical_tautomer: bool = True
|
|
255
|
-
remove_atom_map: bool = True):
|
|
198
|
+
make_images: bool = False, canonical_tautomer: bool = True):
|
|
256
199
|
ret = dict()
|
|
257
|
-
ret['originalMol'] = mol_to_sapio_substance(mol, include_stereoisomers
|
|
200
|
+
ret['originalMol'] = mol_to_sapio_substance(mol, include_stereoisomers,
|
|
258
201
|
normalize=False, remove_salt=False, make_images=make_images,
|
|
259
|
-
canonical_tautomer=canonical_tautomer
|
|
260
|
-
enhanced_stereo=enhanced_stereo, remove_atom_map=remove_atom_map)
|
|
202
|
+
canonical_tautomer=canonical_tautomer)
|
|
261
203
|
if resolve_canonical:
|
|
262
204
|
ret['canonicalMol'] = mol_to_sapio_substance(mol, include_stereoisomers=False,
|
|
263
205
|
normalize=True, remove_salt=True, make_images=make_images,
|
|
264
|
-
salt_def=salt_def, canonical_tautomer=canonical_tautomer
|
|
265
|
-
enhanced_stereo=enhanced_stereo, remove_atom_map=remove_atom_map)
|
|
206
|
+
salt_def=salt_def, canonical_tautomer=canonical_tautomer)
|
|
266
207
|
return ret
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import io
|
|
2
2
|
|
|
3
|
-
from sapiopylib.rest.
|
|
3
|
+
from sapiopylib.rest.User import SapioUser
|
|
4
|
+
from sapiopylib.rest.pojo.webhook.WebhookContext import SapioWebhookContext
|
|
4
5
|
from sapiopylib.rest.utils.recordmodel.RecordModelWrapper import WrappedType
|
|
5
6
|
|
|
6
|
-
from sapiopycommons.general.aliases import AliasUtil, SapioRecord
|
|
7
|
+
from sapiopycommons.general.aliases import AliasUtil, SapioRecord
|
|
7
8
|
from sapiopycommons.general.exceptions import SapioException
|
|
8
9
|
from sapiopycommons.recordmodel.record_handler import RecordHandler
|
|
9
10
|
|
|
@@ -11,32 +12,31 @@ from sapiopycommons.recordmodel.record_handler import RecordHandler
|
|
|
11
12
|
# FR-46064 - Initial port of PyWebhookUtils to sapiopycommons.
|
|
12
13
|
class AttachmentUtil:
|
|
13
14
|
@staticmethod
|
|
14
|
-
def get_attachment_bytes(context:
|
|
15
|
+
def get_attachment_bytes(context: SapioWebhookContext, attachment: SapioRecord) -> bytes:
|
|
15
16
|
"""
|
|
16
17
|
Get the data bytes for the given attachment record. Makes a webservice call to retrieve the data.
|
|
17
18
|
|
|
18
|
-
:param context: The current webhook context
|
|
19
|
+
:param context: The current webhook context.
|
|
19
20
|
:param attachment: The attachment record.
|
|
20
21
|
:return: The bytes for the attachment's file data.
|
|
21
22
|
"""
|
|
22
23
|
attachment = AliasUtil.to_data_record(attachment)
|
|
23
|
-
dr_man = DataMgmtServer.get_data_record_manager(AliasUtil.to_sapio_user(context))
|
|
24
24
|
with io.BytesIO() as data_sink:
|
|
25
25
|
def consume_data(chunk: bytes):
|
|
26
26
|
data_sink.write(chunk)
|
|
27
|
-
|
|
27
|
+
context.data_record_manager.get_attachment_data(attachment, consume_data)
|
|
28
28
|
data_sink.flush()
|
|
29
29
|
data_sink.seek(0)
|
|
30
30
|
file_bytes = data_sink.read()
|
|
31
31
|
return file_bytes
|
|
32
32
|
|
|
33
33
|
@staticmethod
|
|
34
|
-
def set_attachment_bytes(context:
|
|
34
|
+
def set_attachment_bytes(context: SapioWebhookContext, attachment: SapioRecord,
|
|
35
35
|
file_name: str, file_bytes: bytes) -> None:
|
|
36
36
|
"""
|
|
37
37
|
Set the attachment data for a given attachment record. Makes a webservice call to set the data.
|
|
38
38
|
|
|
39
|
-
:param context: The current webhook context
|
|
39
|
+
:param context: The current webhook context.
|
|
40
40
|
:param attachment: The attachment record. Must be an existing data record that is an attachment type.
|
|
41
41
|
:param file_name: The name of the attachment.
|
|
42
42
|
:param file_bytes: The bytes of the attachment data.
|
|
@@ -45,12 +45,11 @@ class AttachmentUtil:
|
|
|
45
45
|
raise SapioException("Provided record cannot have its attachment data set, as it does not exist in the "
|
|
46
46
|
"system yet.")
|
|
47
47
|
attachment = AliasUtil.to_data_record(attachment)
|
|
48
|
-
dr_man = DataMgmtServer.get_data_record_manager(AliasUtil.to_sapio_user(context))
|
|
49
48
|
with io.BytesIO(file_bytes) as stream:
|
|
50
|
-
|
|
49
|
+
context.data_record_manager.set_attachment_data(attachment, file_name, stream)
|
|
51
50
|
|
|
52
51
|
@staticmethod
|
|
53
|
-
def create_attachment(context:
|
|
52
|
+
def create_attachment(context: SapioWebhookContext | SapioUser, file_name: str, file_bytes: bytes,
|
|
54
53
|
wrapper_type: type[WrappedType]) -> WrappedType:
|
|
55
54
|
"""
|
|
56
55
|
Create an attachment data type and initialize its attachment bytes at the same time.
|