-
Notifications
You must be signed in to change notification settings - Fork 0
/
FunctionalParse.C
151 lines (110 loc) · 2.77 KB
/
FunctionalParse.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
/****************************************************************
FunctionalParse.C
william.majoros@duke.edu
This is open-source software, governed by the Gnu General Public License (GPL) version 3
(see www.opensource.org).
****************************************************************/
#include <iostream>
#include "FunctionalParse.H"
#include "BranchHMM.H"
#include "Taxon.H"
using namespace std;
using namespace BOOM;
FunctionalParse::FunctionalParse()
: taxon(NULL)
{
// ctor
}
FunctionalParse::FunctionalParse(const StatePath &path,BranchEnd branchEnd)
: taxon(NULL)
{
PairHMM *hmm=path.getHMM();
if(!hmm) throw "NULL hmm in StatePath";
BranchHMM *bhmm=dynamic_cast<BranchHMM*>(hmm);
if(!bhmm) throw "Attempt to get functional parse from non-BranchHMM";
int L=path.length();
for(int i=0 ; i<L ; ++i) {
STATE s=path[i];
bool keep;
switch(hmm->getStateType(s))
{
case PHMM_MATCH:
keep=true;
break;
case PHMM_INSERT:
keep=(branchEnd==CHILD);
break;
case PHMM_DELETE:
keep=(branchEnd==PARENT);
break;
default:
keep=false;
break;
}
if(keep) parse.push_back(bhmm->getFunctionalClass(s,branchEnd));
}
}
int FunctionalParse::length() const
{
return size();
}
int FunctionalParse::size() const
{
return parse.size();
}
void FunctionalParse::push_back(FunctionalClass c)
{
parse.push_back(c);
}
void FunctionalParse::clear()
{
parse.clear();
}
FunctionalClass FunctionalParse::operator[](int i) const
{
if(i>=parse.size())
throw String("FunctionalParse::operator[] : out of bounds: ")+i;
return parse[i];
}
FunctionalClass &FunctionalParse::operator[](int i)
{
if(i>=parse.size())
throw String("FunctionalParse::operator[] : out of bounds: ")+i;
return parse[i];
}
void FunctionalParse::resize(int x)
{
parse.resize(x);
}
void FunctionalParse::printOn(ostream &os)
{
int L=size();
//cout<<"L="<<L<<endl; for(int i=0 ; i<L ; ++i) os<<i<<" "<<parse[i].getLabel()<<endl;//###
for(int i=0 ; i<L ; ++i)
os<<parse[i].getLabel();
}
ostream &operator<<(ostream &os,const FunctionalParse &phi)
{
phi.printOn(os);
return os;
}
Array1D<FunctionalElement> *FunctionalParse::getElements()
{
Vector<FunctionalElement> elements;
int L=parse.size();
FunctionalElementType currentType=FunctionalElementType::NO_FUNC_ELEM;
int begin;
for(int i=0 ; i<L ; ++i) {
FunctionalElementType t=parse[i].getElementType();
if(t!=currentType) {
if(t.isValid()) begin=i;
else elements.push_back(FunctionalElement(currentType,begin,i,
currentType.getStrand(),
taxon));
//else elements.push_back(FunctionalElement(currentType,begin,i,
// FORWARD_STRAND,taxon));
currentType=t;
}
}
return new Array1D<FunctionalElement>(elements);
}