The Barcode, UMI, Set (BUS) format is a new way to represent pseudoalignments of reads from RNA-seq. Files of this format can be efficiently generated by the command line tool kallisto bus
. With kallisto bus
and this package, we go from the fastq files to the sparse matrix used for downstream analysis such as with Seurat within half an hour, while Cell Ranger would take hours.
In this vignette, we convert an 10x 1:1 mouse and human cell mixture dataset from the BUS format to a sparse matrix. To see how the BUS format can be generated from fastq file, as well as more in depth vignettes, see the website of this package.
# The dataset package
library(TENxBUSData)
library(BUSpaRse)
library(Matrix)
library(zeallot)
library(ggplot2)
TENxBUSData(".", dataset = "hgmm100")
#> snapshotDate(): 2020-04-27
#> see ?TENxBUSData and browseVignettes('TENxBUSData') for documentation
#> loading from cache
#> The downloaded files are in /tmp/RtmpCgGaPg/Rbuild3a875d4e443f/BUSpaRse/vignettes/out_hgmm100
#> [1] "/tmp/RtmpCgGaPg/Rbuild3a875d4e443f/BUSpaRse/vignettes/out_hgmm100"
First, we map transcripts, as in the kallisto
index, to the corresponding genes.
tr2g <- transcript2gene(species = c("Homo sapiens", "Mus musculus"), type = "vertebrate",
kallisto_out_path = "./out_hgmm100", ensembl_version = 99,
write_tr2g = FALSE)
#> Querying biomart for transcript and gene IDs of Homo sapiens
#> Querying biomart for transcript and gene IDs of Mus musculus
head(tr2g)
#> transcript gene gene_name chromosome_name
#> 1 ENST00000434970.2 ENSG00000237235.2 TRDD2 14
#> 2 ENST00000415118.1 ENSG00000223997.1 TRDD1 14
#> 3 ENST00000448914.1 ENSG00000228985.1 TRDD3 14
#> 4 ENST00000632684.1 ENSG00000282431.1 TRBD1 7
#> 5 ENST00000390583.1 ENSG00000211923.1 IGHD3-10 14
#> 6 ENST00000431440.2 ENSG00000232543.2 IGHD4-11 14
Here we make both the gene count matrix and the TCC matrix.
c(gene_count, tcc) %<-% make_sparse_matrix("./out_hgmm100/output.sorted.txt",
tr2g = tr2g, est_ncells = 1e5,
est_ngenes = nrow(tr2g))
#> Reading matrix.ec
#> Processing ECs
#> Matching genes to ECs
#> Reading data
#> Constructing gene count matrix
#> Constructing TCC matrix
Here we have a sparse matrix with genes in rows and cells in columns.
dim(gene_count)
#> [1] 26937 151449
This dataset should only have about 100 cells, but here we get over 100,000. In fact, most of the barcodes correspond to empty droplets; they can be removed by filtering out barcodes with too few UMI.
tot_counts <- Matrix::colSums(gene_count)
summary(tot_counts)
#> Min. 1st Qu. Median Mean 3rd Qu. Max.
#> 1.00 1.00 2.00 24.77 5.00 64041.00
df1 <- get_knee_df(gene_count)
infl1 <- get_inflection(df1)
knee_plot(df1, infl1)
gene_count <- gene_count[, tot_counts > infl1]
dim(gene_count)
#> [1] 26937 122
Then this sparse matrix can be used in Seurat for downstream analysis.
Likewise, we can remove empty droplets from the TCC matrix.
dim(tcc)
#> [1] 129371 157659
This dataset should only have about 100 cells, but here we get over 100,000. In fact, most of the barcodes correspond to empty droplets; they can be removed by filtering out barcodes with too few UMI.
tot_counts <- Matrix::colSums(tcc)
summary(tot_counts)
#> Min. 1st Qu. Median Mean 3rd Qu. Max.
#> 1.00 1.00 2.00 25.84 5.00 69235.00
df2 <- get_knee_df(tcc)
infl2 <- get_inflection(df2)
knee_plot(df2, infl2)
tcc <- tcc[, tot_counts > infl2]
dim(tcc)
#> [1] 129371 121
sessionInfo()
#> R version 4.0.0 (2020-04-24)
#> Platform: x86_64-pc-linux-gnu (64-bit)
#> Running under: Ubuntu 18.04.4 LTS
#>
#> Matrix products: default
#> BLAS: /home/biocbuild/bbs-3.11-bioc/R/lib/libRblas.so
#> LAPACK: /home/biocbuild/bbs-3.11-bioc/R/lib/libRlapack.so
#>
#> locale:
#> [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
#> [3] LC_TIME=en_US.UTF-8 LC_COLLATE=C
#> [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
#> [7] LC_PAPER=en_US.UTF-8 LC_NAME=C
#> [9] LC_ADDRESS=C LC_TELEPHONE=C
#> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
#>
#> attached base packages:
#> [1] stats graphics grDevices utils datasets methods base
#>
#> other attached packages:
#> [1] ggplot2_3.3.1 zeallot_0.1.0 Matrix_1.2-18 BUSpaRse_1.2.2
#> [5] TENxBUSData_1.2.1 BiocStyle_2.16.0
#>
#> loaded via a namespace (and not attached):
#> [1] ProtGenerics_1.20.0 bitops_1.0-6
#> [3] matrixStats_0.56.0 bit64_0.9-7
#> [5] progress_1.2.2 httr_1.4.1
#> [7] GenomeInfoDb_1.24.0 tools_4.0.0
#> [9] R6_2.4.1 DBI_1.1.0
#> [11] lazyeval_0.2.2 BiocGenerics_0.34.0
#> [13] colorspace_1.4-1 withr_2.2.0
#> [15] tidyselect_1.1.0 prettyunits_1.1.1
#> [17] bit_1.1-15.2 curl_4.3
#> [19] compiler_4.0.0 Biobase_2.48.0
#> [21] DelayedArray_0.14.0 rtracklayer_1.48.0
#> [23] bookdown_0.19 scales_1.1.1
#> [25] askpass_1.1 rappdirs_0.3.1
#> [27] stringr_1.4.0 digest_0.6.25
#> [29] Rsamtools_2.4.0 rmarkdown_2.2
#> [31] XVector_0.28.0 pkgconfig_2.0.3
#> [33] htmltools_0.4.0 dbplyr_1.4.4
#> [35] fastmap_1.0.1 ensembldb_2.12.1
#> [37] BSgenome_1.56.0 rlang_0.4.6
#> [39] RSQLite_2.2.0 shiny_1.4.0.2
#> [41] generics_0.0.2 farver_2.0.3
#> [43] BiocParallel_1.22.0 dplyr_1.0.0
#> [45] RCurl_1.98-1.2 magrittr_1.5
#> [47] GenomeInfoDbData_1.2.3 Rcpp_1.0.4.6
#> [49] munsell_0.5.0 S4Vectors_0.26.1
#> [51] lifecycle_0.2.0 stringi_1.4.6
#> [53] yaml_2.2.1 SummarizedExperiment_1.18.1
#> [55] zlibbioc_1.34.0 BiocFileCache_1.12.0
#> [57] AnnotationHub_2.20.0 grid_4.0.0
#> [59] blob_1.2.1 parallel_4.0.0
#> [61] promises_1.1.0 ExperimentHub_1.14.0
#> [63] crayon_1.3.4 lattice_0.20-41
#> [65] Biostrings_2.56.0 GenomicFeatures_1.40.0
#> [67] hms_0.5.3 magick_2.3
#> [69] knitr_1.28 pillar_1.4.4
#> [71] GenomicRanges_1.40.0 biomaRt_2.44.0
#> [73] stats4_4.0.0 XML_3.99-0.3
#> [75] glue_1.4.1 BiocVersion_3.11.1
#> [77] evaluate_0.14 BiocManager_1.30.10
#> [79] vctrs_0.3.0 httpuv_1.5.3.1
#> [81] gtable_0.3.0 openssl_1.4.1
#> [83] purrr_0.3.4 tidyr_1.1.0
#> [85] assertthat_0.2.1 xfun_0.14
#> [87] mime_0.9 xtable_1.8-4
#> [89] AnnotationFilter_1.12.0 later_1.0.0
#> [91] tibble_3.0.1 GenomicAlignments_1.24.0
#> [93] AnnotationDbi_1.50.0 plyranges_1.8.0
#> [95] memoise_1.1.0 IRanges_2.22.2
#> [97] ellipsis_0.3.1 interactiveDisplayBase_1.26.3