spacr 0.3.80__py3-none-any.whl → 0.3.81__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/gui_core.py CHANGED
@@ -4,6 +4,7 @@ from tkinter import ttk
4
4
  from tkinter import filedialog
5
5
  from multiprocessing import Process, Value, Queue, set_start_method
6
6
  from tkinter import ttk
7
+ import matplotlib
7
8
  from matplotlib.figure import Figure
8
9
  from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
9
10
  import numpy as np
@@ -324,17 +325,14 @@ def show_next_figure():
324
325
  index_control.set_to(len(figures) - 1)
325
326
  display_figure(fig)
326
327
 
327
- def process_fig_queue():
328
+ def process_fig_queue_v1():
328
329
  global canvas, fig_queue, canvas_widget, parent_frame, uppdate_frequency, figures, figure_index, index_control
329
330
  from .gui_elements import standardize_figure
330
331
 
331
332
  #print("process_fig_queue called", flush=True)
332
333
  try:
333
- got_new_figure = False
334
334
  while not fig_queue.empty():
335
335
  fig = fig_queue.get_nowait()
336
- #print("Got a figure from fig_queue", flush=True)
337
-
338
336
  if fig is None:
339
337
  print("Warning: Retrieved a None figure from fig_queue.", flush=True)
340
338
  continue
@@ -345,30 +343,63 @@ def process_fig_queue():
345
343
 
346
344
  # Update slider maximum
347
345
  index_control.set_to(len(figures) - 1)
348
- #print("New maximum slider value after adding a figure:", index_control.to, flush=True)
349
346
 
350
347
  # If no figure has been displayed yet
351
348
  if figure_index == -1:
352
349
  figure_index = 0
353
350
  display_figure(figures[figure_index])
354
351
  index_control.set(figure_index)
355
- #print("Displayed the first figure and set slider value to 0", flush=True)
356
352
 
357
- #got_new_figure = True
353
+ except Exception as e:
354
+ print("Exception in process_fig_queue:", e, flush=True)
355
+ traceback.print_exc()
358
356
 
359
- #if not got_new_figure:
360
- # No new figures this time
361
- #print("No new figures found in the queue this iteration.", flush=True)
357
+ finally:
358
+ # Schedule process_fig_queue() to run again
359
+ after_id = canvas_widget.after(uppdate_frequency, process_fig_queue)
360
+ parent_frame.after_tasks.append(after_id)
361
+
362
+ def process_fig_queue():
363
+ global canvas, fig_queue, canvas_widget, parent_frame, uppdate_frequency, figures, figure_index, index_control
364
+ from .gui_elements import standardize_figure
365
+
366
+ try:
367
+ while not fig_queue.empty():
368
+ fig = fig_queue.get_nowait()
369
+ if fig is None:
370
+ print("Warning: Retrieved a None figure from fig_queue.")
371
+ continue
372
+
373
+ # Standardize the figure appearance before adding it
374
+ fig = standardize_figure(fig)
375
+ figures.append(fig)
376
+
377
+ # OPTIONAL: Cap the size of the figures deque at 100
378
+ MAX_FIGURES = 100
379
+ while len(figures) > MAX_FIGURES:
380
+ # Discard the oldest figure
381
+ old_fig = figures.popleft()
382
+ # If needed, you could also close the figure to free memory:
383
+ matplotlib.pyplot.close(old_fig)
384
+
385
+ # Update slider maximum
386
+ index_control.set_to(len(figures) - 1)
387
+
388
+ # If no figure has been displayed yet
389
+ if figure_index == -1:
390
+ figure_index = 0
391
+ display_figure(figures[figure_index])
392
+ index_control.set(figure_index)
362
393
 
363
394
  except Exception as e:
364
- print("Exception in process_fig_queue:", e, flush=True)
395
+ print("Exception in process_fig_queue:", e)
365
396
  traceback.print_exc()
366
397
 
367
398
  finally:
368
399
  # Schedule process_fig_queue() to run again
369
400
  after_id = canvas_widget.after(uppdate_frequency, process_fig_queue)
370
401
  parent_frame.after_tasks.append(after_id)
371
- #print("process_fig_queue scheduled again", flush=True)
402
+
372
403
 
373
404
  def update_figure(value):
374
405
  from .gui_elements import standardize_figure
spacr/gui_elements.py CHANGED
@@ -17,8 +17,7 @@ from skimage.draw import polygon, line
17
17
  from skimage.transform import resize
18
18
  from scipy.ndimage import binary_fill_holes, label
