39 SimpleSNP::SimpleSNP(SimpleSNP && s) : PolyTable(
std::move(s))
43 SimpleSNP & SimpleSNP::operator=(SimpleSNP && pt)
45 PolyTable::operator=(std::move(pt));
49 std::istream & SimpleSNP::read (std::istream & s)
55 unsigned nsam, nsites, i, j;
57 if(!(s >> nsam >> nsites))
59 throw std::runtime_error(
"SimpleSNP.cc: file did not start with nsam nsites");
63 std::vector<double> _positions(nsites);
65 for (i = 0; i < nsites; ++i)
67 if (! (s >> _positions[i] >> std::ws))
68 throw std::runtime_error(
"SimpleSNP.cc: error in processing site positions");
70 std::string outgroup,temp,temp2;
72 std::istringstream check(temp),check2(temp);
74 while (! check.eof() )
76 check >> temp2 >> std::ws;
79 bool haveOGlabel = (nc == nsites + 1) ?
true :
false;
80 _names.resize(nsam+1);
85 outgroup.resize(nsites);
86 for (i = 0; i < nsites; ++i)
90 throw std::runtime_error(
"SimpleSNP.cc: error reading in seg. sites");
92 ch = char(toupper(ch));
106 for (i = 0; i < outgroup.length(); ++i)
108 if (
char(std::toupper(outgroup[i])) ==
'N')
113 std::vector<std::string> _data;
114 if(numn == outgroup.length())
120 for (i = 0 ; i < nsam ; ++i)
121 _data[i].resize(nsites);
126 _data.resize(nsam+1);
127 for (i = 0 ; i < nsam+1 ; ++i)
128 _data[i].resize(nsites);
135 for (i = 0 + haveOG; i < nsam + haveOG; ++i)
139 throw std::runtime_error(
"SimpleSNP.cc: error processing sequences");
141 _names[i-haveOG+1] = name;
142 char *temp =
new char[nsites+1];
143 char *temp2 =
nullptr;
147 _names[i-haveOG+2] = name;
148 temp2 =
new char[nsites+1];
150 for (j = 0; j < nsites; ++j)
155 if(temp2 !=
nullptr)
delete [] temp2;
156 throw std::runtime_error(
"SimpleSNP.cc: error processing sequenes");
158 ch = char(toupper(ch));
161 switch (
char(std::toupper(ch)))
227 if (_data.size() != nsam+haveOG)
229 throw (std::runtime_error(
"SimpleSNP::read() -- number of sequences does not match input value"));
231 this->assign(std::move(_positions),std::move(_data));
235 std::ostream & SimpleSNP::print(std::ostream &o)
const 237 o << this->size()-this->haveOutgroup <<
'\t' <<this->numsites() <<
'\n';
239 for(
unsigned i = 0 ; i < this->numsites()-1 ; ++i)
241 o << this->position(i) <<
'\t';
243 o << this->position(this->numsites()-1) <<
'\n';
245 if (haveOutgroup ==
true)
255 for(
unsigned i = 0 ; i < this->numsites() ; ++i)
257 o <<
'\t' << (*this)[0][i];
260 for(
unsigned i = 1 ; i < this->size() ; ++i)
270 for(
unsigned j = 0 ; j < this->numsites() ; ++j)
272 o <<
'\t' << (*this)[i][j];
274 if (i < this->size()-1)
281 for(
unsigned i = 0 ; i < this->numsites() ; ++i)
286 for(
unsigned i = 0 ; i < this->size() ; ++i)
294 for(
unsigned j = 0 ; j < this->numsites() ; ++j)
296 o <<
'\t' << (*this)[i][j];
298 if (i < this->size()-1)
305 std::string SimpleSNP::label(
unsigned i)
const 310 if(i >= this->size() )
312 throw std::out_of_range(
"Sequence::SimpleSNP::label(), i out of range");
314 if (haveOutgroup && i==0)
316 return string(
"anc");
320 return string(
"seq" + std::to_string(i));
322 return _names[i-unsigned(haveOutgroup)];
325 bool SimpleSNP::outgroup(
void)
const 334 void SimpleSNP::set_outgroup(
const bool & b)
The namespace in which this library resides.
Declaration of Sequence::SimpleSNP, a polymorphism table stream in a "spreadsheet" format...
Operations on non-const Sequence::PolyTable objects.