Analysing Long Read RNA-Seq data with bambu

Ying Chen, Andre Sim, Yuk Kei Wan, Jonathan Göke

Introduction

Bambu is a method for transcript discovery and quantification from long read RNA-Seq data. Bambu uses aligned reads and genome reference annotations as input, and will return abundance estimates for all known transcripts and for newly discovered transcripts. Bambu uses the information from the reference annotations to correct misalignment at splice junctions, then reduces the aligned reads to read equivalent classes, and uses this information to identify novel transcripts across all samples of interest. Reads are then assigned to transcripts, and expression estimates are obtained using an expectation maximisation algorithm. Here, we present an example workflow for analysing Nanopore long read RNA-Sequencing data from two human cancer cell lines from the Singapore Nanopore Expression Project (SG-NEx).

Quick start: Transcript discovery and quantification with bambu

Installation

You can install bambu from github:

General Usage

The default mode to run bambu is using a set of aligned reads (bam files), reference genome annotations (gtf file, TxDb object, or bambuAnnotation object), and reference genome sequence (fasta file or BSgenome). bambu will return a summarizedExperiment object with the genomic coordinates for annotated and new transcripts and transcript expression estimates. We highly recommend to use the same annotations that were used for genome alignment. If you have a gtf file and fasta file you can run bambu with the following options:

library(bambu)
test.bam <- system.file("extdata", "SGNex_A549_directRNA_replicate5_run1_chr9_1_1000000.bam",
    package = "bambu")
fa.file <- system.file("extdata", "Homo_sapiens.GRCh38.dna_sm.primary_assembly_chr9_1_1000000.fa",
    package = "bambu")
gtf.file <- system.file("extdata", "Homo_sapiens.GRCh38.91_chr9_1_1000000.gtf", package = "bambu")
bambuAnnotations <- prepareAnnotations(gtf.file)
se <- bambu(reads = test.bam, annotations = bambuAnnotations, genome = fa.file)
##> 
  |                                                                            
  |                                                                      |   0%[15:53:14] WARNING: amalgamation/../src/learner.cc:1040: 
