Unconfigured Ad

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • toreoe
    Junior Member
    • Jan 2013
    • 3

    #1

    Extracting a subset of bam files

    Hi everyone,

    What I have:
    A bam file with 10kb MP reads mapped back to an in house reference genome assembled in Allpaths-LG. Going to be used for visual inspection in IGV and Geneious to evaluate a possible scaffold break up suggested by linkage map.

    What I want:
    To extract a new bam file that contains the mapped reads for only one of the scaffolds in my reference genome.

    Problem:
    samtools view -b mybamfile.bam 'scaffold000046' > scf000046.bam

    The resulting file lists all the original scaffolds in the header, like this:

    @SQ SN:scaffold_0 LN:21965366
    @SQ SN:scaffold_1 LN:18670197
    @SQ SN:scaffold_2 LN:16657575
    @SQ SN:scaffold_3 LN:15264954
    @SQ SN:scaffold_4 LN:14680565
    ...

    I may have misunderstood the output of the above command, but I expected to find only the target scaffold in the new bam-file header.

    Any help would be much appreciated. Feel free to direct me if the solution for my problem has already been posted elsewhere. However, have not succeeded in finding one.

    Best,
    Tore
    Last edited by toreoe; 04-14-2014, 10:17 AM.
  • jeales
    Member
    • Oct 2012
    • 13

    #2
    Index scf000046.bam ('samtools index scf000046.bam') and then see what 'samtools idxstats scf000046.bam' says
    Are there reads reported for all the scaffolds or just scaffold000046?

    Comment

    • toreoe
      Junior Member
      • Jan 2013
      • 3

      #3
      I extracted another, scaffold0008, from a different bam file. I then indexed scaffold00008.bam as suggested. samtools idxstats reported reads only for the target scaffold, none for the others:

      scaffold00001 21966007 0 0
      scaffold00002 18670670 0 0
      scaffold00003 16657927 0 0
      scaffold00004 15265287 0 0
      scaffold00005 14680965 0 0
      scaffold00006 14166276 0 0
      scaffold00007 14112451 0 0
      scaffold00008 13353334 2289885 55567
      scaffold00009 13059713 0 0

      scaffold00008 loaded properly in IGV, something I couldn't do with my previous extracted file. So it might be that there was something wrong with my original bam file.

      Anyways, it seems like this is simply the way the samtools view extract command outputs the subset bam, i.e. contains all scaffolds from original bam in header. And it works fine.

      Thank you very much for your help, jeales.

      Comment

      • jeales
        Member
        • Oct 2012
        • 13

        #4
        Thats good, if there were reads from other scaffolds an awful lot of my work would be wrong as well!

        I don't have a good solution for trimming the header to only include scaffolds/chromosomes that have reads present in the bam, other than manual editing

        But it's not realyl doing any harm as long as the counts are zero

        Comment

        • dpryan
          Devon Ryan
          • Jul 2011
          • 3478

          #5
          The header is left as-is for technical reasons. In BAM files (and internally by samtools and likely picard too) the chromosome/contig field of an alignment is just a numeric index into this list in the header. Trimming the header, then would result in needing to alter every read as it was output, which would be annoying (this is also why people need to be careful when they reheader BAM files, since changing the order of the contigs/chromosomes in the header will make all of the alignments wrong), though I guess not that hard to implement (it would affect performance, though).

          Comment

          • jeales
            Member
            • Oct 2012
            • 13

            #6
            Very informative thanks
            So if all the alignments in a bam are mapped to the 10th chromosome/contig in the header their chromosome/contig will be 10 (or probably 9, if you start counting at 0), irrespective of chromosome name?

            Comment

            • dpryan
              Devon Ryan
              • Jul 2011
              • 3478

              #7
              Exactly. As you surmised, everything is 0-based internally, so the value is 9. For those curious, the value is unsigned, so a value of -1 used for unmapped reads.

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