Skip to content

Commit 824db18

Browse files
author
Sui Yue
authored
Merge pull request #460 from GoekeLab/singleExon_2
Remove the prefix of gtf file
2 parents e316ebe + 7de4994 commit 824db18

2 files changed

Lines changed: 35 additions & 36 deletions

File tree

R/bambu.R

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,7 @@ bambu <- function(reads, annotations = NULL, genome = NULL, NDR = NULL,
149149
processByBam <- TRUE
150150
}
151151
if(mode == "multiplexed"){
152-
if(is.null(demultiplexed))
153-
demultiplexed <- TRUE
152+
demultiplexed <- TRUE
154153
cleanReads <- TRUE
155154
opt.em <- list(degradationBias = FALSE)
156155
quant <- FALSE

R/readWrite.R

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ writeBambuOutput <- function(se, path, prefix = "", outputExtendedAnno = TRUE,
2727
dir.create(outdir, recursive = TRUE)
2828

2929
transcript_grList <- rowRanges(se)
30-
transcript_gtffn <- paste(outdir, prefix,
31-
"extended_annotations", sep = "")
30+
prefix <- ifelse(prefix != "", paste0(prefix, "_"), "")
31+
transcript_gtffn <- paste(outdir, prefix, sep = "")
3232
gtf <- writeAnnotationsToGTF(annotation = transcript_grList,
3333
file = transcript_gtffn, outputExtendedAnno = outputExtendedAnno,
3434
outputAll = outputAll, outputBambuModels = outputBambuModels, outputNovelOnly = outputNovelOnly)
3535

36-
utils::write.table(colData(se), file = paste0(outdir, "/", prefix, "sampleData.tsv"),
36+
utils::write.table(colData(se), file = paste0(transcript_gtffn, "sampleData.tsv"),
3737
sep = "\t", quote = FALSE, row.names = FALSE, col.names = TRUE)
3838
for(d in names(assays(se))){
3939
writeCountsOutput(se, varname=d,
@@ -43,17 +43,17 @@ writeBambuOutput <- function(se, path, prefix = "", outputExtendedAnno = TRUE,
4343
#write incompatible counts
4444
if(!is.null(metadata(se)$incompatibleCounts)){
4545
estimates = metadata(se)$incompatibleCounts
46-
estimatesfn <- paste(outdir, prefix, "incompatibleCounts.mtx", sep = "")
46+
estimatesfn <- paste(transcript_gtffn, "incompatibleCounts.mtx", sep = "")
4747
Matrix::writeMM(estimates, estimatesfn)
4848
}
4949
seGene <- transcriptToGeneExpression(se)
5050
writeCountsOutput(seGene, varname='counts', feature='gene',outdir, prefix)
5151
#utils::write.table(paste0(colnames(se), "-1"), file = paste0(outdir, "barcodes.tsv"), quote = FALSE, row.names = FALSE, col.names = FALSE)
5252
#R.utils::gzip(paste0(outdir, "barcodes.tsv"))
5353
txANDGenes <- data.table(as.data.frame(rowData(se))[,c("TXNAME","GENEID")])
54-
utils::write.table(txANDGenes, file = paste0(outdir, "txANDgenes.tsv"),
54+
utils::write.table(txANDGenes, file = paste0(transcript_gtffn, "txANDgenes.tsv"),
5555
sep = "\t", quote = FALSE, row.names = FALSE, col.names = FALSE)
56-
utils::write.table(names(seGene), file = paste0(outdir, "genes.tsv"),
56+
utils::write.table(names(seGene), file = paste0(transcript_gtffn, "genes.tsv"),
5757
sep = "\t", quote = FALSE, row.names = FALSE, col.names = FALSE)
5858

5959
#R.utils::gzip(paste0(outdir, "txANDgenes.tsv"))
@@ -105,16 +105,9 @@ writeCountsOutput <- function(se, varname = "counts",
105105

106106
} else{
107107
estimates <- assays(se)[[varname]]
108-
if (feature == "transcript"){
109-
estimatesfn <- paste(outdir, prefix, varname,"_",feature,".mtx", sep = "")
110-
Matrix::writeMM(estimates, estimatesfn)
111-
#R.utils::gzip(estimatesfn)
112-
113-
} else{
114-
estimatesfn <- paste(outdir, prefix, varname,"_",feature,".mtx", sep = "")
115-
Matrix::writeMM(estimates, estimatesfn)
116-
#R.utils::gzip(estimatesfn)
117-
}
108+
estimatesfn <- paste(outdir, prefix, varname,"_",feature,".mtx", sep = "")
109+
Matrix::writeMM(estimates, estimatesfn)
110+
#R.utils::gzip(estimatesfn)
118111
}
119112
}
120113

@@ -180,7 +173,7 @@ writeToGTF <- function(annotation, file, geneIDs = NULL) {
180173
frame = ".", attributes = paste(GENEID, group_name, exon_rank, NDR, txScore, txScore.noFit, novelGene, novelTranscript, txClassDescription )) %>%
181174
select(seqnames, source, feature, start, end, score,
182175
strand, frame, attributes, group_name)
183-
dfTx <- as.data.frame(range(ranges(annotation)))
176+
dfTx <- as_tibble(as.data.frame(range(ranges(annotation))))
184177
dfTx <-
185178
left_join(dfTx, geneIDs, by = c("group_name" = "TXNAME"))
186179
dfTx$group_name <-
@@ -233,24 +226,24 @@ writeToGTF <- function(annotation, file, geneIDs = NULL) {
233226
writeAnnotationsToGTF <- function(annotation, file, geneIDs = NULL, outputExtendedAnno = TRUE,
234227
outputAll = TRUE, outputBambuModels = TRUE, outputNovelOnly = TRUE){
235228
if(outputExtendedAnno){
236-
writeToGTF(annotation, paste0(file, "_extendedAnnotations.gtf"), geneIDs)
229+
writeToGTF(annotation, paste0(file, "extendedAnnotations.gtf"), geneIDs)
237230
}
238231
if(outputAll){
239232
annotationAll = setNDR(annotation, 1)
240233
if(length(annotationAll) == length(annotation))
241234
message("The current NDR threshold already outputs all transcript models. This may result in reduced precision for th extendedAnnotations and supportedTranscriptModels gtfs")
242-
writeToGTF(annotationAll, paste0(file, "_allTranscriptModels.gtf"), geneIDs)
235+
writeToGTF(annotationAll, paste0(file, "allTranscriptModels.gtf"), geneIDs)
243236
}
244237

245238
#todo - have this write bambu start and ends for annotated transcripts
246239
if(outputBambuModels){
247240
annotationBambu = annotation[!is.na(mcols(annotation)$readCount)]
248-
writeToGTF(annotationBambu, paste0(file, "_supportedTranscriptModels.gtf"), geneIDs)
241+
writeToGTF(annotationBambu, paste0(file, "supportedTranscriptModels.gtf"), geneIDs)
249242
}
250243

251244
if(outputNovelOnly){
252245
annotationNovel = annotation[mcols(annotation)$novelTranscript]
253-
writeToGTF(annotationBambu, paste0(file, "_novelTranscripts.gtf"), geneIDs)
246+
writeToGTF(annotationNovel, paste0(file, "novelTranscripts.gtf"), geneIDs)
254247
}
255248
}
256249

@@ -322,20 +315,27 @@ readFromGTF <- function(file, keep.extra.columns = NULL){
322315
#' ))
323316
#' path <- tempdir()
324317
#' writeBambuOutput(se, path)
325-
importBambuResults <- function(path, prefixes = NA){
326-
annotations = prepareAnnotations(paste0(path, "/extended_annotations.gtf"))
327-
counts = readMM(paste0(path, "/counts_transcript.mtx"))
328-
CPM = readMM(paste0(path, "/CPM_transcript.mtx"))
329-
fullLengthCounts = readMM(paste0(path, "/fullLengthCounts_transcript.mtx"))
330-
uniqueCounts = readMM(paste0(path, "/uniqueCounts_transcript.mtx"))
318+
importBambuResults <- function(path, prefixes = ""){
319+
if(prefixes == ""){
320+
path <- paste0(path,"/")
321+
} else{
322+
path <- paste0(path,"/",prefixes,"_")
323+
}
324+
annotations = prepareAnnotations(paste0(path, "extendedAnnotations.gtf"))
325+
counts = readMM(paste0(path, "counts_transcript.mtx"))
326+
CPM = readMM(paste0(path, "CPM_transcript.mtx"))
327+
fullLengthCounts = readMM(paste0(path, "fullLengthCounts_transcript.mtx"))
328+
uniqueCounts = readMM(paste0(path, "uniqueCounts_transcript.mtx"))
331329
incompatibleCounts = NULL
332-
if(file.exists(paste0(path, "/incompatibleCounts.mtx"))){
333-
incompatibleCounts = readMM(paste0(path, "/incompatibleCounts.mtx"))
330+
if(file.exists(paste0(path, "incompatibleCounts.mtx"))){
331+
incompatibleCounts = readMM(paste0(path, "incompatibleCounts.mtx"))
334332
}
335-
barcodes = read.table(paste0(path, "/barcodes.tsv"))
336-
geneIds = read.table(paste0(path, "/genes.tsv"))
337-
txIds = read.table(paste0(path, "/txANDgenes.tsv"))
338-
colData = read.table(paste0(path, "/sampleData.tsv"), header = TRUE)
333+
if(file.exists(paste0(path, "barcodes.tsv"))){
334+
incompatibleCounts = read.table(paste0(path, "barcodes.tsv"))
335+
}
336+
geneIds = read.table(paste0(path, "genes.tsv"))
337+
txIds = read.table(paste0(path, "txANDgenes.tsv"))
338+
colData = read.table(paste0(path, "sampleData.tsv"), header = TRUE)
339339
rownames(incompatibleCounts) = geneIds[,1]
340340

341341
countsSe <- SummarizedExperiment(assays = SimpleList(counts = counts,
@@ -347,4 +347,4 @@ importBambuResults <- function(path, prefixes = NA){
347347
colData(countsSe) = DataFrame(colData)
348348
colnames(countsSe) = colData[,1]
349349
return(countsSe)
350-
}
350+
}

0 commit comments

Comments
 (0)