Skip to content

Commit 5229dcc

Browse files
author
Your Name
committed
Made the mismatch computatation general so there is no assumption of readlength
1 parent c5a7057 commit 5229dcc

2 files changed

Lines changed: 47 additions & 21 deletions

File tree

profile.cpp

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -284,32 +284,56 @@ inline void increaseCounters(const bam1_t *b, const char *reconstructedReference
284284
}
285285
}
286286

287+
//this function will not get a commen
288+
void mysuperduper_function(triple &t, size_t old_m, size_t new_m) {
289+
assert(t.rlens!=NULL&&old_m<new_m);
290+
assert(t.rlens_m == old_m);//just so ser ser double sure
291+
size_t *tmp = new size_t[new_m];
292+
memset(tmp, 0, new_m * sizeof(size_t));
293+
memcpy(tmp, t.rlens, t.rlens_m * sizeof(size_t));
294+
delete [] t.rlens;
295+
296+
t.rlens = tmp;
297+
t.rlens_m = new_m;
298+
}
299+
287300
int damage::damage_analysis(bam1_t *b, int which, float incval) {
301+
size_t rlen = (size_t)b->core.l_qseq;
288302
// fprintf(stderr,"\t-> incval: %f\n",incval);
303+
//ok we need to do something
304+
if (rlen + 10 >= temp_len) {//so lets be sure,
305+
temp_len = b->core.l_qseq+10;//and then be really sure
306+
kroundup32(temp_len);
307+
free(reconstructedTemp);
308+
reconstructedTemp = (char *)calloc(temp_len, 1);
309+
310+
}
311+
memset(reconstructedTemp, 0, temp_len);//maybe bottleneck, should not be needed.
312+
289313
if (assoc.find(which) == assoc.end()) {
290-
triple val = {0, getmatrix(MAXLENGTH, 16), getmatrix(MAXLENGTH, 16),new size_t[500]};
291-
for(int i=0;i<500;i++)
292-
val.rlens[i] = 0;
314+
triple val = {0, getmatrix(MAXLENGTH, 16), getmatrix(MAXLENGTH, 16),new size_t[temp_len],temp_len};
315+
memset(val.rlens, 0, temp_len * sizeof(size_t));
293316
assoc[which] = val;
294317
mm5pF = val.mm5pF;
295318
mm3pF = val.mm3pF;
296319
// fprintf(stderr,"has added which: %d\n",which);
297320
}
298-
std::map<int, triple>::iterator it = assoc.find(which);
299-
it->second.nreads++;
300-
// fprintf(stderr,"[%s] it->first:%d it->second.nreads:%d\n",__FUNCTION__,it->first,it->second.nreads);
301-
assert(b->core.l_qseq<500);
302-
it->second.rlens[b->core.l_qseq] = it->second.rlens[b->core.l_qseq] + 1;
303-
if (b->core.l_qseq - 10 > temp_len) {
304-
temp_len = b->core.l_qseq;
305-
kroundup32(temp_len);
306-
free(reconstructedTemp);
307-
reconstructedTemp = (char *)calloc(temp_len, 1);
308-
}
309-
memset(reconstructedTemp, 0, temp_len);
310-
reconstructRefWithPosHTS(b, reconstructedReference, reconstructedTemp);
311-
increaseCounters(b, reconstructedReference.first->s, reconstructedReference.second, minQualBase, MAXLENGTH, it->second.mm5pF, it->second.mm3pF, incval);
312-
return 0;
321+
322+
323+
std::map<int, triple>::iterator it = assoc.find(which);
324+
//so lets make sure that
325+
if (rlen +10 >= it->second.rlens_m) {
326+
size_t new_m = rlen + 10;
327+
kroundup32(new_m);
328+
mysuperduper_function(it->second, it->second.rlens_m, new_m);
329+
}
330+
331+
it->second.nreads++;
332+
it->second.rlens[rlen]++;
333+
fprintf(stderr,"er vi her fprintf%lu rlen: %lu\n",it->second.nreads,rlen);
334+
reconstructRefWithPosHTS(b, reconstructedReference, reconstructedTemp);
335+
increaseCounters(b, reconstructedReference.first->s, reconstructedReference.second, minQualBase, MAXLENGTH, it->second.mm5pF, it->second.mm3pF, incval);
336+
return 0;
313337
}
314338

315339
void damage::write(char *fname, bam_hdr_t *hdr) {
@@ -382,7 +406,7 @@ void damage::bwrite(char *fname) {
382406
if (it->second.nreads == 0) // should never happen
383407
continue;
384408
ksprintf(&kstr3000,"%d",it->first);
385-
for(int i=0;i<500;i++)
409+
for(int i=0;i<it->second.rlens_m;i++)
386410
if(it->second.rlens[i]>0)
387411
ksprintf(&kstr3000,"\t%d:%lu",it->second.rlens[i]);
388412
ksprintf(&kstr3000,"\n");

profile.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ typedef struct {
2121
size_t nreads;
2222
float **mm5pF;
2323
float **mm3pF;
24-
size_t *rlens;
24+
size_t *rlens; //this is the counts. Not hashmap to speed up things
25+
int rlens_m; // the length of the above. surprise
2526
} triple;
2627

2728
class damage {
@@ -40,7 +41,8 @@ class damage {
4041
void bwrite(char *prefix);
4142
int damage_analysis(bam1_t *b, int whichclass, float incval);
4243
void printit(FILE *fp, int l);
43-
int temp_len;
44+
int temp_len;//<- this is the maxlenght of the reconstructed reference etc. This might be updated to a higher value.
45+
//also when we initialize a new rlens for a ref/taxid that will be used.
4446
damage(int maxlen, int nthd, int minqb) {
4547
temp_len = 512;
4648
MAXLENGTH = maxlen;

0 commit comments

Comments
 (0)