csaw autosim.R: Error in crunch2BAM(fnames): failed to sort BAM file
2
0
Entering edit mode
endrebak85 ▴ 40
@endrebak85-10660
Last seen 5.2 years ago
github.com/endrebak/

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?

 

csaw • 2.1k views
ADD COMMENT
2
Entering edit mode
Aaron Lun ★ 28k
@alun
Last seen 4 hours ago
The city by the bay

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 COMMENT
0
Entering edit mode

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 REPLY
0
Entering edit mode

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 REPLY
0
Entering edit mode

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 REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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 REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode
endrebak85 ▴ 40
@endrebak85-10660
Last seen 5.2 years ago
github.com/endrebak/

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 COMMENT
0
Entering edit mode

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 REPLY
0
Entering edit mode

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 REPLY
0
Entering edit mode

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 REPLY

Login before adding your answer.

Traffic: 747 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