samtools / htslib

C library for high-throughput sequencing data formats
Other
789 stars 447 forks source link

Extract auxiliary tags from BAM file #1588

Closed sagnikbanerjee15 closed 1 year ago

sagnikbanerjee15 commented 1 year ago

Hello,

I wish to extract some fields from a BAM file of B type. For example, jM:B:c,1 jI:B:i,3914,3995. Here is the code I am using:

uint8_t *jI = bam_aux_get(aln,"jI");
printf("\nValue of jI: %hhn", jI);
if(jI != NULL)
{
    char *jI_val = NULL;
    jI_val = bam_aux2Z(jI);
    printf("\njI:%s", jI_val);
}

I know what I am doing is incorrect but I am unsure what to replace it with. Could you please help?

Also, is there detailed documentation about the API?

Thank you.

daviesrob commented 1 year ago

For B tags, use bam_aux_get() followed by bam_auxB_len, then bam_auxB2i or bam_auxB2f depending on type.

sagnikbanerjee15 commented 1 year ago

Thanks it worked!