ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/gclib/gclib/GBam.h
(Generate patch)
# Line 19 | Line 19
19     //   +seq  (4bit-encoded)
20     //    +qual
21     //     +aux
22 <   //bool novel; //created from scratch, not from a given bam1_t* record
22 >   bool novel; //created from scratch, not from a given bam1_t* record
23     bam_header_t* bam_header;
24 <
24 >   char tag[2];
25 >   uint8_t abuf[512];
26   public:
27     GVec<GSeg> exons;
28     //created from a reader:
# Line 29 | Line 30
30        bam_header=NULL;
31        if (from_b==NULL) {
32             b=bam_init1();
33 <           //novel=true;
33 >           novel=true;
34             }
35          else {
36 <           b=from_b; //it'll take over from_b and FREE it when destroyed
37 <           //novel=false;
36 >           b=from_b; //it'll take over from_b but not free it when destroyed
37 >           novel=false;
38             }
39        bam_header=b_header;
40        setupCoordinates();//sets start, end coordinate and populates exons array
# Line 43 | Line 44
44        //make a new copy of the bam1_t record etc.
45        clear();
46        b=bam_dup1(r.b);
47 <      //novel=true; //will also free b when destroyed
47 >      novel=true; //will also free b when destroyed
48        start=r.start;
49        end=r.end;
50        exons = r.exons;
# Line 52 | Line 53
53  
54       void setupCoordinates();
55       void clear() {
56 <        //if (novel) {
57 <        bam_destroy1(b);
58 <        //   novel=false;
59 <        //   }
56 >        if (novel) {
57 >           bam_destroy1(b);
58 >           novel=false;
59 >           }
60          b=NULL;
61          exons.Clear();
62          bam_header=NULL;
# Line 97 | Line 98
98      void add_quals(const char* quals); //quality values string in Phred33 format
99      void add_aux(const char* str); //adds one aux field in plain SAM text format (e.g. "NM:i:1")
100      void add_aux(const char tag[2], char atype, int len, uint8_t *data) {
101 +      //IMPORTANT:  strings (Z,H) should include the terminal \0
102 +      int addz=0;
103 +      if ((atype=='Z' || atype=='H') && data[len-1]!=0) {
104 +        addz=1;
105 +        }
106        int ori_len = b->data_len;
107 <      b->data_len += 3 + len;
108 <      b->l_aux += 3 + len;
107 >      b->data_len += 3 + len + addz;
108 >      b->l_aux += 3 + len + addz;
109        if (b->m_data < b->data_len) {
110          b->m_data = b->data_len;
111          kroundup32(b->m_data);
# Line 107 | Line 113
113        }
114        b->data[ori_len] = tag[0]; b->data[ori_len + 1] = tag[1];
115        b->data[ori_len + 2] = atype;
116 +      if (addz) {
117 +        b->data[ori_len+len+4]=0;
118 +        }
119        memcpy(b->data + ori_len + 3, data, len);
120        }
121 +
122      void add_tag(const char tag[2], char atype, int len, uint8_t *data) {
123        //same with add_aux()
124        add_aux(tag,atype,len,data);
# Line 143 | Line 153
153   int32_t insertSize() { return b->core.isize; }
154   int32_t mate_start() { return b->core.mpos<0? 0 : b->core.mpos+1; }
155  
156 < int find_tag(const char tag[2], uint8_t* & s, char& tag_type);
156 > //int find_tag(const char tag[2], uint8_t* & s, char& tag_type);
157 > uint8_t* find_tag(const char tag[2]);
158   //position s at the beginning of tag data, tag_type is set to the found tag type
159   //returns length of tag data, or 0 if tag not found
160  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines