1 /* ===========================================================================
2  *
3  *                            PUBLIC DOMAIN NOTICE
4  *               National Center for Biotechnology Information
5  *
6  *  This software/database is a "United States Government Work" under the
7  *  terms of the United States Copyright Act.  It was written as part of
8  *  the author's official duties as a United States Government employee and
9  *  thus cannot be copyrighted.  This software/database is freely available
10  *  to the public for use. The National Library of Medicine and the U.S.
11  *  Government have not placed any restriction on its use or reproduction.
12  *
13  *  Although all reasonable efforts have been taken to ensure the accuracy
14  *  and reliability of the software and data, the NLM and the U.S.
15  *  Government do not and cannot warrant the performance or results that
16  *  may be obtained by using this software or data. The NLM and the U.S.
17  *  Government disclaim all warranties, express or implied, including
18  *  warranties of performance, merchantability or fitness for any particular
19  *  purpose.
20  *
21  *  Please cite the author in any work or product based on this material.
22  *
23  * ===========================================================================
24  */
25 
26 struct BAM_ReadCollection;
27 
28 typedef struct BAM_Record BAM_Record;
29 struct BAM_Record {
30     uint8_t const *extra;
31     char const *QNAME;
32     char const *RNAME;
33     char const *RNEXT;
34     char const *SEQ;
35     char const *QUAL;
36 
37     uint32_t POS;
38     uint32_t PNEXT;
39 
40     int32_t TLEN;
41     int32_t REFID;
42 
43     uint32_t seqlen;
44     uint32_t ncigar;
45     uint32_t extralen;
46 
47     uint16_t FLAG;
48     uint8_t MAPQ;
49     uint8_t padd;
50 
51     uint32_t cigar[1];
52 };
53 
54 typedef struct BAM_Record_Extra_Field BAM_Record_Extra_Field;
55 struct BAM_Record_Extra_Field {
56     char const *tag;
57     union {
58         uint8_t   u8[4]; /* for val_type == 'C' */
59         uint16_t u16[2]; /* for val_type == 'S' */
60         uint32_t u32[1]; /* for val_type == 'I' */
61         int8_t    i8[4]; /* for val_type == 'c' */
62         int16_t  i16[2]; /* for val_type == 's' */
63         int32_t  i32[1]; /* for val_type == 'i' */
64         float    f32[1]; /* for val_type == 'f' */
65         char  string[1]; /* for val_type == 'A', 'Z', or 'H'
66                           * for 'Z' and 'H' elemcount is strlen
67                           * but the value is still null terminated */
68     } const *value;      /* all multi-byte values are little-endian,
69                           * byte swap as needed */
70     int elemcount;
71     int fieldsize;
72     char val_type;
73 };
74 
75 typedef bool (*BAM_Record_ForEachExtra_cb)( void *usr_ctx, ctx_t ctx,
76                                             unsigned ordinal,
77                                             BAM_Record_Extra_Field const *fld );
78 
79 unsigned BAM_Record_ForEachExtra(BAM_Record const *self, ctx_t ctx,
80                                  BAM_Record_ForEachExtra_cb, void *usr_ctx);
81 
82 BAM_Record *BAM_GetRecord(struct NGS_Refcount *const self, ctx_t ctx);
83