Question: The error generated by Rsamtools
1
gravatar for wangdp123
9 months ago by
wangdp123250
Oxford
wangdp123250 wrote:

Hi there,

I use Rsubread to produce the BAM files and then use Rsamtools to manipulate the BAM files.

A few errors were thrown out:

1)

> indexBam(files = "sample.bam")

Error in FUN(X[[i]], ...) : failed to build index

2)

> asSam(file = "sample.bam") 

> asBam(file = "sample.sam")

Error in value[[3L]](cond) : 'asBam' truncated input file at record 8

I have checked the content of the BAM file generated by Rsubread by converting it into a SAM file and it seems that it uses quite a few CR (carriage return) in the middle of each long line. Does Rsamtools not recognise this format?

Many thanks,

Tom

rsamtools rsubread • 341 views
ADD COMMENTlink modified 9 months ago by Gordon Smyth2.0k • written 9 months ago by wangdp123250
1

Sounds like you have a SAM file rather than a BAM file.

ADD REPLYlink written 9 months ago by Devon Ryan97k

No. I have checked that it is BAM file. I can use asSam() function to convert sample.bam to sample.sam but cannot convert back from sample.sam to sample.bam using asBam() function.

ADD REPLYlink written 9 months ago by wangdp123250

Can you show output of samtools quickcheck -vvv that.bam on that bam file via terminal?

ADD REPLYlink modified 9 months ago • written 9 months ago by ATpoint41k

I run the following command line on terminal:

samtools quickcheck -v sample.bam

The output is empty.

ADD REPLYlink written 9 months ago by wangdp123250

Please use vvv, this is not a typo. Tripple-v means "set verbosity to 3" which is "output everything". It will give a more detailed output message from the tool. A simple head(sample.bam) will also tellyou if it is not a SAM file in terms of not being binary.

ADD REPLYlink modified 9 months ago • written 9 months ago by ATpoint41k

OK. I have run the command line: samtools quickcheck -vvv sample.bam

The output is below:

verbosity set to 3
checking sample.bam
opened sample.bam
sample.bam is sequence data
sample.bam has 1 targets in header
sample.bam has good EOF block
ADD REPLYlink modified 9 months ago by _r_am31k • written 9 months ago by wangdp123250

Hmm, ok next step, checking the header: samtools view -H sample.bam

ADD REPLYlink modified 9 months ago • written 9 months ago by ATpoint41k
@HD     VN:1.0  SO:unsorted
@SQ     SN:22   LN:50818468
@PG     ID:subread      PN:subread      VN:Rsubread 1.34.7      CL:"subread-align" "-r" "sample.R1.fastq.gz" "-R" "sample.R2.fastq.gz" "-o" "sample.bam" "-i" "index" "--type" "0" "-n" "10" "-m" "3" "-p" "1" "-M" "3" "-T" "1" "-I" "5" "-B" "1" "-d" "50" "-D" "600" "-S" "fr" "--trim5" "0" "--trim3" "0" "-G" "-1" "-E" "0" "-X" "0" "-Y" "2" "-P" "3"
ADD REPLYlink modified 9 months ago by _r_am31k • written 9 months ago by wangdp123250
1
gravatar for Gordon Smyth
9 months ago by
Gordon Smyth2.0k
Australia
Gordon Smyth2.0k wrote:

Rsubread can sort and index the BAM file on-the-fly during the alignment. It is much faster to take advantage of that facility than to sort and index the BAM file afterwards.

indexBAM might perhaps assume that the BAM file is location-sorted but, by default, it won't be.

ADD COMMENTlink modified 9 months ago • written 9 months ago by Gordon Smyth2.0k
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.3.0
Traffic: 1041 users visited in the last hour