#ifndef _MATCH_TRIE #define _MATCH_TRIE #include #include #include "dna.h" #include "nuctrie.h" using std::map; using std::set; using cis::NUC; template class match_trie : public nuc_trie { map *> children; TAG * _label; NUC _childbits; public: typedef bool (*MATCH_FCN)(NUC, NUC); typedef int (*LOSS_FCN)(NUC, NUC); static MATCH_FCN match; static LOSS_FCN loss; static int min_score; match_trie(); ~match_trie(); TAG * label(); NUC childbits(); match_trie * child(NUC); void insert(NUC const*const pat, TAG const & label); void match_all(NUC const*const pat, int, std::set & labels); void score_all(NUC const*const pat, int, std::set & labels, int cur_mismatch); /* static void set_match_fcn(MATCH_FCN); */ /* static void set_loss_fcn(LOSS_FCN); */ /* static MATCH_FCN get_match_fcn(); */ /* static LOSS_FCN get_loss_fcn(); */ }; template bool (*match_trie::match)(NUC query, NUC target); template int (*match_trie::loss)(NUC query, NUC target); template int match_trie::min_score; //template bool (match_trie::* match)(NUC query, NUC target); template match_trie::match_trie(){ label = NULL; } template match_trie::~match_trie(){ typename map *>::iterator cit; for (cit = children.begin(); cit != children.end(); cit++){ delete (*cit).second; } children.clear(); if (label != NULL) { delete label; label = NULL; } } template void match_trie::match_all(NUC const*const target, int tsize, set & labels){ typename map *>::iterator cit; if (label != NULL) labels.insert(label); if (tsize == 0) return; for (cit = children.begin(); cit != children.end(); cit++){ if (match(cit->first, *target)){ (*cit).second->match_all(target+1, tsize-1, labels); } } } //this assumes a 'score' field in the TAG, which is set temporarily //this is in accordance with the 'early stopping criterion' whereby the //scoring function is template void match_trie::score_all(NUC const*const target, int tsize, set & labels, int cur_score){ typename map *>::iterator cit; if (label != NULL){ label->score = cur_score; //this is only valid for one top-level complete call to score_all labels.insert(label); } if (tsize == 0) return; int next_score = 0; for (cit = children.begin(); cit != children.end(); cit++){ next_score = cur_score + match_trie::loss(cit->first, *target); if (next_score >= match_trie::min_score) (*cit).second->score_all(target+1, tsize-1, labels, next_score); } } #endif //_MATCH_TRIE