1 // Code for the -*- C++ -*- namespace Sequence::ClustalW<T>
     5 Copyright (C) 2003-2009 Kevin Thornton, krthornt[]@[]uci.edu
     7 Remove the brackets to email me.
     9 This file is part of libsequence.
    11 libsequence is free software: you can redistribute it and/or modify
    12 it under the terms of the GNU General Public License as published by
    13 the Free Software Foundation, either version 3 of the License, or
    14 (at your option) any later version.
    16 libsequence is distributed in the hope that it will be useful,
    17 but WITHOUT ANY WARRANTY; without even the implied warranty of
    18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    19 GNU General Public License for more details.
    21 You should have received a copy of the GNU General Public License
    22 long with libsequence.  If not, see <http://www.gnu.org/licenses/>.
    26 /*! \file Clustalw.tcc
    27   @brief code for Clustalw.hpp
    30 #include <Sequence/AlignStream.hpp>
    39     ClustalW<T>::read(std::istream &s)
    41     Calls to Sequence::operator>> into objects of type ClustalW<T>
    42     results in a call to this function, which reads the alignment in
    48         std::map<std::string, std::string> seqs;
    49         std::map<std::string, int> order;
    50         std::size_t nseqs = 0;
    51         s >> clustalw >> std::ws;
    52         if (clustalw != "CLUSTAL")
    54                 throw std::runtime_error("Sequence::ClustalW::read() : input "
    55                                          "stream does not appear to be in "
    62         std::string temp, temp2;
    67                 if (ch == '\n' || ch == ' ' || ch == '*')
    78                         auto iter = seqs.find(temp);
    79                         if (iter != seqs.end())
    81                                 s >> temp2 >> std::ws;
    82                                 seqs[(*iter).first] += temp2;
    86                                 s >> temp2 >> std::ws;
    88                                 order[temp] = nseqs++;
    94         typename std::vector<T> _data;
    95         for (int i = 0; i < nseqs; ++i)
    97                 auto iter = seqs.begin(), iter_end = seqs.end();
    99                 while (iter != iter_end)
   101                         if (order[(*iter).first] == i)
   104                                 t.name = iter->first;
   105                                 t.seq = std::move(iter->second);
   106                                 _data.emplace_back(std::move(t));
   107                                 //_data[i].name = std::move(iter->first);
   108                                 //_data[i].seq = std::move(iter->second);
   116         if (_data.size() != nseqs)
   118                 throw std::runtime_error("fatal error converting input data");
   120         this->assign(std::move(_data));
   124     template <typename T>
   126     ClustalW<T>::print(std::ostream &s) const
   128         typename ClustalW<T>::const_iterator i = this->begin(),
   130         unsigned k = 0, len = unsigned(i->seq.length());
   135                 unsigned offset = (k + 60 < len) ? k + 60 : k + (len - k);
   136                 for (i = this->begin(); i < j; ++i)
   138                         s << i->name << '\t';
   139                         std::copy(i->seq.begin()
   140                                       + std::string::difference_type(k),
   142                                       + std::string::difference_type(offset),
   143                                   std::ostream_iterator<char>(s, ""));
   152     template <typename T>
   154     ClustalW<T>::ReadThroughLine(std::istream &s)