Skip to content

Commit c66f216

Browse files
committed
allow reads be NULL when quantData is provided for quant mode only
1 parent 9f7b49b commit c66f216

File tree

2 files changed

+92
-75
lines changed

2 files changed

+92
-75
lines changed

R/bambu.R

Lines changed: 67 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -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,

R/bambu_utilityFunctions.R

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -112,25 +112,35 @@ checkInputs <- function(annotations, reads, readClass.outputDir, genomeSequence,
112112
if (!dir.exists(readClass.outputDir))
113113
stop("output folder does not exist")
114114
}
115-
116-
if (is(reads, "BamFileList")){
117-
if(is.null(genomeSequence)){
118-
stop("A genome must be provided when running bambu from bam files")
119-
}
120-
} else{
121-
# ===# Check whether provided read files are all in the same format (.bam or .rds) #===#
122-
isRDSs = all(sapply(reads, class)=="RangedSummarizedExperiment")
123-
if(!isRDSs){
124-
if (!all(grepl(".bam$", reads)) & !all(grepl(".rds$", reads)))
125-
stop("Reads should either be: a vector of paths to .bam files, ",
126-
"a vector of paths to Bambu RCfile .rds files, ",
127-
"or a list of loaded Bambu RCfiles")
128-
# if bam files are loaded in check that a genome is provided
129-
if (all(grepl(".bam$", reads)) & is.null(genomeSequence)){
115+
if(!is.null(reads)){
116+
if (is(reads, "BamFileList")){
117+
if(is.null(genomeSequence)){
130118
stop("A genome must be provided when running bambu from bam files")
131119
}
120+
} else{
121+
# ===# Check whether provided read files are all in the same format (.bam or .rds) #===#
122+
isRDSs <- all(sapply(reads, class)=="RangedSummarizedExperiment")
123+
# there is a bug here, when reads is NULL, isRDSs == TRUE
124+
if(!isRDSs){
125+
if (!all(grepl(".bam$", reads)) & !all(grepl(".rds$", reads)))
126+
stop("Reads should either be: a vector of paths to .bam files, ",
127+
"a vector of paths to Bambu RCfile .rds files, ",
128+
"or a list of loaded Bambu RCfiles")
129+
# if bam files are loaded in check that a genome is provided
130+
if (all(grepl(".bam$", reads)) & is.null(genomeSequence)){
131+
stop("A genome must be provided when running bambu from bam files")
132+
}
133+
}
132134
}
135+
}else if(is.null(quantData)){
136+
stop("Please provide either reads or quantData!",
137+
"Reads should either be: a vector of paths to .bam files, ",
138+
"a vector of paths to Bambu RCfile .rds files, ",
139+
"or a list of loaded Bambu RCfiles. ",
140+
"quantData should be output from bambu with ",
141+
"assignDist = TRUE and quant = FALSE")
133142
}
143+
134144
## check genomeSequence can't be FaFile in Windows as faFile will be dealt
135145
## strangely in windows system
136146
if (.Platform$OS.type == "windows") {

0 commit comments

Comments
 (0)