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
                  Best Practices for Single-Cell Sequencing Analysis
                  by seqadmin



                  While isolating and preparing single cells for sequencing was historically the bottleneck, recent technological advancements have shifted the challenge to data analysis. This highlights the rapidly evolving nature of single-cell sequencing. The inherent complexity of single-cell analysis has intensified with the surge in data volume and the incorporation of diverse and more complex datasets. This article explores the challenges in analysis, examines common pitfalls, offers...
                  06-06-2024, 07:15 AM
                • seqadmin
                  Latest Developments in Precision Medicine
                  by seqadmin



                  Technological advances have led to drastic improvements in the field of precision medicine, enabling more personalized approaches to treatment. This article explores four leading groups that are overcoming many of the challenges of genomic profiling and precision medicine through their innovative platforms and technologies.

                  Somatic Genomics
                  “We have such a tremendous amount of genetic diversity that exists within each of us, and not just between us as individuals,”...
                  05-24-2024, 01:16 PM

                ad_right_rmr

                Collapse

                News

                Collapse

                Topics Statistics Last Post
                Started by seqadmin, Today, 07:23 AM
                0 responses
                8 views
                0 likes
                Last Post seqadmin  
                Started by seqadmin, 06-17-2024, 06:54 AM
                0 responses
                11 views
                0 likes
                Last Post seqadmin  
                Started by seqadmin, 06-14-2024, 07:24 AM
                0 responses
                24 views
                0 likes
                Last Post seqadmin  
                Started by seqadmin, 06-13-2024, 08:58 AM
                0 responses
                18 views
                0 likes
                Last Post seqadmin  
                Working...
                X