ToPS
|
00001 /* 00002 * PhasedRunLengthDistributionCreator.cpp 00003 * 00004 * Copyright 2011 Andre Yoshiaki Kashiwabara <akashiwabara@usp.br> 00005 * Ígor Bonádio <ibonadio@ime.usp.br> 00006 * Vitor Onuchic <vitoronuchic@gmail.com> 00007 * Alan Mitchell Durham <aland@usp.br> 00008 * 00009 * This program is free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation; either version 3 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * This program is distributed in the hope that it will be useful, 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 * GNU General Public License for more details. 00018 * 00019 * You should have received a copy of the GNU General Public License 00020 * along with this program; if not, write to the Free Software 00021 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 00022 * MA 02110-1301, USA. 00023 */ 00024 00025 #include "PhasedRunLengthDistributionCreator.hpp" 00026 #include "SequenceFactory.hpp" 00027 #include "SequenceFactory.hpp" 00028 #include "ProbabilisticModelCreatorClient.hpp" 00029 #include "PhasedRunLengthDistribution.hpp" 00030 00031 namespace tops { 00032 ProbabilisticModelPtr PhasedRunLengthDistributionCreator::create( ProbabilisticModelParameters & parameters, const std::map<std::string,ProbabilisticModelPtr> & models) const { 00033 ProbabilisticModelParameterValuePtr iphasepar = parameters.getMandatoryParameterValue("input_phase"); 00034 ProbabilisticModelParameterValuePtr ophasepar = parameters.getMandatoryParameterValue("output_phase"); 00035 ProbabilisticModelParameterValuePtr nphasepar = parameters.getMandatoryParameterValue("number_of_phases"); 00036 ProbabilisticModelParameterValuePtr deltapar = parameters.getMandatoryParameterValue("delta"); 00037 ProbabilisticModelParameterValuePtr modelpar = parameters.getMandatoryParameterValue("model"); 00038 if( 00039 (nphasepar == NULL) || 00040 (deltapar == NULL) || 00041 (iphasepar == NULL) || 00042 (ophasepar == NULL) || 00043 (modelpar == NULL) ) { 00044 exit(-1); 00045 } 00046 int iphase = iphasepar -> getInt(); 00047 int ophase = ophasepar -> getInt(); 00048 int nphase = nphasepar -> getInt(); 00049 int delta = deltapar -> getInt(); 00050 std::string modelstr = modelpar->getString(); 00051 00052 00053 ConfigurationReader reader; 00054 ProbabilisticModelPtr m; 00055 std::map<std::string, ProbabilisticModelPtr>::const_iterator it = models.find(modelstr); 00056 if(it != models.end()) 00057 m = it->second; 00058 else{ 00059 std::cerr << "Model " << modelstr << " not loaded ! " << std::endl; 00060 std::exit(-1); 00061 } 00062 00063 PhasedRunLengthDistributionPtr decorator = PhasedRunLengthDistributionPtr(new PhasedRunLengthDistribution(m)); 00064 AlphabetPtr alpha = m->alphabet(); 00065 decorator->initialize(delta, iphase, ophase, nphase); 00066 decorator->setAlphabet(m->alphabet()); 00067 decorator->subModelName(modelstr); 00068 return decorator; 00069 } 00070 00071 ProbabilisticModelPtr PhasedRunLengthDistributionCreator::create( ProbabilisticModelParameters & parameters) const { 00072 ProbabilisticModelParameterValuePtr iphasepar = parameters.getMandatoryParameterValue("input_phase"); 00073 ProbabilisticModelParameterValuePtr ophasepar = parameters.getMandatoryParameterValue("output_phase"); 00074 ProbabilisticModelParameterValuePtr nphasepar = parameters.getMandatoryParameterValue("number_of_phases"); 00075 ProbabilisticModelParameterValuePtr deltapar = parameters.getMandatoryParameterValue("delta"); 00076 ProbabilisticModelParameterValuePtr modelpar = parameters.getMandatoryParameterValue("model"); 00077 if( 00078 (nphasepar == NULL) || 00079 (deltapar == NULL) || 00080 (iphasepar == NULL) || 00081 (ophasepar == NULL) || 00082 (modelpar == NULL) ) { 00083 exit(-1); 00084 } 00085 int iphase = iphasepar -> getInt(); 00086 int ophase = ophasepar -> getInt(); 00087 int nphase = nphasepar -> getInt(); 00088 int delta = deltapar -> getInt(); 00089 std::string modelstr = modelpar->getString(); 00090 00091 ProbabilisticModelCreatorClient creator; 00092 ConfigurationReader reader; 00093 ProbabilisticModelPtr m ; 00094 if((modelstr.size() > 0) && (modelstr[0] == '[') ){ 00095 modelstr = modelstr.substr(1, modelstr.size() -2 ); 00096 reader.load(modelstr); 00097 ProbabilisticModelParametersPtr par = reader.parameters(); 00098 m = creator.create(*par); 00099 } else { 00100 m = creator.create(modelstr) ; 00101 if(m == NULL) { 00102 std::cerr << "Can not load model file " << modelstr<< "!" << std::endl; 00103 exit(-1); 00104 } 00105 } 00106 PhasedRunLengthDistributionPtr decorator = PhasedRunLengthDistributionPtr(new PhasedRunLengthDistribution(m)); 00107 AlphabetPtr alpha = m->alphabet(); 00108 decorator->initialize(delta, iphase, ophase, nphase); 00109 decorator->setAlphabet(m->alphabet()); 00110 return decorator; 00111 00112 } 00113 00114 }