sapiopycommons 2024.6.24a263__tar.gz → 2024.6.24a265__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.

Potentially problematic release.


This version of sapiopycommons might be problematic. Click here for more details.

Files changed (49) hide show
  1. {sapiopycommons-2024.6.24a263 → sapiopycommons-2024.6.24a265}/PKG-INFO +1 -1
  2. {sapiopycommons-2024.6.24a263 → sapiopycommons-2024.6.24a265}/pyproject.toml +1 -1
  3. {sapiopycommons-2024.6.24a263 → sapiopycommons-2024.6.24a265}/src/sapiopycommons/callbacks/callback_util.py +21 -13
  4. {sapiopycommons-2024.6.24a263 → sapiopycommons-2024.6.24a265}/src/sapiopycommons/multimodal/multimodal_data.py +2 -2
  5. {sapiopycommons-2024.6.24a263 → sapiopycommons-2024.6.24a265}/tests/chem_test.py +23 -61
  6. {sapiopycommons-2024.6.24a263 → sapiopycommons-2024.6.24a265}/.gitignore +0 -0
  7. {sapiopycommons-2024.6.24a263 → sapiopycommons-2024.6.24a265}/LICENSE +0 -0
  8. {sapiopycommons-2024.6.24a263 → sapiopycommons-2024.6.24a265}/README.md +0 -0
  9. {sapiopycommons-2024.6.24a263 → sapiopycommons-2024.6.24a265}/src/sapiopycommons/__init__.py +0 -0
  10. {sapiopycommons-2024.6.24a263 → sapiopycommons-2024.6.24a265}/src/sapiopycommons/callbacks/__init__.py +0 -0
  11. {sapiopycommons-2024.6.24a263 → sapiopycommons-2024.6.24a265}/src/sapiopycommons/chem/IndigoMolecules.py +0 -0
  12. {sapiopycommons-2024.6.24a263 → sapiopycommons-2024.6.24a265}/src/sapiopycommons/chem/Molecules.py +0 -0
  13. {sapiopycommons-2024.6.24a263 → sapiopycommons-2024.6.24a265}/src/sapiopycommons/chem/__init__.py +0 -0
  14. {sapiopycommons-2024.6.24a263 → sapiopycommons-2024.6.24a265}/src/sapiopycommons/datatype/__init__.py +0 -0
  15. {sapiopycommons-2024.6.24a263 → sapiopycommons-2024.6.24a265}/src/sapiopycommons/datatype/attachment_util.py +0 -0
  16. {sapiopycommons-2024.6.24a263 → sapiopycommons-2024.6.24a265}/src/sapiopycommons/eln/__init__.py +0 -0
  17. {sapiopycommons-2024.6.24a263 → sapiopycommons-2024.6.24a265}/src/sapiopycommons/eln/experiment_handler.py +0 -0
  18. {sapiopycommons-2024.6.24a263 → sapiopycommons-2024.6.24a265}/src/sapiopycommons/eln/plate_designer.py +0 -0
  19. {sapiopycommons-2024.6.24a263 → sapiopycommons-2024.6.24a265}/src/sapiopycommons/files/__init__.py +0 -0
  20. {sapiopycommons-2024.6.24a263 → sapiopycommons-2024.6.24a265}/src/sapiopycommons/files/complex_data_loader.py +0 -0
  21. {sapiopycommons-2024.6.24a263 → sapiopycommons-2024.6.24a265}/src/sapiopycommons/files/file_bridge.py +0 -0
  22. {sapiopycommons-2024.6.24a263 → sapiopycommons-2024.6.24a265}/src/sapiopycommons/files/file_bridge_handler.py +0 -0
  23. {sapiopycommons-2024.6.24a263 → sapiopycommons-2024.6.24a265}/src/sapiopycommons/files/file_data_handler.py +0 -0
  24. {sapiopycommons-2024.6.24a263 → sapiopycommons-2024.6.24a265}/src/sapiopycommons/files/file_util.py +0 -0
  25. {sapiopycommons-2024.6.24a263 → sapiopycommons-2024.6.24a265}/src/sapiopycommons/files/file_validator.py +0 -0
  26. {sapiopycommons-2024.6.24a263 → sapiopycommons-2024.6.24a265}/src/sapiopycommons/files/file_writer.py +0 -0
  27. {sapiopycommons-2024.6.24a263 → sapiopycommons-2024.6.24a265}/src/sapiopycommons/general/__init__.py +0 -0
  28. {sapiopycommons-2024.6.24a263 → sapiopycommons-2024.6.24a265}/src/sapiopycommons/general/aliases.py +0 -0
  29. {sapiopycommons-2024.6.24a263 → sapiopycommons-2024.6.24a265}/src/sapiopycommons/general/custom_report_util.py +0 -0
  30. {sapiopycommons-2024.6.24a263 → sapiopycommons-2024.6.24a265}/src/sapiopycommons/general/exceptions.py +0 -0
  31. {sapiopycommons-2024.6.24a263 → sapiopycommons-2024.6.24a265}/src/sapiopycommons/general/popup_util.py +0 -0
  32. {sapiopycommons-2024.6.24a263 → sapiopycommons-2024.6.24a265}/src/sapiopycommons/general/storage_util.py +0 -0
  33. {sapiopycommons-2024.6.24a263 → sapiopycommons-2024.6.24a265}/src/sapiopycommons/general/time_util.py +0 -0
  34. {sapiopycommons-2024.6.24a263 → sapiopycommons-2024.6.24a265}/src/sapiopycommons/multimodal/multimodal.py +0 -0
  35. {sapiopycommons-2024.6.24a263 → sapiopycommons-2024.6.24a265}/src/sapiopycommons/processtracking/__init__.py +0 -0
  36. {sapiopycommons-2024.6.24a263 → sapiopycommons-2024.6.24a265}/src/sapiopycommons/processtracking/endpoints.py +0 -0
  37. {sapiopycommons-2024.6.24a263 → sapiopycommons-2024.6.24a265}/src/sapiopycommons/recordmodel/__init__.py +0 -0
  38. {sapiopycommons-2024.6.24a263 → sapiopycommons-2024.6.24a265}/src/sapiopycommons/recordmodel/record_handler.py +0 -0
  39. {sapiopycommons-2024.6.24a263 → sapiopycommons-2024.6.24a265}/src/sapiopycommons/rules/__init__.py +0 -0
  40. {sapiopycommons-2024.6.24a263 → sapiopycommons-2024.6.24a265}/src/sapiopycommons/rules/eln_rule_handler.py +0 -0
  41. {sapiopycommons-2024.6.24a263 → sapiopycommons-2024.6.24a265}/src/sapiopycommons/rules/on_save_rule_handler.py +0 -0
  42. {sapiopycommons-2024.6.24a263 → sapiopycommons-2024.6.24a265}/src/sapiopycommons/webhook/__init__.py +0 -0
  43. {sapiopycommons-2024.6.24a263 → sapiopycommons-2024.6.24a265}/src/sapiopycommons/webhook/webhook_handlers.py +0 -0
  44. {sapiopycommons-2024.6.24a263 → sapiopycommons-2024.6.24a265}/tests/_do_not_add_init_py_here +0 -0
  45. {sapiopycommons-2024.6.24a263 → sapiopycommons-2024.6.24a265}/tests/bio_reg_test.py +0 -0
  46. {sapiopycommons-2024.6.24a263 → sapiopycommons-2024.6.24a265}/tests/data_type_models.py +0 -0
  47. {sapiopycommons-2024.6.24a263 → sapiopycommons-2024.6.24a265}/tests/kappa.chains.fasta +0 -0
  48. {sapiopycommons-2024.6.24a263 → sapiopycommons-2024.6.24a265}/tests/mafft_test.py +0 -0
  49. {sapiopycommons-2024.6.24a263 → sapiopycommons-2024.6.24a265}/tests/test.gb +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: sapiopycommons
