Skip to content

Commit 9b378ba

Browse files
committed
Formatting and linting
1 parent bfbe9fc commit 9b378ba

16 files changed

+65
-41
lines changed

cellpack_analysis/analysis/notebooks/grid_points_illustration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def add_distance_weights(axis_data, distance_type, distances, labels, decay_leng
219219
if measure == "distances":
220220
available_types = distance_configs.keys()
221221
else: # weights
222-
available_types = list(distance_configs.keys()) + ["mixed"]
222+
available_types = [*list(distance_configs.keys()), "mixed"]
223223

224224
for distance_type in available_types:
225225
# Skip mixed for distances since it doesn't exist

cellpack_analysis/analysis/notebooks/multi_structure_colocalization.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
"distances": {dm: {} for dm in distance_measures},
6767
},
6868
}
69-
all_structures = list(set([v["structure_id"] for v in distance_dict.values()]))
69+
all_structures = list({v["structure_id"] for v in distance_dict.values()})
7070
row_modes = ["peroxisome", "endosome"]
7171
col_modes = ["ER", "golgi"]
7272

cellpack_analysis/analysis/notebooks/multi_structure_colocalization_akaike.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
# %% [markdown]
5353
# ### Load occupancy EMD data
5454
df_list = []
55-
for packing_id, comparison_mode in packing_id_info.items():
55+
for packing_id, _comparison_mode in packing_id_info.items():
5656
logger.info(f"Loading data for packing id: {packing_id}")
5757

5858
occupancy_emd_df_path = occupancy_emd_folder / packing_id / "occupancy_emd.parquet"
@@ -122,14 +122,15 @@
122122
def calculate_aic(emd_values, n_params):
123123
"""
124124
Calculate AIC for EMD values.
125+
125126
AIC = 2k - 2ln(L)
126-
where k is number of parameters and L is likelihood
127+
where k is number of parameters and L is likelihood.
127128
128-
For EMD, we treat it as residuals and assume normal distribution
129+
For EMD, we treat it as residuals and assume normal distribution.
129130
"""
130131
n = len(emd_values)
131132
# Calculate log-likelihood assuming normal distribution
132-
# L = -n/2 * ln(2π) - n/2 * ln(σ²) - 1/(²) * Σ(residuals²)
133+
# L = -n/2 * ln(2π) - n/2 * ln(sigma²) - 1/(2sigma²) * Σ(residuals²)
133134
# For simplicity, we use mean squared error as proxy for -2ln(L)
134135
mse = np.mean(emd_values**2)
135136
# sigma2 = np.var(emd_values, ddof=1)
@@ -273,7 +274,7 @@ def calculate_aic(emd_values, n_params):
273274
"Blue: 5-param preferred\nRed: 4-param preferred",
274275
transform=ax1.transAxes,
275276
verticalalignment="top",
276-
bbox=dict(boxstyle="round", facecolor="white", alpha=0.8),
277+
bbox={"boxstyle": "round", "facecolor": "white", "alpha": 0.8},
277278
)
278279

279280
# Add strength indicators

cellpack_analysis/analysis/notebooks/multi_structure_colocalization_heatmap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
},
7676
}
7777
all_structures = list(
78-
set([v["channel_map"][k] for v in distance_dict.values() for k in v["channel_map"]])
78+
{v["channel_map"][k] for v in distance_dict.values() for k in v["channel_map"]}
7979
)
8080

8181
# %% [markdown]

