Unconfigured Ad

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • serhatg
    Member
    • Mar 2014
    • 10

    #1

    Using samtools view function in my own code?

    Hey all,

    I'd like to use samtools view function in my own code in order to map all the reads within some genomic coordinates such as chr1:200000-500000

    There is main_samview function in sam_view.c source code file, however I couldn't figure it out how to use it in this case. Besides, when including sam_view.c in my program I get some compilation errors.

    P.S. What I want to do is to store all the reads belong to a specific region in a vector of strings. I can view the reads in a region my using samtools view file.bam chr1:10000-50000, but I want to store them in a vector inside my program for later use.

    Any help would be appreciated, thank you.
    Last edited by serhatg; 03-28-2014, 12:52 AM. Reason: more details
  • dpryan
    Devon Ryan
    • Jul 2011
    • 3478

    #2
    A somewhat outdated version of the API is here. The idea is to not include the C files, but just the bam.h header and then link to libbam.a, which isn't installed anywhere by default...this is somewhat unfortunate though I understand the reasons.

    The actual steps would be as follows:
    1. Parse a region (foo:start-end) into chromosome/contig id (tid), start and end positions.
    2. The these values in bam_fetch()
    3. bam_fetch() calls a user-defined function of the form "typedef int (*bam_fetch_f)(const bam1_t *b, void *data)" for every returned alignment.


    Note that "data" is a pointer to an object that you can control, so presumably whatever buffer you want to store things in.

    Comment

    • serhatg
      Member
      • Mar 2014
      • 10

      #3
      Thanks a lot @dpryan that has been so helpful!

      Comment

      • serhatg
        Member
        • Mar 2014
        • 10

        #4
        Dear dpryan,

        I couldn't figure out a way to store all the allignments in a vector<bam1_t>. I have declared this vector as a global variable rather then sending it by data parameter, and I push back the "const bam1_t *b" object whenever the user defined function is called, but at the end it assigns unreadable data such as to sequence name( Probably I can't manage to deppcopy the value assigned by pointer 'b'). And the cigar strings stored in the core variable of vectors are right when there is just one cigar operation.

        To sum it up, I am looking for a way to store all the allignments belong to the region, which means to store all the return "const bam1_t *b" variables for later use.

        Could you please gimme some idea,

        Thank you.
        Last edited by serhatg; 04-03-2014, 04:42 AM.

        Comment

        • dpryan
          Devon Ryan
          • Jul 2011
          • 3478

          #5
          If you send me the code you have at the moment I'll try to have a look. You can just email it to me (my_username@my_username.com, where my_username=dpryan) if you don't want to post the whole thing somewhere.

          Comment

          Latest Articles

          Collapse

          • SEQadmin2
            Multiomic Liquid Biopsy: What DNA/RNA Panels Reveal That DNA Alone Can’t
            by SEQadmin2



            Tumors contain complex mixtures of cell populations that evolve in response to treatment and host-specific factors. Tissue biopsies provide only static snapshots of a tumor’s state. But what if we could follow that evolution over time using a minimally invasive technique?

            Liquid biopsies can detect tumor-derived material circulating in the bloodstream, providing a way to study treatment response, detect emerging resistance, and discover new biomarkers. Circulating
            ...
            10-14-2026, 09:55 AM
          • SEQadmin2
            New Genomics Technologies Take Aim at Long-Standing Limits
            by SEQadmin2


            Researchers using sequencing and genomics tools often have to make trade-offs. They can choose between speed or scale, short reads or long-range information, or targeted panels or a view of the whole transcriptome. New technologies that have been released this year are built to address those tough choices.

            We asked six companies the same four questions to learn about their latest products. The new technologies bring a lot to the table, including rethinking sequencing
            ...
            09-28-2026, 10:25 AM

          ad_right_rmr

          Collapse

          News

          Collapse

          Topics Statistics Last Post
          Started by SEQadmin2, 10-22-2026, 11:13 AM
          0 responses
          22 views
          0 reactions
          Last Post SEQadmin2  
          Started by SEQadmin2, 10-22-2026, 10:48 AM
          0 responses
          19 views
          0 reactions
          Last Post SEQadmin2  
          Started by SEQadmin2, 10-15-2026, 10:52 AM
          0 responses
          36 views
          0 reactions
          Last Post SEQadmin2  
          Started by SEQadmin2, 10-14-2026, 05:39 AM
          0 responses
          42 views
          0 reactions
          Last Post SEQadmin2  
          Working...