Announcement

Collapse
No announcement yet.
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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.

  • #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


    • #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


      • #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


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

          Comment


          • #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


            • #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


              • #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


                • #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

                  • seqadmin
                    Advanced Tools Transforming the Field of Cytogenomics
                    by seqadmin


                    At the intersection of cytogenetics and genomics lies the exciting field of cytogenomics. It focuses on studying chromosomes at a molecular scale, involving techniques that analyze either the whole genome or particular DNA sequences to examine variations in structure and behavior at the chromosomal or subchromosomal level. By integrating cytogenetic techniques with genomic analysis, researchers can effectively investigate chromosomal abnormalities related to diseases, particularly...
                    09-26-2023, 06:26 AM
                  • seqadmin
                    How RNA-Seq is Transforming Cancer Studies
                    by seqadmin



                    Cancer research has been transformed through numerous molecular techniques, with RNA sequencing (RNA-seq) playing a crucial role in understanding the complexity of the disease. Maša Ivin, Ph.D., Scientific Writer at Lexogen, and Yvonne Goepel Ph.D., Product Manager at Lexogen, remarked that “The high-throughput nature of RNA-seq allows for rapid profiling and deep exploration of the transcriptome.” They emphasized its indispensable role in cancer research, aiding in biomarker...
                    09-07-2023, 11:15 PM

                  ad_right_rmr

                  Collapse

                  News

                  Collapse

                  Topics Statistics Last Post
                  Started by seqadmin, Yesterday, 07:14 AM
                  0 responses
                  11 views
                  0 likes
                  Last Post seqadmin  
                  Started by seqadmin, 09-29-2023, 09:38 AM
                  0 responses
                  13 views
                  0 likes
                  Last Post seqadmin  
                  Started by seqadmin, 09-27-2023, 06:57 AM
                  0 responses
                  14 views
                  0 likes
                  Last Post seqadmin  
                  Started by seqadmin, 09-26-2023, 07:53 AM
                  0 responses
                  31 views
                  0 likes
                  Last Post seqadmin  
                  Working...
                  X