-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathContentSensor.C
181 lines (124 loc) · 3.43 KB
/
ContentSensor.C
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/****************************************************************
ContentSensor.C
Copyright (C)2013 William H. Majoros ([email protected]).
This is OPEN SOURCE SOFTWARE governed by the Gnu General Public
License (GPL) version 3, as described at www.opensource.org.
****************************************************************/
#include "ContentSensor.H"
#include <iostream>
#include <fstream>
#include "MarkovChain.H"
#include "ThreePeriodicMarkovChain.H"
#include "FastMarkovChain.H"
#include "Fast3PMC.H"
#include "IMM.H"
#include "ThreePeriodicIMM.H"
#include "SignalQueue.H"
#include "BOOM/PureDnaAlphabet.H"
BOOM::Regex ContentSensor::binmodRegex("binmod$");
const int ContentSensor::NO_PHASE=-1;
ContentSensor::ContentSensor()
{
}
void ContentSensor::setContentType(ContentType t)
{
contentType=t;
}
void ContentSensor::setStrand(Strand s)
{
strand=s;
}
ContentSensor *ContentSensor::loadBinary(const BOOM::String &filename)
{
BOOM::File file(filename);
BOOM::String modelType;
file >> modelType;
file.rewind();
if(modelType=="FastMC") return new FastMarkovChain(file);
if(modelType=="Fast3PMC") return new Fast3PMC(file);
throw BOOM::String("Unrecognized model type in ContentSensor::loadBinary(): ")+
modelType;
}
ContentSensor *ContentSensor::load(const BOOM::String &filename)
{
if(binmodRegex.search(filename))
return loadBinary(filename);
ifstream is(filename.c_str());
if(!is.good())
throw BOOM::String("Error opening file ")+filename+
" in ContentSensor::load()";
return load(is);
}
ContentSensor *ContentSensor::load(istream &is)
{
BOOM::String modelType;
is >> modelType;
if(modelType=="MC")
return new MarkovChain(is);
if(modelType=="3P")
return new ThreePeriodicMarkovChain(is);
if(modelType=="IMM")
return new IMM(is);
if(modelType=="3PIMM")
return new ThreePeriodicIMM(is);
/*
if(modelType=="HMM")
return new HiddenMarkovModel(is,alphabet);
if(modelType=="NonstationaryMarkovChain")
return new NonstationaryMarkovChain(is,alphabet);
if(modelType=="CodingPotential")
return new CodingPotential(is,alphabet);
*/
throw BOOM::String("Unrecognized model type in ContentSensor::load(): ")+
modelType;
}
ContentType ContentSensor::getContentType() const
{
return contentType;
}
Strand ContentSensor::getStrand() const
{
return strand;
}
bool ContentSensor::isCoding() const
{
return ::isCoding(contentType);
}
bool ContentSensor::isIntron() const
{
return ::isIntron(contentType);
}
bool ContentSensor::isIntergenic() const
{
return ::isIntergenic(contentType);
}
bool ContentSensor::isUTR() const
{
return ::isUTR(contentType);
}
void ContentSensor::addQueue(SignalQueue *q)
{
signalQueues.insert(q);
}
BOOM::Set<SignalQueue*> &ContentSensor::getSignalQueues()
{
return signalQueues;
}
void ContentSensor::computeScores(const Sequence &seq,Array1D<double> &scores)
{
String str=seq(PureDnaAlphabet::global());
int L=str.length();
scores.resize(L);
for(int i=0 ; i<L ; ++i)
scores[i]=scoreSingleBase(seq,str,i,seq[i],str[i]);
}
void ContentSensor::computeScores(const Sequence &seq,Array1D<double> &phase0,
Array1D<double> &phase1,
Array1D<double> &phase2)
{
String str=seq(PureDnaAlphabet::global());
int L=str.length();
phase0.resize(L); phase1.resize(L); phase2.resize(L);
for(int i=0 ; i<L ; ++i)
scoreSingleBase(seq,str,i,seq[i],str[i],phase0[i],phase1[i],phase2[i]);
}