spacr 0.3.0__py3-none-any.whl → 0.3.1__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.
spacr/core.py CHANGED
@@ -1672,9 +1672,9 @@ def preprocess_generate_masks(src, settings={}):
1672
1672
  time_ls=[]
1673
1673
  if check_mask_folder(src, 'cell_mask_stack'):
1674
1674
  start = time.time()
1675
- if settings['segmantation_model'] == 'cellpose':
1675
+ if settings['segmentation_mode'] == 'cellpose':
1676
1676
  generate_cellpose_masks(mask_src, settings, 'cell')
1677
- elif settings['segmantation_model'] == 'mediar':
1677
+ elif settings['segmentation_mode'] == 'mediar':
1678
1678
  generate_mediar_masks(mask_src, settings, 'cell')
1679
1679
  stop = time.time()
1680
1680
  duration = (stop - start)
@@ -1686,9 +1686,9 @@ def preprocess_generate_masks(src, settings={}):
1686
1686
  time_ls=[]
1687
1687
  if check_mask_folder(src, 'nucleus_mask_stack'):
1688
1688
  start = time.time()
1689
- if settings['segmantation_model'] == 'cellpose':
1689
+ if settings['segmentation_mode'] == 'cellpose':
1690
1690
  generate_cellpose_masks(mask_src, settings, 'nucleus')
1691
- elif settings['segmantation_model'] == 'mediar':
1691
+ elif settings['segmentation_mode'] == 'mediar':
1692
1692
  generate_mediar_masks(mask_src, settings, 'nucleus')
1693
1693
  stop = time.time()
1694
1694
  duration = (stop - start)
@@ -1700,9 +1700,9 @@ def preprocess_generate_masks(src, settings={}):
1700
1700
  time_ls=[]
1701
1701
  if check_mask_folder(src, 'pathogen_mask_stack'):
1702
1702
  start = time.time()
1703
- if settings['segmantation_model'] == 'cellpose':
1703
+ if settings['segmentation_mode'] == 'cellpose':
1704
1704
  generate_cellpose_masks(mask_src, settings, 'pathogen')
1705
- elif settings['segmantation_model'] == 'mediar':
1705
+ elif settings['segmentation_mode'] == 'mediar':
1706
1706
  generate_mediar_masks(mask_src, settings, 'pathogen')
1707
1707
  stop = time.time()
1708
1708
  duration = (stop - start)
@@ -1757,7 +1757,7 @@ def preprocess_generate_masks(src, settings={}):
1757
1757
  files_processed = i+1
1758
1758
  files_to_process = settings['examples_to_plot']
1759
1759
  print_progress(files_processed, files_to_process, n_jobs=1, time_ls=time_ls, batch_size=None, operation_type="Plot mask outlines")
1760
- print("Successfully completed run")
1760
+
1761
1761
  except Exception as e:
1762
1762
  print(f'Failed to plot image mask overly. Error: {e}')
1763
1763
  else:
