sapiopycommons 2025.8.12a693__tar.gz → 2025.8.12a696__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 (91) hide show
  1. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/PKG-INFO +2 -2
  2. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/pyproject.toml +2 -2
  3. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/src/sapiopycommons/callbacks/callback_util.py +14 -21
  4. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/src/sapiopycommons/flowcyto/flow_cyto.py +24 -2
  5. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/src/sapiopycommons/general/accession_service.py +28 -2
  6. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/src/sapiopycommons/multimodal/multimodal.py +24 -2
  7. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/tests/accession_test.py +1 -1
  8. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/tests/mafft_test.py +1 -1
  9. sapiopycommons-2025.8.12a693/src/sapiopycommons/files/assay_plate_reader.py +0 -93
  10. sapiopycommons-2025.8.12a693/src/sapiopycommons/files/file_text_converter.py +0 -207
  11. sapiopycommons-2025.8.12a693/tests/assay_plate_reader/BMGLabtech96.txt +0 -28
  12. sapiopycommons-2025.8.12a693/tests/assay_plate_reader/assay_plate_processing_test.py +0 -43
  13. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/.gitignore +0 -0
  14. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/LICENSE +0 -0
  15. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/README.md +0 -0
  16. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/src/sapiopycommons/__init__.py +0 -0
  17. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/src/sapiopycommons/callbacks/__init__.py +0 -0
  18. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/src/sapiopycommons/callbacks/field_builder.py +0 -0
  19. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/src/sapiopycommons/chem/IndigoMolecules.py +0 -0
  20. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/src/sapiopycommons/chem/Molecules.py +0 -0
  21. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/src/sapiopycommons/chem/__init__.py +0 -0
  22. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/src/sapiopycommons/customreport/__init__.py +0 -0
  23. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/src/sapiopycommons/customreport/auto_pagers.py +0 -0
  24. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/src/sapiopycommons/customreport/column_builder.py +0 -0
  25. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/src/sapiopycommons/customreport/custom_report_builder.py +0 -0
  26. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/src/sapiopycommons/customreport/term_builder.py +0 -0
  27. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/src/sapiopycommons/datatype/__init__.py +0 -0
  28. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/src/sapiopycommons/datatype/attachment_util.py +0 -0
  29. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/src/sapiopycommons/datatype/data_fields.py +0 -0
  30. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/src/sapiopycommons/datatype/pseudo_data_types.py +0 -0
  31. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/src/sapiopycommons/eln/__init__.py +0 -0
  32. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/src/sapiopycommons/eln/experiment_cache.py +0 -0
  33. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/src/sapiopycommons/eln/experiment_handler.py +0 -0
  34. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/src/sapiopycommons/eln/experiment_report_util.py +0 -0
  35. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/src/sapiopycommons/eln/experiment_step_factory.py +0 -0
  36. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/src/sapiopycommons/eln/experiment_tags.py +0 -0
  37. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/src/sapiopycommons/eln/plate_designer.py +0 -0
  38. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/src/sapiopycommons/eln/step_creation.py +0 -0
  39. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/src/sapiopycommons/files/__init__.py +0 -0
  40. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/src/sapiopycommons/files/complex_data_loader.py +0 -0
  41. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/src/sapiopycommons/files/file_bridge.py +0 -0
  42. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/src/sapiopycommons/files/file_bridge_handler.py +0 -0
  43. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/src/sapiopycommons/files/file_data_handler.py +0 -0
  44. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/src/sapiopycommons/files/file_util.py +0 -0
  45. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/src/sapiopycommons/files/file_validator.py +0 -0
  46. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/src/sapiopycommons/files/file_writer.py +0 -0
  47. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/src/sapiopycommons/flowcyto/flowcyto_data.py +0 -0
  48. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/src/sapiopycommons/general/__init__.py +0 -0
  49. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/src/sapiopycommons/general/aliases.py +0 -0
  50. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/src/sapiopycommons/general/audit_log.py +0 -0
  51. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/src/sapiopycommons/general/custom_report_util.py +0 -0
  52. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/src/sapiopycommons/general/data_structure_util.py +0 -0
  53. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/src/sapiopycommons/general/directive_util.py +0 -0
  54. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/src/sapiopycommons/general/exceptions.py +0 -0
  55. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/src/sapiopycommons/general/html_formatter.py +0 -0
  56. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/src/sapiopycommons/general/popup_util.py +0 -0
  57. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/src/sapiopycommons/general/sapio_links.py +0 -0
  58. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/src/sapiopycommons/general/storage_util.py +0 -0
  59. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/src/sapiopycommons/general/time_util.py +0 -0
  60. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/src/sapiopycommons/multimodal/multimodal_data.py +0 -0
  61. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/src/sapiopycommons/processtracking/__init__.py +0 -0
  62. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/src/sapiopycommons/processtracking/custom_workflow_handler.py +0 -0
  63. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/src/sapiopycommons/processtracking/endpoints.py +0 -0
  64. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/src/sapiopycommons/recordmodel/__init__.py +0 -0
  65. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/src/sapiopycommons/recordmodel/record_handler.py +0 -0
  66. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/src/sapiopycommons/rules/__init__.py +0 -0
  67. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/src/sapiopycommons/rules/eln_rule_handler.py +0 -0
  68. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/src/sapiopycommons/rules/on_save_rule_handler.py +0 -0
  69. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/src/sapiopycommons/samples/aliquot.py +0 -0
  70. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/src/sapiopycommons/sftpconnect/__init__.py +0 -0
  71. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/src/sapiopycommons/sftpconnect/sftp_builder.py +0 -0
  72. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/src/sapiopycommons/webhook/__init__.py +0 -0
  73. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/src/sapiopycommons/webhook/webhook_context.py +0 -0
  74. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/src/sapiopycommons/webhook/webhook_handlers.py +0 -0
  75. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/src/sapiopycommons/webhook/webservice_handlers.py +0 -0
  76. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/tests/AF-A0A009IHW8-F1-model_v4.cif +0 -0
  77. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/tests/_do_not_add_init_py_here +0 -0
  78. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/tests/aliquot_test.py +0 -0
  79. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/tests/bio_reg_test.py +0 -0
  80. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/tests/chem_test.py +0 -0
  81. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/tests/chem_test_curation_queue.py +0 -0
  82. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/tests/curation_queue_test.sdf +0 -0
  83. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/tests/data_type_models.py +0 -0
  84. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/tests/flowcyto/101_DEN084Y5_15_E01_008_clean.fcs +0 -0
  85. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/tests/flowcyto/101_DEN084Y5_15_E03_009_clean.fcs +0 -0
  86. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/tests/flowcyto/101_DEN084Y5_15_E05_010_clean.fcs +0 -0
  87. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/tests/flowcyto/8_color_ICS.wsp +0 -0
  88. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/tests/flowcyto/COVID19_W_001_O.fcs +0 -0
  89. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/tests/flowcyto_test.py +0 -0
  90. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/tests/kappa.chains.fasta +0 -0
  91. {sapiopycommons-2025.8.12a693 → sapiopycommons-2025.8.12a696}/tests/test.gb +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: sapiopycommons
