Skip to content

Commit

Permalink
edited README around new functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Totty authored and Michael Totty committed Mar 13, 2024
1 parent 72865d2 commit aed0698
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 72 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ Imports:
stats,
BiocParallel,
MASS,
dbscan
dbscan,
escheR
Suggests:
escheR,
knitr,
scuttle,
STexampleData,
Expand Down
6 changes: 3 additions & 3 deletions R/plotOutliers.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@

plotOutliers <- function(spe, sample_id = "sample_id",
sample=unique(spe$sample_id)[1], metric="detected",
outliers="local_outliers",
outliers="local_outliers", point_size=1,
colors=c("white","black"), stroke=1) {


spe.subset <- spe[ ,colData(spe)[[sample_id]] == sample]

p <- make_escheR(spe.subset) |>
add_fill(var = metric) |>
add_fill(var = metric, point_size = point_size) |>
add_ground(var = outliers, stroke = stroke) +
ggtitle(paste0("Sample: ", sample))

Expand All @@ -60,5 +60,5 @@ plotOutliers <- function(spe, sample_id = "sample_id",
scale_y_reverse()
}

print(p)
return(p)
}
70 changes: 45 additions & 25 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,28 @@ spe<- scuttle::addPerCellQCMetrics(spe, subsets=list(Mito=is.mito))
colnames(colData(spe))
# Identifying local outliers using SpotSweeper
features <- c('sum' ,'detected', "subsets_Mito_percent")
spe<- localOutliers(spe,
features=features,
n_neighbors=18,
data_output=TRUE,
method="multivariate"
)
spe <- localOutliers(spe,
metric="sum",
direction="lower",
log=TRUE
)
# show column data after SpotSweeper
colnames(colData(spe))
spe <- localOutliers(spe,
metric="detected",
direction="lower",
log=TRUE
)
spe <- localOutliers(spe,
metric="subsets_Mito_percent",
direction="higher",
log=FALSE
)
# combine all outliers into "local_outliers" column
spe$local_outliers <- as.logical(spe$sum_outliers) |
as.logical(spe$detected_outliers) |
as.logical(spe$subsets_Mito_percent_outliers)
```

Expand All @@ -104,28 +116,36 @@ We can now visualize `local_outliers` vs one of the QC metrics, `sum_log2`, with
library(escheR)
library(ggpubr)
# plotting using escheR
p1 <- make_escheR(spe) |>
add_fill(var = "sum_log2", point_size=1.25) +
scale_fill_gradient(low ="white",high = "darkgreen")
# library size
p1 <- plotOutliers(spe, metric="sum_log2",
outliers="sum_outliers", point_size=1.1) +
ggtitle("Library Size")
p2 <- make_escheR(spe) |>
add_fill(var = "sum_log2", point_size=1.25) |>
add_ground(var = "local_outliers", stroke = 1) +
scale_color_manual(
name = "", # turn off legend name for ground_truth
values = c(
"TRUE" = "red",
"FALSE" = "transparent")
) +
scale_fill_gradient(low ="white",high = "darkgreen")
# unique genes
p2 <- plotOutliers(spe, metric="detected_log2",
outliers="detected_outliers", point_size=1.1) +
ggtitle("Unique Genes")
# mitochondrial percent
p3 <- plotOutliers(spe, metric="subsets_Mito_percent",
outliers="subsets_Mito_percent_outliers", point_size=1.1) +
ggtitle("Mitochondrial Percent")
plot_list <- list(p1, p2)
# all local outliers
p4 <- plotOutliers(spe, metric="sum_log2",
outliers="local_outliers", point_size=1.1, stroke=0.75) +
ggtitle("All Local Outliers")
# plot
plot_list <- list(p1, p2, p3, p4)
ggarrange(
plotlist = plot_list,
ncol = 2, nrow = 1,
ncol = 2, nrow = 2,
common.legend = FALSE
)
```

## Artifact detection
Expand Down
84 changes: 42 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ library(SpotSweeper)

