@@ -175,81 +175,88 @@ bambu <- function(reads, annotations = NULL, genome = NULL, NDR = NULL,
175175 annotations <- checkInputs(annotations , reads ,
176176 readClass.outputDir = rcOutDir ,
177177 genomeSequence = genome , discovery = discovery ,
178- sampleNames = sampleNames , spatial = spatial )
178+ sampleNames = sampleNames , spatial = spatial , quantData = quantData )
179179 }
180180 isoreParameters <- setIsoreParameters(isoreParameters = opt.discovery )
181181 # below line is to be compatible with earlier version of running bambu
182182 if (! is.null(isoreParameters $ max.txNDR )) NDR = isoreParameters $ max.txNDR
183183
184184 emParameters <- setEmParameters(emParameters = opt.em )
185185 bpParameters <- setBiocParallelParameters(reads , ncore , verbose , demultiplexed )
186-
187- rm.readClassSe <- FALSE
188- readClassList <- reads
189- isRDSs <- all(sapply(reads , class )== " RangedSummarizedExperiment" )
190- isBamFiles <- ! isRDSs
191- warnings <- NULL
192- if (! isRDSs )
193- isBamFiles <- ifelse(! is(reads , " BamFileList" ),
194- all(grepl(" .bam$" , reads )), FALSE )
195- if (isBamFiles | is(reads , " BamFileList" )) {
196- if (length(reads ) > 10 & (is.null(rcOutDir ))) {
197- rcOutDir <- tempdir() # >=10 samples, save to temp folder
198- message(" There are more than 10 samples, read class files
186+ # only when reads is not NULL, this proceed, otherwise, it will jump to quant step
187+ if (! is.null(reads )){
188+ rm.readClassSe <- FALSE
189+ readClassList <- reads
190+ isRDSs <- all(sapply(reads , class )== " RangedSummarizedExperiment" )
191+ isBamFiles <- ! isRDSs
192+ warnings <- NULL
193+ if (! isRDSs )
194+ isBamFiles <- ifelse(! is(reads , " BamFileList" ),
195+ all(grepl(" .bam$" , reads )), FALSE )
196+ if (isBamFiles | is(reads , " BamFileList" )) {
197+ if (length(reads ) > 10 & (is.null(rcOutDir ))) {
198+ rcOutDir <- tempdir() # >=10 samples, save to temp folder
199+ message(" There are more than 10 samples, read class files
199200 will be temporarily saved to " , rcOutDir ,
200- " for more efficient processing" )
201- rm.readClassSe <- TRUE # remove temporary read class files
201+ " for more efficient processing" )
202+ rm.readClassSe <- TRUE # remove temporary read class files
203+ }
204+ message(" --- Start generating read class files ---" )
205+ readClassList <- bambu.processReads(reads , annotations ,
206+ genomeSequence = genome ,
207+ readClass.outputDir = rcOutDir , yieldSize = yieldSize ,
208+ bpParameters = bpParameters , stranded = stranded , verbose = verbose ,
209+ isoreParameters = isoreParameters , trackReads = trackReads ,
210+ fusionMode = fusionMode ,
211+ processByChromosome = processByChromosome , processByBam = processByBam ,
212+ demultiplexed = demultiplexed ,
213+ sampleNames = sampleNames , cleanReads = cleanReads ,
214+ dedupUMI = dedupUMI ,barcodesToFilter = barcodesToFilter )
202215 }
203- message(" --- Start generating read class files ---" )
204- readClassList <- bambu.processReads(reads , annotations ,
205- genomeSequence = genome ,
206- readClass.outputDir = rcOutDir , yieldSize = yieldSize ,
207- bpParameters = bpParameters , stranded = stranded , verbose = verbose ,
208- isoreParameters = isoreParameters , trackReads = trackReads ,
209- fusionMode = fusionMode ,
210- processByChromosome = processByChromosome , processByBam = processByBam ,
211- demultiplexed = demultiplexed ,
212- sampleNames = sampleNames , cleanReads = cleanReads ,
213- dedupUMI = dedupUMI ,barcodesToFilter = barcodesToFilter )
214- }
215-
216- # warnings = handleWarnings(readClassList, verbose)
217- if (! discovery & ! assignDist & ! quant ) return (readClassList )
218- if (discovery ) {
219- message(" --- Start extending annotations ---" )
220- extendedAnnotations <- bambu.extendAnnotations(readClassList , annotations , NDR ,
221- isoreParameters , stranded , bpParameters , fusionMode , verbose )
222- metadata(extendedAnnotations )$ warnings = warnings
223216
224- # ### cluster based transcript discovery
225- if (! is.null(clusters )){
226- annotations.clusters <- isore.extendAnnotations.clusters(readClassList ,
227- annotations , clusters , NDR ,
228- isoreParameters , stranded , bpParameters , fusionMode , verbose = FALSE )
229- metadata(extendedAnnotations )$ clusters <- annotations.clusters
217+ # warnings = handleWarnings(readClassList, verbose)
218+ if (! discovery & ! assignDist & ! quant ) return (readClassList )
219+ if (discovery ) {
220+ message(" --- Start extending annotations ---" )
221+ extendedAnnotations <- bambu.extendAnnotations(readClassList , annotations , NDR ,
222+ isoreParameters , stranded , bpParameters , fusionMode , verbose )
223+ metadata(extendedAnnotations )$ warnings = warnings
224+
225+ # ### cluster based transcript discovery
226+ if (! is.null(clusters )){
227+ annotations.clusters <- isore.extendAnnotations.clusters(readClassList ,
228+ annotations , clusters , NDR ,
229+ isoreParameters , stranded , bpParameters , fusionMode , verbose = FALSE )
230+ metadata(extendedAnnotations )$ clusters <- annotations.clusters
231+ }
232+ annotations <- extendedAnnotations
233+
234+ if (! quant & ! assignDist ) return (annotations )
235+ }
236+ if (assignDist ){
237+ message(" --- Start calculating equivilance classes ---" )
238+ quantData <- bplapply(readClassList ,
239+ FUN = assignReadClasstoTranscripts ,
240+ annotations = annotations ,
241+ isoreParameters = isoreParameters ,
242+ verbose = verbose ,
243+ demultiplexed = demultiplexed ,
244+ spatial = spatial ,
245+ returnDistTable = returnDistTable ,
246+ trackReads = trackReads ,
247+ BPPARAM = bpParameters )
248+ if (! quant ) return (quantData )
230249 }
231- annotations <- extendedAnnotations
232-
233- if (! quant & ! assignDist ) return (annotations )
234- }
235-
236- if (assignDist ){
237- message(" --- Start calculating equivilance classes ---" )
238- quantData <- bplapply(readClassList ,
239- FUN = assignReadClasstoTranscripts ,
240- annotations = annotations ,
241- isoreParameters = isoreParameters ,
242- verbose = verbose ,
243- demultiplexed = demultiplexed ,
244- spatial = spatial ,
245- returnDistTable = returnDistTable ,
246- trackReads = trackReads ,
247- BPPARAM = bpParameters )
248- if (! quant ) return (quantData )
249250 }
251+
252+
250253
251254 if (quant ) {
252255 message(" --- Start isoform EM quantification ---" )
256+ # the step below is a bit confusing but it seems to be the only way
257+ # if discovery == TRUE, extendAnnotations happen already
258+ # if users want discovery at this step, assign a desired value for NDR with discovery being FALSE
259+ # here also reads need to be not file or bam file or rc file
253260 if (! is.null(NDR ) & ! discovery )
254261 annotations <- setNDR(annotations , NDR ,
255262 prefix = isoreParameters $ prefix ,
0 commit comments