Search
Question: cn.MOPs: Error in value[[3L]](cond) :
0
gravatar for laurabuggiotti
4 months ago by
laurabuggiotti0 wrote:

Hi,

I have been using cn.mops successfully using the following commands:

bamDataRanges <- getReadCountsFromBAM(BAMFiles, refSeqName=readLines("Chr_list.txt"), WL=1000)

results <- calcIntegerCopyNumbers(cn.mops(bamDataRanges))

segm <- as.data.frame(segmentation(results))
CNVs <- as.data.frame(cnvs(results))
CNVRegions <- as.data.frame(cnvr(results))

However, im now running it on additional bam files and i get the following error:

Error in value[[3L]](cond) : 
  failed to open BamFile: failed to load BAM index
  file: A27.realigned.rmdup.bam
Calls: getReadCountsFromBAM ... tryCatch -> tryCatchList -> tryCatchOne -> <Anonymous>
In addition: Warning message:
In doTryCatch(return(expr), name, parentenv, handler) :
  [bam_index_load] fail to load BAM index.
Execution halted

 

i have checked the header of my bam file and looks fine, would you please help me in trying to fix the error?

Thanks for your time and support,

Laura

 

 

ADD COMMENTlink modified 4 months ago by Günter Klambauer510 • written 4 months ago by laurabuggiotti0
0
gravatar for Günter Klambauer
4 months ago by
Austria
Günter Klambauer510 wrote:

I think this is not a problem of cn.mops but of an internally used function (Rsamtools?).

  • Could you run "traceback" right after the error occurs and post the result here.
  • Please check if for each BAM file, there exists an BAI (index) file. This can be generated using samtools

Regards,
Günter

ADD COMMENTlink written 4 months ago by Günter Klambauer510

Hi again,

i did try various bam files and it seems that the error occurs when using recalibrated bam files (after the BQSR step)...do you reckon there might be a link with the issue? Did you ever experience the same issue?

Thanks a lot for your time,

Laura

ADD REPLYlink written 4 months ago by laurabuggiotti0
0
gravatar for laurabuggiotti
4 months ago by
laurabuggiotti0 wrote:

Thanks for your prompt answer, here is the traceback:

> traceback()
11: stop("failed to open BamFile: ", conditionMessage(err))
10: value[[3L]](cond)
9: tryCatchOne(expr, names, parentenv, handlers[[1L]])
8: tryCatchList(expr, classes, parentenv, handlers)
7: tryCatch({
       .io_check_exists(path(con))
       index <- sub("\\.bai$", "", index(con, asNA = FALSE))
       con$.extptr <- .Call(.bamfile_open, path(con), index, "rb")
   }, error = function(err) {
       stop("failed to open BamFile: ", conditionMessage(err))
   })
6: open.BamFile(BamFile(file, index), "rb")
5: open(BamFile(file, index), "rb")
4: scanBam(bam.file, param = ScanBamParam(what = scan.what, which = range(granges.subset)))
3: scanBam(bam.file, param = ScanBamParam(what = scan.what, which = range(granges.subset)))
2: exomeCopy::countBamInGRanges(bam.file = BAMFiles[i], granges = GR,
       ...)
1: getReadCountsFromBAM(BAMFiles, refSeqName = readLines("/users/lbuggiotti/WGresRussia/cn.MOPS/Chr_list.txt"),
       WL = 1000)

Moreover i have BAI file for each bam created by using samtools.

Thanks again,

Laura

ADD COMMENTlink written 4 months ago by laurabuggiotti0
0
gravatar for Günter Klambauer
4 months ago by
Austria
Günter Klambauer510 wrote:

Ok, this is a problem either with your BAM files or with Rsamtools with the function "scanBam". Please contact the maintainers of Rsamtools.

ADD COMMENTlink written 4 months ago by Günter Klambauer510

Is the bam file index '.bai' in the same directory as the bam file, and following a standard naming convention? You could simplify debugging with

library(Rsamtools)
open(BamFile("path/to/file.bam"))

