Unconfigured Ad

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rkizen
    Member
    • Jun 2013
    • 20

    #1

    Samtools view bam parse region issues

    I have mapped reads from illumina sequencing onto a reference genome using bwa aln and I wanted to get some regions of the bam files using samtools view:

    samtools view -o test_region.sam merged.sort.bam 1:100-1000

    however I kept getting the error:

    [bam_parse_region] fail to determine the sequence name.

    I have realized that I used an NCBI version of the reference genome which resulted in the reference sequence name in the bam file to be that of the NCBI sequence names. For example, here is bit of the bam file:

    EBRI093151_0050:4:117:5648:11807#0 99 gi|358485511|ref|NC_006088.3| 66454 60 101M = 66940 587 CTCCAAGATCATCCAGTCCACCCATCCACCCACCACCAATGTAACCCCATTAAAACACGTCCCTCAGTACCACATCTAAATGTTTCTTGAGCACTGGCAGG fffffdffffefffffefeffffeffffffffffffffcdefedffdfeffdfaeffffdeffffdedfffeffe`f`ccdfadfffdaYd^cd`bbd`dc XT:A:U NM:i:0 SM:i:37 AM:i:37 X0:i:1 X1:i:0 XM:i:0 XO:i:0 XG:i:0 MD:Z:101


    Notice how instead of "chr1" it has "gi|358485511|ref|NC_006088.3|" as the sequence name. I believe this is the cause of the parsing issue. However, now I cannot seem to figure out how to pull a region from the bam file. I tried using:

    samtools view -o test_region.sam merged.sort.bam NC_006088.3:1-1000

    But I get the same error as before:
    [bam_parse_region] fail to determine the sequence name.

    If I put this instead:

    samtools view -o test_region.sam merged.sort.bam NC_006088.3

    It seems to do as one would expect and pull all read mappings for that sequence region, however, I would like to pull specific coordinates from each chromosome.

    Does anybody have some ideas of how I could do this? I was thinking about replacing all the reference sequence names with their generic equivalent (ie "chr1,chr2 etc") however I am not certain that would solve my issue here.

    Thank you!
  • lh3
    Senior Member
    • Feb 2008
    • 686

    #2
    Try "gi|358485511|ref|NC_006088.3|:100-1000", though I don't know if that works.

    The best solution is to replace the sequence names with something easier.

    Comment

    • rkizen
      Member
      • Jun 2013
      • 20

      #3
      Thanks lh3! That works. I should change the sequence names but I needed this for something a bit urgent and there are a lot of sequence names which would require a bit of time ensuring that a name changing script was not corrupting the file in any way. Thank you again and I am kicking myself for not using the quotation marks to get past the pipes in the sequence names.

      Comment

      • dpryan
        Devon Ryan
        • Jul 2011
        • 3478

        #4
        The reheader script can simply be "samtools reheader"

        Do a "samtools view -H file.bam > header.sam", edit the header.sam file by replacing the chromosome names (they need to be in the same order as the original, so don't reorder anything!), then use samtools reheader. Unless your alignments are to a large number of contigs, this should be quite quick.

        Comment

        • rkizen
          Member
          • Jun 2013
          • 20

          #5
          Thanks dpryan!

          I have not used reheader before. Will it replace all the sequence names? or will it just replace the header info?

          There are a lot of contigs and there are many mappings which may not have the same contigs represented. I will have to write a script to run "samtools view -H file.bam > header.sam" for each mapping and then replace the sequence names for each of the header sam files and apply those back onto the origin bam file using samtools reheader.

          For now I just need some intervals quickly so I will use the method lh3 to get these intervals and then work on converting the headers later.

          Comment

          • dpryan
            Devon Ryan
            • Jul 2011
            • 3478

            #6
            If you have a BAM file, the chromosome/contig names are only stored in the header (there's an ordered list and each read just has a numeric value saying where in that list it's chromosome name can be found). Yeah, if you have a bunch of different mappings, then following what Heng Li suggested might prove faster.

            Comment

            • lh3
              Senior Member
              • Feb 2008
              • 686

              #7
              @dpryan your reheader is better in the long run. Haven't thought about that...

              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, 10-22-2026, 11:13 AM
              0 responses
              27 views
              0 reactions
              Last Post SEQadmin2  
              Started by SEQadmin2, 10-22-2026, 10:48 AM
              0 responses
              20 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
              43 views
              0 reactions
              Last Post SEQadmin2  
              Working...