Skip to content

Commit

Permalink
Auto updated the code style with https://github.com/LieberInstitute/s…
Browse files Browse the repository at this point in the history
  • Loading branch information
lcolladotor committed Feb 16, 2023
1 parent da849f1 commit 702ca0c
Show file tree
Hide file tree
Showing 32 changed files with 3,540 additions and 2,752 deletions.
12 changes: 6 additions & 6 deletions code/analysis/01_build_spe/03_add_deconvolution.R
Original file line number Diff line number Diff line change
Expand Up @@ -151,19 +151,19 @@ for (sample_id in anno_samples) {
"\\{sample_id\\}", sample_id, anno_wrinkle_path
)
this_anno_layers_path <- sub("\\{sample_id\\}", sample_id, anno_layers_path)

# Read in wrinkle annotation and use unique and informative colnames
anno_wrinkle <- this_anno_wrinkle_path |>
read.csv() |>
as_tibble() |>
rename(wrinkle_type = ManualAnnotation, barcode = spot_name)

# Read in layer annotation and use unique and informative colnames
anno_layers <- this_anno_layers_path |>
read.csv() |>
as_tibble() |>
rename(manual_layer_label = ManualAnnotation, barcode = spot_name)

anno_list[[sample_id]] <- anno_layers |>
full_join(anno_wrinkle, by = c("sample_id", "barcode"))
}
Expand Down Expand Up @@ -191,11 +191,11 @@ colData(spe) <- colData(spe)[, sort(colnames(colData(spe)))]
# Interactively double-check that the annotations merged as expected

# table(is.na(spe$manual_layer_label))
# FALSE TRUE
# FALSE TRUE
# 11991 101936

# table(is.na(spe$wrinkle_type))
# FALSE TRUE
# FALSE TRUE
# 2094 111833

