copick-utils 0.5.0__tar.gz → 0.6.0__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: copick-utils
3
- Version: 0.5.0
3
+ Version: 0.6.0
4
4
  Summary: Utilities for copick
5
5
  License: MIT
6
6
  Author: Kyle Harrington
@@ -15,7 +15,6 @@ Classifier: Programming Language :: Python :: 3.10
15
15
  Classifier: Programming Language :: Python :: 3.11
16
16
  Classifier: Programming Language :: Python :: 3.12
17
17
  Classifier: Programming Language :: Python :: 3.13
18
- Classifier: Programming Language :: Python :: 3.8
19
18
  Classifier: Programming Language :: Python :: Implementation :: CPython
20
19
  Classifier: Programming Language :: Python :: Implementation :: PyPy
21
20
  Requires-Dist: copick (>=0.8.0)
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
4
4
 
5
5
  [tool.poetry]
6
6
  name = "copick-utils"
7
- version = "0.5.0"
7
+ version = "0.6.0"
8
8
  description = "Utilities for copick"
9
9
  readme = "README.md"
10
10
  license = "MIT"
@@ -16,11 +16,11 @@ authors = [
16
16
  classifiers = [
17
17
  "Development Status :: 4 - Beta",
18
18
  "Programming Language :: Python",
19
- "Programming Language :: Python :: 3.8",
20
19
  "Programming Language :: Python :: 3.9",
21
20
  "Programming Language :: Python :: 3.10",
22
21
  "Programming Language :: Python :: 3.11",
23
22
  "Programming Language :: Python :: 3.12",
23
+ "Programming Language :: Python :: 3.13",
24
24
  "Programming Language :: Python :: Implementation :: CPython",
25
25
  "Programming Language :: Python :: Implementation :: PyPy",
26
26
  ]
@@ -0,0 +1,132 @@
1
+ import numpy as np
2
+
3
+ def tomogram(run,
4
+ voxel_size: float = 10,
5
+ algorithm: str = 'wbp',
6
+ raise_error: bool = False):
7
+
8
+ voxel_spacing_obj = run.get_voxel_spacing(voxel_size)
9
+
10
+ if voxel_spacing_obj is None:
11
+ # Query Avaiable Voxel Spacings
12
+ availableVoxelSpacings = [tomo.voxel_size for tomo in run.voxel_spacings]
13
+
14
+ # Report to the user which voxel spacings they can use
15
+ message = (f"[Warning] No tomogram found for {run.name} with voxel size {voxel_size} and tomogram type {algorithm}"
16
+ f"Available spacings are: {', '.join(map(str, availableVoxelSpacings))}" )
17
+ if raise_error:
18
+ raise ValueError(message)
19
+ else:
20
+ print(message)
21
+ return None
22
+
23
+ tomogram = voxel_spacing_obj.get_tomogram(algorithm)
24
+ if tomogram is None:
25
+ # Get available algorithms
26
+ availableAlgorithms = [tomo.tomo_type for tomo in run.get_voxel_spacing(voxel_size).tomograms]
27
+
28
+ # Report to the user which algorithms are available
29
+ message = (f"[Warning] No tomogram found for {run.name} with voxel size {voxel_size} and tomogram type {algorithm}"
30
+ f"Available algorithms are: {', '.join(availableAlgorithms)}")
31
+ if raise_error:
32
+ raise ValueError(message)
33
+ else:
34
+ print(message)
35
+ return None
36
+
37
+ return tomogram.numpy()
38
+
39
+ def segmentation(run,
40
+ voxel_spacing: float,
41
+ segmentation_name: str,
42
+ session_id=None,
43
+ user_id=None,
44
+ raise_error = False):
45
+
46
+ seg = run.get_segmentations(name=segmentation_name,
47
+ session_id = session_id,
48
+ user_id = user_id,
49
+ voxel_size = voxel_spacing)
50
+
51
+ # No Segmentations Are Available, Result in Error
52
+ if len(seg) == 0:
53
+ # Get all available segmentations with their metadata
54
+ available_segs = run.get_segmentations(voxel_size=voxel_spacing)
55
+ seg_info = [(s.name, s.user_id, s.session_id) for s in available_segs]
56
+
57
+ # Format the information for display
58
+ seg_details = [f"(name: {name}, user_id: {uid}, session_id: {sid})"
59
+ for name, uid, sid in seg_info]
60
+
61
+ message = ( f'\nNo segmentation found matching:\n'
62
+ f' name: {segmentation_name}, user_id: {user_id}, session_id: {session_id}\n'
63
+ f'Available segmentations in {run.name} are:\n ' +
64
+ '\n '.join(seg_details) )
65
+ if raise_error:
66
+ raise ValueError(message)
67
+ else:
68
+ print(message)
69
+ return None
70
+
71
+ # No Segmentations Are Available, Result in Error
72
+ if len(seg) > 1:
73
+ print(f'[Warning] More Than 1 Segmentation is Available for the Query Information. '
74
+ f'Available Segmentations are: {seg} '
75
+ f'Defaulting to Loading: {seg[0]}\n')
76
+ seg = seg[0]
77
+
78
+ return seg.numpy()
79
+
80
+ def coordinates(run, # CoPick run object containing the segmentation data
81
+ name: str, # Name of the object or protein for which coordinates are being extracted
82
+ user_id: str, # Identifier of the user that generated the picks
83
+ session_id: str = None, # Identifier of the session that generated the picks
84
+ voxel_size: float = 10, # Voxel size of the tomogram, used for scaling the coordinates
85
+ raise_error: bool = False):
86
+
87
+ # Retrieve the pick points associated with the specified object and user ID
88
+ picks = run.get_picks(object_name=name, user_id=user_id, session_id=session_id)
89
+
90
+ if len(picks) == 0:
91
+ # Get all available segmentations with their metadata
92
+
93
+ available_picks = run.get_picks()
94
+ picks_info = [(s.pickable_object_name, s.user_id, s.session_id) for s in available_picks]
95
+
96
+ # Format the information for display
97
+ picks_details = [f"(name: {name}, user_id: {uid}, session_id: {sid})"
98
+ for name, uid, sid in picks_info]
99
+
100
+ message = ( f'\nNo picks found matching:\n'
101
+ f' name: {name}, user_id: {user_id}, session_id: {session_id}\n'
102
+ f'Available picks are:\n '
103
+ + '\n '.join(picks_details) )
104
+ if raise_error:
105
+ raise ValueError(message)
106
+ else:
107
+ print(message)
108
+ return None
109
+ elif len(picks) > 1:
110
+ # Format pick information for display
111
+ picks_info = [(p.pickable_object_name, p.user_id, p.session_id) for p in picks]
112
+ picks_details = [f"(name: {name}, user_id: {uid}, session_id: {sid})"
113
+ for name, uid, sid in picks_info]
114
+
115
+ print(f'[Warning] More than 1 pick is available for the query information.'
116
+ f'\nAvailable picks are:\n ' +
117
+ '\n '.join(picks_details) +
118
+ f'\nDefaulting to loading:\n {picks[0]}\n')
119
+ points = picks[0].points
120
+
121
+ # Initialize an array to store the coordinates
122
+ nPoints = len(picks[0].points) # Number of points retrieved
123
+ coordinates = np.zeros([len(picks[0].points), 3]) # Create an empty array to hold the (z, y, x) coordinates
124
+
125
+ # Iterate over all points and convert their locations to coordinates in voxel space
126
+ for ii in range(nPoints):
127
+ coordinates[ii,] = [points[ii].location.z / voxel_size, # Scale z-coordinate by voxel size
128
+ points[ii].location.y / voxel_size, # Scale y-coordinate by voxel size
129
+ points[ii].location.x / voxel_size] # Scale x-coordinate by voxel size
130
+
131
+ # Return the array of coordinates
132
+ return coordinates
File without changes
File without changes
File without changes