Seqanswers Leaderboard Ad

Collapse

Announcement

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

  • How can I extract the reads that map in genomic region?

    Hello,
    I have a bam file with the alignment of Illumina reads to a genome, and a bed file with the coordinates of some genomic regions.

    I found out the coverage of these regions using Bedtools, and now I want to retrieve the reads that map in these regions, but I do not know how to get the names of the reads.

    Is there any available tool to extract the reads that map in a particular genomic region?

    I thought Bedtools or Samtools would have it but I cannot find it.
    My only other idea is to blast the reads against these regions, but I know that the results would be different.

    Thank you for your help

  • #2
    Assuming your BAM file is sorted and indexed:

    Code:
    samtools view -h -L Regions.bed alignments.bam > alignments_in_regions.sam

    Comment


    • #3
      Originally posted by dpryan View Post
      Assuming your BAM file is sorted and indexed:

      Code:
      samtools view -h -L Regions.bed alignments.bam > alignments_in_regions.sam
      Sorry for blatantly hijacking this thread with a follow up question:

      Assuming paired-end reads, would this suggested command also extract reads wherein only one of the mates falls into the region? If not, how could I archive that?

      Comment


      • #4
        Originally posted by dexterslab View Post
        Sorry for blatantly hijacking this thread with a follow up question:

        Assuming paired-end reads, would this suggested command also extract reads wherein only one of the mates falls into the region? If not, how could I archive that?
        Good question. Looking at the source code for samtools, it appears that it processes reads one at a time (i.e., not as pairs). So, if only one mate in a pair overlapped a region, I expect only that read would be output and not its mate. If you need both mates, it's possible that bedops implements that (I've never looked, but wouldn't be surprised).

        Comment


        • #5
          Devon,
          maybe I'm wrong but did you meant to type "-L"?
          Because:

          "view: invalid option -- 'L'

          Usage: samtools view [options] <in.bam>|<in.sam> [region1 [...]]

          Options: -b output BAM
          -h print header for the SAM output
          -H print header only (no alignments)
          -S input is SAM
          -u uncompressed BAM output (force -b)
          -x output FLAG in HEX (samtools-C specific)
          -X output FLAG in string (samtools-C specific)
          -t FILE list of reference names and lengths (force -S) [null]
          -T FILE reference sequence file (force -S) [null]
          -o FILE output file name [stdout]
          -f INT required flag, 0 for unset [0]
          -F INT filtering flag, 0 for unset [0]
          -q INT minimum mapping quality [0]
          -l STR only output reads in library STR [null]
          -r STR only output reads in read group STR [null]
          -? longer help"

          Comment


          • #6
            Yes, but it seems that you have an earlier version of samtools (0.1.17 maybe?). Try upgrading, as I know the -L option is available in 0.1.18 and 0.1.19 (the most recent).

            Comment


            • #7
              BTW, here are the options for the most recent version (0.1.19):

              Code:
              Usage:   samtools view [options] <in.bam>|<in.sam> [region1 [...]]
              
              Options: -b       output BAM
                       -h       print header for the SAM output
                       -H       print header only (no alignments)
                       -S       input is SAM
                       -u       uncompressed BAM output (force -b)
                       -1       fast compression (force -b)
                       -x       output FLAG in HEX (samtools-C specific)
                       -X       output FLAG in string (samtools-C specific)
                       -c       print only the count of matching records
                       -B       collapse the backward CIGAR operation
                       -@ INT   number of BAM compression threads [0]
                       -L FILE  output alignments overlapping the input BED FILE [null]
                       -t FILE  list of reference names and lengths (force -S) [null]
                       -T FILE  reference sequence file (force -S) [null]
                       -o FILE  output file name [stdout]
                       -R FILE  list of read groups to be outputted [null]
                       -f INT   required flag, 0 for unset [0]
                       -F INT   filtering flag, 0 for unset [0]
                       -q INT   minimum mapping quality [0]
                       -l STR   only output reads in library STR [null]
                       -r STR   only output reads in read group STR [null]
                       -s FLOAT fraction of templates to subsample; integer part as seed [-1]
                       -?       longer help
              You'll also often find the -@ option useful, at least if you ever need to make BAM files.

              Comment

              Latest Articles

              Collapse

              • seqadmin
                Exploring the Dynamics of the Tumor Microenvironment
                by seqadmin




                The complexity of cancer is clearly demonstrated in the diverse ecosystem of the tumor microenvironment (TME). The TME is made up of numerous cell types and its development begins with the changes that happen during oncogenesis. “Genomic mutations, copy number changes, epigenetic alterations, and alternative gene expression occur to varying degrees within the affected tumor cells,” explained Andrea O’Hara, Ph.D., Strategic Technical Specialist at Azenta. “As...
                07-08-2024, 03:19 PM
              • seqadmin
                Exploring Human Diversity Through Large-Scale Omics
                by seqadmin


                In 2003, researchers from the Human Genome Project (HGP) announced the most comprehensive genome to date1. Although the genome wasn’t fully completed until nearly 20 years later2, numerous large-scale projects, such as the International HapMap Project and 1000 Genomes Project, continued the HGP's work, capturing extensive variation and genomic diversity within humans. Recently, newer initiatives have significantly increased in scale and expanded beyond genomics, offering a more detailed...
                06-25-2024, 06:43 AM

              ad_right_rmr

              Collapse

              News

              Collapse

              Topics Statistics Last Post
              Started by seqadmin, 07-16-2024, 05:49 AM
              0 responses
              26 views
              0 likes
              Last Post seqadmin  
              Started by seqadmin, 07-15-2024, 06:53 AM
              0 responses
              32 views
              0 likes
              Last Post seqadmin  
              Started by seqadmin, 07-10-2024, 07:30 AM
              0 responses
              40 views
              0 likes
              Last Post seqadmin  
              Started by seqadmin, 07-03-2024, 09:45 AM
              0 responses
              205 views
              0 likes
              Last Post seqadmin  
              Working...
              X