small-fish-gui 2.1.3__py3-none-any.whl → 2.1.4__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.
@@ -37,7 +37,7 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37
37
  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
38
38
  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39
39
  """
40
- __version__ = "2.1.3"
40
+ __version__ = "2.1.4"
41
41
  __wiki__ = "https://github.com/2Echoes/small_fish_gui/wiki"
42
42
 
43
43
  import os, platform
@@ -228,7 +228,7 @@ def _global_coloc(acquisition_id1,acquisition_id2, result_dataframe, colocalisat
228
228
  - fraction_spot2_coloc_spots
229
229
 
230
230
  """
231
-
231
+ CLUSTER_KEY = "clustered_spots_coords"
232
232
  acquisition1 = result_dataframe.loc[result_dataframe['acquisition_id'] == acquisition_id1]
233
233
  acquisition2 = result_dataframe.loc[result_dataframe['acquisition_id'] == acquisition_id2]
234
234
 
@@ -259,7 +259,7 @@ def _global_coloc(acquisition_id1,acquisition_id2, result_dataframe, colocalisat
259
259
  fraction_spots1_coloc_spots2 = np.nan
260
260
  fraction_spots2_coloc_spots1 = np.nan
261
261
 
262
- if 'clusters' in acquisition1.columns :
262
+ if CLUSTER_KEY in acquisition1.columns :
263
263
  try :
264
264
  clusters_id_1 = np.array(acquisition1.iloc[0].at['spots_cluster_id'], dtype=int)
265
265
  fraction_spots2_coloc_cluster1 = spots_colocalisation(spot_list1=spots2, spot_list2=spots1[clusters_id_1 != -1], distance= colocalisation_distance, voxel_size=voxel_size) / spot2_total
@@ -272,7 +272,7 @@ def _global_coloc(acquisition_id1,acquisition_id2, result_dataframe, colocalisat
272
272
 
273
273
  else : fraction_spots2_coloc_cluster1 = np.nan
274
274
 
275
- if 'clusters' in acquisition2.columns :
275
+ if CLUSTER_KEY in acquisition2.columns :
276
276
  try :
277
277
  clusters_id_2 = np.array(acquisition2.iloc[0].at['spots_cluster_id'], dtype=int)
278
278
  fraction_spots1_coloc_cluster2 = spots_colocalisation(spot_list1=spots1, spot_list2=spots2[clusters_id_2 != -1], distance= colocalisation_distance, voxel_size=voxel_size) / spot1_total
@@ -285,7 +285,7 @@ def _global_coloc(acquisition_id1,acquisition_id2, result_dataframe, colocalisat
285
285
 
286
286
  else : fraction_spots1_coloc_cluster2 = np.nan
287
287
 
288
- if 'clusters' in acquisition2.columns and 'clusters' in acquisition1.columns :
288
+ if CLUSTER_KEY in acquisition2.columns and CLUSTER_KEY in acquisition1.columns :
289
289
  try :
290
290
  total_clustered_spots1 = len(spots1[clusters_id_1 != -1])
291
291
  total_clustered_spots2 = len(spots2[clusters_id_2 != -1])
@@ -340,6 +340,8 @@ def _cell_coloc(
340
340
 
341
341
  acquisition1 = result_dataframe.loc[result_dataframe['acquisition_id'] == acquisition_id1]
342
342
  acquisition2 = result_dataframe.loc[result_dataframe['acquisition_id'] == acquisition_id2]
343
+ has_clusters_1 = "clustered_spots_coords" in acquisition1.columns or "clusters" in acquisition1.columns
344
+ has_clusters_2 = "clustered_spots_coords" in acquisition2.columns or "clusters" in acquisition2.columns
343
345
 
344
346
  acquisition_name_id1 = acquisition1['name'].iat[0]
345
347
  acquisition_name_id2 = acquisition2['name'].iat[0]
@@ -357,15 +359,22 @@ def _cell_coloc(
357
359
 
358
360
  #Putting spots lists in 2 cols for corresponding cells
359
361
  pivot_values_columns = ['rna_coords', 'total_rna_number']
360
- if 'clusters' in acquisition2.columns or 'clusters' in acquisition1.columns:
362
+ if has_clusters_1 or has_clusters_2 :
361
363
  pivot_values_columns.extend(['clustered_spots_coords','clustered_spot_number'])
362
- print(cell_dataframe.loc[:,["clustered_spots_coords"]])
363
364
  cell_dataframe.loc[:,['cell_id']] = cell_dataframe['cell_id'].astype(int)
365
+
366
+ if has_clusters_1 or has_clusters_2 :
367
+ target_column = "clustered_spots_coords"
368
+ target_mask = cell_dataframe.loc[:, target_column].apply(len) == 0
369
+ cell_dataframe.loc[target_mask,target_column] = pd.Series([np.empty(shape=(0,3), dtype=int)]* sum(target_mask), dtype=object)
370
+
364
371
  colocalisation_df = cell_dataframe.pivot(
365
372
  columns=['name', 'acquisition_id'],
366
373
  values= pivot_values_columns,
367
374
  index= 'cell_id'
368
375
  )
376
+ colocalisation_df = colocalisation_df.dropna(axis=0)
377
+
369
378
  #spots _vs spots
370
379
  colocalisation_df[("spots_with_spots_count",coloc_name_forward,"forward")] = colocalisation_df['rna_coords'].apply(
371
380
  lambda x: spots_colocalisation(
@@ -387,10 +396,9 @@ def _cell_coloc(
387
396
  )
388
397
  colocalisation_df[("spots_with_spots_fraction",coloc_name_backward,"backward")] = colocalisation_df[("spots_with_spots_count",coloc_name_backward,"backward")].astype(float) / colocalisation_df[('total_rna_number',acquisition_name_id2,acquisition_id2)].astype(float)
389
398
 
390
- if 'clusters' in acquisition2.columns:
391
- if len(acquisition2['clusters'].iat[0]) > 0 or len(acquisition2['clustered_spots_coords'][acquisition2['clustered_spots_coords'] != -1]) > 0 :
392
-
393
- print("COLOCALISATION_DF\n", colocalisation_df.loc[:,('clustered_spots_coords',acquisition_name_id2,acquisition_id2)])
399
+ if has_clusters_2:
400
+ CLUSTER_KEY2 = "clustered_spots_coords" if "clustered_spots_coords" in acquisition2.columns else "clusters"
401
+ if len(acquisition2[CLUSTER_KEY2].iat[0]) > 0 :
394
402
 
395
403
  #spots to clusters
396
404
  colocalisation_df[("spots_with_clustered_spots_count",coloc_name_forward,"forward")] = colocalisation_df.apply(
@@ -403,8 +411,9 @@ def _cell_coloc(
403
411
  )
404
412
  colocalisation_df[("spots_with_clustered_spots_fraction",coloc_name_forward,"forward")] = colocalisation_df[("spots_with_clustered_spots_count",coloc_name_forward,"forward")].astype(float) / colocalisation_df[('total_rna_number',acquisition_name_id1,acquisition_id1)].astype(float)
405
413
 
406
- if 'clusters' in acquisition1.columns:
407
- if len(acquisition1['clusters'].iat[0]) > 0 :
414
+ if has_clusters_1:
415
+ CLUSTER_KEY1 = "clustered_spots_coords" if "clustered_spots_coords" in acquisition1.columns else "clusters"
416
+ if len(acquisition1[CLUSTER_KEY1].iat[0]) > 0 :
408
417
  colocalisation_df[("spots_with_clustered_spots_count",coloc_name_backward,"backward")] = colocalisation_df.apply(
409
418
  lambda x: spots_colocalisation(
410
419
  spot_list1= x[('rna_coords',acquisition_name_id2,acquisition_id2)],
@@ -416,8 +425,9 @@ def _cell_coloc(
416
425
 
417
426
  colocalisation_df[("spots_with_clustered_spots_fraction",coloc_name_backward,"backward")] = colocalisation_df[("spots_with_clustered_spots_count",coloc_name_backward,"backward")].astype(float) / colocalisation_df[('total_rna_number',acquisition_name_id2,acquisition_id2)].astype(float)
418
427
 
419
- if 'clusters' in acquisition2.columns and 'clusters' in acquisition1.columns:
420
- if len(acquisition1['clusters'].iat[0]) > 0 and len(acquisition2['clusters'].iat[0]) > 0 :
428
+ if has_clusters_1 and has_clusters_2:
429
+
430
+ if len(acquisition1[CLUSTER_KEY1].iat[0]) > 0 and len(acquisition2[CLUSTER_KEY2].iat[0]) > 0 :
421
431
  #clusters to clusters
422
432
  colocalisation_df[("clustered_spots_with_clustered_spots_count",coloc_name_forward,"forward")] = colocalisation_df.apply(
423
433
  lambda x: spots_colocalisation(
@@ -441,7 +451,7 @@ def _cell_coloc(
441
451
 
442
452
  colocalisation_df = colocalisation_df.sort_index(axis=0).sort_index(axis=1, level=0)
443
453
 
444
- if 'clustered_spots_coords' in cell_dataframe.columns : colocalisation_df = colocalisation_df.drop('clustered_spots_coords', axis=1)
454
+ if 'clustered_spots_coords' in colocalisation_df.columns : colocalisation_df = colocalisation_df.drop('clustered_spots_coords', axis=1)
445
455
  colocalisation_df = colocalisation_df.drop('rna_coords', axis=1)
446
456
  colocalisation_df['voxel_size'] = [voxel_size]*len(colocalisation_df)
447
457
  colocalisation_df['pair_name'] = [(acquisition_name_id1, acquisition_name_id2)] * len(colocalisation_df)
@@ -452,11 +462,19 @@ def _cell_coloc(
452
462
  return colocalisation_df
453
463
 
454
464
  @add_default_loading
455
- def launch_colocalisation(acquisition_id1, acquisition_id2, result_dataframe, cell_result_dataframe, colocalisation_distance, global_coloc_df, cell_coloc_df: dict) :
465
+ def launch_colocalisation(
466
+ acquisition_id1 : int,
467
+ acquisition_id2 : int,
468
+ result_dataframe : pd.DataFrame,
469
+ cell_result_dataframe : pd.DataFrame,
470
+ colocalisation_distance : pd.DataFrame,
471
+ global_coloc_df : pd.DataFrame,
472
+ cell_coloc_df: dict) :
456
473
 
457
474
 
458
475
  if acquisition_id1 in list(cell_result_dataframe['acquisition_id']) and acquisition_id2 in list(cell_result_dataframe['acquisition_id']) :
459
476
  print("Launching cell to cell colocalisation.")
477
+
460
478
  new_coloc = _cell_coloc(
461
479
  acquisition_id1 = acquisition_id1,
462
480
  acquisition_id2 = acquisition_id2,
@@ -213,23 +213,26 @@ def initiate_detection(user_parameters : pipeline_parameters, map_, shape) :
213
213
  #Attempt to read voxel size from metadata
214
214
  voxel_size = get_voxel_size(user_parameters['image_path'])
215
215
  if voxel_size is None :
216
- if not user_parameters.get('voxel_size') is None:
217
- pass
218
- else :
216
+ if user_parameters.get('voxel_size') is None:
219
217
  detection_parameters['voxel_size_z'] = None
220
218
  detection_parameters['voxel_size_y'] = None
221
219
  detection_parameters['voxel_size_x'] = None
220
+ else :
221
+ if is_3D_stack : detection_parameters['voxel_size_z'] = user_parameters.get['voxel_size'][0]
222
+ detection_parameters['voxel_size_y'] = user_parameters.get['voxel_size'][0 + is_3D_stack]
223
+ detection_parameters['voxel_size_x'] = user_parameters.get['voxel_size'][1 + is_3D_stack]
224
+
222
225
  else :
223
226
  detection_parameters['voxel_size'] = [round(v) if isinstance(v, (float,int)) else None for v in voxel_size]
224
- detection_parameters['voxel_size_z'] = detection_parameters['voxel_size'][0] if isinstance(detection_parameters['voxel_size'][0], (float,int)) else None
225
- detection_parameters['voxel_size_y'] = detection_parameters['voxel_size'][1] if isinstance(detection_parameters['voxel_size'][1], (float,int)) else None
226
- detection_parameters['voxel_size_x'] = detection_parameters['voxel_size'][2] if isinstance(detection_parameters['voxel_size'][2], (float,int)) else None
227
+ detection_parameters['voxel_size_z'] = detection_parameters['voxel_size'][0] if isinstance(detection_parameters.get('voxel_size')[0], (float,int)) else None
228
+ detection_parameters['voxel_size_y'] = detection_parameters['voxel_size'][0 + is_3D_stack] if isinstance(detection_parameters.get('voxel_size')[0 + is_3D_stack], (float,int)) else None
229
+ detection_parameters['voxel_size_x'] = detection_parameters['voxel_size'][1 + is_3D_stack] if isinstance(detection_parameters.get('voxel_size')[1 + is_3D_stack], (float,int)) else None
227
230
 
228
231
  #Setting default spot size to 1.5 voxel
229
232
  if detection_parameters.get('spot_size') is None and not detection_parameters.get('voxel_size') is None:
230
233
  detection_parameters['spot_size_z'] = round(detection_parameters['voxel_size_z']*1.5) if isinstance(detection_parameters.get('voxel_size_z'), (float,int)) else None
231
- detection_parameters['spot_size_y'] = round(detection_parameters['voxel_size_y']*1.5) if isinstance(detection_parameters['voxel_size_y'],(float,int)) else None
232
- detection_parameters['spot_size_x'] = round(detection_parameters['voxel_size_x']*1.5) if isinstance(detection_parameters['voxel_size_x'],(float,int)) else None
234
+ detection_parameters['spot_size_y'] = round(detection_parameters['voxel_size_y']*1.5) if isinstance(detection_parameters.get('voxel_size_y'),(float,int)) else None
235
+ detection_parameters['spot_size_x'] = round(detection_parameters['voxel_size_x']*1.5) if isinstance(detection_parameters.get('voxel_size_x'),(float,int)) else None
233
236
 
234
237
  while True :
235
238
  detection_parameters = detection_parameters_promt(
@@ -60,6 +60,17 @@ def compute_Spots(
60
60
  else :
61
61
  in_nuc_list = np.nan
62
62
  if type(cell_label) != type(None) :
63
+
64
+ # Collect all labels that are on fov edge
65
+ on_edge_labels = np.unique(
66
+ np.concatenate([
67
+ cell_label[:,0],
68
+ cell_label[:,-1],
69
+ cell_label[0,:],
70
+ cell_label[-1,:],
71
+ ])
72
+ ).astype(int)
73
+
63
74
  if cell_label.ndim == 3 :
64
75
  cell_label_list = list(cell_label[index])
65
76
  else :
@@ -79,6 +90,10 @@ def compute_Spots(
79
90
  'coordinates' : coord_list,
80
91
  'cluster_id' : cluster_id,
81
92
  })
93
+
94
+ if type(cell_label) != type(None) : #Filter on edge cells
95
+ target_index = Spots.loc[Spots["cell_label"].isin(on_edge_labels)].index
96
+ Spots.loc[target_index,["cell_label"]] = 0
82
97
 
83
98
  return Spots
84
99
 
@@ -126,7 +141,6 @@ def reconstruct_acquisition_data(
126
141
  clusters = np.empty(shape=(0,5), dtype=int)
127
142
  spot_cluster_id = Spots['cluster_id'].to_numpy().astype(int)
128
143
  clustered_spots = spots[spot_cluster_id != -1]
129
- print("clustered_spots : ", clustered_spots)
130
144
 
131
145
  new_acquisition = pd.DataFrame({
132
146
  'acquisition_id' : [max_id + 1],
@@ -151,10 +165,6 @@ def reconstruct_acquisition_data(
151
165
  'voxel_size' : [voxel_size],
152
166
  })
153
167
 
154
- print("Reconstructed acquisition : \n", new_acquisition)
155
- print("\n", new_acquisition.columns)
156
- if 'clusters' in new_acquisition.columns :
157
- print("\n", new_acquisition['clusters'])
158
168
 
159
169
  return new_acquisition
160
170
 
@@ -176,23 +186,25 @@ def reconstruct_cell_data(
176
186
  ) :
177
187
 
178
188
  has_cluster = not Spots['cluster_id'].isna().all()
189
+ if 'cell_label' in Spots.columns : Spots = Spots.loc[Spots["cell_label"] !=0]
179
190
  coordinates = reconstruct_spots(Spots['coordinates'])
180
- Spots['coordinates'] = pd.Series(coordinates.tolist(), dtype=object, index= Spots.index)
191
+ Spots.loc[:,['coordinates']] = pd.Series(coordinates.tolist(), dtype=object, index= Spots.index)
181
192
 
182
193
  cell = Spots.groupby('cell_label')['coordinates'].apply(np.array).rename("rna_coords").reset_index(drop=False)
183
194
 
184
195
  #Handle cells with no spots
185
196
  na_mask =cell[cell['rna_coords'].isna()].index
186
197
  cell.loc[na_mask, ['rna_coords']] = pd.Series([np.empty(shape=(0,3))]*len(na_mask), dtype= object, index=na_mask)
198
+ cell.loc[~na_mask, "rna_coords"] = cell.loc[~na_mask, "rna_coords"].apply(list).apply(np.array)
187
199
 
188
200
  cell['total_rna_number'] = cell['rna_coords'].apply(len)
189
-
190
201
  if has_cluster :
191
202
  cell['clustered_spots_coords'] = Spots[Spots['cluster_id'] !=-1].groupby('cell_label')['coordinates'].apply(np.array).rename("clustered_spots_coords")
192
203
 
193
204
  #Handle cells with no clusters
194
205
  na_mask =cell[cell['clustered_spots_coords'].isna()].index
195
206
  cell.loc[na_mask, ['clustered_spots_coords']] = pd.Series([np.empty(shape=(0,3))]*len(na_mask), dtype= object, index=na_mask)
207
+ cell["clustered_spots_coords"] = cell["clustered_spots_coords"].apply(list).apply(np.array)
196
208
 
197
209
  cell['clustered_spot_number'] = cell['clustered_spots_coords'].apply(len)
198
210
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: small_fish_gui
3
- Version: 2.1.3
3
+ Version: 2.1.4
4
4
  Summary: Small Fish is a python application for the analysis of smFish images. It provides a ready to use graphical interface to combine famous python packages for cell analysis without any need for coding.
5
5
  Project-URL: Homepage, https://github.com/SmallFishGUI/small_fish_gui
6
6
  Project-URL: Wiki, https://github.com/SmallFishGUI/small_fish_gui/wiki
@@ -1,4 +1,4 @@
1
- small_fish_gui/__init__.py,sha256=LXbX5bfmwGeIZqpQAvwXrknqBfev-XlPYsJqXKB2Ch8,2163
1
+ small_fish_gui/__init__.py,sha256=RhdSeAF9XtPM-QArrG71J9oJeFkP8qVJLGLuDyVG9BQ,2163
2
2
  small_fish_gui/__main__.py,sha256=xwpFMDuo0kkYvPamyhlTHJ68bymDfbRpPzKy3SKwezY,1639
3
3
  small_fish_gui/hints.py,sha256=NEKqCbjXF3guHnc1dzq_LYYGlTxIV6z6wtdwVlmgHos,3349
4
4
  small_fish_gui/main_menu.py,sha256=z0ZlidWNGHLYYnBx2Z1i2IX_EGQr-HtIlsOQl-yTw4o,6273
@@ -31,16 +31,16 @@ small_fish_gui/interface/testing.py,sha256=AUdqmFJ6kBvFTOLRfZZJBBe3nm1key2bGpUDX
31
31
  small_fish_gui/interface/user_settings.py,sha256=vMpj-s9tzMKQy1CdJ3SO-6yAknU-ZIMT0RZQs8WAGPY,2620
32
32
  small_fish_gui/pipeline/__init__.py,sha256=Oww6dcuvnktl5jFKLriz8ZXObKo9MkneE739A8C1reY,739
33
33
  small_fish_gui/pipeline/_bigfish_wrapers.py,sha256=WcIu5HLc4bUuU8qmsINP5snXef3Tx9zJDNKES-SiftA,9776
34
- small_fish_gui/pipeline/_colocalisation.py,sha256=r96rrWS5lim5bPCcoQMs83DRApCGxJ3ADruFhhYHxN0,22228
34
+ small_fish_gui/pipeline/_colocalisation.py,sha256=IEH7_okSG5Wfm7rBxudtKwCti_Op3mP-XXLUkDD08k4,22789
35
35
  small_fish_gui/pipeline/_custom_errors.py,sha256=tQ-AUhgzIFpK30AZiQQrtHCHyGVRDdAoIjzL0Fk-1pA,43
36
36
  small_fish_gui/pipeline/_preprocess.py,sha256=zfwhNoAUkVv1TYlyffNQkSTitMXTDokADabBeHuB58U,15766
37
37
  small_fish_gui/pipeline/actions.py,sha256=dtRCf_UKg-Y9uV1jCBeASeuR7-pZ8dHVEYHs7MW-0pg,21263
38
- small_fish_gui/pipeline/detection.py,sha256=IE0Wf9NaHcxkCv1cjrOdyfnQUzv8SlXilIT7KI8INP4,35988
38
+ small_fish_gui/pipeline/detection.py,sha256=JOvk1fuJT2EudfqSVAc5iwIwns7OUo0n5o4vxgiVJUI,36353
39
39
  small_fish_gui/pipeline/segmentation.py,sha256=m9XW8XiWCSpGFdi6It6RkeDYTiKtNhfj30kUSBG8pNo,32023
40
- small_fish_gui/pipeline/spots.py,sha256=lG9hvn0MqnDWUr2VfSEm8LHoprSlGoDHQFuQGlJHaxM,6807
40
+ small_fish_gui/pipeline/spots.py,sha256=oW8TVJK16K_LK_fpG_9GnCTCVCzmfedaGZswyboq2MI,7328
41
41
  small_fish_gui/pipeline/test.py,sha256=w4ZMGDmUDXxVgWTlZ2TKw19W8q5gcE9gLMKe0SWnRrw,2827
42
42
  small_fish_gui/pipeline/utils.py,sha256=dYV7WAJ375xM5RdaljjxeKvBC1niQvBl1E55SeIiIYo,563
43
- small_fish_gui-2.1.3.dist-info/METADATA,sha256=pFbXtb_Zd3RskgJg-chYrG11YZL32xahnim4TpuTusk,6553
44
- small_fish_gui-2.1.3.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
45
- small_fish_gui-2.1.3.dist-info/licenses/LICENSE,sha256=-iFy8VGBYs5VsHglKpk4D-hxqQ2jMJaqmfq_ulIzDks,1303
46
- small_fish_gui-2.1.3.dist-info/RECORD,,
43
+ small_fish_gui-2.1.4.dist-info/METADATA,sha256=F6zA2y4gOIPJm3SMChUUl0PHTGoc5ZHwJe_7rrVF0hk,6553
44
+ small_fish_gui-2.1.4.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
45
+ small_fish_gui-2.1.4.dist-info/licenses/LICENSE,sha256=-iFy8VGBYs5VsHglKpk4D-hxqQ2jMJaqmfq_ulIzDks,1303
46
+ small_fish_gui-2.1.4.dist-info/RECORD,,