diff --git a/.Rbuildignore b/.Rbuildignore index 83390479..9564bfe0 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -2,3 +2,5 @@ ^\.Rproj\.user$ ^packrat/ ^\.Rprofile$ +^doc$ +^Meta$ diff --git a/.gitignore b/.gitignore index 6b9f0569..2126ec2e 100644 --- a/.gitignore +++ b/.gitignore @@ -40,3 +40,5 @@ vignettes/*.pdf .Renviron packrat/lib*/ .Rproj.user +doc +Meta diff --git a/DESCRIPTION b/DESCRIPTION index a7dbe59f..6e0dd559 100755 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,10 +1,10 @@ Package: bambu Type: Package Title: Reference-guided isoform reconstruction and quantification for long read RNA-Seq data -Version: 0.9.0 -Authors@R: c(person("Jonathan Goeke", "Developer", role = "aut", - email = "gokej@gis.a-star.edu.sg"), - person("Ying Chen", "Developer", role = "cre",email = "chen_ying@gis.a-star.edu.sg")) +Version: 0.1.0 +Authors@R: c(person("Ying Chen", "Developer", role = "cre",email = "chen_ying@gis.a-star.edu.sg"), + person("Jonathan Goeke", "Developer", role = "aut", + email = "gokej@gis.a-star.edu.sg")) Description: Multi-sample transcript discovery and quantification using long read RNA-Seq data. License: GPL-3 Encoding: UTF-8 diff --git a/R/abundance_quantification.R b/R/abundance_quantification.R index fa1c506d..3ffb9813 100755 --- a/R/abundance_quantification.R +++ b/R/abundance_quantification.R @@ -2,26 +2,37 @@ #' @title transcript_abundance_quantification #' @param method A string variable indicates the whether a one-step or two-step approach will be used. See \code{Details} #' for details on one-step and two-step approach. -#' @param read_classDT A \code{data.table} with columns +#' @param readClassDt A \code{data.table} with columns #' @importFrom BiocParallel bplapply #' @noRd -abundance_quantification <- function(read_classDT,ncore = 1, - bias_correction = TRUE, +abundance_quantification <- function(readClassDt,ncore = 1, + bias = TRUE, maxiter = 20000, - conv.control = 10^(-8)){ - gene_sidList <- unique(read_classDT$gene_sid) - - bpParameters <- BiocParallel::bpparam() - bpParameters$workers <- ncore - + conv = 10^(-8)){ + gene_sidList <- unique(readClassDt$gene_sid) + + if(ncore == 1){ + + emResultsList <- lapply(as.list(gene_sidList), + run_parallel, + conv = conv, + bias = bias, + maxiter = maxiter, + readClassDt = readClassDt) + }else{ + bpParameters <- BiocParallel::bpparam() + bpParameters$workers <- ncore + + emResultsList <- BiocParallel::bplapply(as.list(gene_sidList), + run_parallel, + conv = conv, + bias = bias, + maxiter = maxiter, + readClassDt = readClassDt, + BPPARAM=bpParameters) + } + - emResultsList <- BiocParallel::bplapply(as.list(gene_sidList), - run_parallel, - conv.control = conv.control, - bias_correction = bias_correction, - maxiter = maxiter, - read_classDT = read_classDT, - BPPARAM=bpParameters) estimates <- list(do.call('rbind',lapply(1:length(emResultsList), function(x) emResultsList[[x]][[1]])), @@ -30,8 +41,8 @@ abundance_quantification <- function(read_classDT,ncore = 1, return(estimates) } -run_parallel <- function(g,conv.control,bias_correction,maxiter, read_classDT){ - tmp <- read_classDT[gene_sid==g] +run_parallel <- function(g,conv,bias,maxiter, readClassDt){ + tmp <- readClassDt[gene_sid==g] if((nrow(tmp)==1)){ out <- list(data.table(tx_sid = tmp$tx_sid, estimates = tmp$nobs, @@ -58,12 +69,12 @@ run_parallel <- function(g,conv.control,bias_correction,maxiter, read_classDT){ est_output <- emWithL1(X = as.matrix(a_mat), Y = n.obs, lambda = lambda, - d = bias_correction, + d = bias, maxiter = maxiter, - conv = conv.control) + conv = conv) t_est <- as.numeric(t(est_output[["theta"]])) - if(bias_correction){ + if(bias){ b_est <- as.numeric(t(est_output[["b"]])) }else{ b_est <- rep(0,ncol(a_mat)) diff --git a/R/annotationFunctions.R b/R/annotationFunctions.R index 1f36447a..16db3f5e 100755 --- a/R/annotationFunctions.R +++ b/R/annotationFunctions.R @@ -34,39 +34,52 @@ prepareAnnotations <- function(txdb) { } -#' Prepare annotations from gtf -#' @title prepare annotations from gtf file -#' @param gtf.file A string variable indicates the path to a gtf file. -#' @param organism as described in \code{\link{makeTxDbFromGFF}}. -#' @param dataSource as described in \code{\link{makeTxDbFromGFF}}. -#' @param taxonomyId as described in \code{\link{makeTxDbFromGFF}}. -#' @param chrominfo as described in \code{\link{makeTxDbFromGFF}}. -#' @param miRBaseBuild as described in \code{\link{makeTxDbFromGFF}}. -#' @param metadata as described in \code{\link{makeTxDbFromGFF}}. -#' @param dbxrefTag as described in \code{\link{makeTxDbFromGFF}}. -#' @param ... see \code{\link{makeTxDbFromGFF}}. -#' @return A \code{\link{GrangesList}} object +#' Prepare annotation granges object from GTF file +#' @title Prepare annotation granges object from GTF file into a GRangesList object +#' @param file a GTF file +#' @return grlist a \code{\link{GRangesList}} object, unlike \code\link{readFromGTF}}, +#' this function finds out the equivalence classes between the transcripts, +#' with \code{\link{mcols}} data having three columns: +#' \itemize{ +#' \item TXNAME specifying prefix for new gene Ids (genePrefix.number), defaults to empty +#' \item GENEID indicating whether filter to remove read classes which are a subset of known transcripts(), defaults to TRUE +#' \item eqClass specifying minimun read count to consider a read class valid in a sample, defaults to 2 +#' } +#' #' @export -prepareAnnotationsFromGTF <- function(gtf.file, dataSource=NA, - organism="Homo sapiens", - taxonomyId=NA, - chrominfo=NULL, - miRBaseBuild=NA, - metadata=NULL, - dbxrefTag,...){ - return(prepareAnnotations(GenomicFeatures::makeTxDbFromGFF(gtf.file, format = "gtf", - organism = organism, - dataSource = dataSource, - taxonomyId = taxonomyId, - chrominfo = chrominfo, - miRBaseBuild = miRBaseBuild, - metadata = metadata, - dbxrefTag = dbxrefTag - ))) +prepareAnnotationsFromGTF <- function(file){ + if (missing(file)){ + stop('A GTF file is required.') + }else{ + data <- read.delim(file,header=FALSE,comment.char='#') + colnames(data) <- c("seqname","source","type","start","end","score","strand","frame","attribute") + data <- data[data$type=='exon',] + data$strand[data$strand=='.'] <- '*' + data$GENEID = gsub('gene_id (.*?);.*','\\1',data$attribute) + data$TXNAME=gsub('.*transcript_id (.*?);.*', '\\1',data$attribute) + data$exon_rank=as.integer(gsub('.*exon_number (.*?);.*', '\\1',data$attribute)) + geneData=unique(data[,c('TXNAME', 'GENEID')]) + grlist <- makeGRangesListFromDataFrame( + data[,c('seqname', 'start','end','strand','exon_rank','TXNAME')],split.field='TXNAME',keep.extra.columns = TRUE) + + unlistedExons <- unlist(grlist, use.names = FALSE) + partitioning <- PartitioningByEnd(cumsum(elementNROWS(grlist)), names=NULL) + txIdForReorder <- togroup(PartitioningByWidth(grlist)) + unlistedExons <- unlistedExons[order(txIdForReorder, unlistedExons$exon_rank)] #'exonsByTx' is always sorted by exon rank, not by strand, make sure that this is the case here + unlistedExons$exon_endRank <- unlist(sapply(elementNROWS(grlist),seq,to=1), use.names=FALSE) + unlistedExons <- unlistedExons[order(txIdForReorder, start(unlistedExons))] + # mcols(unlistedExons) <- mcols(unlistedExons)[,c('exon_rank','exon_endRank')] + grlist <- relist(unlistedExons, partitioning) + minEqClasses <- getMinimumEqClassByTx(grlist) + mcols(grlist) <- DataFrame(geneData[(match(names(grlist), geneData$TXNAME)),]) + mcols(grlist)$eqClass <- minEqClasses$eqClass[match(names(grlist),minEqClasses$queryTxId)] + } + return (grlist) } + #' Get minimum equivalent class by Transcript #' @param exonsByTranscripts exonsByTranscripts #' @noRd diff --git a/R/bambu.R b/R/bambu.R index 1f20613e..3cd3e7d4 100755 --- a/R/bambu.R +++ b/R/bambu.R @@ -4,22 +4,14 @@ #' It also allows saving of read class files of alignments, extending provided annotations, and quantification based on extended annotations. #' When multiple samples are provided, extended annotations will be combined across samples to allow comparison. #' @param reads A string or a vector of strings specifying the paths of bam files for genomic alignments, or a \code{\link{BamFile}} object or a \code{\link{BamFileList}} object (see \code{\link{Rsamtools}}). -#' @param readclass.file A string or a vector of strings specifying the read class files that are saved during previous run of \code{\link{bambu}}. -#' @param outputReadClassDir A string variable specifying the path to where read class files will be saved. +#' @param readClass.file A string or a vector of strings specifying the read class files that are saved during previous run of \code{\link{bambu}}. +#' @param readClass.outputDir A string variable specifying the path to where read class files will be saved. #' @param annotations A \code{\link{TxDb}} object or A GRangesList object obtained by \code{\link{prepareAnnotations}} or \code{\link{prepareAnnotationsFromGTF}}. -#' @param extendAnnotations A logical variable indicating whether annotations are to be extended for quantification. #' @param genomeSequence A fasta file or a BSGenome object. -#' @param algo.control A list of controlling parameters for quantification algorithm estimation process: -#' \itemize{ -#' \item ncore specifying number of cores used when parallel processing is used, defaults to 1. -#' \item maxiter specifying maximum number of run interations, defaults to 10000. -#' \item bias_correction specifying whether to correct for bias, defaults to FALSE. -#' \item convcontrol specifying the covergence trheshold control, defaults to 0.0001. -#' } +#' @param ncore specifying number of cores used when parallel processing is used, defaults to 1. #' @param yieldSize see \code{\link{Rsamtools}}. -#' @param ir.control A list of controlling parameters for isoform reconstruction process: +#' @param isoreParameters A list of controlling parameters for isoform reconstruction process: #' \itemize{ -#' \item whether stranded, defaults to FALSE #' \item prefix specifying prefix for new gene Ids (genePrefix.number), defaults to empty #' \item remove.subsetTx indicating whether filter to remove read classes which are a subset of known transcripts(), defaults to TRUE #' \item min.readCount specifying minimun read count to consider a read class valid in a sample, defaults to 2 @@ -28,6 +20,13 @@ #' \item min.exonDistance specifying minum distance to known transcript to be considered valid as new, defaults to 35 #' \item min.exonOverlap specifying minimum number of bases shared with annotation to be assigned to the same gene id, defaults 10 base pairs #' } +#' @param emParameters A list of controlling parameters for quantification algorithm estimation process: +#' \itemize{ +#' \item maxiter specifying maximum number of run interations, defaults to 10000. +#' \item bias specifying whether to correct for bias, defaults to FALSE. +#' \item conv specifying the covergence trheshold control, defaults to 0.0001. +#' } +#' @param extendAnnotations A logical variable indicating whether annotations are to be extended for quantification. #' @param verbose A logical variable indicating whether processing messages will be printed. #' @details #' @return A list of two SummarizedExperiment object for transcript expression and gene expression. @@ -37,11 +36,16 @@ #' ## More stringent new gene/isoform discovery: new isoforms are identified with at least 5 read count in 1 sample #' ## Increase EM convergence threshold to 10^(-6) #' seOutput <- bambu(reads, annotationGrangesList, -#' genomeSequence, ir.control = list(min.readCount=5), -#' algo.control = list(convcontrol = 10^(-6)) +#' genomeSequence, isoreParameters = list(min.readCount=5), +#' emParameters = list(conv = 10^(-6)) #' } #' @export -bambu <- function(reads = NULL, readclass.file = NULL, outputReadClassDir = NULL, annotations = NULL, genomeSequence = NULL, algo.control = NULL, yieldSize = NULL, ir.control = NULL, extendAnnotations = TRUE, stranded = FALSE, ncore = 1, verbose = FALSE){ +bambu <- function(reads = NULL, readClass.file = NULL, readClass.outputDir = NULL, + annotations = NULL, genomeSequence = NULL, + stranded = FALSE, ncore = 1, + yieldSize = NULL, + isoreParameters = NULL, emParameters = NULL, + extendAnnotations = TRUE, verbose = FALSE){ #===# Check annotation inputs #===# @@ -62,63 +66,61 @@ bambu <- function(reads = NULL, readclass.file = NULL, outputReadClassDir = NULL ## When SE object from bambu.quantISORE is provided ## - if(!is.null(reads) & (!is.null(readclass.file))){ + if(!is.null(reads) & (!is.null(readClass.file))){ stop("At least bam file or path to readClass file needs to be provided.") } - #===# Check whether provided outputReadClassDir exists #===# - if(!is.null(outputReadClassDir)) { - if(!dir.exists(outputReadClassDir)) { + #===# Check whether provided readClass.outputDir exists #===# + if(!is.null(readClass.outputDir)) { + if(!dir.exists(readClass.outputDir)) { stop("output folder does not exist") } } #===# Check whether provided readclass files are all in rds format #===# - if(!is.null(readclass.file)){ - if(!all(grepl(".rds", readclass.file))){ + if(!is.null(readClass.file)){ + if(!all(grepl(".rds", readClass.file))){ stop("Read class files should be provided in rds format.") } } #===# set default controlling parameters for isoform reconstruction #===# - ir.control.default <- list(stranded = FALSE, - remove.subsetTx = TRUE, # + isoreParameters.default <- list(remove.subsetTx = TRUE, # min.readCount = 2, # min.readFractionByGene = 0.05, ## min.sampleNumber = 1, # min.exonDistance = 35, # min.exonOverlap = 10, # prefix='') ## - if(!is.null(ir.control)){ - for(i in names(ir.control)) { - ir.control.default[[i]] <- ir.control[[i]] + if(!is.null(isoreParameters)){ + for(i in names(isoreParameters)) { + isoreParameters.default[[i]] <- isoreParameters[[i]] } } - ir.control <- ir.control.default + isoreParameters <- isoreParameters.default ## check quantification parameters - algo.control.default <- list(bias_correction = FALSE, + emParameters.default <- list(bias = FALSE, maxiter = 10000, - convcontrol = 10^(-4)) + conv = 10^(-4)) - if(!is.null(algo.control)){ - for(i in names(algo.control)) { - algo.control.default[[i]] <- algo.control[[i]] + if(!is.null(emParameters)){ + for(i in names(emParameters)) { + emParameters.default[[i]] <- emParameters[[i]] } } - algo.control <- algo.control.default + emParameters <- emParameters.default rm.readClassSe <- FALSE # indicator to remove temporary read class files bpParameters <- BiocParallel::bpparam() #===# set parallel options: If more CPUs than samples available, use parallel computing on each sample, otherwise use parallel to distribute samples (more efficient) - if(length(reads)<=(0.5*ncore)) { - bpParameters$workers <- 1 - } else { - bpParameters$workers <- ncore + bpParameters$workers <- ifelse(length(reads)==1, 1, ncore) + bpParameters$progressbar <- (!verbose) + + if(bpParameters$workers>1){ ncore <- 1 } - if(!is.null(reads)){ # calculate readClass objects #===# create BamFileList object from character #===# @@ -148,45 +150,53 @@ bambu <- function(reads = NULL, readclass.file = NULL, outputReadClassDir = NULL #===# When more than 10 samples are provided, files will be written to a temporary directory - if(length(reads)>10 &(is.null(outputReadClassDir))){ - outputReadClassDir <- tempdir() - warning(paste0("There are more than 10 samples, read class files will be temporarily saved to ",outputReadClassDir, " for more efficient processing")) + if(length(reads)>10 &(is.null(readClass.outputDir))){ + readClass.outputDir <- tempdir() + message(paste0("There are more than 10 samples, read class files will be temporarily saved to ",readClass.outputDir, " for more efficient processing")) rm.readClassSe <- TRUE # remove temporary read class files from system } - + if(!verbose) message("Start generating read class files") readClassList <- BiocParallel::bplapply(names(reads), function(bamFileName){ bambu.constructReadClass( bam.file= reads[bamFileName], - outputReadClassDir=outputReadClassDir, + readClass.outputDir=readClass.outputDir, genomeSequence = genomeSequence, annotations = annotations, stranded=stranded, ncore = ncore, verbose = verbose)}, BPPARAM=bpParameters) + + if(!verbose) message("Finished generating read classes from genomic alignments.") } else { - readClassList <- readclass.file + readClassList <- readClass.file } if(extendAnnotations) { - annotations <- bambu.extendAnnotations(readClassList, annotations, ir.control, verbose=verbose) + annotations <- bambu.extendAnnotations(readClassList, annotations, isoreParameters, verbose=verbose) + if(!verbose) message("Finished extending annotations.") gc(verbose = FALSE) } - countsSe <- BiocParallel::bplapply(readClassList, - bambu.quantify, - annotations=annotations, - min.exonDistance= ir.control[['min.exonDistance']], - algo.control = algo.control, - ncore = ncore, - verbose = verbose, - BPPARAM=bpParameters) + + if(!verbose) message("Start isoform quantification") + + countsSe <- BiocParallel::bplapply(readClassList, + bambu.quantify, + annotations=annotations, + min.exonDistance= isoreParameters[['min.exonDistance']], + emParameters = emParameters, + ncore = ncore, + verbose = verbose, + BPPARAM=bpParameters) + countsSe <- do.call(SummarizedExperiment::cbind, countsSe) rowRanges(countsSe) <- annotations + if(!verbose) message("Finished isoform quantification.") #===# Clean up temp directory if(rm.readClassSe){ @@ -198,7 +208,7 @@ bambu <- function(reads = NULL, readclass.file = NULL, outputReadClassDir = NULL #' Extend annotations #' @inheritParams bambu #' @noRd -bambu.extendAnnotations <- function(readClassList, annotations, ir.control, verbose = FALSE){ +bambu.extendAnnotations <- function(readClassList, annotations, isoreParameters, verbose = FALSE){ combinedTxCandidates = NULL for(readClassIndex in seq_along(readClassList)){ readClass <- readClassList[[readClassIndex]] @@ -210,13 +220,13 @@ bambu.extendAnnotations <- function(readClassList, annotations, ir.control, verb } annotations <- isore.extendAnnotations(se=combinedTxCandidates, annotationGrangesList=annotations, - remove.subsetTx = ir.control[['remove.subsetTx']], - min.readCount = ir.control[['min.readCount']], - min.readFractionByGene = ir.control[['min.readFractionByGene']], - min.sampleNumber = ir.control[['min.sampleNumber']], - min.exonDistance = ir.control[['min.exonDistance']], - min.exonOverlap = ir.control[['min.exonOverlap']], - prefix = ir.control[['prefix']], + remove.subsetTx = isoreParameters[['remove.subsetTx']], + min.readCount = isoreParameters[['min.readCount']], + min.readFractionByGene = isoreParameters[['min.readFractionByGene']], + min.sampleNumber = isoreParameters[['min.sampleNumber']], + min.exonDistance = isoreParameters[['min.exonDistance']], + min.exonOverlap = isoreParameters[['min.exonOverlap']], + prefix = isoreParameters[['prefix']], verbose = verbose) return(annotations) } @@ -224,19 +234,19 @@ bambu.extendAnnotations <- function(readClassList, annotations, ir.control, verb #' Perform quantification #' @inheritParams bambu #' @noRd -bambu.quantify <- function(readClass, annotations, algo.control, min.exonDistance=35, ncore = 1, verbose = FALSE){ +bambu.quantify <- function(readClass, annotations, emParameters, min.exonDistance=35, ncore = 1, verbose = FALSE){ if(is.character(readClass)){ readClass <- readRDS(file=readClass) seqlevelsStyle(readClass) <- seqlevelsStyle(annotations)[1] } readClass <- isore.estimateDistanceToAnnotations(readClass, annotations, min.exonDistance = min.exonDistance, verbose = verbose) - dt <- getEmptyClassFromSE(readClass, annotations) + readClassDt <- getEmptyClassFromSE(readClass, annotations) colNameRC <- colnames(readClass) colDataRC <- colData(readClass) rm(readClass) gc(verbose=FALSE) - counts <- bambu.quantDT(dt,algo.control = algo.control, ncore = ncore, verbose = verbose) + counts <- bambu.quantDT(readClassDt,emParameters = emParameters, ncore = ncore, verbose = verbose) if(length(setdiff(counts$tx_name,names(annotations)))>0){ stop("The provided annotation is incomplete") } @@ -252,10 +262,10 @@ bambu.quantify <- function(readClass, annotations, algo.control, min.exonDistanc #' Preprocess bam files and save read class files #' @inheritParams bambu #' @noRd -bambu.constructReadClass <- function(bam.file, genomeSequence, annotations, outputReadClassDir=NULL, stranded=FALSE, ncore=1, verbose=FALSE){ +bambu.constructReadClass <- function(bam.file, genomeSequence, annotations, readClass.outputDir=NULL, stranded=FALSE, ncore=1, verbose=FALSE){ - readGrgList <- prepareDataFromBam(bam.file[[1]], cores=ncore, verbose = verbose) + readGrgList <- prepareDataFromBam(bam.file[[1]], ncore=ncore, verbose = verbose) seqlevelsStyle(readGrgList) <- seqlevelsStyle(annotations)[1] se <- isore.constructReadClasses(readGrgList = readGrgList, runName = names(bam.file)[1], @@ -265,8 +275,8 @@ bambu.constructReadClass <- function(bam.file, genomeSequence, annotations, outp ncore = ncore, verbose = verbose) seqlevels(se) <- unique(c(seqlevels(se), seqlevels(annotations))) - if(!is.null(outputReadClassDir)){ - readClassFile <- fs::path(outputReadClassDir,paste0(names(bam.file),'_readClassSe'), ext='rds') + if(!is.null(readClass.outputDir)){ + readClassFile <- fs::path(readClass.outputDir,paste0(names(bam.file),'_readClassSe'), ext='rds') if(file.exists(readClassFile)){ show(paste(readClassFile, 'exists, will be overwritten')) #warning is not printed, use show in addition warning(paste(readClassFile, 'exists, will be overwritten')) @@ -280,52 +290,52 @@ bambu.constructReadClass <- function(bam.file, genomeSequence, annotations, outp #' Process data.table object -#' @param dt A data.table object +#' @param readClassDt A data.table object #' @inheritParams bambu #' @noRd -bambu.quantDT <- function(dt = dt,algo.control = NULL,ncore = 1, verbose = FALSE){ - if(is.null(dt)){ +bambu.quantDT <- function(readClassDt = readClassDt,emParameters = NULL,ncore = 1, verbose = FALSE){ + if(is.null(readClassDt)){ stop("Input object is missing.") - }else if(any(!(c('gene_id','tx_id','read_class_id','nobs') %in% colnames(dt)))){ + }else if(any(!(c('gene_id','tx_id','read_class_id','nobs') %in% colnames(readClassDt)))){ stop("Columns gene_id, tx_id, read_class_id, nobs, are missing from object.") } ## check quantification parameters - algo.control.default <- list(bias_correction = FALSE, + emParameters.default <- list(bias = FALSE, maxiter = 10000, - convcontrol = 10^(-4)) + conv = 10^(-4)) - if(!is.null(algo.control)){ - for(i in names(algo.control)) { - algo.control.default[[i]] <- algo.control[[i]] + if(!is.null(emParameters)){ + for(i in names(emParameters)) { + emParameters.default[[i]] <- emParameters[[i]] } } - algo.control <- algo.control.default + emParameters <- emParameters.default ##----step2: match to simple numbers to increase claculation efficiency - geneVec <- unique(dt$gene_id) - txVec <- unique(dt$tx_id) - readclassVec <- unique(dt$read_class_id) - dt <- as.data.table(dt) - dt[, gene_sid:=match(gene_id, geneVec)] - dt[, tx_sid:=match(tx_id, txVec)] - dt[, read_class_sid:=match(read_class_id, readclassVec)] + geneVec <- unique(readClassDt$gene_id) + txVec <- unique(readClassDt$tx_id) + readclassVec <- unique(readClassDt$read_class_id) + readClassDt <- as.data.table(readClassDt) + readClassDt[, gene_sid:=match(gene_id, geneVec)] + readClassDt[, tx_sid:=match(tx_id, txVec)] + readClassDt[, read_class_sid:=match(read_class_id, readclassVec)] - dt[,`:=`(tx_id = NULL, gene_id = NULL, read_class_id = NULL)] + readClassDt[,`:=`(tx_id = NULL, gene_id = NULL, read_class_id = NULL)] ##----step3: aggregate read class - temp <- aggReadClass(dt) - dt <- temp[[1]] + temp <- aggReadClass(readClassDt) + readClassDt <- temp[[1]] eqClassVec <- temp[[2]] ##----step4: quantification start.time <- proc.time() - outList <- abundance_quantification(dt, + outList <- abundance_quantification(readClassDt, ncore = ncore, - bias_correction = algo.control[["bias_correction"]], - maxiter = algo.control[["maxiter"]], - conv.control = algo.control[["convcontrol"]]) + bias = emParameters[["bias"]], + maxiter = emParameters[["maxiter"]], + conv = emParameters[["conv"]]) end.time <- proc.time() if(verbose) message('Finished EM estimation in ', round((end.time-start.time)[3]/60,1), ' mins.') diff --git a/R/plotBambu.R b/R/plotBambu.R index 0b301197..a9c95dd7 100644 --- a/R/plotBambu.R +++ b/R/plotBambu.R @@ -59,7 +59,7 @@ plot.bambu <- function(se, group.variable = NULL, type = c("annotation","pca","h txRanges <- rowRanges(se)[txVec] names(txRanges) <- paste0(txVec,":", unlist(lapply(strand(txRanges),function(x) unique(as.character(x))))) p_annotation <- ggbio::autoplot(txRanges, group.selfish = TRUE) - p_expression <- ggbio::autoplot(as.matrix(log2(assays(se)$CPM[txVec,]+1)),axis.text.angle = 45) + p_expression <- ggbio::autoplot(as.matrix(log2(assays(se)$CPM[txVec,]+1)),axis.text.angle = 45, hjust = 1) p <- gridExtra::grid.arrange(p_annotation@ggplot, p_expression, top = g, heights = c(1,1)) @@ -133,11 +133,11 @@ plot.bambu <- function(se, group.variable = NULL, type = c("annotation","pca","h topAnnotation <- ComplexHeatmap::HeatmapAnnotation(group = sample.info[match(colnames(count.data), runname)]$groupVar) p <- ComplexHeatmap::Heatmap(corData, name = "Sp.R", col = col_fun, - top_annotation = topAnnotation) - + top_annotation = topAnnotation, show_row_names = FALSE,column_names_gp = grid::gpar(fontsize = 9)) }else{ - p <- ComplexHeatmap::Heatmap(corData, name = "Sp.R", col = col_fun) + p <- ComplexHeatmap::Heatmap(corData, name = "Sp.R", col = col_fun, show_row_names = FALSE,column_names_gp = grid::gpar(fontsize = 9)) + } return(p) diff --git a/R/prepareBam.R b/R/prepareBam.R index 5e8bc78d..72541fd4 100755 --- a/R/prepareBam.R +++ b/R/prepareBam.R @@ -2,7 +2,7 @@ #' @param bamFile bamFile #' @inheritParams bambu #' @noRd -prepareDataFromBam <- function(bamFile, yieldSize=NULL, verbose = FALSE, cores=1) { +prepareDataFromBam <- function(bamFile, yieldSize=NULL, verbose = FALSE, ncore=1) { if(class(bamFile)=='BamFile') { if(!is.null(yieldSize)) { @@ -22,7 +22,7 @@ prepareDataFromBam <- function(bamFile, yieldSize=NULL, verbose = FALSE, cores=1 } # parallel processing of single files by reading chromosomes separately - if(cores>1){ + if(ncore>1){ chr <- scanBamHeader(bamFile)[[1]] chrRanges <- GRanges(seqnames=names(chr), ranges=IRanges(start=1, end=chr)) @@ -30,7 +30,7 @@ prepareDataFromBam <- function(bamFile, yieldSize=NULL, verbose = FALSE, cores=1 helpFun, chrRanges=chrRanges, bamFile=bamFile, - mc.cores = cores) + mc.cores = ncore) } else { diff --git a/R/readWrite.R b/R/readWrite.R index 86651f66..173af0f5 100644 --- a/R/readWrite.R +++ b/R/readWrite.R @@ -1,20 +1,21 @@ #' Outputs a GTF file, transcript-count file, and gene-count file from bambu -#' @title write bambu results to GTF and transcript/gene-count files -#' @param se a summarizedExperiment object from \code{\link{bambu}} +#' @title Write bambu results to GTF and transcript/gene-count files +#' @param se a \code{\link{SummarizedExperiment}} object from \code{\link{bambu}} #' @param path the destination of the output files (gtf, transcript counts, and gene counts) -#' @return gtf a GTF dataframe +#' @return The function will generate three files, a \code{\link{.gtf}} file for the annotations, +#' two \code{\link{.txt}} files for transcript and gene counts respectively. #' @export -write.bambu <- function(se,path){ +writeBambuOutput <- function(se,path){ if (missing(se) | missing(path)){ stop('Both summarizedExperiment object from bambu and the path for the output files are required.') }else{ - outdir <- strsplit(path,"/")[[1]][1] - if (dir.exists(outdir) == FALSE){ - dir.create(outdir) + outdir <- paste0(path,"/") + if (!dir.exists(outdir)){ + dir.create(outdir, recursive = TRUE) } transcript_grList <- rowRanges(se) transcript_gtffn <- paste(path,"transcript_exon.gtf",sep="") - gtf <- write.gtf(annotation=transcript_grList,file=transcript_gtffn) + gtf <- writeToGTF(annotation=transcript_grList,file=transcript_gtffn) transcript_counts <- as.data.frame(assays(se)$counts) transcript_countsfn <- paste(path,"counts_transcript.txt",sep="") write.table(transcript_counts, file= transcript_countsfn, sep="\t",quote=FALSE) @@ -24,14 +25,14 @@ write.bambu <- function(se,path){ write.table(gene_counts, file= gene_countsfn, sep="\t", quote=FALSE) } } -#' Outputs a GTF file for the nanorna-bam nextflow pipeline +#' Write annotation GRangesList into a GTF file #' @title write GRangeslist into GTF file -#' @param annotation a GRangesList object +#' @param annotation a \code{\link{GRangesList}} object #' @param file the output gtf file name #' @param geneIDs an optional dataframe of geneIDs (column 2) with the corresponding transcriptIDs (column 1) #' @return gtf a GTF dataframe #' @export -write.gtf <- function (annotation,file,geneIDs=NULL) { +writeToGTF <- function (annotation,file,geneIDs=NULL) { if (missing(annotation) | missing(file)){ stop('Both GRangesList and the name of file are required.') }else if (class(annotation) != "CompressedGRangesList"){ @@ -63,17 +64,23 @@ write.gtf <- function (annotation,file,geneIDs=NULL) { gtf <- rbind(gtf_trns,gtf_exon) gtf <- gtf[order(gtf$attributes),] write.table(gtf, file= file, quote=FALSE, row.names=FALSE, col.names=FALSE, sep = "\t") - } +} + + #' Outputs GRangesList object from reading a GTF file #' @title convert a GTF file into a GRangesList -#' @param file a GTF file -#' @return grlist a GRangesList object +#' @param file a \code{\link{.gtf}} file +#' @return grlist a \code{\link{GRangesList}} object, with two columns +#' \itemize{ +#' \item TXNAME specifying prefix for new gene Ids (genePrefix.number), defaults to empty +#' \item GENEID indicating whether filter to remove read classes which are a subset of known transcripts(), defaults to TRUE +#' } #' @export -read.gtf <- function(file){ +readFromGTF <- function(file){ if (missing(file)){ stop('A GTF file is required.') }else{ - data=read.delim(file,header=FALSE) + data=read.delim(file,header=FALSE, comment.char='#') colnames(data) <- c("seqname","source","type","start","end","score","strand","frame","attribute") data$strand[data$strand=='.'] <- '*' data$GENEID = gsub('gene_id (.*); tra.*','\\1',data$attribute) @@ -88,37 +95,3 @@ read.gtf <- function(file){ return (grlist) } -#' Outputs GRangesList object from reading a GTF file for running bambu -#' @title convert a GTF file into a GRangesList -#' @param file a GTF file -#' @return grlist a GRangesList object -#' @export -prepareAnnotationsFromGTF_draft <- function(file){ - if (missing(file)){ - stop('A GTF file is required.') - }else{ - data <- read.delim(file,header=FALSE,comment.char='#') - colnames(data) <- c("seqname","source","type","start","end","score","strand","frame","attribute") - data <- data[data$type=='exon',] - data$strand[data$strand=='.'] <- '*' - data$GENEID = gsub('gene_id (.*?);.*','\\1',data$attribute) - data$TXNAME=gsub('.*transcript_id (.*?);.*', '\\1',data$attribute) - data$exon_rank=as.integer(gsub('.*exon_number (.*?);.*', '\\1',data$attribute)) - geneData=unique(data[,c('TXNAME', 'GENEID')]) - grlist <- makeGRangesListFromDataFrame( - data[,c('seqname', 'start','end','strand','exon_rank','TXNAME')],split.field='TXNAME',keep.extra.columns = TRUE) - - unlistedExons <- unlist(grlist, use.names = FALSE) - partitioning <- PartitioningByEnd(cumsum(elementNROWS(grlist)), names=NULL) - txIdForReorder <- togroup(PartitioningByWidth(grlist)) - unlistedExons <- unlistedExons[order(txIdForReorder, unlistedExons$exon_rank)] #'exonsByTx' is always sorted by exon rank, not by strand, make sure that this is the case here - unlistedExons$exon_endRank <- unlist(sapply(elementNROWS(grlist),seq,to=1), use.names=FALSE) - unlistedExons <- unlistedExons[order(txIdForReorder, start(unlistedExons))] -# mcols(unlistedExons) <- mcols(unlistedExons)[,c('exon_rank','exon_endRank')] - grlist <- relist(unlistedExons, partitioning) - minEqClasses <- getMinimumEqClassByTx(grlist) - mcols(grlist) <- DataFrame(geneData[(match(names(grlist), geneData$TXNAME)),]) - mcols(grlist)$eqClass <- minEqClasses$eqClass[match(names(grlist),minEqClasses$queryTxId)] - } - return (grlist) -} diff --git a/R/sysdata.rda b/R/sysdata.rda index ed5526f2..2a68a949 100755 Binary files a/R/sysdata.rda and b/R/sysdata.rda differ diff --git a/README.md b/README.md index 59bcf5bf..d872787b 100755 --- a/README.md +++ b/README.md @@ -1,5 +1,201 @@ -Bambu + + +Bambu # bambu: reference-guided transcript discovery and quantification for long read RNA-Seq data -The code is still under development. + +[![GitHub release (latest by date)](https://img.shields.io/github/v/release/GoekeLab/bambu?style=plastic)](https://github.com/GoekeLab/bambu) +[![Maintained?](https://img.shields.io/badge/Maintained%3F-Yes-brightgreen)](https://github.com/GoekeLab/bambu/graphs/contributors) +[![Install](https://img.shields.io/badge/Install-Github-brightgreen)](#installation) +[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0) + + +***bambu*** is a R package for multi-sample transcript discovery and quantification using long read RNA-Seq data. You can use ***bambu*** after read alignment to obtain expression estimates for known and novel transcripts and genes. The output from ***bambu*** can directly be used for visualisation and downstream analysis such as differential gene expression or transcript usage. + + +--- + +### Content + + - [Installation](#installation) + - [General usage](#general-usage) + - [Use precalculated annotation objects](#use-precalculated-annotation-objects) + - [Advanced options](#advanced-options) + - [Complementary functions](#complementary-functions) + - [Release History](#release-history) + - [Contributors](#contributors) + + +### Installation + +You can install ***bambu*** from github: + +```rscript +if (!requireNamespace("devtools", quietly = TRUE)) + install.packages("devtools") +devtools::install_github("GoekeLab/bambu") +``` +--- + +### 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: + + ```rscript +library(bambu) + +test.bam <- system.file("extdata", "SGNex_A549_directRNA_replicate5_run1_chr9_1_1000000.bam", package = "bambu") + + +se <- bambu(reads = test.bam, annotations = "TxDb.Hsapiens.UCSC.hg38.knownGene", genomeSequence = "BSgenome.Hsapiens.NCBI.GRCh38") + +``` + + +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: + +```rscript +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 <- prepareAnnotationsFromGTF(gtf.file) + +se <- bambu(reads = test.bam, annotations = bambuAnnotations, genomeSequence = fa.file) + +``` + + +**Quantification of annotated transcripts and genes only (no transcript/gene discovery)** + +```rscript +bambu(reads = test.bam, annotations = txdb, genomeSequence = fa.file, extendAnnotations = FALSE) +``` + +**Large sample number/ limited memory** +For larger sample numbers we recommend to write the processed data to a file: + +```rscript +bambu(reads = test.bam, readClass.outputDir = "./bambu/", annotations = bambuAnnotations, genomeSequence = fa.file) +``` +--- + + +### Use precalculated annotation objects + +You can also use precalculated annotations. + +If you plan to run ***bambu*** more frequently, we recommend to save the bambuAnnotations object. + +The bambuAnnotation object can be calculated from a *.gtf* file: + +```rscript +annotations <- prepareAnnotationFromGTF(gtf.file) +``` + +From *TxDb* object + +```rscript +annotations <- prepareAnnotations(txdb) +``` + +--- + +### Advanced Options + +**More stringent filtering thresholds imposed on potential novel transcripts** + +- Keep novel transcripts with min 5 read count in at least 1 sample: + +```rscript +bambu(reads, annotations, genomeSequence, isoreParameters = list(min.readCount = 5)) +``` + +- Keep novel transcripts with min 5 samples having at least 2 counts: + +```rscript +bambu(reads, annotations, genomeSequence, isoreParameters = list(min.sampleNumber = 5)) +``` + +- Filter out transcripts with relative abundance within gene lower than 10%: + +```rscript +bambu(reads, annotations, genomeSequence, isoreParameters = list(min.readFractionByGene = 0.1)) +``` + +**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. + +```rscript +bambu(reads, annotations, genomeSequence, emParameters = list(bias = FALSE)) +``` + +**Parallel computation** + ***bambu*** allows parallel computation. + +```rscript +bambu(reads, annotations, genomeSequence, ncore = 8) +``` + +See [manual](docs/bambu_0.1.0.pdf) for details to customize other conditions. + +--- + +### Complementary functions + +**Transcript expression to gene expression** + +```rscript +transcriptToGeneExpression(se) +``` + +**Visualization** + + You can visualize the novel genes/transcripts using ***plot.bambu*** function + +```rscript +plot.bambu(se, type = "annotation", gene_id) + +plot.bambu(se, type = "annotation", transcript_id) +``` + +- ***plot.bambu*** can also be used to visualize the clustering of input samples on gene/transcript expressions + +```rscript +plot.bambu(se, type = "heatmap") # heatmap + +plot.bambu(se, type = "pca") # PCA visualization +``` + +- ***plot.bambu*** can also be used to visualize the clustering of input samples on gene/transcript expressions with grouping variable + +```rscript +plot.bambu(se, type = "heatmap", group.var) # heatmap + +plot.bambu(se, type = "pca", group.var) # PCA visualization +``` + +**Write bambu outputs to files** + +- ***writeBambuOutput*** will generate three files, including a *.gtf* file for the extended annotations, and two *.txt* files for the expression counts at transcript and gene levels. + +```rscript +writeBambuOutput(se, path = "./bambu/") +``` +--- + +### Release History + +**bambu version 0.1.0** + +Release date: 29th May 2020 + +### Contributors + +This package is developed and maintained by [Ying Chen](https://github.com/cying111), [Yuk Kei Wan](https://github.com/yuukiiwa), and [Jonathan Goeke](https://github.com/jonathangoeke) at the Genome Institute of Singapore. If you want to contribute, please leave an issue. Thank you. + +Bambu diff --git a/data-raw/DATASET.R b/data-raw/DATASET.R index 4b168235..8fa19830 100755 --- a/data-raw/DATASET.R +++ b/data-raw/DATASET.R @@ -30,11 +30,11 @@ data5 <- data.frame(tx_id = c(1:6,2,3,1,2,5,1,2,3,5,1:5), estOutput_woBC <- lapply(1:5, function(s){ - est <- bambu.quantDT(dt = get(paste0("data",s)), algo.control=list(bias_correction = FALSE,ncore = 1)) + est <- bambu.quantDT(readClassDt = get(paste0("data",s)), emParameters=list(bias = FALSE)) }) estOutput_wBC <- lapply(1:5, function(s){ - est <- bambu.quantDT(dt = get(paste0("data",s)), algo.control=list(ncore = 1)) + est <- bambu.quantDT(readClassDt = get(paste0("data",s))) }) diff --git a/docs/404.html b/docs/404.html new file mode 100644 index 00000000..282f3cbb --- /dev/null +++ b/docs/404.html @@ -0,0 +1,148 @@ + + + + + + + + +Page not found (404) • bambu + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + +
+ +
+
+ + +Content not found. Please use links in the navbar. + +
+ + + +
+ + + + +
+ + + + + + + + diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html new file mode 100644 index 00000000..37073b6f --- /dev/null +++ b/docs/LICENSE-text.html @@ -0,0 +1,822 @@ + + + + + + + + +License • bambu + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + +
+ +
+
+ + +
                    GNU GENERAL PUBLIC LICENSE