3
- Version: 2024.6.24a263
3
+ Version: 2024.6.24a265
4
4
  Summary: Official Sapio Python API Utilities Package
5
5
  Project-URL: Homepage, https://github.com/sapiosciences
6
6
  Author-email: Jonathan Steck <jsteck@sapiosciences.com>, Yechen Qiao <yqiao@sapiosciences.com>
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "sapiopycommons"
7
- version='2024.06.24a263'
7
+ version='2024.06.24a265'
8
8
  authors = [
9
9
  { name="Jonathan Steck", email="jsteck@sapiosciences.com" },
10
10
  { name="Yechen Qiao", email="yqiao@sapiosciences.com" },
@@ -14,8 +14,8 @@ from sapiopylib.rest.pojo.datatype.FieldDefinition import AbstractVeloxFieldDefi
14
14
  VeloxIntegerFieldDefinition, VeloxDoubleFieldDefinition, FieldDefinitionParser
15
15
  from sapiopylib.rest.pojo.webhook.ClientCallbackRequest import OptionDialogRequest, ListDialogRequest, \
16
16
  FormEntryDialogRequest, InputDialogCriteria, TableEntryDialogRequest, ESigningRequestPojo, \
17
- DataRecordSelectionRequest, DataRecordDialogRequest, InputSelectionRequest, FilePromptRequest, \
18
- MultiFilePromptRequest
17
+ DataRecordDialogRequest, InputSelectionRequest, FilePromptRequest, MultiFilePromptRequest, \
18
+ TempTableSelectionRequest
19
19
  from sapiopylib.rest.pojo.webhook.ClientCallbackResult import ESigningResponsePojo
20
20
  from sapiopylib.rest.pojo.webhook.WebhookContext import SapioWebhookContext
21
21
  from sapiopylib.rest.pojo.webhook.WebhookEnums import FormAccessLevel, ScanToSelectCriteria, SearchType
@@ -627,7 +627,8 @@ class CallbackUtil:
627
627
  values: list[FieldMap],
628
628
  multi_select: bool = True,
629
629
  *,
630
- display_name: str = "Default",
630
+ data_type: str = "Default",
631
+ display_name: str | None = None,
631
632
  plural_display_name: str | None = None) -> list[FieldMap]:
