Question: Rsamtools: system.file no file found
0
2.2 years ago by
Berlin
seungjoon.kim0 wrote:

Hi, I am watching Rsamtools in Coursera and I want to get Bam file to R so I used system.file and Rsamtools.

So when I ran this command:

bamPath <- system.file("extdata", "sorted_file.bam", package = "Rsamtools", mustWork = TRUE)

It gives me error with message no file found. w/o mustWork, it just gives empty data.

I checked the path by getwd() and I checked whether there is file or not.

Can anyone solve this problem?

rsamtools bam file • 1.4k views
modified 2.2 years ago by Martin Morgan ♦♦ 23k • written 2.2 years ago by seungjoon.kim0
Answer: Rsamtools: system.file no file found
1
2.2 years ago by
Martin Morgan ♦♦ 23k
United States
Martin Morgan ♦♦ 23k wrote:

Probably you want to specify the path to your file, rather than to a file installed in the Rsamtools package. Something along the lines of

bamPath <- "c:/Users/mtmorgan/my_data/sorted_file.bam"


Thank you!!! It works well. But a question comes out. Then, why people do

bamPath <- system.file("extdata", "sorted_file.bam", package = "Rsamtools", mustWork = TRUE)

bamPath <- "c:/Users/mtmorgan/my_data/sorted_file.bam"

Because the latter one seems more short and convenience than former one.

The command system.file() is used to access data that is part of the package, e.g., used in the help page or vignette to show how the package is used. It is NOT meant to be used for your own data.

Specify the path to the file works well in analyzing overlap between Bam file and gene model  but I want to sort reads into groups by start position and system.file and Rsamtools gives me empty file.

It gives this result:

bam Large GAlignments (192883 elements, 20.4 Mb)

But when I do this....

bamfile <- system.file("extdata", "Aligned.out.sorted.bam", package = "Rsamtools")

It gives this result:

bamfile ""

So when I conduct following procedures.....

param <- ScanBamParam(what=c("seq", "qual"))
gal <- readGAlignments(bamfile, use.names = TRUE, param=param)

It gives this error:
Error in value[[3L]](cond) :
failed to open BamFile: file(s) do not exist:
''

Can you figure out what is wrong with this problem??

As before, set bamfile to the path of your actual file, "c:/Users/..."