cellpack_analysis/lib/distance.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ def get_distance_dictionary(
266266
break
267267

268268
all_distance_dict[distance_measure] = distance_dict
269-
if not all([len(v) > 0 for v in distance_dict.values()]):
269+
if not all(len(v) > 0 for v in distance_dict.values()):
270270
logger.warning(
271271
f"Cached data in {file_path.relative_to(PROJECT_ROOT)} is empty. "
272272
f"Recalculating distances."
@@ -303,9 +303,7 @@ def get_distance_dictionary(
303303
str(cell_id).split("_")[0],
304304
positions,
305305
mode_mesh_dict,
306-
): (
307-
str(cell_id).split("_")[0]
308-
)
306+
): (str(cell_id).split("_")[0])
309307
for cell_id, positions in position_dict.items()
310308
}
311309
for future in tqdm(

cellpack_analysis/lib/io.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ def load_dataframe(load_local: bool = True, prefix: str = "all_cell_ids") -> pd.
3939
----------
4040
load_local
4141
If True, attempt to load from local file first. If False, load from S3.
42+
prefix
43+
Prefix for the parquet file name.
4244
4345
Returns
4446
-------

cellpack_analysis/lib/label_tables.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ def adjust_color_saturation(hex_color, saturation):
77
"""
88
Adjust the saturation of a hex color.
99
10-
Parameters:
11-
-----------
10+
Parameters
11+
----------
1212
hex_color : str
1313
Hex color code (e.g., '#ff0000' or 'ff0000')
1414
saturation : float
1515
Saturation value between 0 and 1
1616
17-
Returns:
18-
--------
17+
Returns
18+
-------
1919
str
2020
Hex color code with adjusted saturation
2121
"""

cellpack_analysis/lib/mesh_tools.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -913,17 +913,17 @@ def get_grid_points_slice(
913913
"""
914914
Select a slice of grid points at the median coordinate along the projection axis.
915915
916-
Parameters:
917-
-----------
916+
Parameters
917+
----------
918918
all_grid_points : np.ndarray
919919
All grid points in pixels
920920
projection_axis : str
921921
Axis to project along ('x', 'y', or 'z')
922922
spacing : float
923923
Spacing between grid points in pixels
924924
925-
Returns:
926-
--------
925+
Returns
926+
-------
927927
grid_points_slice : np.ndarray
928928
Grid points for the selected slice in pixels
929929
"""
@@ -985,6 +985,8 @@ def get_distances_from_mesh(
985985
Points to calculate distances for
986986
mesh
987987
Mesh to calculate distances to
988+
invert
989+
If True, invert the sign of the distances.
988990
989991
Returns
990992
-------

cellpack_analysis/lib/occupancy.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ def get_kde_occupancy_dict(
8888
Maximum number of cells to sample per structure, by default None
8989
num_points
9090
Number of points for KDE evaluation, by default 100
91+
x_min
92+
Minimum x value for occupancy evaluation. Default is 0
93+
x_max
94+
Maximum x value for occupancy evaluation. Default is None
9195
9296
Returns
9397
-------
@@ -336,7 +340,7 @@ def get_occupancy_emd_df(
336340
337341
Parameters
338342
----------
339-
occupancy_dict
343+
combined_occupancy_dict
340344
Dictionary containing occupancy measures for each packing mode
341345
packing_modes
342346
List of packing modes to calculate pairwise EMD for
@@ -541,6 +545,8 @@ def interpolate_occupancy_dict(
541545
Dictionary containing occupancy data for each packing mode
542546
Has the structure:
543547
{distance_measure:{mode:{"individual":{ ... },"combined": { ... }}}}
548+
channel_map
549+
Mapping from packing modes to structure IDs
544550
baseline_mode
545551
The baseline packing mode used for interpolation
546552
results_dir
@@ -672,10 +678,10 @@ def interpolate_occupancy_dict(
672678
"modes": {
673679
mode: distance_data[mode]["combined"]["occupancy"] for mode in distance_data.keys()
674680
},
675-
"coeffs_individual": {
676-
mode: coeff for mode, coeff in zip(packing_modes, coeffs_individual)
677-
},
678-
"coeffs_joint": {mode: coeff for mode, coeff in zip(packing_modes, coeffs_joint)},
681+
"coeffs_individual": dict(
682+
zip(packing_modes, coeffs_individual, strict=False)
683+
),
684+
"coeffs_joint": dict(zip(packing_modes, coeffs_joint, strict=False)),
679685
"relative_contribution_individual": {
680686
mode: params["relative_contribution"]
681687
for mode, params in interp_dict["interpolation"]["individual"][distance_measure][

cellpack_analysis/lib/visualization.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,8 @@ def plot_occupancy_ratio(
705705
Dictionary containing occupancy information
706706
channel_map
707707
Dictionary mapping packing modes to channels
708+
baseline_mode
709+
The baseline packing mode for normalization. Default is None
708710
figures_dir
709711
Directory to save the figures
710712
suffix
@@ -719,6 +721,12 @@ def plot_occupancy_ratio(
719721
Y-axis limit for plots
720722
save_format
721723
Format to save the figures in
724+
fig_params
725+
Dictionary of figure parameters (dpi, figsize). Default is None
726+
plot_individual
727+
Whether to plot individual cell data. Default is True
728+
show_legend
729+
Whether to show the legend. Default is False
722730
723731
Returns
724732
-------
@@ -838,6 +846,8 @@ def plot_occupancy_ratio_interpolation(
838846
Format to save the figures in
839847
plot_type
840848
Type of plot to generate: "individual" or "joint"
849+
fig_params
850+
Dictionary of figure parameters (dpi, figsize). Default is None
841851
842852
Returns
843853
-------
@@ -1514,8 +1524,12 @@ def plot_grid_points_slice(
15141524
Size of scatter plot points (default: 2)
15151525
projection_axis
15161526
Axis of projection ('x', 'y', or 'z')
1527+
cmap
1528+
Colormap to use for coloring. Default is None
15171529
reverse_cmap
15181530
Whether to reverse the colormap
1531+
clim
1532+
Color limits as (min, max) tuple. Default is None
15191533
15201534
Returns
15211535
-------

0 commit comments

Comments
 (0)