annotate PsiCLASS-1.0.2/samtools-0.1.19/bam_pileup.c @ 0:903fc43d6227 draft default tip

Uploaded
author lsong10
date Fri, 26 Mar 2021 16:52:45 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
1 #include <stdio.h>
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
2 #include <stdlib.h>
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
3 #include <ctype.h>
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
4 #include <assert.h>
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
5 #include "sam.h"
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
6
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
7 typedef struct {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
8 int k, x, y, end;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
9 } cstate_t;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
10
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
11 static cstate_t g_cstate_null = { -1, 0, 0, 0 };
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
12
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
13 typedef struct __linkbuf_t {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
14 bam1_t b;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
15 uint32_t beg, end;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
16 cstate_t s;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
17 struct __linkbuf_t *next;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
18 } lbnode_t;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
19
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
20 /* --- BEGIN: Memory pool */
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
21
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
22 typedef struct {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
23 int cnt, n, max;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
24 lbnode_t **buf;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
25 } mempool_t;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
26
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
27 static mempool_t *mp_init()
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
28 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
29 mempool_t *mp;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
30 mp = (mempool_t*)calloc(1, sizeof(mempool_t));
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
31 return mp;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
32 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
33 static void mp_destroy(mempool_t *mp)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
34 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
35 int k;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
36 for (k = 0; k < mp->n; ++k) {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
37 free(mp->buf[k]->b.data);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
38 free(mp->buf[k]);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
39 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
40 free(mp->buf);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
41 free(mp);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
42 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
43 static inline lbnode_t *mp_alloc(mempool_t *mp)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
44 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
45 ++mp->cnt;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
46 if (mp->n == 0) return (lbnode_t*)calloc(1, sizeof(lbnode_t));
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
47 else return mp->buf[--mp->n];
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
48 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
49 static inline void mp_free(mempool_t *mp, lbnode_t *p)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
50 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
51 --mp->cnt; p->next = 0; // clear lbnode_t::next here
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
52 if (mp->n == mp->max) {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
53 mp->max = mp->max? mp->max<<1 : 256;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
54 mp->buf = (lbnode_t**)realloc(mp->buf, sizeof(lbnode_t*) * mp->max);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
55 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
56 mp->buf[mp->n++] = p;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
57 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
58
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
59 /* --- END: Memory pool */
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
60
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
61 /* --- BEGIN: Auxiliary functions */
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
62
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
63 /* s->k: the index of the CIGAR operator that has just been processed.
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
64 s->x: the reference coordinate of the start of s->k
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
65 s->y: the query coordiante of the start of s->k
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
66 */
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
67 static inline int resolve_cigar2(bam_pileup1_t *p, uint32_t pos, cstate_t *s)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
68 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
69 #define _cop(c) ((c)&BAM_CIGAR_MASK)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
70 #define _cln(c) ((c)>>BAM_CIGAR_SHIFT)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
71
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
72 bam1_t *b = p->b;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
73 bam1_core_t *c = &b->core;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
74 uint32_t *cigar = bam1_cigar(b);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
75 int k, is_head = 0;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
76 // determine the current CIGAR operation
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
77 // fprintf(stderr, "%s\tpos=%d\tend=%d\t(%d,%d,%d)\n", bam1_qname(b), pos, s->end, s->k, s->x, s->y);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
78 if (s->k == -1) { // never processed
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
79 is_head = 1;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
80 if (c->n_cigar == 1) { // just one operation, save a loop
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
81 if (_cop(cigar[0]) == BAM_CMATCH || _cop(cigar[0]) == BAM_CEQUAL || _cop(cigar[0]) == BAM_CDIFF) s->k = 0, s->x = c->pos, s->y = 0;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
82 } else { // find the first match or deletion
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
83 for (k = 0, s->x = c->pos, s->y = 0; k < c->n_cigar; ++k) {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
84 int op = _cop(cigar[k]);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
85 int l = _cln(cigar[k]);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
86 if (op == BAM_CMATCH || op == BAM_CDEL || op == BAM_CEQUAL || op == BAM_CDIFF) break;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
87 else if (op == BAM_CREF_SKIP) s->x += l;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
88 else if (op == BAM_CINS || op == BAM_CSOFT_CLIP) s->y += l;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
89 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
90 assert(k < c->n_cigar);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
91 s->k = k;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
92 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
93 } else { // the read has been processed before
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
94 int op, l = _cln(cigar[s->k]);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
95 if (pos - s->x >= l) { // jump to the next operation
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
96 assert(s->k < c->n_cigar); // otherwise a bug: this function should not be called in this case
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
97 op = _cop(cigar[s->k+1]);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
98 if (op == BAM_CMATCH || op == BAM_CDEL || op == BAM_CREF_SKIP || op == BAM_CEQUAL || op == BAM_CDIFF) { // jump to the next without a loop
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
99 if (_cop(cigar[s->k]) == BAM_CMATCH|| _cop(cigar[s->k]) == BAM_CEQUAL || _cop(cigar[s->k]) == BAM_CDIFF) s->y += l;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
100 s->x += l;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
101 ++s->k;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
102 } else { // find the next M/D/N/=/X
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
103 if (_cop(cigar[s->k]) == BAM_CMATCH|| _cop(cigar[s->k]) == BAM_CEQUAL || _cop(cigar[s->k]) == BAM_CDIFF) s->y += l;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
104 s->x += l;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
105 for (k = s->k + 1; k < c->n_cigar; ++k) {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
106 op = _cop(cigar[k]), l = _cln(cigar[k]);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
107 if (op == BAM_CMATCH || op == BAM_CDEL || op == BAM_CREF_SKIP || op == BAM_CEQUAL || op == BAM_CDIFF) break;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
108 else if (op == BAM_CINS || op == BAM_CSOFT_CLIP) s->y += l;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
109 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
110 s->k = k;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
111 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
112 assert(s->k < c->n_cigar); // otherwise a bug
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
113 } // else, do nothing
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
114 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
115 { // collect pileup information
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
116 int op, l;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
117 op = _cop(cigar[s->k]); l = _cln(cigar[s->k]);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
118 p->is_del = p->indel = p->is_refskip = 0;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
119 if (s->x + l - 1 == pos && s->k + 1 < c->n_cigar) { // peek the next operation
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
120 int op2 = _cop(cigar[s->k+1]);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
121 int l2 = _cln(cigar[s->k+1]);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
122 if (op2 == BAM_CDEL) p->indel = -(int)l2;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
123 else if (op2 == BAM_CINS) p->indel = l2;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
124 else if (op2 == BAM_CPAD && s->k + 2 < c->n_cigar) { // no working for adjacent padding
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
125 int l3 = 0;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
126 for (k = s->k + 2; k < c->n_cigar; ++k) {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
127 op2 = _cop(cigar[k]); l2 = _cln(cigar[k]);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
128 if (op2 == BAM_CINS) l3 += l2;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
129 else if (op2 == BAM_CDEL || op2 == BAM_CMATCH || op2 == BAM_CREF_SKIP || op2 == BAM_CEQUAL || op2 == BAM_CDIFF) break;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
130 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
131 if (l3 > 0) p->indel = l3;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
132 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
133 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
134 if (op == BAM_CMATCH || op == BAM_CEQUAL || op == BAM_CDIFF) {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
135 p->qpos = s->y + (pos - s->x);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
136 } else if (op == BAM_CDEL || op == BAM_CREF_SKIP) {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
137 p->is_del = 1; p->qpos = s->y; // FIXME: distinguish D and N!!!!!
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
138 p->is_refskip = (op == BAM_CREF_SKIP);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
139 } // cannot be other operations; otherwise a bug
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
140 p->is_head = (pos == c->pos); p->is_tail = (pos == s->end);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
141 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
142 return 1;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
143 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
144
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
145 /* --- END: Auxiliary functions */
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
146
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
147 /*******************
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
148 * pileup iterator *
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
149 *******************/
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
150
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
151 struct __bam_plp_t {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
152 mempool_t *mp;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
153 lbnode_t *head, *tail, *dummy;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
154 int32_t tid, pos, max_tid, max_pos;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
155 int is_eof, flag_mask, max_plp, error, maxcnt;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
156 bam_pileup1_t *plp;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
157 // for the "auto" interface only
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
158 bam1_t *b;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
159 bam_plp_auto_f func;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
160 void *data;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
161 };
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
162
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
163 bam_plp_t bam_plp_init(bam_plp_auto_f func, void *data)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
164 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
165 bam_plp_t iter;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
166 iter = calloc(1, sizeof(struct __bam_plp_t));
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
167 iter->mp = mp_init();
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
168 iter->head = iter->tail = mp_alloc(iter->mp);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
169 iter->dummy = mp_alloc(iter->mp);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
170 iter->max_tid = iter->max_pos = -1;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
171 iter->flag_mask = BAM_DEF_MASK;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
172 iter->maxcnt = 8000;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
173 if (func) {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
174 iter->func = func;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
175 iter->data = data;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
176 iter->b = bam_init1();
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
177 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
178 return iter;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
179 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
180
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
181 void bam_plp_destroy(bam_plp_t iter)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
182 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
183 mp_free(iter->mp, iter->dummy);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
184 mp_free(iter->mp, iter->head);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
185 if (iter->mp->cnt != 0)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
186 fprintf(stderr, "[bam_plp_destroy] memory leak: %d. Continue anyway.\n", iter->mp->cnt);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
187 mp_destroy(iter->mp);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
188 if (iter->b) bam_destroy1(iter->b);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
189 free(iter->plp);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
190 free(iter);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
191 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
192
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
193 const bam_pileup1_t *bam_plp_next(bam_plp_t iter, int *_tid, int *_pos, int *_n_plp)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
194 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
195 if (iter->error) { *_n_plp = -1; return 0; }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
196 *_n_plp = 0;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
197 if (iter->is_eof && iter->head->next == 0) return 0;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
198 while (iter->is_eof || iter->max_tid > iter->tid || (iter->max_tid == iter->tid && iter->max_pos > iter->pos)) {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
199 int n_plp = 0;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
200 lbnode_t *p, *q;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
201 // write iter->plp at iter->pos
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
202 iter->dummy->next = iter->head;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
203 for (p = iter->head, q = iter->dummy; p->next; q = p, p = p->next) {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
204 if (p->b.core.tid < iter->tid || (p->b.core.tid == iter->tid && p->end <= iter->pos)) { // then remove
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
205 q->next = p->next; mp_free(iter->mp, p); p = q;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
206 } else if (p->b.core.tid == iter->tid && p->beg <= iter->pos) { // here: p->end > pos; then add to pileup
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
207 if (n_plp == iter->max_plp) { // then double the capacity
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
208 iter->max_plp = iter->max_plp? iter->max_plp<<1 : 256;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
209 iter->plp = (bam_pileup1_t*)realloc(iter->plp, sizeof(bam_pileup1_t) * iter->max_plp);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
210 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
211 iter->plp[n_plp].b = &p->b;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
212 if (resolve_cigar2(iter->plp + n_plp, iter->pos, &p->s)) ++n_plp; // actually always true...
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
213 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
214 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
215 iter->head = iter->dummy->next; // dummy->next may be changed
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
216 *_n_plp = n_plp; *_tid = iter->tid; *_pos = iter->pos;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
217 // update iter->tid and iter->pos
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
218 if (iter->head->next) {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
219 if (iter->tid > iter->head->b.core.tid) {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
220 fprintf(stderr, "[%s] unsorted input. Pileup aborts.\n", __func__);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
221 iter->error = 1;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
222 *_n_plp = -1;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
223 return 0;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
224 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
225 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
226 if (iter->tid < iter->head->b.core.tid) { // come to a new reference sequence
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
227 iter->tid = iter->head->b.core.tid; iter->pos = iter->head->beg; // jump to the next reference
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
228 } else if (iter->pos < iter->head->beg) { // here: tid == head->b.core.tid
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
229 iter->pos = iter->head->beg; // jump to the next position
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
230 } else ++iter->pos; // scan contiguously
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
231 // return
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
232 if (n_plp) return iter->plp;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
233 if (iter->is_eof && iter->head->next == 0) break;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
234 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
235 return 0;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
236 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
237
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
238 int bam_plp_push(bam_plp_t iter, const bam1_t *b)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
239 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
240 if (iter->error) return -1;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
241 if (b) {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
242 if (b->core.tid < 0) return 0;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
243 if (b->core.flag & iter->flag_mask) return 0;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
244 if (iter->tid == b->core.tid && iter->pos == b->core.pos && iter->mp->cnt > iter->maxcnt) return 0;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
245 bam_copy1(&iter->tail->b, b);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
246 iter->tail->beg = b->core.pos; iter->tail->end = bam_calend(&b->core, bam1_cigar(b));
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
247 iter->tail->s = g_cstate_null; iter->tail->s.end = iter->tail->end - 1; // initialize cstate_t
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
248 if (b->core.tid < iter->max_tid) {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
249 fprintf(stderr, "[bam_pileup_core] the input is not sorted (chromosomes out of order)\n");
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
250 iter->error = 1;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
251 return -1;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
252 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
253 if ((b->core.tid == iter->max_tid) && (iter->tail->beg < iter->max_pos)) {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
254 fprintf(stderr, "[bam_pileup_core] the input is not sorted (reads out of order)\n");
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
255 iter->error = 1;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
256 return -1;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
257 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
258 iter->max_tid = b->core.tid; iter->max_pos = iter->tail->beg;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
259 if (iter->tail->end > iter->pos || iter->tail->b.core.tid > iter->tid) {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
260 iter->tail->next = mp_alloc(iter->mp);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
261 iter->tail = iter->tail->next;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
262 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
263 } else iter->is_eof = 1;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
264 return 0;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
265 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
266
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
267 const bam_pileup1_t *bam_plp_auto(bam_plp_t iter, int *_tid, int *_pos, int *_n_plp)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
268 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
269 const bam_pileup1_t *plp;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
270 if (iter->func == 0 || iter->error) { *_n_plp = -1; return 0; }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
271 if ((plp = bam_plp_next(iter, _tid, _pos, _n_plp)) != 0) return plp;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
272 else { // no pileup line can be obtained; read alignments
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
273 *_n_plp = 0;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
274 if (iter->is_eof) return 0;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
275 while (iter->func(iter->data, iter->b) >= 0) {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
276 if (bam_plp_push(iter, iter->b) < 0) {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
277 *_n_plp = -1;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
278 return 0;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
279 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
280 if ((plp = bam_plp_next(iter, _tid, _pos, _n_plp)) != 0) return plp;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
281 // otherwise no pileup line can be returned; read the next alignment.
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
282 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
283 bam_plp_push(iter, 0);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
284 if ((plp = bam_plp_next(iter, _tid, _pos, _n_plp)) != 0) return plp;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
285 return 0;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
286 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
287 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
288
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
289 void bam_plp_reset(bam_plp_t iter)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
290 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
291 lbnode_t *p, *q;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
292 iter->max_tid = iter->max_pos = -1;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
293 iter->tid = iter->pos = 0;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
294 iter->is_eof = 0;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
295 for (p = iter->head; p->next;) {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
296 q = p->next;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
297 mp_free(iter->mp, p);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
298 p = q;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
299 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
300 iter->head = iter->tail;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
301 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
302
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
303 void bam_plp_set_mask(bam_plp_t iter, int mask)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
304 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
305 iter->flag_mask = mask < 0? BAM_DEF_MASK : (BAM_FUNMAP | mask);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
306 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
307
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
308 void bam_plp_set_maxcnt(bam_plp_t iter, int maxcnt)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
309 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
310 iter->maxcnt = maxcnt;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
311 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
312
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
313 /*****************
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
314 * callback APIs *
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
315 *****************/
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
316
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
317 int bam_pileup_file(bamFile fp, int mask, bam_pileup_f func, void *func_data)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
318 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
319 bam_plbuf_t *buf;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
320 int ret;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
321 bam1_t *b;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
322 b = bam_init1();
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
323 buf = bam_plbuf_init(func, func_data);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
324 bam_plbuf_set_mask(buf, mask);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
325 while ((ret = bam_read1(fp, b)) >= 0)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
326 bam_plbuf_push(b, buf);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
327 bam_plbuf_push(0, buf);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
328 bam_plbuf_destroy(buf);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
329 bam_destroy1(b);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
330 return 0;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
331 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
332
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
333 void bam_plbuf_set_mask(bam_plbuf_t *buf, int mask)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
334 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
335 bam_plp_set_mask(buf->iter, mask);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
336 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
337
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
338 void bam_plbuf_reset(bam_plbuf_t *buf)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
339 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
340 bam_plp_reset(buf->iter);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
341 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
342
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
343 bam_plbuf_t *bam_plbuf_init(bam_pileup_f func, void *data)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
344 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
345 bam_plbuf_t *buf;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
346 buf = calloc(1, sizeof(bam_plbuf_t));
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
347 buf->iter = bam_plp_init(0, 0);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
348 buf->func = func;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
349 buf->data = data;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
350 return buf;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
351 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
352
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
353 void bam_plbuf_destroy(bam_plbuf_t *buf)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
354 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
355 bam_plp_destroy(buf->iter);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
356 free(buf);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
357 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
358
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
359 int bam_plbuf_push(const bam1_t *b, bam_plbuf_t *buf)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
360 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
361 int ret, n_plp, tid, pos;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
362 const bam_pileup1_t *plp;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
363 ret = bam_plp_push(buf->iter, b);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
364 if (ret < 0) return ret;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
365 while ((plp = bam_plp_next(buf->iter, &tid, &pos, &n_plp)) != 0)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
366 buf->func(tid, pos, n_plp, plp, buf->data);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
367 return 0;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
368 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
369
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
370 /***********
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
371 * mpileup *
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
372 ***********/
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
373
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
374 struct __bam_mplp_t {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
375 int n;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
376 uint64_t min, *pos;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
377 bam_plp_t *iter;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
378 int *n_plp;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
379 const bam_pileup1_t **plp;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
380 };
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
381
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
382 bam_mplp_t bam_mplp_init(int n, bam_plp_auto_f func, void **data)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
383 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
384 int i;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
385 bam_mplp_t iter;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
386 iter = calloc(1, sizeof(struct __bam_mplp_t));
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
387 iter->pos = calloc(n, 8);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
388 iter->n_plp = calloc(n, sizeof(int));
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
389 iter->plp = calloc(n, sizeof(void*));
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
390 iter->iter = calloc(n, sizeof(void*));
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
391 iter->n = n;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
392 iter->min = (uint64_t)-1;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
393 for (i = 0; i < n; ++i) {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
394 iter->iter[i] = bam_plp_init(func, data[i]);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
395 iter->pos[i] = iter->min;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
396 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
397 return iter;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
398 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
399
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
400 void bam_mplp_set_maxcnt(bam_mplp_t iter, int maxcnt)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
401 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
402 int i;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
403 for (i = 0; i < iter->n; ++i)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
404 iter->iter[i]->maxcnt = maxcnt;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
405 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
406
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
407 void bam_mplp_destroy(bam_mplp_t iter)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
408 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
409 int i;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
410 for (i = 0; i < iter->n; ++i) bam_plp_destroy(iter->iter[i]);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
411 free(iter->iter); free(iter->pos); free(iter->n_plp); free(iter->plp);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
412 free(iter);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
413 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
414
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
415 int bam_mplp_auto(bam_mplp_t iter, int *_tid, int *_pos, int *n_plp, const bam_pileup1_t **plp)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
416 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
417 int i, ret = 0;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
418 uint64_t new_min = (uint64_t)-1;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
419 for (i = 0; i < iter->n; ++i) {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
420 if (iter->pos[i] == iter->min) {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
421 int tid, pos;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
422 iter->plp[i] = bam_plp_auto(iter->iter[i], &tid, &pos, &iter->n_plp[i]);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
423 iter->pos[i] = (uint64_t)tid<<32 | pos;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
424 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
425 if (iter->plp[i] && iter->pos[i] < new_min) new_min = iter->pos[i];
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
426 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
427 iter->min = new_min;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
428 if (new_min == (uint64_t)-1) return 0;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
429 *_tid = new_min>>32; *_pos = (uint32_t)new_min;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
430 for (i = 0; i < iter->n; ++i) {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
431 if (iter->pos[i] == iter->min) { // FIXME: valgrind reports "uninitialised value(s) at this line"
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
432 n_plp[i] = iter->n_plp[i], plp[i] = iter->plp[i];
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
433 ++ret;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
434 } else n_plp[i] = 0, plp[i] = 0;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
435 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
436 return ret;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
437 }