spacr 0.3.34__py3-none-any.whl → 0.3.35__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/ml.py CHANGED
@@ -732,7 +732,7 @@ def generate_ml_scores(settings):
732
732
 
733
733
  from .io import _read_and_merge_data, _read_db
734
734
  from .plot import plot_plates
735
- from .utils import get_ml_results_paths
735
+ from .utils import get_ml_results_paths, add_column_to_database
736
736
  from .settings import set_default_analyze_screen
737
737
 
738
738
  settings = set_default_analyze_screen(settings)
@@ -835,6 +835,14 @@ def generate_ml_scores(settings):
835
835
  figs[1].savefig(feature_importance_fig_path, format='pdf')
836
836
  shap_fig.savefig(shap_fig_path, format='pdf')
837
837
 
838
+ if settings['save_to_db']:
839
+ settings['csv_path'] = data_path
840
+ settings['db_path'] = os.path.join(src, 'measurements', 'measurements.db')
841
+ settings['table_name'] = 'png_list'
842
+ settings['update_column'] = 'predictions'
843
+ settings['match_column'] = 'prcfo'
844
+ add_column_to_database(settings)
845
+
838
846
  return [output, plate_heatmap]
839
847
 
840
848
  def ml_analysis(df, channel_of_interest=3, location_column='col', positive_control='c2', negative_control='c1', exclude=None, n_repeats=10, top_features=30, n_estimators=100, test_size=0.2, model_type='xgboost', n_jobs=-1, remove_low_variance_features=True, remove_highly_correlated_features=True, verbose=False):
spacr/settings.py CHANGED
@@ -279,6 +279,7 @@ def get_measure_crop_settings(settings={}):
279
279
  def set_default_analyze_screen(settings):
280
280
  settings.setdefault('src', 'path')
281
281
  settings.setdefault('annotation_column', None)
282
+ settings.setdefault('save_to_db', False)
282
283
  settings.setdefault('model_type_ml','xgboost')
283
284
  settings.setdefault('heatmap_feature','predictions')
284
285
  settings.setdefault('grouping','mean')
@@ -885,6 +886,7 @@ expected_types = {
885
886
  "overlay":bool,
886
887
  "correlate":bool,
887
888
  "target_layer":str,
889
+ "save_to_db":bool,
888
890
  "normalize_input":bool,
889
891
  }
890
892
 
@@ -897,7 +899,7 @@ categories = {"Paths":[ "src", "grna", "barcodes", "custom_model_path", "dataset
897
899
  "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"],
898
900
  "Object Image": ["save_png", "dialate_pngs", "dialate_png_ratios", "png_size", "png_dims", "save_arrays", "normalize_by", "crop_mode", "dialate_pngs", "normalize", "use_bounding_box"],
899
901
  "Sequencing": ["signal_direction","mode","comp_level","comp_type","save_h5","expected_end","offset","target_sequence","regex", "highlight"],
900
- "Generate Dataset":["file_metadata","class_metadata", "annotation_column","annotated_classes", "dataset_mode", "metadata_type_by","custom_measurement", "sample", "size"],
902
+ "Generate Dataset":["save_to_db","file_metadata","class_metadata", "annotation_column","annotated_classes", "dataset_mode", "metadata_type_by","custom_measurement", "sample", "size"],
901
903
  "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"],
902
904
  "Hyperparamiters (Embedding)": ["visualize","n_neighbors","min_dist","metric","resnet_features","reduction_method","embedding_by_controls","col_to_compare","log_data"],
903
905
  "Hyperparamiters (Clustering)": ["eps","min_samples","analyze_clusters","clustering","remove_cluster_noise"],
spacr/utils.py CHANGED
@@ -5042,3 +5042,44 @@ def generate_cytoplasm_mask(nucleus_mask, cell_mask):
5042
5042
  cytoplasm_mask = np.where(np.logical_or(nucleus_mask != 0), 0, cell_mask)
5043
5043
 
5044
5044
  return cytoplasm_mask