3
- Version: 2025.8.12a693
3
+ Version: 2025.8.12a696
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>
@@ -17,7 +17,7 @@ Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
17
17
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
18
18
  Requires-Python: >=3.10
19
19
  Requires-Dist: databind>=4.5
20
- Requires-Dist: sapiopylib>=2025.7.31a279
20
+ Requires-Dist: sapiopylib>=2025.4.17.264
21
21
  Description-Content-Type: text/markdown
22
22
 
23
23
 
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "sapiopycommons"
7
- version='2025.08.12a693'
7
+ version='2025.08.12a696'
8
8
  authors = [
9
9
  { name="Jonathan Steck", email="jsteck@sapiosciences.com" },
10
10
  { name="Yechen Qiao", email="yqiao@sapiosciences.com" },
@@ -14,7 +14,7 @@ license = "MPL-2.0"
14
14
  readme = "README.md"
15
15
  requires-python = ">=3.10"
16
16
  dependencies = [
17
- 'sapiopylib>=2025.7.31a279', 'databind>=4.5'
17
+ 'sapiopylib>=2025.4.17.264', 'databind>=4.5'
18
18
  ]
19
19
  classifiers = [
20
20
  "Intended Audience :: Developers",
@@ -1815,8 +1815,7 @@ class CallbackUtil:
1815
1815
  return response
1816
1816
 
1817
1817
  def request_file(self, title: str, exts: Iterable[str] | None = None,
1818
- show_image_editor: bool = False, show_camera_button: bool = False,
1819
- *, enforce_file_extensions: bool = True) -> tuple[str, bytes]:
1818
+ show_image_editor: bool = False, show_camera_button: bool = False) -> tuple[str, bytes]:
1820
1819
  """
1821
1820
  Request a single file from the user.
1822
1821
 
@@ -1826,8 +1825,6 @@ class CallbackUtil:
1826
1825
  :param show_image_editor: Whether the user will see an image editor when image is uploaded in this file prompt.
1827
1826
  :param show_camera_button: Whether the user will be able to use camera to take a picture as an upload request,
1828
1827
  rather than selecting an existing file.
1829
- :param enforce_file_extensions: If true, then the file extensions provided in the exts parameter will be
1830
- enforced. If false, then the user may upload any file type.
1831
1828
  :return: The file name and bytes of the uploaded file.
1832
1829
  """
1833
1830
  # If no extensions were provided, use an empty list for the extensions instead.
@@ -1847,12 +1844,11 @@ class CallbackUtil:
1847
1844
  file_path: str = self.__send_dialog(request, self.callback.show_file_dialog, data_sink=do_consume)
1848
1845
 
1849
1846
  # Verify that each of the file given matches the expected extension(s).
1850
- self.__verify_file(file_path, sink.data, exts if enforce_file_extensions else None)
1847
+ self.__verify_file(file_path, sink.data, exts)
1851
1848
  return file_path, sink.data
1852
1849
 
1853
1850
  def request_files(self, title: str, exts: Iterable[str] | None = None,
1854
- show_image_editor: bool = False, show_camera_button: bool = False,
1855
- *, enforce_file_extensions: bool = True) -> dict[str, bytes]:
1851
+ show_image_editor: bool = False, show_camera_button: bool = False) -> dict[str, bytes]:
1856
1852
  """
1857
1853
  Request multiple files from the user.
1858
1854
 
@@ -1862,8 +1858,6 @@ class CallbackUtil:
1862
1858
  :param show_image_editor: Whether the user will see an image editor when image is uploaded in this file prompt.
1863
1859
  :param show_camera_button: Whether the user will be able to use camera to take a picture as an upload request,
1864
1860
  rather than selecting an existing file.
1865
- :param enforce_file_extensions: If true, then the file extensions provided in the exts parameter will be
1866
- enforced. If false, then the user may upload any file type.
1867
1861
  :return: A dictionary of file name to file bytes for each file the user uploaded.
1868
1862
  """
