@@ -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+
287300int 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
315339void 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 " );
0 commit comments