5045
+
5046
+ def add_column_to_database(settings):
5047
+ """
5048
+ Updates a column in the database by matching on a common column from the DataFrame.
5049
+
5050
+ Parameters:
5051
+ - settings: A dictionary containing the following keys:
5052
+ - 'csv_path': Path to the CSV file with the data to be added.
5053
+ - 'db_path': Path to the SQLite database (or connection string for other databases).
5054
+ - 'table_name': The name of the table in the database.
5055
+ - 'update_column': The column to update in the database.
5056
+ - 'match_column': The common column used to match rows.
5057
+ """
5058
+
5059
+ # Read the DataFrame from the provided CSV path
5060
+ df = pd.read_csv(settings['csv_path'])
5061
+
5062
+ # Connect to the SQLite database
5063
+ conn = sqlite3.connect(settings['db_path'])
5064
+ cursor = conn.cursor()
5065
+
5066
+ # Iterate over the DataFrame and update the database
5067
+ for index, row in df.iterrows():
5068
+ value_to_update = row[settings['update_column']]
5069
+ match_value = row[settings['match_column']]
5070
+
5071
+ # Prepare and execute the SQL update query
5072
+ query = f"""
5073
+ UPDATE {settings['table_name']}
5074
+ SET {settings['update_column']} = ?
5075
+ WHERE {settings['match_column']} = ?
5076
+ """
5077
+ cursor.execute(query, (value_to_update, match_value))
5078
+
5079
+ # Commit the transaction and close the connection
5080
+ conn.commit()
5081
+ conn.close()
5082
+
5083
+ print(f"Updated '{settings['update_column']}' in '{settings['table_name']}' using '{settings['match_column']}'.")
5084
+
5085
+
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: spacr
3
- Version: 0.3.34
3
+ Version: 0.3.35
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
@@ -18,16 +18,16 @@ spacr/io.py,sha256=AARmqn1fMmTgVDwWy8bEYK6SjH-6DZIulgCSPdBTyf0,143370
18
18
  spacr/logger.py,sha256=lJhTqt-_wfAunCPl93xE65Wr9Y1oIHJWaZMjunHUeIw,1538
19
19
  spacr/measure.py,sha256=BThn_sALgKrwGKnLOGpT4FyoJeRVoTZoP9SXbCtCMRw,54857
20
20
  spacr/mediar.py,sha256=FwLvbLQW5LQzPgvJZG8Lw7GniA2vbZx6Jv6vIKu7I5c,14743
21
- spacr/ml.py,sha256=8i2D9YEC9rSYdbgkuuMLl6adwivWn2Z5BEUjPRsW4t4,48983
21
+ spacr/ml.py,sha256=Wy_H_bI5cD_N4xIZCo3_M-73wVvmCC35tJbLspMOWbg,49341
22
22
  spacr/openai.py,sha256=5vBZ3Jl2llYcW3oaTEXgdyCB2aJujMUIO5K038z7w_A,1246
23
23
  spacr/plot.py,sha256=PtCSoBmLFlGC7ebmsk-vMlyd7q2ahXgRVaTtAq3w_po,116513
24
24
  spacr/sequencing.py,sha256=t18mgpK6rhWuB1LtFOsPxqgpFXxuUmrD06ecsaVQ0Gw,19655
25
- spacr/settings.py,sha256=7rAvzPkfyfbpY6JQqcTe6PcCghEvLebUgsfKMVBtNyU,75879
25
+ spacr/settings.py,sha256=AzP9NGiXI1MqT69bHObxwDSCUk0kdstBVvl1JpcD_-w,75960
26
26
  spacr/sim.py,sha256=1xKhXimNU3ukzIw-3l9cF3Znc_brW8h20yv8fSTzvss,71173
27
27
  spacr/submodules.py,sha256=AB7s6-cULsaqz-haAaCtXfGEIi8uPZGT4xoCslUJC3Y,18391
