-
Notifications
You must be signed in to change notification settings - Fork 0
/
MotifSite.cpp
95 lines (85 loc) · 3.13 KB
/
MotifSite.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
/*
* Copyright (C) 2006 Cold Spring Harbor Laboratory
* Authors: Andrew D. Smith, Pavel Sumazin and Michael Q. Zhang
*
* This file is part of CREAD.
*
* CREAD is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* CREAD 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. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with CREAD; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "MotifSite.hpp"
using std::string;
using std::ostringstream;
using std::vector;
bool
MotifSite::is_valid_orientation(char c) {
// static const char* MotifSite::valid_orientations = "pn";
// static const size_t n_valid_orientations = 2;
return c == 'p' || c == 'n';
}
MotifSite::MotifSite(std::string s, std::string sn, std::string st,
std::string l, std::string g, std::string o, std::string sc) :
site(s), seq_name(sn), gaps(g) {
orientation = (is_valid_orientation(o[0])) ? o[0] : 'p';
start = atoi(st.c_str());
score = atof(sc.c_str());
int temp_length = atoi(l.c_str());
if (temp_length > 0)
length = static_cast<size_t>(temp_length);
else throw InvalidMotifSiteException(
static_cast<string>("non-positive site length"));
}
MotifSite::MotifSite(string s) {
vector<string> parts = smithlab::split(s, ";", true);
if (parts.size() < 6) {
string message("invalid site format: ");
message += s;
throw InvalidMotifSiteException(message);
}
site = smithlab::strip(parts[0]);
seq_name = smithlab::strip(parts[1]);
start = atoi(parts[2].c_str());
// TODO: make sure the length is sensible
length = static_cast<size_t>(atoi(parts[3].c_str()));
gaps = smithlab::strip(parts[4]); // this is always empty
orientation = smithlab::strip(parts[5])[0];
if (parts.size() > 6)
score = atof(parts[6].c_str());
else score = -std::numeric_limits<float>::max();
}
string
MotifSite::tostring() const {
ostringstream os;
os << site << "; " << seq_name << "; " << start << "; "
<< length << "; " << gaps << "; " << orientation << "; " << score;
return os.str();
}
bool
MotifSite::operator<(const MotifSite& ms) const {
return ((seq_name < ms.seq_name) ||
(seq_name == ms.seq_name && start < ms.start) ||
(seq_name == ms.seq_name && start == ms.start &&
length < ms.length) ||
(seq_name == ms.seq_name && start == ms.start &&
length == ms.length && orientation < ms.orientation) ||
(seq_name == ms.seq_name && start == ms.start &&
length == ms.length && orientation == ms.orientation &&
score < ms.score));
}
bool
MotifSite::operator==(const MotifSite& ms) const {
return site == ms.site && seq_name == ms.seq_name &&
start == ms.start && length == ms.length &&
orientation == ms.orientation && score == ms.score;
}