On Fri, Oct 23, 2015 at 03:55:10PM +0200, Bingding Huang wrote:
>      uint32_t *cigar = bam1_cigar(b)
>   string new_cigar="70M6S"
> // how can I change the cigare in b using this new_cigar value


cigar is an array of integers with the bottom BAM_CIGAR_SHIFT bits
(masked off with BAM_CIGAR_MASK) being the cigar opcode and the
remaining bits being the length.  See these in sam.h:

/****************************
 *** CIGAR related macros ***
 ****************************/

#define BAM_CMATCH      0
#define BAM_CINS        1
#define BAM_CDEL        2
#define BAM_CREF_SKIP   3
#define BAM_CSOFT_CLIP  4
#define BAM_CHARD_CLIP  5
#define BAM_CPAD        6
#define BAM_CEQUAL      7
#define BAM_CDIFF       8
#define BAM_CBACK       9

#define BAM_CIGAR_STR   "MIDNSHP=XB"
#define BAM_CIGAR_SHIFT 4
#define BAM_CIGAR_MASK  0xf
#define BAM_CIGAR_TYPE  0x3C1A7

#define bam_cigar_op(c) ((c)&BAM_CIGAR_MASK)
#define bam_cigar_oplen(c) ((c)>>BAM_CIGAR_SHIFT)
#define bam_cigar_opchr(c) (BAM_CIGAR_STR[bam_cigar_op(c)])
#define bam_cigar_gen(l, o) ((l)<<BAM_CIGAR_SHIFT|(o))


You cannot simply set it to a string although I guess you could write
a function that takes a string and generates the integers for you.

As to how it should be set, it's tricky as the bam in-memory structure
is squashed all into one block of memory, and due to the design of it
you don't get word-aligned memory access to CIGAR fields either.
(Whether that matters to you will depend on what CPUs you plan on
targetting, but fortunately the most widely used ones don't care about
memory alignment.)

This means you need to reallocate the entire bam core to be large
enough for the new cigar array and memmove things around to correct
the layout.  See samtools/padding.c (specifically the replace_cigar
function) for an example of how to do this.  I'm not aware of there
being a specific library API function to do this for you, but I may be
wrong on that front.

James

-- 
James Bonfield ([email protected]) | Hora aderat briligi. Nunc et Slythia Tova
                                  | Plurima gyrabant gymbolitare vabo;
  A Staden Package developer:     | Et Borogovorum mimzebant undique formae,
https://sf.net/projects/staden/   | Momiferique omnes exgrabure Rathi. 


-- 
 The Wellcome Trust Sanger Institute is operated by Genome Research 
 Limited, a charity registered in England with number 1021457 and a 
 company registered in England with number 2742969, whose registered 
 office is 215 Euston Road, London, NW1 2BE. 

------------------------------------------------------------------------------
_______________________________________________
Samtools-help mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/samtools-help

Reply via email to