Skip to content

Commit

Permalink
Merge pull request #122 from gwaygenomics/sample-images
Browse files Browse the repository at this point in the history
Adding Code to Visualize Example Images
  • Loading branch information
gwaybio authored Apr 1, 2020
2 parents 460c444 + 4f7ffc0 commit fc4735b
Show file tree
Hide file tree
Showing 129 changed files with 706 additions and 51 deletions.
257 changes: 257 additions & 0 deletions 1.generate-profiles/4.load-example-cell-painting-image.ipynb

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
#!/usr/bin/env python
# coding: utf-8

# # Load an Example Image for Approach Figure
#
# Here, I use `skimage` to load, process, and output example images across channels and an example composite image with merged channels.
#
# Note that much of this code was adapted from https://github.com/jr0th/segmentation/blob/master/visualization/CellArt.ipynb and with insights from Marzieh Haghighi.

# In[1]:


import os
import sys
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

import skimage.io
import skimage.exposure

from pycytominer.aggregate import AggregateProfiles


# In[2]:


sys.path.append("../scripts")
from grabPictures import grabPicture


# ## Set File Paths

# In[3]:


bucket_path = "/home/ubuntu/bucket/projects/2015_07_01_Cell_Health_Vazquez_Cancer_Broad/"
image_path = os.path.join(bucket_path, "CRISPR_PILOT_B1/images/")
sqlite_path = os.path.join(bucket_path, "workspace/backend/CRISPR_PILOT_B1/")
metadata_path = os.path.join("data", "metadata")


# In[4]:


plate = "SQ00014613"
sqlite_dir = os.path.join(sqlite_path, plate)
sqlite_file = "sqlite:///{}/{}.sqlite".format(sqlite_dir, plate)
sqlite_file


# In[5]:


barcode_file = os.path.join(metadata_path, "barcode_platemap.csv")
platemap_name = pd.read_csv(barcode_file).query("Assay_Plate_Barcode == @plate").Plate_Map_Name.values[0]
platemap_path = os.path.join(metadata_path, "platemap", "{}.csv".format(platemap_name))


# ## Process Data and Load Example Images

# In[6]:


gene_name = "EMPTY"
pert_name = "EMPTY"
site = 1


# In[7]:


example_image = grabPicture(
bucket_path=bucket_path,
image_path=image_path,
sqlite_path=sqlite_path,
metadata_path=metadata_path,
plate=plate,
aggregate_strata_cols=["Image_Metadata_Plate", "Image_Metadata_Well"],
gene_name=gene_name,
pert_name=pert_name,
site=site,
)


# In[8]:


example_image.load_image_table(get_well=True)


# In[9]:


# Prep images with a narrow crop
example_image.prep_images(low_prop=0.1, high_prop=0.3)


# ## Output an Example Image

# In[10]:


example_image.plot_images(cropped=True, color=False)

output_file = os.path.join("figures", "example_images", "greyscale_channel.png")
plt.subplots_adjust(top=0.8)
plt.savefig(output_file, pad_inches=0.2, dpi=500)


# In[11]:


example_image.plot_images(cropped=True, color=True)

output_file = os.path.join("figures", "example_images", "color_channel.png")
plt.subplots_adjust(top=0.8)
plt.savefig(output_file, pad_inches=0.2, dpi=500)


# In[12]:


example_image.plot_combined_image()

output_file = os.path.join("figures", "example_images", "color_merged.png")
plt.savefig(output_file, dpi=500)

41 changes: 20 additions & 21 deletions 3.train/4.visualize-regression-performance.ipynb

Large diffs are not rendered by default.

8 changes: 2 additions & 6 deletions 3.train/7.visualize-cell-line-performance.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -557,12 +557,8 @@
" xlab(\"CRISPR Efficiency\") + \n",
" scale_color_manual(\n",
" name = \"Cell Line\",\n",
" labels = c(\"A549\" = \"A549\",\n",
" \"ES2\" = \"ES2\",\n",
" \"HCC44\" = \"HCC44\"),\n",
" values = c(\"A549\" = \"#7fc97f\",\n",
" \"ES2\" = \"#beaed4\",\n",
" \"HCC44\" = \"#fdc086\")\n",
" labels = cell_line_labels,\n",
" values = cell_line_colors\n",
" ) +\n",
" coord_fixed() +\n",
" theme_bw() +\n",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Diff not rendered.
12 changes: 12 additions & 0 deletions 3.train/scripts/assay_themes.R
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,18 @@ dye_labels <- c(
"qc" = "CRISPR Efficiency"
)

