Seqanswers Leaderboard Ad

Collapse

Announcement

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

  • 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

  • #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


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

      Comment


      • #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


        • #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

          • 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
          15 views
          0 likes
          Last Post seqadmin  
          Started by seqadmin, 05-10-2024, 06:35 AM
          0 responses
          37 views
          0 likes
          Last Post seqadmin  
          Started by seqadmin, 05-09-2024, 02:46 PM
          0 responses
          46 views
          0 likes
          Last Post seqadmin  
          Started by seqadmin, 05-07-2024, 06:57 AM
          0 responses
          39 views
          0 likes
          Last Post seqadmin  
          Working...
          X