Seqanswers Leaderboard Ad

Collapse

Announcement

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

  • samtools c api

    Hi all,

    Does anyone know if it is possible to use samtools c api to retrieve programmatically all alignments of a readid contained in an indexed bam file?

    I am looking for something like the the bam_fetch function but instead of retrieving alignments by chromosome position, I'd like to retrieve alignments by read id.

    Thanks in advance for your help.

  • #2
    samtools view your_file.bam | awk ' { if( $1 == "your_read_id" ){print $_} } '

    assuming that with read_id you meant the sequence name.

    You could also implement similar behavior in c / c++ by simply iterating over your file and checking the read_id.

    Cheers

    "You are only young once, but you can stay immature indefinitely."

    Comment


    • #3
      Hi, thanks a lot for your answer.

      I have to do this necessarily with the c api as this is part of a bigger program and I wanted to understand if it was possible to avoid iterating through the whole file and getting advantage of the index information somehow (i.e. something like the bam_fetch I mean)

      Thanks

      Comment


      • #4
        I don't think the (current) BAM indexes help access reads by their name (just by their mapped position).

        Comment


        • #5
          Depending how the bam is sorted you'll have to traverse the whole file but you can just iterate over all the alignments and save the ones that match the read id you are interested on. Once you have traversed the file you can dump the bam with those alignments.
          -drd

          Comment


          • #6
            I too don't think that this is possible in BAM currently without first building your own index.

            Comment


            • #7
              that's a shame... I will sort alignments by readid and go through the entire file then to retrieve those I am interested in.

              Thanks for the help guys

              Comment

              Latest Articles

              Collapse

              • 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
              • seqadmin
                Current Approaches to Protein Sequencing
                by seqadmin


                Proteins are often described as the workhorses of the cell, and identifying their sequences is key to understanding their role in biological processes and disease. Currently, the most common technique used to determine protein sequences is mass spectrometry. While still a valuable tool, mass spectrometry faces several limitations and requires a highly experienced scientist familiar with the equipment to operate it. Additionally, other proteomic methods, like affinity assays, are constrained...
                04-04-2024, 04:25 PM

              ad_right_rmr

              Collapse

              News

              Collapse

              Topics Statistics Last Post
              Started by seqadmin, Today, 08:47 AM
              0 responses
              12 views
              0 likes
              Last Post seqadmin  
              Started by seqadmin, 04-11-2024, 12:08 PM
              0 responses
              60 views
              0 likes
              Last Post seqadmin  
              Started by seqadmin, 04-10-2024, 10:19 PM
              0 responses
              59 views
              0 likes
              Last Post seqadmin  
              Started by seqadmin, 04-10-2024, 09:21 AM
              0 responses
              54 views
              0 likes
              Last Post seqadmin  
              Working...
              X