cell_line_labels <- c(
"A549" = "A549",
"ES2" = "ES2",
"HCC44" = "HCC44"
)

cell_line_colors <- c(
"A549" = "#7fc97f",
"ES2" = "#beaed4",
"HCC44" = "#fdc086"
)

dye_theme <- theme(
axis.title = element_text(size = 4),
axis.title.x = element_text(margin = margin(0, 0, 0, 0)),
Expand Down
35 changes: 17 additions & 18 deletions 3.train/scripts/nbconverted/4.visualize-regression-performance.r
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,11 @@ rsquared_bar_cellline_gg <- ggplot(cellline_compare_regression_df,
xlab(bquote("Test Set "~R^2~"")) +
ylab("Cell Health Target") +
facet_wrap(~outlier, scales="free_x") +
scale_color_manual(name = "Cell Line",
values = c("A549" = "#A1473A", "ES2" = "#209481", "HCC44" = "#241B3B"),
labels = c("A549" = "A549", "ES2" = "ES2", "HCC44" = "HCC44")) +
scale_color_manual(
name = "Cell Line",
labels = cell_line_labels,
values = cell_line_colors
) +
theme(axis.text.x = element_text(size = 8, angle = 90),
axis.text.y = element_text(size = 5.5),
axis.title = element_text(size = 10),
Expand Down Expand Up @@ -376,6 +378,7 @@ ggplot(r2_spread_df,
ggtitle("Regression Performance") +
theme_bw() +
facet_wrap("~data_type") +
coord_fixed() +
scale_color_manual(
name = "Cell Health\nPhenotypes",
values = measurement_colors,
Expand Down Expand Up @@ -445,6 +448,7 @@ for (good_model in c(good_example_models, bad_example_models)) {
plot_list[[good_model]] <- ggplot(sup_fig_good_subset_df,
aes(x = recode_target_value_true,
y = recode_target_value_pred)) +
geom_smooth(method='lm', formula=y~x) +
geom_point(aes(color = Metadata_cell_line),
size = 0.5,
alpha = 0.8) +
Expand All @@ -453,14 +457,11 @@ for (good_model in c(good_example_models, bad_example_models)) {
theme_bw() +
xlab("True Values") +
ylab("Predicted Values") +
scale_color_manual(name = "Cell Line",
labels = c("A549" = "A549",
"ES2" = "ES2",
"HCC44" = "HCC44"),
values = c("A549" = "#7fc97f",
"ES2" = "#beaed4",
"HCC44" = "#fdc086")) +
geom_smooth(method='lm', formula=y~x) +
scale_color_manual(
name = "Cell Line",
labels = cell_line_labels,
values = cell_line_colors
) +
geom_text(data = r2_df, size = 3, aes(label = paste("R2 =", r2), x = x, y = y)) +
theme(strip.text = element_text(size = 10),
strip.background = element_rect(colour = "black",
Expand Down Expand Up @@ -580,13 +581,11 @@ for (target in unique(y_plot_df$target)) {
theme_bw() +
xlab("True Values") +
ylab("Predicted Values") +
scale_color_manual(name = "Cell Line",
labels = c("A549" = "A549",
"ES2" = "ES2",
"HCC44" = "HCC44"),
values = c("A549" = "#7fc97f",
"ES2" = "#beaed4",
"HCC44" = "#fdc086")) +
scale_color_manual(
name = "Cell Line",
labels = cell_line_labels,
values = cell_line_colors
) +
geom_smooth(method='lm', formula=y~x) +
theme(strip.text = element_text(size = 10),
strip.background = element_rect(colour = "black",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,8 @@ ggplot(summary_df, aes(x = mean_crispr_eff, y = mean_rsquared_diff, color = Meta
xlab("CRISPR Efficiency") +
scale_color_manual(
name = "Cell Line",
labels = c("A549" = "A549",
"ES2" = "ES2",
"HCC44" = "HCC44"),
values = c("A549" = "#7fc97f",
"ES2" = "#beaed4",
"HCC44" = "#fdc086")
labels = cell_line_labels,
values = cell_line_colors
) +
coord_fixed() +
theme_bw() +
Expand Down
Empty file added scripts/__init__.py
Empty file.
Loading

0 comments on commit fc4735b

Please sign in to comment.