spacr/io.py CHANGED
@@ -653,7 +653,6 @@ def _rename_and_organize_image_files(src, regex, batch_size=100, pick_slice=Fals
653
653
  from .utils import _extract_filename_metadata, print_progress
654
654
 
655
655
  regular_expression = re.compile(regex)
656
- images_by_key = defaultdict(list)
657
656
  stack_path = os.path.join(src, 'stack')
658
657
  files_processed = 0
659
658
  if not os.path.exists(stack_path) or (os.path.isdir(stack_path) and len(os.listdir(stack_path)) == 0):
@@ -665,7 +664,7 @@ def _rename_and_organize_image_files(src, regex, batch_size=100, pick_slice=Fals
665
664
  start = time.time()
666
665
  batch_filenames = all_filenames[idx:idx+batch_size]
667
666
  for filename in batch_filenames:
668
- images_by_key = _extract_filename_metadata(batch_filenames, src, images_by_key, regular_expression, metadata_type, pick_slice, skip_mode)
667
+ images_by_key = _extract_filename_metadata(batch_filenames, src, regular_expression, metadata_type, pick_slice, skip_mode)
669
668
 
670
669
  if pick_slice:
671
670
  for i, key in enumerate(images_by_key):
@@ -683,16 +682,16 @@ def _rename_and_organize_image_files(src, regex, batch_size=100, pick_slice=Fals
683
682
  files_to_process = len(all_filenames)
684
683
  print_progress(files_processed, files_to_process, n_jobs=1, time_ls=time_ls, batch_size=batch_size, operation_type='Preprocessing filenames')
685
684
 
686
- if os.path.exists(output_path):
687
- print(f'WARNING: A file with the same name already exists at location {output_filename}')
688
- else:
685
+ #if os.path.exists(output_path):
686
+ # print(f'WARNING: A file with the same name already exists at location {output_filename}')
687
+ if not os.path.exists(output_path):
689
688
  mip_image.save(output_path)
690
689
  else:
691
690
  for i, (key, images) in enumerate(images_by_key.items()):
692
- mip = np.max(np.stack(images), axis=0)
693
- mip_image = Image.fromarray(mip)
694
691
  plate, well, field, channel = key[:4]
695
692
  output_dir = os.path.join(src, channel)
693
+ mip = np.max(np.stack(images), axis=0)
694
+ mip_image = Image.fromarray(mip)
696
695
  os.makedirs(output_dir, exist_ok=True)
697
696
  output_filename = f'{plate}_{well}_{field}.tif'
698
697
  output_path = os.path.join(output_dir, output_filename)
@@ -703,9 +702,9 @@ def _rename_and_organize_image_files(src, regex, batch_size=100, pick_slice=Fals
703
702
  files_to_process = len(all_filenames)
704
703
  print_progress(files_processed, files_to_process, n_jobs=1, time_ls=time_ls, batch_size=batch_size, operation_type='Preprocessing filenames')
705
704
 
706
- if os.path.exists(output_path):
707
- print(f'WARNING: A file with the same name already exists at location {output_filename}')
708
- else:
705
+ #if os.path.exists(output_path):
706
+ # print(f'WARNING: A file with the same name already exists at location {output_filename}')
707
+ if not os.path.exists(output_path):
709
708
  mip_image.save(output_path)
710
709
  images_by_key.clear()
711
710
 
@@ -972,8 +971,8 @@ def _mip_all(src, include_first_chan=True):
972
971
  if filename.endswith('.npy'):
973
972
  # Load the array from the file.
974
973
  array = np.load(os.path.join(src, filename))
975
- # Normalize the array using custom parameters (q1=2, q2=98).
976
- array = normalize_to_dtype(array, q1=2, q2=98, percentiles=None)
974
+ # Normalize the array
975
+ #array = normalize_to_dtype(array, q1=0, q2=99, percentiles=None)
977
976
 
978
977
  if array.ndim != 3: # Check if the array is not 3-dimensional.
979
978
  # Log a message indicating a zero array will be generated due to unexpected dimensions.
@@ -1671,6 +1670,7 @@ def preprocess_img_data(settings):
1671
1670
  if plot:
1672
1671
  print(f'plotting {nr} images from {src}/stack')
1673
1672
  plot_arrays(src+'/stack', figuresize, cmap, nr=nr, normalize=normalize)
1673
+
1674
1674
  if all_to_mip:
1675
1675
  _mip_all(src+'/stack')
1676
1676
  if plot:
spacr/mediar.py CHANGED
@@ -22,8 +22,6 @@ try:
22
22
  # Now import the dependencies from MEDIAR
23
23
  from core.MEDIAR import Predictor, EnsemblePredictor
24
24
  from train_tools.models import MEDIARFormer
25
-
26
- print("Imports successful.")
27
25
  finally:
28
26
  # Remove the temporary __init__.py file after the import
29
27
  if os.path.exists(init_file):
spacr/plot.py CHANGED
@@ -123,7 +123,7 @@ def plot_image_mask_overlay(file, channels, cell_channel, nucleus_channel, patho
123
123
 
124
124
  fig = _plot_merged_plot(image=image, outlines=outlines, outline_colors=outline_colors, figuresize=figuresize, thickness=thickness)
125
125
 
126
- return
126
+ return fig
127
127
 
128
128
  def plot_masks(batch, masks, flows, cmap='inferno', figuresize=10, nr=1, file_type='.npz', print_object_number=True):
129
129
  """
spacr/utils.py CHANGED
@@ -303,7 +303,10 @@ def _get_cellpose_batch_size():
303
303
  except Exception as e:
304
304
  return 8
305
305
 
306
- def _extract_filename_metadata(filenames, src, images_by_key, regular_expression, metadata_type='cellvoyager', pick_slice=False, skip_mode='01'):
306
+ def _extract_filename_metadata(filenames, src, regular_expression, metadata_type='cellvoyager', pick_slice=False, skip_mode='01'):
307
+
308
+ images_by_key = defaultdict(list)
309
+
307
310
  for filename in filenames:
308
311
  match = regular_expression.match(filename)
309
312
  if match:
@@ -328,7 +331,6 @@ def _extract_filename_metadata(filenames, src, images_by_key, regular_expression
328
331
  if metadata_type =='cq1':
329
332
  orig_wellID = wellID
330
333
  wellID = _convert_cq1_well_id(wellID)
331
- #clear_output(wait=True)
332
334
  print(f'Converted Well ID: {orig_wellID} to {wellID}', end='\r', flush=True)
333
335
 
334
336
  if pick_slice:
@@ -338,7 +340,7 @@ def _extract_filename_metadata(filenames, src, images_by_key, regular_expression
338
340
  sliceid = '00'
339
341
 
340
342
  if mode == skip_mode:
341
- continue
343
+ continue
342
344
 
343
345
  key = (plate, well, field, channel, mode)
344
346
  with Image.open(os.path.join(src, filename)) as img:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: spacr
3
- Version: 0.3.0
3
+ Version: 0.3.1
4
4
  Summary: Spatial phenotype analysis of crisp screens (SpaCr)
5
5
  Home-page: https://github.com/EinarOlafsson/spacr
6
6
  Author: Einar Birnir Olafsson
@@ -8,24 +8,24 @@ spacr/app_measure.py,sha256=_K7APYIeOKpV6e_LcqabBjvEi7mfq9Fch8175x1x0k8,162
8
8
  spacr/app_sequencing.py,sha256=DjG26jy4cpddnV8WOOAIiExtOe9MleVMY4MFa5uTo5w,157
9
9
  spacr/app_umap.py,sha256=ZWAmf_OsIKbYvolYuWPMYhdlVe-n2CADoJulAizMiEo,153
10
10
  spacr/chris.py,sha256=YlBjSgeZaY8HPy6jkrT_ISAnCMAKVfvCxF0I9eAZLFM,2418
11
- spacr/core.py,sha256=gOr5P58s4ubzDfO0Ar3Zwce0bo-E8qxdN37Ian82RGw,150744
11
+ spacr/core.py,sha256=uyZdJ93ysd8oXgRX9b-6iTCldJ0CM1dq5VxF-xbZyN8,150703
12
12
  spacr/deep_spacr.py,sha256=a2YewgkQvLV-95NYJAutnojvJmX4S8z_wv6Tb-XIgUI,34484
13
13
  spacr/graph_learning.py,sha256=1tR-ZxvXE3dBz1Saw7BeVFcrsUFu9OlUZeZVifih9eo,13070
14
14
  spacr/gui.py,sha256=zUkIyAuOwwoMDoExxtI-QHRfOhE1R2rulXJDNxwSLGc,7947
15
15
  spacr/gui_core.py,sha256=ZUIqvK7x6NzgrmuTRbvwCTTSpU3yWUaId6MZjXv16us,40128
16
16
  spacr/gui_elements.py,sha256=OA514FUVRKAcdu9CFVOt7UEzn1vztakQ-rDyKqV0b9A,129771
17
17
  spacr/gui_utils.py,sha256=DCI--DNoYDWY1q0Aohd0XwFqjdPM3K5kCgRKiJGTnfc,30697
18
- spacr/io.py,sha256=o2Sxan6_HylbYNUjNdgeQ4iEpcXRwlgV1r59J2HG0xQ,117292
18
+ spacr/io.py,sha256=VjH_1zXmf0yEdtABnsoabCEIpU0S3wB-7Hog7_ntCdE,117267
19
19
  spacr/logger.py,sha256=7Zqr3TuuOQLWT32gYr2q1qvv7x0a2JhLANmZcnBXAW8,670
20
20
  spacr/measure.py,sha256=ooMOP2OE0BHUNqIkg0ltwV2FiO6hZDIcRC6A0YmGcws,54875
21
- spacr/mediar.py,sha256=KEkrO0dlAbOr2tN4c8-vDncTy3IWNzUAwWYiPRofFqU,14864
22
- spacr/plot.py,sha256=9Ty2cMJpICXPCEE4inGTb1FvlUZkVgqB7lqJaggmjZE,73975
21
+ spacr/mediar.py,sha256=5HaCyZYiOff74PCvHwKj-jSRua0QRoIv1mvElPfVKtY,14830
22
+ spacr/plot.py,sha256=yFC5m54lB8xVnC7vQp50-FvRn6lCjCt2mgi2GeiRwSs,73979
23
23
  spacr/sequencing.py,sha256=92KmjFa8Ptwmpf-GtyH3-uX6djFOYR5lJjMBHeciqhs,66921
24
24
  spacr/settings.py,sha256=PfIPLyMyBAfOodtdgNT8QzbysNDxTnsONXdI-fKtIDQ,68038
25
25
  spacr/sim.py,sha256=FveaVgBi3eypO2oVB5Dx-v0CC1Ny7UPfXkJiiRRodAk,71212
26
26
  spacr/sim_app.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
27
27
  spacr/timelapse.py,sha256=KMYCgHzf9LTZe-lWl5mvH2EjbKRE6OhpwdY13wEumGc,39504
28
- spacr/utils.py,sha256=D13hYJsVuq1ZMWYGyvtEskU_W2P8ddsI9zX9pTtMAFA,189159
28
+ spacr/utils.py,sha256=JGjL_Tg5ec1qmaf9BV3gqlREUpxjK8hutgPEGj5mAEs,189141
29
29
  spacr/version.py,sha256=axH5tnGwtgSnJHb5IDhiu4Zjk5GhLyAEDRe-rnaoFOA,409
30
30
  spacr/resources/MEDIAR/.git,sha256=nHbNNUgehWnXyS2LbJZitX4kbpd1urzYgE0WZYvdMfc,53
31
31
  spacr/resources/MEDIAR/.gitignore,sha256=Ff1q9Nme14JUd-4Q3jZ65aeQ5X4uttptssVDgBVHYo8,152
@@ -151,9 +151,9 @@ spacr/resources/images/plate1_E01_T0001F001L01A03Z01C03.tif,sha256=Pbhk7xn-KUP6R
151
151
  spacr/resources/models/cp/toxo_plaque_cyto_e25000_X1120_Y1120.CP_model,sha256=z8BbHWZPRnE9D_BHO0fBREE85c1vkltDs-incs2ytXQ,26566572
152
152
  spacr/resources/models/cp/toxo_plaque_cyto_e25000_X1120_Y1120.CP_model_settings.csv,sha256=fBAGuL_B8ERVdVizO3BHozTDSbZUh1yFzsYK3wkQN68,420
153
153
  spacr/resources/models/cp/toxo_pv_lumen.CP_model,sha256=2y_CindYhmTvVwBH39SNILF3rI3x9SsRn6qrMxHy3l0,26562451
154
- spacr-0.3.0.dist-info/LICENSE,sha256=SR-2MeGc6SCM1UORJYyarSWY_A-JaOMFDj7ReSs9tRM,1083
155
- spacr-0.3.0.dist-info/METADATA,sha256=gPhwJrEAVxewekQKy4X9qiLlDr3Q4JvwXnq941vcpew,5646
156
- spacr-0.3.0.dist-info/WHEEL,sha256=HiCZjzuy6Dw0hdX5R3LCFPDmFS4BWl8H-8W39XfmgX4,91
157
- spacr-0.3.0.dist-info/entry_points.txt,sha256=BMC0ql9aNNpv8lUZ8sgDLQMsqaVnX5L535gEhKUP5ho,296
158
- spacr-0.3.0.dist-info/top_level.txt,sha256=GJPU8FgwRXGzKeut6JopsSRY2R8T3i9lDgya42tLInY,6
159
- spacr-0.3.0.dist-info/RECORD,,
154
+ spacr-0.3.1.dist-info/LICENSE,sha256=SR-2MeGc6SCM1UORJYyarSWY_A-JaOMFDj7ReSs9tRM,1083
155
+ spacr-0.3.1.dist-info/METADATA,sha256=Fi3B8Vxgz4IzfYodV9zMgRdFLXTtVtel4OCdE06o5cI,5646
156
+ spacr-0.3.1.dist-info/WHEEL,sha256=HiCZjzuy6Dw0hdX5R3LCFPDmFS4BWl8H-8W39XfmgX4,91
157
+ spacr-0.3.1.dist-info/entry_points.txt,sha256=BMC0ql9aNNpv8lUZ8sgDLQMsqaVnX5L535gEhKUP5ho,296
158
+ spacr-0.3.1.dist-info/top_level.txt,sha256=GJPU8FgwRXGzKeut6JopsSRY2R8T3i9lDgya42tLInY,6
159
+ spacr-0.3.1.dist-info/RECORD,,
File without changes
File without changes