##>   If you are loading a serialized model (like pickle in Python, RDS in R) generated by
##>   older XGBoost, please export the model by calling `Booster.save_model` from that version
##>   first, then load it back in current version. See:
##> 
##>     https://xgboost.readthedocs.io/en/latest/tutorials/saving_model.html
##> 
##>   for more details about differences between saving model and serializing.
##> 
##> [15:53:14] WARNING: amalgamation/../src/learner.cc:749: Found JSON model saved before XGBoost 1.6, please save the model using current version again. The support for old JSON model will be discontinued in XGBoost 2.3.
##> [15:53:14] WARNING: amalgamation/../src/learner.cc:438: 
##>   If you are loading a serialized model (like pickle in Python, RDS in R) generated by
##>   older XGBoost, please export the model by calling `Booster.save_model` from that version
##>   first, then load it back in current version. See:
##> 
##>     https://xgboost.readthedocs.io/en/latest/tutorials/saving_model.html
##> 
##>   for more details about differences between saving model and serializing.
##> 
##> [15:53:14] WARNING: amalgamation/../src/learner.cc:1040: 
##>   If you are loading a serialized model (like pickle in Python, RDS in R) generated by
##>   older XGBoost, please export the model by calling `Booster.save_model` from that version
##>   first, then load it back in current version. See:
##> 
##>     https://xgboost.readthedocs.io/en/latest/tutorials/saving_model.html
##> 
##>   for more details about differences between saving model and serializing.
##> 
##> [15:53:14] WARNING: amalgamation/../src/learner.cc:749: Found JSON model saved before XGBoost 1.6, please save the model using current version again. The support for old JSON model will be discontinued in XGBoost 2.3.
##> [15:53:14] WARNING: amalgamation/../src/learner.cc:438: 
##>   If you are loading a serialized model (like pickle in Python, RDS in R) generated by
##>   older XGBoost, please export the model by calling `Booster.save_model` from that version
##>   first, then load it back in current version. See:
##> 
##>     https://xgboost.readthedocs.io/en/latest/tutorials/saving_model.html
##> 
##>   for more details about differences between saving model and serializing.
##> 
##> [15:53:14] WARNING: amalgamation/../src/learner.cc:1040: 
##>   If you are loading a serialized model (like pickle in Python, RDS in R) generated by
##>   older XGBoost, please export the model by calling `Booster.save_model` from that version
##>   first, then load it back in current version. See:
##> 
##>     https://xgboost.readthedocs.io/en/latest/tutorials/saving_model.html
##> 
##>   for more details about differences between saving model and serializing.
##> 
##> [15:53:14] WARNING: amalgamation/../src/learner.cc:749: Found JSON model saved before XGBoost 1.6, please save the model using current version again. The support for old JSON model will be discontinued in XGBoost 2.3.
##> [15:53:14] WARNING: amalgamation/../src/learner.cc:438: 
##>   If you are loading a serialized model (like pickle in Python, RDS in R) generated by
##>   older XGBoost, please export the model by calling `Booster.save_model` from that version
##>   first, then load it back in current version. See:
##> 
##>     https://xgboost.readthedocs.io/en/latest/tutorials/saving_model.html
##> 
##>   for more details about differences between saving model and serializing.
##> 
##> [15:53:14] WARNING: amalgamation/../src/learner.cc:1040: 
##>   If you are loading a serialized model (like pickle in Python, RDS in R) generated by
##>   older XGBoost, please export the model by calling `Booster.save_model` from that version
##>   first, then load it back in current version. See:
##> 
##>     https://xgboost.readthedocs.io/en/latest/tutorials/saving_model.html
##> 
##>   for more details about differences between saving model and serializing.
##> 
##> [15:53:14] WARNING: amalgamation/../src/learner.cc:749: Found JSON model saved before XGBoost 1.6, please save the model using current version again. The support for old JSON model will be discontinued in XGBoost 2.3.
##> [15:53:14] WARNING: amalgamation/../src/learner.cc:438: 
##>   If you are loading a serialized model (like pickle in Python, RDS in R) generated by
##>   older XGBoost, please export the model by calling `Booster.save_model` from that version
##>   first, then load it back in current version. See:
##> 
##>     https://xgboost.readthedocs.io/en/latest/tutorials/saving_model.html
##> 
##>   for more details about differences between saving model and serializing.
##> 
##> [15:53:17] WARNING: amalgamation/../src/learner.cc:1040: 
##>   If you are loading a serialized model (like pickle in Python, RDS in R) generated by
##>   older XGBoost, please export the model by calling `Booster.save_model` from that version
##>   first, then load it back in current version. See:
##> 
##>     https://xgboost.readthedocs.io/en/latest/tutorials/saving_model.html
##> 
##>   for more details about differences between saving model and serializing.
##> 
##> [15:53:17] WARNING: amalgamation/../src/learner.cc:749: Found JSON model saved before XGBoost 1.6, please save the model using current version again. The support for old JSON model will be discontinued in XGBoost 2.3.
##> [15:53:17] WARNING: amalgamation/../src/learner.cc:438: 
##>   If you are loading a serialized model (like pickle in Python, RDS in R) generated by
##>   older XGBoost, please export the model by calling `Booster.save_model` from that version
##>   first, then load it back in current version. See:
##> 
##>     https://xgboost.readthedocs.io/en/latest/tutorials/saving_model.html
##> 
##>   for more details about differences between saving model and serializing.
##> 
##> [15:53:17] WARNING: amalgamation/../src/learner.cc:1040: 
##>   If you are loading a serialized model (like pickle in Python, RDS in R) generated by
##>   older XGBoost, please export the model by calling `Booster.save_model` from that version
##>   first, then load it back in current version. See:
##> 
##>     https://xgboost.readthedocs.io/en/latest/tutorials/saving_model.html
##> 
##>   for more details about differences between saving model and serializing.
##> 
##> [15:53:17] WARNING: amalgamation/../src/learner.cc:749: Found JSON model saved before XGBoost 1.6, please save the model using current version again. The support for old JSON model will be discontinued in XGBoost 2.3.
##> [15:53:17] WARNING: amalgamation/../src/learner.cc:438: 
##>   If you are loading a serialized model (like pickle in Python, RDS in R) generated by
##>   older XGBoost, please export the model by calling `Booster.save_model` from that version
##>   first, then load it back in current version. See:
##> 
##>     https://xgboost.readthedocs.io/en/latest/tutorials/saving_model.html
##> 
##>   for more details about differences between saving model and serializing.
##> 
##> 
  |                                                                            
  |======================================================================| 100%
