ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/gclib/gclib/GBam.cpp
(Generate patch)
# Line 2 | Line 2
2   #include <ctype.h>
3   #include "kstring.h"
4  
5 < //auxiliary functions for BAM record handling
5 > //auxiliary functions for low level BAM record creation
6   uint8_t* realloc_bdata(bam1_t *b, int size) {
7    if (b->m_data < size) {
8          b->m_data = size;
# Line 35 | Line 35
35     novel=true;
36     bam_header=NULL;
37     b=bam_init1();
38 <   b->core.tid=gseq_tid;
39 <   if (pos<=0) {
38 >   if (pos<=0 || gseq_tid<0) {
39                 b->core.pos=-1; //unmapped
41               //if (gseq_tid<0)
40                 b->core.flag |= BAM_FUNMAP;
41 +               gseq_tid=-1;
42                 }
43            else b->core.pos=pos-1; //BAM is 0-based
44 +   b->core.tid=gseq_tid;
45     b->core.qual=255;
46 +   b->core.mtid=-1;
47 +   b->core.mpos=-1;
48     int l_qseq=strlen(qseq);
49     //this may not be accurate, setting CIGAR is the correct way
50     //b->core.bin = bam_reg2bin(b->core.pos, b->core.pos+l_qseq-1);
# Line 168 | Line 170
170  
171   void GBamRecord::add_aux(const char* str) {
172       //requires: being called AFTER add_quals()
171     static char tag[2];
172     static uint8_t abuf[512];
173     //requires: being called AFTER add_quals()
173       int strl=strlen(str);
174       //int doff = b->core.l_qname + b->core.n_cigar*4 + (b->core.l_qseq+1)/2 + b->core.l_qseq + b->l_aux;
175       //int doff0=doff;
# Line 266 | Line 265
265             else if (op == BAM_CREF_SKIP) { //N
266                 //intron starts
267                 //exon ends here
268 <               exons.Add(new GSeg(exstart+1,l));
268 >               GSeg exon(exstart+1,c->pos+l);
269 >               exons.Add(exon);
270                 l += cigar[i]>>4;
271                 exstart=c->pos+l;
272                 }
273          }
274 <   exons.Add(new GSeg(exstart+1, l));
274 >   GSeg exon(exstart+1,c->pos+l);
275 >   exons.Add(exon);
276     end=c->pos+l;
277   }
278  
279   int GBamRecord::find_tag(const char tag[2], uint8_t* & s, char& tag_type) {
280     //position s at the beginning of tag "data" (after the type char)
281     //returns the length of tag data, and tag type in tag_type
282 <   s=bam1_aux(b);
283 <   while (s < b->data + b->data_len) {
282 >   uint8_t* aux_start=bam1_aux(b);
283 >   s=aux_start;
284 >   while (s < aux_start + b->l_aux - 1) {
285       char key[2];
286       key[0] = (char)s[0]; key[1] = (char)s[1];
287       s += 2; tag_type = (char)*s; ++s;
# Line 317 | Line 319
319                           { m_inc = 2; }
320             else if ('i' == sub_type || 'I' == sub_type || 'f' == sub_type)
321                           { m_inc = 4; }
322 <           if (m_inc==0) GError("Error: invalid 'B' array subtype (%c)!\n",sub_type);
322 >           if (m_inc==0)
323 >                 GError("Error: invalid 'B' array subtype (%c)!\n",sub_type);
324             inc += m_inc*n;
325             break;
326         case 'H':
# Line 327 | Line 330
330         } //switch (tag_type)
331       if (tag[0]==key[0] && tag[1]==key[1])
332          return inc;
333 +     s+=inc;
334       }//while aux data
335     return 0;
336     }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines