spacr 0.3.60__py3-none-any.whl → 0.3.62__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/app_annotate.py +0 -8
- spacr/core.py +12 -7
- spacr/gui_utils.py +24 -8
- spacr/io.py +134 -157
- spacr/ml.py +3 -4
- spacr/plot.py +82 -23
- spacr/settings.py +4 -13
- spacr/submodules.py +299 -5
- spacr/utils.py +96 -3
- {spacr-0.3.60.dist-info → spacr-0.3.62.dist-info}/METADATA +1 -1
- {spacr-0.3.60.dist-info → spacr-0.3.62.dist-info}/RECORD +15 -15
- {spacr-0.3.60.dist-info → spacr-0.3.62.dist-info}/LICENSE +0 -0
- {spacr-0.3.60.dist-info → spacr-0.3.62.dist-info}/WHEEL +0 -0
- {spacr-0.3.60.dist-info → spacr-0.3.62.dist-info}/entry_points.txt +0 -0
- {spacr-0.3.60.dist-info → spacr-0.3.62.dist-info}/top_level.txt +0 -0
spacr/utils.py
CHANGED
@@ -1371,7 +1371,7 @@ def annotate_conditions(df, cells=None, cell_loc=None, pathogens=None, pathogen_
|
|
1371
1371
|
|
1372
1372
|
return df
|
1373
1373
|
|
1374
|
-
def
|
1374
|
+
def _split_data_v1(df, group_by, object_type):
|
1375
1375
|
"""
|
1376
1376
|
Splits the input dataframe into numeric and non-numeric parts, groups them by the specified column,
|
1377
1377
|
and returns the grouped dataframes.
|
@@ -1385,16 +1385,72 @@ def _split_data(df, group_by, object_type):
|
|
1385
1385
|
grouped_numeric (pandas.DataFrame): The grouped dataframe containing numeric columns.
|
1386
1386
|
grouped_non_numeric (pandas.DataFrame): The grouped dataframe containing non-numeric columns.
|
1387
1387
|
"""
|
1388
|
+
|
1389
|
+
if 'prcf' not in df.columns:
|
1390
|
+
try:
|
1391
|
+
df['prcf'] = df['plate'].astype(str) + '_' + df['row_name'].astype(str) + '_' + df['column_name'].astype(str) + '_' + df['field'].astype(str)
|
1392
|
+
except Exception as e:
|
1393
|
+
print(e)
|
1394
|
+
|
1388
1395
|
df['prcfo'] = df['prcf'] + '_' + df[object_type]
|
1389
1396
|
df = df.set_index(group_by, inplace=False)
|
1390
1397
|
|
1391
1398
|
df_numeric = df.select_dtypes(include=np.number)
|
1392
1399
|
df_non_numeric = df.select_dtypes(exclude=np.number)
|
1400
|
+
|
1401
|
+
[]
|
1393
1402
|
|
1394
1403
|
grouped_numeric = df_numeric.groupby(df_numeric.index).mean()
|
1395
1404
|
grouped_non_numeric = df_non_numeric.groupby(df_non_numeric.index).first()
|
1396
1405
|
|
1397
1406
|
return pd.DataFrame(grouped_numeric), pd.DataFrame(grouped_non_numeric)
|
1407
|
+
|
1408
|
+
def _split_data(df, group_by, object_type):
|
1409
|
+
"""
|
1410
|
+
Splits the input dataframe into numeric and non-numeric parts, groups them by the specified column,
|
1411
|
+
and returns the grouped dataframes with conditional aggregation.
|
1412
|
+
|
1413
|
+
Parameters:
|
1414
|
+
df (pandas.DataFrame): The input dataframe.
|
1415
|
+
group_by (str): The column name to group the dataframes by.
|
1416
|
+
object_type (str): The column name to concatenate with 'prcf' to create a new column 'prcfo'.
|
1417
|
+
|
1418
|
+
Returns:
|
1419
|
+
grouped_numeric (pandas.DataFrame): The grouped dataframe containing numeric columns with conditional aggregation.
|
1420
|
+
grouped_non_numeric (pandas.DataFrame): The grouped dataframe containing non-numeric columns.
|
1421
|
+
"""
|
1422
|
+
|
1423
|
+
# Ensure 'prcf' column exists by concatenating specific columns
|
1424
|
+
if 'prcf' not in df.columns:
|
1425
|
+
try:
|
1426
|
+
df['prcf'] = df['plate'].astype(str) + '_' + df['row_name'].astype(str) + '_' + df['column_name'].astype(str) + '_' + df['field'].astype(str)
|
1427
|
+
except Exception as e:
|
1428
|
+
print(e)
|
1429
|
+
|
1430
|
+
# Create the 'prcfo' column
|
1431
|
+
df['prcfo'] = df['prcf'] + '_' + df[object_type]
|
1432
|
+
df = df.set_index(group_by, inplace=False)
|
1433
|
+
|
1434
|
+
# Split the DataFrame into numeric and non-numeric parts
|
1435
|
+
df_numeric = df.select_dtypes(include=np.number)
|
1436
|
+
df_non_numeric = df.select_dtypes(exclude=np.number)
|
1437
|
+
|
1438
|
+
# Define keywords for columns to be summed instead of averaged
|
1439
|
+
sum_keywords = ['area', 'perimeter', 'convex_area', 'bbox_area', 'filled_area', 'major_axis_length', 'minor_axis_length', 'equivalent_diameter']
|
1440
|
+
|
1441
|
+
# Create a dictionary for custom aggregation
|
1442
|
+
agg_dict = {}
|
1443
|
+
for column in df_numeric.columns:
|
1444
|
+
if any(keyword in column for keyword in sum_keywords):
|
1445
|
+
agg_dict[column] = 'sum'
|
1446
|
+
else:
|
1447
|
+
agg_dict[column] = 'mean'
|
1448
|
+
|
1449
|
+
# Apply custom aggregation
|
1450
|
+
grouped_numeric = df_numeric.groupby(df_numeric.index).agg(agg_dict)
|
1451
|
+
grouped_non_numeric = df_non_numeric.groupby(df_non_numeric.index).first()
|
1452
|
+
|
1453
|
+
return pd.DataFrame(grouped_numeric), pd.DataFrame(grouped_non_numeric)
|
1398
1454
|
|
1399
1455
|
def _calculate_recruitment(df, channel):
|
1400
1456
|
"""
|
@@ -4052,7 +4108,7 @@ def measure_test_mode(settings):
|
|
4052
4108
|
|
4053
4109
|
return settings
|
4054
4110
|
|
4055
|
-
def preprocess_data(df, filter_by, remove_highly_correlated, log_data, exclude):
|
4111
|
+
def preprocess_data(df, filter_by, remove_highly_correlated, log_data, exclude, column_list=False):
|
4056
4112
|
"""
|
4057
4113
|
Preprocesses the given dataframe by applying filtering, removing highly correlated columns,
|
4058
4114
|
applying log transformation, filling NaN values, and scaling the numeric data.
|
@@ -4076,7 +4132,10 @@ def preprocess_data(df, filter_by, remove_highly_correlated, log_data, exclude):
|
|
4076
4132
|
# Apply filtering based on the `filter_by` parameter
|
4077
4133
|
if filter_by is not None:
|
4078
4134
|
df, _ = filter_dataframe_features(df, channel_of_interest=filter_by, exclude=exclude)
|
4079
|
-
|
4135
|
+
|
4136
|
+
if column_list:
|
4137
|
+
df = df[column_list]
|
4138
|
+
|
4080
4139
|
# Select numerical features
|
4081
4140
|
numeric_data = df.select_dtypes(include=['number'])
|
4082
4141
|
|
@@ -4181,6 +4240,7 @@ def filter_dataframe_features(df, channel_of_interest, exclude=None, remove_low_
|
|
4181
4240
|
|
4182
4241
|
if verbose:
|
4183
4242
|
print("Columns to remove:", count_and_id_columns)
|
4243
|
+
|
4184
4244
|
df = df.drop(columns=count_and_id_columns)
|
4185
4245
|
|
4186
4246
|
if not channel_of_interest is None:
|
@@ -4189,6 +4249,9 @@ def filter_dataframe_features(df, channel_of_interest, exclude=None, remove_low_
|
|
4189
4249
|
if isinstance(channel_of_interest, list):
|
4190
4250
|
feature_strings = [f"channel_{channel}" for channel in channel_of_interest]
|
4191
4251
|
|
4252
|
+
elif isinstance(channel_of_interest, str):
|
4253
|
+
feature_strings = [channel_of_interest]
|
4254
|
+
|
4192
4255
|
elif isinstance(channel_of_interest, int):
|
4193
4256
|
feature_string = f"channel_{channel_of_interest}"
|
4194
4257
|
feature_strings = [feature_string]
|
@@ -5164,3 +5227,33 @@ def rename_columns_in_db(db_path):
|
|
5164
5227
|
# After closing the 'with' block, run VACUUM outside of any transaction
|
5165
5228
|
with sqlite3.connect(db_path) as conn:
|
5166
5229
|
conn.execute("VACUUM;")
|
5230
|
+
|
5231
|
+
def group_feature_class(df, feature_groups=['cell', 'cytoplasm', 'nucleus', 'pathogen'], name='compartment'):
|
5232
|
+
|
5233
|
+
# Function to determine compartment based on multiple matches
|
5234
|
+
def find_feature_class(feature, compartments):
|
5235
|
+
matches = [compartment for compartment in compartments if re.search(compartment, feature)]
|
5236
|
+
if len(matches) > 1:
|
5237
|
+
return '-'.join(matches)
|
5238
|
+
elif matches:
|
5239
|
+
return matches[0]
|
5240
|
+
else:
|
5241
|
+
return None
|
5242
|
+
|
5243
|
+
from .plot import spacrGraph
|
5244
|
+
|
5245
|
+
df[name] = df['feature'].apply(lambda x: find_feature_class(x, feature_groups))
|
5246
|
+
|
5247
|
+
if name == 'channel':
|
5248
|
+
df['channel'].fillna('morphology', inplace=True)
|
5249
|
+
|
5250
|
+
# Create new DataFrame with summed importance for each compartment and channel
|
5251
|
+
importance_sum = df.groupby(name)['importance'].sum().reset_index(name=f'{name}_importance_sum')
|
5252
|
+
total_compartment_importance = importance_sum[f'{name}_importance_sum'].sum()
|
5253
|
+
importance_sum = pd.concat(
|
5254
|
+
[importance_sum,
|
5255
|
+
pd.DataFrame(
|
5256
|
+
[{name: 'all', '{name}_importance_sum': total_compartment_importance}])]
|
5257
|
+
, ignore_index=True)
|
5258
|
+
|
5259
|
+
return df
|
@@ -1,6 +1,6 @@
|
|
1
1
|
spacr/__init__.py,sha256=CZtAdU5etLcb9dVmz-4Y7Hjhw3ubjMzfjG0L5ybyFVA,1592
|
2
2
|
spacr/__main__.py,sha256=bkAJJD2kjIqOP-u1kLvct9jQQCeUXzlEjdgitwi1Lm8,75
|
3
|
-
spacr/app_annotate.py,sha256=
|
3
|
+
spacr/app_annotate.py,sha256=W9eLPa_LZIvXsXx_-0iDFEU938LBDvRy6prXo0qF4KQ,2533
|
4
4
|
spacr/app_classify.py,sha256=urTP_wlZ58hSyM5a19slYlBxN0PdC-9-ga0hvq8CGWc,165
|
5
5
|
spacr/app_make_masks.py,sha256=pqDhRpluiHZz-kPX2Zh_KbYe4TsU43qYBa_7f-rsjpw,1694
|
6
6
|
spacr/app_mask.py,sha256=l-dBY8ftzCMdDe6-pXc2Nh_u-idNL9G7UOARiLJBtds,153
|
@@ -9,26 +9,26 @@ spacr/app_sequencing.py,sha256=DjG26jy4cpddnV8WOOAIiExtOe9MleVMY4MFa5uTo5w,157
|
|
9
9
|
spacr/app_umap.py,sha256=ZWAmf_OsIKbYvolYuWPMYhdlVe-n2CADoJulAizMiEo,153
|
10
10
|
spacr/cellpose.py,sha256=RBHMs2vwXcfkj0xqAULpALyzJYXddSRycgZSzmwI7v0,14755
|
11
11
|
spacr/chat_bot.py,sha256=n3Fhqg3qofVXHmh3H9sUcmfYy9MmgRnr48663MVdY9E,1244
|
12
|
-
spacr/core.py,sha256=
|
12
|
+
spacr/core.py,sha256=3u2qKmPmTlswvE1uKTF4gi7KQ3sJBHV9No_ysgk7JCU,48487
|
13
13
|
spacr/deep_spacr.py,sha256=HdOcNU8cHcE_19nP7_5uTz-ih3E169ffr2Hm--NvMvA,43255
|
14
14
|
spacr/gui.py,sha256=ARyn9Q_g8HoP-cXh1nzMLVFCKqthY4v2u9yORyaQqQE,8230
|
15
15
|
spacr/gui_core.py,sha256=N7R7yvfK_dJhOReM_kW3Ci8Bokhi1OzsxeKqvSGdvV4,41460
|
16
16
|
spacr/gui_elements.py,sha256=EKlvEg_4_je7jciEdR3NTgPrcTraowa2e2RUt-xqd6M,138254
|
17
|
-
spacr/gui_utils.py,sha256=
|
18
|
-
spacr/io.py,sha256=
|
17
|
+
spacr/gui_utils.py,sha256=u9RoIOWpAXFEOnUlLpMQZrc1pWSg6omZsJMIhJdRv_g,41211
|
18
|
+
spacr/io.py,sha256=0cBVmhqMaPkdEXib5Vhp19FC_1qfaK_NgtoImuDuwGU,142664
|
19
19
|
spacr/logger.py,sha256=lJhTqt-_wfAunCPl93xE65Wr9Y1oIHJWaZMjunHUeIw,1538
|
20
20
|
spacr/measure.py,sha256=2lK-ZcTxLM-MpXV1oZnucRD9iz5aprwahRKw9IEqshg,55085
|
21
21
|
spacr/mediar.py,sha256=FwLvbLQW5LQzPgvJZG8Lw7GniA2vbZx6Jv6vIKu7I5c,14743
|
22
|
-
spacr/ml.py,sha256=
|
22
|
+
spacr/ml.py,sha256=aLDeeaAl0d4-RP1CzFHPqz5br2HrFbJhvPexEm9lvSI,68198
|
23
23
|
spacr/openai.py,sha256=5vBZ3Jl2llYcW3oaTEXgdyCB2aJujMUIO5K038z7w_A,1246
|
24
|
-
spacr/plot.py,sha256=
|
24
|
+
spacr/plot.py,sha256=zITe54dzQRz-gk_ZT0qJyARuUWJivIBKW8V4rjUH8SE,160320
|
25
25
|
spacr/sequencing.py,sha256=ClUfwPPK6rNUbUuiEkzcwakzVyDKKUMv9ricrxT8qQY,25227
|
26
|
-
spacr/settings.py,sha256=
|
26
|
+
spacr/settings.py,sha256=zANLspVmllDZeYjQWIfrHN3VkVgicnYGTduv30MmQ18,77257
|
27
27
|
spacr/sim.py,sha256=1xKhXimNU3ukzIw-3l9cF3Znc_brW8h20yv8fSTzvss,71173
|
28
|
-
spacr/submodules.py,sha256=
|
28
|
+
spacr/submodules.py,sha256=Xq4gjvooHN8S7cTk5PIAkd7XD2c7CMVqNpeo8GCvtHc,42489
|
29
29
|
spacr/timelapse.py,sha256=KGfG4L4-QnFfgbF7L6C5wL_3gd_rqr05Foje6RsoTBg,39603
|
30
30
|
spacr/toxo.py,sha256=z2nT5aAze3NUIlwnBQcnkARihDwoPfqOgQIVoUluyK0,25087
|
31
|
-
spacr/utils.py,sha256=
|
31
|
+
spacr/utils.py,sha256=vvciLh1gH0nsrCWQw3taUcDjxP59wme3gqrejeNO05w,222943
|
32
32
|
spacr/version.py,sha256=axH5tnGwtgSnJHb5IDhiu4Zjk5GhLyAEDRe-rnaoFOA,409
|
33
33
|
spacr/resources/MEDIAR/.gitignore,sha256=Ff1q9Nme14JUd-4Q3jZ65aeQ5X4uttptssVDgBVHYo8,152
|
34
34
|
spacr/resources/MEDIAR/LICENSE,sha256=yEj_TRDLUfDpHDNM0StALXIt6mLqSgaV2hcCwa6_TcY,1065
|
@@ -151,9 +151,9 @@ spacr/resources/icons/umap.png,sha256=dOLF3DeLYy9k0nkUybiZMe1wzHQwLJFRmgccppw-8b
|
|
151
151
|
spacr/resources/images/plate1_E01_T0001F001L01A01Z01C02.tif,sha256=Tl0ZUfZ_AYAbu0up_nO0tPRtF1BxXhWQ3T3pURBCCRo,7958528
|
152
152
|
spacr/resources/images/plate1_E01_T0001F001L01A02Z01C01.tif,sha256=m8N-V71rA1TT4dFlENNg8s0Q0YEXXs8slIn7yObmZJQ,7958528
|
153
153
|
spacr/resources/images/plate1_E01_T0001F001L01A03Z01C03.tif,sha256=Pbhk7xn-KUP6RSIhJsxQcrHFImBm3GEpLkzx7WOc-5M,7958528
|
154
|
-
spacr-0.3.
|
155
|
-
spacr-0.3.
|
156
|
-
spacr-0.3.
|
157
|
-
spacr-0.3.
|
158
|
-
spacr-0.3.
|
159
|
-
spacr-0.3.
|
154
|
+
spacr-0.3.62.dist-info/LICENSE,sha256=SR-2MeGc6SCM1UORJYyarSWY_A-JaOMFDj7ReSs9tRM,1083
|
155
|
+
spacr-0.3.62.dist-info/METADATA,sha256=Ox14lWGxbXuMW36MriYHppKcZDqD_4HopfbcLAi8dLc,6032
|
156
|
+
spacr-0.3.62.dist-info/WHEEL,sha256=HiCZjzuy6Dw0hdX5R3LCFPDmFS4BWl8H-8W39XfmgX4,91
|
157
|
+
spacr-0.3.62.dist-info/entry_points.txt,sha256=BMC0ql9aNNpv8lUZ8sgDLQMsqaVnX5L535gEhKUP5ho,296
|
158
|
+
spacr-0.3.62.dist-info/top_level.txt,sha256=GJPU8FgwRXGzKeut6JopsSRY2R8T3i9lDgya42tLInY,6
|
159
|
+
spacr-0.3.62.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|