1 // Code for the -*- C++ -*- namespace Sequence::phylipData<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 #include <Sequence/phylipData.hpp>
35 template < typename T >
36 std::istream & phylipData < T >::read (std::istream & s)
38 std::string notAllowed = {"()[]:;,"}; //characters not allowed in sequence name
40 s >> nsam >> nsites >> std::ws;
41 std::vector<T> _data(nsam);
42 std::string name(10,' '),temp;
44 for(unsigned i = 0 ; i < nsam ; ++i)
46 s.read( &name[0], 10*sizeof(char) ); //A name is 10 characters
47 for( auto c : notAllowed )
49 if(name.find(c) != std::string::npos)
51 throw std::runtime_error("Sequence::phylipData::read -- invalid character found in sequence name");
55 temp.erase( std::remove_if(temp.begin(),temp.end(),[](const char & __ch){ return std::isspace(__ch);}), temp.end() );
56 _data[i] = T(name,temp);
61 for ( unsigned i = 0 ; !s.eof() && i < nsam ; ++i )
65 temp.erase( std::remove_if(temp.begin(),temp.end(),[](const char & __ch){ return std::isspace(__ch);}), temp.end() );
69 this->assign(std::move(_data));
73 template < typename T >
74 std::ostream & phylipData < T >::print (std::ostream & s) const
76 size_t nsam = this->size();
79 << (*this)[0].seq.size() << '\n';
81 for( auto __t = this->begin() ; __t != this->end() ; ++__t )
83 if ( __t->name.length() >= 10 )
85 std::copy( __t->name.begin(),
87 std::ostream_iterator<char>(s,""));
89 else //it is too short
91 std::copy( __t->name.begin(),
93 std::ostream_iterator<char>(s,""));
94 for( decltype(__t->name.size()) i = __t->name.size() ; i < 10 ; ++i )
100 if( __t < this->end() - 1 ) s << '\n';
107 phylipData<T> & phylipData<T>::operator=( const AlignStream<T> & rhs)
109 An "assignment operator" member function.
110 If a phylipData object was constructed with a value of
111 0 for the sequence name length, this function
112 will set _namelen to the max sequence name contained in \a rhs.
113 If the object was constructed with a value k > 0, the
114 sequence name length will remain unchanged.
117 this->assign(rhs.begin(),rhs.end());