I would like to cache bam files and their index files using BiocFileCache. However the prefixes added to filenames in the cache can prevent downstream tools from recognizing the index. Is there a way to have the same prefix for files in a BiocFileCache?
library(Rsamtools)
library(BiocFileCache)
bam_fn <- system.file("extdata", "ex1.bam", package="Rsamtools",
mustWork=TRUE)
idx_fn <- indexBam(bam_fn)
tmpdir <- tempdir()
on.exit(unlink(tmpdir))
bfc <- BiocFileCache(tmpdir)
bid <- bfcadd(bfc, bam_fn)
iid <- bfcadd(bfc, idx_fn)
bid
#> BFC1
#> "/var/folders/r9/g3c47jrj40gc14d8qsqx7src0000gn/T//RtmpZBmvJe/14178762f5e8e_ex1.bam"
iid
#> BFC2
#> "/var/folders/r9/g3c47jrj40gc14d8qsqx7src0000gn/T//RtmpZBmvJe/141781fe8f940_ex1.bam.bai"
FWIW within Rsamtools the 'solution' is to use
BamFile(bid, iid)
.