Seqanswers Leaderboard Ad

Collapse

Announcement

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

  • 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

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


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


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


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


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


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


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


                Comment

                Latest Articles

                Collapse

                • seqadmin
                  Current Approaches to Protein Sequencing
                  by seqadmin


                  Proteins are often described as the workhorses of the cell, and identifying their sequences is key to understanding their role in biological processes and disease. Currently, the most common technique used to determine protein sequences is mass spectrometry. While still a valuable tool, mass spectrometry faces several limitations and requires a highly experienced scientist familiar with the equipment to operate it. Additionally, other proteomic methods, like affinity assays, are constrained...
                  04-04-2024, 04:25 PM
                • seqadmin
                  Strategies for Sequencing Challenging Samples
                  by seqadmin


                  Despite advancements in sequencing platforms and related sample preparation technologies, certain sample types continue to present significant challenges that can compromise sequencing results. Pedro Echave, Senior Manager of the Global Business Segment at Revvity, explained that the success of a sequencing experiment ultimately depends on the amount and integrity of the nucleic acid template (RNA or DNA) obtained from a sample. “The better the quality of the nucleic acid isolated...
                  03-22-2024, 06:39 AM

                ad_right_rmr

                Collapse

                News

                Collapse

                Topics Statistics Last Post
                Started by seqadmin, 04-11-2024, 12:08 PM
                0 responses
                24 views
                0 likes
                Last Post seqadmin  
                Started by seqadmin, 04-10-2024, 10:19 PM
                0 responses
                25 views
                0 likes
                Last Post seqadmin  
                Started by seqadmin, 04-10-2024, 09:21 AM
                0 responses
                21 views
                0 likes
                Last Post seqadmin  
                Started by seqadmin, 04-04-2024, 09:00 AM
                0 responses
                52 views
                0 likes
                Last Post seqadmin  
                Working...
                X