Commit f62ab84a authored by Mikaël Salson's avatar Mikaël Salson

MultiKmerSegmenter: Use pointer for the_kseg

Not using a pointer creates some problems with KmerSegmenter.
We should have a copy constructor in KmerSegmenter but it is a pain in the ***.

Not using pointers makes several copies of the same object. However the copies share the
same pointer to a KmerAffectAnalyser and that's the problem. When one of the copy is
deleted, its destructor is called which will delete the KmerAffectAnalyser and the other
copies won't have access to it, and it will also generate an error when the copies will try
to delete the KmerAffectAnalyser.

This has been solved by using pointers to KmerSegmenter everywhere.
parent 59858b66
......@@ -242,56 +242,64 @@ KmerSegmenter::KmerSegmenter(Sequence seq, Germline *germline)
}
KmerSegmenter::~KmerSegmenter() {
// if (kaa)
// delete kaa;
if (kaa)
delete kaa;
}
KmerMultiSegmenter::KmerMultiSegmenter(Sequence seq, MultiGermline *multigermline, ostream *out_unsegmented)
{
int best_score = 0 ;
the_kseg = NULL;
// Iterate over the germlines
for (list<Germline*>::const_iterator it = multigermline->germlines.begin(); it != multigermline->germlines.end(); ++it)
{
Germline *germline = *it ;
KmerSegmenter kseg(seq, germline);
KmerSegmenter *kseg = new KmerSegmenter(seq, germline);
bool keep_seg = false;
if (out_unsegmented)
{
// Debug, display k-mer affectation and segmentation result for this germline
*out_unsegmented << "#"
<< left << setw(4) << kseg.segmented_germline->code << " "
<< left << setw(20) << segmented_mesg[kseg.getSegmentationStatus()] << " ";
<< left << setw(4) << kseg->segmented_germline->code << " "
<< left << setw(20) << segmented_mesg[kseg->getSegmentationStatus()] << " ";
if (kseg.isSegmented())
*out_unsegmented << right << setw(3) << kseg.score << " ";
if (kseg->isSegmented())
*out_unsegmented << right << setw(3) << kseg->score << " ";
else
*out_unsegmented << " " ;
if (kseg.getSegmentationStatus() != UNSEG_TOO_SHORT)
*out_unsegmented << kseg.getKmerAffectAnalyser()->toString();
if (kseg->getSegmentationStatus() != UNSEG_TOO_SHORT)
*out_unsegmented << kseg->getKmerAffectAnalyser()->toString();
*out_unsegmented << endl ;
}
if (!best_score)
the_kseg = kseg;
keep_seg = true;
if (kseg.isSegmented())
if (kseg->isSegmented())
{
// Yes, it is segmented
if (kseg.score > best_score)
if (kseg->score > best_score)
{
the_kseg = kseg ;
best_score = kseg.score ;
keep_seg = true;
best_score = kseg->score ;
}
}
if (keep_seg) {
the_kseg = kseg;
} else {
delete kseg;
}
} // end for (Germlines)
}
KmerMultiSegmenter::~KmerMultiSegmenter() {
if (the_kseg)
delete the_kseg;
}
void KmerSegmenter::computeSegmentation(int strand, Germline* germline) {
......
......@@ -152,6 +152,8 @@ class KmerSegmenter : public Segmenter
*/
KmerSegmenter(Sequence seq, Germline *germline);
KmerSegmenter(const KmerSegmenter &seg);
~KmerSegmenter();
/**
......@@ -182,7 +184,7 @@ class KmerMultiSegmenter
KmerMultiSegmenter(Sequence seq, MultiGermline *multigermline, ostream *out_unsegmented);
~KmerMultiSegmenter();
KmerSegmenter the_kseg;
KmerSegmenter *the_kseg;
};
......
......@@ -27,33 +27,33 @@ WindowsStorage *WindowExtractor::extract(OnlineFasta *reads, MultiGermline *mult
KmerMultiSegmenter kmseg(reads->getSequence(), multigermline, out_unsegmented);
KmerSegmenter seg = kmseg.the_kseg ;
int read_length = seg.getSequence().sequence.length();
KmerSegmenter *seg = kmseg.the_kseg ;
int read_length = seg->getSequence().sequence.length();
stats[seg.getSegmentationStatus()].insert(read_length);
if (seg.isSegmented()) {
stats[seg->getSegmentationStatus()].insert(read_length);
if (seg->isSegmented()) {
seg.segmented_germline->stats.insert(read_length);
seg->segmented_germline->stats.insert(read_length);
junction junc = seg.getJunction(w);
junction junc = seg->getJunction(w);
if (junc.size()) {
stats[TOTAL_SEG_AND_WINDOW].insert(read_length) ;
windowsStorage->add(junc, reads->getSequence(), seg.getSegmentationStatus(), seg.segmented_germline);
windowsStorage->add(junc, reads->getSequence(), seg->getSegmentationStatus(), seg->segmented_germline);
} else {
stats[TOTAL_SEG_BUT_TOO_SHORT_FOR_THE_WINDOW].insert(read_length) ;
}
if (out_segmented) {
*out_segmented << seg ; // KmerSegmenter output (V/N/J)
*out_segmented << *seg ; // KmerSegmenter output (V/N/J)
if (out_unsegmented) {
*out_segmented << seg.getKmerAffectAnalyser()->toString() << endl;
*out_unsegmented << "#>" << reads->getSequence().label << " segmented on " << seg.segmented_germline->code << endl << endl;
*out_segmented << seg->getKmerAffectAnalyser()->toString() << endl;
*out_unsegmented << "#>" << reads->getSequence().label << " segmented on " << seg->segmented_germline->code << endl << endl;
}
}
nb_reads_germline[seg.system]++;
nb_reads_germline[seg->system]++;
} else if (out_unsegmented) {
*out_unsegmented << "#>" << reads->getSequence().label << " not segmented" << endl << endl;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment