How to specify the sort based on name in samtools sort?
1
0
Entering edit mode
6.4 years ago

I would like to know how to issue the command when sorting a BAM file based on name. The problem is that when I used the command,

samtools sort -n -o WT.bam /home/exp/accepted_hits.bam

It run without any error. However, when tried to index the BAM file like,

samtools index WT.bam

I go the error,

[E::hts_idx_push] Unsorted positions on sequence #8: 29211960 followed by 29211761
samtools index: failed to create index for "WT.bam"

I noticed that sorting based on position was successful in indexing. I tried different form of inputing -n and -o , but failed.

BAM SORT RNA-Seq HTSeq samtools • 6.2k views
ADD COMMENT
2
Entering edit mode
6.4 years ago

Hello,

you can only index the bam file when it ist coordinate-sorted. From the manual:

samtools index [-bc] [-m INT] aln.bam|aln.cram [out.index]

Index a **coordinate-sorted** BAM or CRAM file for fast random access. (Note that this does not work with SAM files even if they are bgzip compressed — to index such files, use tabix(1) instead.)

This index is needed when region arguments are used to limit samtools view and similar commands to particular regions of interest.

I don't know whether there are other ways to index bam files which are sorted by read name. Why do you need it?

fin swimmer

ADD COMMENT
0
Entering edit mode

It was a doubt from my previous post. I think i need to use -r option in HTSeq since I will sort bam file using position and not by name.

ADD REPLY

Login before adding your answer.

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