+                       Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+                            Preamble
+
+  The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+  The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works.  By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users.  We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors.  You can apply it to
+your programs, too.
+
+  When we speak of free software, we are referring to freedom, not
+price.  Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+  To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights.  Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
+
+  For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received.  You must make sure that they, too, receive
+or can get the source code.  And you must show them these terms so they
+know their rights.
+
+  Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+  For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software.  For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+  Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so.  This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software.  The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable.  Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products.  If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+  Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary.  To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.
+
+                       TERMS AND CONDITIONS
+
+  0. Definitions.
+
+  "This License" refers to version 3 of the GNU General Public License.
+
+  "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+  "The Program" refers to any copyrightable work licensed under this
+License.  Each licensee is addressed as "you".  "Licensees" and
+"recipients" may be individuals or organizations.
+
+  To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy.  The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+  A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+  To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy.  Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+  To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies.  Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+  An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License.  If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+  1. Source Code.
+
+  The "source code" for a work means the preferred form of the work
+for making modifications to it.  "Object code" means any non-source
+form of a work.
+
+  A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+  The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form.  A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+  The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities.  However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work.  For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+  The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+  The Corresponding Source for a work in source code form is that
+same work.
+
+  2. Basic Permissions.
+
+  All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met.  This License explicitly affirms your unlimited
+permission to run the unmodified Program.  The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work.  This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+  You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force.  You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright.  Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+  Conveying under any other circumstances is permitted solely under
+the conditions stated below.  Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+  3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+  No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+  When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+  4. Conveying Verbatim Copies.
+
+  You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+  You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+  5. Conveying Modified Source Versions.
+
+  You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+    a) The work must carry prominent notices stating that you modified
+    it, and giving a relevant date.
+
+    b) The work must carry prominent notices stating that it is
+    released under this License and any conditions added under section
+    7.  This requirement modifies the requirement in section 4 to
+    "keep intact all notices".
+
+    c) You must license the entire work, as a whole, under this
+    License to anyone who comes into possession of a copy.  This
+    License will therefore apply, along with any applicable section 7
+    additional terms, to the whole of the work, and all its parts,
+    regardless of how they are packaged.  This License gives no
+    permission to license the work in any other way, but it does not
+    invalidate such permission if you have separately received it.
+
+    d) If the work has interactive user interfaces, each must display
+    Appropriate Legal Notices; however, if the Program has interactive
+    interfaces that do not display Appropriate Legal Notices, your
+    work need not make them do so.
+
+  A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit.  Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+  6. Conveying Non-Source Forms.
+
+  You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+    a) Convey the object code in, or embodied in, a physical product
+    (including a physical distribution medium), accompanied by the
+    Corresponding Source fixed on a durable physical medium
+    customarily used for software interchange.
+
+    b) Convey the object code in, or embodied in, a physical product
+    (including a physical distribution medium), accompanied by a
+    written offer, valid for at least three years and valid for as
+    long as you offer spare parts or customer support for that product
+    model, to give anyone who possesses the object code either (1) a
+    copy of the Corresponding Source for all the software in the
+    product that is covered by this License, on a durable physical
+    medium customarily used for software interchange, for a price no
+    more than your reasonable cost of physically performing this
+    conveying of source, or (2) access to copy the
+    Corresponding Source from a network server at no charge.
+
+    c) Convey individual copies of the object code with a copy of the
+    written offer to provide the Corresponding Source.  This
+    alternative is allowed only occasionally and noncommercially, and
+    only if you received the object code with such an offer, in accord
+    with subsection 6b.
+
+    d) Convey the object code by offering access from a designated
+    place (gratis or for a charge), and offer equivalent access to the
+    Corresponding Source in the same way through the same place at no
+    further charge.  You need not require recipients to copy the
+    Corresponding Source along with the object code.  If the place to
+    copy the object code is a network server, the Corresponding Source
+    may be on a different server (operated by you or a third party)
+    that supports equivalent copying facilities, provided you maintain
+    clear directions next to the object code saying where to find the
+    Corresponding Source.  Regardless of what server hosts the
+    Corresponding Source, you remain obligated to ensure that it is
+    available for as long as needed to satisfy these requirements.
+
+    e) Convey the object code using peer-to-peer transmission, provided
+    you inform other peers where the object code and Corresponding
+    Source of the work are being offered to the general public at no
+    charge under subsection 6d.
+
+  A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+  A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling.  In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage.  For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product.  A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+  "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source.  The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+  If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information.  But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+  The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed.  Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+  Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+  7. Additional Terms.
+
+  "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law.  If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+  When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it.  (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.)  You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+  Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+    a) Disclaiming warranty or limiting liability differently from the
+    terms of sections 15 and 16 of this License; or
+
+    b) Requiring preservation of specified reasonable legal notices or
+    author attributions in that material or in the Appropriate Legal
+    Notices displayed by works containing it; or
+
+    c) Prohibiting misrepresentation of the origin of that material, or
+    requiring that modified versions of such material be marked in
+    reasonable ways as different from the original version; or
+
+    d) Limiting the use for publicity purposes of names of licensors or
+    authors of the material; or
+
+    e) Declining to grant rights under trademark law for use of some
+    trade names, trademarks, or service marks; or
+
+    f) Requiring indemnification of licensors and authors of that
+    material by anyone who conveys the material (or modified versions of
+    it) with contractual assumptions of liability to the recipient, for
+    any liability that these contractual assumptions directly impose on
+    those licensors and authors.
+
+  All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10.  If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term.  If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+  If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+  Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+  8. Termination.
+
+  You may not propagate or modify a covered work except as expressly
+provided under this License.  Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+  However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+  Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+  Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License.  If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+  9. Acceptance Not Required for Having Copies.
+
+  You are not required to accept this License in order to receive or
+run a copy of the Program.  Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance.  However,
+nothing other than this License grants you permission to propagate or
+modify any covered work.  These actions infringe copyright if you do
+not accept this License.  Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+  10. Automatic Licensing of Downstream Recipients.
+
+  Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License.  You are not responsible
+for enforcing compliance by third parties with this License.
+
+  An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations.  If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+  You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License.  For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+  11. Patents.
+
+  A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based.  The
+work thus licensed is called the contributor's "contributor version".
+
+  A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version.  For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+  Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+  In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement).  To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+  If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients.  "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+  If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+  A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License.  You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+  Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+  12. No Surrender of Others' Freedom.
+
+  If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all.  For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+  13. Use with the GNU Affero General Public License.
+
+  Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work.  The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
+
+  14. Revised Versions of this License.
+
+  The Free Software Foundation may publish revised and/or new versions of
+the GNU General Public License from time to time.  Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+  Each version is given a distinguishing version number.  If the
+Program specifies that a certain numbered version of the GNU General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation.  If the Program does not specify a version number of the
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+  If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+  Later license versions may give you additional or different
+permissions.  However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+  15. Disclaimer of Warranty.
+
+  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+  16. Limitation of Liability.
+
+  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+  17. Interpretation of Sections 15 and 16.
+
+  If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+                     END OF TERMS AND CONDITIONS
+
+            How to Apply These Terms to Your New Programs
+
+  If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+  To do so, attach the following notices to the program.  It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+    <one line to give the program's name and a brief idea of what it does.>
+    Copyright (C) <year>  <name of author>
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+Also add information on how to contact you by electronic and paper mail.
+
+  If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
+
+    <program>  Copyright (C) <year>  <name of author>
+    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+    This is free software, and you are welcome to redistribute it
+    under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License.  Of course, your program's commands
+might be different; for a GUI interface, you would use an "about box".
+
+  You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU GPL, see
+<https://www.gnu.org/licenses/>.
+
+  The GNU General Public License does not permit incorporating your program
+into proprietary programs.  If your program is a subroutine library, you
+may consider it more useful to permit linking proprietary applications with
+the library.  If this is what you want to do, use the GNU Lesser General
+Public License instead of this License.  But first, please read
+<https://www.gnu.org/licenses/why-not-lgpl.html>.
+
+ +
+ + + +
+ + + + +
+ + + + + + + + diff --git a/docs/articles/bambu.html b/docs/articles/bambu.html new file mode 100644 index 00000000..7930456d --- /dev/null +++ b/docs/articles/bambu.html @@ -0,0 +1,702 @@ + + + + + + + +bambu • bambu + + + + + + + + + + +
+
+ + + + +
+
+ + + + +
+

