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

              • performena
                Reply to Recent Advances in Sequencing Technologies
                by performena
                Performena is a digital-first creative agency based in the UAE. We craft resonant brand experiences through strategic consultancy, creative services, media planning, programmatic advertising, and custom technology solutions.

                Our journey began with a vision to revolutionize digital marketing. We combine data-driven insights with creative storytelling to deliver impactful campaigns that drive measurable results. Our team of wild hearts and tech wizards work tirelessly to unlock your brand's...
                Today, 05:26 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...
                Yesterday, 01:49 PM
              • seqadmin
                Genetic Variation in Immunogenetics and Antibody Diversity
                by seqadmin



                The field of immunogenetics explores how genetic variations influence immune responses and susceptibility to disease. In a recent SEQanswers webinar, Oscar Rodriguez, Ph.D., Postdoctoral Researcher at the University of Louisville, and Ruben Martínez Barricarte, Ph.D., Assistant Professor of Medicine at Vanderbilt University, shared recent advancements in immunogenetics. This article discusses their research on genetic variation in antibody loci, antibody production processes,...
                11-06-2024, 07:24 PM

              ad_right_rmr

              Collapse

              News

              Collapse

              Topics Statistics Last Post
              Started by seqadmin, Yesterday, 09:29 AM
              0 responses
              14 views
              0 likes
              Last Post seqadmin  
              Started by seqadmin, Yesterday, 09:06 AM
              0 responses
              11 views
              0 likes
              Last Post seqadmin  
              Started by seqadmin, Yesterday, 08:03 AM
              0 responses
              11 views
              0 likes
              Last Post seqadmin  
              Started by seqadmin, 11-22-2024, 07:36 AM
              0 responses
              65 views
              0 likes
              Last Post seqadmin  
              Working...
              X