Skip to content

Commit

Permalink
Add the exonManager, that does garbage collection of exons. Improve
Browse files Browse the repository at this point in the history
general garbage collection.  Claim that there are no leaks left ('cause
everything is garbage collected now).
  • Loading branch information
brianwalenz committed Jul 13, 2005
1 parent 89404ca commit 794f606
Show file tree
Hide file tree
Showing 14 changed files with 322 additions and 231 deletions.
155 changes: 107 additions & 48 deletions kmer/libsim4/sim4core/exon.H
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
68 changes: 34 additions & 34 deletions kmer/libsim4/sim4core/greedy.C
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand Down
65 changes: 32 additions & 33 deletions kmer/libsim4/sim4core/mspManager.C
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
mspManager::mspManager() {
_sorted = true;

_ESTlen = 0;
_GENlen = 0;

_allocMSPs = 16384;
_numMSPs = 0;
_allMSPs = new msp [_allocMSPs];
Expand All @@ -24,15 +27,20 @@ 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.
//
_match = 0;
_matchdiff = 0;
_percentError = 0.0;
_wordExtAllow = 0;

_exonManager = 0L;

_minMSPScore = 0;

_diagMax = 0;
_diagExt = 0L;
Expand Down Expand Up @@ -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;

Expand All @@ -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
Expand All @@ -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;
Expand Down
Loading

0 comments on commit 794f606

Please sign in to comment.