+Introduction

+

Bambu can be used for transcript discovery and quantification from long read RNA-Seq data. Here, we present an example usage of bambu on Nanopore long read RNA-Sequencing from 2 human cancer cell lines

+
+
+

+Data description

+

To demonstrate the usage of Bambu, we used the data in NanoporeRNASeq, which contains single chromosome RNA-Seq data from two common cell lines K562 and MCF7. Each of these cell line has three replicates, with 1 direct RNA sequencing data and 2 cDNA sequencing data.

+
library(NanoporeRNASeq)
+library(bambu)
+
data("sample_info")
+sample_info
+##>                                sample_id Platform cellLine   protocol
+##> 1: SGNex_K562_directcDNA_replicate1_run2   MinION     K562 directcDNA
+##> 2: SGNex_K562_directcDNA_replicate4_run2  GridION     K562 directcDNA
+##> 3:  SGNex_K562_directRNA_replicate6_run1  GridION     K562  directRNA
+##> 4: SGNex_MCF7_directcDNA_replicate1_run2   MinION     MCF7 directcDNA
+##> 5: SGNex_MCF7_directcDNA_replicate3_run3  GridION     MCF7 directcDNA
+##> 6:  SGNex_MCF7_directRNA_replicate4_run1  GridION     MCF7  directRNA
+##>        bioRep cancer_type
+##> 1: replicate1   Leukocyte
+##> 2: replicate4   Leukocyte
+##> 3: replicate6   Leukocyte
+##> 4: replicate1      Breast
+##> 5: replicate3      Breast
+##> 6: replicate4      Breast
+

Name of bamfiles can be loaded as follows

+
data("bamFileNames")
+bamFileNames
+##> [1] "SGNex_K562_directcDNA_replicate1_run2_genome_chr22_1_25409234.bam"
+##> [2] "SGNex_K562_directcDNA_replicate4_run2_genome_chr22_1_25409234.bam"
+##> [3] "SGNex_K562_directRNA_replicate6_run1_genome_chr22_1_25409234.bam" 
+##> [4] "SGNex_MCF7_directcDNA_replicate1_run2_genome_chr22_1_25409234.bam"
+##> [5] "SGNex_MCF7_directcDNA_replicate3_run3_genome_chr22_1_25409234.bam"
+##> [6] "SGNex_MCF7_directRNA_replicate4_run1_genome_chr22_1_25409234.bam"
+

We then loaded bam.files.

+
bam.file <- system.file("extdata",bamFileNames, package = "NanoporeRNASeq")
+data("annotationGrangesList_chr22_1_25409234")
+

We applied bambu to perform EM on extended annotations

+
seExtended <- bambu(reads = bam.file, annotations = annotationGrangesList_chr22_1_25409234, genomeSequence = "BSgenome.Hsapiens.NCBI.GRCh38", extendAnnotations = TRUE, verbose = FALSE, ncore = 6)
+##> 
+  |                                                                            
+  |                                                                      |   0%
+  |                                                                            
+  |                                                                      |   0%
+  |                                                                            
+  |======================================================================| 100%
+##> 
+##> 
+  |                                                                            
+  |                                                                      |   0%
+  |                                                                            
+  |======================================================================| 100%
+##> 
+##> 
+  |                                                                            
+  |============                                                          |  17%
+  |                                                                            
+  |                                                                      |   0%
+  |                                                                            
+  |======================================================================| 100%
+##> 
+##> 
+  |                                                                            
+  |                                                                      |   0%
+  |                                                                            
+  |======================================================================| 100%
+##> 
+##> 
+  |                                                                            
+  |=======================                                               |  33%
+  |                                                                            
+  |                                                                      |   0%
+  |                                                                            
+  |======================================================================| 100%
+##> 
+##> 
+  |                                                                            
+  |                                                                      |   0%
+  |                                                                            
+  |======================================================================| 100%
+##> 
+##> 
+  |                                                                            
+  |===================================                                   |  50%
+  |                                                                            
+  |                                                                      |   0%
+  |                                                                            
+  |======================================================================| 100%
+##> 
+##> 
+  |                                                                            
+  |                                                                      |   0%
+  |                                                                            
+  |======================================================================| 100%
+##> 
+##> 
+  |                                                                            
+  |===============================================                       |  67%
+  |                                                                            
+  |                                                                      |   0%
+  |                                                                            
+  |======================================================================| 100%
+##> 
+##> 
+  |                                                                            
+  |                                                                      |   0%
+  |                                                                            
+  |======================================================================| 100%
+##> 
+##> 
+  |                                                                            
+  |==========================================================            |  83%
+  |                                                                            
+  |                                                                      |   0%
+  |                                                                            
+  |======================================================================| 100%
+##> 
+##> 
+  |                                                                            
+  |                                                                      |   0%
+  |                                                                            
+  |======================================================================| 100%
+##> 
+##> 
+  |                                                                            
+  |======================================================================| 100%
+##> 
+##> 
+  |                                                                            
+  |                                                                      |   0%
+  |                                                                            
+  |============                                                          |  17%
+  |                                                                            
+  |=======================                                               |  33%
+  |                                                                            
+  |===================================                                   |  50%
+  |                                                                            
+  |===============================================                       |  67%
+  |                                                                            
+  |==========================================================            |  83%
+  |                                                                            
+  |======================================================================| 100%
+seExtended
+##> class: RangedSummarizedExperiment 
+##> dim: 1923 6 
+##> metadata(0):
+##> assays(2): counts CPM
+##> rownames(1923): tx.1 tx.2 ... ENST00000484509 ENST00000468442
+##> rowData names(4): TXNAME GENEID eqClass newTxClass
+##> colnames(6):
+##>   SGNex_K562_directcDNA_replicate1_run2_genome_chr22_1_25409234
+##>   SGNex_K562_directcDNA_replicate4_run2_genome_chr22_1_25409234 ...
+##>   SGNex_MCF7_directcDNA_replicate3_run3_genome_chr22_1_25409234
+##>   SGNex_MCF7_directRNA_replicate4_run1_genome_chr22_1_25409234
+##> colData names(1): name
+

bambu allows quantification without isoform discovery

+
se <- bambu(reads = bam.file, annotations = annotationGrangesList_chr22_1_25409234, genomeSequence = "BSgenome.Hsapiens.NCBI.GRCh38", extendAnnotations = FALSE, verbose = FALSE, ncore = 6)
+##> 
+  |                                                                            
+  |                                                                      |   0%
+  |                                                                            
+  |                                                                      |   0%
+  |                                                                            
+  |======================================================================| 100%
+##> 
+##> 
+  |                                                                            
+  |                                                                      |   0%
+  |                                                                            
+  |======================================================================| 100%
+##> 
+##> 
+  |                                                                            
+  |============                                                          |  17%
+  |                                                                            
+  |                                                                      |   0%
+  |                                                                            
+  |======================================================================| 100%
+##> 
+##> 
+  |                                                                            
+  |                                                                      |   0%
+  |                                                                            
+  |======================================================================| 100%
+##> 
+##> 
+  |                                                                            
+  |=======================                                               |  33%
+  |                                                                            
+  |                                                                      |   0%
+  |                                                                            
+  |======================================================================| 100%
+##> 
+##> 
+  |                                                                            
+  |                                                                      |   0%
+  |                                                                            
+  |======================================================================| 100%
+##> 
+##> 
+  |                                                                            
+  |===================================                                   |  50%
+  |                                                                            
+  |                                                                      |   0%
+  |                                                                            
+  |======================================================================| 100%
+##> 
+##> 
+  |                                                                            
+  |                                                                      |   0%
+  |                                                                            
+  |======================================================================| 100%
+##> 
+##> 
+  |                                                                            
+  |===============================================                       |  67%
+  |                                                                            
+  |                                                                      |   0%
+  |                                                                            
+  |======================================================================| 100%
+##> 
+##> 
+  |                                                                            
+  |                                                                      |   0%
+  |                                                                            
+  |======================================================================| 100%
+##> 
+##> 
+  |                                                                            
+  |==========================================================            |  83%
+  |                                                                            
+  |                                                                      |   0%
+  |                                                                            
+  |======================================================================| 100%
+##> 
+##> 
+  |                                                                            
+  |                                                                      |   0%
+  |                                                                            
+  |======================================================================| 100%
+##> 
+##> 
+  |                                                                            
+  |======================================================================| 100%
+##> 
+##> 
+  |                                                                            
+  |                                                                      |   0%
+  |                                                                            
+  |============                                                          |  17%
+  |                                                                            
+  |=======================                                               |  33%
+  |                                                                            
+  |===================================                                   |  50%
+  |                                                                            
+  |===============================================                       |  67%
+  |                                                                            
+  |==========================================================            |  83%
+  |                                                                            
+  |======================================================================| 100%
+se
+##> class: RangedSummarizedExperiment 
+##> dim: 1500 6 
+##> metadata(0):
+##> assays(2): counts CPM
+##> rownames(1500): ENST00000624155 ENST00000422332 ... ENST00000484509
+##>   ENST00000468442
+##> rowData names(3): TXNAME GENEID eqClass
+##> colnames(6):
+##>   SGNex_K562_directcDNA_replicate1_run2_genome_chr22_1_25409234
+##>   SGNex_K562_directcDNA_replicate4_run2_genome_chr22_1_25409234 ...
+##>   SGNex_MCF7_directcDNA_replicate3_run3_genome_chr22_1_25409234
+##>   SGNex_MCF7_directRNA_replicate4_run1_genome_chr22_1_25409234
+##> colData names(1): name
+
+
+

+Check expression estimates

+

We can check the estimated transcript expression using heatmap:

+
colData(seExtended)$groupVar <-  unlist(lapply(colnames(seExtended),function(x) unlist(strsplit(x,"_"))[2]))
+colnames(seExtended) <- gsub("_genome_chr22_1_25409234","",colnames(seExtended))
+colData(seExtended)$name <- gsub("_genome_chr22_1_25409234","",colData(seExtended)$name)
+plot.bambu(seExtended, group.variable = "groupVar", type = "heatmap")
+

+

or with PCA plot

+
colData(seExtended)$groupVar <-  unlist(lapply(colnames(seExtended),function(x) unlist(strsplit(x,"_"))[2]))
+plot.bambu(seExtended, group.variable = "groupVar", type = "pca")
+

+
+

+Check for gene examples

+

Single gene examples can also be checked using plot functions from bambu

+
plot.bambu(seExtended, type = "annotation", gene_id = unique(rowData(seExtended)$GENEID)[10])
+

+
##> [[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.210]
+
+
+

+Transcript to Gene expression

+

Gene expression can be obtained from transcript expression using this function:

+
seGene <- transcriptToGeneExpression(seExtended)
+seGene
+##> class: RangedSummarizedExperiment 
+##> dim: 887 6 
+##> metadata(0):
+##> assays(2): counts CPM
+##> rownames(887): ENSG00000015475 ENSG00000040608 ... gene.98 gene.99
+##> rowData names(2): GENEID newGeneClass
+##> colnames(6): SGNex_K562_directcDNA_replicate1_run2
+##>   SGNex_K562_directcDNA_replicate4_run2 ...
+##>   SGNex_MCF7_directcDNA_replicate3_run3
+##>   SGNex_MCF7_directRNA_replicate4_run1
+##> colData names(2): name groupVar
+

Gene expression heatmap

+
colData(seGene)$groupVar <-  unlist(lapply(colnames(seGene),function(x) unlist(strsplit(x,"_"))[2]))
+plot.bambu(seGene, group.variable = "groupVar", type = "heatmap")
+

+

Gene expression PCA plot

+
colData(seGene)$groupVar <-  unlist(lapply(colnames(seGene),function(x) unlist(strsplit(x,"_"))[2]))
+plot.bambu(seGene, group.variable = "groupVar", type = "pca")
+

+
+
+
+

+Differentially expressed genes

+

We used DESeq2 to find the differentially expressed genes:

+
library(DESeq2)
+dds <- DESeqDataSetFromMatrix(apply(assays(seGene)$counts,c(1,2),round),#tmp_wide[,-1],
+                                   colData = colData(seExtended),
+                                   design = ~ groupVar)
+system.time(dds.deseq <- DESeq(dds))
+##>    user  system elapsed 
+##>   1.996   0.028   2.025
+
+deGeneRes <- DESeq2::results(dds.deseq, independentFiltering=FALSE)
+
head(deGeneRes[order(deGeneRes$padj),])
+##> log2 fold change (MLE): groupVar MCF7 vs K562 
+##> Wald test p-value: groupVar MCF7 vs K562 
+##> DataFrame with 6 rows and 6 columns
+##>                  baseMean log2FoldChange     lfcSE      stat
+##>                 <numeric>      <numeric> <numeric> <numeric>
+##> ENSG00000185686  513.5554       -7.22327  0.498140 -14.50048
+##> ENSG00000197077   26.2357        9.09835  1.326114   6.86091
+##> ENSG00000283633   88.7407       -9.03039  1.431724  -6.30736
+##> ENSG00000099977  232.6720        1.85141  0.306629   6.03795
+##> ENSG00000169635   44.4275       -3.44047  0.579080  -5.94127
+##> ENSG00000100181   38.3698       -5.07047  0.892940  -5.67840
+##>                                                                 pvalue
+##>                                                              <numeric>
+##> ENSG00000185686 0.0000000000000000000000000000000000000000000000120303
+##> ENSG00000197077 0.0000000000068425448545783570607904382313656081217312
+##> ENSG00000283633 0.0000000002838407468976333203669654163178986266968806
+##> ENSG00000099977 0.0000000015607995974142258612474572408387353539271913
+##> ENSG00000169635 0.0000000028282083250919303521398367383355917925591427
+##> ENSG00000100181 0.0000000135958879211409468852046023923732520621854292
+##>                                                                 padj
+##>                                                            <numeric>
+##> ENSG00000185686 0.00000000000000000000000000000000000000000000714599
+##> ENSG00000197077 0.00000000203223582180977191457661517551974705853013
+##> ENSG00000283633 0.00000005620046788573139474432216163360398475390411
+##> ENSG00000099977 0.00000023177874021601254939083656177872816428475744
+##> ENSG00000169635 0.00000033599114902092130879429198592189820260500710
+##> ENSG00000100181 0.00000134599290419295367876952908281484866392929689
+
summary(deGeneRes)
+##> 
+##> out of 594 with nonzero total read count
+##> adjusted p-value < 0.1
+##> LFC > 0 (up)       : 16, 2.7%
+##> LFC < 0 (down)     : 20, 3.4%
+##> outliers [1]       : 0, 0%
+##> low counts [2]     : 0, 0%
+##> (mean count < 0)
+##> [1] see 'cooksCutoff' argument of ?results
+##> [2] see 'independentFiltering' argument of ?results
+
plotMA(deGeneRes, ylim = c(-3,3))
+

+

Plotting shrinked lFC results

+
resLFC <- lfcShrink(dds.deseq, coef="groupVar_MCF7_vs_K562", type="apeglm")
+plotMA(resLFC, ylim = c(-3,3))
+

+
+
+

+Differential expression for isoform detection

+

We used DEXSeq to detect alternative used isoforms.

+
library(DRIMSeq)
+count.data <- as.data.frame(rowData(seExtended))
+count.data$gene_id <- count.data$GENEID
+count.data$feature_id <- count.data$TXNAME
+count.data$GENEID <- count.data$TXNAME <- NULL
+
+count.data <- cbind(count.data, assays(seExtended)$counts)
+
+sample.info <- as.data.frame(colData(seExtended))
+sample.info$sample_id <- sample.info$name
+sample.info$name <- NULL
+d <- dmDSdata(counts=count.data, samples=sample.info)
+
+n_samp_gene <- 1
+n_samp_feature <- 1
+min_count_gene <- 1
+min_count_feature <- 1
+dFilter <- dmFilter(d,
+              min_samps_feature_expr = n_samp_feature,
+              min_samps_feature_prop = n_samp_feature,
+              min_samps_gene_expr = n_samp_gene,
+              min_feature_expr = min_count_feature,
+              min_gene_expr = min_count_gene,
+              min_feature_prop=0.1)
+table(table(counts(dFilter)$gene_id)) ## number of isoforms 
+##> 
+##>  2  3  4  5  6  7  8 10 
+##> 23 15 21 12  8  6  4  1
+
library(DEXSeq)
+formulaFullModel <- as.formula("~sample + exon + groupVar:exon")
+
+
+dxd <- DEXSeqDataSet(countData=round(as.matrix(counts(dFilter)[,-c(1:2)])),
+                     sampleData=DRIMSeq::samples(dFilter),
+                     design=formulaFullModel,
+                     featureID = counts(dFilter)$feature_id,
+                     groupID=counts(dFilter)$gene_id)
+
+
+system.time({
+  dxd <- estimateSizeFactors(dxd)
+  print('Size factor estimated')
+  dxd <- estimateDispersions(dxd, formula = formulaFullModel)
+  print('Dispersion estimated')
+  #dxd <- estimateExonFoldChanges( dxd )
+  dxd <- testForDEU(dxd, fullModel = formulaFullModel)
+  print('DEU tested')
+  dxd <- estimateExonFoldChanges(dxd, fitExpToVar="groupVar")
+  print('Exon fold changes estimated')
+})
+##> [1] "Size factor estimated"
+##> [1] "Dispersion estimated"
+##> [1] "DEU tested"
+##> [1] "Exon fold changes estimated"
+##>    user  system elapsed 
+##>   7.860   0.040   7.903
+
dxr <- DEXSeqResults(dxd, independentFiltering=FALSE)
+head(dxr)
+##> 
+##> LRT p-value: full vs reduced
+##> 
+##> DataFrame with 6 rows and 12 columns
+##>                   groupID   featureID exonBaseMean dispersion      stat
+##>               <character> <character>    <numeric>  <numeric> <numeric>
+##> gene.2:tx.2        gene.2        tx.2     2.714822   0.427670  3.150551
+##> gene.2:tx.3        gene.2        tx.3     0.654029   0.791030  0.140914
+##> gene.2:tx.4        gene.2        tx.4     2.567833   0.315359  1.003001
+##> gene.2:tx.66       gene.2       tx.66     2.107202   0.332461  0.422016
+##> gene.2:tx.67       gene.2       tx.67     1.243100   1.748445  1.683733
+##> gene.2:tx.122      gene.2      tx.122     1.865452   0.467004  1.043483
+##>                  pvalue      padj      K562      MCF7 log2fold_MCF7_K562
+##>               <numeric> <numeric> <numeric> <numeric>          <numeric>
+##> gene.2:tx.2   0.0759013   0.99485   2.14944 0.0448427         -11.620740
+##> gene.2:tx.3   0.7073738   1.00000   1.15465 0.0448419          -9.506951
+##> gene.2:tx.4   0.3165853   1.00000   2.03209 1.1710398          -1.860342
+##> gene.2:tx.66  0.5159328   1.00000   1.58048 1.8911532           0.622989
+##> gene.2:tx.67  0.1944292   1.00000   1.05916 1.7073365           1.554900
+##> gene.2:tx.122 0.3070128   1.00000   1.44728 1.8878239           0.910422
+##>                 genomicData   countData
+##>               <GRangesList>    <matrix>
+##> gene.2:tx.2                 18:13:3:...
+##> gene.2:tx.3                   2:3:2:...
+##> gene.2:tx.4                 10:15:3:...
+##> gene.2:tx.66                  7:5:3:...
+##> gene.2:tx.67                  0:6:0:...
+##> gene.2:tx.122                 2:9:1:...
+
library(stageR)
+strp <- function(x) substr(x,1,15)
+qval <- perGeneQValue(dxr)
+dxr.g <- data.frame(gene=names(qval),qval)
+
+columns <- c("featureID","groupID","pvalue")
+dxr_pval <- as.data.frame(dxr[,columns])
+head(dxr_pval)
+##>               featureID groupID     pvalue
+##> gene.2:tx.2        tx.2  gene.2 0.07590133
+##> gene.2:tx.3        tx.3  gene.2 0.70737384
+##> gene.2:tx.4        tx.4  gene.2 0.31658535
+##> gene.2:tx.66      tx.66  gene.2 0.51593283
+##> gene.2:tx.67      tx.67  gene.2 0.19442922
+##> gene.2:tx.122    tx.122  gene.2 0.30701285
+
+pConfirmation <- matrix(dxr_pval$pvalue,ncol=1)
+dimnames(pConfirmation) <- list(strp(dxr_pval$featureID),"transcript")
+pScreen <- qval
+names(pScreen) <- strp(names(pScreen))
+tx2gene <- as.data.frame(dxr_pval[,c("featureID", "groupID")])
+for (i in 1:2) tx2gene[,i] <- strp(tx2gene[,i])
+
+
+stageRObj <- stageRTx(pScreen=pScreen, pConfirmation=pConfirmation,
+                      pScreenAdjusted=TRUE, tx2gene=tx2gene)
+stageRObj <- stageWiseAdjustment(stageRObj, method="dtu", alpha=0.5)
+suppressWarnings({
+  dex.padj <- getAdjustedPValues(stageRObj, order=FALSE,
+                                 onlySignificantGenes=TRUE)
+})
+
dxrDT <- data.table(as.data.frame(dxr))
+setnames(dxrDT, old = c('groupID','featureID'), new = c('geneID','txID'))
+dex.padj <- data.table(dex.padj)
+
+dxrDT <- dex.padj[dxrDT, on = c('geneID','txID')]
+head(dxrDT)
+##>    geneID   txID gene transcript exonBaseMean dispersion      stat     pvalue
+##> 1: gene.2   tx.2   NA         NA    2.7148218  0.4276702 3.1505509 0.07590133
+##> 2: gene.2   tx.3   NA         NA    0.6540286  0.7910296 0.1409142 0.70737384
+##> 3: gene.2   tx.4   NA         NA    2.5678325  0.3153589 1.0030014 0.31658535
+##> 4: gene.2  tx.66   NA         NA    2.1072015  0.3324607 0.4220160 0.51593283
+##> 5: gene.2  tx.67   NA         NA    1.2431000  1.7484453 1.6837326 0.19442922
+##> 6: gene.2 tx.122   NA         NA    1.8654524  0.4670041 1.0434828 0.30701285
+##>         padj     K562       MCF7 log2fold_MCF7_K562 genomicData
+##> 1: 0.9948496 2.149443 0.04484265        -11.6207395   <GRanges>
+##> 2: 1.0000000 1.154654 0.04484192         -9.5069512   <GRanges>
+##> 3: 1.0000000 2.032089 1.17103980         -1.8603417   <GRanges>
+##> 4: 1.0000000 1.580476 1.89115320          0.6229887   <GRanges>
+##> 5: 1.0000000 1.059156 1.70733655          1.5549004   <GRanges>
+##> 6: 1.0000000 1.447282 1.88782389          0.9104218   <GRanges>
+##>    countData.SGNex_K562_directcDNA_replicate1_run2
+##> 1:                                              18
+##> 2:                                               2
+##> 3:                                              10
+##> 4:                                               7
+##> 5:                                               0
+##> 6:                                               2
+##>    countData.SGNex_K562_directcDNA_replicate4_run2
+##> 1:                                              13
+##> 2:                                               3
+##> 3:                                              15
+##> 4:                                               5
+##> 5:                                               6
+##> 6:                                               9
+##>    countData.SGNex_K562_directRNA_replicate6_run1
+##> 1:                                              3
+##> 2:                                              2
+##> 3:                                              3
+##> 4:                                              3
+##> 5:                                              0
+##> 6:                                              1
+##>    countData.SGNex_MCF7_directcDNA_replicate1_run2
+##> 1:                                               0
+##> 2:                                               0
+##> 3:                                               0
+##> 4:                                               1
+##> 5:                                               1
+##> 6:                                               1
+##>    countData.SGNex_MCF7_directcDNA_replicate3_run3
+##> 1:                                               0
+##> 2:                                               0
+##> 3:                                               1
+##> 4:                                               2
+##> 5:                                               0
+##> 6:                                               2
+##>    countData.SGNex_MCF7_directRNA_replicate4_run1
+##> 1:                                              0
+##> 2:                                              0
+##> 3:                                              0
+##> 4:                                              0
+##> 5:                                              1
+##> 6:                                              0
+
dxrDT[,sigLFC2:=(padj < 0.5&(abs(log2fold_MCF7_K562)>=2))]
+ggplot(dxrDT, aes(y = log2fold_MCF7_K562, x = exonBaseMean, color = as.factor(padj<0.5)))+
+  geom_point(size = 0.5)+
+     scale_x_log10()+
+  scale_color_manual(values = c('grey','indianred'), name = "Significant")+
+     xlab("Mean of normalized counts")+
+    ylab("Log2 Fold change")+
+  theme_minimal()
+

