Error handling with Rsamtools
1
0
Entering edit mode
t.kuilman ▴ 170
@tkuilman-6868
Last seen 2.5 years ago
Netherlands

Dear colleague,

I am developing an R package for which I want to provide error handling when warning/error messages are produced by Rsamtools. Specifically, I would like to test whether there any truncated files in a list of BAM files. When using the following command:

indexBam(bamFile)

I will get the following message:

[bam_header_read] EOF marker is absent. The input is probably truncated.

I have tried to capture this event in R, but this fails using tryCatch (no warning or error is raised), and also sink() or capture.output() does not capture this event (likely because the message is created by the C core underlying Rsamtools).

My question is how I could detect that this message is printed, and thus that there are truncated BAM files present.

Thank you very much for your help,

Thomas

 

My sessionInfo() is below:

R version 3.1.1 (2014-07-10)
Platform: x86_64-pc-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] parallel  stats     graphics  grDevices utils     datasets  methods  
[8] base     

other attached packages:
[1] Rsamtools_1.12.4     Biostrings_2.28.0    GenomicRanges_1.12.5
[4] IRanges_1.18.3       BiocGenerics_0.6.0  

loaded via a namespace (and not attached):
[1] bitops_1.0-6   stats4_3.1.1   tools_3.1.1    zlibbioc_1.6.0

rsamtools • 1.1k views
ADD COMMENT
0
Entering edit mode
@martin-morgan-1513
Last seen 4 months ago
United States

Hi Thomas -- Your Rsamtools and other packages are quite old; as a (Bioconductor) package developer you really want to be using the 'devel' branch of Bioconductor. It would also help to see exactly the code that you're using to conclude that warnings are not being generated.

Rsamtools is supposed to capture this message as an R warning. The last change to the code enabling this was I think in 2012-12-19, Rsamtools 1.11.13, so your version of Rsamtools should be generating an R warning. It does however rely on re-directing samtools' use of stderr to R's warning, and some compilers and operating systems make this difficult. During installation you should see

-U_FORTIFY_SOURCE -Dfprintf=_samtools_fprintf -Dexit=_samtools_exit -Dabort=_samtools_abort 

when individual source files are compiled. Also, the installed library should include a symbol '_samtools_fprintf', which I can see in my installation (the path to the installed library might be different for you) with

$ R CMD nm ~/R/x86_64-unknown-linux-gnu-library/3.1/Rsamtools/libs/Rsamtools.so |grep _samtools_fprintf
0000000000061f10 T _samtools_fprintf

I suggest first that you update to using a current version of Bioconductor and Rsamtools, and if the warnings are still not generated provide the (yes, I know it's a lot!) output generated when Rsamtools is installed. Also, this is really a question about package development, and the appropriate forum for such questions is the bioc-devel mailing list.

 

ADD COMMENT
0
Entering edit mode

Hi Martin,

Thanks for your comments; they partly solved the problem. I will continue the discussion via the bioc-devel mailing list.

Thomas

ADD REPLY

Login before adding your answer.

Traffic: 534 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6