Seqanswers Leaderboard Ad

Collapse

Announcement

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

  • Can you read a bam file by mate pairs?

    I need to process a bam file by reading mate pairs together i.e. each read of the bam file must return TWO alignments to analyze together.

    I have been using the Bam API function bam_read_1 (http://samtools.sourceforge.net/samt...func/bam_read1) which returns the "next" alignment in a bam. And I know that the alignment object has some basic info about the mate, but I am looking for all of the mate's alignment.

    I realize that a bam file is usually sorted by genome coordinates and therefore the mate pairs are not together and that "next pair" call to a function like bam_read_1 is ambiguous since there are two positions in the bam file that are being read.

    Nevertheless, I wonder, is there a way to get a pointer from each alignment to that of its mate? (I know we then have to worry about whether the "next" alignment has already been read as some other read's mate, but still...)

    This seems like it should be a common programming problem in reading bam files. Curious if there is any solution out there.

    Thanks,
    Gulu
    Kamalakar Gulukota,
    Director,
    Center for Bioinformatics and Computational Biology
    NorthShore University Health System, [email protected]

  • #2
    If you sort your file by name, instead of coordinate, the pairs will be next to each other.

    Comment


    • #3
      Just name-sort the file and then you can (normally) just take two reads at a time. I mention normally since some programs, such as tophat, will leave orphaned reads and leave them marked as paired.

      Edit: I guess I should have updated before replying, since swbarnes2 beat me to it. I'll add that I do this in the methylation extractor in bison, which also uses the samtools C API.
      Last edited by dpryan; 08-28-2013, 12:25 PM.

      Comment


      • #4
        Originally posted by kgulukota View Post
        I need to process a bam file by reading mate pairs together i.e. each read of the bam file must return TWO alignments to analyze together.

        I have been using the Bam API function bam_read_1 (http://samtools.sourceforge.net/samt...func/bam_read1) which returns the "next" alignment in a bam. And I know that the alignment object has some basic info about the mate, but I am looking for all of the mate's alignment.

        I realize that a bam file is usually sorted by genome coordinates and therefore the mate pairs are not together and that "next pair" call to a function like bam_read_1 is ambiguous since there are two positions in the bam file that are being read.

        Nevertheless, I wonder, is there a way to get a pointer from each alignment to that of its mate? (I know we then have to worry about whether the "next" alignment has already been read as some other read's mate, but still...)

        This seems like it should be a common programming problem in reading bam files. Curious if there is any solution out there.

        Thanks,
        Gulu
        As the previous replies already state, one way to collate all the pairs is to perform a full sorting by query name. For most BAM files this is however a waste of computational resources, as even if the file is not sorted by name, the pairs will be close together. The biobambam package (https://github.com/gt1/biobambam, Linux binaries at ftp://ftp.sanger.ac.uk/pub/users/gt1/biobambam/) contains a tool named bamcollate which reads a BAM file from standard input and outputs a BAM file on standard output in which the ends of the pairs appear consecutively. It tries to find pairs which are close together in the file without sorting and only performs sorting for those which are far apart. There is an API also (see http://arxiv.org/abs/1306.0836).

        Comment


        • #5
          Thank you @dpryan and @swbarnes2. But sorting by name won't work for me. My project involves examining reads mapped to a particular region - so I have to sort by coordinate in order to load index and use bam_fetch.

          So, the real question is: when bam_fetch retrieves an alignment in the region of interest, is there a way to quickly skip to the mate's alignment?

          Thank you @gt1. I will check it out.
          Kamalakar Gulukota,
          Director,
          Center for Bioinformatics and Computational Biology
          NorthShore University Health System, [email protected]

          Comment


          • #6
            There's no direct function for that. The best you can do is bam_fetch the appropriate area and then iterate through the results until you find the mate. I presume that this is what the package that gt1 posted does.

            Comment

            Latest Articles

            Collapse

            • seqadmin
              Recent Advances in Sequencing Analysis Tools
              by seqadmin


              The sequencing world is rapidly changing due to declining costs, enhanced accuracies, and the advent of newer, cutting-edge instruments. Equally important to these developments are improvements in sequencing analysis, a process that converts vast amounts of raw data into a comprehensible and meaningful form. This complex task requires expertise and the right analysis tools. In this article, we highlight the progress and innovation in sequencing analysis by reviewing several of the...
              05-06-2024, 07:48 AM
            • 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...
              04-22-2024, 07:01 AM

            ad_right_rmr

            Collapse

            News

            Collapse

            Topics Statistics Last Post
            Started by seqadmin, 05-14-2024, 07:03 AM
            0 responses
            26 views
            0 likes
            Last Post seqadmin  
            Started by seqadmin, 05-10-2024, 06:35 AM
            0 responses
            45 views
            0 likes
            Last Post seqadmin  
            Started by seqadmin, 05-09-2024, 02:46 PM
            0 responses
            59 views
            0 likes
            Last Post seqadmin  
            Started by seqadmin, 05-07-2024, 06:57 AM
            0 responses
            46 views
            0 likes
            Last Post seqadmin  
            Working...
            X