+
dxrDT[padj<0.5,.(geneID, txID, log2fold_MCF7_K562,K562,MCF7)]
+##>             geneID            txID log2fold_MCF7_K562      K562     MCF7
+##> 1: ENSG00000183597           tx.35          -2.925745 4.2504114 2.284457
+##> 2: ENSG00000184436           tx.44          -4.132398 3.3428343 1.103626
+##> 3: ENSG00000272779          tx.105           4.276779 0.6241729 2.320295
+##> 4: ENSG00000100030 ENST00000215832           1.112208 5.7031758 6.535581
+##> 5: ENSG00000100030 ENST00000398822          -1.438071 4.0021766 3.004256
+##> 6: ENSG00000169635 ENST00000407464           2.362562 1.9298346 3.404064
+##> 7: ENSG00000169635 ENST00000443632          -1.904184 4.0971165 2.785404
+##> 8: ENSG00000215012 ENST00000407472          -1.753270 3.6246114 2.462383
+
+
+ + + +
+ + + + +
+ + + + + + diff --git a/docs/articles/bambu_files/figure-html/unnamed-chunk-10-1.png b/docs/articles/bambu_files/figure-html/unnamed-chunk-10-1.png new file mode 100644 index 00000000..a6bc24c4 Binary files /dev/null and b/docs/articles/bambu_files/figure-html/unnamed-chunk-10-1.png differ diff --git a/docs/articles/bambu_files/figure-html/unnamed-chunk-11-1.png b/docs/articles/bambu_files/figure-html/unnamed-chunk-11-1.png new file mode 100644 index 00000000..0e1a832e Binary files /dev/null and b/docs/articles/bambu_files/figure-html/unnamed-chunk-11-1.png differ diff --git a/docs/articles/bambu_files/figure-html/unnamed-chunk-12-1.png b/docs/articles/bambu_files/figure-html/unnamed-chunk-12-1.png new file mode 100644 index 00000000..9fa54445 Binary files /dev/null and b/docs/articles/bambu_files/figure-html/unnamed-chunk-12-1.png differ diff --git a/docs/articles/bambu_files/figure-html/unnamed-chunk-13-1.png b/docs/articles/bambu_files/figure-html/unnamed-chunk-13-1.png new file mode 100644 index 00000000..82f4585a Binary files /dev/null and b/docs/articles/bambu_files/figure-html/unnamed-chunk-13-1.png differ diff --git a/docs/articles/bambu_files/figure-html/unnamed-chunk-16-1.png b/docs/articles/bambu_files/figure-html/unnamed-chunk-16-1.png new file mode 100644 index 00000000..a46aada9 Binary files /dev/null and b/docs/articles/bambu_files/figure-html/unnamed-chunk-16-1.png differ diff --git a/docs/articles/bambu_files/figure-html/unnamed-chunk-17-1.png b/docs/articles/bambu_files/figure-html/unnamed-chunk-17-1.png new file mode 100644 index 00000000..496028d3 Binary files /dev/null and b/docs/articles/bambu_files/figure-html/unnamed-chunk-17-1.png differ diff --git a/docs/articles/bambu_files/figure-html/unnamed-chunk-18-1.png b/docs/articles/bambu_files/figure-html/unnamed-chunk-18-1.png new file mode 100644 index 00000000..0d0a974a Binary files /dev/null and b/docs/articles/bambu_files/figure-html/unnamed-chunk-18-1.png differ diff --git a/docs/articles/bambu_files/figure-html/unnamed-chunk-23-1.png b/docs/articles/bambu_files/figure-html/unnamed-chunk-23-1.png new file mode 100644 index 00000000..c4098bdc Binary files /dev/null and b/docs/articles/bambu_files/figure-html/unnamed-chunk-23-1.png differ diff --git a/docs/articles/bambu_files/figure-html/unnamed-chunk-24-1.png b/docs/articles/bambu_files/figure-html/unnamed-chunk-24-1.png new file mode 100644 index 00000000..88bc9991 Binary files /dev/null and b/docs/articles/bambu_files/figure-html/unnamed-chunk-24-1.png differ diff --git a/docs/articles/bambu_files/figure-html/unnamed-chunk-7-1.png b/docs/articles/bambu_files/figure-html/unnamed-chunk-7-1.png new file mode 100644 index 00000000..45dff792 Binary files /dev/null and b/docs/articles/bambu_files/figure-html/unnamed-chunk-7-1.png differ diff --git a/docs/articles/bambu_files/figure-html/unnamed-chunk-8-1.png b/docs/articles/bambu_files/figure-html/unnamed-chunk-8-1.png new file mode 100644 index 00000000..6c6b3d03 Binary files /dev/null and b/docs/articles/bambu_files/figure-html/unnamed-chunk-8-1.png differ diff --git a/docs/articles/bambu_files/figure-html/unnamed-chunk-9-1.png b/docs/articles/bambu_files/figure-html/unnamed-chunk-9-1.png new file mode 100644 index 00000000..4b4cb90a Binary files /dev/null and b/docs/articles/bambu_files/figure-html/unnamed-chunk-9-1.png differ diff --git a/docs/articles/index.html b/docs/articles/index.html new file mode 100644 index 00000000..96fe7af1 --- /dev/null +++ b/docs/articles/index.html @@ -0,0 +1,147 @@ + + + + + + + + +Articles • bambu + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + +
+ +
+
+ + +
+

All vignettes

+

+ +
+
bambu
+
+
+
+
+
+ + + +
+ + + + + + + + diff --git a/docs/authors.html b/docs/authors.html new file mode 100644 index 00000000..a7afa2ca --- /dev/null +++ b/docs/authors.html @@ -0,0 +1,151 @@ + + + + + + + + +Authors • bambu + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + +
+ +
+
+ + +
    +
  • +

    Ying Chen Developer. Maintainer. +

    +
  • +
  • +

    Jonathan Goeke Developer. Author. +

    +
  • +
+ +
+ +
+ + + + +
+ + + + + + + + diff --git a/docs/bambu.html b/docs/bambu.html new file mode 100644 index 00000000..28455315 --- /dev/null +++ b/docs/bambu.html @@ -0,0 +1,700 @@ + + + + + + + + + + + + + + +bambu + + + + + + + + + + + + + + + + + + + + + +

bambu

+ + + +
+

Introduction

+

Bambu can be used for transcript discovery and quantification from long read RNA-Seq data. Here, we present an example usage of bambu on Nanopore long read RNA-Sequencing from 2 human cancer cell lines

+
+
+

Data description

+

To demonstrate the usage of Bambu, we used the data in NanoporeRNASeq, which contains single chromosome RNA-Seq data from two common cell lines K562 and MCF7. Each of these cell line has three replicates, with 1 direct RNA sequencing data and 2 cDNA sequencing data.

+
library(NanoporeRNASeq)
+library(bambu)
+
data("sample_info")
+sample_info
+##>                                sample_id Platform cellLine   protocol
+##> 1: SGNex_K562_directcDNA_replicate1_run2   MinION     K562 directcDNA
+##> 2: SGNex_K562_directcDNA_replicate4_run2  GridION     K562 directcDNA
+##> 3:  SGNex_K562_directRNA_replicate6_run1  GridION     K562  directRNA
+##> 4: SGNex_MCF7_directcDNA_replicate1_run2   MinION     MCF7 directcDNA
+##> 5: SGNex_MCF7_directcDNA_replicate3_run3  GridION     MCF7 directcDNA
+##> 6:  SGNex_MCF7_directRNA_replicate4_run1  GridION     MCF7  directRNA
+##>        bioRep cancer_type
+##> 1: replicate1   Leukocyte
+##> 2: replicate4   Leukocyte
+##> 3: replicate6   Leukocyte
+##> 4: replicate1      Breast
+##> 5: replicate3      Breast
+##> 6: replicate4      Breast
+

Name of bamfiles can be loaded as follows

+
data("bamFileNames")
+bamFileNames
+##> [1] "SGNex_K562_directcDNA_replicate1_run2_genome_chr22_1_25409234.bam"
+##> [2] "SGNex_K562_directcDNA_replicate4_run2_genome_chr22_1_25409234.bam"
+##> [3] "SGNex_K562_directRNA_replicate6_run1_genome_chr22_1_25409234.bam" 
+##> [4] "SGNex_MCF7_directcDNA_replicate1_run2_genome_chr22_1_25409234.bam"
+##> [5] "SGNex_MCF7_directcDNA_replicate3_run3_genome_chr22_1_25409234.bam"
+##> [6] "SGNex_MCF7_directRNA_replicate4_run1_genome_chr22_1_25409234.bam"
+

We then loaded bam.files.

+
bam.file <- system.file("extdata",bamFileNames, package = "NanoporeRNASeq")
+data("annotationGrangesList_chr22_1_25409234")
+

We applied bambu to perform EM on extended annotations

+
seExtended <- bambu(reads = bam.file, annotations = annotationGrangesList_chr22_1_25409234, genomeSequence = "BSgenome.Hsapiens.NCBI.GRCh38", extendAnnotations = TRUE, verbose = FALSE, ncore = 6)
+##> 
+  |                                                                            
+  |                                                                      |   0%
+  |                                                                            
+  |                                                                      |   0%
+  |                                                                            
+  |======================================================================| 100%
+##> 
+##> 
+  |                                                                            
+  |                                                                      |   0%
+  |                                                                            
+  |======================================================================| 100%
+##> 
+##> 
+  |                                                                            
+  |============                                                          |  17%
+  |                                                                            
+  |                                                                      |   0%
+  |                                                                            
+  |======================================================================| 100%
+##> 
+##> 
+  |                                                                            
+  |                                                                      |   0%
+  |                                                                            
+  |======================================================================| 100%
+##> 
+##> 
+  |                                                                            
+  |=======================                                               |  33%
+  |                                                                            
+  |                                                                      |   0%
+  |                                                                            
+  |======================================================================| 100%
+##> 
+##> 
+  |                                                                            
+  |                                                                      |   0%
+  |                                                                            
+  |======================================================================| 100%
+##> 
+##> 
+  |                                                                            
+  |===================================                                   |  50%
+  |                                                                            
+  |                                                                      |   0%
+  |                                                                            
+  |======================================================================| 100%
+##> 
+##> 
+  |                                                                            
+  |                                                                      |   0%
+  |                                                                            
+  |======================================================================| 100%
+##> 
+##> 
+  |                                                                            
+  |===============================================                       |  67%
+  |                                                                            
+  |                                                                      |   0%
+  |                                                                            
+  |======================================================================| 100%
+##> 
+##> 
+  |                                                                            
+  |                                                                      |   0%
+  |                                                                            
+  |======================================================================| 100%
+##> 
+##> 
+  |                                                                            
+  |==========================================================            |  83%
+  |                                                                            
+  |                                                                      |   0%
+  |                                                                            
+  |======================================================================| 100%
+##> 
+##> 
+  |                                                                            
+  |                                                                      |   0%
+  |                                                                            
+  |======================================================================| 100%
+##> 
+##> 
+  |                                                                            
+  |======================================================================| 100%
+##> 
+##> 
+  |                                                                            
+  |                                                                      |   0%
+  |                                                                            
+  |============                                                          |  17%
+  |                                                                            
+  |=======================                                               |  33%
+  |                                                                            
+  |===================================                                   |  50%
+  |                                                                            
+  |===============================================                       |  67%
+  |                                                                            
+  |==========================================================            |  83%
+  |                                                                            
+  |======================================================================| 100%
+seExtended
+##> class: RangedSummarizedExperiment 
+##> dim: 1923 6 
+##> metadata(0):
+##> assays(2): counts CPM
+##> rownames(1923): tx.1 tx.2 ... ENST00000484509 ENST00000468442
+##> rowData names(4): TXNAME GENEID eqClass newTxClass
+##> colnames(6):
+##>   SGNex_K562_directcDNA_replicate1_run2_genome_chr22_1_25409234
+##>   SGNex_K562_directcDNA_replicate4_run2_genome_chr22_1_25409234 ...
+##>   SGNex_MCF7_directcDNA_replicate3_run3_genome_chr22_1_25409234
+##>   SGNex_MCF7_directRNA_replicate4_run1_genome_chr22_1_25409234
+##> colData names(1): name
+

bambu allows quantification without isoform discovery

+
se <- bambu(reads = bam.file, annotations = annotationGrangesList_chr22_1_25409234, genomeSequence = "BSgenome.Hsapiens.NCBI.GRCh38", extendAnnotations = FALSE, verbose = FALSE, ncore = 6)
+##> 
+  |                                                                            
+  |                                                                      |   0%
+  |                                                                            
+  |                                                                      |   0%
+  |                                                                            
+  |======================================================================| 100%
+##> 
+##> 
+  |                                                                            
+  |                                                                      |   0%
+  |                                                                            
+  |======================================================================| 100%
+##> 
+##> 
+  |                                                                            
+  |============                                                          |  17%
+  |                                                                            
+  |                                                                      |   0%
+  |                                                                            
+  |======================================================================| 100%
+##> 
+##> 
+  |                                                                            
+  |                                                                      |   0%
+  |                                                                            
+  |======================================================================| 100%
+##> 
+##> 
+  |                                                                            
+  |=======================                                               |  33%
+  |                                                                            
+  |                                                                      |   0%
+  |                                                                            
+  |======================================================================| 100%
+##> 
+##> 
+  |                                                                            
+  |                                                                      |   0%
+  |                                                                            
+  |======================================================================| 100%
+##> 
+##> 
+  |                                                                            
+  |===================================                                   |  50%
+  |                                                                            
+  |                                                                      |   0%
+  |                                                                            
+  |======================================================================| 100%
+##> 
+##> 
+  |                                                                            
+  |                                                                      |   0%
+  |                                                                            
+  |======================================================================| 100%
+##> 
+##> 
+  |                                                                            
+  |===============================================                       |  67%
+  |                                                                            
+  |                                                                      |   0%
+  |                                                                            
+  |======================================================================| 100%
+##> 
+##> 
+  |                                                                            
+  |                                                                      |   0%
+  |                                                                            
+  |======================================================================| 100%
+##> 
+##> 
+  |                                                                            
+  |==========================================================            |  83%
+  |                                                                            
+  |                                                                      |   0%
+  |                                                                            
+  |======================================================================| 100%
+##> 
+##> 
+  |                                                                            
+  |                                                                      |   0%
+  |                                                                            
+  |======================================================================| 100%
+##> 
+##> 
+  |                                                                            
+  |======================================================================| 100%
+##> 
+##> 
+  |                                                                            
+  |                                                                      |   0%
+  |                                                                            
+  |============                                                          |  17%
+  |                                                                            
+  |=======================                                               |  33%
+  |                                                                            
+  |===================================                                   |  50%
+  |                                                                            
+  |===============================================                       |  67%
+  |                                                                            
+  |==========================================================            |  83%
+  |                                                                            
+  |======================================================================| 100%
+se
+##> class: RangedSummarizedExperiment 
+##> dim: 1500 6 
+##> metadata(0):
+##> assays(2): counts CPM
+##> rownames(1500): ENST00000624155 ENST00000422332 ... ENST00000484509
+##>   ENST00000468442
+##> rowData names(3): TXNAME GENEID eqClass
+##> colnames(6):
+##>   SGNex_K562_directcDNA_replicate1_run2_genome_chr22_1_25409234
+##>   SGNex_K562_directcDNA_replicate4_run2_genome_chr22_1_25409234 ...
+##>   SGNex_MCF7_directcDNA_replicate3_run3_genome_chr22_1_25409234
+##>   SGNex_MCF7_directRNA_replicate4_run1_genome_chr22_1_25409234
+##> colData names(1): name
+
+
+

Check expression estimates

+

We can check the estimated transcript expression using heatmap:

+
colData(seExtended)$groupVar <-  unlist(lapply(colnames(seExtended),function(x) unlist(strsplit(x,"_"))[2]))
+colnames(seExtended) <- gsub("_genome_chr22_1_25409234","",colnames(seExtended))
+colData(seExtended)$name <- gsub("_genome_chr22_1_25409234","",colData(seExtended)$name)
+plot.bambu(seExtended, group.variable = "groupVar", type = "heatmap")
+

+

or with PCA plot

+
colData(seExtended)$groupVar <-  unlist(lapply(colnames(seExtended),function(x) unlist(strsplit(x,"_"))[2]))
+plot.bambu(seExtended, group.variable = "groupVar", type = "pca")
+

+
+

Check for gene examples

+

Single gene examples can also be checked using plot functions from bambu

+
plot.bambu(seExtended, type = "annotation", gene_id = unique(rowData(seExtended)$GENEID)[10])
+

+
##> [[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.210]
+
+
+

Transcript to Gene expression

+

Gene expression can be obtained from transcript expression using this function:

+
seGene <- transcriptToGeneExpression(seExtended)
+seGene
+##> class: RangedSummarizedExperiment 
+##> dim: 887 6 
+##> metadata(0):
+##> assays(2): counts CPM
+##> rownames(887): ENSG00000015475 ENSG00000040608 ... gene.98 gene.99
+##> rowData names(2): GENEID newGeneClass
+##> colnames(6): SGNex_K562_directcDNA_replicate1_run2
+##>   SGNex_K562_directcDNA_replicate4_run2 ...
+##>   SGNex_MCF7_directcDNA_replicate3_run3
+##>   SGNex_MCF7_directRNA_replicate4_run1
+##> colData names(2): name groupVar
+

Gene expression heatmap

+
colData(seGene)$groupVar <-  unlist(lapply(colnames(seGene),function(x) unlist(strsplit(x,"_"))[2]))
+plot.bambu(seGene, group.variable = "groupVar", type = "heatmap")
+

+

Gene expression PCA plot

+
colData(seGene)$groupVar <-  unlist(lapply(colnames(seGene),function(x) unlist(strsplit(x,"_"))[2]))
+plot.bambu(seGene, group.variable = "groupVar", type = "pca")
+

+
+
+
+

Differentially expressed genes

+

We used DESeq2 to find the differentially expressed genes:

+
library(DESeq2)
+dds <- DESeqDataSetFromMatrix(apply(assays(seGene)$counts,c(1,2),round),#tmp_wide[,-1],
+                                   colData = colData(seExtended),
+                                   design = ~ groupVar)
+system.time(dds.deseq <- DESeq(dds))
+##>    user  system elapsed 
+##>   2.020   0.068   2.089
+
+deGeneRes <- DESeq2::results(dds.deseq, independentFiltering=FALSE)
+
head(deGeneRes[order(deGeneRes$padj),])
+##> log2 fold change (MLE): groupVar MCF7 vs K562 
+##> Wald test p-value: groupVar MCF7 vs K562 
+##> DataFrame with 6 rows and 6 columns
+##>                  baseMean log2FoldChange     lfcSE      stat
+##>                 <numeric>      <numeric> <numeric> <numeric>
+##> ENSG00000185686  513.5554       -7.22327  0.498140 -14.50048
+##> ENSG00000197077   26.2357        9.09835  1.326114   6.86091
+##> ENSG00000283633   88.7407       -9.03039  1.431724  -6.30736
+##> ENSG00000099977  232.6720        1.85141  0.306629   6.03795
+##> ENSG00000169635   44.4275       -3.44047  0.579080  -5.94127
+##> ENSG00000100181   38.3698       -5.07047  0.892940  -5.67840
+##>                                                                 pvalue
+##>                                                              <numeric>
+##> ENSG00000185686 0.0000000000000000000000000000000000000000000000120303
+##> ENSG00000197077 0.0000000000068425448545783570607904382313656081217312
+##> ENSG00000283633 0.0000000002838407468976333203669654163178986266968806
+##> ENSG00000099977 0.0000000015607995974142258612474572408387353539271913
+##> ENSG00000169635 0.0000000028282083250919303521398367383355917925591427
+##> ENSG00000100181 0.0000000135958879211409468852046023923732520621854292
+##>                                                                 padj
+##>                                                            <numeric>
+##> ENSG00000185686 0.00000000000000000000000000000000000000000000714599
+##> ENSG00000197077 0.00000000203223582180977191457661517551974705853013
+##> ENSG00000283633 0.00000005620046788573139474432216163360398475390411
+##> ENSG00000099977 0.00000023177874021601254939083656177872816428475744
+##> ENSG00000169635 0.00000033599114902092130879429198592189820260500710
+##> ENSG00000100181 0.00000134599290419295367876952908281484866392929689
+
summary(deGeneRes)
+##> 
+##> out of 594 with nonzero total read count
+##> adjusted p-value < 0.1
+##> LFC > 0 (up)       : 16, 2.7%
+##> LFC < 0 (down)     : 20, 3.4%
+##> outliers [1]       : 0, 0%
+##> low counts [2]     : 0, 0%
+##> (mean count < 0)
+##> [1] see 'cooksCutoff' argument of ?results
+##> [2] see 'independentFiltering' argument of ?results
+
plotMA(deGeneRes, ylim = c(-3,3))
+

+

Plotting shrinked lFC results

+
resLFC <- lfcShrink(dds.deseq, coef="groupVar_MCF7_vs_K562", type="apeglm")
+plotMA(resLFC, ylim = c(-3,3))
+

+
+
+

Differential expression for isoform detection

+

We used DEXSeq to detect alternative used isoforms.

