diff --git a/kmer/libsim4/sim4core/exon.H b/kmer/libsim4/sim4core/exon.H index 35778e02e..0ec5e9568 100644 --- a/kmer/libsim4/sim4core/exon.H +++ b/kmer/libsim4/sim4core/exon.H @@ -6,12 +6,62 @@ // Define this only if Liliana is watching you. //#define SPLSCORE - class Exon { -public: - Exon(int f1, int f2, int t1, int t2, int len, int edist, int flag, Exon *next); - ~Exon(); +private: + Exon() { + next_exon = 0L; + frGEN = 0; + frEST = 0; + toGEN = 0; + toEST = 0; + ori = 'U'; + length = 0; + + edist = 0; + flag = 0; + + percentID = 0; + alignmentLength = 0; + numMatches = 0; + numNs = 0; + numInDel = 0; + numEdits = 0; + +#ifdef SPLSCORE + splScore = -999999; +#endif + }; + ~Exon() {}; + + void init(int f1, int f2, int t1, int t2, int len, int edist, int flag, Exon *next) { + next_exon = next; + + frGEN = f1; + frEST = f2; + toGEN = t1; + toEST = t2; + + ori = 'U'; + length = (len < 0) ? (t2-f2+1) : len; + + edist = edost; + flag = flog; + + percentID = 0; + alignmentLength = 0; + numMatches = 0; + numNs = 0; + numInDel = 0; + numEdits = 0; + +#ifdef SPLSCORE + splScore = -999999; +#endif + }; + friend class exonManager; + +public: void printList(char *label) { Exon *l = this; @@ -56,59 +106,68 @@ public: #endif }; -inline -Exon::Exon(int f1, int f2, int t1, int t2, int len, int edost, int flog, Exon *next) { - next_exon = next; - - frGEN = f1; - frEST = f2; - toGEN = t1; - toEST = t2; - - ori = 'U'; - length = (len < 0) ? (t2-f2+1) : len; - edist = edost; - flag = flog; - percentID = 0; - alignmentLength = 0; - numMatches = 0; - numNs = 0; - numInDel = 0; - numEdits = 0; - -#ifdef SPLSCORE - splScore = -999999; -#endif -} -inline -Exon::~Exon() { -} -inline -void -freeExon(Exon *&l) { - delete l; - l = 0L; -} +// Just for allocating exons. It takes care of deleting exons. You +// are not allowed to delete them. +// +class exonManager { + +public: + exonManager() { + _listLen = 1; + _listMax = 8; + _list = new Exon* [_listMax]; + + _curLen = 0; + _curMax = 256; + _list[0] = new Exon [_curMax]; + }; + ~exonManager() { + for (u32bit i=0; i<_listLen; i++) + delete [] _list[i]; + delete [] _list; + }; -inline -void -freeExonList(Exon *&l) { - Exon *t; + Exon *newExon(int f1, int f2, int t1, int t2, int len, int edist, int flag, Exon *next) { + + // If the current list is full, move to the next one, or allocate + // more space. + // + if (_curLen >= _curMax) { + if (_listLen >= _listMax) { + _listMax *= 2; + Exon **l = new Exon* [_listMax]; + memcpy(l, _list, sizeof(Exon**) * _listLen); + delete [] _list; + _list = l; + } + + _list[_listLen++] = new Exon [_curMax]; + _curLen = 0; + } - while (l) { - t = l->next_exon; - freeExon(l); - l = t; - } + Exon *e = _list[_listLen - 1] + _curLen; + _curLen++; + e->init(f1, f2, t1, t2, len, edist, flag, next); + return(e);; + }; - l = 0L; -} +private: + // Exon pointers are valid throughout the lifetime of execution, + // so we can't use realloc here. Instead, we keep a list of arrays + // of exons. + // + u32bit _listLen; + u32bit _listMax; + Exon **_list; + u32bit _curLen; + u32bit _curMax; +}; #endif // EXON_H diff --git a/kmer/libsim4/sim4core/greedy.C b/kmer/libsim4/sim4core/greedy.C index df6793ebc..b256f83f0 100644 --- a/kmer/libsim4/sim4core/greedy.C +++ b/kmer/libsim4/sim4core/greedy.C @@ -25,8 +25,8 @@ Sim4::greedy(char *s1, char *s2, int m, int n0, int OFFSET1, int OFFSET2, Exon * if (n0 < m) { if (m < (int)min(wordSize, (1 + globalParams->_percentError) * n0)) { - *lblock = *rblock = new Exon(OFFSET2+1,OFFSET1+1,OFFSET2+n0,OFFSET1+m, - m,n0-m+(int)(globalParams->_percentError * m + 1),0,NULL); + *lblock = *rblock = _exonManager.newExon(OFFSET2+1,OFFSET1+1,OFFSET2+n0,OFFSET1+m, + m,n0-m+(int)(globalParams->_percentError * m + 1),0,NULL); ANNOUNCEEXIT("greedy-1\n"); return(m-n0+(int)(globalParams->_percentError * n0 + 1)); } else if (m > (int)min(wordSize, (1 + globalParams->_percentError) * n0)) { @@ -59,8 +59,8 @@ Sim4::greedy(char *s1, char *s2, int m, int n0, int OFFSET1, int OFFSET2, Exon * if (row == 0) { /* hit last row; stop search */ - *lblock = *rblock = new Exon(r_offset2-m+n2+1,r_offset1+1,r_offset2+n2, - r_offset1+m,m,0,0,NULL); + *lblock = *rblock = _exonManager.newExon(r_offset2-m+n2+1,r_offset1+1,r_offset2+n2, + r_offset1+m,m,0,0,NULL); ANNOUNCEEXIT("greedy-3\n"); return 0; } @@ -98,8 +98,8 @@ Sim4::greedy(char *s1, char *s2, int m, int n0, int OFFSET1, int OFFSET2, Exon * if (row == m) { /* hit last row; stop search */ - *lblock = *rblock = new Exon(l_offset2+1,l_offset1+1,l_offset2+m, - l_offset1+m,m,0,0,NULL); + *lblock = *rblock = _exonManager.newExon(l_offset2+1,l_offset1+1,l_offset2+m, + l_offset1+m,m,0,0,NULL); ckfree(allocdSpace); ANNOUNCEEXIT("greedy-4\n"); @@ -289,35 +289,35 @@ Sim4::greedy(char *s1, char *s2, int m, int n0, int OFFSET1, int OFFSET2, Exon * if (m-min_row[back]>=max_row[forth]) { - if ((r_offset2+1+min_diag[back]-R_ORIGIN) < - (l_offset2+max_diag[forth]-L_ORIGIN)) { - *rblock = *lblock = new Exon(l_offset2+1,l_offset1+1, - l_offset2+n0,l_offset1+m, - m,back+forth,0,NULL); - } else { - *rblock = new Exon(r_offset2+1+min_row[back]+min_diag[back]-R_ORIGIN, - r_offset1+1+min_row[back], - r_offset2+n2,r_offset1+m, - m-min_row[back],back,0,NULL); - *lblock = new Exon(l_offset2+1,l_offset1+1, - l_offset2+min_row[back]+max_diag[forth]-L_ORIGIN, - l_offset1+min_row[back], - min_row[back],forth,0,*rblock); - } + if ((r_offset2+1+min_diag[back]-R_ORIGIN) < + (l_offset2+max_diag[forth]-L_ORIGIN)) { + *rblock = *lblock = _exonManager.newExon(l_offset2+1,l_offset1+1, + l_offset2+n0,l_offset1+m, + m,back+forth,0,NULL); + } else { + *rblock = _exonManager.newExon(r_offset2+1+min_row[back]+min_diag[back]-R_ORIGIN, + r_offset1+1+min_row[back], + r_offset2+n2,r_offset1+m, + m-min_row[back],back,0,NULL); + *lblock = _exonManager.newExon(l_offset2+1,l_offset1+1, + l_offset2+min_row[back]+max_diag[forth]-L_ORIGIN, + l_offset1+min_row[back], + min_row[back],forth,0,*rblock); + } } else { - if ((r_offset2+1+min_diag[back]-R_ORIGIN) < - (l_offset2+max_diag[forth]-L_ORIGIN)) { - *rblock = *lblock = new Exon(l_offset2+1,l_offset1+1, - l_offset2+n0,l_offset1+m, - m,back+forth,0,NULL); - } else { - *rblock = new Exon(r_offset2+1+max_row[forth]+min_diag[back]-R_ORIGIN, - r_offset1+1+max_row[forth], - r_offset2+n2,r_offset1+m,m-max_row[forth],back,0,NULL); - *lblock = new Exon(l_offset2+1,l_offset1+1, - l_offset2+max_row[forth]+max_diag[forth]-L_ORIGIN, - l_offset1+max_row[forth],max_row[forth],forth,0,*rblock); - } + if ((r_offset2+1+min_diag[back]-R_ORIGIN) < + (l_offset2+max_diag[forth]-L_ORIGIN)) { + *rblock = *lblock = _exonManager.newExon(l_offset2+1,l_offset1+1, + l_offset2+n0,l_offset1+m, + m,back+forth,0,NULL); + } else { + *rblock = _exonManager.newExon(r_offset2+1+max_row[forth]+min_diag[back]-R_ORIGIN, + r_offset1+1+max_row[forth], + r_offset2+n2,r_offset1+m,m-max_row[forth],back,0,NULL); + *lblock = _exonManager.newExon(l_offset2+1,l_offset1+1, + l_offset2+max_row[forth]+max_diag[forth]-L_ORIGIN, + l_offset1+max_row[forth],max_row[forth],forth,0,*rblock); + } } ckfree(allocdSpace); diff --git a/kmer/libsim4/sim4core/mspManager.C b/kmer/libsim4/sim4core/mspManager.C index 337fd7d0f..b5867df76 100644 --- a/kmer/libsim4/sim4core/mspManager.C +++ b/kmer/libsim4/sim4core/mspManager.C @@ -13,6 +13,9 @@ mspManager::mspManager() { _sorted = true; + _ESTlen = 0; + _GENlen = 0; + _allocMSPs = 16384; _numMSPs = 0; _allMSPs = new msp [_allocMSPs]; @@ -24,8 +27,8 @@ mspManager::mspManager() { // _tooManyMSPs = false; _cDNALength = 0; + _mspLimitPercent = 0.0; _mspLimitAbsolute = 0; - _mspLimitPercent = 0; // These need to be reset with setParameters. The code will die // during link() if they are not set. @@ -33,6 +36,11 @@ mspManager::mspManager() { _match = 0; _matchdiff = 0; _percentError = 0.0; + _wordExtAllow = 0; + + _exonManager = 0L; + + _minMSPScore = 0; _diagMax = 0; _diagExt = 0L; @@ -190,31 +198,22 @@ mspManager::doLinking(int weight, } } + if (best < 0) + return(0L); - - - - // In the code below, last_msp = best. - // int last_msp = best; - int diag_dist; - int diff; - - Exon *elist = 0L; - - if (last_msp < 0) - return(elist); - - msp *mp = _allMSPs + last_msp; - - elist = new Exon(mp->pos1, - mp->pos2, - mp->pos1+mp->len-1, - mp->pos2+mp->len-1, - -1, - (mp->len * _match - mp->score) / _matchdiff, - 0, - elist); + int diag_dist; + int diff; + + msp *mp = _allMSPs + last_msp; + Exon *elist = _exonManager->newExon(mp->pos1, + mp->pos2, + mp->pos1+mp->len-1, + mp->pos2+mp->len-1, + -1, + (mp->len * _match - mp->score) / _matchdiff, + 0, + 0L); last_msp = mp->prev; @@ -223,7 +222,7 @@ mspManager::doLinking(int weight, int l1 = elist->frEST - elist->frGEN; int l2 = mp->pos2 - mp->pos1; - + if (l1 > l2) diag_dist = l1 - l2; else @@ -249,14 +248,14 @@ mspManager::doLinking(int weight, elist->frGEN = min(elist->frGEN,mp->pos1); elist->frEST = min(elist->frEST,mp->pos2); } else { - elist = new Exon(mp->pos1, - mp->pos2, - mp->pos1+mp->len-1, - mp->pos2+mp->len-1, - -1, - (mp->len * _match - mp->score) / _matchdiff, - 0, - elist); + elist = _exonManager->newExon(mp->pos1, + mp->pos2, + mp->pos1+mp->len-1, + mp->pos2+mp->len-1, + -1, + (mp->len * _match - mp->score) / _matchdiff, + 0, + elist); } last_msp = mp->prev; diff --git a/kmer/libsim4/sim4core/mspManager.H b/kmer/libsim4/sim4core/mspManager.H index e4045894e..18363b78d 100644 --- a/kmer/libsim4/sim4core/mspManager.H +++ b/kmer/libsim4/sim4core/mspManager.H @@ -37,6 +37,10 @@ public: _wordExtAllow = wordextallow; }; + void setExonSource(exonManager *em) { + _exonManager = em; + }; + void setLimits(u32bit a, double p) { _mspLimitAbsolute = a; _mspLimitPercent = p; @@ -146,6 +150,8 @@ private: double _percentError; int _wordExtAllow; + exonManager *_exonManager; + int _minMSPScore; int _diagMax; diff --git a/kmer/libsim4/sim4core/pluri_align.C b/kmer/libsim4/sim4core/pluri_align.C index 0b7e0aac6..19f5154da 100644 --- a/kmer/libsim4/sim4core/pluri_align.C +++ b/kmer/libsim4/sim4core/pluri_align.C @@ -68,12 +68,12 @@ Sim4::pluri_align(int *dist_ptr, enew = (edit_script_list *)ckalloc(sizeof(edit_script_list)); enew->next_script = *Aligns; *Aligns = enew; - (*Aligns)->script = head; + (*Aligns)->script = head; (*Aligns)->offset1 = thisExon->frGEN; (*Aligns)->offset2 = thisExon->frEST; - (*Aligns)->len1 = end1-(*Aligns)->offset1+1; - (*Aligns)->len2 = end2-(*Aligns)->offset2+1; - (*Aligns)->score = ali_dist; + (*Aligns)->len1 = end1-(*Aligns)->offset1+1; + (*Aligns)->len2 = end2-(*Aligns)->offset2+1; + (*Aligns)->score = ali_dist; ali_dist = 0; head = NULL; } diff --git a/kmer/libsim4/sim4core/poly.C b/kmer/libsim4/sim4core/poly.C index 69bf2f699..d54145f15 100644 --- a/kmer/libsim4/sim4core/poly.C +++ b/kmer/libsim4/sim4core/poly.C @@ -115,7 +115,7 @@ Sim4::trim_polyA_align(struct edit_script_list **Sptr, Exon *lblock, Exon **exon } prev->next_exon = (*exons)->next_exon; - freeExon(*exons); + //freeExon(*exons); garbage collected *exons = prev; } *pA = bc; @@ -253,7 +253,7 @@ Sim4::trim_polyA_align(struct edit_script_list **Sptr, Exon *lblock, Exon **exon } prev->next_exon = (*exons)->next_exon; - freeExon(*exons); + //freeExon(*exons); garbage collected *exons = prev; } else { (*exons)->toEST = i; @@ -367,7 +367,7 @@ Sim4::trim_polyT_align(struct edit_script_list **Sptr, Exon **exons, const int e while ((*exons)->frESTnext_exon; - freeExon(t); + //freeExon(t); garbage collected } *pT = ec; return; @@ -491,7 +491,7 @@ Sim4::trim_polyT_align(struct edit_script_list **Sptr, Exon **exons, const int e if ((*exons)->toESTnext_exon; - freeExon(t); + //freeExon(t); garbage collected } else { (*exons)->frEST = i; (*exons)->frGEN = j; diff --git a/kmer/libsim4/sim4core/sim4.H b/kmer/libsim4/sim4core/sim4.H index d770686f9..a2d6b0c4e 100644 --- a/kmer/libsim4/sim4core/sim4.H +++ b/kmer/libsim4/sim4core/sim4.H @@ -131,6 +131,8 @@ struct hash_table { private: mspManager _mspManager; + exonManager _exonManager; + sim4parameters *globalParams; char *_genSeq; @@ -443,11 +445,13 @@ private: void *_pallochandle; void *ckalloc(size_t amount) { - //void *x = palloc2(amount, _pallochandle); - //memset(x, 0xff, amount); - //return(x); return(palloc2(amount, _pallochandle)); }; + void *ckcalloc(size_t amount) { + void *x = palloc2(amount, _pallochandle); + memset(x, 0x00, amount); + return(x); + }; void ckfree(void *) { }; @@ -506,6 +510,8 @@ public: globalParams->_mismatch, globalParams->_percentError, wordExtensionAllowance); + _mspManager.setExonSource(&_exonManager); + // wordSize -- for finding initial seeds // wordSizeInt -- for extending seeds between seeds @@ -557,6 +563,7 @@ public: #ifdef WITH_PALLOC pfree2(_pallochandle); + pfreehandle(_pallochandle); #endif }; diff --git a/kmer/libsim4/sim4core/sim4b1-1.C b/kmer/libsim4/sim4core/sim4b1-1.C index f43f0757d..54cd94994 100644 --- a/kmer/libsim4/sim4core/sim4b1-1.C +++ b/kmer/libsim4/sim4core/sim4b1-1.C @@ -78,7 +78,7 @@ Sim4::SIM4_block1(Exon* &Lblock, tmp_block->next_exon = tmp_block1->next_exon; tmp_block->flag = tmp_block1->flag; rollbflag = 1; - freeExon(tmp_block1); + //freeExon(tmp_block1); garbage collected tmp_block1 = NULL; } @@ -105,7 +105,7 @@ Sim4::SIM4_block1(Exon* &Lblock, prev->flag = tmp_block->flag; if ((tmp_block->toEST - tmp_block->frEST + 1) > 0) rollbflag = 1; - freeExon(tmp_block); + //freeExon(tmp_block); garbage collected tmp_block = prev; } diff --git a/kmer/libsim4/sim4core/sim4b1-2.C b/kmer/libsim4/sim4core/sim4b1-2.C index a59e3cb7a..b407da241 100644 --- a/kmer/libsim4/sim4core/sim4b1-2.C +++ b/kmer/libsim4/sim4core/sim4b1-2.C @@ -50,7 +50,7 @@ Sim4::SIM4_block2(Exon* &tmp_Lblock, (tmp_Lblock && (tmp_block1->frEST-tmp_Rblock->toEST>100) && (tmp_block1->frGEN-tmp_Rblock->frGEN>50000))) { /* possible large intron; increase the score weight */ - freeExonList(tmp_Lblock); + //freeExonList(tmp_Lblock); garbage collected exon_list = _mspManager.doLinking(globalParams->_relinkWeight, DEFAULT_DRANGE, diff --git a/kmer/libsim4/sim4core/sim4b1-3.C b/kmer/libsim4/sim4core/sim4b1-3.C index cd99910e8..de95a73c3 100644 --- a/kmer/libsim4/sim4core/sim4b1-3.C +++ b/kmer/libsim4/sim4core/sim4b1-3.C @@ -85,7 +85,7 @@ Sim4::SIM4_block3(bool good_match, (tmp_Lblock && (tmp_block1->frEST-tmp_Rblock->toEST>100) && (tmp_block1->frGEN-tmp_Rblock->frGEN>50000))) { /* possible large intron; increase the score weight */ - freeExonList(tmp_Lblock); + //freeExonList(tmp_Lblock); garbage collected exon_list = _mspManager.doLinking(globalParams->_relinkWeight, DEFAULT_DRANGE, diff --git a/kmer/libsim4/sim4core/sim4b1-4.C b/kmer/libsim4/sim4core/sim4b1-4.C index c6906837a..7738be8c0 100644 --- a/kmer/libsim4/sim4core/sim4b1-4.C +++ b/kmer/libsim4/sim4core/sim4b1-4.C @@ -84,7 +84,7 @@ Sim4::SIM4_block4(bool good_match, (tmp_Lblock && (tmp_block1->frEST-tmp_Rblock->toEST>100) && (tmp_block1->frGEN-tmp_Rblock->frGEN>50000))) { /* possible large intron; increase the score weight */ - freeExonList(tmp_Lblock); + //freeExonList(tmp_Lblock); garbage collected exon_list = _mspManager.doLinking(globalParams->_relinkWeight, DEFAULT_DRANGE, diff --git a/kmer/libsim4/sim4core/sim4b1.C b/kmer/libsim4/sim4core/sim4b1.C index 323db9262..43fa476bb 100644 --- a/kmer/libsim4/sim4core/sim4b1.C +++ b/kmer/libsim4/sim4core/sim4b1.C @@ -51,7 +51,7 @@ Sim4::SIM4(int *dist_ptr, if (Lblock && ((Lblock->frGEN>50000 && Lblock->frEST>100) || ((_genLen - Rblock->toGEN > 50000) && (_estLen - Rblock->toEST > 100)))) { - freeExonList(exon_list); + //freeExonList(exon_list); garbage collected exon_list = _mspManager.doLinking(globalParams->_relinkWeight, DEFAULT_DRANGE, @@ -86,13 +86,13 @@ Sim4::SIM4(int *dist_ptr, #ifdef SHOW_PROGRESS fprintf(stderr, "exon bracket at start\n"); #endif - Lblock = new Exon(0,0,0,0,0,0,0,Lblock); + Lblock = _exonManager.newExon(0,0,0,0,0,0,0,Lblock); if (Rblock == NULL) Rblock = Lblock; #ifdef SHOW_PROGRESS fprintf(stderr, "exon bracket at end; Lblock = 0x%08lx, Rblock = 0x%08lx\n", Lblock, Rblock); #endif - Rblock->next_exon = new Exon(_genLen+1,_estLen+1,0,0,0,0,0,NULL); + Rblock->next_exon = _exonManager.newExon(_genLen+1,_estLen+1,0,0,0,0,0,NULL); PRINTEXONS("initial exon set after inserting brackets\n", Lblock); @@ -238,7 +238,7 @@ Sim4::SIM4(int *dist_ptr, while ((tmp_block!=NULL) && (tmp_block->lengthtoGEN) { tmp_block1 = tmp_block; tmp_block = tmp_block->next_exon; - freeExon(tmp_block1); + //freeExon(tmp_block1); garbage collected } Lblock->next_exon = tmp_block; @@ -297,11 +297,11 @@ Sim4::SIM4(int *dist_ptr, get_stats(Lblock, st); *Exons = Lblock->next_exon; - freeExon(Lblock); + //freeExon(Lblock); garbage collected } else { *Exons = 0L; - freeExonList(Lblock); + //freeExonList(Lblock); garbage collected } // Memory leak when Script_head == 0L -- see pluri_align, too! diff --git a/kmer/libsim4/sim4core/sim4string.C b/kmer/libsim4/sim4core/sim4string.C index db8d7b1af..c77e93337 100644 --- a/kmer/libsim4/sim4core/sim4string.C +++ b/kmer/libsim4/sim4core/sim4string.C @@ -537,11 +537,11 @@ Sim4::run(sim4command *cmd) { fail: - if (fAligns) free_align(fAligns); - if (rAligns) free_align(rAligns); - - freeExonList(fExons); - freeExonList(rExons); + // These are now garbage collected + //if (fAligns) free_align(fAligns); + //if (rAligns) free_align(rAligns); + //freeExonList(fExons); + //freeExonList(rExons); fAligns = rAligns = 0L; fExons = rExons = 0L; diff --git a/kmer/libsim4/sim4core/util.C b/kmer/libsim4/sim4core/util.C index 69181047e..7c3a812e0 100644 --- a/kmer/libsim4/sim4core/util.C +++ b/kmer/libsim4/sim4core/util.C @@ -29,12 +29,12 @@ Sim4::complement_exons(Exon **left, int M, int N) #endif switch (ch) { - case 'C': prev = 'G'; break; - case 'G': prev = 'C'; break; - case 'N': prev = 'N'; break; - case 'E': prev = 'E'; break; - default : fatal("sim4b1.c: Inconsistency. Check exon orientation at complementation."); - } + case 'C': prev = 'G'; break; + case 'G': prev = 'C'; break; + case 'N': prev = 'N'; break; + case 'E': prev = 'E'; break; + default : fatal("sim4b1.c: Inconsistency. Check exon orientation at complementation."); + } } else { tmp_block->ori = prev; #ifdef SPLSCORE @@ -72,12 +72,12 @@ Sim4::check_consistency_intron_ori(Exon *exons, int match_ori, char *gene) while (t && t->toGEN) { if (t->next_exon && t->next_exon->toGEN) { switch (t->ori) { - case 'G': numG++; break; - case 'C': numC++; break; - case 'N': numN++; break; - case 'E': numE++; break; - default : fatal("sim4b1.c: Unrecognized intron orientation."); - } + case 'G': numG++; break; + case 'C': numC++; break; + case 'N': numN++; break; + case 'E': numE++; break; + default : fatal("sim4b1.c: Unrecognized intron orientation."); + } } t = t->next_exon; } @@ -184,7 +184,7 @@ Sim4::compact_list(Exon **Lblock, Exon **Rblock) tmp_block->edist -= (int)(globalParams->_percentError * diff); tmp_block->next_exon = tmp_block1->next_exon; - freeExon(tmp_block1); + //freeExon(tmp_block1); garbage collected } else tmp_block = tmp_block1; } @@ -240,7 +240,7 @@ Sim4::merge(Exon **t0, Exon **t1) } tmp0->next_exon = tmp1->next_exon; - freeExon(tmp1); + //freeExon(tmp1); garbage collected } else { tmp0 = tmp0->next_exon; } @@ -281,8 +281,8 @@ Sim4::bmatch (char *s1, char *s2, int l1, int l2, int offset1, int offset2) if (*(s1+i1+l2-1)==*(s2+j+l2-1)) score++; if (*(s1+i1+l2)==*(s2+j+l2)) score++; if (score>=3) { - newthing = new Exon(i1+3+offset1, offset2, i1+3+offset1+l2-5, - offset2+l2-5, l2-4, 0, 0, NULL); + newthing = _exonManager.newExon(i1+3+offset1, offset2, i1+3+offset1+l2-5, + offset2+l2-5, l2-4, 0, 0, NULL); newthing->ori = (G_score >= abs(C_score)) ? 'G' : 'C'; return newthing; @@ -311,8 +311,8 @@ Sim4::fmatch (char *s1, char *s2, int l1, int l2, int offset1, int offset2) if (*(s1+i1-l2)==*s2) score++; if (*(s1+i1-l2+1)==*(s2+1)) score++; if (score>=3) { - newthing = new Exon(i+offset1,offset2,i1+offset1-2,offset2+l2-5, - l2-4,0,0,NULL); + newthing = _exonManager.newExon(i+offset1,offset2,i1+offset1-2,offset2+l2-5, + l2-4,0,0,NULL); newthing->ori = (G_score >= abs(C_score)) ? 'G' : 'C'; return newthing; @@ -348,34 +348,30 @@ Sim4::get_sync_flag(Exon *lblock, Exon *rblock, int w) void -Sim4::sync_slide_intron(int in_w, Exon **lblock, sim4_stats_t *st) -{ +Sim4::sync_slide_intron(int in_w, Exon **lblock, sim4_stats_t *st) { Exon *t0, *t1, *head = *lblock; splice_t *g, *c, *cell; - splice_t **Glist, **Clist; - int Gscore=0, Cscore=0; - char *oris; - int w1, w2, ni, i, numC, numG; - - ni = 0; - numG = numC = 0; + int w1, w2, i; // Count the exons to allocate space for Glist, Clist and oris // + int ni = 1; t0 = head->next_exon; while (t0 && (t1=t0->next_exon) && t1->toGEN) { ni++; t0 = t1; } - Glist = (splice_t **)calloc(ni + 1, sizeof(splice_t *)); - Clist = (splice_t **)calloc(ni + 1, sizeof(splice_t *)); - oris = (char *)calloc(ni + 1, sizeof(char)); + // These leak, but I don't know where. + splice_t **Glist = (splice_t **)ckcalloc(ni * sizeof(splice_t *)); + splice_t **Clist = (splice_t **)ckcalloc(ni * sizeof(splice_t *)); + char *oris = (char *)ckcalloc(ni * sizeof(char)); - if ((Glist == 0L) || (Clist == 0L) || (oris == 0L)) { - fprintf(stderr, "Can't allocate memory for sync_slide_intron() with %d exons.\n", ni); - exit(1); - } + if ((Glist == 0L) || (Clist == 0L) || (oris == 0L)) + fprintf(stderr, "Can't allocate memory for sync_slide_intron() with %d exons.\n", ni), exit(1); + + int numG = 0, Gscore = 0; + int numC = 0, Cscore = 0; ni = 0; @@ -444,30 +440,33 @@ Sim4::sync_slide_intron(int in_w, Exon **lblock, sim4_stats_t *st) for (i=0, t0=head->next_exon; inext_exon; switch (oris[i]) { - case 'G': break; - case 'C': if (Glist[i]==NULL) { - /* compute the values for C */ - w1 = min(in_w, min(t0->length-1, t0->toGEN-t0->frGEN)); - w2 = min(in_w, min(t1->length-1, t1->toGEN-t1->frGEN)); - splice(_genSeq, t0->toGEN-w1, t0->toGEN+w1, - t1->frGEN-w2, t1->frGEN+w2, _estSeq, - t0->toEST-w1, t1->frEST+w2, &g, &c, FWD); - } else g = Glist[i]; - + case 'G': + break; + case 'C': if (Glist[i]==NULL) { + /* compute the values for C */ + w1 = min(in_w, min(t0->length-1, t0->toGEN-t0->frGEN)); + w2 = min(in_w, min(t1->length-1, t1->toGEN-t1->frGEN)); + splice(_genSeq, t0->toGEN-w1, t0->toGEN+w1, + t1->frGEN-w2, t1->frGEN+w2, _estSeq, + t0->toEST-w1, t1->frEST+w2, &g, &c, FWD); + } else { + g = Glist[i]; + } + #ifdef SPLSCORE - t0->splScore = g->score; + t0->splScore = g->score; #endif - t0->ori = 'G'; - t0->toGEN = g->xs; t0->toEST = g->ys; - t1->frGEN = g->xe; t1->frEST = g->ye; - t0->length = t0->toEST-t0->frEST+1; - t1->length = t1->toEST-t1->frEST+1; + t0->ori = 'G'; + t0->toGEN = g->xs; t0->toEST = g->ys; + t1->frGEN = g->xe; t1->frEST = g->ye; + t0->length = t0->toEST-t0->frEST+1; + t1->length = t1->toEST-t1->frEST+1; - break; - case 'E': break; - default : fatal("sim4b1.c: intron orientation not initialized."); - } + break; + case 'E': break; + default : fatal("sim4b1.c: intron orientation not initialized."); + } if (oris[i]!='E') wobble(&t0,&t1,"GT","AG",_genSeq); } @@ -477,28 +476,28 @@ Sim4::sync_slide_intron(int in_w, Exon **lblock, sim4_stats_t *st) for (i=0, t0=head->next_exon; inext_exon; switch (oris[i]) { - case 'C': break; - case 'G': if (Clist[i]==NULL) { - /* compute the values for C */ - w1 = min(in_w, min(t0->length-1, t0->toGEN-t0->frGEN)); - w2 = min(in_w, min(t1->length-1, t1->toGEN-t1->frGEN)); - splice(_genSeq, t0->toGEN-w1, t0->toGEN+w1, - t1->frGEN-w2, t1->frGEN+w2, - _estSeq, t0->toEST-w1, t1->frEST+w2, &g, &c, BWD); - } else c = Clist[i]; + case 'C': break; + case 'G': if (Clist[i]==NULL) { + /* compute the values for C */ + w1 = min(in_w, min(t0->length-1, t0->toGEN-t0->frGEN)); + w2 = min(in_w, min(t1->length-1, t1->toGEN-t1->frGEN)); + splice(_genSeq, t0->toGEN-w1, t0->toGEN+w1, + t1->frGEN-w2, t1->frGEN+w2, + _estSeq, t0->toEST-w1, t1->frEST+w2, &g, &c, BWD); + } else c = Clist[i]; #ifdef SPLSCORE - t0->splScore = c->score; + t0->splScore = c->score; #endif - t0->ori = 'C'; - t0->toGEN = c->xs; t0->toEST = c->ys; - t1->frGEN = c->xe; t1->frEST = c->ye; - t0->length = t0->toEST-t0->frEST+1; - t1->length = t1->toEST-t1->frEST+1; - break; - case 'E': break; - default : fatal("sim4b1.c: intron orientation not initialized."); - } + t0->ori = 'C'; + t0->toGEN = c->xs; t0->toEST = c->ys; + t1->frGEN = c->xe; t1->frEST = c->ye; + t0->length = t0->toEST-t0->frEST+1; + t1->length = t1->toEST-t1->frEST+1; + break; + case 'E': break; + default : fatal("sim4b1.c: intron orientation not initialized."); + } if (oris[i]!='E') wobble(&t0,&t1,"CT","AC",_genSeq); } @@ -573,8 +572,7 @@ Sim4::wobble(Exon **t0, Exon **t1, const char *donor, const char *acceptor, char } void -Sim4::slide_intron(int in_w, Exon **lblock, sim4_stats_t *st) -{ +Sim4::slide_intron(int in_w, Exon **lblock, sim4_stats_t *st) { Exon *t0, *t1, *head = *lblock; splice_t *g, *c, *cell; char type; @@ -600,8 +598,7 @@ Sim4::slide_intron(int in_w, Exon **lblock, sim4_stats_t *st) #ifdef SPLSCORE t0->splScore = 888888; #endif - } - else { + } else { int gtag=0, ctac=0; char *s; @@ -609,9 +606,17 @@ Sim4::slide_intron(int in_w, Exon **lblock, sim4_stats_t *st) w2 = min(in_w, min(t1->length-2, t1->toGEN-t1->frGEN-1)); splice(_genSeq, t0->toGEN-w1, t0->toGEN+w1, t1->frGEN-w2, t1->frGEN+w2, _estSeq, t0->toEST-w1, t1->frEST+w2, &g, &c, BOTH); - if (g->score>c->score) { cell = g; type = 'G'; } - else if (c->score>g->score) { cell = c; type = 'C'; } - else { cell = g; type = 'G'; } + + if (g->score>c->score) { + cell = g; + type = 'G'; + } else if (c->score>g->score) { + cell = c; + type = 'C'; + } else { + cell = g; + type = 'G'; + } #ifdef SPLSCORE t0->splScore = cell->score; @@ -628,23 +633,38 @@ Sim4::slide_intron(int in_w, Exon **lblock, sim4_stats_t *st) ckfree(c); /* determine the type, based on the # matches w/ GT-AG (CT-AC) */ + s = _genSeq+t0->toGEN; - if (*s=='G') gtag++; else if (*s=='C') ctac++; - ++s; - if (*s=='T') { gtag++; ctac++;} + if (*s=='G') + gtag++; + if (*s=='C') + ctac++; + s++; + + if (*s=='T') { + gtag++; + ctac++; + } s = _genSeq+t1->frGEN-3; - if (*s=='A') { gtag++; ctac++; } + + if (*s=='A') { + gtag++; + ctac++; + } ++s; - if (*s=='G') gtag++; else if (*s=='C') ctac++; + + if (*s=='G') + gtag++; + if (*s=='C') + ctac++; + if (gtag>ctac) { type = 'G'; numG++; - } - else if (ctac>gtag) { + } else if (ctac>gtag) { type = 'C'; numC++; - } - else { + } else { type = 'N'; numN++; }