Unconfigured Ad

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • Desiree Wilson
    Junior Member
    • Mar 2012
    • 9

    Samtools error: the alignment was not sorted

    Hello everyone! How are you all doing? I hope all is well with you!

    I'm having a difficult time indexing my sorted bam files. I would like to use IGV to visualize my bam file. I used samtools to sort and index the bam file. Here's my code:

    samtools sort -n <path of .bam file> <sorted .bam file>
    samtools index <sorted .bam file>


    But then I get this message:
    [bam_index_core] the alignment is not sorted .....
    [bam_index_build2] fail to index the BAM file.


    So I tried to re-sort the bam file based on coordinates instead of gene name:
    samtools sort <path of .bam file> <sorted .bam file>
    samtools index <sorted .bam file>


    This time I didn't have a problem with indexing but when I loaded my bam file (both sorted and unsorted), I couldn't visualize my reads. I can really use someone's help here.
  • Alex Renwick
    Member
    • Jul 2011
    • 44

    #2
    As you've discovered, bam files almost always need to be sorted by coordinate.

    IGV won't display reads until you've zoomed in a good deal. Have you tried that? Are you sure you have reads in the place you're looking?

    Comment

    • Desiree Wilson
      Junior Member
      • Mar 2012
      • 9

      #3
      Thank you so much for the prompt reply.

      I've zoomed in to the nucleotide level and I still cannot see my reads. According to the IGV user guide, I should be able to see reads at 30kb. I believe that I'm looking in the right place. I downloaded the chromosome 6 data from the 1000 genomes website to learn how to process ngs data. So when I loaded the bam file, I clicked on "chr6" from the drop down box and still couldn't see my reads.

      Thank you so much. Now I learned that I cannot align my bam files by gene name.

      Comment

      • Alex Renwick
        Member
        • Jul 2011
        • 44

        #4
        You can use samtools mpileup to check read coverage:

        Code:
        samtools mpileup -r chr6:28543200-28543220 file.bam
        ...looks at reads covering 28,543,200 to 28,543,220 of chromosome 6. If you have the reference handy, you can specify it with the "-f" argument to see whether the reads match the reference.

        Comment

        • Desiree Wilson
          Junior Member
          • Mar 2012
          • 9

          #5
          Thanks! Wow, you reply so quickly! I will try this. Thank you so much.

          Comment

          • swbarnes2
            Senior Member
            • May 2008
            • 910

            #6
            I use IGV to look at samtools sorted files all the time.

            This may be a silly question, but you know that in order to get sort.bam, you run samtools like this:

            samtools sort unsorted.bam sort
            and not

            samtools sort unsorted.bam sort.bam
            And you spot-checked your bam to see that you really have reads aligning, and the that genome they were aligned to is exactly the same as the reference genome you uploaded into IGV?

            Comment

            • Desiree Wilson
              Junior Member
              • Mar 2012
              • 9

              #7
              Thanks swbarnes2! This is really good advice! Man I am soooo green! I'm so new to bioinformatics but I'm more than willing to learn!

              I do not know how to spot-check to see if I really have reads. May you please direct me to some literature that can teach me how to do this? I do think that there are reads in my bam file because I downloaded the bam file from 1000 genomes website. I think that I chose the correct reference genome in IGV but I will double check to make sure.
              Last edited by Desiree Wilson; 03-28-2012, 12:58 PM.

              Comment

              • Desiree Wilson
                Junior Member
                • Mar 2012
                • 9

                #8
                Wow. I feel so foolish right now. I selected the wrong reference build in IGV. Thank you so much swbarnes2! And thank you Alex Renwick for helping me! Thank you both!

                Comment

                • swbarnes2
                  Senior Member
                  • May 2008
                  • 910

                  #9
                  Originally posted by Desiree Wilson View Post
                  Thanks swbarnes2! This is really good advice! Man I am soooo green! I'm so new to bioinformatics but I'm more than willing to learn!

                  I do not know how to spot-check to see if I really have reads. May you please direct me to some literature that can teach me how to do this? I do think that there are reads in my bam file because I downloaded the bam file from 1000 genomes website. I think that I chose the correct reference genome in IGV but I will double check to make sure.
                  Well, you can't actaully eyeball a .bam. It's gibberish. But you convert it to .sam (samtools view out.bam > out.sam) and you'll get a very large file that is human readable. (hitting control-C will halt the process early, which is good if you just want to spot-check a bit of the file)

                  Look up the .sam format, and learn it, at least the first 8 columns or so. Learn to interpret the flags. The flags you want to see are 83, 99, 147,163. Figure out why those are the good ones.

                  The thing is, when you are doing everything right, but stuff isn't working, it's probably because you are making some assumption that is wrong, so that's when you stop and double-check all of your assumptions, and one of those assumptions is that your data is good.

                  If you had let samtools view convert the .bam to .sam for a little while, you could have looked at that .sam, and just confirmed that yes, the file is not corrupted, yes, most of the reads really did align, yes, the chromosome names in the .sam match the chromosome names of my reference file, and yes, there are supposed to be reads visible in this region of chr 1, etc.

                  You might have spotted the discrepancy between your genome version and the version used to make the .bam at that point.

                  Comment

                  Latest Articles

                  Collapse

                  • SEQadmin2
                    Cancer Drug Resistance: The Lingering Barrier to Rising Survival
                    by SEQadmin2



                    Cancer survival rates have significantly increased in the last few decades in the United States, reaching a combined 70% 5-year survival rate by 2021. Behind this number, there are years of research to find new therapies, drug targets, and early detection methods. But there is one core challenge that keeps slowing down these advances, and it’s about drug resistance.

                    There is no single reason why many patients don’t respond to treatment as expected. Cancer is...
                    Today, 05:17 AM
                  • GATTACAT
                    Reply to Nine Things a Sample Prep Scientist Thinks About Before Sequencing
                    by GATTACAT
                    Love this - good data definitely starts from good input, and poor input can only give relatively poor data. I particularly like the mention of Nanodrop/absorbance based methods for quantification. It's such a toss up if you'll get an accurate reading or what amounts to a randomly generated number, and a lot of library/sequencing related issues can be traced back to poor quant.
                    07-01-2026, 11:43 AM
                  • SEQadmin2
                    Nine Things a Sample Prep Scientist Thinks About Before Sequencing
                    by SEQadmin2


                    I’m not a sequencing expert. I’m a purification scientist who uses NGS to evaluate workflows my group develops. With this perspective, we think about the sample first and the NGS workflow second. The sequencer is an exceptionally honest reporter, but it can only report on what you give it, so whether you get clean, interpretable data from an NGS workflow is largely determined before you begin.

                    Here are nine questions we think about, in roughly the order they matter, before...
                    06-18-2026, 07:11 AM

                  ad_right_rmr

                  Collapse

                  News

                  Collapse

                  Topics Statistics Last Post
                  Started by SEQadmin2, Today, 10:08 AM
                  0 responses
                  5 views
                  0 reactions
                  Last Post SEQadmin2  
                  Started by SEQadmin2, Yesterday, 11:05 AM
                  0 responses
                  7 views
                  0 reactions
                  Last Post SEQadmin2  
                  Started by SEQadmin2, 07-02-2026, 11:08 AM
                  0 responses
                  30 views
                  0 reactions
                  Last Post SEQadmin2  
                  Started by SEQadmin2, 06-30-2026, 05:37 AM
                  0 responses
                  28 views
                  0 reactions
                  Last Post SEQadmin2  
                  Working...