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
              Advancing Precision Medicine for Rare Diseases in Children
              by seqadmin




              Many organizations study rare diseases, but few have a mission as impactful as Rady Children’s Institute for Genomic Medicine (RCIGM). “We are all about changing outcomes for children,” explained Dr. Stephen Kingsmore, President and CEO of the group. The institute’s initial goal was to provide rapid diagnoses for critically ill children and shorten their diagnostic odyssey, a term used to describe the long and arduous process it takes patients to obtain an accurate...
              12-16-2024, 07:57 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 seen remarkable advancements,...
              12-02-2024, 01:49 PM

            ad_right_rmr

            Collapse

            News

            Collapse

            Topics Statistics Last Post
            Started by seqadmin, 12-17-2024, 10:28 AM
            0 responses
            26 views
            0 likes
            Last Post seqadmin  
            Started by seqadmin, 12-13-2024, 08:24 AM
            0 responses
            42 views
            0 likes
            Last Post seqadmin  
            Started by seqadmin, 12-12-2024, 07:41 AM
            0 responses
            28 views
            0 likes
            Last Post seqadmin  
            Started by seqadmin, 12-11-2024, 07:45 AM
            0 responses
            42 views
            0 likes
            Last Post seqadmin  
            Working...
            X