# load Maynard et al DLPFC daatset
spe <- STexampleData::Visium_humanDLPFC()
#> Warning: package 'S4Vectors' was built under R version 4.3.2
#> Warning: package 'GenomeInfoDb' was built under R version 4.3.2
#> see ?STexampleData and browseVignettes('STexampleData') for documentation
#> loading from cache

Expand Down Expand Up @@ -99,27 +97,28 @@ colnames(colData(spe))
#> [13] "total"

# Identifying local outliers using SpotSweeper
features <- c('sum' ,'detected', "subsets_Mito_percent")
spe<- localOutliers(spe,
features=features,
n_neighbors=18,
data_output=TRUE,
method="multivariate"
)
spe <- localOutliers(spe,
metric="sum",
direction="lower",
log=TRUE
)

# show column data after SpotSweeper
colnames(colData(spe))
#> [1] "barcode_id" "sample_id"
#> [3] "in_tissue" "array_row"
#> [5] "array_col" "ground_truth"
#> [7] "cell_count" "sum"
#> [9] "detected" "subsets_Mito_sum"
#> [11] "subsets_Mito_detected" "subsets_Mito_percent"
#> [13] "total" "sum_log2"
#> [15] "detected_log2" "subsets_Mito_percent_log2"
#> [17] "coords" "local_outliers"
#> [19] "sum_z" "detected_z"
#> [21] "subsets_Mito_percent_z" "LOF"
spe <- localOutliers(spe,
metric="detected",
direction="lower",
log=TRUE
)

spe <- localOutliers(spe,
metric="subsets_Mito_percent",
direction="higher",
log=FALSE
)

# combine all outliers into "local_outliers" column
spe$local_outliers <- as.logical(spe$sum_outliers) |
as.logical(spe$detected_outliers) |
as.logical(spe$subsets_Mito_percent_outliers)
```

We can now visualize `local_outliers` vs one of the QC metrics,
Expand All @@ -130,30 +129,31 @@ library(escheR)
#> Loading required package: ggplot2
library(ggpubr)

# plotting using escheR
p1 <- make_escheR(spe) |>
add_fill(var = "sum_log2", point_size=1.25) +
scale_fill_gradient(low ="white",high = "darkgreen")
#> Scale for fill is already present.
#> Adding another scale for fill, which will replace the existing scale.
# library size
p1 <- plotOutliers(spe, metric="sum_log2",
outliers="sum_outliers", point_size=1.1) +
ggtitle("Library Size")

p2 <- make_escheR(spe) |>
add_fill(var = "sum_log2", point_size=1.25) |>
add_ground(var = "local_outliers", stroke = 1) +
scale_color_manual(
name = "", # turn off legend name for ground_truth
values = c(
"TRUE" = "red",
"FALSE" = "transparent")
) +
scale_fill_gradient(low ="white",high = "darkgreen")
#> Scale for fill is already present.
#> Adding another scale for fill, which will replace the existing scale.
# unique genes
p2 <- plotOutliers(spe, metric="detected_log2",
outliers="detected_outliers", point_size=1.1) +
ggtitle("Unique Genes")

# mitochondrial percent
p3 <- plotOutliers(spe, metric="subsets_Mito_percent",
outliers="subsets_Mito_percent_outliers", point_size=1.1) +
ggtitle("Mitochondrial Percent")

# all local outliers
p4 <- plotOutliers(spe, metric="sum_log2",
outliers="local_outliers", point_size=1.1, stroke=0.75) +
ggtitle("All Local Outliers")

plot_list <- list(p1, p2)
# plot
plot_list <- list(p1, p2, p3, p4)
ggarrange(
plotlist = plot_list,
ncol = 2, nrow = 1,
ncol = 2, nrow = 2,
common.legend = FALSE
)
```
Expand Down
Binary file modified man/figures/README-artifact_visualization-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-local_outlier_plot-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added man/figures/README-local_outlier_plot-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added man/figures/README-local_outlier_plot-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added man/figures/README-local_outlier_plot-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added man/figures/README-local_outlier_plot-5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit aed0698

Please sign in to comment.