Unconfigured Ad

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • blu78
    Member
    • Apr 2010
    • 20

    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.
  • Dethecor
    Member
    • May 2010
    • 24

    #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

    • blu78
      Member
      • Apr 2010
      • 20

      #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

      • maubp
        Peter (Biopython etc)
        • Jul 2009
        • 1544

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

        Comment

        • drio
          Senior Member
          • Oct 2008
          • 323

          #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

          • jkbonfield
            Senior Member
            • Jul 2008
            • 146

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

            Comment

            • blu78
              Member
              • Apr 2010
              • 20

              #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

              • mylaser
                Reply to Advanced Sequencing Platforms Tackle Neuroscience’s Toughest Genomics Problems
                by mylaser
                Kheloyar – Everything You Need to Know About Kheloyaar Login and Kheoyar Id
                If you are looking for an online gaming platform that offers a user-friendly experience, Kheloyar has become a name that many users search for. Whether you're interested in creating a new account, accessing your dashboard through Kheloyaar Login, or learning how to obtain a Kheoyar Id, understanding the platform's features and account process is essential.
                This guide explains everything you need to know about...
                Yesterday, 01:13 AM
              • SEQadmin2
                Advanced Sequencing Platforms Tackle Neuroscience’s Toughest Genomics Problems
                by SEQadmin2



                Genomics studies in neuroscience face a special challenge due to the brain’s complexity and scarcity of samples. Mapping changes in cell type and state using conventional next-generation sequencing methods remains challenging. Advances in technologies like single-cell sequencing, spatial transcriptomics, and long-read sequencing have opened the door to deeper studies of the brain and diseases like Alzheimer’s, amyotrophic lateral sclerosis (ALS), and schizophrenia.
                ...
                07-09-2026, 11:10 AM
              • SEQadmin2
                Cancer Drug Resistance: The Lingering Barrier to Rising Survival
                by SEQadmin2



                Cancer survival rates have significantly increased in the last few decades in the United States, reaching a combined 70% 5-year survival rate by 2021. Behind this number, there are years of research to find new therapies, drug targets, and early detection methods. But there is one core challenge that keeps slowing down these advances, and it’s about drug resistance.

                There is no single reason why many patients don’t respond to treatment as expected. Cancer is...
                07-08-2026, 05:17 AM

              ad_right_rmr

              Collapse

              News

              Collapse

              Topics Statistics Last Post
              Started by SEQadmin2, 07-09-2026, 10:04 AM
              0 responses
              20 views
              0 reactions
              Last Post SEQadmin2  
              Started by SEQadmin2, 07-08-2026, 10:08 AM
              0 responses
              12 views
              0 reactions
              Last Post SEQadmin2  
              Started by SEQadmin2, 07-07-2026, 11:05 AM
              0 responses
              30 views
              0 reactions
              Last Post SEQadmin2  
              Started by SEQadmin2, 07-02-2026, 11:08 AM
              0 responses
              31 views
              0 reactions
              Last Post SEQadmin2  
              Working...