Unconfigured Ad

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

    #1

    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
                    Multiomic Liquid Biopsy: What DNA/RNA Panels Reveal That DNA Alone Can’t
                    by SEQadmin2



                    Tumors contain complex mixtures of cell populations that evolve in response to treatment and host-specific factors. Tissue biopsies provide only static snapshots of a tumor’s state. But what if we could follow that evolution over time using a minimally invasive technique?

                    Liquid biopsies can detect tumor-derived material circulating in the bloodstream, providing a way to study treatment response, detect emerging resistance, and discover new biomarkers. Circulating
                    ...
                    10-14-2026, 09:55 AM
                  • SEQadmin2
                    New Genomics Technologies Take Aim at Long-Standing Limits
                    by SEQadmin2


                    Researchers using sequencing and genomics tools often have to make trade-offs. They can choose between speed or scale, short reads or long-range information, or targeted panels or a view of the whole transcriptome. New technologies that have been released this year are built to address those tough choices.

                    We asked six companies the same four questions to learn about their latest products. The new technologies bring a lot to the table, including rethinking sequencing
                    ...
                    09-28-2026, 10:25 AM

                  ad_right_rmr

                  Collapse

                  News

                  Collapse

                  Topics Statistics Last Post
                  Started by SEQadmin2, Yesterday, 11:13 AM
                  0 responses
                  17 views
                  0 reactions
                  Last Post SEQadmin2  
                  Started by SEQadmin2, Yesterday, 10:48 AM
                  0 responses
                  18 views
                  0 reactions
                  Last Post SEQadmin2  
                  Started by SEQadmin2, 10-15-2026, 10:52 AM
                  0 responses
                  36 views
                  0 reactions
                  Last Post SEQadmin2  
                  Started by SEQadmin2, 10-14-2026, 05:39 AM
                  0 responses
                  42 views
                  0 reactions
                  Last Post SEQadmin2  
                  Working...