4

I am currently working on my own Metagenomic pipeline, utilizing Bowtie 2 to map. Bowtie 2 outputs a SAM file, which I convert to a .BAM and sort it using Samtools. When I try to utilize Samtools to index my .BAM file it gives me this error:

[E::hts_idx_push] NO_COOR reads not in a single block at the end 1652 -1.

Here is my code:

source /opt/asn/etc/asn-bash-profiles-special/modules.sh
module load samtools/1.3.1

cd ~/gz_files/soapdenovo
r=20
###SAM to BAM and sort 

samtools faidx soapdenovo.fa 
samtools view -b -T soapdenovo.fa -o sample${r}bowtiemapping.bam sample${r}bowtiemapping.sam
samtools sort -n -T ~/gz_files/soapdenovo/temp -o sample${r}bowtiemapping_sorte$
samtools index sample${r}bowtiemapping_sorted.bam

################LETS MAKE THE ABUNDANCE TABLES###########################$
samtools view -c -f 4  sample${r}bowtiemapping_sorted.bam > sample${r}alignment$

samtools idxstats sample${r}bowtiemapping_sorted.bam >  sample${r}idxstats.txt

#git clone https://github.com/metajinomics/mapping_tools.git
#python mapping_tools/get_count_table.py *.idxstats.txt > contig_counts.tsv
##less contig_counts.tsv

Any help would be appreciated!


Notes on pipeline

  • samtools import was replaced with samtools view
  • faidxcorrected
  • Instructions used are here on github
  • Suggestion for future trouble shooting is given here by @winni2k
M__
  • 12,263
  • 5
  • 28
  • 47
  • samtools faidx file.bam file.bai makes no sense. samtools faidx indexes fasta files, not bams or bais (bai are the indexes of bam files). – Poshi Sep 21 '18 at 20:07
  • In you code, which is the line that is causing trouble? I cannot see any samtools index for indexing the bam, as you say. – Poshi Sep 21 '18 at 07:25
  • BTW, don't search for "null". This is a name for something that does not exists. Check if all your records have a non-empty sequence. – Poshi Sep 21 '18 at 07:26
  • 1
    More comments... samtools import has been deprecated for 8 years. Use samtools view instead. – Poshi Sep 21 '18 at 07:30
  • In your usage of samtools view, you didn't add neither the parameter to tell samtools the input is a sam file nor the parameter to tell samtools the output should be a bam file. By default, you get the other direction. – Poshi Sep 21 '18 at 07:31
  • 1
    Finally, the second samtools faidx makes no sense: there are no fasta files to index! – Poshi Sep 21 '18 at 07:31
  • I was following a tutorial from the 2018 Edamame course (https://github.com/edamame-course/2018-Tutorials/wiki/Schedule-EDAMAME-2018) –  Sep 21 '18 at 15:22
  • I am new to bioinformatics so any tips would be helpful. This is the line that is giving me issues:

    samtools faidx sample${r}bowtiemapping_sorted.bam sample${r}bowtiemapping_sorted.bam.bai

    –  Sep 21 '18 at 15:22
  • I made the recommended changes above. I am now getting this error: [E::hts_idx_push] NO_COOR reads not in a single block at the end 1652 -1 samtools index: "sample20bowtiemapping_sorted.bam" is corrupted or unsorted @Poshi –  Sep 21 '18 at 17:56
  • I'm not sure about the new error you are getting. It looks like the execution of some samtools index, but no samtools index is in the code. Can you update the question with the new information? Put the new code, tell us the line that fails and put also the error message. – Poshi Sep 21 '18 at 20:09
  • Okay, Ive updated everything with the new error and new code @Poshi –  Sep 24 '18 at 15:09
  • 1
    Which is the command that fails? Which one is giving that message? Again, I'm seeing several errors. faidx have too many parameters (what are you trying to achieve?), view will complain about not having a bam input, and sort have no input file given and the shell will complain about an orphan dollar sign. Four errors in for different lines. Better go step by step and check that one step works before going to the next. – Poshi Sep 24 '18 at 17:47
  • 1
    Try upgrading to the most recent version of samtools, this bug may have been squashed already. – Devon Ryan Nov 02 '18 at 08:05
  • I think a lot of the questions in the comments could be solved with a Minimal, Complete, and Verifiable example: https://stackoverflow.com/help/mcve – winni2k Nov 25 '18 at 14:23

1 Answers1

1

By now this will be of little interest to the original poster, but for future reference:

$ samtools sort -n -T ~/[etc] -o sample${r}bowtiemapping_sorted.bam [etc]
$ samtools index sample${r}bowtiemapping_sorted.bam
[E::hts_idx_push] NO_COOR reads not in a single block at the end 1652 -1.

This error message indicates (admittedly somewhat obscurely) that the reads are not sorted by coordinate — in particular, there are mapped reads appearing after the unplaced unmapped reads (those with RNAME *) that should be at the very end of the file.

This is because samtools sort -n has been used to sort the reads by name instead. Remove -n to sort by position, which is what is needed to prepare a BAM file for indexing with samtools index.

John Marshall
  • 1,006
  • 8
  • 12