Seqanswers Leaderboard Ad

Collapse

Announcement

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

  • How to filter out chromosomes/specific regions from a BAM file?

    Is there any way of filtering out specific regions from a BAM file. Let's say I want to exclude the sex chromosomes from some analyses, is there any way to do this from a processed BAM file?
    Seems possible to do it by excluding those chromosomes from the reference fasta during the alignment. But does implies, ehem, starting the pipeline all over again!

    Cheers,
    Nando

  • #2
    Originally posted by fcr View Post
    Is there any way of filtering out specific regions from a BAM file. Let's say I want to exclude the sex chromosomes from some analyses, is there any way to do this from a processed BAM file?
    Seems possible to do it by excluding those chromosomes from the reference fasta during the alignment. But does implies, ehem, starting the pipeline all over again!

    Cheers,
    Nando
    I would make a file of regions you want to retain (e.g. a tab separated file with <chromosome> <start> <end> for all chromosomes but excluding, say, chrY and chrX). Then pass this file to samtools view.

    Dario
    Last edited by dariober; 02-13-2013, 02:23 AM. Reason: Do not use -R

    Comment


    • #3
      Thanks Dario,

      Ah, so it will work like this:

      samtools view aln.bam regions_to_keep.tab

      without the -R. Right??

      Cheers,
      Nando
      Last edited by fcr; 02-13-2013, 02:40 AM.

      Comment


      • #4
        Originally posted by fcr View Post
        Ahá damn simple, I guess this will work:

        samtools view -R aln.bam regions_to_keep.tab

        Thanks Dario!
        ...Hold on, I don't think -R is correct (I haven't tested it) I actually think you have to pass the file after the bam, without flag... (Sorry about the confusion)

        Comment


        • #5
          Ok, no worries. thanks again for your answer.

          Comment


          • #6
            i dont think realigning without certain parts of the reference is a good idea, because some reads will instead be mapping elsewhere in the genome.

            you could also use awk to filter:
            samtools view -h aln.bam | awk '{if($3 != "chrX" && $3 != "chrY"){print $0}}' | samtools view -Sb - > aln.filter.bam

            Comment


            • #7
              To filter out specific regions from a BAM file, you could use the -U option of samtools view:

              samtools view -b -L specificRegions.bed -U myFileWithoutSpecificRegions.bam myFile.bam > overlappingSpecificRegions.bam

              -b Output in the BAM format
              -L FILE Only output alignments overlapping the input BED FILE
              -U FILE Write alignments that are not selected by the various filter options to FILE. When this option is used, all alignments intersecting the regions specified are written to either the output file or this file, but never both

              Comment

              Latest Articles

              Collapse

              • 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
              • seqadmin
                Techniques and Challenges in Conservation Genomics
                by seqadmin



                The field of conservation genomics centers on applying genomics technologies in support of conservation efforts and the preservation of biodiversity. This article features interviews with two researchers who showcase their innovative work and highlight the current state and future of conservation genomics.

                Avian Conservation
                Matthew DeSaix, a recent doctoral graduate from Kristen Ruegg’s lab at The University of Colorado, shared that most of his research...
                03-08-2024, 10:41 AM

              ad_right_rmr

              Collapse

              News

              Collapse

              Topics Statistics Last Post
              Started by seqadmin, Yesterday, 06:37 PM
              0 responses
              10 views
              0 likes
              Last Post seqadmin  
              Started by seqadmin, Yesterday, 06:07 PM
              0 responses
              9 views
              0 likes
              Last Post seqadmin  
              Started by seqadmin, 03-22-2024, 10:03 AM
              0 responses
              50 views
              0 likes
              Last Post seqadmin  
              Started by seqadmin, 03-21-2024, 07:32 AM
              0 responses
              67 views
              0 likes
              Last Post seqadmin  
              Working...
              X