+
library(DRIMSeq)
+count.data <- as.data.frame(rowData(seExtended))
+count.data$gene_id <- count.data$GENEID
+count.data$feature_id <- count.data$TXNAME
+count.data$GENEID <- count.data$TXNAME <- NULL
+
+count.data <- cbind(count.data, assays(seExtended)$counts)
+
+sample.info <- as.data.frame(colData(seExtended))
+sample.info$sample_id <- sample.info$name
+sample.info$name <- NULL
+d <- dmDSdata(counts=count.data, samples=sample.info)
+
+n_samp_gene <- 1
+n_samp_feature <- 1
+min_count_gene <- 1
+min_count_feature <- 1
+dFilter <- dmFilter(d,
+              min_samps_feature_expr = n_samp_feature, 
+              min_samps_feature_prop = n_samp_feature,
+              min_samps_gene_expr = n_samp_gene, 
+              min_feature_expr = min_count_feature,
+              min_gene_expr = min_count_gene,
+              min_feature_prop=0.1)
+table(table(counts(dFilter)$gene_id)) ## number of isoforms 
+##> 
+##>  2  3  4  5  6  7  8 10 
+##> 23 15 21 12  8  6  4  1
+
library(DEXSeq)
+formulaFullModel <- as.formula("~sample + exon + groupVar:exon")
+
+
+dxd <- DEXSeqDataSet(countData=round(as.matrix(counts(dFilter)[,-c(1:2)])),
+                     sampleData=DRIMSeq::samples(dFilter),
+                     design=formulaFullModel,
+                     featureID = counts(dFilter)$feature_id,
+                     groupID=counts(dFilter)$gene_id)
+
+
+system.time({
+  dxd <- estimateSizeFactors(dxd)
+  print('Size factor estimated')
+  dxd <- estimateDispersions(dxd, formula = formulaFullModel)
+  print('Dispersion estimated')
+  #dxd <- estimateExonFoldChanges( dxd )
+  dxd <- testForDEU(dxd, fullModel = formulaFullModel)
+  print('DEU tested')
+  dxd <- estimateExonFoldChanges(dxd, fitExpToVar="groupVar")
+  print('Exon fold changes estimated')
+}) 
+##> [1] "Size factor estimated"
+##> [1] "Dispersion estimated"
+##> [1] "DEU tested"
+##> [1] "Exon fold changes estimated"
+##>    user  system elapsed 
+##>   7.816   0.024   7.844
+
dxr <- DEXSeqResults(dxd, independentFiltering=FALSE)
+head(dxr)
+##> 
+##> LRT p-value: full vs reduced
+##> 
+##> DataFrame with 6 rows and 12 columns
+##>                   groupID   featureID exonBaseMean dispersion      stat
+##>               <character> <character>    <numeric>  <numeric> <numeric>
+##> gene.2:tx.2        gene.2        tx.2     2.714822   0.427670  3.150551
+##> gene.2:tx.3        gene.2        tx.3     0.654029   0.791030  0.140914
+##> gene.2:tx.4        gene.2        tx.4     2.567833   0.315359  1.003001
+##> gene.2:tx.66       gene.2       tx.66     2.107202   0.332461  0.422016
+##> gene.2:tx.67       gene.2       tx.67     1.243100   1.748445  1.683733
+##> gene.2:tx.122      gene.2      tx.122     1.865452   0.467004  1.043483
+##>                  pvalue      padj      K562      MCF7 log2fold_MCF7_K562
+##>               <numeric> <numeric> <numeric> <numeric>          <numeric>
+##> gene.2:tx.2   0.0759013   0.99485   2.14944 0.0448427         -11.620740
+##> gene.2:tx.3   0.7073738   1.00000   1.15465 0.0448419          -9.506951
+##> gene.2:tx.4   0.3165853   1.00000   2.03209 1.1710398          -1.860342
+##> gene.2:tx.66  0.5159328   1.00000   1.58048 1.8911532           0.622989
+##> gene.2:tx.67  0.1944292   1.00000   1.05916 1.7073365           1.554900
+##> gene.2:tx.122 0.3070128   1.00000   1.44728 1.8878239           0.910422
+##>                 genomicData   countData
+##>               <GRangesList>    <matrix>
+##> gene.2:tx.2                 18:13:3:...
+##> gene.2:tx.3                   2:3:2:...
+##> gene.2:tx.4                 10:15:3:...
+##> gene.2:tx.66                  7:5:3:...
+##> gene.2:tx.67                  0:6:0:...
+##> gene.2:tx.122                 2:9:1:...
+
library(stageR)
+strp <- function(x) substr(x,1,15)
+qval <- perGeneQValue(dxr)
+dxr.g <- data.frame(gene=names(qval),qval)
+
+columns <- c("featureID","groupID","pvalue")
+dxr_pval <- as.data.frame(dxr[,columns])
+head(dxr_pval)
+##>               featureID groupID     pvalue
+##> gene.2:tx.2        tx.2  gene.2 0.07590133
+##> gene.2:tx.3        tx.3  gene.2 0.70737384
+##> gene.2:tx.4        tx.4  gene.2 0.31658535
+##> gene.2:tx.66      tx.66  gene.2 0.51593283
+##> gene.2:tx.67      tx.67  gene.2 0.19442922
+##> gene.2:tx.122    tx.122  gene.2 0.30701285
+
+pConfirmation <- matrix(dxr_pval$pvalue,ncol=1)
+dimnames(pConfirmation) <- list(strp(dxr_pval$featureID),"transcript")
+pScreen <- qval
+names(pScreen) <- strp(names(pScreen))
+tx2gene <- as.data.frame(dxr_pval[,c("featureID", "groupID")])
+for (i in 1:2) tx2gene[,i] <- strp(tx2gene[,i])
+
+
+stageRObj <- stageRTx(pScreen=pScreen, pConfirmation=pConfirmation,
+                      pScreenAdjusted=TRUE, tx2gene=tx2gene)
+stageRObj <- stageWiseAdjustment(stageRObj, method="dtu", alpha=0.5)
+suppressWarnings({
+  dex.padj <- getAdjustedPValues(stageRObj, order=FALSE,
+                                 onlySignificantGenes=TRUE)
+})
+
dxrDT <- data.table(as.data.frame(dxr))
+setnames(dxrDT, old = c('groupID','featureID'), new = c('geneID','txID'))
+dex.padj <- data.table(dex.padj)
+
+dxrDT <- dex.padj[dxrDT, on = c('geneID','txID')]
+head(dxrDT)
+##>    geneID   txID gene transcript exonBaseMean dispersion      stat     pvalue
+##> 1: gene.2   tx.2   NA         NA    2.7148218  0.4276702 3.1505509 0.07590133
+##> 2: gene.2   tx.3   NA         NA    0.6540286  0.7910296 0.1409142 0.70737384
+##> 3: gene.2   tx.4   NA         NA    2.5678325  0.3153589 1.0030014 0.31658535
+##> 4: gene.2  tx.66   NA         NA    2.1072015  0.3324607 0.4220160 0.51593283
+##> 5: gene.2  tx.67   NA         NA    1.2431000  1.7484453 1.6837326 0.19442922
+##> 6: gene.2 tx.122   NA         NA    1.8654524  0.4670041 1.0434828 0.30701285
+##>         padj     K562       MCF7 log2fold_MCF7_K562 genomicData
+##> 1: 0.9948496 2.149443 0.04484265        -11.6207395   <GRanges>
+##> 2: 1.0000000 1.154654 0.04484192         -9.5069512   <GRanges>
+##> 3: 1.0000000 2.032089 1.17103980         -1.8603417   <GRanges>
+##> 4: 1.0000000 1.580476 1.89115320          0.6229887   <GRanges>
+##> 5: 1.0000000 1.059156 1.70733655          1.5549004   <GRanges>
+##> 6: 1.0000000 1.447282 1.88782389          0.9104218   <GRanges>
+##>    countData.SGNex_K562_directcDNA_replicate1_run2
+##> 1:                                              18
+##> 2:                                               2
+##> 3:                                              10
+##> 4:                                               7
+##> 5:                                               0
+##> 6:                                               2
+##>    countData.SGNex_K562_directcDNA_replicate4_run2
+##> 1:                                              13
+##> 2:                                               3
+##> 3:                                              15
+##> 4:                                               5
+##> 5:                                               6
+##> 6:                                               9
+##>    countData.SGNex_K562_directRNA_replicate6_run1
+##> 1:                                              3
+##> 2:                                              2
+##> 3:                                              3
+##> 4:                                              3
+##> 5:                                              0
+##> 6:                                              1
+##>    countData.SGNex_MCF7_directcDNA_replicate1_run2
+##> 1:                                               0
+##> 2:                                               0
+##> 3:                                               0
+##> 4:                                               1
+##> 5:                                               1
+##> 6:                                               1
+##>    countData.SGNex_MCF7_directcDNA_replicate3_run3
+##> 1:                                               0
+##> 2:                                               0
+##> 3:                                               1
+##> 4:                                               2
+##> 5:                                               0
+##> 6:                                               2
+##>    countData.SGNex_MCF7_directRNA_replicate4_run1
+##> 1:                                              0
+##> 2:                                              0
+##> 3:                                              0
+##> 4:                                              0
+##> 5:                                              1
+##> 6:                                              0
+
dxrDT[,sigLFC2:=(padj < 0.5&(abs(log2fold_MCF7_K562)>=2))]
+ggplot(dxrDT, aes(y = log2fold_MCF7_K562, x = exonBaseMean, color = as.factor(padj<0.5)))+
+  geom_point(size = 0.5)+
+     scale_x_log10()+
+  scale_color_manual(values = c('grey','indianred'), name = "Significant")+
+     xlab("Mean of normalized counts")+
+    ylab("Log2 Fold change")+
+  theme_minimal()
+

