sapiopycommons 2024.10.24a342__py3-none-any.whl → 2024.10.29a346__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.

@@ -1,77 +0,0 @@
1
- from __future__ import annotations
2
-
3
- from weakref import WeakValueDictionary
4
-
5
- from sapiopylib.rest.User import SapioUser
6
- from databind.json import dumps
7
-
8
- from sapiopycommons.flowcyto.flowcyto_data import FlowJoWorkspaceInputJson, UploadFCSInputJson, \
9
- ComputeFlowStatisticsInputJson
10
-
11
-
12
- class FlowCytoManager:
13
- """
14
- This manager includes flow cytometry analysis tools that would require FlowCyto license to use.
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
39
-
40
- def create_flowjo_workspace(self, workspace_input: FlowJoWorkspaceInputJson) -> int:
41
- """
42
- Create FlowJo Workspace and return the workspace record ID of workspace root record,
43
- after successful creation.
44
- :param workspace_input: the request data payload.
45
- :return: The new workspace record ID.
46
- """
47
- payload = dumps(workspace_input, FlowJoWorkspaceInputJson)
48
- response = self._user.plugin_post("flowcyto/workspace", payload=payload, is_payload_plain_text=True)
49
- self._user.raise_for_status(response)
50
- return int(response.json())
51
-
52
- def upload_fcs_for_sample(self, upload_input: UploadFCSInputJson) -> int:
53
- """
54
- Upload FCS file as root of the sample FCS.
55
- :param upload_input: The request data payload
56
- :return: The root FCS file uploaded under sample.
57
- """
58
- payload = dumps(upload_input, UploadFCSInputJson)
59
- response = self._user.plugin_post("flowcyto/fcs", payload=payload, is_payload_plain_text=True)
60
- self._user.raise_for_status(response)
61
- return int(response.json())
62
-
63
- def compute_statistics(self, stat_compute_input: ComputeFlowStatisticsInputJson) -> list[int]:
64
- """
65
- Requests to compute flow cytometry statistics.
66
- The children are of type FCSStatistic.
67
- If the FCS files have not been evaluated yet,
68
- then the lazy evaluation will be performed immediately prior to computing statistics, which can take longer.
69
- If any new statistics are computed as children of FCS, they will be returned in the result record id list.
70
- Note: if input has multiple FCS files, the client should try to get parent FCS file from each record to figure out which one is for which FCS.
71
- :param stat_compute_input:
72
- :return:
73
- """
74
- payload = dumps(stat_compute_input, ComputeFlowStatisticsInputJson)
75
- response = self._user.plugin_post("flowcyto/statistics", payload=payload, is_payload_plain_text=True)
76
- self._user.raise_for_status(response)
77
- return list(response.json())
@@ -1,75 +0,0 @@
1
- import base64
2
- from enum import Enum
3
-
4
- from databind.core.dataclasses import dataclass
5
-
6
-
7
- class ChannelStatisticType(Enum):
8
- """
9
- All supported channel statistics type.
10
- """
11
- MEAN = "(Mean) MFI"
12
- MEDIAN = "(Median) MFI"
13
- STD_EV = "Std. Dev."
14
- COEFFICIENT_OF_VARIATION = "CV"
15
-
16
- display_name: str
17
-
18
- def __init__(self, display_name: str):
19
- self.display_name = display_name
20
-
21
-
22
- @dataclass
23
- class ChannelStatisticsParameterJSON:
24
- channelNameList: list[str]
25
- statisticsType: ChannelStatisticType
26
-
27
- def __init__(self, channel_name_list: list[str], stat_type: ChannelStatisticType):
28
- self.channelNameList = channel_name_list
29
- self.statisticsType = stat_type
30
-
31
-
32
- @dataclass
33
- class ComputeFlowStatisticsInputJson:
34
- fcsFileRecordIdList: list[int]
35
- statisticsParameterList: list[ChannelStatisticsParameterJSON]
36
-
37
- def __init__(self, fcs_file_record_id_list: list[int], statistics_parameter_list: list[ChannelStatisticsParameterJSON]):
38
- self.fcsFileRecordIdList = fcs_file_record_id_list
39
- self.statisticsParameterList = statistics_parameter_list
40
-
41
-
42
- @dataclass
43
- class FlowJoWorkspaceInputJson:
44
- filePath: str
45
- base64Data: str
46
-
47
- def __init__(self, filePath: str, file_data: bytes):
48
- self.filePath = filePath
49
- self.base64Data = base64.b64encode(file_data).decode('utf-8')
50
-
51
-
52
- @dataclass
53
- class UploadFCSInputJson:
54
- """
55
- Request to upload new FCS file
56
- Attributes:
57
- filePath: The file name of the FCS file to be uploaded. For FlowJo workspace, this is important to match the file in group (via file names).
58
- attachmentDataType: the attachment data type that contains already-uploaded FCS data.
59
- attachmentRecordId: the attachment record ID that contains already-uploaded FCS data.
60
- associatedRecordDataType: the "parent" association for the FCS. Can either be a workspace or a sample record.
61
- associatedRecordId: the "parent" association for the FCS. Can either be a workspace or a sample record.
62
- """
63
- filePath: str
64
- attachmentDataType: str
65
- attachmentRecordId: int
66
- associatedRecordDataType: str
67
- associatedRecordId: int
68
-
69
- def __init__(self, associated_record_data_type: str, associated_record_id: int,
70
- file_path: str, attachment_data_type: str, attachment_record_id: int):
71
- self.filePath = file_path
72
- self.attachmentDataType = attachment_data_type
73
- self.attachmentRecordId = attachment_record_id
74
- self.associatedRecordDataType = associated_record_data_type
75
- self.associatedRecordId = associated_record_id