-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathAlignment.h
More file actions
230 lines (190 loc) · 5.76 KB
/
Alignment.h
File metadata and controls
230 lines (190 loc) · 5.76 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
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
//////////////////////////////////////////////////////////////////////////////////
//
// STAMP version 1.3
//
// Written By: Shaun Mahony
//
// Alignment.h
//
// Started: 31st Oct 2005
//
// Copyright 2007-2015 Shaun Mahony
//
// This file is part of STAMP.
//
// STAMP 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.
//
// STAMP 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 STAMP; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
////////////////////////////////////////////////////////////////////////////////////
#ifndef ALIGN_MARK
#define ALIGN_MARK
//Includes
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include "Motif.h"
#include "ColumnComp.h"
#include "globals.h"
//Cell struct
struct AlignMatCell{
public:
double M;
double Ix;
double Iy;
double max;
int point_i;
int point_j;
};
//Alignment record
class AlignRec{
private:
int alignL;
int numAligned;
public:
int** alignSection;
int i1;
int i2;
bool forward1;
bool forward2;
double score;
double z_score;
double p_value;
double dist;
char** alignedNames;
int* alignedIDs;
//Constructor
AlignRec(int nA=2, int aL=0);
//Accessors
int GetAlignL(){return alignL;}
int GetNumAligned(){return numAligned;}
//Copy the alignment section
void CopyAlignSec(int** AS, int aL, int nA=2);
//Destructor
~AlignRec(){if(alignSection!=NULL){
for(int i=0; i<numAligned; i++){
delete [] alignSection[i];
delete [] alignedNames[i];
}delete [] alignSection;
delete [] alignedNames;
delete [] alignedIDs;
}}
};
//Alignment record
class MultiAlignRec{
private:
int alignL;
int numAligned;
public:
Motif** profileAlignment;
char** alignedNames;
int* alignedIDs;
bool* alignedRC; // Tracks whether each motif was reverse-complemented relative to input
//Constructor
MultiAlignRec(int nA=2, int aL=0);
//Accessors
int GetAlignL(){return alignL;}
int GetNumAligned(){return numAligned;}
//Destructor
~MultiAlignRec(){
for(int i=0; i<numAligned; i++){
delete profileAlignment[i];
}delete [] profileAlignment;
for(int k=0; k<numAligned; k++)
delete [] alignedNames[k];
delete [] alignedNames;
delete [] alignedIDs;
delete [] alignedRC;
}
};
//Alignment method
class Alignment
{
protected:
double gapOpen;
double gapExtend;
int alignLen;
bool alignForward;
double alignScore;
ColumnComp* Metric;
bool overlapOnly;
bool extendOverlap;
bool forwardAlignOnly;
int** alignSectionTmp;
//Helper methods
double Info(double* col);
public:
//The alignment section
int** alignSection;
//Constructor
Alignment(ColumnComp* c, double gO = DFLT_GAP_OPEN, double gE = DFLT_GAP_EXTEND, bool overlap = false, bool extend=false, bool forwardonly=false);
//Accessors
int GetAlignLen(){return alignLen;}
//Align
virtual double AlignMotifs(Motif* one, Motif* two, int &i1, int &i2, int& alignL, bool& forward)=0;
//Two sweeps of AlignMotifs
double AlignMotifs2D(Motif* one, Motif* two, int &i1, int &i2, int& alignL, bool& forward1, bool& forward2);
//Print the current alignment section
void PrintAlignmentConsensus(Motif* one, Motif* two);
//Copy the current alignment section to provided strings
void CopyAlignmentConsensus(Motif* one, Motif* two, char* str_one, char* str_two);
//Trim edges of a motif
Motif* TrimEdges(Motif* in, int &start_offset, int &stop_offset, int minLen=IC_win_len, bool allowExclusive=false);
//Destructor
virtual ~Alignment(){for(int i=0; i<2; i++){delete alignSection[i];delete alignSectionTmp[i];} delete alignSection;delete alignSectionTmp;};
};
//Smith-Waterman Alignment
class SmithWaterman : public Alignment
{
public:
//Constructor
SmithWaterman(ColumnComp* c, double gO = DFLT_GAP_OPEN, double gE = DFLT_GAP_EXTEND, bool overlap=false, bool extend=false, bool forwardonly=false):Alignment(c, gO, gE, overlap, extend, forwardonly){}
//Alignment implementation
double AlignMotifs(Motif* one, Motif* two, int &i1, int &i2, int& alignL, bool& forward);
//Destructor
~SmithWaterman(){}
};
//Smith-Waterman Alignment with affine gap cost
class SmithWatermanAffine : public Alignment
{
public:
//Constructor
SmithWatermanAffine(ColumnComp* c, double gO = DFLT_GAP_OPEN, double gE = DFLT_GAP_EXTEND, bool overlap=false, bool extend=false, bool forwardonly=false):Alignment(c, gO, gE, overlap, extend, forwardonly){}
//Alignment implementation
double AlignMotifs(Motif* one, Motif* two, int &i1, int &i2, int& alignL, bool& forward);
//Destructor
~SmithWatermanAffine(){}
};
//Smith-Waterman Alignment with affine gap cost
class NeedlemanWunsch : public Alignment
{
public:
//Constructor
NeedlemanWunsch(ColumnComp* c, double gO = DFLT_GAP_OPEN, double gE = DFLT_GAP_EXTEND, bool overlap=true, bool extend=false, bool forwardonly=false):Alignment(c, gO, gE, true, false, forwardonly){}
//Alignment implementation
double AlignMotifs(Motif* one, Motif* two, int &i1, int &i2, int& alignL, bool& forward);
//Destructor
~NeedlemanWunsch(){}
};
//Smith-Waterman Alignment with affine gap cost
class SmithWatermanUngappedExtended : public Alignment
{
public:
//Constructor
SmithWatermanUngappedExtended(ColumnComp* c, bool forwardonly=false):Alignment(c, 0, 0, false, true, forwardonly){}
//Alignment implementation
double AlignMotifs(Motif* one, Motif* two, int &i1, int &i2, int& alignL, bool& forward);
//Destructor
~SmithWatermanUngappedExtended(){}
};
#endif