632
633
  """
633
634
  Create a selection dialog for a list of field maps for the user to choose from. Requires that the caller
@@ -638,18 +639,25 @@ class CallbackUtil:
638
639
  they are provided in this list.
639
640
  :param values: The values to set for each row of the table.
640
641
  :param multi_select: Whether the user is able to select multiple rows from the list.
641
- :param display_name: The display name for the temporary data type that will be created.
642
+ :param data_type: The data type name for the temporary data type that will be created for this table.
643
+ :param display_name: The display name for the temporary data type. If not provided, defaults to the data type
644
+ name.
642
645
  :param plural_display_name: The plural display name for the temporary data type. If not provided, defaults to
643
646
  the display name + "s".
644
647
  :return: A list of field maps corresponding to the chosen input field maps.
645
648
  """
649
+ if display_name is None:
650
+ display_name = data_type
646
651
  if plural_display_name is None:
647
652
  plural_display_name = display_name + "s"
648
653
 
649
- # Build the form using only those fields that are desired.
650
- request = DataRecordSelectionRequest(display_name, plural_display_name,
651
- fields, values, msg, multi_select)
652
- response: list[FieldMap] | None = self.callback.show_data_record_selection_dialog(request)
654
+ builder = FormBuilder(data_type, display_name, plural_display_name)
655
+ for field in fields:
656
+ builder.add_field(field)
657
+
658
+ request = TempTableSelectionRequest(builder.get_temporary_data_type(), msg, values,
659
+ multi_select=multi_select)
660
+ response: list[FieldMap] | None = self.callback.show_temp_table_selection_dialog(request)
653
661
  if response is None:
654
662
  raise SapioUserCancelledException()
655
663
  return response
@@ -690,16 +698,16 @@ class CallbackUtil:
690
698
  modifier = FieldModifier(visible=True, key_field=False)
691
699
 
692
700
  # Build the form using only those fields that are desired.
693
- field_def_list: list = []
701
+ builder = FormBuilder(data_type, type_def.display_name, type_def.plural_display_name)
694
702
  for field_name in fields:
