samtools index error
2
0
Entering edit mode
18 months ago
evelyn ▴ 140

Hello,

I am trying to index sorted bam files using samtools index. I created the sorted bam files by downsampling from higher depth sorted bam files using samtools depthandsamtools view. Samtools index works on the original high depth sorted bam files but it gives an error for downsampled sorted bam file:

samtools index: example is in a format that cannot be usefully indexed

Thank you for your help!

SNP • 3.5k views
ADD COMMENT
0
Entering edit mode

could be good to look at the commands you are using to create the down-sampling, also some example of the file generated

ADD REPLY
0
Entering edit mode

I used these commands to downsample:

samtools view -h -s 0.5 E.sorted.bam > E.5x.sorted.bam
ADD REPLY
1
Entering edit mode

BAM is a compressed binary file, SAM is the same information in human readable form (text), whey you run:

samtools view -h -s 0.5 E.sorted.bam > E.5x.sorted.bam

with view -hyou are decompressing your BAM, so you need to compress it again, like this:

samtools view -h -s 0.5 E.sorted.bam > E.5x.sorted.sam
samtools -bS  E.5x.sorted.sam >  E.5x.sorted.bam
samtools index  E.5x.sorted.bam
ADD REPLY
0
Entering edit mode

It worked. Thank you!

ADD REPLY
0
Entering edit mode

Given the information provided here, should this discussion should be moved to an answer and accepted?

ADD REPLY
2
Entering edit mode
18 months ago
JC 12k

Problem was identified as the commands used were incorrect, here are the proposed commands:

samtools view -h -s 0.5 E.sorted.bam > E.5x.sorted.sam
samtools -bS E.5x.sorted.sam > E.5x.sorted.bam
samtools index E.5x.sorted.bam
ADD COMMENT
1
Entering edit mode

Are you sure that you can't write straight to bam?

samtools view -bh -s 0.5 E.sorted.bam > E.5x.sorted.bam
ADD REPLY
0
Entering edit mode

Probably, but I would prefer this syntax:

samtools view -s 0.5 E.sorted.bam -o E.5x.sorted.bam
ADD REPLY
0
Entering edit mode
18 months ago
Brice Sarver ★ 3.6k

Are you sure that you've output a BAM file from samtools view? You can confirm with samtools quickcheck [bam]; see here. Additionally, sometimes people forget to include the -h flag in view to include the header - just a thought.

ADD COMMENT
0
Entering edit mode

Thank you! the file is intact and I used -h as well.

ADD REPLY
0
Entering edit mode

Great! Is there a possibility of running out of space in a temporary directory, or are you executing this on a network filesystem? See here for one possible avenue of investigation. Sorry it's getting a tad technical, but indexing is usually so dialed-in that it's strange if it doesn't work, barring BAM structure-related issues.

ADD REPLY
0
Entering edit mode

Thank you, I actually checked this post before posting my question. I am using a cluster and I believe space is not an issue for this job. I checked all the versions and everything is updated.

ADD REPLY
0
Entering edit mode

What about using a shared filesystem for, e.g., your home directory? Any NFSs mounted that could be indicative of a similar issue to the Github one above?

ADD REPLY
0
Entering edit mode

I am not sure how to check for that.

ADD REPLY

Login before adding your answer.

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