28
28
  spacr/timelapse.py,sha256=FSYpUtAVy6xc3lwprRYgyDTT9ysUhfRQ4zrP9_h2mvg,39465
29
29
  spacr/toxo.py,sha256=us3pQyULtMTyfTq0MWPn4QJTTmQ6BwAJKChNf75jo3I,10082
30
- spacr/utils.py,sha256=w4Cht32Mhep7jfXKm5CSpyFLB3lOxiBCQI6PnaYcI3Q,213360
30
+ spacr/utils.py,sha256=hqxgN3tZTUyYvntaDc7tCRxgqlST0suAtkV3HYfbOO4,214847
31
31
  spacr/version.py,sha256=axH5tnGwtgSnJHb5IDhiu4Zjk5GhLyAEDRe-rnaoFOA,409
32
32
  spacr/resources/MEDIAR/.gitignore,sha256=Ff1q9Nme14JUd-4Q3jZ65aeQ5X4uttptssVDgBVHYo8,152
33
33
  spacr/resources/MEDIAR/LICENSE,sha256=yEj_TRDLUfDpHDNM0StALXIt6mLqSgaV2hcCwa6_TcY,1065
@@ -150,9 +150,9 @@ spacr/resources/icons/umap.png,sha256=dOLF3DeLYy9k0nkUybiZMe1wzHQwLJFRmgccppw-8b
150
150
  spacr/resources/images/plate1_E01_T0001F001L01A01Z01C02.tif,sha256=Tl0ZUfZ_AYAbu0up_nO0tPRtF1BxXhWQ3T3pURBCCRo,7958528
151
151
  spacr/resources/images/plate1_E01_T0001F001L01A02Z01C01.tif,sha256=m8N-V71rA1TT4dFlENNg8s0Q0YEXXs8slIn7yObmZJQ,7958528
152
152
  spacr/resources/images/plate1_E01_T0001F001L01A03Z01C03.tif,sha256=Pbhk7xn-KUP6RSIhJsxQcrHFImBm3GEpLkzx7WOc-5M,7958528
153
- spacr-0.3.34.dist-info/LICENSE,sha256=SR-2MeGc6SCM1UORJYyarSWY_A-JaOMFDj7ReSs9tRM,1083
154
- spacr-0.3.34.dist-info/METADATA,sha256=6C9_x3YSb9ycM9cXRufcPTJG809Cf-hkNYDOdEVXMT0,5949
155
- spacr-0.3.34.dist-info/WHEEL,sha256=HiCZjzuy6Dw0hdX5R3LCFPDmFS4BWl8H-8W39XfmgX4,91
156
- spacr-0.3.34.dist-info/entry_points.txt,sha256=BMC0ql9aNNpv8lUZ8sgDLQMsqaVnX5L535gEhKUP5ho,296
157
- spacr-0.3.34.dist-info/top_level.txt,sha256=GJPU8FgwRXGzKeut6JopsSRY2R8T3i9lDgya42tLInY,6
158
- spacr-0.3.34.dist-info/RECORD,,
153
+ spacr-0.3.35.dist-info/LICENSE,sha256=SR-2MeGc6SCM1UORJYyarSWY_A-JaOMFDj7ReSs9tRM,1083
154
+ spacr-0.3.35.dist-info/METADATA,sha256=xBdKUQpQuuru72Lgt9dirwo_Of5GdAwOKqs7bH7Sd0k,5949
155
+ spacr-0.3.35.dist-info/WHEEL,sha256=HiCZjzuy6Dw0hdX5R3LCFPDmFS4BWl8H-8W39XfmgX4,91
156
+ spacr-0.3.35.dist-info/entry_points.txt,sha256=BMC0ql9aNNpv8lUZ8sgDLQMsqaVnX5L535gEhKUP5ho,296
157
+ spacr-0.3.35.dist-info/top_level.txt,sha256=GJPU8FgwRXGzKeut6JopsSRY2R8T3i9lDgya42tLInY,6
158
+ spacr-0.3.35.dist-info/RECORD,,
File without changes