695
703
  field_def = field_defs.get(field_name)
696
704
  if field_def is None:
697
705
  raise SapioException(f"No field of name \"{field_name}\" in field definitions of type \"{data_type}\"")
698
- field_def_list.append(modifier.modify_field(field_def))
706
+ builder.add_field(modifier.modify_field(field_def))
699
707
 
700
- request = DataRecordSelectionRequest(type_def.display_name, type_def.plural_display_name,
701
- field_def_list, field_map_list, msg, multi_select)
702
- response: list[FieldMap] | None = self.callback.show_data_record_selection_dialog(request)
708
+ request = TempTableSelectionRequest(builder.get_temporary_data_type(), msg, field_map_list,
709
+ multi_select=multi_select)
710
+ response: list[FieldMap] | None = self.callback.show_temp_table_selection_dialog(request)
703
711
  if response is None:
704
712
  raise SapioUserCancelledException()
705
713
  # Map the field maps in the response back to the record they come from, returning the chosen record instead of
@@ -251,11 +251,11 @@ class ChemSearchRequestPojo:
251
251
  contextData: ChemQuickSearchContextData | None
252
252
  simSearchUpperLimit: float | None
253
253
 
254
- def __init__(self, search_str: str, search_type: ChemSearchType, join_method: str | None = None,
254
+ def __init__(self, search_str: str, search_type: ChemSearchType, join_sapio_type: str | None = None,
255
255
  context_data: ChemQuickSearchContextData | None = None, sim_search_upper: float | None = None):
256
256
  self.searchStr = search_str
257
257
  self.searchType = search_type
258
- self.joinMethod = join_method
258
+ self.joinSapioType = join_sapio_type
259
259
  self.contextData = context_data
260
260
  self.simSearchUpperLimit = sim_search_upper
261
261
 
@@ -1,6 +1,6 @@
1
1
  # Add facilities to test chemistry endpoints. This will run its own webserver.
2
2
  # These testing will require working with a server with chemistry license and is set up with chemistry correctly.
3
- from io import StringIO, BytesIO
3
+ from io import BytesIO
4
4
 
5
5
  from sapiopylib.rest.ClientCallbackService import ClientCallback
6
6
  from sapiopylib.rest.DataMgmtService import DataMgmtServer
@@ -11,31 +11,30 @@ from sapiopylib.rest.pojo.webhook.ClientCallbackRequest import *
11
11
  from sapiopylib.rest.pojo.webhook.WebhookContext import SapioWebhookContext
12
12
  from sapiopylib.rest.pojo.webhook.WebhookResult import SapioWebhookResult
13
13
  from sapiopylib.rest.utils.autopaging import QueryDataRecordByIdListAutoPager
14
- from sapiopylib.rest.utils.recorddatasinks import InMemoryRecordDataSink
15
14
 
16
15
  from data_type_models import *
17
16
  from sapiopycommons.multimodal.multimodal import MultiModalManager
18
17
  from sapiopycommons.multimodal.multimodal_data import *
19
18
 
20
19
 
21
- def __select_type_and_item_to_load(client_callback: ClientCallback) -> tuple[ChemDataType, bool]:
20
+ def __select_type_and_item_to_load(client_callback: ClientCallback) -> tuple[str, bool]:
22
21
  options = ["Compound Parts", "Compound Samples", "Chem Reagent Parts", "Chem Reagent Samples"]
23
22
  selected = client_callback.show_option_dialog(OptionDialogRequest(
24
23
  "Select Item Type", "Select one of the following item types that correspond to what you are registering",
25
24
  options))
26
- data_type: ChemDataType
25
+ data_type: str
27
26
  is_adding_items: bool
28
27
  if selected == 0:
29
- data_type = ChemDataType.CompoundPart
28
+ data_type = CompoundPartModel.DATA_TYPE_NAME
30
29
  is_adding_items = False
31
30
  elif selected == 1:
32
- data_type = ChemDataType.CompoundPart
31
+ data_type = CompoundPartModel.DATA_TYPE_NAME
33
32
  is_adding_items = True
34
33
  elif selected == 2:
35
- data_type = ChemDataType.ChemicalReagentPart
34
+ data_type = ChemicalReagentPartModel.DATA_TYPE_NAME
36
35
  is_adding_items = False
37
36
  elif selected == 3:
38
- data_type = ChemDataType.ChemicalReagentPart
37
+ data_type = ChemicalReagentPartModel.DATA_TYPE_NAME
39
38
  is_adding_items = True
40
39
  else:
41
40
  raise ValueError("Invalid selection index: " + str(selected))
@@ -61,34 +60,6 @@ def download_chem_image(context: SapioWebhookContext) -> SapioWebhookResult:
61
60
  return SapioWebhookResult(True)
62
61
 
63
62
 
64
- def register_interactively(context: SapioWebhookContext) -> SapioWebhookResult:
65
- """
66
- Load an SDF file, provide error report back to the caller, and then let user pick the field mapping like loading from material management.
67
- """
68
- # TODO pending client_callback enablement on the webhook => webservice endpoint route.
69
- user = context.user
70
- client_callback = DataMgmtServer.get_client_callback(user)
71
- data_type, is_adding_items = __select_type_and_item_to_load(client_callback)
72
-
73
- data_sink = InMemoryRecordDataSink(user)
74
- data_sink.upload_single_file_to_webhook_server(FilePromptRequest("Upload SDF File Data", file_extension=".sdf"))
75
-
76
- reg_man = MultiModalManager(user)
77
- reg_result: ChemCompleteImportPojo = reg_man.register_interactively(
78
- ChemInteractiveRegisterRequestPojo(data_type, ChemFileType.SDF, is_adding_items, data_sink.data))
79
- if not reg_result:
80
- client_callback.display_warning("Registration incomplete.")
81
- return SapioWebhookResult(False)
82
- if reg_result.errors:
83
- for error in reg_result.errors:
84
- client_callback.display_warning(
85
- "Item with properties " + str(error.properties) + "cannot be registered: " + str(error.errorMsg))
86
- client_callback.display_info(
87
- "Successfully registered " + str(len(reg_result.newPartList)) + " new parts and used " + str(
88
- reg_result.numOldParts) + " old parts in this registration.")
89
- return SapioWebhookResult(True)
90
-
91
-
92
63
  def register_non_interactively(context: SapioWebhookContext) -> SapioWebhookResult:
93
64
  """
94
65
  Without asking user for anything in between the registration,
@@ -152,17 +123,19 @@ def structure_search(context: SapioWebhookContext) -> SapioWebhookResult:
152
123
  "Enter the SMARTS for compound substructure search or SMILES for compound similarity search, "
153
124
  "or rSMARTS for reaction substructure search."))
154
125
 
155
- join_method: CartridgeMolJoinMethod | None = None
126
+ join_sapio_type: str
156
127
  if search_type is ChemSearchType.COMPOUND_SUBSTRUCTURE or search_type is ChemSearchType.COMPOUND_SIMILARITY:
157
128
  option = client_callback.show_option_dialog(OptionDialogRequest(
158
129
  "Select Join Type", "Select a Sapio registry type you are joining result with.",
159
130
  ["Compounds", "Chemical Reagants", "HELM Chemical Properties"]))
160
131
  if option == 0:
161
- join_method = CartridgeMolJoinMethod.COMPOUND_REGISTRY
132
+ join_sapio_type = CompoundPartModel.DATA_TYPE_NAME
162
133
  elif option == 1:
163
- join_method = CartridgeMolJoinMethod.REAGENT_REGISTRY
134
+ join_sapio_type = ChemicalReagentPartModel.DATA_TYPE_NAME
164
135
  else:
165
- join_method = CartridgeMolJoinMethod.HELM_STRUCTURE
136
+ join_sapio_type = HelmChemPropertyModel.DATA_TYPE_NAME
137
+ else:
138
+ join_sapio_type = ReactionModel.DATA_TYPE_NAME
166
139
  sim_search_upper: float | None = None
167
140
  if search_type is ChemSearchType.COMPOUND_SIMILARITY:
168
141
  field_def = VeloxDoubleFieldDefinition("Upper", "Upper", "Upper",
@@ -177,24 +150,10 @@ def structure_search(context: SapioWebhookContext) -> SapioWebhookResult:
177
150
  return SapioWebhookResult(False)
178
151
  reg_man = MultiModalManager(user)
179
152
  dt_man = DataTypeManager(user)
180
- temp_dt: TemporaryDataType
181
- if search_type is ChemSearchType.REACTION_SUBSTRUCTURE:
182
- temp_dt: TemporaryDataType = dt_man.get_temporary_data_type(ReactionModel.DATA_TYPE_NAME)
183
- elif join_method is CartridgeMolJoinMethod.COMPOUND_REGISTRY:
184
- temp_dt: TemporaryDataType = dt_man.get_temporary_data_type(CompoundPartModel.DATA_TYPE_NAME)
185
- elif join_method is CartridgeMolJoinMethod.REAGENT_REGISTRY:
186
- temp_dt: TemporaryDataType = dt_man.get_temporary_data_type(ChemicalReagentPartModel.DATA_TYPE_NAME)
187
- elif join_method is CartridgeMolJoinMethod.HELM_STRUCTURE:
188
- temp_dt: TemporaryDataType = dt_man.get_temporary_data_type(HelmChemPropertyModel.DATA_TYPE_NAME)
189
- else:
190
- raise ValueError("Unable to obtain temp type to display???")
153
+ temp_dt: TemporaryDataType = dt_man.get_temporary_data_type(join_sapio_type)
191
154
  while True:
192
155
  search_result = reg_man.search_structures(
193
- ChemSearchRequestPojo(query, search_type, join_method, next_page_context, sim_search_upper))
194
- if not search_result.nextPageAvailable:
195
- client_callback.display_info("Hit End of Results. No further pages available.")
196
- return SapioWebhookResult(True)
197
- next_page_context = search_result.nextPageContext
156
+ ChemSearchRequestPojo(query, search_type, join_sapio_type, next_page_context, sim_search_upper))
198
157
  if search_result.recordIdListOfPage:
199
158
  records: list[DataRecord] = QueryDataRecordByIdListAutoPager(
200
159
  temp_dt.data_type_name, search_result.recordIdListOfPage, user).get_all_at_once()
@@ -204,6 +163,11 @@ def structure_search(context: SapioWebhookContext) -> SapioWebhookResult:
204
163
  client_callback.display_popup(DisplayPopupRequest(
205
164
  "No Results in Page", "This page may not contain any results. Good luck next time!",
206
165
  PopupType.Info))
166
+ if not search_result.nextPageAvailable:
167
+ client_callback.display_info("Hit End of Results. No further pages available.")
168
+ return SapioWebhookResult(True)
169
+ next_page_context = search_result.nextPageContext
170
+
207
171
  selected = client_callback.show_option_dialog(OptionDialogRequest("Continue?", "Continue to next page?", ["Yes", "No"]))
208
172
  if selected is None or selected != 0:
209
173
  return SapioWebhookResult(True)
@@ -215,7 +179,7 @@ class ChemistryRegistrationTestHandler(AbstractWebhookHandler):
215
179
  """
216
180
 
217
181
  def run(self, context: SapioWebhookContext) -> SapioWebhookResult:
218
- options = ['Download Image', 'Register Interactively', 'Register Non-Interactively', 'Structure Search',
182
+ options = ['Download Image', 'Register Non-Interactively', 'Structure Search',
219
183
  'Register Reaction']
220
184
  user = context.user
221
185
  client_callback = DataMgmtServer.get_client_callback(user)
@@ -226,12 +190,10 @@ class ChemistryRegistrationTestHandler(AbstractWebhookHandler):
226
190
  if selected == 0:
227
191
  return download_chem_image(context)
228
192
  elif selected == 1:
229
- return register_interactively(context)
230
- elif selected == 2:
231
193
  return register_non_interactively(context)
232
- elif selected == 3:
194
+ elif selected == 2:
233
195
  return structure_search(context)
234
- elif selected == 4:
196
+ elif selected == 3:
235
197
  return register_reaction(context)
236
198
  return SapioWebhookResult(False)
237
199