(updated to the correct path to one of your bam files as presented in the input to getReadCountsFromBAM().

ADD REPLYlink written 4 months ago by Martin Morgan ♦♦ 22k

yes, it is in the same directory, here one example of the name:

A27.realigned.rmdup.bai
A27.realigned.rmdup.bam

and got no error when opening the bam file as you suggested (via Rsamtools).

anything else you could think of?

 

ADD REPLYlink written 4 months ago by laurabuggiotti0

Look carefully at BAMFiles, and make sure that you can open each element via open(BamFile(BAMFiles[i])). Programmatically, you could do

trace(Rsamtools:::open.BamFile, quote(print(path(con))))
bamDataRanges <- getReadCountsFromBAM(BAMFiles, refSeqName=readLines("Chr_list.txt"), WL=1000)

Each time Rsamtools tries to open a BAM file, it will print the path to the file. The last path printed is the one that causes problems.

ADD REPLYlink written 4 months ago by Martin Morgan ♦♦ 22k

i have tried with one bam file as you suggested:

Tracing open.BamFile(BamFile(file, character(0))) on entry
[1] "/users/lbuggiotti/bamKorea/A27.realigned.rmdup.bam"

Identified the following reference sequences:  Chr1,Chr2......
.....
Missing "refSeqNames"! Selecting all identified reference sequence for analysis.

PLEASE BE PATIENT... this might take a while. Consider using the parallel version of this function

Error in if (WL >= sl[i]) { : missing value where TRUE/FALSE needed

Now it seems to be the window length the issue...

Thanks a lot for your help!

ADD REPLYlink written 4 months ago by laurabuggiotti0

I think I did not communicate correctly. Try just opening each element of BAMFile with

for (i in seq_along(BAMfiles)
    open(BamFile(BAMFiles[i]))

If that doesn't help then try

trace(Rsamtools:::open.BamFile, quote(print(path(con))))
bamDataRanges <- getReadCountsFromBAM(BAMFiles, refSeqName=readLines("Chr_list.txt"), WL=1000)

Your original error was about opening BAM files, so let's solve that first before moving on to errors in the cn.mops package (or errors that only occur while trying to debug other errors).

ADD REPLYlink written 4 months ago by Martin Morgan ♦♦ 22k

Ok..this is what i did:

> bamFile <- open(BamFile("bamKorea/A27.realigned.rmdup.bam"))
> bamFile
class: BamFile
path: bamKorea/A27.realigned.rmdup.bam
index: bamKorea/A27.realigned.rmdup.bai
isOpen: TRUE
yieldSize: NA
obeyQname: FALSE
asMates: FALSE

> BAMFiles = ("bamKorea/SAMN02225733.realigned.rmdup.bam")
> trace(Rsamtools:::open.BamFile, quote(print(path(con))))
Tracing function "open.BamFile" in package "Rsamtools (not-exported)"
[1] "open.BamFile"
> bamDataRanges <- getReadCountsFromBAM(BAMFiles, refSeqName=readLines("/users/lTracing open.BamFile(BamFile(file, character(0))) on entry
[1] "bamKorea/SAMN02225733.realigned.rmdup.bam"
Identified the following reference sequences:  Chr1,Chr2,Chr3,Chr4,Chr5,Chr6...

 

Using Chr1, Chr2, Chr3, Chr4, Chr5, Chr6, .... as reference.

PLEASE BE PATIENT... this might take a while. Consider using the parallel version of this function

Tracing open.BamFile(BamFile(file, character(0))) on entry
[1] "bamKorea/SAMN02225733.realigned.rmdup.bam"
Tracing open.BamFile(BamFile(file, index), "rb") on entry
[1] "bamKorea/SAMN02225733.realigned.rmdup.bam"
Error in value[[3L]](cond) :
  failed to open BamFile: failed to load BAM index
  file: bamKorea/SAMN02225733.realigned.rmdup.bam
In addition: Warning message:
In doTryCatch(return(expr), name, parentenv, handler) :
  [bam_index_load] fail to load BAM index.

Im back to square one...the problem is the index? I used samtools to produce the .bai for each of the bam; plus when i open bamFile it does see that there is a correspondent .bai.

thanks a lot for your time!

 

Hi again, i did try various bam files and it seems that the error occurs when using recalibrated bam files (after the BQSR step)...do you reckon there might be a link with the issue?

Thanks,

Laura

ADD REPLYlink modified 4 months ago • written 4 months ago by laurabuggiotti0

So what happens when you try to open the problematic BAM file

open(BamFile("bamKorea/SAMN02225733.realigned.rmdup.bam""))

?

ADD REPLYlink written 3 months ago by Martin Morgan ♦♦ 22k

it doesnt complain:

​> open(BamFile("bamKorea/SAMN02225733.realigned.rmdup.bam"))

>

Im running the scan Bam at the moment and will need sometime...

Rsamtools::scanBam("bamKorea/SAMN02225733.realigned.rmdup.bam")

 

ADD REPLYlink written 3 months ago by laurabuggiotti0

Have you tried using the full path to the BAM files in the getReadCountsFromBAM() command? By full path I mean from the root of the directory, along the lines of /home/mtmorgan/projects/bamKorea/SAMN02225733.realigned.rmdup.bam . You might also modify the trace command to

trace(Rsamtools:::open.BamFile, quote({ print(path(con)); print(index(con)) }))

so that it prints both the bam file and index path. I do not think the problem is with scanBam.

ADD REPLYlink written 3 months ago by Martin Morgan ♦♦ 22k
> BAMFile="bamKorea/SAMN02225733.realigned.rmdup.bam"

>bamDataRanges <- getReadCountsFromBAM(BAMFile, refSeqName=readLines("/users/lbuggiotti/WGresRussia/cn.MOPS/Chr_list.txt"), WL=1000)

I get the same error:

Error in value[[3L]](cond) :

  failed to open BamFile: failed to load BAM index

  file: bamKorea/SAMN02225733.realigned.rmdup.bam

In addition: Warning message:

In doTryCatch(return(expr), name, parentenv, handler) :

  [bam_index_load] fail to load BAM index.
ADD REPLYlink written 3 months ago by laurabuggiotti0

I meant the full path to the BAM file. Also please use the updated trace command.

ADD REPLYlink written 3 months ago by Martin Morgan ♦♦ 22k
Tracing open.BamFile(BamFile(file, character(0))) on entry

[1] "/users/lbuggiotti/bamKorea/SAMN02225733.realigned.rmdup.bam"

[1] NA

Tracing open.BamFile(BamFile(file, index), "rb") on entry

[1] "/users/lbuggiotti/bamKorea/SAMN02225733.realigned.rmdup.bam"

[1] "/users/lbuggiotti/bamKorea/SAMN02225733.realigned.rmdup.bam"

Error in value[[3L]](cond) :

  failed to open BamFile: failed to load BAM index

  file: /users/lbuggiotti/bamKorea/SAMN02225733.realigned.rmdup.bam

In addition: Warning message:

In doTryCatch(return(expr), name, parentenv, handler) :

  [bam_index_load] fail to load BAM index.

if i open BamFile:

> open(BamFile("/users/lbuggiotti/bamKorea/SAMN02225733.realigned.rmdup.bam"))

Tracing open.BamFile(BamFile("/users/lbuggiotti/bamKorea/SAMN02225733.realigned.rmdup.bam")) on entry

[1] "/users/lbuggiotti/bamKorea/SAMN02225733.realigned.rmdup.bam"

[1] "/users/lbuggiotti/bamKorea/SAMN02225733.realigned.rmdup.bai"
ADD REPLYlink written 3 months ago by laurabuggiotti0

Can you provide the output of the commands

packageVersion("Rsamtools")
sessionInfo()

A workaround might rename the index files from

bamKorea/SAMN02225733.realigned.rmdup.bai"

to

bamKorea/SAMN02225733.realigned.rmdup.bam.bai
ADD REPLYlink written 3 months ago by Martin Morgan ♦♦ 22k

when renaming the index file i dont get the error...thank you!
Ill modify all indexes and i hope all the samples will be analysed with cn.MOPS.

Thank you so much for your help!
cheers,

Laura

ADD REPLYlink written 3 months ago by laurabuggiotti0
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.2.0
Traffic: 337 users visited in the last hour