This is a test version of Biostars. For the public version, visit https://www.biostars.org.
cant make index file for my bam file that sorted by -n

hi

i have a bam file (from tophat2)

i use :

samtools view -b -h -T Triticum_aestivum.fa 19358.bam -o 119358.bam

then:

samtools sort -n 119358.bam -o 119358.sorted.bam

but when i use:

samtools index 119358.sorted.bam

or

samtools index -c 119358.sorted.bam

i see this error:

[E::hts_idx_push] Unsorted positions on sequence #18: 102855883 followed by 102853406
[E::sam_index] Read 'A00783:167:HTLJ3DSXX:3:1101:1036:16689' with ref_name='6D', ref_length=473592718, flags=163, pos=102853406 cannot be indexed
samtools index: failed to create index for "119358.sorted.bam"

i need a sorted bam file (by name or pos.) and a index file for that sorted bam file to use in HTSeq-count. i have to write (-r name or -r pos) in htseq-count. but it seems that when i sort my bam file by -n i cant make index file for it and so i cant count it by htseq-count

htseq-count -q -t gene -i gene_id -s no -r ?????? -f bam x.bam x.gff3 > x.txt

rna-seq rna-seq sequencing software error

the first command samtools view -b -h -T Triticum_aestivum.fa 19358.bam -o 119358.bam is useless (no filtering,no conversion,...).

Hello meisam.radfar!

Questions similar to yours can already be found at:

We have closed your question to allow us to keep similar content in the same thread.

If you disagree with this please tell us why in a reply below. We'll be happy to talk about it.

Cheers!

hi my previous question is about difference between x.csi and x.bai files

but now i ask about error when i indexing my bam file that sorted by -n , because htseq-count need name or pos after -r so i edit my question and i explain more.

It is the same underlying problem. You should in these cases comment on the previous question, these simple types of questions can easily be answered in the same thread.

Just do samtools sort -o sorted.bam 19358.bam and then samtools index -c sorted.bam. Be sure to use current samtools versions and not super-old ones.

thank you and sorry I think i cant explain my problem!!!

htseq-count need sorted bam file (with name or pos.)

you can see below:

-r <order> For paired-end data, the alignment have to be sorted either by read name or by alignment position. If your data is not sorted, use the samtools sort function of samtools to sort it. Use this option, with name or pos for <order> to indicate how the input data has been sorted. The default is name

So i have to sort my bam files with -n to use it in htseq-count

i know that i can sort my bam file with samtools sort x.bam > x.sorted.bam and i index it by samtools index x.sorted.bam, but i dont know that i can use that file in htseq-count or not?? because htseq need sorted files by name or pos

1 answer

samtools sort -n

option -n is for sorting on query/read name. You cannot index such file. Indexes only works for coordinate-based bams. Just remove the '-n' if you want the later.

hi thank you samtools sort 119358.bam is work but for htseq-count need to use sorted bam file with name

Htseq-count:

-r <order> For paired-end data, the alignment have to be sorted either by read name or by alignment position. If your data is not sorted, use the samtools sort function of samtools to sort it. Use this option, with name or pos for <order> to indicate how the input data has been sorted. The default is name

. You cannot index such file. Indexes only work for coordinate-based bams

htseq-count -q -t gene -i gene_id -s no -r ?(name or pos)? -f bam x.bam x.gff3 > x.txt

-r in htseq-count need name or pos, so if i remove -n and i sort without -n, i have to use name or pos in htseq-count after -r ??

when i dont use -r i have a result, when i use -r name i have other result and when i use -r pos i have another result!!

3 different results in counts, no_feature, ambiguous and alignment_not_unique

Log in to answer this question.