+
dxrDT[padj<0.5,.(geneID, txID, log2fold_MCF7_K562,K562,MCF7)]
+##>             geneID            txID log2fold_MCF7_K562      K562     MCF7
+##> 1: ENSG00000183597           tx.35          -2.925745 4.2504114 2.284457
+##> 2: ENSG00000184436           tx.44          -4.132398 3.3428343 1.103626
+##> 3: ENSG00000272779          tx.105           4.276779 0.6241729 2.320295
+##> 4: ENSG00000100030 ENST00000215832           1.112208 5.7031758 6.535581
+##> 5: ENSG00000100030 ENST00000398822          -1.438071 4.0021766 3.004256
+##> 6: ENSG00000169635 ENST00000407464           2.362562 1.9298346 3.404064
+##> 7: ENSG00000169635 ENST00000443632          -1.904184 4.0971165 2.785404
+##> 8: ENSG00000215012 ENST00000407472          -1.753270 3.6246114 2.462383
+
+ + + + + + + + + + + diff --git a/docs/bambu_0.1.0.pdf b/docs/bambu_0.1.0.pdf new file mode 100644 index 00000000..40f9124e Binary files /dev/null and b/docs/bambu_0.1.0.pdf differ diff --git a/docs/bootstrap-toc.css b/docs/bootstrap-toc.css new file mode 100644 index 00000000..5a859415 --- /dev/null +++ b/docs/bootstrap-toc.css @@ -0,0 +1,60 @@ +/*! + * Bootstrap Table of Contents v0.4.1 (http://afeld.github.io/bootstrap-toc/) + * Copyright 2015 Aidan Feldman + * Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */ + +/* modified from https://github.com/twbs/bootstrap/blob/94b4076dd2efba9af71f0b18d4ee4b163aa9e0dd/docs/assets/css/src/docs.css#L548-L601 */ + +/* All levels of nav */ +nav[data-toggle='toc'] .nav > li > a { + display: block; + padding: 4px 20px; + font-size: 13px; + font-weight: 500; + color: #767676; +} +nav[data-toggle='toc'] .nav > li > a:hover, +nav[data-toggle='toc'] .nav > li > a:focus { + padding-left: 19px; + color: #563d7c; + text-decoration: none; + background-color: transparent; + border-left: 1px solid #563d7c; +} +nav[data-toggle='toc'] .nav > .active > a, +nav[data-toggle='toc'] .nav > .active:hover > a, +nav[data-toggle='toc'] .nav > .active:focus > a { + padding-left: 18px; + font-weight: bold; + color: #563d7c; + background-color: transparent; + border-left: 2px solid #563d7c; +} + +/* Nav: second level (shown on .active) */ +nav[data-toggle='toc'] .nav .nav { + display: none; /* Hide by default, but at >768px, show it */ + padding-bottom: 10px; +} +nav[data-toggle='toc'] .nav .nav > li > a { + padding-top: 1px; + padding-bottom: 1px; + padding-left: 30px; + font-size: 12px; + font-weight: normal; +} +nav[data-toggle='toc'] .nav .nav > li > a:hover, +nav[data-toggle='toc'] .nav .nav > li > a:focus { + padding-left: 29px; +} +nav[data-toggle='toc'] .nav .nav > .active > a, +nav[data-toggle='toc'] .nav .nav > .active:hover > a, +nav[data-toggle='toc'] .nav .nav > .active:focus > a { + padding-left: 28px; + font-weight: 500; +} + +/* from https://github.com/twbs/bootstrap/blob/e38f066d8c203c3e032da0ff23cd2d6098ee2dd6/docs/assets/css/src/docs.css#L631-L634 */ +nav[data-toggle='toc'] .nav > .active > ul { + display: block; +} diff --git a/docs/bootstrap-toc.js b/docs/bootstrap-toc.js new file mode 100644 index 00000000..1cdd573b --- /dev/null +++ b/docs/bootstrap-toc.js @@ -0,0 +1,159 @@ +/*! + * Bootstrap Table of Contents v0.4.1 (http://afeld.github.io/bootstrap-toc/) + * Copyright 2015 Aidan Feldman + * Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */ +(function() { + 'use strict'; + + window.Toc = { + helpers: { + // return all matching elements in the set, or their descendants + findOrFilter: function($el, selector) { + // http://danielnouri.org/notes/2011/03/14/a-jquery-find-that-also-finds-the-root-element/ + // http://stackoverflow.com/a/12731439/358804 + var $descendants = $el.find(selector); + return $el.filter(selector).add($descendants).filter(':not([data-toc-skip])'); + }, + + generateUniqueIdBase: function(el) { + var text = $(el).text(); + var anchor = text.trim().toLowerCase().replace(/[^A-Za-z0-9]+/g, '-'); + return anchor || el.tagName.toLowerCase(); + }, + + generateUniqueId: function(el) { + var anchorBase = this.generateUniqueIdBase(el); + for (var i = 0; ; i++) { + var anchor = anchorBase; + if (i > 0) { + // add suffix + anchor += '-' + i; + } + // check if ID already exists + if (!document.getElementById(anchor)) { + return anchor; + } + } + }, + + generateAnchor: function(el) { + if (el.id) { + return el.id; + } else { + var anchor = this.generateUniqueId(el); + el.id = anchor; + return anchor; + } + }, + + createNavList: function() { + return $(''); + }, + + createChildNavList: function($parent) { + var $childList = this.createNavList(); + $parent.append($childList); + return $childList; + }, + + generateNavEl: function(anchor, text) { + var $a = $(''); + $a.attr('href', '#' + anchor); + $a.text(text); + var $li = $('
  • '); + $li.append($a); + return $li; + }, + + generateNavItem: function(headingEl) { + var anchor = this.generateAnchor(headingEl); + var $heading = $(headingEl); + var text = $heading.data('toc-text') || $heading.text(); + return this.generateNavEl(anchor, text); + }, + + // Find the first heading level (`

    `, then `

    `, etc.) that has more than one element. Defaults to 1 (for `

    `). + getTopLevel: function($scope) { + for (var i = 1; i <= 6; i++) { + var $headings = this.findOrFilter($scope, 'h' + i); + if ($headings.length > 1) { + return i; + } + } + + return 1; + }, + + // returns the elements for the top level, and the next below it + getHeadings: function($scope, topLevel) { + var topSelector = 'h' + topLevel; + + var secondaryLevel = topLevel + 1; + var secondarySelector = 'h' + secondaryLevel; + + return this.findOrFilter($scope, topSelector + ',' + secondarySelector); + }, + + getNavLevel: function(el) { + return parseInt(el.tagName.charAt(1), 10); + }, + + populateNav: function($topContext, topLevel, $headings) { + var $context = $topContext; + var $prevNav; + + var helpers = this; + $headings.each(function(i, el) { + var $newNav = helpers.generateNavItem(el); + var navLevel = helpers.getNavLevel(el); + + // determine the proper $context + if (navLevel === topLevel) { + // use top level + $context = $topContext; + } else if ($prevNav && $context === $topContext) { + // create a new level of the tree and switch to it + $context = helpers.createChildNavList($prevNav); + } // else use the current $context + + $context.append($newNav); + + $prevNav = $newNav; + }); + }, + + parseOps: function(arg) { + var opts; + if (arg.jquery) { + opts = { + $nav: arg + }; + } else { + opts = arg; + } + opts.$scope = opts.$scope || $(document.body); + return opts; + } + }, + + // accepts a jQuery object, or an options object + init: function(opts) { + opts = this.helpers.parseOps(opts); + + // ensure that the data attribute is in place for styling + opts.$nav.attr('data-toggle', 'toc'); + + var $topContext = this.helpers.createChildNavList(opts.$nav); + var topLevel = this.helpers.getTopLevel(opts.$scope); + var $headings = this.helpers.getHeadings(opts.$scope, topLevel); + this.helpers.populateNav($topContext, topLevel, $headings); + } + }; + + $(function() { + $('nav[data-toggle="toc"]').each(function(i, el) { + var $nav = $(el); + Toc.init($nav); + }); + }); +})(); diff --git a/docs/docsearch.css b/docs/docsearch.css new file mode 100644 index 00000000..e5f1fe1d --- /dev/null +++ b/docs/docsearch.css @@ -0,0 +1,148 @@ +/* Docsearch -------------------------------------------------------------- */ +/* + Source: https://github.com/algolia/docsearch/ + License: MIT +*/ + +.algolia-autocomplete { + display: block; + -webkit-box-flex: 1; + -ms-flex: 1; + flex: 1 +} + +.algolia-autocomplete .ds-dropdown-menu { + width: 100%; + min-width: none; + max-width: none; + padding: .75rem 0; + background-color: #fff; + background-clip: padding-box; + border: 1px solid rgba(0, 0, 0, .1); + box-shadow: 0 .5rem 1rem rgba(0, 0, 0, .175); +} + +@media (min-width:768px) { + .algolia-autocomplete .ds-dropdown-menu { + width: 175% + } +} + +.algolia-autocomplete .ds-dropdown-menu::before { + display: none +} + +.algolia-autocomplete .ds-dropdown-menu [class^=ds-dataset-] { + padding: 0; + background-color: rgb(255,255,255); + border: 0; + max-height: 80vh; +} + +.algolia-autocomplete .ds-dropdown-menu .ds-suggestions { + margin-top: 0 +} + +.algolia-autocomplete .algolia-docsearch-suggestion { + padding: 0; + overflow: visible +} + +.algolia-autocomplete .algolia-docsearch-suggestion--category-header { + padding: .125rem 1rem; + margin-top: 0; + font-size: 1.3em; + font-weight: 500; + color: #00008B; + border-bottom: 0 +} + +.algolia-autocomplete .algolia-docsearch-suggestion--wrapper { + float: none; + padding-top: 0 +} + +.algolia-autocomplete .algolia-docsearch-suggestion--subcategory-column { + float: none; + width: auto; + padding: 0; + text-align: left +} + +.algolia-autocomplete .algolia-docsearch-suggestion--content { + float: none; + width: auto; + padding: 0 +} + +.algolia-autocomplete .algolia-docsearch-suggestion--content::before { + display: none +} + +.algolia-autocomplete .ds-suggestion:not(:first-child) .algolia-docsearch-suggestion--category-header { + padding-top: .75rem; + margin-top: .75rem; + border-top: 1px solid rgba(0, 0, 0, .1) +} + +.algolia-autocomplete .ds-suggestion .algolia-docsearch-suggestion--subcategory-column { + display: block; + padding: .1rem 1rem; + margin-bottom: 0.1; + font-size: 1.0em; + font-weight: 400 + /* display: none */ +} + +.algolia-autocomplete .algolia-docsearch-suggestion--title { + display: block; + padding: .25rem 1rem; + margin-bottom: 0; + font-size: 0.9em; + font-weight: 400 +} + +.algolia-autocomplete .algolia-docsearch-suggestion--text { + padding: 0 1rem .5rem; + margin-top: -.25rem; + font-size: 0.8em; + font-weight: 400; + line-height: 1.25 +} + +.algolia-autocomplete .algolia-docsearch-footer { + width: 110px; + height: 20px; + z-index: 3; + margin-top: 10.66667px; + float: right; + font-size: 0; + line-height: 0; +} + +.algolia-autocomplete .algolia-docsearch-footer--logo { + background-image: url("data:image/svg+xml;utf8,"); + background-repeat: no-repeat; + background-position: 50%; + background-size: 100%; + overflow: hidden; + text-indent: -9000px; + width: 100%; + height: 100%; + display: block; + transform: translate(-8px); +} + +.algolia-autocomplete .algolia-docsearch-suggestion--highlight { + color: #FF8C00; + background: rgba(232, 189, 54, 0.1) +} + + +.algolia-autocomplete .algolia-docsearch-suggestion--text .algolia-docsearch-suggestion--highlight { + box-shadow: inset 0 -2px 0 0 rgba(105, 105, 105, .5) +} + +.algolia-autocomplete .ds-suggestion.ds-cursor .algolia-docsearch-suggestion--content { + background-color: rgba(192, 192, 192, .15) +} diff --git a/docs/docsearch.js b/docs/docsearch.js new file mode 100644 index 00000000..b35504cd --- /dev/null +++ b/docs/docsearch.js @@ -0,0 +1,85 @@ +$(function() { + + // register a handler to move the focus to the search bar + // upon pressing shift + "/" (i.e. "?") + $(document).on('keydown', function(e) { + if (e.shiftKey && e.keyCode == 191) { + e.preventDefault(); + $("#search-input").focus(); + } + }); + + $(document).ready(function() { + // do keyword highlighting + /* modified from https://jsfiddle.net/julmot/bL6bb5oo/ */ + var mark = function() { + + var referrer = document.URL ; + var paramKey = "q" ; + + if (referrer.indexOf("?") !== -1) { + var qs = referrer.substr(referrer.indexOf('?') + 1); + var qs_noanchor = qs.split('#')[0]; + var qsa = qs_noanchor.split('&'); + var keyword = ""; + + for (var i = 0; i < qsa.length; i++) { + var currentParam = qsa[i].split('='); + + if (currentParam.length !== 2) { + continue; + } + + if (currentParam[0] == paramKey) { + keyword = decodeURIComponent(currentParam[1].replace(/\+/g, "%20")); + } + } + + if (keyword !== "") { + $(".contents").unmark({ + done: function() { + $(".contents").mark(keyword); + } + }); + } + } + }; + + mark(); + }); +}); + +/* Search term highlighting ------------------------------*/ + +function matchedWords(hit) { + var words = []; + + var hierarchy = hit._highlightResult.hierarchy; + // loop to fetch from lvl0, lvl1, etc. + for (var idx in hierarchy) { + words = words.concat(hierarchy[idx].matchedWords); + } + + var content = hit._highlightResult.content; + if (content) { + words = words.concat(content.matchedWords); + } + + // return unique words + var words_uniq = [...new Set(words)]; + return words_uniq; +} + +function updateHitURL(hit) { + + var words = matchedWords(hit); + var url = ""; + + if (hit.anchor) { + url = hit.url_without_anchor + '?q=' + escape(words.join(" ")) + '#' + hit.anchor; + } else { + url = hit.url + '?q=' + escape(words.join(" ")); + } + + return url; +} diff --git a/docs/index.html b/docs/index.html new file mode 100644 index 00000000..f13f5c72 --- /dev/null +++ b/docs/index.html @@ -0,0 +1,255 @@ + + + + + + + +Reference-guided isoform reconstruction and quantification for long read RNA-Seq data • bambu + + + + + + + + + + +
    +
    + + + + +
    +
    + + +
    + +

    bambu is a R package for multi-sample transcript discovery and quantification using long read RNA-Seq data. You can use bambu after read alignment to obtain expression estimates for known and novel transcripts and genes. The output from bambu can directly be used for visualisation and downstream analysis such as differential gene expression or transcript usage.

    +

    GitHub release (latest by date) Maintained?
    Install License: GPL v3

    +
    + +
    +

    +Installation

    +

    You can install bambu from github:

    +
    if (!requireNamespace("devtools", quietly = TRUE))
    +    install.packages("devtools")
    +devtools::install_github("GoekeLab/bambu")
    +
    +
    +
    +

    +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:

    +

    ```rscript library(bambu)

    +

    test.bam <- system.file(“extdata”, “SGNex_A549_directRNA_replicate5_run1_chr9_1_1000000.bam”, package = “bambu”)

    +

    se <- bambu(reads = test.bam, annotations = “TxDb.Hsapiens.UCSC.hg38.knownGene”, genomeSequence = “BSgenome.Hsapiens.NCBI.GRCh38”)

    +

    ```

    +

    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:

    +
    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 <- prepareAnnotationsFromGTF(gtf.file)
    +
    +se <- bambu(reads = test.bam, annotations = bambuAnnotations, genomeSequence = fa.file)
    +
    +

    Quantification of annotated transcripts and genes only (no transcript/gene discovery)

    +
    bambu(reads = test.bam, annotations = txdb, genomeSequence = fa.file, extendAnnotations = FALSE)
    +

    Large sample number/ limited memory
    +For larger sample numbers we recommend to write the processed data to a file:

    +
    bambu(reads = test.bam, readClass.outputDir = "./bambu/", annotations = bambuAnnotations, genomeSequence = fa.file)
    +
    +
    +
    +

    +Use precalculated annotation objects

    +

    You can also use precalculated annotations.

    +

    If you plan to run bambu more frequently, we recommend to save the bambuAnnotations object.

    +

    The bambuAnnotation object can be calculated from a gtf file:

    +
    annotations <- prepareAnnotationFromGTF(gtf.file)
    +

    From TxDb object

    +
    annotations <- prepareAnnotations(txdb)
    +
    +
    +
    +

    +Advanced Options

    +

    More stringent filtering thresholds imposed on potential novel transcripts

    +
    +

    Keep novel transcripts with min 5 read count in at least 1 sample:

    +
    +
    bambu(reads, annotations, genomeSequence, isoreParameters = list(min.readCount = 5))
    +
    +

    Keep novel transcripts with min 5 samples having at least 2 counts:

    +
    +
    bambu(reads, annotations, genomeSequence, isoreParameters = list(min.sampleNumber = 5))
    +
    +

    Filter out transcripts with relative abundance within gene lower than 10%:

    +
    +
    bambu(reads, annotations, genomeSequence, isoreParameters = list(min.readFractionByGene = 0.1))
    +

    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.

    +
    +
    bambu(reads, annotations, genomeSequence, emParameters(bias = FALSE))
    +

    Parallel computation

    +
    +

    bambu allows parallel computation.

    +
    +
    bambu(reads, annotations, genomeSequence, ncore = 8)
    +

    See manual for details to customize other conditions.

    +
    +
    +

    +Complementary functions

    +

    Transcript expression to gene expression

    +
    transcriptToGeneExpression(se)
    +

    Visualization

    +
    +

    You can visualize the novel genes/transcripts using plot.bambu function

    +
    +
    plot.bambu(se, type = "annotation", gene_id)
    +
    +plot.bambu(se, type = "annotation", transcript_id)
    +
    +

    plot.bambu can also be used to visualize the clustering of input samples on gene/transcript expressions

    +
    +
    plot.bambu(se, type = "heatmap") # heatmap 
    +
    +plot.bambu(se, type = "pca") # PCA visualization
    +
    +

    plot.bambu can also be used to visualize the clustering of input samples on gene/transcript expressions with grouping variable

    +
    +
    plot.bambu(se, type = "heatmap", group.var) # heatmap 
    +
    +plot.bambu(se, type = "pca", group.var) # PCA visualization
    +

    Write bambu outputs to files

    +
    +

    writeBambuOutput will generate three files, including a .gtf file for the extended annotations, and two .txt files for the expression counts at transcript and gene levels.

    +
    +
    writeBambuOutput(se, path = "./bambu/")
    +
    +
    +
    +

    +Contributors

    +

    This package is developed and maintained byYing Chen, Yuk Kei Wan, Jonathan Goeke and at Genome Institute of Singapore. If you want to contribute, please leave an issue. Thank you.

    +
    +
    +
    + +
    + + +
    + + +
    + +
    +

    Site built with pkgdown 1.5.1.

    +
    + +
    +
    + + + + + + diff --git a/docs/link.svg b/docs/link.svg new file mode 100644 index 00000000..88ad8276 --- /dev/null +++ b/docs/link.svg @@ -0,0 +1,12 @@ + + + + + + diff --git a/docs/pkgdown.css b/docs/pkgdown.css new file mode 100644 index 00000000..c01e5923 --- /dev/null +++ b/docs/pkgdown.css @@ -0,0 +1,367 @@ +/* Sticky footer */ + +/** + * Basic idea: https://philipwalton.github.io/solved-by-flexbox/demos/sticky-footer/ + * Details: https://github.com/philipwalton/solved-by-flexbox/blob/master/assets/css/components/site.css + * + * .Site -> body > .container + * .Site-content -> body > .container .row + * .footer -> footer + * + * Key idea seems to be to ensure that .container and __all its parents__ + * have height set to 100% + * + */ + +html, body { + height: 100%; +} + +body { + position: relative; +} + +body > .container { + display: flex; + height: 100%; + flex-direction: column; +} + +body > .container .row { + flex: 1 0 auto; +} + +footer { + margin-top: 45px; + padding: 35px 0 36px; + border-top: 1px solid #e5e5e5; + color: #666; + display: flex; + flex-shrink: 0; +} +footer p { + margin-bottom: 0; +} +footer div { + flex: 1; +} +footer .pkgdown { + text-align: right; +} +footer p { + margin-bottom: 0; +} + +img.icon { + float: right; +} + +img { + max-width: 100%; +} + +/* Fix bug in bootstrap (only seen in firefox) */ +summary { + display: list-item; +} + +/* Typographic tweaking ---------------------------------*/ + +.contents .page-header { + margin-top: calc(-60px + 1em); +} + +dd { + margin-left: 3em; +} + +/* Section anchors ---------------------------------*/ + +a.anchor { + margin-left: -30px; + display:inline-block; + width: 30px; + height: 30px; + visibility: hidden; + + background-image: url(./link.svg); + background-repeat: no-repeat; + background-size: 20px 20px; + background-position: center center; +} + +.hasAnchor:hover a.anchor { + visibility: visible; +} + +@media (max-width: 767px) { + .hasAnchor:hover a.anchor { + visibility: hidden; + } +} + + +/* Fixes for fixed navbar --------------------------*/ + +.contents h1, .contents h2, .contents h3, .contents h4 { + padding-top: 60px; + margin-top: -40px; +} + +/* Navbar submenu --------------------------*/ + +.dropdown-submenu { + position: relative; +} + +.dropdown-submenu>.dropdown-menu { + top: 0; + left: 100%; + margin-top: -6px; + margin-left: -1px; + border-radius: 0 6px 6px 6px; +} + +.dropdown-submenu:hover>.dropdown-menu { + display: block; +} + +.dropdown-submenu>a:after { + display: block; + content: " "; + float: right; + width: 0; + height: 0; + border-color: transparent; + border-style: solid; + border-width: 5px 0 5px 5px; + border-left-color: #cccccc; + margin-top: 5px; + margin-right: -10px; +} + +.dropdown-submenu:hover>a:after { + border-left-color: #ffffff; +} + +.dropdown-submenu.pull-left { + float: none; +} + +.dropdown-submenu.pull-left>.dropdown-menu { + left: -100%; + margin-left: 10px; + border-radius: 6px 0 6px 6px; +} + +/* Sidebar --------------------------*/ + +#pkgdown-sidebar { + margin-top: 30px; + position: -webkit-sticky; + position: sticky; + top: 70px; +} + +#pkgdown-sidebar h2 { + font-size: 1.5em; + margin-top: 1em; +} + +#pkgdown-sidebar h2:first-child { + margin-top: 0; +} + +#pkgdown-sidebar .list-unstyled li { + margin-bottom: 0.5em; +} + +/* bootstrap-toc tweaks ------------------------------------------------------*/ + +/* All levels of nav */ + +nav[data-toggle='toc'] .nav > li > a { + padding: 4px 20px 4px 6px; + font-size: 1.5rem; + font-weight: 400; + color: inherit; +} + +nav[data-toggle='toc'] .nav > li > a:hover, +nav[data-toggle='toc'] .nav > li > a:focus { + padding-left: 5px; + color: inherit; + border-left: 1px solid #878787; +} + +nav[data-toggle='toc'] .nav > .active > a, +nav[data-toggle='toc'] .nav > .active:hover > a, +nav[data-toggle='toc'] .nav > .active:focus > a { + padding-left: 5px; + font-size: 1.5rem; + font-weight: 400; + color: inherit; + border-left: 2px solid #878787; +} + +/* Nav: second level (shown on .active) */ + +nav[data-toggle='toc'] .nav .nav { + display: none; /* Hide by default, but at >768px, show it */ + padding-bottom: 10px; +} + +nav[data-toggle='toc'] .nav .nav > li > a { + padding-left: 16px; + font-size: 1.35rem; +} + +nav[data-toggle='toc'] .nav .nav > li > a:hover, +nav[data-toggle='toc'] .nav .nav > li > a:focus { + padding-left: 15px; +} + +nav[data-toggle='toc'] .nav .nav > .active > a, +nav[data-toggle='toc'] .nav .nav > .active:hover > a, +nav[data-toggle='toc'] .nav .nav > .active:focus > a { + padding-left: 15px; + font-weight: 500; + font-size: 1.35rem; +} + +/* orcid ------------------------------------------------------------------- */ + +.orcid { + font-size: 16px; + color: #A6CE39; + /* margins are required by official ORCID trademark and display guidelines */ + margin-left:4px; + margin-right:4px; + vertical-align: middle; +} + +/* Reference index & topics ----------------------------------------------- */ + +.ref-index th {font-weight: normal;} + +.ref-index td {vertical-align: top;} +.ref-index .icon {width: 40px;} +.ref-index .alias {width: 40%;} +.ref-index-icons .alias {width: calc(40% - 40px);} +.ref-index .title {width: 60%;} + +.ref-arguments th {text-align: right; padding-right: 10px;} +.ref-arguments th, .ref-arguments td {vertical-align: top;} +.ref-arguments .name {width: 20%;} +.ref-arguments .desc {width: 80%;} + +/* Nice scrolling for wide elements --------------------------------------- */ + +table { + display: block; + overflow: auto; +} + +/* Syntax highlighting ---------------------------------------------------- */ + +pre { + word-wrap: normal; + word-break: normal; + border: 1px solid #eee; +} + +pre, code { + background-color: #f8f8f8; + color: #333; +} + +pre code { + overflow: auto; + word-wrap: normal; + white-space: pre; +} + +pre .img { + margin: 5px 0; +} + +pre .img img { + background-color: #fff; + display: block; + height: auto; +} + +code a, pre a { + color: #375f84; +} + +a.sourceLine:hover { + text-decoration: none; +} + +.fl {color: #1514b5;} +.fu {color: #000000;} /* function */ +.ch,.st {color: #036a07;} /* string */ +.kw {color: #264D66;} /* keyword */ +.co {color: #888888;} /* comment */ + +.message { color: black; font-weight: bolder;} +.error { color: orange; font-weight: bolder;} +.warning { color: #6A0366; font-weight: bolder;} + +/* Clipboard --------------------------*/ + +.hasCopyButton { + position: relative; +} + +.btn-copy-ex { + position: absolute; + right: 0; + top: 0; + visibility: hidden; +} + +.hasCopyButton:hover button.btn-copy-ex { + visibility: visible; +} + +/* headroom.js ------------------------ */ + +.headroom { + will-change: transform; + transition: transform 200ms linear; +} +.headroom--pinned { + transform: translateY(0%); +} +.headroom--unpinned { + transform: translateY(-100%); +} + +/* mark.js ----------------------------*/ + +mark { + background-color: rgba(255, 255, 51, 0.5); + border-bottom: 2px solid rgba(255, 153, 51, 0.3); + padding: 1px; +} + +/* vertical spacing after htmlwidgets */ +.html-widget { + margin-bottom: 10px; +} + +/* fontawesome ------------------------ */ + +.fab { + font-family: "Font Awesome 5 Brands" !important; +} + +/* don't display links in code chunks when printing */ +/* source: https://stackoverflow.com/a/10781533 */ +@media print { + code a:link:after, code a:visited:after { + content: ""; + } +} diff --git a/docs/pkgdown.js b/docs/pkgdown.js new file mode 100644 index 00000000..7e7048fa --- /dev/null +++ b/docs/pkgdown.js @@ -0,0 +1,108 @@ +/* http://gregfranko.com/blog/jquery-best-practices/ */ +(function($) { + $(function() { + + $('.navbar-fixed-top').headroom(); + + $('body').css('padding-top', $('.navbar').height() + 10); + $(window).resize(function(){ + $('body').css('padding-top', $('.navbar').height() + 10); + }); + + $('[data-toggle="tooltip"]').tooltip(); + + var cur_path = paths(location.pathname); + var links = $("#navbar ul li a"); + var max_length = -1; + var pos = -1; + for (var i = 0; i < links.length; i++) { + if (links[i].getAttribute("href") === "#") + continue; + // Ignore external links + if (links[i].host !== location.host) + continue; + + var nav_path = paths(links[i].pathname); + + var length = prefix_length(nav_path, cur_path); + if (length > max_length) { + max_length = length; + pos = i; + } + } + + // Add class to parent
  • , and enclosing
  • if in dropdown + if (pos >= 0) { + var menu_anchor = $(links[pos]); + menu_anchor.parent().addClass("active"); + menu_anchor.closest("li.dropdown").addClass("active"); + } + }); + + function paths(pathname) { + var pieces = pathname.split("/"); + pieces.shift(); // always starts with / + + var end = pieces[pieces.length - 1]; + if (end === "index.html" || end === "") + pieces.pop(); + return(pieces); + } + + // Returns -1 if not found + function prefix_length(needle, haystack) { + if (needle.length > haystack.length) + return(-1); + + // Special case for length-0 haystack, since for loop won't run + if (haystack.length === 0) { + return(needle.length === 0 ? 0 : -1); + } + + for (var i = 0; i < haystack.length; i++) { + if (needle[i] != haystack[i]) + return(i); + } + + return(haystack.length); + } + + /* Clipboard --------------------------*/ + + function changeTooltipMessage(element, msg) { + var tooltipOriginalTitle=element.getAttribute('data-original-title'); + element.setAttribute('data-original-title', msg); + $(element).tooltip('show'); + element.setAttribute('data-original-title', tooltipOriginalTitle); + } + + if(ClipboardJS.isSupported()) { + $(document).ready(function() { + var copyButton = ""; + + $(".examples, div.sourceCode").addClass("hasCopyButton"); + + // Insert copy buttons: + $(copyButton).prependTo(".hasCopyButton"); + + // Initialize tooltips: + $('.btn-copy-ex').tooltip({container: 'body'}); + + // Initialize clipboard: + var clipboardBtnCopies = new ClipboardJS('[data-clipboard-copy]', { + text: function(trigger) { + return trigger.parentNode.textContent; + } + }); + + clipboardBtnCopies.on('success', function(e) { + changeTooltipMessage(e.trigger, 'Copied!'); + e.clearSelection(); + }); + + clipboardBtnCopies.on('error', function() { + changeTooltipMessage(e.trigger,'Press Ctrl+C or Command+C to copy'); + }); + }); + } +})(window.jQuery || window.$) diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml new file mode 100644 index 00000000..48cff625 --- /dev/null +++ b/docs/pkgdown.yml @@ -0,0 +1,7 @@ +pandoc: 1.19.2.1 +pkgdown: 1.5.1 +pkgdown_sha: ~ +articles: + bambu: bambu.html +last_built: 2020-05-29T02:32Z + diff --git a/docs/reference/SEtoGTF.html b/docs/reference/SEtoGTF.html new file mode 100644 index 00000000..2b24d9c6 --- /dev/null +++ b/docs/reference/SEtoGTF.html @@ -0,0 +1,165 @@ + + + + + + + + +transcript to gene expression — SEtoGTF • bambu + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Outputs a GTF dataframe for the nanorna-bam nextflow pipeline

    +
    + +
    SEtoGTF(se)
    + +

    Arguments

    + + + + + + +
    se

    a summarizedExperiment object from bambu

    + +

    Value

    + +

    gtf a GTF dataframe

    + +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.5.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/bambu.html b/docs/reference/bambu.html new file mode 100644 index 00000000..dc910571 --- /dev/null +++ b/docs/reference/bambu.html @@ -0,0 +1,239 @@ + + + + + + + + +long read isoform reconstruction and quantification — bambu • bambu + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    This function takes bam file of genomic alignments and performs isoform recontruction and gene and transcript expression quantification. +It also allows saving of read class files of alignments, extending provided annotations, and quantification based on extended annotations. +When multiple samples are provided, extended annotations will be combined across samples to allow comparison.

    +
    + +
    bambu(
    +  reads = NULL,
    +  readClass.file = NULL,
    +  readClass.outputDir = NULL,
    +  annotations = NULL,
    +  genomeSequence = NULL,
    +  stranded = FALSE,
    +  ncore = 1,
    +  yieldSize = NULL,
    +  isoreParameters = NULL,
    +  emParameters = NULL,
    +  extendAnnotations = TRUE,
    +  verbose = FALSE
    +)
    + +

    Arguments

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    reads

    A string or a vector of strings specifying the paths of bam files for genomic alignments, or a BamFile object or a BamFileList object (see Rsamtools).

    readClass.file

    A string or a vector of strings specifying the read class files that are saved during previous run of bambu.

    readClass.outputDir

    A string variable specifying the path to where read class files will be saved.

    annotations

    A TxDb object or A GRangesList object obtained by prepareAnnotations or prepareAnnotationsFromGTF.

    genomeSequence

    A fasta file or a BSGenome object.

    ncore

    specifying number of cores used when parallel processing is used, defaults to 1.

    yieldSize

    see Rsamtools.

    isoreParameters

    A list of controlling parameters for isoform reconstruction process:

      +
    • prefix specifying prefix for new gene Ids (genePrefix.number), defaults to empty

    • +
    • remove.subsetTx indicating whether filter to remove read classes which are a subset of known transcripts(), defaults to TRUE

    • +
    • min.readCount specifying minimun read count to consider a read class valid in a sample, defaults to 2

    • +
    • min.readFractionByGene specifying minimum relative read count per gene, highly expressed genes will have many high read count low relative abundance transcripts that can be filtered, defaults to 0.05

    • +
    • min.sampleNumber specifying minimum sample number with minimum read count, defaults to 1

    • +
    • min.exonDistance specifying minum distance to known transcript to be considered valid as new, defaults to 35

    • +
    • min.exonOverlap specifying minimum number of bases shared with annotation to be assigned to the same gene id, defaults 10 base pairs

    • +
    emParameters

    A list of controlling parameters for quantification algorithm estimation process:

      +
    • maxiter specifying maximum number of run interations, defaults to 10000.

    • +
    • bias specifying whether to correct for bias, defaults to FALSE.

    • +
    • conv specifying the covergence trheshold control, defaults to 0.0001.

    • +
    extendAnnotations

    A logical variable indicating whether annotations are to be extended for quantification.

    verbose

    A logical variable indicating whether processing messages will be printed.

    + +

    Value

    + +

    A list of two SummarizedExperiment object for transcript expression and gene expression.

    +

    Details

    + +

    Main function

    + +

    Examples

    +
    
    +  
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.5.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/index.html b/docs/reference/index.html new file mode 100644 index 00000000..52aec1ab --- /dev/null +++ b/docs/reference/index.html @@ -0,0 +1,215 @@ + + + + + + + + +Function reference • bambu + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +

    All functions

    +

    +
    +

    bambu()

    +

    long read isoform reconstruction and quantification

    +

    plot(<bambu>)

    +

    plot.bambu

    +

    prepareAnnotations()

    +

    prepare annotations from txdb object

    +

    prepareAnnotationsFromGTF()

    +

    Prepare annotation granges object from GTF file into a GRangesList

    +

    readFromGTF()

    +

    convert a GTF file into a GRangesList

    +

    transcriptToGeneExpression()

    +

    transcript to gene expression

    +

    writeBambuOutput()

    +

    Write bambu results to GTF and transcript/gene-count files

    +

    writeToGTF()

    +

    write GRangeslist into GTF file

    +
    + + +
    + + +
    + + +
    +

    Site built with pkgdown 1.5.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/plot.bambu.html b/docs/reference/plot.bambu.html new file mode 100644 index 00000000..f1248854 --- /dev/null +++ b/docs/reference/plot.bambu.html @@ -0,0 +1,185 @@ + + + + + + + + +plot.bambu — plot.bambu • bambu + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +
    + +
    # S3 method for bambu
    +plot(
    +  se,
    +  group.variable = NULL,
    +  type = c("annotation", "pca", "heatmap"),
    +  gene_id = NULL,
    +  transcript_id = NULL
    +)
    + +

    Arguments

    + + + + + + +
    se

    An summarized experiment object obtained from bambu or transcriptToGene.} + +{group.variable}{Variable for grouping in plot, has be to provided if choosing to plot PCA.} + +{type}{plot type variable, a values of annotation for a single gene with heatmap for isoform expressions, pca, or heatmap, see details.} + +{gene_id}{specifying the gene_id for plotting gene annotation, either gene_id or transcript_id has to be provided when type = "annotation".} + +{transcript_id}{specifying the transcript_id for plotting transcript annotation, either gene_id or transcript_id has to be provided when type = "annotation"} +} +{ +A heatmap plot for all samples +} +{ +plotSEOuptut +} +{ +type indicates the type of plots to be plotted. There are two types of plots can be chosen, PCA or heatmap. +}

    + + +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.5.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/prepareAnnotations.html b/docs/reference/prepareAnnotations.html new file mode 100644 index 00000000..f8795e1f --- /dev/null +++ b/docs/reference/prepareAnnotations.html @@ -0,0 +1,171 @@ + + + + + + + + +prepare annotations from txdb object — prepareAnnotations • bambu + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Function to prepare tables and genomic ranges for transript reconstruction using a txdb object

    +
    + +
    prepareAnnotations(txdb)
    + +

    Arguments

    + + + + + + +
    txdb

    a TxDb object

    + +

    Value

    + +

    A GrangesList object

    + +

    Examples

    +
    if (FALSE) { + library(TxDb.Hsapiens.UCSC.hg38.knownGene) + txdb <- TxDb.Hsapiens.UCSC.hg38.knownGene + prepareAnnotations(txdb) + }
    +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.5.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/prepareAnnotationsFromGTF.html b/docs/reference/prepareAnnotationsFromGTF.html new file mode 100644 index 00000000..e4ef85be --- /dev/null +++ b/docs/reference/prepareAnnotationsFromGTF.html @@ -0,0 +1,167 @@ + + + + + + + + +Prepare annotation granges object from GTF file into a <code>GRangesList</code> — prepareAnnotationsFromGTF • bambu + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Prepare annotation granges object from GTF file

    +
    + +
    prepareAnnotationsFromGTF(file)
    + +

    Arguments

    + + + + + + +
    file

    a GTF file

    + +

    Value

    + + + + + +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.5.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/readFromGTF.html b/docs/reference/readFromGTF.html new file mode 100644 index 00000000..63876c38 --- /dev/null +++ b/docs/reference/readFromGTF.html @@ -0,0 +1,169 @@ + + + + + + + + +convert a GTF file into a GRangesList — readFromGTF • bambu + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Outputs GRangesList object from reading a GTF file

    +
    + +
    readFromGTF(file)
    + +

    Arguments

    + + + + + + +
    file

    a .gtf file

    + +

    Value

    + +

    grlist a GRangesList object, with two columns

      +
    • TXNAME specifying prefix for new gene Ids (genePrefix.number), defaults to empty

    • +
    • GENEID indicating whether filter to remove read classes which are a subset of known transcripts(), defaults to TRUE

    • +
    + + +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.5.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/transcriptToGeneExpression.html b/docs/reference/transcriptToGeneExpression.html new file mode 100644 index 00000000..0c6cac70 --- /dev/null +++ b/docs/reference/transcriptToGeneExpression.html @@ -0,0 +1,162 @@ + + + + + + + + +transcript to gene expression — transcriptToGeneExpression • bambu + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Reduce transcript expression to gene expression

    +
    + +
    transcriptToGeneExpression(se)
    + +

    Arguments

    + + + + + + +
    se

    a summarizedExperiment object from bambu

    + + +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.5.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/writeBambuOutput.html b/docs/reference/writeBambuOutput.html new file mode 100644 index 00000000..0861515d --- /dev/null +++ b/docs/reference/writeBambuOutput.html @@ -0,0 +1,170 @@ + + + + + + + + +Write bambu results to GTF and transcript/gene-count files — writeBambuOutput • bambu + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Outputs a GTF file, transcript-count file, and gene-count file from bambu

    +
    + +
    writeBambuOutput(se, path)
    + +

    Arguments

    + + + + + + + + + + +
    se

    a summarizedExperiment object from bambu

    path

    the destination of the output files (gtf, transcript counts, and gene counts)

    + +

    Value

    + +

    The function will generate three files, a .gtf file for the annotations, +two .txt files for transcript and gene counts respectively.

    + +
    + +
    + + +
    + + +
    +

    Site built with pkgdown 1.5.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/writeToGTF.html b/docs/reference/writeToGTF.html new file mode 100644 index 00000000..ea71bb29 --- /dev/null +++ b/docs/reference/writeToGTF.html @@ -0,0 +1,173 @@ + + + + + + + + +write GRangeslist into GTF file — writeToGTF • bambu + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Write annotation GRangesList into a GTF file

    +
    + +
    writeToGTF(annotation, file, geneIDs = NULL)
    + +

    Arguments

    + + + + + + + + + + + + + + +
    annotation

    a GRangesList object

    file

    the output gtf file name

    geneIDs

    an optional dataframe of geneIDs (column 2) with the corresponding transcriptIDs (column 1)

    + +

    Value

    + +

    gtf a GTF dataframe

    + +
    + +
    + + + +
    + + + + + + + + diff --git a/figures/bambu_design_highres.png b/figures/bambu_design_highres.png new file mode 100644 index 00000000..f8dc93af Binary files /dev/null and b/figures/bambu_design_highres.png differ diff --git a/figures/transparent-bambu.png b/figures/transparent-bambu.png index 6ed0d6b6..a9a1efe7 100644 Binary files a/figures/transparent-bambu.png and b/figures/transparent-bambu.png differ diff --git a/inst/extdata/annotationGranges_txdbGrch38_91_chr9_1_1000000.rds b/inst/extdata/annotationGranges_txdbGrch38_91_chr9_1_1000000.rds index be16bd14..1a8d091e 100644 Binary files a/inst/extdata/annotationGranges_txdbGrch38_91_chr9_1_1000000.rds and b/inst/extdata/annotationGranges_txdbGrch38_91_chr9_1_1000000.rds differ diff --git a/inst/extdata/extendedAnnotationGranges_txdbGrch38_91_chr9_1_1000000.rds b/inst/extdata/extendedAnnotationGranges_txdbGrch38_91_chr9_1_1000000.rds index fe3dc06f..d68bc6fb 100644 Binary files a/inst/extdata/extendedAnnotationGranges_txdbGrch38_91_chr9_1_1000000.rds and b/inst/extdata/extendedAnnotationGranges_txdbGrch38_91_chr9_1_1000000.rds differ diff --git a/inst/extdata/readGrgList_SGNex_A549_directRNA_replicate5_run1_chr9_1_1000000.rds b/inst/extdata/readGrgList_SGNex_A549_directRNA_replicate5_run1_chr9_1_1000000.rds index 84305d1d..bacfbab8 100644 Binary files a/inst/extdata/readGrgList_SGNex_A549_directRNA_replicate5_run1_chr9_1_1000000.rds and b/inst/extdata/readGrgList_SGNex_A549_directRNA_replicate5_run1_chr9_1_1000000.rds differ diff --git a/inst/extdata/seIsoReCombined_SGNex_A549_directRNA_replicate5_run1_chr9_1_1000000.rds b/inst/extdata/seIsoReCombined_SGNex_A549_directRNA_replicate5_run1_chr9_1_1000000.rds index e213c071..057588f7 100644 Binary files a/inst/extdata/seIsoReCombined_SGNex_A549_directRNA_replicate5_run1_chr9_1_1000000.rds and b/inst/extdata/seIsoReCombined_SGNex_A549_directRNA_replicate5_run1_chr9_1_1000000.rds differ diff --git a/inst/extdata/seIsoReRef_SGNex_A549_directRNA_replicate5_run1_chr9_1_1000000.rds b/inst/extdata/seIsoReRef_SGNex_A549_directRNA_replicate5_run1_chr9_1_1000000.rds index 6aa618f8..d2d3384d 100644 Binary files a/inst/extdata/seIsoReRef_SGNex_A549_directRNA_replicate5_run1_chr9_1_1000000.rds and b/inst/extdata/seIsoReRef_SGNex_A549_directRNA_replicate5_run1_chr9_1_1000000.rds differ diff --git a/inst/extdata/seOutputCombinedExtended_SGNex_A549_directRNA_replicate5_run1_chr9_1_1000000.rds b/inst/extdata/seOutputCombinedExtended_SGNex_A549_directRNA_replicate5_run1_chr9_1_1000000.rds index cfae8143..9d8ccfbf 100644 Binary files a/inst/extdata/seOutputCombinedExtended_SGNex_A549_directRNA_replicate5_run1_chr9_1_1000000.rds and b/inst/extdata/seOutputCombinedExtended_SGNex_A549_directRNA_replicate5_run1_chr9_1_1000000.rds differ diff --git a/inst/extdata/seOutputCombined_SGNex_A549_directRNA_replicate5_run1_chr9_1_1000000.rds b/inst/extdata/seOutputCombined_SGNex_A549_directRNA_replicate5_run1_chr9_1_1000000.rds index 3eb1124b..8638bbb6 100644 Binary files a/inst/extdata/seOutputCombined_SGNex_A549_directRNA_replicate5_run1_chr9_1_1000000.rds and b/inst/extdata/seOutputCombined_SGNex_A549_directRNA_replicate5_run1_chr9_1_1000000.rds differ diff --git a/inst/extdata/seOutputExtended_SGNex_A549_directRNA_replicate5_run1_chr9_1_1000000.rds b/inst/extdata/seOutputExtended_SGNex_A549_directRNA_replicate5_run1_chr9_1_1000000.rds index ba4bdedd..5b829cb0 100644 Binary files a/inst/extdata/seOutputExtended_SGNex_A549_directRNA_replicate5_run1_chr9_1_1000000.rds and b/inst/extdata/seOutputExtended_SGNex_A549_directRNA_replicate5_run1_chr9_1_1000000.rds differ diff --git a/inst/extdata/seOutput_SGNex_A549_directRNA_replicate5_run1_chr9_1_1000000.rds b/inst/extdata/seOutput_SGNex_A549_directRNA_replicate5_run1_chr9_1_1000000.rds index d0bc6061..d57a12ef 100644 Binary files a/inst/extdata/seOutput_SGNex_A549_directRNA_replicate5_run1_chr9_1_1000000.rds and b/inst/extdata/seOutput_SGNex_A549_directRNA_replicate5_run1_chr9_1_1000000.rds differ diff --git a/inst/extdata/seReadClassStranded_SGNex_A549_directRNA_replicate5_run1_chr9_1_1000000.rds b/inst/extdata/seReadClassStranded_SGNex_A549_directRNA_replicate5_run1_chr9_1_1000000.rds index 029de162..e51391ff 100644 Binary files a/inst/extdata/seReadClassStranded_SGNex_A549_directRNA_replicate5_run1_chr9_1_1000000.rds and b/inst/extdata/seReadClassStranded_SGNex_A549_directRNA_replicate5_run1_chr9_1_1000000.rds differ diff --git a/inst/extdata/seReadClassUnstranded_SGNex_A549_directRNA_replicate5_run1_chr9_1_1000000.rds b/inst/extdata/seReadClassUnstranded_SGNex_A549_directRNA_replicate5_run1_chr9_1_1000000.rds index 41b9b1aa..7318fb34 100644 Binary files a/inst/extdata/seReadClassUnstranded_SGNex_A549_directRNA_replicate5_run1_chr9_1_1000000.rds and b/inst/extdata/seReadClassUnstranded_SGNex_A549_directRNA_replicate5_run1_chr9_1_1000000.rds differ diff --git a/inst/extdata/seReadClass_SGNex_A549_directRNA_replicate5_run1_chr9_1_1000000.rds b/inst/extdata/seReadClass_SGNex_A549_directRNA_replicate5_run1_chr9_1_1000000.rds index 03b00443..875b83c7 100644 Binary files a/inst/extdata/seReadClass_SGNex_A549_directRNA_replicate5_run1_chr9_1_1000000.rds and b/inst/extdata/seReadClass_SGNex_A549_directRNA_replicate5_run1_chr9_1_1000000.rds differ diff --git a/man/bambu.Rd b/man/bambu.Rd index 390a5eab..ba1e5ca5 100644 --- a/man/bambu.Rd +++ b/man/bambu.Rd @@ -6,13 +6,15 @@ \usage{ bambu( reads = NULL, - readclass.file = NULL, - outputReadClassDir = NULL, + readClass.file = NULL, + readClass.outputDir = NULL, annotations = NULL, genomeSequence = NULL, - algo.control = NULL, + stranded = FALSE, + ncore = 1, yieldSize = NULL, - ir.control = NULL, + isoreParameters = NULL, + emParameters = NULL, extendAnnotations = TRUE, verbose = FALSE ) @@ -20,27 +22,20 @@ bambu( \arguments{ \item{reads}{A string or a vector of strings specifying the paths of bam files for genomic alignments, or a \code{\link{BamFile}} object or a \code{\link{BamFileList}} object (see \code{\link{Rsamtools}}).} -\item{readclass.file}{A string or a vector of strings specifying the read class files that are saved during previous run of \code{\link{bambu}}.} +\item{readClass.file}{A string or a vector of strings specifying the read class files that are saved during previous run of \code{\link{bambu}}.} -\item{outputReadClassDir}{A string variable specifying the path to where read class files will be saved.} +\item{readClass.outputDir}{A string variable specifying the path to where read class files will be saved.} \item{annotations}{A \code{\link{TxDb}} object or A GRangesList object obtained by \code{\link{prepareAnnotations}} or \code{\link{prepareAnnotationsFromGTF}}.} \item{genomeSequence}{A fasta file or a BSGenome object.} -\item{algo.control}{A list of controlling parameters for quantification algorithm estimation process: -\itemize{ - \item ncore specifying number of cores used when parallel processing is used, defaults to 1. - \item maxiter specifying maximum number of run interations, defaults to 10000. - \item bias_correction specifying whether to correct for bias, defaults to FALSE. - \item convcontrol specifying the covergence trheshold control, defaults to 0.0001. -}} +\item{ncore}{specifying number of cores used when parallel processing is used, defaults to 1.} \item{yieldSize}{see \code{\link{Rsamtools}}.} -\item{ir.control}{A list of controlling parameters for isoform reconstruction process: +\item{isoreParameters}{A list of controlling parameters for isoform reconstruction process: \itemize{ - \item whether stranded, defaults to FALSE \item prefix specifying prefix for new gene Ids (genePrefix.number), defaults to empty \item remove.subsetTx indicating whether filter to remove read classes which are a subset of known transcripts(), defaults to TRUE \item min.readCount specifying minimun read count to consider a read class valid in a sample, defaults to 2 @@ -50,6 +45,13 @@ bambu( \item min.exonOverlap specifying minimum number of bases shared with annotation to be assigned to the same gene id, defaults 10 base pairs }} +\item{emParameters}{A list of controlling parameters for quantification algorithm estimation process: +\itemize{ + \item maxiter specifying maximum number of run interations, defaults to 10000. + \item bias specifying whether to correct for bias, defaults to FALSE. + \item conv specifying the covergence trheshold control, defaults to 0.0001. +}} + \item{extendAnnotations}{A logical variable indicating whether annotations are to be extended for quantification.} \item{verbose}{A logical variable indicating whether processing messages will be printed.} @@ -71,7 +73,7 @@ Main function ## More stringent new gene/isoform discovery: new isoforms are identified with at least 5 read count in 1 sample ## Increase EM convergence threshold to 10^(-6) seOutput <- bambu(reads, annotationGrangesList, -genomeSequence, ir.control = list(min.readCount=5), -algo.control = list(convcontrol = 10^(-6)) +genomeSequence, isoreParameters = list(min.readCount=5), +emParameters = list(conv = 10^(-6)) } } diff --git a/man/plot.bambu.Rd b/man/plot.bambu.Rd new file mode 100644 index 00000000..f296dca5 --- /dev/null +++ b/man/plot.bambu.Rd @@ -0,0 +1,34 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/plotBambu.R +\name{plot.bambu} +\alias{plot.bambu} +\title{plot.bambu} +\usage{ +\method{plot}{bambu}( + se, + group.variable = NULL, + type = c("annotation", "pca", "heatmap"), + gene_id = NULL, + transcript_id = NULL +) +} +\arguments{ +\item{se}{An summarized experiment object obtained from \code\link{bambu} or \code{\link{transcriptToGene}}.} + +\item{group.variable}{Variable for grouping in plot, has be to provided if choosing to plot PCA.} + +\item{type}{plot type variable, a values of annotation for a single gene with heatmap for isoform expressions, pca, or heatmap, see \code{\link{details}}.} + +\item{gene_id}{specifying the gene_id for plotting gene annotation, either gene_id or transcript_id has to be provided when type = "annotation".} + +\item{transcript_id}{specifying the transcript_id for plotting transcript annotation, either gene_id or transcript_id has to be provided when type = "annotation"} +} +\value{ +A heatmap plot for all samples +} +\description{ +plotSEOuptut +} +\details{ +\code{\link{type}} indicates the type of plots to be plotted. There are two types of plots can be chosen, PCA or heatmap. +} diff --git a/man/prepareAnnotationsFromGTF.Rd b/man/prepareAnnotationsFromGTF.Rd index 6761df1e..56506ce3 100644 --- a/man/prepareAnnotationsFromGTF.Rd +++ b/man/prepareAnnotationsFromGTF.Rd @@ -2,42 +2,16 @@ % Please edit documentation in R/annotationFunctions.R \name{prepareAnnotationsFromGTF} \alias{prepareAnnotationsFromGTF} -\title{prepare annotations from gtf file} +\title{Prepare annotation granges object from GTF file into a GRangesList object} \usage{ -prepareAnnotationsFromGTF( - gtf.file, - dataSource = NA, - organism = "Homo sapiens", - taxonomyId = NA, - chrominfo = NULL, - miRBaseBuild = NA, - metadata = NULL, - dbxrefTag, - ... -) +prepareAnnotationsFromGTF(file) } \arguments{ -\item{gtf.file}{A string variable indicates the path to a gtf file.} - -\item{dataSource}{as described in \code{\link{makeTxDbFromGFF}}.} - -\item{organism}{as described in \code{\link{makeTxDbFromGFF}}.} - -\item{taxonomyId}{as described in \code{\link{makeTxDbFromGFF}}.} - -\item{chrominfo}{as described in \code{\link{makeTxDbFromGFF}}.} - -\item{miRBaseBuild}{as described in \code{\link{makeTxDbFromGFF}}.} - -\item{metadata}{as described in \code{\link{makeTxDbFromGFF}}.} - -\item{dbxrefTag}{as described in \code{\link{makeTxDbFromGFF}}.} - -\item{...}{see \code{\link{makeTxDbFromGFF}}.} +\item{file}{a GTF file} } \value{ -A \code{\link{GrangesList}} object + } \description{ -Prepare annotations from gtf +Prepare annotation granges object from GTF file } diff --git a/man/readFromGTF.Rd b/man/readFromGTF.Rd new file mode 100644 index 00000000..bc58c175 --- /dev/null +++ b/man/readFromGTF.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/readWrite.R +\name{readFromGTF} +\alias{readFromGTF} +\title{convert a GTF file into a GRangesList} +\usage{ +readFromGTF(file) +} +\arguments{ +\item{file}{a \code{\link{.gtf}} file} +} +\value{ +grlist a \code{\link{GRangesList}} object, with two columns +\itemize{ + \item TXNAME specifying prefix for new gene Ids (genePrefix.number), defaults to empty + \item GENEID indicating whether filter to remove read classes which are a subset of known transcripts(), defaults to TRUE + } +} +\description{ +Outputs GRangesList object from reading a GTF file +} diff --git a/man/writeBambuOutput.Rd b/man/writeBambuOutput.Rd new file mode 100644 index 00000000..87357f29 --- /dev/null +++ b/man/writeBambuOutput.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/readWrite.R +\name{writeBambuOutput} +\alias{writeBambuOutput} +\title{Write bambu results to GTF and transcript/gene-count files} +\usage{ +writeBambuOutput(se, path) +} +\arguments{ +\item{se}{a \code{\link{SummarizedExperiment}} object from \code{\link{bambu}}} + +\item{path}{the destination of the output files (gtf, transcript counts, and gene counts)} +} +\value{ +The function will generate three files, a \code{\link{.gtf}} file for the annotations, +two \code{\link{.txt}} files for transcript and gene counts respectively. +} +\description{ +Outputs a GTF file, transcript-count file, and gene-count file from bambu +} diff --git a/man/writeToGTF.Rd b/man/writeToGTF.Rd new file mode 100644 index 00000000..d773f051 --- /dev/null +++ b/man/writeToGTF.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/readWrite.R +\name{writeToGTF} +\alias{writeToGTF} +\title{write GRangeslist into GTF file} +\usage{ +writeToGTF(annotation, file, geneIDs = NULL) +} +\arguments{ +\item{annotation}{a \code{\link{GRangesList}} object} + +\item{file}{the output gtf file name} + +\item{geneIDs}{an optional dataframe of geneIDs (column 2) with the corresponding transcriptIDs (column 1)} +} +\value{ +gtf a GTF dataframe +} +\description{ +Write annotation GRangesList into a GTF file +} diff --git a/tests/testthat/test_bambu.R b/tests/testthat/test_bambu.R index d7dc939c..fa6ebb52 100644 --- a/tests/testthat/test_bambu.R +++ b/tests/testthat/test_bambu.R @@ -9,16 +9,15 @@ test_that("generic function of isoform quantification of data.table is list of 2 # 4: Second overlapping scenario with read support for each transcript # 5: A real example of observed counts with complex overlapping scenario - ## without bias correction lapply(1:5, function(s){ - est <- bambu.quantDT(dt = get(paste0("data",s)), algo.control=list(ncore = 1)) + est <- bambu.quantDT(readClassDt = get(paste0("data",s))) expect_type(est, "list") expect_equal(est, estOutput_woBC[[s]]) }) ## with bias correction lapply(1:5, function(s){ - est <- bambu.quantDT(dt = get(paste0("data",s)), algo.control=list(ncore = 1)) + est <- bambu.quantDT(readClassDt = get(paste0("data",s))) expect_type(est, "list") expect_equal(est, estOutput_wBC[[s]]) }) @@ -27,8 +26,8 @@ test_that("generic function of isoform quantification of data.table is list of 2 -# bambu.quantISORE -test_that("bambu.quantISORE (isoform quantification of bam file) produces expected output",{ + +test_that("bambu (isoform quantification of bam file) produces expected output",{ 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") @@ -44,20 +43,20 @@ test_that("bambu.quantISORE (isoform quantification of bam file) produces expect seCombinedExtendedExpected <- readRDS(system.file("extdata", "seOutputCombinedExtended_SGNex_A549_directRNA_replicate5_run1_chr9_1_1000000.rds", package = "bambu")) - + # test case 1: bambu with single bam file, only using annotations (default option) set.seed(1234) - se = bambu(reads = test.bam, annotations = txdb, genomeSequence = fa.file, algo.control=list(bias_correction = FALSE, ncore = 1), extendAnnotations = FALSE) + se = bambu(reads = test.bam, annotations = txdb, genomeSequence = fa.file, emParameters=list(bias = FALSE), extendAnnotations = FALSE) expect_s4_class(se, "SummarizedExperiment") expect_equal(assays(se),assays(seExpected)) set.seed(1234) - se = bambu(reads = test.bam, annotations = gr, genomeSequence = fa.file, algo.control=list(bias_correction = FALSE, ncore = 1), extendAnnotations = FALSE) + se = bambu(reads = test.bam, annotations = gr, genomeSequence = fa.file, emParameters=list(bias = FALSE), extendAnnotations = FALSE) expect_s4_class(se, "SummarizedExperiment") expect_equal(assays(se),assays(seExpected)) set.seed(1234) - seExtended = bambu(reads = test.bam, annotations = gr, genomeSequence = fa.file, algo.control=list(bias_correction = FALSE, ncore = 1), extendAnnotations = TRUE) + seExtended = bambu(reads = test.bam, annotations = gr, genomeSequence = fa.file, emParameters=list(bias = FALSE), extendAnnotations = TRUE) expect_s4_class(seExtended, "SummarizedExperiment") expect_equal(assays(seExtended),assays(seExtendedExpected)) @@ -65,22 +64,21 @@ test_that("bambu.quantISORE (isoform quantification of bam file) produces expect # test case 2: bambu with multiple bam file, only using annotations (default option), yieldSize lower than read count set.seed(1234) - seCombined = bambu(reads = Rsamtools::BamFileList(c(test.bam, test.bam), yieldSize = 1000), annotations = gr, genomeSequence = fa.file, algo.control = list(ncore = 1), extendAnnotations = FALSE) + seCombined = bambu(reads = Rsamtools::BamFileList(c(test.bam, test.bam), yieldSize = 1000), annotations = gr, genomeSequence = fa.file, extendAnnotations = FALSE) expect_s4_class(seCombined, "SummarizedExperiment") expect_equal(seCombined,seCombinedExpected) # test case 3: bambu with multiple bam file, extending annotations, yieldSize lower than read count set.seed(1234) - seCombinedExtended = bambu(reads = Rsamtools::BamFileList(c(test.bam, test.bam), yieldSize = 1000), annotations = gr, genomeSequence = fa.file, algo.control = list(ncore = 1), extendAnnotations = TRUE) + seCombinedExtended = bambu(reads = Rsamtools::BamFileList(c(test.bam, test.bam), yieldSize = 1000), annotations = gr, genomeSequence = fa.file, extendAnnotations = TRUE) expect_s4_class(seCombinedExtended, "SummarizedExperiment") expect_equal(seCombinedExtended,seCombinedExtendedExpected) - - + }) -test_that("bambu.preprocess (isoform quantification of bam file and save readClassFiles) produces expected output",{ +test_that("bambu (isoform quantification of bam file and save readClassFiles) produces expected output",{ ## ToDo: update data sets for comparison test.bam <- system.file("extdata", "SGNex_A549_directRNA_replicate5_run1_chr9_1_1000000.bam", package = "bambu") @@ -88,7 +86,7 @@ test_that("bambu.preprocess (isoform quantification of bam file and save readCla txdb <- loadDb(system.file("extdata", "Homo_sapiens.GRCh38.91.annotations-txdb_chr9_1_1000000.sqlite", package = "bambu")) gr <- readRDS(system.file("extdata", "annotationGranges_txdbGrch38_91_chr9_1_1000000.rds", package = "bambu")) - outputReadClassDir = tempdir() + readClass.outputDir = tempdir() seExpected <- readRDS(system.file("extdata", "seOutput_SGNex_A549_directRNA_replicate5_run1_chr9_1_1000000.rds", package = "bambu")) @@ -96,48 +94,46 @@ test_that("bambu.preprocess (isoform quantification of bam file and save readCla seCombinedExpected <- readRDS(system.file("extdata", "seOutputCombined_SGNex_A549_directRNA_replicate5_run1_chr9_1_1000000.rds", package = "bambu")) seCombinedExtendedExpected <- readRDS(system.file("extdata", "seOutputCombinedExtended_SGNex_A549_directRNA_replicate5_run1_chr9_1_1000000.rds", package = "bambu")) - # test case 1: bambu with single bam file, only using annotations (default option) set.seed(1234) - se = bambu(reads = test.bam, annotations = txdb, genomeSequence = fa.file, algo.control = list(bias_correction = FALSE, ncore = 1), extendAnnotations = FALSE, outputReadClassDir = outputReadClassDir) + se = bambu(reads = test.bam, annotations = txdb, genomeSequence = fa.file, emParameters = list(bias = FALSE), extendAnnotations = FALSE, readClass.outputDir = readClass.outputDir) expect_s4_class(se, "SummarizedExperiment") expect_equal(se,seExpected) - - + + set.seed(1234) - se = bambu(reads = test.bam, annotations = gr, genomeSequence = fa.file, algo.control = list(bias_correction = FALSE, ncore = 1), extendAnnotations = FALSE, outputReadClassDir = outputReadClassDir) + se = bambu(reads = test.bam, annotations = gr, genomeSequence = fa.file, emParameters = list(bias = FALSE), extendAnnotations = FALSE, readClass.outputDir = readClass.outputDir) expect_s4_class(se, "SummarizedExperiment") expect_equal(se, seExpected) - - + + set.seed(1234) - seExtended = bambu(reads = test.bam, annotations = gr, genomeSequence = fa.file, algo.control = list(bias_correction = FALSE, ncore = 1), extendAnnotations = TRUE, outputReadClassDir = outputReadClassDir) + seExtended = bambu(reads = test.bam, annotations = gr, genomeSequence = fa.file, emParameters = list(bias = FALSE), extendAnnotations = TRUE, readClass.outputDir = readClass.outputDir) expect_s4_class(seExtended, "SummarizedExperiment") expect_equal(seExtended,seExtendedExpected) - - - + + + # test case 2: bambu with multiple bam file, only using annotations (default option), yieldSize lower than read count set.seed(1234) - seCombined = bambu(reads = Rsamtools::BamFileList(c(test.bam, test.bam), yieldSize = 1000), annotations = gr, genomeSequence = fa.file, algo.control = list(bias_correction = FALSE, ncore = 1), extendAnnotations = FALSE,outputReadClassDir = outputReadClassDir) + seCombined = bambu(reads = Rsamtools::BamFileList(c(test.bam, test.bam), yieldSize = 1000), annotations = gr, genomeSequence = fa.file, extendAnnotations = FALSE,readClass.outputDir = readClass.outputDir) expect_s4_class(seCombined, "SummarizedExperiment") expect_equal(seCombined,seCombinedExpected) - - - + + + # test case 3: bambu with multiple bam file, extending annotations, yieldSize lower than read count set.seed(1234) - seCombinedExtended = bambu(reads = Rsamtools::BamFileList(c(test.bam, test.bam), yieldSize = 1000), annotations = gr, genomeSequence = fa.file, algo.control = list(bias_correction = FALSE, ncore = 1), extendAnnotations = TRUE, outputReadClassDir = outputReadClassDir) + seCombinedExtended = bambu(reads = Rsamtools::BamFileList(c(test.bam, test.bam), yieldSize = 1000), annotations = gr, genomeSequence = fa.file, extendAnnotations = TRUE, readClass.outputDir = readClass.outputDir) expect_s4_class(seCombinedExtended, "SummarizedExperiment") expect_equal(seCombinedExtended, seCombinedExtendedExpected) - - + }) -test_that("bambu.combineQuantify (isoform quantification of saved readClassFiles) produces expected output",{ +test_that("bambu (isoform quantification of saved readClassFiles) produces expected output",{ ## ToDo: update data sets for comparison seReadClass1 <- system.file("extdata", "seReadClass_SGNex_A549_directRNA_replicate5_run1_chr9_1_1000000.rds", package = "bambu") gr <- readRDS(system.file("extdata", "annotationGranges_txdbGrch38_91_chr9_1_1000000.rds", package = "bambu")) @@ -151,26 +147,31 @@ test_that("bambu.combineQuantify (isoform quantification of saved readClassFiles # test case 1: bambu with single bam file, only using annotations (default option) set.seed(1234) - se = bambu(readclass.file = seReadClass1, annotations = gr, algo.control = list(ncore = 1), extendAnnotations = FALSE) + se = bambu(readClass.file = seReadClass1, annotations = gr, extendAnnotations = FALSE) expect_s4_class(se, "SummarizedExperiment") expect_equal(se,seExpected) set.seed(1234) - seExtended = bambu(readclass.file = seReadClass1, annotations = gr, algo.control = list(ncore = 1), extendAnnotations = TRUE) + seExtended = bambu(readClass.file = seReadClass1, annotations = gr, extendAnnotations = TRUE) expect_s4_class(seExtended, "SummarizedExperiment") expect_equal(seExtended,seExtendedExpected) # test case 2: bambu with multiple bam file, only using annotations (default option), yieldSize lower than read count set.seed(1234) - seCombined = bambu(readclass.file = c(seReadClass1, seReadClass1), annotations = gr, algo.control = list(ncore = 1), extendAnnotations = FALSE) + seCombined = bambu(readClass.file = c(seReadClass1, seReadClass1), annotations = gr, extendAnnotations = FALSE) + dimnames(assays(seCombinedExpected)$counts)[[2]] <- dimnames(assays(seCombinedExpected)$CPM)[[2]] <- colnames(seCombinedExpected) <- colData(seCombinedExpected)$name <- gsub(".bam","", colnames(seCombinedExpected)) + dimnames(seCombined@assays@data@listData$counts)[[1]] <- dimnames(seCombined@assays@data@listData$CPM)[[1]] <- rownames(seCombinedExpected) + expect_s4_class(seCombined, "SummarizedExperiment") expect_equal(seCombined,seCombinedExpected) # test case 3: bambu with multiple bam file, extending annotations, yieldSize lower than read count set.seed(1234) - seCombinedExtended = bambu(readclass.file = c(seReadClass1, seReadClass1), annotations = gr, algo.control = list(ncore = 1), extendAnnotations = TRUE) + seCombinedExtended = bambu(readClass.file = c(seReadClass1, seReadClass1), annotations = gr, extendAnnotations = TRUE) + dimnames(assays(seCombinedExtendedExpected)$counts)[[2]] <- dimnames(assays(seCombinedExtendedExpected)$CPM)[[2]] <- colnames(seCombinedExtendedExpected) <- colData(seCombinedExtendedExpected)$name <- gsub(".bam","", colnames(seCombinedExtendedExpected)) + dimnames(seCombinedExtended@assays@data@listData$counts)[[1]] <- dimnames(seCombinedExtended@assays@data@listData$CPM)[[1]] <- rownames(seCombinedExtendedExpected) expect_s4_class(seCombinedExtended, "SummarizedExperiment") expect_equal(seCombinedExtended,seCombinedExtendedExpected) diff --git a/tests/testthat/test_isore.R b/tests/testthat/test_isore.R index 0942af41..bed9d309 100644 --- a/tests/testthat/test_isore.R +++ b/tests/testthat/test_isore.R @@ -12,32 +12,32 @@ test_that("isore.constructReadClasses completes successfully", { seReadClassStrandedExpected <- readRDS(system.file("extdata", "seReadClassStranded_SGNex_A549_directRNA_replicate5_run1_chr9_1_1000000.rds", package = "bambu")) - seReadClassUnstranded <- isore.constructReadClasses(readGrgList=readGrgList, - runName='SGNex_A549_directRNA_replicate5_run1_chr9_1_1000000_unstranded', + seReadClassUnstranded <- isore.constructReadClasses(readGrgList = readGrgList, + runName ='SGNex_A549_directRNA_replicate5_run1_chr9_1_1000000_unstranded', annotationGrangesList = gr, - genomeSequence=genomeSequence, - stranded=FALSE, - quickMode=FALSE, - verbose=FALSE) + genomeSequence = genomeSequence, + stranded = FALSE, + ncore = 1, + verbose = FALSE) expect_equal(seReadClassUnstranded, seReadClassUnstrandedExpected) - seReadClassStranded <- isore.constructReadClasses(readGrgList=readGrgList, - runName='SGNex_A549_directRNA_replicate5_run1_chr9_1_1000000_stranded', + seReadClassStranded <- isore.constructReadClasses(readGrgList = readGrgList, + runName = 'SGNex_A549_directRNA_replicate5_run1_chr9_1_1000000_stranded', annotationGrangesList = gr, - genomeSequence=genomeSequence, + genomeSequence = genomeSequence, stranded=TRUE, - quickMode=FALSE, - verbose=FALSE) + ncore = 1, + verbose = FALSE) expect_equal(seReadClassStranded, seReadClassStrandedExpected) - seReadClassFromBsgenome <- isore.constructReadClasses(readGrgList=readGrgList, - runName='SGNex_A549_directRNA_replicate5_run1_chr9_1_1000000_stranded', + seReadClassFromBsgenome <- isore.constructReadClasses(readGrgList = readGrgList, + runName = 'SGNex_A549_directRNA_replicate5_run1_chr9_1_1000000_stranded', annotationGrangesList = gr, - genomeSequence="BSgenome.Hsapiens.NCBI.GRCh38", - stranded=TRUE, - quickMode=FALSE, - verbose=FALSE) + genomeSequence = "BSgenome.Hsapiens.NCBI.GRCh38", + stranded = TRUE, + ncore = 1, + verbose = FALSE) expect_equal(seReadClassFromBsgenome,seReadClassStrandedExpected) @@ -51,13 +51,13 @@ test_that("isore.combineTranscriptCandidates completes successfully", { seIsoReRefExpected <- readRDS(system.file("extdata", "seIsoReRef_SGNex_A549_directRNA_replicate5_run1_chr9_1_1000000.rds", package = "bambu")) seIsoReCombinedExpected <- readRDS(system.file("extdata", "seIsoReCombined_SGNex_A549_directRNA_replicate5_run1_chr9_1_1000000.rds", package = "bambu")) - seIsoReRef <- isore.combineTranscriptCandidates(readClassSe=seReadClass1, + seIsoReRef <- isore.combineTranscriptCandidates(readClassSe = seReadClass1, readClassSeRef = NULL, stranded = FALSE, verbose = FALSE) expect_equal(seIsoReRef, seIsoReRefExpected) - seIsoReCombined <- isore.combineTranscriptCandidates(readClassSe=seReadClass2, + seIsoReCombined <- isore.combineTranscriptCandidates(readClassSe = seReadClass2, readClassSeRef = seIsoReRef, stranded = FALSE, verbose = FALSE) @@ -75,15 +75,15 @@ test_that("isore.extendAnnotations completes successfully", { extendedAnnotationsExpected <- readRDS(system.file("extdata", "extendedAnnotationGranges_txdbGrch38_91_chr9_1_1000000.rds", package = "bambu")) - extendedAnnotations <- isore.extendAnnotations(se=seIsoReCombined, - annotationGrangesList=gr, - remove.subsetTx=TRUE, - min.readCount=2, - min.readFractionByGene=0.05, - min.sampleNumber=1, - min.exonDistance=35, - min.exonOverlap=10, - prefix='', + extendedAnnotations <- isore.extendAnnotations(se = seIsoReCombined, + annotationGrangesList = gr, + remove.subsetTx = TRUE, + min.readCount = 2, + min.readFractionByGene = 0.05, + min.sampleNumber = 1, + min.exonDistance = 35, + min.exonOverlap = 10, + prefix = '', verbose=FALSE) expect_equal(extendedAnnotations, extendedAnnotationsExpected) }) @@ -94,8 +94,8 @@ test_that("isore.estimateDistanceToAnnotations completes successfully", { seReadClass1 <- readRDS(system.file("extdata", "seReadClassUnstranded_SGNex_A549_directRNA_replicate5_run1_chr9_1_1000000.rds", package = "bambu")) extendedAnnotations <- readRDS(system.file("extdata", "extendedAnnotationGranges_txdbGrch38_91_chr9_1_1000000.rds", package = "bambu")) - seWithDist <- isore.estimateDistanceToAnnotations(seReadClass=seReadClass1, - annotationGrangesList=extendedAnnotations, + seWithDist <- isore.estimateDistanceToAnnotations(seReadClass = seReadClass1, + annotationGrangesList = extendedAnnotations, min.exonDistance = 35) expect_equal(seWithDist, seWithDistExpected) diff --git a/tests/testthat/test_plotBambu.R b/tests/testthat/test_plotBambu.R index 65f13a45..5bc710a1 100644 --- a/tests/testthat/test_plotBambu.R +++ b/tests/testthat/test_plotBambu.R @@ -24,7 +24,8 @@ test_that("visualization for transcript expression is successful",{ test_that("visualization for gene expression is successful",{ - colnames(seCombinedGeneExpected) <- c("sample1","sample2") + colnames(seCombinedGeneExpected) <- colData(seCombinedGeneExpected)$name <- c("sample1","sample2") + set.seed(1) assays(seCombinedGeneExpected)$CPM[,2] <- pmax(0, rnorm(length(assays(seCombinedGeneExpected)$CPM[,2]),assays(seCombinedGeneExpected)$CPM[,2],10)) diff --git a/tests/testthat/test_prepareAnnotations.R b/tests/testthat/test_prepareAnnotations.R index d819d95c..1c878ca5 100644 --- a/tests/testthat/test_prepareAnnotations.R +++ b/tests/testthat/test_prepareAnnotations.R @@ -31,7 +31,7 @@ test_that("prepareAnnotationsFromGTF is GRangesList",{ gr <- prepareAnnotationsFromGTF(gtf.file) - expect_equal(gr, expectedGR) + expect_equal(gr, expectedGR[order(names(expectedGR))]) expect_s4_class(gr, class = 'CompressedGRangesList') expect_named(mcols(gr), c("TXNAME", "GENEID","eqClass")) }) diff --git a/tests/testthat/test_readWrite.R b/tests/testthat/test_readWrite.R index c2c05f60..84383454 100644 --- a/tests/testthat/test_readWrite.R +++ b/tests/testthat/test_readWrite.R @@ -1,10 +1,13 @@ context("Generate GTF file from summarizedExperiment object") -test_that("read.gtf can generate a GRangesList from a GTF file",{ +test_that("readGTF can generate a GRangesList from a GTF file",{ se <- readRDS(system.file("extdata", "seOutput_SGNex_A549_directRNA_replicate5_run1_chr9_1_1000000.rds", package = "bambu")) - path <- "test_writebambu_gtf" - gtf <- write.bambu(se,path) - gr <- read.gtf(gtf) + gtf.file <- system.file("extdata", "Homo_sapiens.GRCh38.91_chr9_1_1000000.gtf", package = "bambu") + path <- tempdir() + outputGtfFile <- tempfile() + expect_null(writeBambuOutput(se,path)) + gr <- readFromGTF(gtf.file) + expect_null(writeToGTF(gr, outputGtfFile)) expect_s4_class(gr, class = 'CompressedGRangesList') expect_named(mcols(gr), c("TXNAME", "GENEID")) diff --git a/vignettes/bambu.Rmd b/vignettes/bambu.Rmd index 775e2a42..ccca631f 100644 --- a/vignettes/bambu.Rmd +++ b/vignettes/bambu.Rmd @@ -10,10 +10,253 @@ vignette: > ```{r, include = FALSE} knitr::opts_chunk$set( collapse = TRUE, - comment = "#>" + warning=FALSE, message=FALSE, + comment = "##>" ) ``` + +## Introduction +*[Bambu](https://github.com/GoekeLab/bambu)* can be used for transcript discovery and quantification from long read RNA-Seq data. Here, we present an example usage of bambu on Nanopore long read RNA-Sequencing from 2 human cancer cell lines + + +## Data description +To demonstrate the usage of *Bambu*, we used the data in NanoporeRNASeq, which contains single chromosome RNA-Seq data from two common cell lines K562 and MCF7. Each of these cell line has three +replicates, with 1 direct RNA sequencing data and 2 cDNA sequencing data. + +```{r, include = FALSE} +# To be removed later +devtools::load_all("/mnt/ont/s3.ontdata.store.genome.sg/projects/bambuAnddatapackage/PrepareForBambu/bambu/") +#To be removed later +devtools::load_all("/mnt/ont/s3.ontdata.store.genome.sg/projects/bambuAnddatapackage/PrepareDataPackage/NanoporeRNASeq/") +``` + ```{r setup} +library(NanoporeRNASeq) library(bambu) ``` + +```{r} +data("sample_info") +sample_info +``` + + +Name of bamfiles can be loaded as follows +```{r} +data("bamFileNames") +bamFileNames +``` + +We then loaded bam.files. +```{r} +bam.file <- system.file("extdata",bamFileNames, package = "NanoporeRNASeq") +data("annotationGrangesList_chr22_1_25409234") +``` + + +We applied *bambu* to perform EM on extended annotations +```{r} +seExtended <- bambu(reads = bam.file, annotations = annotationGrangesList_chr22_1_25409234, genomeSequence = "BSgenome.Hsapiens.NCBI.GRCh38", extendAnnotations = TRUE, verbose = FALSE, ncore = 6) +seExtended +``` +*bambu* allows quantification without isoform discovery +```{r} +se <- bambu(reads = bam.file, annotations = annotationGrangesList_chr22_1_25409234, genomeSequence = "BSgenome.Hsapiens.NCBI.GRCh38", extendAnnotations = FALSE, verbose = FALSE, ncore = 6) +se +``` + +## Check expression estimates +We can check the estimated transcript expression using heatmap: +```{r, fig.width = 8, fig.height = 6} +colData(seExtended)$groupVar <- unlist(lapply(colnames(seExtended),function(x) unlist(strsplit(x,"_"))[2])) +colnames(seExtended) <- gsub("_genome_chr22_1_25409234","",colnames(seExtended)) +colData(seExtended)$name <- gsub("_genome_chr22_1_25409234","",colData(seExtended)$name) +plot.bambu(seExtended, group.variable = "groupVar", type = "heatmap") +``` + +or with PCA plot +```{r, fig.width = 8, fig.height = 6} +colData(seExtended)$groupVar <- unlist(lapply(colnames(seExtended),function(x) unlist(strsplit(x,"_"))[2])) +plot.bambu(seExtended, group.variable = "groupVar", type = "pca") +``` + + +### Check for gene examples + +Single gene examples can also be checked using plot functions from *bambu* +```{r, fig.width = 8, fig.height = 10} +plot.bambu(seExtended, type = "annotation", gene_id = unique(rowData(seExtended)$GENEID)[10]) + +``` + +### Transcript to Gene expression +Gene expression can be obtained from transcript expression using this function: +```{r} +seGene <- transcriptToGeneExpression(seExtended) +seGene +``` + +Gene expression heatmap +```{r, fig.width = 8, fig.height = 6} +colData(seGene)$groupVar <- unlist(lapply(colnames(seGene),function(x) unlist(strsplit(x,"_"))[2])) +plot.bambu(seGene, group.variable = "groupVar", type = "heatmap") +``` + +Gene expression PCA plot +```{r, fig.width = 8, fig.height = 6} +colData(seGene)$groupVar <- unlist(lapply(colnames(seGene),function(x) unlist(strsplit(x,"_"))[2])) +plot.bambu(seGene, group.variable = "groupVar", type = "pca") +``` + +## Differentially expressed genes +We used *DESeq2* to find the differentially expressed genes: +```{r} +library(DESeq2) +dds <- DESeqDataSetFromMatrix(apply(assays(seGene)$counts,c(1,2),round),#tmp_wide[,-1], + colData = colData(seExtended), + design = ~ groupVar) +system.time(dds.deseq <- DESeq(dds)) + +deGeneRes <- DESeq2::results(dds.deseq, independentFiltering=FALSE) +``` + +```{r} +head(deGeneRes[order(deGeneRes$padj),]) +``` + +```{r} +summary(deGeneRes) +``` +```{r, fig.width = 8, fig.height = 6} +plotMA(deGeneRes, ylim = c(-3,3)) +``` + +Plotting shrinked lFC results +```{r, fig.width = 8, fig.height = 6} +resLFC <- lfcShrink(dds.deseq, coef="groupVar_MCF7_vs_K562", type="apeglm") +plotMA(resLFC, ylim = c(-3,3)) +``` + + + +## Differential expression for isoform detection +We used *DEXSeq* to detect alternative used isoforms. +```{r} +library(DRIMSeq) +count.data <- as.data.frame(rowData(seExtended)) +count.data$gene_id <- count.data$GENEID +count.data$feature_id <- count.data$TXNAME +count.data$GENEID <- count.data$TXNAME <- NULL + +count.data <- cbind(count.data, assays(seExtended)$counts) + +sample.info <- as.data.frame(colData(seExtended)) +sample.info$sample_id <- sample.info$name +sample.info$name <- NULL +d <- dmDSdata(counts=count.data, samples=sample.info) + +n_samp_gene <- 1 +n_samp_feature <- 1 +min_count_gene <- 1 +min_count_feature <- 1 +dFilter <- dmFilter(d, + min_samps_feature_expr = n_samp_feature, + min_samps_feature_prop = n_samp_feature, + min_samps_gene_expr = n_samp_gene, + min_feature_expr = min_count_feature, + min_gene_expr = min_count_gene, + min_feature_prop=0.1) +table(table(counts(dFilter)$gene_id)) ## number of isoforms + + + +``` + +```{r} +library(DEXSeq) +formulaFullModel <- as.formula("~sample + exon + groupVar:exon") + + +dxd <- DEXSeqDataSet(countData=round(as.matrix(counts(dFilter)[,-c(1:2)])), + sampleData=DRIMSeq::samples(dFilter), + design=formulaFullModel, + featureID = counts(dFilter)$feature_id, + groupID=counts(dFilter)$gene_id) + + +system.time({ + dxd <- estimateSizeFactors(dxd) + print('Size factor estimated') + dxd <- estimateDispersions(dxd, formula = formulaFullModel) + print('Dispersion estimated') + #dxd <- estimateExonFoldChanges( dxd ) + dxd <- testForDEU(dxd, fullModel = formulaFullModel) + print('DEU tested') + dxd <- estimateExonFoldChanges(dxd, fitExpToVar="groupVar") + print('Exon fold changes estimated') +}) +``` + +```{r} +dxr <- DEXSeqResults(dxd, independentFiltering=FALSE) +head(dxr) +``` + + +```{r} +library(stageR) +strp <- function(x) substr(x,1,15) +qval <- perGeneQValue(dxr) +dxr.g <- data.frame(gene=names(qval),qval) + +columns <- c("featureID","groupID","pvalue") +dxr_pval <- as.data.frame(dxr[,columns]) +head(dxr_pval) + +pConfirmation <- matrix(dxr_pval$pvalue,ncol=1) +dimnames(pConfirmation) <- list(strp(dxr_pval$featureID),"transcript") +pScreen <- qval +names(pScreen) <- strp(names(pScreen)) +tx2gene <- as.data.frame(dxr_pval[,c("featureID", "groupID")]) +for (i in 1:2) tx2gene[,i] <- strp(tx2gene[,i]) + + +stageRObj <- stageRTx(pScreen=pScreen, pConfirmation=pConfirmation, + pScreenAdjusted=TRUE, tx2gene=tx2gene) +stageRObj <- stageWiseAdjustment(stageRObj, method="dtu", alpha=0.5) +suppressWarnings({ + dex.padj <- getAdjustedPValues(stageRObj, order=FALSE, + onlySignificantGenes=TRUE) +}) +``` + +```{r} +dxrDT <- data.table(as.data.frame(dxr)) +setnames(dxrDT, old = c('groupID','featureID'), new = c('geneID','txID')) +dex.padj <- data.table(dex.padj) + +dxrDT <- dex.padj[dxrDT, on = c('geneID','txID')] +head(dxrDT) +``` + + +```{r, fig.width = 8, fig.height = 6} +dxrDT[,sigLFC2:=(padj < 0.5&(abs(log2fold_MCF7_K562)>=2))] +ggplot(dxrDT, aes(y = log2fold_MCF7_K562, x = exonBaseMean, color = as.factor(padj<0.5)))+ + geom_point(size = 0.5)+ + scale_x_log10()+ + scale_color_manual(values = c('grey','indianred'), name = "Significant")+ + xlab("Mean of normalized counts")+ + ylab("Log2 Fold change")+ + theme_minimal() + +``` + + +```{r} +dxrDT[padj<0.5,.(geneID, txID, log2fold_MCF7_K562,K562,MCF7)] +``` + + +