-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Quick run_all_manuscript_workflow error catching #53
Merged
jcass11
merged 10 commits into
feature_doc_test_density
from
feature_doc_test_density_frick
Dec 6, 2024
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
167d0ba
add density to perturbation manifests
chantelleleveille 30d8555
Merge remote-tracking branch 'origin/dev' into density_calc
chantelleleveille 5331938
Merge branch 'dev' of github.com:AllenCell/nuc-morph-analysis into de…
cfrick13 af2652c
small fix to generate_perturbation_manifest to avoid parallel errors
cfrick13 79de7c9
updated all_datasets to read fmsid for newly generated main_manifests…
cfrick13 248cdd7
add temp code to sanity check density over time for perturbations
cfrick13 4531e86
Merge pull request #47 from AllenCell/density_calc
cfrick13 1e0dcc8
make fast load_local run all
cfrick13 df10a28
Merge branch 'dev' of github.com:AllenCell/nuc-morph-analysis into fe…
cfrick13 b81fdc1
restore load_local=False
cfrick13 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
103 changes: 103 additions & 0 deletions
103
...orph_analysis/analyses/density/extra_checks/check_that_density_works_for_perturbations.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
# %% | ||
from nuc_morph_analysis.lib.preprocessing.global_dataset_filtering import load_dataset_with_features | ||
from nuc_morph_analysis.lib.preprocessing import filter_data | ||
import matplotlib.pyplot as plt | ||
import matplotlib.pyplot as plt | ||
import matplotlib | ||
from nuc_morph_analysis.lib.visualization.notebook_tools import save_and_show_plot | ||
from nuc_morph_analysis.lib.visualization.plotting_tools import get_plot_labels_for_metric | ||
from nuc_morph_analysis.lib.visualization.reference_points import COLONY_COLORS, COLONY_LABELS | ||
from nuc_morph_analysis.analyses.inhibitors.dataset_info import get_drug_perturbation_details_from_colony_name | ||
|
||
matplotlib.rcParams["pdf.fonttype"] = 42 | ||
plt.rcParams["font.family"] = "Arial" | ||
|
||
#%% | ||
def try_to_get_drug_name(colony_name): | ||
try: | ||
return get_drug_perturbation_details_from_colony_name(colony_name)["drugs_string"] | ||
except: | ||
return colony_name | ||
|
||
def plot_perturbation_densities(df, figdir, time_axis = 'real_time', error="percentile", show_legend=True, interval=5,titlestr=""): | ||
fig, ax = plt.subplots(1, 1, figsize=(10, 4)) | ||
|
||
feature_col = "2d_area_nuc_cell_ratio" | ||
scale, label, units, _ = get_plot_labels_for_metric(feature_col) | ||
|
||
new_colors = plt.cm.tab20(range(20)) | ||
for ci, (colony, df_colony) in enumerate(df.groupby("colony")): | ||
df_colony = df_colony.sort_values("index_sequence") | ||
|
||
color = COLONY_COLORS.get(colony,new_colors[ci]) | ||
|
||
if time_axis == "real_time": | ||
time_col = "index_sequence" | ||
x_label = "Real Time (hr)" | ||
if time_axis == "colony_time": | ||
time_col = "colony_time" | ||
x_label = "Aligned Colony Time (hr)" | ||
|
||
grouper = df_colony[[time_col] + [feature_col]].groupby(time_col)[ | ||
feature_col | ||
] | ||
|
||
# filter grouper so that only timepoints with more than 15 cells are included | ||
count = grouper.count() | ||
log_count = count[count>15].index | ||
|
||
|
||
mean_density = grouper.mean() * scale | ||
if error == "std": | ||
std_density = grouper.std() * scale | ||
lower = mean_density - std_density | ||
upper = mean_density + std_density | ||
if error == "percentile": | ||
lower = grouper.quantile(0.05) * scale | ||
upper = grouper.quantile(0.95) * scale | ||
|
||
time = mean_density.index.values * interval / 60 | ||
|
||
time = time[log_count] | ||
mean_density = mean_density[log_count] | ||
lower = lower[log_count] | ||
upper = upper[log_count] | ||
|
||
ax.fill_between( | ||
time, | ||
lower, | ||
upper, | ||
alpha=0.12, | ||
color=color, | ||
zorder=0, | ||
edgecolor="none", | ||
label=COLONY_LABELS.get(colony,try_to_get_drug_name(colony)), | ||
) | ||
ax.plot( | ||
time, mean_density, linewidth=1.2, color=color, label="", zorder=20 | ||
) | ||
|
||
ax.set_ylabel(f"Average Density \n Across Colony {units}") | ||
ax.set_xlabel(x_label) | ||
if show_legend is True: | ||
# ax.legend(loc="upper right", handletextpad=0.7, frameon=False) | ||
# put legend outside to the right | ||
ax.legend(loc="center left", bbox_to_anchor=(1.1, 0.5), frameon=False) | ||
plt.title(titlestr) | ||
plt.tight_layout() | ||
# save_and_show_plot( | ||
# f"{figdir}/avg_density_colony_{time_axis}_alignment-{feature_col}", | ||
# file_extension=".pdf", | ||
# dpi=300, | ||
# transparent=True, | ||
# ) | ||
|
||
from nuc_morph_analysis.lib.preprocessing.global_dataset_filtering import load_dataset_with_features | ||
for dataset in ["all_drug_perturbation","all_feeding_control","all_baseline"]: | ||
df0 = load_dataset_with_features(dataset,load_local=True) | ||
df = filter_data.all_timepoints_minimal_filtering(df0) | ||
figdir = f"figures/{dataset}/density_plots" | ||
plot_perturbation_densities(df, figdir, time_axis = 'real_time', error="percentile", show_legend=True, interval=5,titlestr=dataset) | ||
|
||
|
||
#%% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -393,7 +393,7 @@ def merge_datasets(df_all, df_full): | |
'resolution_level', | ||
'2d_area_cyto', | ||
'inv_cyto_density', | ||
'density' | ||
'density', | ||
|
||
# created in add_groth_features.fit_tracks_to_model() | ||
'tscale_exponentialfit_volume', | ||
|
@@ -438,6 +438,8 @@ def remove_columns(df, column_list=COLUMNS_TO_DROP): | |
df : pandas.DataFrame | ||
The dataframe with the columns removed. | ||
""" | ||
column_list = [col for col in column_list if col in df.columns] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you! |
||
|
||
df = df.drop(columns=column_list) | ||
return df | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!