Last updated: 2023-10-20
Checks: 6 1
Knit directory: NextClone-analysis/
This reproducible R Markdown analysis was created with workflowr (version 1.7.0). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.
The R Markdown is untracked by Git. To know which version of the R
Markdown file created these results, you’ll want to first commit it to
the Git repo. If you’re still working on the analysis, you can ignore
this warning. When you’re finished, you can run
wflow_publish
to commit the R Markdown file and build the
HTML.
Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.
The command set.seed(20231011)
was run prior to running
the code in the R Markdown file. Setting a seed ensures that any results
that rely on randomness, e.g. subsampling or permutations, are
reproducible.
Great job! Recording the operating system, R version, and package versions is critical for reproducibility.
Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.
Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.
Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.
The results in this page were generated with repository version e8b74da. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.
Note that you need to be careful to ensure that all relevant files for
the analysis have been committed to Git prior to generating the results
(you can use wflow_publish
or
wflow_git_commit
). workflowr only checks the R Markdown
file, but you know if there are other scripts or data files that it
depends on. Below is the status of the Git repository when the results
were generated:
Ignored files:
Ignored: .Rhistory
Ignored: .Rproj.user/
Untracked files:
Untracked: .DS_Store
Untracked: analysis/NGS_data_analysis.Rmd
Untracked: analysis/sc_data_analysis.Rmd
Untracked: data/.DS_Store
Untracked: data/cellranger_out/
Untracked: data/nextclone_out/
Untracked: data/pycashier_out/
Unstaged changes:
Modified: analysis/index.Rmd
Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.
There are no past versions. Publish this analysis with
wflow_publish()
to start tracking its development.
Analysis for the 8k and 10k library of MCF7 cell line tagged with ClonMapper protocol.
Working directory for NextClone run:
/vast/projects/Goel_senescence/nextclone_dev/07_analysis/ngs_v1/run_nextclone/output_20231016
library(CloneDetective)
library(data.table)
library(ggplot2)
library(scales)
NextClone and pycashier pipeline:
clones_nxclone <- fread("data/nextclone_out/ngs_clone_barcode_counts.csv")
# The samples in the sample_name column is way too complicated.
# Let's create a new column.
clones_nxclone[, sample_name_simple := gsub("vexGFP-", "", gsub("_.*", "", sample_name))]
clones_nxclone[, sample_name_simple := factor(sample_name_simple, levels = c("8k", "10k"))]
clones_pycashier <- lapply(c("8k", "10k"), function(samp) {
# read_count as the count column so we can use count_retained_clones
dt <- fread(
file = paste0("data/pycashier_out/", samp, ".tsv"),
header = FALSE,
col.names = c("clone_barcode", "read_count")
)
dt[, sample := samp]
return(dt)
})
clones_pycashier <- rbindlist(clones_pycashier)
clones_pycashier[, sample := factor(sample, levels = c("8k", "10k"))]
Count the number of unique barcodes with at least x number of cells.
thresholds <- c(1, 20, 200, 1000)
n_barcodes_nxclone <- count_retained_clones(
count_data = clones_nxclone,
thresholds = thresholds,
grouping_col = "sample_name_simple",
count_column = "read_count"
)
n_barcodes_nxclone[, tool := 'NextClone']
setnames(n_barcodes_nxclone, "sample_name_simple", "sample")
n_barcodes_pycashier <- count_retained_clones(
count_data = clones_pycashier,
thresholds = thresholds,
grouping_col = "sample",
count_column = "read_count"
)
n_barcodes_pycashier[, tool := 'PyCashier']
n_barcodes <- rbind(n_barcodes_nxclone, n_barcodes_pycashier)
n_barcodes_long <- melt(n_barcodes, id.vars = c("sample", "tool"),
variable.name = "filtering_threshold",
value.name = "n_barcode")
filtering_threshold_levels <- paste(">=", thresholds, "cells")
n_barcodes_long[, filtering_threshold := factor(
gsub("_"," ",gsub("at_least_", ">= ", filtering_threshold)),
levels = filtering_threshold_levels
)]
ggplot(n_barcodes_long, aes(x=factor(filtering_threshold), y=n_barcode, fill=tool)) +
geom_bar(stat="identity", position=position_dodge()) +
theme_bw(base_size = 18) +
theme(
axis.text.x = element_text(angle = 45, vjust = 1, hjust=1),
legend.position="bottom"
) +
facet_wrap(~ sample) +
scale_y_continuous(breaks = pretty_breaks(n=10), label = label_comma(accuracy = 1)) +
labs(
y = "Number of barcodes",
x = "Filtering thresholds",
fill = "Pipeline",
title = "Number of barcodes retrieved for 8k and 10k NGS data"
)
To show the proportion of barcode’s frequency.
clones_nxclone_filtered <- remove_clones_below_threshold(
count_data = clones_nxclone,
threshold = 20,
count_column = "read_count"
)
clones_nxclone_filtered <- convert_count_to_proportion(
count_data = clones_nxclone_filtered,
grouping_col = "sample_name_simple",
count_column = "read_count"
)
plt <- draw_elbow_plot(
count_data = clones_nxclone_filtered,
facet_column = "sample_name_simple",
y_axis_column = "read_proportion"
)
plt <- plt +
geom_point(size=0.5, colour='red') +
labs(
title = "Proportion of reads assigned to each barcode",
subtitle = "Barcode IDs are numerically assigned in order of read proportion",
x = "Numerical barcode ID",
y = "Proportion of reads per library"
)
plt
Let’s say we want to sequence 10,000 cells. Based on our NGS data, can we predict what will happen to our clone barcodes? Will we get enough representations?
n_cells_sequenced <- 10000
Do projection by calculating proportion and multiply by amount of cells to be projected to.
clones_nxclone_proportion <- projecting_clones(
count_data = clones_nxclone,
grouping_col = "sample_name_simple",
count_column = "read_count",
project_amnt = 10000
)
How many cells we will get per clone?
plt <- draw_elbow_plot(
count_data = clones_nxclone_proportion,
y_axis_column = 'projected_to_10000',
facet_column = 'sample_name_simple'
) +
geom_point(size = 0.5, colour='blue') +
labs(
y = 'Number of cells',
title = 'Number of cells assigned to each barcode',
subtitle = 'Cell counts computed after projection to 10,000 cells'
)
plt
How many clones that contain at least 10, 20, 50, 100 cells?
thresholds <- c(10, 20, 50, 100)
proj_n_clones_retained <- count_retained_clones(
count_data = clones_nxclone_proportion,
thresholds = thresholds,
grouping_col = "sample_name_simple",
count_column = "projected_to_10000"
)
names(proj_n_clones_retained) <- c("sample", paste(">=", thresholds, "cells"))
proj_n_clones_retained
sample >= 10 cells >= 20 cells >= 50 cells >= 100 cells
1: 8k 6 1 1 0
2: 10k 6 2 1 0
What are the frequency of top 200 clone barcodes? We can present this by computing the number of cells tagged by top 200 clone barcodes.
top_threshold <- 200
top_barcodes <- get_top_barcodes(
count_data = clones_nxclone_proportion,
count_column = "projected_to_10000",
grouping_col = "sample_name_simple",
top_threshold = top_threshold
)
Create a line chart that show cumulative number of cells.
# TODO convert me to function
top_barcodes <- top_barcodes[order(sample_name_simple, -projected_to_10000)]
top_barcodes[, barcode_id := seq(1, top_threshold), by=sample_name_simple]
top_barcodes[, cum_sum_projected_to_10000 := cumsum(projected_to_10000), by=sample_name_simple]
ggplot(top_barcodes, aes(x=barcode_id, y=cum_sum_projected_to_10000,
group=sample_name_simple, colour = sample_name_simple)) +
geom_line(linewidth=1) +
theme_bw(base_size = 16) +
scale_y_continuous(breaks = pretty_breaks(n=10), labels = label_comma(accuracy = 1)) +
scale_x_continuous(breaks = pretty_breaks(n=10)) +
theme(
axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1),
legend.position = "bottom"
) +
labs(
y = "Number of cells",
x = "Barcode ID",
title = paste("Cumulative Number of cells for top", top_threshold, "clone barcodes"),
subtitle = "Number of cells computed after projection to 10,000 cells",
colour = "Library"
)
sessionInfo()
R version 4.2.3 (2023-03-15)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS 14.0
Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] scales_1.2.1 ggplot2_3.4.1 data.table_1.14.8
[4] CloneDetective_0.1.0 workflowr_1.7.0
loaded via a namespace (and not attached):
[1] Rcpp_1.0.10 highr_0.10 compiler_4.2.3 pillar_1.8.1
[5] bslib_0.4.2 later_1.3.0 git2r_0.31.0 jquerylib_0.1.4
[9] tools_4.2.3 getPass_0.2-2 digest_0.6.31 gtable_0.3.1
[13] jsonlite_1.8.4 evaluate_0.20 lifecycle_1.0.3 tibble_3.1.8
[17] pkgconfig_2.0.3 rlang_1.0.6 cli_3.6.1 rstudioapi_0.14
[21] yaml_2.3.7 xfun_0.39 fastmap_1.1.0 withr_2.5.0
[25] dplyr_1.1.0 httr_1.4.4 stringr_1.5.0 knitr_1.42
[29] generics_0.1.3 fs_1.6.1 vctrs_0.5.2 sass_0.4.5
[33] tidyselect_1.2.0 grid_4.2.3 rprojroot_2.0.3 glue_1.6.2
[37] R6_2.5.1 processx_3.8.0 fansi_1.0.4 rmarkdown_2.20
[41] farver_2.1.1 callr_3.7.3 magrittr_2.0.3 whisker_0.4.1
[45] ps_1.7.2 promises_1.2.0.1 htmltools_0.5.4 colorspace_2.1-0
[49] httpuv_1.6.9 utf8_1.2.3 stringi_1.7.12 munsell_0.5.0
[53] cachem_1.0.6