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
                Essential Discoveries and Tools in Epitranscriptomics
                by seqadmin


                The field of epigenetics has traditionally concentrated more on DNA and how changes like methylation and phosphorylation of histones impact gene expression and regulation. However, our increased understanding of RNA modifications and their importance in cellular processes has led to a rise in epitranscriptomics research. “Epitranscriptomics brings together the concepts of epigenetics and gene expression,” explained Adrien Leger, PhD, Principal Research Scientist on Modified Bases...
                Yesterday, 07:01 AM
              • 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

              ad_right_rmr

              Collapse

              News

              Collapse

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