ToPS
RemoveSequenceFromModel.cpp
00001 /*
00002  *       RemoveSequenceFromModel.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 "RemoveSequenceFromModel.hpp"
00026 #include "SequenceFactory.hpp"
00027 #include <map>
00028 #include <vector>
00029 
00030 namespace tops
00031 {
00032   ProbabilisticModelPtr RemoveSequenceFromModel::create( ProbabilisticModelParameters & parameters) const
00033   {
00034     ProbabilisticModelParameterValuePtr seqlistpar = parameters.getMandatoryParameterValue("sequence_list");
00035     ProbabilisticModelParameterValuePtr alphabetpar = parameters.getMandatoryParameterValue("alphabet");
00036     ProbabilisticModelParameterValuePtr phasepar = parameters.getOptionalParameterValue("phase");
00037 
00038     if((seqlistpar == NULL) || (alphabetpar == NULL))
00039       {
00040         std::cerr << help() << std::endl;
00041         exit(-1);
00042       }
00043     AlphabetPtr alphabet = AlphabetPtr(new Alphabet());
00044     alphabet->initializeFromVector(alphabetpar->getStringVector());
00045 
00046     std::vector<std::string> seqs = seqlistpar->getStringVector();
00047 
00048     int phase = 0;
00049     if(phasepar != NULL)
00050       phase = phasepar->getInt();
00051 
00052 
00053     ProbabilisticModelPtr result = _creator->create(parameters);
00054     for(int i = 0; i < (int)seqs.size() ; i ++ )
00055       {
00056         SequenceFactory factory(alphabet);
00057         boost::regex sep(" ");
00058         std::vector<std::string> seqstr;
00059         split_regex(seqs[i], seqstr,  sep);
00060         Sequence s = factory.createSequence(seqstr);
00061         result->removeSequenceFromModel(s, phase);
00062       }
00063 
00064     return result;
00065   }
00066 }