Search
Question: csaw autosim.R: Error in crunch2BAM(fnames): failed to sort BAM file
0
2.1 years ago by
endrebak8530
endrebak8530 wrote:

I am trying to rerun the simulation in the CSAW paper, but the autosim.R file (http://bioinf.wehi.edu.au/csaw/autosim.R) does not seem to work.

I run autosim.R with the following line added:

is.tf = FALSE

and I get the error

Error in crunch2BAM(fnames) : failed to sort BAM file

How do I fix this?

modified 2.0 years ago • written 2.1 years ago by endrebak8530
2
2.1 years ago by
Aaron Lun21k
Cambridge, United Kingdom
Aaron Lun21k wrote:

I'm guessing that you're using the latest version of SAMtools, where it seems that the legacy options for sort are no longer supported. Specifically, instead of:

samtools sort <INPUT.BAM> <OUT>

... the new call is now:

samtools sort <INPUT.BAM> -o <OUT.BAM>

Note the extra "-o" flag and the use of the full output file name rather than just the prefix in the legacy version. You can just change the relevant line in crunch2BAM to:

system(paste("samtools sort", temp, "-o", paste0(prefix, ".bam")), ignore.stderr=TRUE)

... and then re-install the xscss package. I'll also update the package on the WEHI page (now version 1.1.3).

P.S. This question is about the paper, not the package, so it's probably best to email me directly rather than putting it on the support site.

Thank you! If I e-mail you directly, my question and your answer will not be googleable for others. Is asking about the paper on the csaw github an acceptable compromise?

Also, thanks for making the simulations available. For a non-statistician like me, seeing what is produced is much more helpful than reading a description :)

My pleasure. Do the simulations work with the modified crunch2BAM? If there's anything else that's broken, I'd like to fix it before uploading a new copy of the package to the WEHI website.

Well, I suppose. You know what - it doesn't really matter, this is fine.

I do not get e-mail notifications from support.bioconductor, so I did not see your q. Will find out now and report back to you.

It did not work. I'll try different things to get it to work, but suggestions welcome :)

0
2.0 years ago by
endrebak8530
endrebak8530 wrote:

I changed crunch2bam to the following:

crunch2BAM<-function(sam.files, dir=".")
# This crunches a set of SAM files to sorted & indexed BAM files using the samtools command.
# We avoid calling Rsamtools because of strange errors with 'invalid cross-device link'. I
# think it's putting things in /tmp when that might be full, and I can't see any option to
# change the temporary directory.
#
# written by Aaron Lun
{
out<-NULL
for (sam.file in sam.files) {
prefix<-file.path(dir, sub("\\.sam\$", "", basename(sam.file)))
temp<-tempfile(tmpdir=dir, fileext=".bam")
if (system(paste("samtools view -bS -h", sam.file, "-o", temp), ignore.stderr=TRUE)) {
stop("failed to compress to BAM")
}

# system(paste("samtools sort", temp, prefix), ignore.stderr=TRUE)
if (system(paste("samtools sort", temp, "-o", paste0(prefix, ".bam")), ignore.stderr=TRUE)) {
stop("failed to sort BAM file")
}
bam.file<-paste0(prefix, ".bam")
indexBam(bam.file)
out<-append(out, bam.file)
}
return(out);
}

and then created a new tar.gz with

tar -cvzf xscss_1.1.2.tar.gz xscss/**

But when I try to install it I get

> install.packages("xscss_1.1.2.tar.gz", repos=NULL, type="source")
Installing package into '/local/home/endrebak/R/x86_64-pc-linux-gnu-library/3.2'
(as 'lib' is unspecified)
During startup - Warning message:
Setting LC_CTYPE failed, using "C"
cannot link 'xscss/man/fillGenome.Rd' to 'xscss/man/fillGenome.Rd', reason 'No such file or directory'
... long list of similar messages ...
* installing *source* package 'xscss' ...
** libs
Warning: no source files found
** help
No man pages found in package  'xscss'
*** installing help indices
** building package indices
** testing if installed package can be loaded
During startup - Warning message:
Setting LC_CTYPE failed, using "C"
Note: the specification for S3 class "AsIs" in package 'DBI' seems equivalent to one from package 'BiocGenerics': not turning on duplicate class definitions for this class.
Error in library.dynam(lib, package, package.lib) :
Execution halted
ERROR: loading failed

Well, you need to do R CMD build xscss to build a package, rather than manually making a tarball. But that shouldn't even be necessary, just use the new package on the WEHI page.

For what it's worth, there is also Rsamtools::sortBam(), removing the need for external samtools (based on an earlier version of samtools, so probably slower).

Yes, and the latest version uses Rsamtools now. I can't quite recall why I did it using an external samtools. I think that, at the time, Rsamtools wasn't running properly on my institute's servers - maybe something to do with temporary files, or perhaps issues with disk I/O that we were experiencing at the time.