1869
1863
  # If no extensions were provided, use an empty list for the extensions instead.
@@ -1879,7 +1873,7 @@ class CallbackUtil:
1879
1873
  for file_path in file_paths:
1880
1874
  sink = InMemoryRecordDataSink(self.user)
1881
1875
  sink.consume_client_callback_file_path_data(file_path)
1882
- self.__verify_file(file_path, sink.data, exts if enforce_file_extensions else None)
1876
+ self.__verify_file(file_path, sink.data, exts)
1883
1877
  ret_dict.update({file_path: sink.data})
1884
1878
 
1885
1879
  return ret_dict
@@ -1896,17 +1890,16 @@ class CallbackUtil:
1896
1890
  """
1897
1891
  if file_path is None or len(file_path) == 0 or file_bytes is None or len(file_bytes) == 0:
1898
1892
  raise SapioUserErrorException("Empty file provided or file unable to be read.")
1899
- if not allowed_extensions:
1900
- return
1901
- matches: bool = False
1902
- for ext in allowed_extensions:
1903
- # FR-47690: Changed to a case-insensitive match.
1904
- if file_path.casefold().endswith("." + ext.lstrip(".").casefold()):
1905
- matches = True
1906
- break
1907
- if not matches:
1908
- raise SapioUserErrorException("Unsupported file type. Expecting the following extension(s): "
1909
- + (",".join(allowed_extensions)))
1893
+ if allowed_extensions:
1894
+ matches: bool = False
1895
+ for ext in allowed_extensions:
1896
+ # FR-47690: Changed to a case-insensitive match.
1897
+ if file_path.casefold().endswith("." + ext.lstrip(".").casefold()):
1898
+ matches = True
1899
+ break
1900
+ if matches is False:
1901
+ raise SapioUserErrorException("Unsupported file type. Expecting the following extension(s): "
1902
+ + (",".join(allowed_extensions)))
1910
1903
 
1911
1904
  def write_file(self, file_name: str, file_data: str | bytes) -> None:
1912
1905
  """
@@ -4,16 +4,38 @@ from weakref import WeakValueDictionary
4
4
 
5
5
  from databind.json import dumps
6
6
  from sapiopylib.rest.User import SapioUser
