spacr 0.3.34__py3-none-any.whl → 0.3.36__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 +9 -1
- spacr/settings.py +3 -1
- spacr/utils.py +64 -0
- {spacr-0.3.34.dist-info → spacr-0.3.36.dist-info}/METADATA +1 -1
- {spacr-0.3.34.dist-info → spacr-0.3.36.dist-info}/RECORD +9 -9
- {spacr-0.3.34.dist-info → spacr-0.3.36.dist-info}/LICENSE +0 -0
- {spacr-0.3.34.dist-info → spacr-0.3.36.dist-info}/WHEEL +0 -0
- {spacr-0.3.34.dist-info → spacr-0.3.36.dist-info}/entry_points.txt +0 -0
- {spacr-0.3.34.dist-info → spacr-0.3.36.dist-info}/top_level.txt +0 -0
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,67 @@ 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
|
+
Adds a new column to the database table by matching on a common column from the DataFrame.
|
5049
|
+
If the column already exists in the database, it adds the column with a suffix.
|
5050
|
+
|
5051
|
+
Parameters:
|
5052
|
+
- settings: A dictionary containing the following keys:
|
5053
|
+
- 'csv_path': Path to the CSV file with the data to be added.
|
5054
|
+
- 'db_path': Path to the SQLite database (or connection string for other databases).
|
5055
|
+
- 'table_name': The name of the table in the database.
|
5056
|
+
- 'update_column': The name of the new column in the DataFrame to add to the database.
|
5057
|
+
- 'match_column': The common column used to match rows.
|
5058
|
+
"""
|
5059
|
+
|
5060
|
+
# Read the DataFrame from the provided CSV path
|
5061
|
+
df = pd.read_csv(settings['csv_path'])
|
5062
|
+
|
5063
|
+
# Connect to the SQLite database
|
5064
|
+
conn = sqlite3.connect(settings['db_path'])
|
5065
|
+
cursor = conn.cursor()
|
5066
|
+
|
5067
|
+
# Get the existing columns in the database table
|
5068
|
+
cursor.execute(f"PRAGMA table_info({settings['table_name']})")
|
5069
|
+
columns_in_db = [col[1] for col in cursor.fetchall()]
|
5070
|
+
|
5071
|
+
# Check if the update column already exists in the database
|
5072
|
+
if settings['update_column'] in columns_in_db:
|
5073
|
+
# Add a suffix to the column name (e.g., '_new', '_1', or similar)
|
5074
|
+
suffix = 1
|
5075
|
+
new_column_name = f"{settings['update_column']}_{suffix}"
|
5076
|
+
# Ensure uniqueness by incrementing the suffix if needed
|
5077
|
+
while new_column_name in columns_in_db:
|
5078
|
+
suffix += 1
|
5079
|
+
new_column_name = f"{settings['update_column']}_{suffix}"
|
5080
|
+
print(f"Column '{settings['update_column']}' already exists. Using new column name: '{new_column_name}'")
|
5081
|
+
else:
|
5082
|
+
new_column_name = settings['update_column']
|
5083
|
+
|
5084
|
+
# Add the new column to the database table
|
5085
|
+
cursor.execute(f"ALTER TABLE {settings['table_name']} ADD COLUMN {new_column_name} TEXT")
|
5086
|
+
print(f"Added new column '{new_column_name}' to the table '{settings['table_name']}'.")
|
5087
|
+
|
5088
|
+
# Iterate over the DataFrame and update the new column in the database
|
5089
|
+
for index, row in df.iterrows():
|
5090
|
+
value_to_update = row[settings['update_column']]
|
5091
|
+
match_value = row[settings['match_column']]
|
5092
|
+
|
5093
|
+
# Prepare and execute the SQL update query
|
5094
|
+
query = f"""
|
5095
|
+
UPDATE {settings['table_name']}
|
5096
|
+
SET {new_column_name} = ?
|
5097
|
+
WHERE {settings['match_column']} = ?
|
5098
|
+
"""
|
5099
|
+
cursor.execute(query, (value_to_update, match_value))
|
5100
|
+
|
5101
|
+
# Commit the transaction and close the connection
|
5102
|
+
conn.commit()
|
5103
|
+
conn.close()
|
5104
|
+
|
5105
|
+
print(f"Updated '{new_column_name}' in '{settings['table_name']}' using '{settings['match_column']}'.")
|
5106
|
+
|
5107
|
+
|
5108
|
+
|
@@ -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=
|
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=
|
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=
|
30
|
+
spacr/utils.py,sha256=iCbweRXWjJgKGbp8DAVC20xUG9nwy2K9cvIsXORAKwA,216043
|
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.
|
154
|
-
spacr-0.3.
|
155
|
-
spacr-0.3.
|
156
|
-
spacr-0.3.
|
157
|
-
spacr-0.3.
|
158
|
-
spacr-0.3.
|
153
|
+
spacr-0.3.36.dist-info/LICENSE,sha256=SR-2MeGc6SCM1UORJYyarSWY_A-JaOMFDj7ReSs9tRM,1083
|
154
|
+
spacr-0.3.36.dist-info/METADATA,sha256=NvcSKD3mIWOPeTDAAbugslvW-1_T0Dzd9k8WzSVNwbY,5949
|
155
|
+
spacr-0.3.36.dist-info/WHEEL,sha256=HiCZjzuy6Dw0hdX5R3LCFPDmFS4BWl8H-8W39XfmgX4,91
|
156
|
+
spacr-0.3.36.dist-info/entry_points.txt,sha256=BMC0ql9aNNpv8lUZ8sgDLQMsqaVnX5L535gEhKUP5ho,296
|
157
|
+
spacr-0.3.36.dist-info/top_level.txt,sha256=GJPU8FgwRXGzKeut6JopsSRY2R8T3i9lDgya42tLInY,6
|
158
|
+
spacr-0.3.36.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|