motif.cpp
2.5 KB
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
#include <iostream>
#include <sstream>
#include "motif.h"
Motif::Motif ()
{
}
Motif::Motif (int rna, std::string seq) : rna_(rna), seq_(seq)
{
listBp_ = std::vector < std::pair < unsigned int, unsigned int > > ();
}
Motif::Motif (int rna, std::string seq, uint ic) : rna_(rna), seq_(seq), ic_(ic)
{
listBp_ = std::vector < std::pair < unsigned int, unsigned int > > ();
}
Motif::Motif (const Motif& that) :
rna_(that.rna_), seq_(that.seq_), listBp_(that.listBp_), ic_(that.ic_)
{
}
Motif::~Motif ()
{
}
int Motif::getRna_() const
{
return rna_;
}
std::string Motif::getSeq_() const
{
return seq_;
}
unsigned int Motif::getIc_() const
{
return ic_;
}
std::vector < std::pair < unsigned int, unsigned int > > Motif::getListBp_() const
{
return listBp_;
}
void Motif::setRna_(int rna)
{
rna_ = rna;
}
void Motif::setSeq_(std::string seq)
{
seq_ = seq;
}
void Motif::setIc_(unsigned int ic)
{
ic_ = ic;
}
void Motif::setListBp_(std::vector < std::pair < unsigned int, unsigned int > > listBp)
{
listBp_ = listBp;
}
Motif& Motif::operator=(const Motif& that)
{
if(&that == this)
return *this;
rna_ = that.rna_;
seq_ = that.seq_;
ic_ = that.ic_;
listBp_ = that.listBp_;
return *this;
}
std::string Motif::convToDP() const
{
std::cout << "debut convToDP" << std::endl;
std::string res(uint(seq_.size()), '.');
char c1 = '(', c2 = ')';
for (int i = 0; i < int(listBp_.size()); i++)
{
res[listBp_[i].first] = c1;
res[listBp_[i].second] = c2;
}
std::cout << "fin convToDP" << std::endl;
return res;
}
void Motif::checkListBp_() const
{
for(size_t i = 0, size = listBp_.size(); i != size; i++)
{
if(!app(seq_[listBp_[i].first], seq_[listBp_[i].second])) {
std::string s = std::string(1, seq_[listBp_[i].first]);
std::string s2 = std::string(1, seq_[listBp_[i].second]);
throw (std::string("Error in the motif or constraint, base pair " + s
+ "-" + s2 + " (" + std::to_string(listBp_[i].first+1) + "," +
std::to_string(listBp_[i].second+1) + ") isn't allow."));
}
}
}
bool Motif::app(const char c1, const char c2) const
{
std::stringstream ss;
ss << c1 << c2;
std::string bp;
ss >> bp;
if (bp.compare("AU") != 0 and bp.compare("UA") != 0 and
bp.compare("UG") != 0 and bp.compare("GU") != 0 and
bp.compare("GC") != 0 and bp.compare("CG") != 0)
return false;
return true;
}