7
- from sapiopylib.rest.utils.singletons import SapioContextManager
8
7
 
9
8
  from sapiopycommons.flowcyto.flowcyto_data import FlowJoWorkspaceInputJson, UploadFCSInputJson, \
10
9
  ComputeFlowStatisticsInputJson
11
10
 
12
11
 
13
- class FlowCytoManager(SapioContextManager):
12
+ class FlowCytoManager:
14
13
  """
15
14
  This manager includes flow cytometry analysis tools that would require FlowCyto license to use.
16
15
  """
16
+ _user: SapioUser
17
+
18
+ __instances: WeakValueDictionary[SapioUser, FlowCytoManager] = WeakValueDictionary()
19
+ __initialized: bool
20
+
21
+ def __new__(cls, user: SapioUser):
22
+ """
23
+ Observes singleton pattern per record model manager object.
24
+
25
+ :param user: The user that will make the webservice request to the application.
26
+ """
27
+ obj = cls.__instances.get(user)
28
+ if not obj:
29
+ obj = object.__new__(cls)
30
+ obj.__initialized = False
31
+ cls.__instances[user] = obj
32
+ return obj
33
+
34
+ def __init__(self, user: SapioUser):
35
+ if self.__initialized:
36
+ return
37
+ self._user = user
38
+ self.__initialized = True
17
39
 
18
40
  def create_flowjo_workspace(self, workspace_input: FlowJoWorkspaceInputJson) -> int:
19
41
  """
@@ -5,7 +5,6 @@ from typing import Any
5
5
  from weakref import WeakValueDictionary
6
6
 
7
7
  from sapiopylib.rest.User import SapioUser
8
- from sapiopylib.rest.utils.singletons import SapioContextManager
9
8
 
10
9
  _STR_JAVA_TYPE = "java.lang.String"
11
10
  _INT_JAVA_TYPE = "java.lang.Integer"
@@ -275,10 +274,37 @@ class AccessionServiceDescriptor:
275
274
  }
276
275
 
277
276
 
278
- class AccessionService(SapioContextManager):
277
+ class AccessionService:
279
278
  """
280
279
  Provides Sapio Foundations Accession Service functionalities.
281
280
  """
281
+ _user: SapioUser
282
+
283
+ __instances: WeakValueDictionary[SapioUser, AccessionService] = WeakValueDictionary()
284
+ __initialized: bool
285
+
286
+ @property
287
+ def user(self) -> SapioUser:
288
+ return self._user
289
+
290
+ def __new__(cls, user: SapioUser):
291
+ """
292
+ Observes singleton pattern per record model manager object.
293
+
294
+ :param user: The user that will make the webservice request to the application.
295
+ """
296
+ obj = cls.__instances.get(user)
297
+ if not obj:
298
+ obj = object.__new__(cls)
299
+ obj.__initialized = False
300
+ cls.__instances[user] = obj
301
+ return obj
302
+
303
+ def __init__(self, user: SapioUser):
304
+ if self.__initialized:
305
+ return
306
+ self._user = user
307
+ self.__initialized = True
282
308
 
283
309
  def accession_with_config(self, data_type_name: str, data_field_name: str, num_ids: int) -> list[str]:
284
310
  """
@@ -7,13 +7,35 @@ from weakref import WeakValueDictionary
7
7
  from databind.json import dumps, loads
8
8
  from sapiopylib.rest.User import SapioUser
9
9
  from sapiopylib.rest.pojo.DataRecord import DataRecord
10
- from sapiopylib.rest.utils.singletons import SapioContextManager
11
10
 
12
11
  from sapiopycommons.general.exceptions import SapioException
13
12
  from sapiopycommons.multimodal.multimodal_data import *
14
13
 
15
14
 
16
- class MultiModalManager(SapioContextManager):
15
+ class MultiModalManager:
16
+ _user: SapioUser
17
+
18
+ __instances: WeakValueDictionary[SapioUser, MultiModalManager] = WeakValueDictionary()
19
+ __initialized: bool
20
+
21
+ def __new__(cls, user: SapioUser):
22
+ """
23
+ Observes singleton pattern per record model manager object.
24
+
25
+ :param user: The user that will make the webservice request to the application.
26
+ """
27
+ obj = cls.__instances.get(user)
28
+ if not obj:
29
+ obj = object.__new__(cls)
30
+ obj.__initialized = False
31
+ cls.__instances[user] = obj
32
+ return obj
33
+
34
+ def __init__(self, user:SapioUser):
35
+ if self.__initialized:
36
+ return
37
+ self._user = user
38
+ self.__initialized = True
17
39
 
