Unconfigured Ad

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • meher
    Member
    • Jun 2011
    • 54

    #1

    Extract reads from multiple regions from bam file

    HI,

    samtools view aln.sorted.bam chr2:20,100,000-20,200,000 is used to extract reads from specific regions.

    Is there a way to extract if we have multiple regions specified in a bed file format?


    Regards
    Mehar
  • krobison
    Senior Member
    • Nov 2007
    • 734

    #2
    You can continue specifying regions after the first one

    samtools view aln.sorted.bam chr2:20,100,000-20,200,000 chr2:30,100,000-30,200,000

    (BTW, will it really tolerate the commas?)

    It's pretty easy to convert BED format to this using your favorite text mangling language; mine is Perl:

    Code:
    samtools view aln.sorted.bam `perl -p -e 'chomp; @a=split(/\t/); print "$a[0]:$a[1]-$a[2]"' sleepy.bed`

    Comment

    • meher
      Member
      • Jun 2011
      • 54

      #3
      Originally posted by krobison View Post
      You can continue specifying regions after the first one

      samtools view aln.sorted.bam chr2:20,100,000-20,200,000 chr2:30,100,000-30,200,000

      (BTW, will it really tolerate the commas?)

      It's pretty easy to convert BED format to this using your favorite text mangling language; mine is Perl:

      Code:
      samtools view aln.sorted.bam `perl -p -e 'chomp; @a=split(/\t/); print "$a[0]:$a[1]-$a[2]"' sleepy.bed`
      Thanks for the answer.

      I have tried it but, the samtools is throwing an error "Argument list too long".
      Any other way of doing this?

      Comment

      • dariober
        Senior Member
        • May 2010
        • 311

        #4
        Originally posted by krobison View Post
        It's pretty easy to convert BED format to this using your favorite text mangling language; mine is Perl:

        Code:
        samtools view aln.sorted.bam `perl -p -e 'chomp; @a=split(/\t/); print "$a[0]:$a[1]-$a[2]"' sleepy.bed`
        Hi- You don't need to convert BED format to string. samtools view accepts a bed file directly (see -L option "output alignments overlapping the input BED FILE")

        Dario

        Comment

        • meher
          Member
          • Jun 2011
          • 54

          #5
          Extract reads from multiple regions from bam file

          Originally posted by dariober View Post
          Hi- You don't need to convert BED format to string. samtools view accepts a bed file directly (see -L option "output alignments overlapping the input BED FILE")

          Dario
          Hi,

          I tried to do this using the following command

          samtools view -L sample.bed test.bam > test1.bam

          and surprisingly the output files is thrice in size than the original and i tried to count the number of reads on the output bam using samtools view -c test1.bam but, it throws the error

          [bam_header_read] EOF marker is absent. The input is probably truncated.
          [bam_header_read] invalid BAM binary header (this is not a BAM file).
          [main_samview] fail to read the header from "test1.bam"


          Any help??

          Comment

          • dariober
            Senior Member
            • May 2010
            • 311

            #6
            Originally posted by meher View Post
            Hi,

            I tried to do this using the following command

            samtools view -L sample.bed test.bam > test1.bam

            and surprisingly the output files is thrice in size than the original and i tried to count the number of reads on the output bam using samtools view -c test1.bam but, it throws the error

            [bam_header_read] EOF marker is absent. The input is probably truncated.
            [bam_header_read] invalid BAM binary header (this is not a BAM file).
            [main_samview] fail to read the header from "test1.bam"


            Any help??
            Hello,
            By default, samtools view expect bam as input and produces sam as output. This should explain why you get a very large output (uncompressed sam) and a complain about BAM binary header.
            To fix it use the -b option. This should work:
            Code:
            samtools view -b -L sample.bed test.bam > test1.bam
            samtools view -c test1.bam
            Hope this helps
            Dario

            Comment

            • wanfahmi
              Member
              • Apr 2008
              • 34

              #7
              Hi,

              How could we extract reads for specific locus / gene from accepted_hits.bam file? Is that possible? Could we get the fastq / fasta from it? Thank you

              Comment

              • ersgupta
                Member
                • Jun 2011
                • 26

                #8
                try out "intersectBed" in bedtools...


                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-15-2026, 10:52 AM
                0 responses
                21 views
                0 reactions
                Last Post SEQadmin2  
                Started by SEQadmin2, 10-14-2026, 05:39 AM
                0 responses
                26 views
                0 reactions
                Last Post SEQadmin2  
                Started by SEQadmin2, 10-13-2026, 09:56 AM
                0 responses
                22 views
                0 reactions
                Last Post SEQadmin2  
                Started by SEQadmin2, 10-09-2026, 11:14 AM
                0 responses
                28 views
                0 reactions
                Last Post SEQadmin2  
                Working...