-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepeats.cpp
141 lines (118 loc) · 3.57 KB
/
repeats.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/**
Copyright (C) 2013 INRA-URGI
This file is part of TEDNA, a short reads transposable elements assembler
TEDNA is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
GNU Affero General Public License for more details.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program.
**/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <algorithm>
#include "repeats.hpp"
Repeats::Repeats() { }
void Repeats::addRepeat(const CountedRepeat &repeat) {
_repeats.push_back(repeat);
}
void Repeats::addRepeat(RepeatHolder &repeatHolder) {
addRepeat(CountedRepeat(repeatHolder.getRepeat(), repeatHolder.getAverage()));
}
void Repeats::addRepeat(const Sequence &repeat, KmerNb count, bool loop) {
addRepeat(CountedRepeat(repeat, count, loop));
}
void Repeats::addRepeat(const string &repeat, KmerNb count, bool loop) {
Sequence sequence(repeat);
addRepeat(sequence, count, loop);
}
void Repeats::addRepeats(const Repeats &repeats) {
for (const CountedRepeat &cr: repeats._repeats) {
addRepeat(cr);
}
}
void Repeats::changeRepeat(const int i, const Sequence &repeat, KmerNb count) {
_repeats[i] = CountedRepeat(repeat, count);
}
void Repeats::setLoop(const int i, bool loop) {
_repeats[i].setLoop(loop);
}
void Repeats::removeRepeat(const int i) {
_repeats[i].clear();
}
bool Repeats::isRemoved(const int i) const {
return _repeats[i].empty();
}
unsigned int Repeats::getNbRepeats() const {
return _repeats.size();
}
void Repeats::sort() {
RepeatsStructure repeats;
for (const CountedRepeat &repeat: _repeats) {
if (repeat.getCount() > 0) {
repeats.push_back(repeat);
}
}
std::sort(repeats.begin(), repeats.end());
_repeats = repeats;
}
void Repeats::cutToThreshold(const KmerNb threshold) {
RepeatsStructure repeats;
for (CountedRepeat &cr: _repeats) {
if (cr.getCount() >= threshold) {
repeats.push_back(cr);
}
}
_repeats = repeats;
}
void Repeats::cutToNLongest(const unsigned int n) {
sort();
if (_repeats.size() < n) {
return;
}
_repeats.erase(_repeats.begin() + n, _repeats.end());
}
const CountedRepeat &Repeats::getRepeat(const int i) const {
return _repeats[i];
}
const CountedRepeat &Repeats::operator[] (const int i) const {
return getRepeat(i);
}
const bool Repeats::empty () const {
return _repeats.empty();
}
void Repeats::printFasta (ostream& stream) {
sort();
for (unsigned int i = 0; i < _repeats.size(); i++) {
if (! _repeats[i].empty()) {
stream << _repeats[i].printFasta(i);
}
}
}
void Repeats::check (const string &message) const {
if (Globals::CHECK.empty()) {
return;
}
cout << "\t\t" << message << endl;
for (const CountedRepeat &repeat: _repeats) {
for (short direction = 0; direction < Globals::DIRECTIONS; direction++) {
string sequence = repeat.getRepeat().getWord(direction);
int score = Globals::localAlignment(Globals::CHECK, sequence);
if (static_cast<unsigned int>(score) >= Globals::CHECK.size() / 2) {
cout << "\t\t\tScore of " << score << " with " << sequence << endl;
}
}
}
}
ostream& operator<<(ostream& output, const Repeats& r) {
for (unsigned int i = 0; i < r._repeats.size(); i++) {
output << i << ": " << r._repeats[i] << endl;
}
return output;
}