18
40
  def load_image_data(self, request: ImageDataRequestPojo) -> list[str]:
19
41
  """
@@ -6,7 +6,7 @@ from sapiopycommons.general.accession_service import AccessionService
6
6
  from data_type_models import SampleModel
7
7
 
8
8
  user = SapioUser(url="https://linux-vm:8443/webservice/api", verify_ssl_cert=False,
9
- guid="66c2bea5-7cb2-4bfc-a413-304a3f4c3f33",
9
+ guid="3c232543-f407-4828-aae5-b33d4cd31fa7",
10
10
  username="yqiao_api", password="Password1!")
11
11
 
12
12
  accession_service = AccessionService(user)
@@ -7,7 +7,7 @@ from sapiopycommons.multimodal.multimodal_data import MultiSequenceAlignmentRequ
7
7
  MultiSequenceAlignmentTool, MultiSequenceAlignmentSeqPojo, MultiSeqAlignemntSeqType
8
8
 
9
9
  user = SapioUser(url="https://linux-vm:8443/webservice/api", verify_ssl_cert=False,
10
- guid="66c2bea5-7cb2-4bfc-a413-304a3f4c3f33",
10
+ guid="3c232543-f407-4828-aae5-b33d4cd31fa7",
11
11
  username="yqiao_api", password="Password1!")
12
12
 
13
13
 
@@ -1,93 +0,0 @@
1
- import base64
2
- import dataclasses
3
- from typing import Any
4
-
5
- from databind.core.dataclasses import dataclass
6
- from databind.json import loads
7
- from sapiopylib.rest.utils.singletons import SapioContextManager
8
-
9
-
10
- @dataclasses.dataclass
11
- class ProcessAssayPlateRequest:
12
- """
13
- A request to process the results of assay plate reader with a configuration set in Sapio.
14
-
15
- Attributes:
16
- num_rows (int): The number of rows in the plate.
17
- num_columns (int): The number of columns in the plate.
18
- plate_ids_in_context (list[str]): List of plate IDs that are in context for this request.
19
- filename (str): The name of the file containing the assay data.
20
- file_data (bytes): The binary content of the file.
21
- plate_reader_config_name (str): The name of the plate reader configuration to use.
22
- """
23
- num_rows: int
24
- num_columns: int
25
- plate_ids_in_context: list[str] | None
26
- filename: str
27
- file_data: bytes
28
- plate_reader_config_name: str
29
-
30
- def to_json(self) -> dict[str, Any]:
31
- return {
32
- "numRows": self.num_rows,
33
- "numCols": self.num_columns,
34
- "plateIdsInContext": self.plate_ids_in_context,
35
- "fileName": self.filename,
36
- "fileDataBase64": base64.b64encode(self.file_data).decode('utf-8'),
37
- "plateReaderName": self.plate_reader_config_name
38
- }
39
-
40
-
41
- @dataclass
42
- class AssayPlateResultIdent:
43
- plateId: str
44
- channelIdOrBlock: str
45
- kineticAssaySeconds: float | None
46
-
47
-
48
- @dataclass
49
- class AssayResultDatum:
50
- """
51
- Describes the data received from an assay plate reader.
52
- Most of the time, the data is a single value, but sometimes it can be multiple values, especially for kinetic data.
53
- """
54
- DEFAULT_PROPERTY_NAME: str = "read"
55
- rowPosition: str
56
- columnPosition: str
57
- valueByPropertyName: dict[str, float]
58
- textValueByPropertyName: dict[str, str]
59
-
60
-
61
- @dataclass
62
- class AssayPlateResult:
63
- """
64
- Assay plate load result for a single plate in a file. A file can have more than one of this result if it has multiple plate of data in a single file.
65
- """
66
- resultIdent: AssayPlateResultIdent
67
- numRows: int
68
- numColumns: int
69
- resultDatum: list[AssayResultDatum]
70
-
71
-
72
- @dataclass
73
- class AssayFileLoadResult:
74
- """
75
- The entire top-level file loading result for an assay plate reader file.
76
- """
77
- filename: str
78
- plateResultList: list[AssayPlateResult]
79
-
80
-
81
- class AssayPlateReader(SapioContextManager):
82
- """
83
- This class contains services for Sapio Assay Plate Reader.
84
- """
85
-
86
- def process_plate_reader_data(self, request: ProcessAssayPlateRequest) -> AssayFileLoadResult:
87
- """
88
- Processes the assay plate reader data using provided request into a structured result using configuration defined in Sapio.
89
- """
90
- payload = request.to_json()
91
- response = self.user.plugin_post("assayplatereader/process", payload=payload)
92
- self.user.raise_for_status(response)
93
- return loads(response.text, AssayFileLoadResult)
@@ -1,207 +0,0 @@
1
- import io
2
- import os
3
- import tempfile
4
- from enum import Enum, auto
5
-
6
- class FileType(Enum):
7
- """Supported file types for conversion."""
8
- TXT = auto()
9
- MD = auto()
10
- CSV = auto()
11
- DOC = auto()
12
- DOCX = auto()
13
- XLS = auto()
14
- XLSX = auto()
15
- PPT = auto()
16
- PPTX = auto()
17
- PDF = auto()
18
- UNKNOWN = auto()
19
-
20
-
21
- class FileToTextConverter:
22
- """
23
- A class for converting various file types to raw text.
24
- """
25
- @staticmethod
26
- def mime_type_to_enum(mime_type: str) -> FileType:
27
- """
28
- Converts a MIME type to a FileType enum.
29
-
30
- :param mime_type: The MIME type string to convert.
31
- :return: The corresponding FileType enum, or UNKNOWN if not recognized.
32
- """
33
- if not mime_type or not mime_type.strip():
34
- return FileType.UNKNOWN
35
-
36
- mime_map = {
37
- "text/plain": FileType.TXT,
38
- "text/markdown": FileType.MD,
39
- "text/csv": FileType.CSV,
40
- "application/msword": FileType.DOC,
41
- "application/vnd.openxmlformats-officedocument.wordprocessingml.document": FileType.DOCX,
42
- "application/vnd.ms-excel": FileType.XLS,
43
- "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": FileType.XLSX,
44
- "application/vnd.ms-powerpoint": FileType.PPT,
45
- "application/vnd.openxmlformats-officedocument.presentationml.presentation": FileType.PPTX,
46
- "application/pdf": FileType.PDF,
47
- }
48
- return mime_map.get(mime_type, FileType.UNKNOWN)
49
-
50
- @staticmethod
51
- def file_extension_to_enum(file_path: str) -> FileType:
52
- """
53
- Converts a file path or extension to a FileType enum.
54
-
55
- :param file_path: The file path or extension to convert.
56
- :return: The corresponding FileType enum, or UNKNOWN if not recognized.
57
- """
58
- if not file_path or not file_path.strip():
59
- return FileType.UNKNOWN
60
-
61
- # Extract the file extension, removing the leading dot and making it lowercase
62
- file_extension = os.path.splitext(file_path)[1].lstrip('.').lower()
63
-
64
- ext_map = {
65
- "txt": FileType.TXT,
66
- "md": FileType.MD,
67
- "csv": FileType.CSV,
68
- "doc": FileType.DOC,
69
- "docx": FileType.DOCX,
70
- "xls": FileType.XLS,
71
- "xlsx": FileType.XLSX,
72
- "ppt": FileType.PPT,
73
- "pptx": FileType.PPTX,
74
- "pdf": FileType.PDF,
75
- }
76
- return ext_map.get(file_extension, FileType.UNKNOWN)
77
-
78
- @classmethod
79
- def parse_file(cls, file_type: FileType, file_bytes: bytes) -> str | None:
80
- """
81
- Parses file bytes based on the FileType and returns the text content.
82
-
83
- :param file_type: The type of the file to parse.
84
- :param file_bytes: The raw bytes of the file to parse.
85
- :return: The text content of the file, or None if the file type is not supported or parsing fails.
86
- """
87
- if file_type is None or file_bytes is None:
88
- return None
89
- if not file_bytes:
90
- return ""
91
-
92
- # Dispatch to the correct parser method
93
- parser_map = {
94
- FileType.TXT: cls._parse_plain_text,
95
- FileType.MD: cls._parse_plain_text,
96
- FileType.CSV: cls._parse_plain_text,
97
- FileType.DOC: cls._parse_doc,
98
- FileType.DOCX: cls._parse_docx,
99
- FileType.XLS: cls._parse_xls,
100
- FileType.XLSX: cls._parse_xlsx,
101
- FileType.PPT: cls._parse_ppt,
102
- FileType.PPTX: cls._parse_pptx,
103
- FileType.PDF: cls._parse_pdf,
104
- }
105
-
106
- parser_func = parser_map.get(file_type)
107
-
108
- if parser_func:
109
- return parser_func(file_bytes)
110
-
111
- return None
112
-
113
- @staticmethod
114
- def _parse_plain_text(file_bytes: bytes) -> str:
115
- return file_bytes.decode('utf-8')
116
-
117
- @staticmethod
118
- def _run_textract(file_bytes: bytes, extension: str) -> str:
119
- """
120
- Helper to run textract on in-memory bytes by writing to a temp file.
121
- Note: textract may require external system dependencies.
122
- """
123
- import textract
124
- with tempfile.NamedTemporaryFile(suffix=f".{extension}", delete=True) as temp_file:
125
- temp_file.write(file_bytes)
126
- temp_file.flush() # Ensure all bytes are written to disk
127
- text = textract.process(temp_file.name).decode('utf-8')
128
- return text
129
-
130
- @classmethod
131
- def _parse_doc(cls, file_bytes: bytes) -> str:
132
- return cls._run_textract(file_bytes, 'doc')
133
-
134
- @staticmethod
135
- def _parse_docx(file_bytes: bytes) -> str:
136
- import docx
137
- with io.BytesIO(file_bytes) as stream:
138
- document = docx.Document(stream)
139
- return "\n".join(para.text for para in document.paragraphs if para.text.strip())
140
-
141
- @staticmethod
142
- def _parse_xls(file_bytes: bytes) -> str:
143
- import xlrd
144
- workbook = xlrd.open_workbook(file_contents=file_bytes)
145
- text_parts = []
146
- for sheet in workbook.sheets():
147
- text_parts.append(f"Sheet: {sheet.name}\n")
148
- for row_idx in range(sheet.nrows):
149
- row_cells = []
150
- for col_idx in range(sheet.ncols):
151
- cell_text = str(sheet.cell_value(row_idx, col_idx))
152
- if cell_text.strip():
153
- row_cells.append(cell_text + "\t")
154
- if row_cells:
155
- text_parts.append("".join(row_cells))
156
- text_parts.append("\n")
157
- text_parts.append("\n")
158
- return "".join(text_parts)
159
-
160
- @staticmethod
161
- def _parse_xlsx(file_bytes: bytes) -> str:
162
- import openpyxl
163
- with io.BytesIO(file_bytes) as stream:
164
- workbook = openpyxl.load_workbook(stream, read_only=True)
165
- text_parts = []
166
- for sheet in workbook.worksheets:
167
- text_parts.append(f"Sheet: {sheet.title}\n")
168
- for row in sheet.iter_rows():
169
- row_cells = []
170
- for cell in row:
171
- cell_text = str(cell.value) if cell.value is not None else ""
172
- if cell_text.strip():
173
- row_cells.append(cell_text + "\t")
174
- if row_cells:
175
- text_parts.append("".join(row_cells))
176
- text_parts.append("\n")
177
- text_parts.append("\n")
178
- return "".join(text_parts)
179
-
180
- @classmethod
181
- def _parse_ppt(cls, file_bytes: bytes) -> str:
182
- return cls._run_textract(file_bytes, 'ppt')
183
-
184
- @staticmethod
185
- def _parse_pptx(file_bytes: bytes) -> str:
186
- import pptx
187
- with io.BytesIO(file_bytes) as stream:
188
- presentation = pptx.Presentation(stream)
189
- text_parts = []
190
- for slide in presentation.slides:
191
- for shape in slide.shapes:
192
- if shape.has_text_frame:
193
- text = shape.text_frame.text
194
- if text and text.strip():
195
- text_parts.append(text)
196
- return "\n".join(text_parts)
197
-
198
- @staticmethod
199
- def _parse_pdf(file_bytes: bytes) -> str:
200
- """Parses a PDF file's bytes and extracts text using PyMuPDF."""
201
- import pymupdf
202
- text_parts = []
203
- with io.BytesIO(file_bytes) as stream:
204
- with pymupdf.open(stream=stream) as doc:
205
- for page in doc:
206
- text_parts.append(page.get_text())
207
- return "\n".join(text_parts)
@@ -1,28 +0,0 @@
1
- User: USER,Path: C:\Program Files (x86)\BMG\CLARIOstar\User\Data\,Test run no.: 30
2
- Test name: 140205_HeLa-CCR5,Date: 13/03/2014,Time: 15:43:29
3
-
4
- Fluorescence (FI), multichromatic
5
-
6
- 1. Raw Data (355-20/455-30 1)
7
-
8
- ,1,2,3,4,5,6,7,8,9,10,11,12,
9
- A,1,2,3,4,5,6,7,8,9,10,11,12
10
- B,1,2,3,4,5,6,7,8,9,10,11,12
11
- C,1,2,3,4,5,6,7,8,9,10,11,12
12
- D,1,2,3,4,5,6,7,8,9,10,11,12
13
- E,1,2,3,4,5,6,7,8,9,10,11,12
14
- F,1,2,3,4,5,6,7,8,9,10,11,12
15
- G,1,2,3,4,5,6,7,8,9,10,11,12
16
- H,1,2,3,4,5,6,7,8,9,10,11,12
17
-
18
- 2. Raw Data (610-30/675-50 2)
19
-
20
- ,1,2,3,4,5,6,7,8,9,10,11,12,
21
- A,2,2,3,4,5,6,7,8,9,10,11,12
22
- B,1,2,3,4,5,6,7,8,9,10,11,12
23
- C,1,2,3,4,5,6,7,8,9,10,11,12
24
- D,1,2,3,4,5,6,7,8,9,10,11,12
25
- E,1,2,3,4,5,6,7,8,9,10,11,12
26
- F,1,2,3,4,5,6,7,8,9,10,11,12
27
- G,1,2,3,4,5,6,7,8,9,10,11,12
28
- H,1,2,3,4,5,6,7,8,9,10,11,12
@@ -1,43 +0,0 @@
1
- import unittest
2
-
3
- from sapiopylib.rest.User import SapioUser
4
-
5
- from sapiopycommons.files.assay_plate_reader import AssayPlateReader, ProcessAssayPlateRequest, AssayFileLoadResult, \
6
- AssayResultDatum
7
-
8
- user = SapioUser(url="https://linux-vm:8443/webservice/api", verify_ssl_cert=False,
9
- guid="66c2bea5-7cb2-4bfc-a413-304a3f4c3f33",
10
- username="yqiao_api", password="Password1!")
11
- processor = AssayPlateReader(user)
12
-
13
- class AssayPlateReaderProcessingTest(unittest.TestCase):
14
- def test_bmg_labtech_96(self):
15
- """
16
- This is just start of some tests. The more rig test is in sapio-commons java unit tests, per default config instead of just 1 config on a little bit of canary test.
17
- """
18
- file_data: bytes
19
- with open("BMGLabtech96.txt", "rb") as file:
20
- file_data = file.read()
21
- file_load_result: AssayFileLoadResult = processor.process_plate_reader_data(ProcessAssayPlateRequest(8, 12, None, "BMGLabtech96.txt", file_data, "BMG Labtech"))
22
- self.assertEqual(len(file_load_result.plateResultList), 2)
23
- plates = file_load_result.plateResultList
24
- # Find the plate that is labelled "Raw Data (355-20/455-30 1)" as channel.
25
- plate = next((p for p in plates if p.resultIdent and p.resultIdent.channelIdOrBlock == "Raw Data (355-20/455-30 1)"), None)
26
- self.assertIsNotNone(plate)
27
- # The plate should have plate ID "140205_HeLa-CCR5"
28
- self.assertEqual(plate.resultIdent.plateId, "140205_HeLa-CCR5")
29
- # Value of A1 should be 1
30
- a1_read = next((d for d in plate.resultDatum if d.rowPosition == "A" and d.columnPosition == "1"), None)
31
- self.assertIsNotNone(a1_read)
32
- self.assertEqual(a1_read.valueByPropertyName.get(AssayResultDatum.DEFAULT_PROPERTY_NAME), 1)
33
- # Value of H12 should be 12
34
- h12_read = next((d for d in plate.resultDatum if d.rowPosition == "H" and d.columnPosition == "12"), None)
35
- self.assertIsNotNone(h12_read)
36
- self.assertEqual(h12_read.valueByPropertyName.get(AssayResultDatum.DEFAULT_PROPERTY_NAME), 12)
37
- # Find the plate labelled "Raw Data (610-30/675-50 2)"
38
- plate = next((p for p in plates if p.resultIdent and p.resultIdent.channelIdOrBlock == "Raw Data (610-30/675-50 2)"), None)
39
- self.assertIsNotNone(plate)
40
- # The plate should have plate ID "140205_HeLa-CCR5"
41
- self.assertEqual(plate.resultIdent.plateId, "140205_HeLa-CCR5")
42
-
43
-