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
                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...
                Today, 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, 08:18 AM
              0 responses
              8 views
              0 likes
              Last Post seqadmin  
              Started by seqadmin, Today, 08:04 AM
              0 responses
              10 views
              0 likes
              Last Post seqadmin  
              Started by seqadmin, 06-03-2024, 06:55 AM
              0 responses
              13 views
              0 likes
              Last Post seqadmin  
              Started by seqadmin, 05-30-2024, 03:16 PM
              0 responses
              27 views
              0 likes
              Last Post seqadmin  
              Working...
              X