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
                Advancing Precision Medicine for Rare Diseases in Children
                by seqadmin




                Many organizations study rare diseases, but few have a mission as impactful as Rady Children’s Institute for Genomic Medicine (RCIGM). “We are all about changing outcomes for children,” explained Dr. Stephen Kingsmore, President and CEO of the group. The institute’s initial goal was to provide rapid diagnoses for critically ill children and shorten their diagnostic odyssey, a term used to describe the long and arduous process it takes patients to obtain an accurate...
                12-16-2024, 07:57 AM
              • seqadmin
                Recent Advances in Sequencing Technologies
                by seqadmin



                Innovations in next-generation sequencing technologies and techniques are driving more precise and comprehensive exploration of complex biological systems. Current advancements include improved accessibility for long-read sequencing and significant progress in single-cell and 3D genomics. This article explores some of the most impactful developments in the field over the past year.

                Long-Read Sequencing
                Long-read sequencing has seen remarkable advancements,...
                12-02-2024, 01:49 PM

              ad_right_rmr

              Collapse

              News

              Collapse

              Topics Statistics Last Post
              Started by seqadmin, 12-17-2024, 10:28 AM
              0 responses
              22 views
              0 likes
              Last Post seqadmin  
              Started by seqadmin, 12-13-2024, 08:24 AM
              0 responses
              42 views
              0 likes
              Last Post seqadmin  
              Started by seqadmin, 12-12-2024, 07:41 AM
              0 responses
              28 views
              0 likes
              Last Post seqadmin  
              Started by seqadmin, 12-11-2024, 07:45 AM
              0 responses
              42 views
              0 likes
              Last Post seqadmin  
              Working...
              X