# vis_clus(spe, sampleid = anno_samples[1], clustervar = "wrinkle_type") +
Expand Down Expand Up @@ -271,7 +271,7 @@ session_info()
# tz US/Eastern
# date 2023-02-09
# pandoc 2.19.2 @ /jhpce/shared/jhpce/core/conda/miniconda3-4.11.0/envs/svnR-4.2.x/bin/pandoc
#
#
# ─ Packages ───────────────────────────────────────────────────────────────────────────────────────────────────
# package * version date (UTC) lib source
# AnnotationDbi 1.60.0 2022-11-01 [2] Bioconductor
Expand Down
25 changes: 12 additions & 13 deletions code/analysis/01_build_spe/my_functions/vis_gene_300.R
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
vis_gene_300 <-
function(
spe,
sampleid,
geneid = "SCGB2A2; ENSG00000110484",
spatial = TRUE,
assayname = "logcounts",
minCount = 0,
viridis = TRUE,
image_id = "lowres",
alpha = 1,
cont_colors = if (viridis) viridisLite::viridis(21) else c("aquamarine4", "springgreen", "goldenrod", "red"),
point_size = 1.25,
...) {
function(spe,
sampleid,
geneid = "SCGB2A2; ENSG00000110484",
spatial = TRUE,
assayname = "logcounts",
minCount = 0,
viridis = TRUE,
image_id = "lowres",
alpha = 1,
cont_colors = if (viridis) viridisLite::viridis(21) else c("aquamarine4", "springgreen", "goldenrod", "red"),
point_size = 1.25,
...) {
spe_sub <- spe[, spe$sample_id == sampleid]
d <- as.data.frame(cbind(colData(spe_sub), SpatialExperiment::spatialCoords(spe_sub)), optional = TRUE)

Expand Down
21 changes: 10 additions & 11 deletions code/analysis/01_build_spe/my_functions/vis_gene_p_300.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
vis_gene_p_300 <-
function(
spe,
d,
sampleid,
spatial,
title,
viridis = TRUE,
image_id = "lowres",
alpha = 1,
cont_colors = if (viridis) viridisLite::viridis(21) else c("aquamarine4", "springgreen", "goldenrod", "red"),
point_size = 1.25) {
function(spe,
d,
sampleid,
spatial,
title,
viridis = TRUE,
image_id = "lowres",
alpha = 1,
cont_colors = if (viridis) viridisLite::viridis(21) else c("aquamarine4", "springgreen", "goldenrod", "red"),
point_size = 1.25) {
## Some variables
pxl_row_in_fullres <- pxl_col_in_fullres <- key <- COUNT <- NULL
# stopifnot(all(c("pxl_col_in_fullres", "pxl_row_in_fullres", "COUNT", "key") %in% colnames(d)))
Expand Down
33 changes: 16 additions & 17 deletions code/analysis/01_build_spe/my_functions/vis_grid_gene_300.R
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
vis_grid_gene_300 <-
function(
spe,
geneid = "SCGB2A2; ENSG00000110484",
pdf_file,
assayname = "logcounts",
minCount = 0,
return_plots = FALSE,
spatial = TRUE,
viridis = TRUE,
height = 24,
width = 36,
image_id = "lowres",
alpha = 1,
cont_colors = if (viridis) viridisLite::viridis(21) else c("aquamarine4", "springgreen", "goldenrod", "red"),
sample_order = unique(spe$sample_id),
point_size = 1.25,
...) {
function(spe,
geneid = "SCGB2A2; ENSG00000110484",
pdf_file,
assayname = "logcounts",
minCount = 0,
return_plots = FALSE,
spatial = TRUE,
viridis = TRUE,
height = 24,
width = 36,
image_id = "lowres",
alpha = 1,
cont_colors = if (viridis) viridisLite::viridis(21) else c("aquamarine4", "springgreen", "goldenrod", "red"),
sample_order = unique(spe$sample_id),
point_size = 1.25,
...) {
stopifnot(all(sample_order %in% unique(spe$sample_id)))

plots <- lapply(sample_order, function(sampleid) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
#' cat = "Mutation_Status",
#' fill_colors = c(negative = "green", positive = "pink")
#' )
custom_plotExpression <- function(sce,
genes,
assay = "logcounts",
cat,
highlight_sample = "None",
line = FALSE,
fill_colors = NULL,
title = NULL) {
custom_plotExpression <- function(
sce,
genes,
assay = "logcounts",
cat,
highlight_sample = "None",
line = FALSE,
fill_colors = NULL,
title = NULL) {
cat_df <- as.data.frame(colData(sce))[, c("sample_id", cat), drop = FALSE]

expression_long <- reshape2::melt(as.matrix(assays(sce)[[assay]][genes, , drop = FALSE]))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,19 @@ cor_stats_layer <- layer_stat_cor(
)

layer_matrix_plot_AS <-
function(
matrix_values,
matrix_labels = NULL,
xlabs = NULL,
layerHeights = NULL,
mypal = c(
"white",
grDevices::colorRampPalette(RColorBrewer::brewer.pal(9, "YlOrRd"))(50)
),
breaks = NULL,
axis.args = NULL,
srt = 0,
mar = c(8, 4 + (max(nchar(rownames(matrix_values))) %/% 3) * 0.5, 4, 2) + 0.1,
cex = 1.2) {
function(matrix_values,
matrix_labels = NULL,
xlabs = NULL,
layerHeights = NULL,
mypal = c(
"white",
grDevices::colorRampPalette(RColorBrewer::brewer.pal(9, "YlOrRd"))(50)
),
breaks = NULL,
axis.args = NULL,
srt = 0,
mar = c(8, 4 + (max(nchar(rownames(matrix_values))) %/% 3) * 0.5, 4, 2) + 0.1,
cex = 1.2) {
## Create some default values in case the user didn't specify them
if (is.null(xlabs)) {
if (is.null(colnames(matrix_values))) {
Expand Down Expand Up @@ -111,12 +110,11 @@ layer_matrix_plot_AS <-
}

layer_stat_cor_plot_AS <-
function(
cor_stats_layer,
max = 0.81,
min = -max,
layerHeights = NULL,
cex = 1.2) {
function(cor_stats_layer,
max = 0.81,
min = -max,
layerHeights = NULL,
cex = 1.2) {
## From https://github.com/LieberInstitute/HumanPilot/blob/master/Analysis/Layer_Guesses/dlpfc_snRNAseq_annotation.R
theSeq <- seq(min, max, by = 0.01)
my.col <- grDevices::colorRampPalette(RColorBrewer::brewer.pal(7, "PRGn"))(length(theSeq))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,19 @@
#' cex = 2
#' )
layer_matrix_plot_AS <-
function(
matrix_values,
matrix_labels = NULL,
xlabs = NULL,
layerHeights = NULL,
mypal = c(
"white",
grDevices::colorRampPalette(RColorBrewer::brewer.pal(9, "YlOrRd"))(50)
),
breaks = NULL,
axis.args = NULL,
srt = 45,
mar = c(8, 4 + (max(nchar(rownames(matrix_values))) %/% 3) * 0.5, 4, 2) + 0.1,
cex = 1.2) {
function(matrix_values,
matrix_labels = NULL,
xlabs = NULL,
layerHeights = NULL,
mypal = c(
"white",
grDevices::colorRampPalette(RColorBrewer::brewer.pal(9, "YlOrRd"))(50)
),
breaks = NULL,
axis.args = NULL,
srt = 45,
mar = c(8, 4 + (max(nchar(rownames(matrix_values))) %/% 3) * 0.5, 4, 2) + 0.1,
cex = 1.2) {
## Create some default values in case the user didn't specify them
if (is.null(xlabs)) {
if (is.null(colnames(matrix_values))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,11 @@
#' top_n = 10
#' ), max = 0.3)
layer_stat_cor_plot_AS <-
function(
cor_stats_layer,
max = 0.81,
min = -max,
layerHeights = NULL,
cex = 1.2) {
function(cor_stats_layer,
max = 0.81,
min = -max,
layerHeights = NULL,
cex = 1.2) {
## From https://github.com/LieberInstitute/HumanPilot/blob/master/Analysis/Layer_Guesses/dlpfc_snRNAseq_annotation.R
theSeq <- seq(min, max, by = 0.01)
my.col <- grDevices::colorRampPalette(RColorBrewer::brewer.pal(7, "PRGn"))(length(theSeq))
Expand Down
25 changes: 16 additions & 9 deletions code/analysis/09_position_differential_expression/02_summarize.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ library("ggplot2")
library("Polychrome")

## Plot directory
dir_plots <- here::here("plots",
"09_position_differential_expression")
dir_plots <- here::here(
"plots",
"09_position_differential_expression"
)
dir.create(dir_plots, showWarnings = FALSE, recursive = TRUE)
stopifnot(file.exists(dir_plots))

Expand All @@ -24,17 +26,20 @@ sce_pseudo <-
)

## Define variables to use
vars <- c("age",
vars <- c(
"age",
"sample_id",
"BayesSpace",
"subject",
"sex",
"position")
"position"
)

## Obtain percent of variance explained at the gene level
## using scater::getVarianceExplained()
vars <- getVarianceExplained(sce_pseudo,
variables = vars)
variables = vars
)

## Now visualize the percent of variance explained across all genes
pdf(
Expand All @@ -49,13 +54,15 @@ dev.off()

## Load Sp09 DE results
load(here("code", "deploy_app_k09", "sig_genes_subset_k09.Rdata"),
verbose = TRUE)
verbose = TRUE
)
sig_domain <- sig_genes
rm(sig_genes)

## Load Sp16 DE results
load(here("code", "deploy_app_k16", "sig_genes_subset_k16.Rdata"),
verbose = TRUE)
verbose = TRUE
)
sig_domain_16 <- sig_genes
rm(sig_genes)

Expand Down Expand Up @@ -92,7 +99,7 @@ pdf(
## Plot densities of t-statistics
ggplot(enriched, aes(x = stat, fill = test)) +
geom_density() +
facet_grid( ~ Analysis + test, margins = "test") +
facet_grid(~ Analysis + test, margins = "test") +
xlab("Enrichment t-statistic") +
scale_color_manual(values = colors, name = "Test") +
scale_fill_manual(values = colors, name = "Test") +
Expand All @@ -103,7 +110,7 @@ ggplot(enriched, aes(x = stat, fill = test)) +
## Plot histogram of t-statistics with FDR < 5%
ggplot(subset(enriched, fdr < 0.05), aes(x = stat, fill = test)) +
geom_histogram() +
facet_grid( ~ Analysis + test, margins = "test") +
facet_grid(~ Analysis + test, margins = "test") +
xlab("Enrichment t-statistic (FDR <5%)") +
scale_color_manual(values = colors, name = "Test") +
scale_fill_manual(values = colors, name = "Test") +
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
library("here")
library("sessioninfo")

dir_rdata <- here::here("processed-data", "rdata", "spe",
"09_position_differential_expression")
dir_rdata <- here::here(
"processed-data", "rdata", "spe",
"09_position_differential_expression"
)
stopifnot(file.exists(dir_rdata))

## Load Sp09 DE results
load(here("code", "deploy_app_k09", "sig_genes_subset_k09.Rdata"),
verbose = TRUE)
verbose = TRUE
)
sig_domain_09 <- sig_genes
rm(sig_genes)

## Load Sp16 DE results
load(here("code", "deploy_app_k16", "sig_genes_subset_k16.Rdata"),
verbose = TRUE)
verbose = TRUE
)
sig_domain_16 <- sig_genes
rm(sig_genes)

Expand Down
Loading

0 comments on commit 702ca0c

Please sign in to comment.