Search
Question: csaw autosim.R: Error in crunch2BAM(fnames): failed to sort BAM file
0
gravatar for endrebak85
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?

 

ADD COMMENTlink modified 2.0 years ago • written 2.1 years ago by endrebak8530
2
gravatar for Aaron Lun
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.

ADD COMMENTlink modified 2.0 years ago • written 2.1 years ago by Aaron Lun21k

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?

ADD REPLYlink written 2.1 years ago by endrebak8530

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 :)

ADD REPLYlink written 2.1 years ago by endrebak8530

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.

ADD REPLYlink written 2.1 years ago by Aaron Lun21k

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

ADD REPLYlink written 2.1 years ago by Aaron Lun21k

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.

ADD REPLYlink written 2.0 years ago by endrebak8530

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

ADD REPLYlink written 2.0 years ago by endrebak8530
0
gravatar for endrebak85
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)
        unlink(temp)
        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"
Warning in file.link(name2, name) :
  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) :
  shared object 'xscss.so' not found
Error: loading failed
Execution halted
ERROR: loading failed
ADD COMMENTlink written 2.0 years ago by endrebak8530

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.

ADD REPLYlink modified 2.0 years ago • written 2.0 years ago by Aaron Lun21k

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).

ADD REPLYlink written 2.0 years ago by Martin Morgan ♦♦ 22k

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.

ADD REPLYlink written 2.0 years ago by Aaron Lun21k
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: 345 users visited in the last hour