ToPS
ReverseComplementDNACreator.cpp
00001 /*
00002  *       ReverseComplementDNACreator.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 "ReverseComplementDNACreator.hpp"
00026 #include "SequenceFactory.hpp"
00027 #include "SequenceFactory.hpp"
00028 #include "ProbabilisticModelCreatorClient.hpp"
00029 #include "ReverseComplementDNA.hpp"
00030 
00031 namespace tops {
00032   ProbabilisticModelPtr ReverseComplementDNACreator::create( ProbabilisticModelParameters & parameters, const std::map<std::string,ProbabilisticModelPtr> & models) const {
00033     ProbabilisticModelParameterValuePtr modelpar = parameters.getMandatoryParameterValue("model");
00034     ConfigurationReader reader;
00035     std::string modelstr = modelpar->getString();
00036     ProbabilisticModelCreatorClient creator;
00037     ProbabilisticModelPtr m;
00038     std::map<std::string, ProbabilisticModelPtr>::const_iterator it = models.find(modelstr);
00039     bool frommodelname = false;
00040     if(it != models.end()) {
00041       m = it->second;
00042       frommodelname = true;
00043     }
00044     else{
00045       if((modelstr.size() > 0) && (modelstr[0] == '[') ){
00046         modelstr = modelstr.substr(1, modelstr.size() -2 );
00047         reader.load(modelstr);
00048         ProbabilisticModelParametersPtr par = reader.parameters();
00049         m = creator.create(*par);
00050       } else
00051         {
00052           m = creator.create(modelstr) ;
00053           if(m == NULL) {
00054             std::cerr << "Can not load model file " << modelstr<< "!" << std::endl;
00055             exit(-1);
00056           }
00057         }
00058     }
00059     ReverseComplementDNAPtr decorator = ReverseComplementDNAPtr(new ReverseComplementDNA(m));
00060     decorator->setAlphabet(m->alphabet());
00061     if(frommodelname)
00062       decorator->subModelName(modelstr);
00063     return decorator;
00064   }
00065 
00066   ProbabilisticModelPtr ReverseComplementDNACreator::create( ProbabilisticModelParameters & parameters) const {
00067     ProbabilisticModelParameterValuePtr modelpar = parameters.getMandatoryParameterValue("model");
00068     ProbabilisticModelCreatorClient creator;
00069     ConfigurationReader reader;
00070     std::string modelstr = modelpar->getString();
00071 
00072     ProbabilisticModelPtr m ;
00073     if((modelstr.size() > 0) && (modelstr[0] == '[') ){
00074       modelstr = modelstr.substr(1, modelstr.size() -2 );
00075       reader.load(modelstr);
00076       ProbabilisticModelParametersPtr par = reader.parameters();
00077       m = creator.create(*par);
00078     } else
00079       {
00080         m = creator.create(modelstr) ;
00081         if(m == NULL) {
00082           std::cerr << "Can not load model file " << modelstr<< "!" << std::endl;
00083           exit(-1);
00084         }
00085       }
00086     ReverseComplementDNAPtr decorator = ReverseComplementDNAPtr(new ReverseComplementDNA(m));
00087 
00088     decorator->setAlphabet(m->alphabet());
00089 
00090     return decorator;
00091   }
00092 
00093 
00094 }