Skip to content
Snippets Groups Projects
Commit 71e280b4 authored by Studer Gabriel's avatar Studer Gabriel
Browse files

Function to extract subpart of HMM

parent b8c55045
No related branches found
No related tags found
No related merge requests found
...@@ -52,6 +52,7 @@ void export_hmm() ...@@ -52,6 +52,7 @@ void export_hmm()
class_<HMM, HMMPtr>("HMM", init<>()) class_<HMM, HMMPtr>("HMM", init<>())
.def("Load", &HMM::Load).staticmethod("Load") .def("Load", &HMM::Load).staticmethod("Load")
.def("AddColumn", &HMM::push_back) .def("AddColumn", &HMM::push_back)
.def("Extract", &HMM::Extract)
.add_property("null_model", make_function(&HMM::GetNullModel, .add_property("null_model", make_function(&HMM::GetNullModel,
return_value_policy<copy_const_reference>())) return_value_policy<copy_const_reference>()))
.add_property("columns", .add_property("columns",
......
...@@ -159,6 +159,27 @@ String HMM::GetSequence() const{ ...@@ -159,6 +159,27 @@ String HMM::GetSequence() const{
return ss.str(); return ss.str();
} }
HMMPtr HMM::Extract(uint from, uint to){
if(to <= from){
throw std::runtime_error("Second index must be bigger than first one!");
}
if(to >= this->size()){
throw std::runtime_error("Invalid index!");
}
HMMPtr return_hmm(new HMM);
return_hmm->SetNullModel(null_model_);
for(uint i = from; i < to; ++i){
return_hmm->push_back(columns_[i]);
}
return return_hmm;
}
Real HMM::GetAverageEntropy() const { Real HMM::GetAverageEntropy() const {
Real n_eff=0.0; Real n_eff=0.0;
......
...@@ -194,6 +194,8 @@ class HMM { ...@@ -194,6 +194,8 @@ class HMM {
String GetSequence() const; String GetSequence() const;
HMMPtr Extract(uint from, uint to);
//some functions to make it behave like a vector //some functions to make it behave like a vector
size_t size() const { return columns_.size(); } size_t size() const { return columns_.size(); }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment