38 for (
size_t i = 0; i < seq1.
size(); i++)
40 if (seq1[i] != seq2[i])
65 for (
size_t i = 0; i < seq.
size(); ++i)
103 return transc_.translate(sequence);
116 return transc_.reverse(sequence);
123 size_t seq_size = seq.
size();
126 for (
size_t i = 0; i < seq_size / 2; ++i)
128 j = seq_size - 1 - i;
139 auto iSeq = unique_ptr<SequenceInterface>(sequence.
clone());
165 size_t seq_size = seq.
size();
168 for (
size_t i = 0; i < seq_size / 2; ++i)
170 j = seq_size - 1 - i;
195 for (
size_t i = 0; i < seq1.
size(); ++i)
201 if (x != gap && y != gap)
215 return static_cast<double>(id) /
static_cast<double>(tot) * 100.;
224 for (
size_t i = 0; i < seq.
size(); ++i)
226 if (!alpha.isGap(seq[i]))
238 for (
size_t i = 0; i < seq.
size(); ++i)
240 if (!alpha.isGap(seq[i]) && !alpha.isUnresolved(seq[i]))
252 for (
size_t i = 0; i < seq.
size(); ++i)
254 if (!(alpha.isGap(seq[i]) || alpha.isUnresolved(seq[i])))
255 content.push_back(seq[i]);
257 auto newSeq = unique_ptr<SequenceInterface>(seq.
clone());
258 newSeq->setContent(content);
268 for (
size_t i = 0; i < seq.
size(); ++i)
270 if (alphaPtr->isUnresolved(seq[i]))
282 for (
size_t i = 0; i < seq.
size(); ++i)
284 if (!alphaPtr->isGap(seq[i]))
285 content.push_back(seq[i]);
287 auto newSeq = unique_ptr<SequenceInterface>(seq.
clone());
288 newSeq->setContent(content);
297 for (
size_t i = seq.
size(); i > 0; --i)
299 if (alphaPtr->isGap(seq[i - 1]))
308 auto calpha = dynamic_pointer_cast<const CodonAlphabet>(seq.
getAlphabet());
310 throw Exception(
"SequenceTools::getSequenceWithoutStops. Input sequence should have a codon alphabet.");
312 for (
size_t i = 0; i < seq.
size(); ++i)
314 if (!gCode.
isStop(seq[i]))
315 content.push_back(seq[i]);
317 auto newSeq = unique_ptr<SequenceInterface>(seq.
clone());
318 newSeq->setContent(content);
326 auto calpha = dynamic_pointer_cast<const CodonAlphabet>(seq.
getAlphabet());
328 throw Exception(
"SequenceTools::removeStops. Input sequence should have a codon alphabet.");
329 for (
size_t i = seq.
size(); i > 0; --i)
331 if (gCode.
isStop(seq[i - 1]))
340 auto calpha = dynamic_pointer_cast<const CodonAlphabet>(seq.
getAlphabet());
342 throw Exception(
"SequenceTools::replaceStopsWithGaps. Input sequence should have a codon alphabet.");
343 int gap = calpha->getGapCharacterCode();
344 for (
size_t i = 0; i < seq.
size(); ++i)
359 size_t n = seq1.
size();
361 unsigned int r = alphaPtr->getSize();
366 for (
size_t i = 0; i < n; ++i)
370 if (!alphaPtr->isGap(x) && !alphaPtr->isUnresolved(x)
371 && !alphaPtr->isGap(y) && !alphaPtr->isUnresolved(y))
373 array(
static_cast<size_t>(x),
static_cast<size_t>(y))++;
378 double sb2 = 0, nij, nji;
379 for (
unsigned int i = 1; i < r; ++i)
381 for (
unsigned int j = 0; j < i; ++j)
385 if (nij != 0 || nji != 0)
387 sb2 += pow(nij - nji, 2) / (nij + nji);
397 auto test = make_unique<BowkerTest>();
398 test->setStatistic(sb2);
399 test->setPValue(pvalue);
407 std::vector<unique_ptr<SequenceInterface>>& hap,
410 vector< vector< int >> states(seq.
size());
411 list< unique_ptr<Sequence>> t_hap;
413 unsigned int hap_count = 1;
415 for (
size_t i = 0; i < seq.
size(); ++i)
417 vector<int> st = alphaPtr->getAlias(seq[i]);
420 st.push_back(alphaPtr->getGapCharacterCode());
422 if (st.size() <= level)
428 states[i] = vector<int>(1, seq[i]);
433 for (
size_t i = 0; i < states.size(); ++i)
435 for (
auto it = t_hap.begin(); it != t_hap.end(); it++)
437 for (
size_t j = 0; j < states[i].size(); ++j)
439 auto tmp_seq = unique_ptr<Sequence>((**it).clone());
440 tmp_seq->setName(seq.
getName() +
"_hap");
441 if (j < states[i].size() - 1)
444 tmp_seq->addElement(states[i][j]);
445 t_hap.insert(it, std::move(tmp_seq));
449 (**it).addElement(states[i][j]);
454 for (
auto it = t_hap.rbegin(); it != t_hap.rend(); it++)
456 hap.push_back(std::move(*it));
474 for (
size_t i = 0; i < length; ++i)
480 seq.push_back(alphaPtr->getGeneric(st));
483 auto s = make_unique<Sequence>(s1.
getName() +
"+" + s2.
getName(), seq, alphaPtr);
496 if (name.size() == 0)
497 name = s.
getName() +
"_haplotype";
501 for (
unsigned int i = 0; i < s.
size(); ++i)
504 vector<int> nucs = alphaPtr->getAlias(s.
getValue(i));
507 std::ignore = remove(nucs.begin(), nucs.end(), h.
getValue(i));
508 nucs = vector<int>(nucs.begin(), nucs.end() - 1);
512 nucs = vector<int>(nucs.begin(), nucs.end());
514 c = alphaPtr->intToChar(alphaPtr->getGeneric(nucs));
515 if (level <= nucs.size() && (alphaPtr->isUnresolved(s.
getValue(i)) || alphaPtr->isUnresolved(h.
getValue(i))))
517 c = alphaPtr->intToChar(alphaPtr->getUnknownCharacterCode());
521 auto hap = make_unique<Sequence>(name, seq, alphaPtr);
535 if ((ph < 1) || (ph > 3))
538 size_t s = seq.
size();
539 size_t n = (s -
static_cast<size_t>(ph) + 3) / 3;
541 vector<int> content(n);
543 int tir = seq.
getAlphabet()->getGapCharacterCode();
546 for (
size_t i = 0; i < n; i++)
548 j = i * 3 +
static_cast<size_t>(ph) - 1;
551 content[i] = RNY_->getRNY(tir, seq[0], seq[1], *seq.
getAlphabet());
555 content[i] = RNY_->getRNY(seq[j - 1], seq[j], tir, *seq.
getAlphabet());
557 content[i] = RNY_->getRNY(seq[j - 1], seq[j], seq[j + 1], *seq.
getAlphabet());
562 auto alphaPtr = dynamic_pointer_cast<const Alphabet>(RNY_);
563 auto seqPtr = make_unique<Sequence>(seq.
getName(), content, seq.
getComments(), alphaPtr);
577 size_t n = seq.
size();
579 vector<int> content(n);
581 int tir = seq.
getAlphabet()->getGapCharacterCode();
585 content[0] = RNY_->getRNY(tir, seq[0], seq[1], *seq.
getAlphabet());
587 for (
unsigned int i = 1; i < n - 1; i++)
589 content[i] = RNY_->getRNY(seq[i - 1], seq[i], seq[i + 1],
593 content[n - 1] = RNY_->getRNY(seq[n - 2], seq[n - 1], tir, *seq.
getAlphabet());
597 auto alphaPtr = dynamic_pointer_cast<const Alphabet>(RNY_);
598 auto seqPtr = make_unique<Sequence>(seq.
getName(), content, seq.
getComments(), alphaPtr);
615 auto alphabet = dynamic_pointer_cast<const CodonAlphabet>(sequence.
getAlphabet());
621 for (i = 0; i < sequence.
size() && !gCode.
isStart(sequence[i]); ++i)
623 for (
size_t j = 0; includeInit ? j < i : j <= i; ++j)
631 for (i = 0; i < sequence.
size() && !gCode.
isStop(sequence[i]); ++i)
633 for (
size_t j = includeStop ? i + 1 : i; j < sequence.
size(); ++j)
649 for (
size_t seqi = 0; seqi < seq.
size() - motif.
size() + 1; seqi++)
652 for (
size_t moti = 0; moti < motif.
size(); moti++)
679 int s =
static_cast<int>(alphabet->getSize());
680 vector<int> content(length);
681 for (
size_t i = 0; i < length; ++i)
685 return make_unique<Sequence>(
"random", content, alphabet);
const Alphabet & alphabet() const override
Get the alphabet associated to the list.
std::shared_ptr< const Alphabet > getAlphabet() const override
Get the alphabet associated to the list.
The alphabet exception base class.
Exception thrown when two alphabets do not match.
virtual std::string getAlphabetType() const =0
Identification method.
virtual int getGapCharacterCode() const =0
virtual const std::string & getName() const =0
Get the name of this sequence.
virtual std::shared_ptr< const Alphabet > getAlphabet() const =0
Get the alphabet associated to the list.
virtual void deleteElement(size_t pos)=0
Remove the element at position 'pos'.
virtual size_t size() const =0
Get the number of elements in the list.
virtual const Alphabet & alphabet() const =0
Get the alphabet associated to the list.
Partial implementation of the Transliterator interface for genetic code object.
virtual bool isStart(int state) const
Tells is a particular codon is a start codon.
virtual bool isStop(int state) const =0
Tells is a particular codon is a stop codon.
virtual void setElement(size_t pos, const std::string &c)=0
Set the element at position 'pos' to character 'c'.
Replication between to nucleic acids.
int translate(int state) const override
Translate a given state coded as a int from source alphabet to target alphabet.
SequenceInterface * clone() const override=0
Exception thrown when a sequence is not align with others.
A basic implementation of the Sequence interface.
virtual const T & getValue(size_t pos) const =0
checked access to a character in list.
std::string toString(T t)
std::size_t count(const std::string &s, const std::string &pattern)
This alphabet is used to deal NumericAlphabet.