19
19
  from tkinter import ttk, scrolledtext
20
- from skimage.color import rgb2gray
21
-
20
+ from skimage.color import rgb2gray
22
21
  fig = None
23
22
 
24
23
  def create_menu_bar(root):
spacr/settings.py CHANGED
@@ -885,9 +885,32 @@ expected_types = {
885
885
  "cmap":str,
886
886
  "pathogen_model":str,
887
887
  "normalize_input":bool,
888
+ "filter_column":str,
889
+ "target_unique_count":int,
890
+ "threshold_multiplier":int,
891
+ "threshold_method":str,
892
+ "count_data":list,
893
+ "score_data":list,
894
+ "min_n":int,
895
+ "controls":list,
896
+ "toxo":bool,
897
+ "volcano":str,
898
+ "metadata_files":list,
899
+ "filter_value":list,
900
+ "split_axis_lims":str,
901
+ "x_lim":(list,None),
902
+ "log_x":bool,
903
+ "log_y":bool,
904
+ "reg_alpha":(int,float),
905
+ "reg_lambda":(int,float),
906
+ "prune_features":bool,
907
+ "cross_validation":bool,
908
+ "offset_start":int,
909
+ "chunk_size":int,
910
+ "single_direction":str,
888
911
  }
889
912
 
890
- categories = {"Paths":[ "src", "grna", "barcodes", "custom_model_path", "dataset","model_path","grna_csv","row_csv","column_csv"],
913
+ categories = {"Paths":[ "src", "grna", "barcodes", "custom_model_path", "dataset","model_path","grna_csv","row_csv","column_csv", "metadata_files", "score_data","count_data"],
891
914
  "General": ["metadata_type", "custom_regex", "experiment", "channels", "magnification", "channel_dims", "apply_model_to_dataset", "generate_training_dataset", "train_DL_model", "segmentation_mode"],
892
915
  "Cellpose":["fill_in","from_scratch", "n_epochs", "width_height", "model_name", "custom_model", "resample", "rescale", "CP_prob", "flow_threshold", "percentiles", "invert", "diameter", "grayscale", "Signal_to_noise", "resize", "target_height", "target_width"],
893
916
  "Cell": ["cell_intensity_range", "cell_size_range", "cell_chann_dim", "cell_channel", "cell_background", "cell_Signal_to_noise", "cell_CP_prob", "cell_FT", "remove_background_cell", "cell_min_size", "cell_mask_dim", "cytoplasm", "cytoplasm_min_size", "uninfected", "merge_edge_pathogen_cells", "adjust_cells", "cells", "cell_loc"],
@@ -895,18 +918,18 @@ categories = {"Paths":[ "src", "grna", "barcodes", "custom_model_path", "dataset
895
918
  "Pathogen": ["pathogen_intensity_range", "pathogen_size_range", "pathogen_chann_dim", "pathogen_channel", "pathogen_background", "pathogen_Signal_to_noise", "pathogen_CP_prob", "pathogen_FT", "pathogen_model", "remove_background_pathogen", "pathogen_min_size", "pathogen_mask_dim", "pathogens", "pathogen_loc", "pathogen_types", "pathogen_plate_metadata", ],
896
919
  "Measurements": ["remove_image_canvas", "remove_highly_correlated", "homogeneity", "homogeneity_distances", "radial_dist", "calculate_correlation", "manders_thresholds", "save_measurements", "tables", "image_nr", "dot_size", "filter_by", "remove_highly_correlated_features", "remove_low_variance_features", "channel_of_interest"],
897
920
  "Object Image": ["save_png", "dialate_pngs", "dialate_png_ratios", "png_size", "png_dims", "save_arrays", "normalize_by", "crop_mode", "normalize", "use_bounding_box"],
898
- "Sequencing": ["signal_direction","mode","comp_level","comp_type","save_h5","expected_end","offset","target_sequence","regex", "highlight"],
921
+ "Sequencing": ["offset_start","chunk_size","single_direction", "signal_direction","mode","comp_level","comp_type","save_h5","expected_end","offset","target_sequence","regex", "highlight"],
899
922
  "Generate Dataset":["save_to_db","file_metadata","class_metadata", "annotation_column","annotated_classes", "dataset_mode", "metadata_type_by","custom_measurement", "sample", "size"],
900
923
  "Hyperparamiters (Training)": ["png_type", "score_threshold","file_type", "train_channels", "epochs", "loss_type", "optimizer_type","image_size","val_split","learning_rate","weight_decay","dropout_rate", "init_weights", "train", "classes", "augment", "amsgrad","use_checkpoint","gradient_accumulation","gradient_accumulation_steps","intermedeate_save","pin_memory"],
901
924
  "Hyperparamiters (Embedding)": ["visualize","n_neighbors","min_dist","metric","resnet_features","reduction_method","embedding_by_controls","col_to_compare","log_data"],
902
925
  "Hyperparamiters (Clustering)": ["eps","min_samples","analyze_clusters","clustering","remove_cluster_noise"],
903
- "Hyperparamiters (Regression)":["cov_type", "class_1_threshold", "plate", "other", "fraction_threshold", "alpha", "random_row_column_effects", "regression_type", "min_cell_count", "agg_type", "transform", "dependent_variable"],
926
+ "Hyperparamiters (Regression)":["cross_validation","prune_features","reg_lambda","reg_alpha","cov_type", "class_1_threshold", "plate", "other", "fraction_threshold", "alpha", "random_row_column_effects", "regression_type", "min_cell_count", "agg_type", "transform", "dependent_variable"],
904
927
  "Hyperparamiters (Activation)":["cam_type", "overlay", "correlation", "target_layer", "normalize_input"],
905
- "Annotation": ["nc_loc", "pc_loc", "nc", "pc", "cell_plate_metadata","treatment_plate_metadata", "metadata_types", "cell_types", "target","positive_control","negative_control", "location_column", "treatment_loc", "channel_of_interest", "measurement", "treatments", "um_per_pixel", "nr_imgs", "exclude", "exclude_conditions", "mix", "pos", "neg"],
906
- "Plot": ["plot", "plot_control", "plot_nr", "examples_to_plot", "normalize_plots", "cmap", "figuresize", "plot_cluster_grids", "img_zoom", "row_limit", "color_by", "plot_images", "smooth_lines", "plot_points", "plot_outlines", "black_background", "plot_by_cluster", "heatmap_feature","grouping","min_max","cmap","save_figure"],
928
+ "Annotation": ["filter_column", "filter_value","volcano", "toxo", "controls", "nc_loc", "pc_loc", "nc", "pc", "cell_plate_metadata","treatment_plate_metadata", "metadata_types", "cell_types", "target","positive_control","negative_control", "location_column", "treatment_loc", "channel_of_interest", "measurement", "treatments", "um_per_pixel", "nr_imgs", "exclude", "exclude_conditions", "mix", "pos", "neg"],
929
+ "Plot": ["plot", "split_axis_lims", "x_lim","log_x","log_y", "plot_control", "plot_nr", "examples_to_plot", "normalize_plots", "cmap", "figuresize", "plot_cluster_grids", "img_zoom", "row_limit", "color_by", "plot_images", "smooth_lines", "plot_points", "plot_outlines", "black_background", "plot_by_cluster", "heatmap_feature","grouping","min_max","cmap","save_figure"],
907
930
  "Test": ["test_mode", "test_images", "random_test", "test_nr", "test", "test_split"],
908
931
  "Timelapse": ["timelapse", "fps", "timelapse_displacement", "timelapse_memory", "timelapse_frame_limits", "timelapse_remove_transient", "timelapse_mode", "timelapse_objects", "compartments"],
909
- "Advanced": ["shuffle", "target_intensity_min", "cells_per_well", "nuclei_limit", "pathogen_limit", "background", "backgrounds", "schedule", "test_size","exclude","n_repeats","top_features", "model_type_ml", "model_type","minimum_cell_count","n_estimators","preprocess", "remove_background", "normalize", "lower_percentile", "merge_pathogens", "batch_size", "filter", "save", "masks", "verbose", "randomize", "n_jobs"],
932
+ "Advanced": ["target_unique_count","threshold_multiplier", "threshold_method", "min_n","shuffle", "target_intensity_min", "cells_per_well", "nuclei_limit", "pathogen_limit", "background", "backgrounds", "schedule", "test_size","exclude","n_repeats","top_features", "model_type_ml", "model_type","minimum_cell_count","n_estimators","preprocess", "remove_background", "normalize", "lower_percentile", "merge_pathogens", "batch_size", "filter", "save", "masks", "verbose", "randomize", "n_jobs"],
910
933
  "Miscellaneous": ["all_to_mip", "pick_slice", "skip_mode", "upscale", "upscale_factor"]
911
934
  }
912
935
 
spacr/utils.py CHANGED
@@ -5045,19 +5045,22 @@ def generate_cytoplasm_mask(nucleus_mask, cell_mask):
5045
5045
  return cytoplasm_mask
5046
5046
 
5047
5047
  def add_column_to_database(settings):
5048
- """
5049
- Adds a new column to the database table by matching on a common column from the DataFrame.
5050
- If the column already exists in the database, it adds the column with a suffix.
5051
- NaN values will remain as NULL in the database.
5052
-
5053
- Parameters:
5054
- - settings: A dictionary containing the following keys:
5055
- - 'csv_path': Path to the CSV file with the data to be added.
5056
- - 'db_path': Path to the SQLite database (or connection string for other databases).
5057
- - 'table_name': The name of the table in the database.
5058
- - 'update_column': The name of the new column in the DataFrame to add to the database.
5059
- - 'match_column': The common column used to match rows.
5060
- """
5048
+ #"""
5049
+ #Adds a new column to the database table by matching on a common column from the DataFrame.
5050
+ #If the column already exists in the database, it adds the column with a suffix.
5051
+ #NaN values will remain as NULL in the database.
5052
+
5053
+ #Parameters:
5054
+ # settings (dict): A dictionary containing the following keys:
5055
+ # csv_path (str): Path to the CSV file with the data to be added.
5056
+ # db_path (str): Path to the SQLite database (or connection string for other databases).
5057
+ # table_name (str): The name of the table in the database.
5058
+ # update_column (str): The name of the new column in the DataFrame to add to the database.
5059
+ # match_column (str): The common column used to match rows.
5060
+
5061
+ #Returns:
5062
+ # None
5063
+ #"""
5061
5064
 
5062
5065
  # Read the DataFrame from the provided CSV path
5063
5066
  df = pd.read_csv(settings['csv_path'])
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: spacr
3
- Version: 0.3.80
3
+ Version: 0.3.81
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
@@ -12,8 +12,8 @@ spacr/chat_bot.py,sha256=n3Fhqg3qofVXHmh3H9sUcmfYy9MmgRnr48663MVdY9E,1244
12
12
  spacr/core.py,sha256=3u2qKmPmTlswvE1uKTF4gi7KQ3sJBHV9No_ysgk7JCU,48487
13
13
  spacr/deep_spacr.py,sha256=V3diLyxX-0_F5UxhX_b94ROOvL9eoLvnoUmF3nMBqPQ,43250
14
14
  spacr/gui.py,sha256=ARyn9Q_g8HoP-cXh1nzMLVFCKqthY4v2u9yORyaQqQE,8230
15
- spacr/gui_core.py,sha256=6NKv8ebqC9Zuior4f2-L1By_Pjtt-RPCrEgnRuE9P54,45576
16
- spacr/gui_elements.py,sha256=I_eSYF1RkAG0zsa-ZiQT0EaaVvUpucULCuWCowO6t4E,138248
15
+ spacr/gui_core.py,sha256=3S1S7rOtGfm5Z-Fb-jk1HxjsLZo6IboBxtXtsDMw1ME,46578
16
+ spacr/gui_elements.py,sha256=fc9z-GP_PmtJy2lIsfi3fx5r5puTJ-zz8ntB9pC53Gc,138246
17
17
  spacr/gui_utils.py,sha256=u9RoIOWpAXFEOnUlLpMQZrc1pWSg6omZsJMIhJdRv_g,41211
18
18
  spacr/io.py,sha256=LF6lpphw7GSeuoHQijPykjKNF56wNTFEWFZuDQp3O6Q,145739
19
19
  spacr/logger.py,sha256=lJhTqt-_wfAunCPl93xE65Wr9Y1oIHJWaZMjunHUeIw,1538
@@ -23,13 +23,13 @@ spacr/ml.py,sha256=x19S8OsR5omb8e6MU9I99Nz95J_QvM5siyk-zaAU3p8,82866
23
23
  spacr/openai.py,sha256=5vBZ3Jl2llYcW3oaTEXgdyCB2aJujMUIO5K038z7w_A,1246
24
24
  spacr/plot.py,sha256=gXC7y3uT4sx8KRODeSFWQG_A1CylsuJ5B7HYe_un6so,165177
25
25
  spacr/sequencing.py,sha256=ClUfwPPK6rNUbUuiEkzcwakzVyDKKUMv9ricrxT8qQY,25227
26
- spacr/settings.py,sha256=xTFTD04H8uXRJ5m4Pnr4Znhx0f_FxdgStMPXol3apxM,80888
26
+ spacr/settings.py,sha256=3bgBWBotIO7TZx2nh6JoEaqHNmwbChAiz1gW4xmURQs,81788
27
27
  spacr/sim.py,sha256=1xKhXimNU3ukzIw-3l9cF3Znc_brW8h20yv8fSTzvss,71173
28
28
  spacr/stats.py,sha256=mbhwsyIqt5upsSD346qGjdCw7CFBa0tIS7zHU9e0jNI,9536
29
29
  spacr/submodules.py,sha256=SK8YEs850LAx30YAiwap7ecLpp1_p-bci6H-Or0GLoA,55500
30
30
  spacr/timelapse.py,sha256=KGfG4L4-QnFfgbF7L6C5wL_3gd_rqr05Foje6RsoTBg,39603
31
31
  spacr/toxo.py,sha256=z2nT5aAze3NUIlwnBQcnkARihDwoPfqOgQIVoUluyK0,25087
32
- spacr/utils.py,sha256=SiUcctyUETEX_GZ-Nflba5whZiEjJynncaH-xcZPK1k,222242
32
+ spacr/utils.py,sha256=jjZIqzJKl9nnWgj2eJiLFT27gED8hO6rAEsJLlimm-E,222298
33
33
  spacr/version.py,sha256=axH5tnGwtgSnJHb5IDhiu4Zjk5GhLyAEDRe-rnaoFOA,409
34
34
  spacr/resources/MEDIAR/.gitignore,sha256=Ff1q9Nme14JUd-4Q3jZ65aeQ5X4uttptssVDgBVHYo8,152
35
35
  spacr/resources/MEDIAR/LICENSE,sha256=yEj_TRDLUfDpHDNM0StALXIt6mLqSgaV2hcCwa6_TcY,1065
@@ -152,9 +152,9 @@ spacr/resources/icons/umap.png,sha256=dOLF3DeLYy9k0nkUybiZMe1wzHQwLJFRmgccppw-8b
152
152
  spacr/resources/images/plate1_E01_T0001F001L01A01Z01C02.tif,sha256=Tl0ZUfZ_AYAbu0up_nO0tPRtF1BxXhWQ3T3pURBCCRo,7958528
153
153
  spacr/resources/images/plate1_E01_T0001F001L01A02Z01C01.tif,sha256=m8N-V71rA1TT4dFlENNg8s0Q0YEXXs8slIn7yObmZJQ,7958528
154
154
  spacr/resources/images/plate1_E01_T0001F001L01A03Z01C03.tif,sha256=Pbhk7xn-KUP6RSIhJsxQcrHFImBm3GEpLkzx7WOc-5M,7958528
155
- spacr-0.3.80.dist-info/LICENSE,sha256=SR-2MeGc6SCM1UORJYyarSWY_A-JaOMFDj7ReSs9tRM,1083
156
- spacr-0.3.80.dist-info/METADATA,sha256=Q0YV4N-C8XyUHH8HFW_k9ryAftcU8v9oMxNhgzvU8cA,6032
157
- spacr-0.3.80.dist-info/WHEEL,sha256=HiCZjzuy6Dw0hdX5R3LCFPDmFS4BWl8H-8W39XfmgX4,91
158
- spacr-0.3.80.dist-info/entry_points.txt,sha256=BMC0ql9aNNpv8lUZ8sgDLQMsqaVnX5L535gEhKUP5ho,296
159
- spacr-0.3.80.dist-info/top_level.txt,sha256=GJPU8FgwRXGzKeut6JopsSRY2R8T3i9lDgya42tLInY,6
160
- spacr-0.3.80.dist-info/RECORD,,
155
+ spacr-0.3.81.dist-info/LICENSE,sha256=SR-2MeGc6SCM1UORJYyarSWY_A-JaOMFDj7ReSs9tRM,1083
156
+ spacr-0.3.81.dist-info/METADATA,sha256=TneYaiWWfNHUuqpSQpRAEzWzYia6KIksYDzNVDcsimw,6032
157
+ spacr-0.3.81.dist-info/WHEEL,sha256=HiCZjzuy6Dw0hdX5R3LCFPDmFS4BWl8H-8W39XfmgX4,91
158
+ spacr-0.3.81.dist-info/entry_points.txt,sha256=BMC0ql9aNNpv8lUZ8sgDLQMsqaVnX5L535gEhKUP5ho,296
159
+ spacr-0.3.81.dist-info/top_level.txt,sha256=GJPU8FgwRXGzKeut6JopsSRY2R8T3i9lDgya42tLInY,6
160
+ spacr-0.3.81.dist-info/RECORD,,
File without changes