##> 
##> 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |======================================================================| 100%
##> 
##> 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |======================================================================| 100%
##> 
##> 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |======================================================================| 100%
##> 
##> 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |======================================================================| 100%
##> 
##> 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |======================================================================| 100%

bambu returns a SummarizedExperiment object which can be accessed as follows:

A complete workflow to identify and quantify transcript expression from

Nanopore RNA-Seq data {#complete-workflow} To demonstrate the usage of Bambu, we used long-read RNA-Seq data generated using Oxford Nanopore Sequencing from the NanoporeRNASeq package, which consists of 6 samples from two human cell lines (K562 and MCF7) that were generated by the SG-NEx project. Each of these cell lines has three replicates, with 1 direct RNA sequencing run and 2 cDNA sequencing runs. Reads are aligned to chromosome 22 (Grch38) and stored as bam files. In this workflow, we will demonstrate how to apply bambu to these bam files to identify novel transcripts and estimates transcript expression, visualize the results, and identify differentially expressed genes and transcripts.

Input data

Genome sequence (fasta file/ BSGenome object)

bambu additionally requires a genome sequence, which is used to correct splicing junctions in read alignments. Ideally, we recommend to use the same genome seqeunce file that was used for alignment to be used for bambu.

As an option, users can also choose to use a BSgenome object:

Genome annotations (bambu annotations object/ gtf file / TxDb object)

{#annotations}
bambu also requires a reference transcript annotations object, which is used to correct read alignments, to identify for transcripts and genes (and the type for novel transcripts), and for quantification. The annotation object can be created from a gtf file:

The annotation object can also be created from a TxDb object:

The annotation object can be stored and used again for re-running bambu. Here we will used the annotation object from the NanoporeRNASeq package that wasis prepared from a gtf file using the function in by function in bambu.

Transcript discovery and quantification

Running bambu

Next we apply bambu on the input data (bam files, annotations, genomeSequence). Bambu will perform isoform discovery to extend the provided annotation, and then quantify the transcript expression from these extended annotation using an Expectation-Maximisation algorithm. Here we will use 1 core, which can be changed to process multiple files in parallel.

For the downstream analysis, we will add the condition of interest to the object that describes the samples. Here we are interested in a comparison of the 2 cell lines:

Optionally, users can choose to apply bambu to do quantification only (without isoform discovery)

Visualise results

bambu provides functions to visualise and explore the results. When multiple samples are used, we can visualise the correlation and clustering of all samples with a heatmap:

Additionally, we can also visualise the correlation with a 2-dimmensional PCA plot.

In addition to visualising the correlation between samples, bambu also provide a function to visualise the extended annotation and expression estimation for individual genes. Here we look at gene ENSG00000099968 and visualise the transcript coordinates for annotated and novel isoforms and expression levels for these isoforms across all samples.

##> [[1]]
##> TableGrob (3 x 1) "arrange": 3 grobs
##>   z     cells    name                grob
##> 1 1 (2-2,1-1) arrange      gtable[layout]
##> 2 2 (3-3,1-1) arrange      gtable[layout]
##> 3 3 (1-1,1-1) arrange text[GRID.text.250]

Obtain gene expression estimates from transcript expression

{#gene-expression} Gene expression can be calculated from the transcript expression estimates returned by bambu using the function. Looking at the output, we can see there are novel genes identified as well

We can again use the function to visualise the gene expression data across the 6 samples with a heatmap or PCA plot. As expected, samples from the same cell line showed higher correlation than across the cell lines.

Save data (gtf/text)

bambu includes a function to write the extended annotations, the transcript and the gene expression estimates that include any newly discovered genes and transcripts to text files.

bambu also includes a function that only exports the extended annotations to gtf file:

Identifying differentially expressed genes

One of the most common tasks when analysing RNA-Seq data is the analysis of differential gene expression across a condition of intertest. Here we use DESeq2 to find the differentially expressed genes between MCF7 and K562 cell lines. Similar to using results from Salmon, estimates from bambu will first be rounded.

library(DESeq2)
dds <- DESeqDataSetFromMatrix(round(assays(seGene)$counts), colData = colData(se),
    design = ~condition)
dds.deseq <- DESeq(dds)
deGeneRes <- DESeq2::results(dds.deseq, independentFiltering = FALSE)
head(deGeneRes[order(deGeneRes$padj), ])
##> log2 fold change (MLE): condition MCF7 vs K562 
##> Wald test p-value: condition MCF7 vs K562 
##> DataFrame with 6 rows and 6 columns
##>                  baseMean log2FoldChange     lfcSE      stat
##>                 <numeric>      <numeric> <numeric> <numeric>
##> ENSG00000185686  500.6470       -7.15159  0.500364 -14.29278
##> ENSG00000283633   95.7518       -9.10519  1.246517  -7.30451
##> ENSG00000197077   26.9189        9.17563  1.320390   6.94918
##> ENSG00000240972 2443.3934        2.47082  0.357369   6.91392
##> ENSG00000099977  235.8601        1.92963  0.306609   6.29347
##> ENSG00000169635   43.5245       -3.36897  0.569649  -5.91411
##>                                                                pvalue
##>                                                             <numeric>
##> ENSG00000185686 0.000000000000000000000000000000000000000000000242728
##> ENSG00000283633 0.000000000000278275679947602694397391918138592006762
##> ENSG00000197077 0.000000000003674139901044544811771829869715655608568
##> ENSG00000240972 0.000000000004714473225560826484330951067763324359265
##> ENSG00000099977 0.000000000310450546572332925146307722118438170155752
##> ENSG00000169635 0.000000003336692881462437529443458496432317605950857
##>                                                                padj
##>                                                           <numeric>
##> ENSG00000185686 0.0000000000000000000000000000000000000000000631093
##> ENSG00000283633 0.0000000000361758383931883483531512278605162501177
##> ENSG00000197077 0.0000000003064407596614537449075252608477826568589
##> ENSG00000240972 0.0000000003064407596614537449075252608477826568589
##> ENSG00000099977 0.0000000161434284217613106600419295823603538231339
##> ENSG00000169635 0.0000001445900248633722995599947686029551618958067

A quick summary of differentially expressed genes

We can also visualise the MA-plot for differentially used isoforms using . However, visualizing the MA-plots using the original log-fold change results will be affected by the noise associated with log2 fold changes from low count genes without requiring arbitrary filtering thresholds. As recommended in the [DESeq2tutorial] (http://bioconductor.org/packages/devel/bioc/vignettes/DESeq2/inst/doc/ DESeq2.html#alternative-shrinkage-estimators). we applied the same shrinkage to effect sizes to improve the visualization.

Identifying differential transcript usage

We used DEXSeq to detect alternative used isoforms.

We can visualize the MA-plot

Running bambu with large number of samples

For larger sample numbers we recommend to write the processed data to a file. This can be done by providing the readClass.outputDir:

se <- bambu(reads = bamFiles, rcOutDir = "./bambu/", annotations = annotaiton, genome = genomeSequence)

Bambu parameters

Advanced Options

For transcript discovery we recommend to adjust the parameters according to the number of replicates and the sequencing throughput. The most relevant parameters are explained here. You can use any combination of these parameters. ### More stringent filtering thresholds imposed on potential novel transcripts

Quantification without bias correction

The default estimation automatically does bias correction for expression estimates. However, you can choose to perform the quantification without bias correction.

Parallel computation

bambu allows parallel computation.

See our page for details to customize other conditions.

Getting help

Questions and issues can be raised at the Bioconductor support site (once bambu is available through bioconductor): https://support.bioconductor.org. Please tag your your posts with bambu.

Alternatively, issues can be raised at the bambu Github repository:https://github.com/GoekeLab/bambu.

Citing bambu

A manuscript describing bambu is currently in preparation. If you use bambu for your research, please cite using the following doi: 10.5281/zenodo.3900025.

Session Information

sessionInfo()
##> R version 4.2.0 RC (2022-04-19 r82224)
##> Platform: x86_64-pc-linux-gnu (64-bit)
##> Running under: Ubuntu 20.04.4 LTS
##> 
##> Matrix products: default
##> BLAS:   /home/biocbuild/bbs-3.15-bioc/R/lib/libRblas.so
##> LAPACK: /home/biocbuild/bbs-3.15-bioc/R/lib/libRlapack.so
##> 
##> locale:
##>  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
##>  [3] LC_TIME=en_GB              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] stats4    stats     graphics  grDevices utils     datasets  methods  
##> [8] base     
##> 
##> other attached packages:
##>  [1] DEXSeq_1.41.0                         
##>  [2] RColorBrewer_1.1-3                    
##>  [3] AnnotationDbi_1.57.1                  
##>  [4] BiocParallel_1.29.21                  
##>  [5] apeglm_1.17.0                         
##>  [6] DESeq2_1.35.0                         
##>  [7] ggplot2_3.3.5                         
##>  [8] BSgenome.Hsapiens.NCBI.GRCh38_1.3.1000
##>  [9] Rsamtools_2.11.0                      
##> [10] NanoporeRNASeq_1.5.1                  
##> [11] ExperimentHub_2.3.7                   
##> [12] AnnotationHub_3.3.12                  
##> [13] BiocFileCache_2.3.5                   
##> [14] dbplyr_2.1.1                          
##> [15] bambu_2.1.8                           
##> [16] BSgenome_1.63.7                       
##> [17] rtracklayer_1.55.4                    
##> [18] Biostrings_2.63.3                     
##> [19] XVector_0.35.0                        
##> [20] SummarizedExperiment_1.25.3           
##> [21] Biobase_2.55.2                        
##> [22] GenomicRanges_1.47.6                  
##> [23] GenomeInfoDb_1.31.10                  
##> [24] IRanges_2.29.1                        
##> [25] S4Vectors_0.33.17                     
##> [26] BiocGenerics_0.41.2                   
##> [27] MatrixGenerics_1.7.0                  
##> [28] matrixStats_0.62.0                    
##> 
##> loaded via a namespace (and not attached):
##>   [1] utf8_1.2.2                    tidyselect_1.1.2             
##>   [3] RSQLite_2.2.12                htmlwidgets_1.5.4            
##>   [5] grid_4.2.0                    munsell_0.5.0                
##>   [7] codetools_0.2-18              statmod_1.4.36               
##>   [9] xgboost_1.6.0.1               withr_2.5.0                  
##>  [11] colorspace_2.0-3              filelock_1.0.2               
##>  [13] OrganismDbi_1.37.2            highr_0.9                    
##>  [15] knitr_1.38                    rstudioapi_0.13              
##>  [17] labeling_0.4.2                bbmle_1.0.24                 
##>  [19] GenomeInfoDbData_1.2.8        hwriter_1.3.2.1              
##>  [21] bit64_4.0.5                   farver_2.1.0                 
##>  [23] coda_0.19-4                   vctrs_0.4.1                  
##>  [25] generics_0.1.2                xfun_0.30                    
##>  [27] biovizBase_1.43.1             R6_2.5.1                     
##>  [29] doParallel_1.0.17             clue_0.3-60                  
##>  [31] locfit_1.5-9.5                AnnotationFilter_1.19.0      
##>  [33] bitops_1.0-7                  cachem_1.0.6                 
##>  [35] reshape_0.8.9                 DelayedArray_0.21.2          
##>  [37] assertthat_0.2.1              promises_1.2.0.1             
##>  [39] BiocIO_1.5.0                  scales_1.2.0                 
##>  [41] nnet_7.3-17                   gtable_0.3.0                 
##>  [43] Cairo_1.5-15                  ggbio_1.43.0                 
##>  [45] ensembldb_2.19.10             rlang_1.0.2                  
##>  [47] genefilter_1.77.1             GlobalOptions_0.1.2          
##>  [49] splines_4.2.0                 lazyeval_0.2.2               
##>  [51] dichromat_2.0-0               checkmate_2.1.0              
##>  [53] BiocManager_1.30.17           yaml_2.3.5                   
##>  [55] reshape2_1.4.4                GenomicFeatures_1.47.14      
##>  [57] backports_1.4.1               httpuv_1.6.5                 
##>  [59] Hmisc_4.7-0                   RBGL_1.71.0                  
##>  [61] tools_4.2.0                   ellipsis_0.3.2               
##>  [63] jquerylib_0.1.4               Rcpp_1.0.8.3                 
##>  [65] plyr_1.8.7                    base64enc_0.1-3              
##>  [67] progress_1.2.2                zlibbioc_1.41.0              
##>  [69] purrr_0.3.4                   RCurl_1.98-1.6               
##>  [71] prettyunits_1.1.1             rpart_4.1.16                 
##>  [73] GetoptLong_1.0.5              cluster_2.1.3                
##>  [75] magrittr_2.0.3                data.table_1.14.2            
##>  [77] magick_2.7.3                  circlize_0.4.14              
##>  [79] mvtnorm_1.1-3                 ProtGenerics_1.27.2          
##>  [81] hms_1.1.1                     mime_0.12                    
##>  [83] evaluate_0.15                 xtable_1.8-4                 
##>  [85] XML_3.99-0.9                  emdbook_1.3.12               
##>  [87] jpeg_0.1-9                    gridExtra_2.3                
##>  [89] shape_1.4.6                   bdsmatrix_1.3-4              
##>  [91] compiler_4.2.0                biomaRt_2.51.4               
##>  [93] tibble_3.1.6                  crayon_1.5.1                 
##>  [95] htmltools_0.5.2               later_1.3.0                  
##>  [97] Formula_1.2-4                 tidyr_1.2.0                  
##>  [99] geneplotter_1.73.0            DBI_1.1.2                    
##> [101] formatR_1.12                  ComplexHeatmap_2.11.1        
##> [103] MASS_7.3-57                   rappdirs_0.3.3               
##> [105] Matrix_1.4-1                  cli_3.2.0                    
##> [107] parallel_4.2.0                pkgconfig_2.0.3              
##> [109] GenomicAlignments_1.31.2      numDeriv_2016.8-1.1          
##> [111] foreign_0.8-82                xml2_1.3.3                   
##> [113] foreach_1.5.2                 annotate_1.73.0              
##> [115] bslib_0.3.1                   stringr_1.4.0                
##> [117] VariantAnnotation_1.41.3      digest_0.6.29                
##> [119] graph_1.73.0                  rmarkdown_2.13               
##> [121] htmlTable_2.4.0               restfulr_0.0.13              
##> [123] curl_4.3.2                    shiny_1.7.1                  
##> [125] rjson_0.2.21                  lifecycle_1.0.1              
##> [127] jsonlite_1.8.0                fansi_1.0.3                  
##> [129] pillar_1.7.0                  lattice_0.20-45              
##> [131] GGally_2.1.2                  KEGGREST_1.35.0              
##> [133] fastmap_1.1.0                 httr_1.4.2                   
##> [135] survival_3.3-1                interactiveDisplayBase_1.33.0
##> [137] glue_1.6.2                    png_0.1-7                    
##> [139] iterators_1.0.14              BiocVersion_3.15.2           
##> [141] bit_4.0.4                     stringi_1.7.6                
##> [143] sass_0.4.1                    blob_1.2.3                   
##> [145] latticeExtra_0.6-29           memoise_2.0.1                
##> [147] dplyr_1.0.8