-
Notifications
You must be signed in to change notification settings - Fork 0
/
Output.cpp
130 lines (117 loc) · 3.97 KB
/
Output.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
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
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include "Config.h"
#include "Node.h"
#include "Output.h"
Output::Output(Config input) {
Parameters = input;
}
Output::~Output() {
}
void Output::OutputAlignment(double Profile, vector<Node> Original, vector<Node> Aligned, vector<string> OutputOrder) {
if(Parameters.getOutputType() == 1) {
OutputStandard(Original, Aligned, OutputOrder);
}
else if(Parameters.getOutputType() == 2) {
OutputTree(Original, Aligned, OutputOrder);
}
OutputSHIFT(Profile, Aligned, OutputOrder);
}
void Output::OutputStandard(vector<Node> Original, vector<Node> Aligned, vector<string> OutputOrder) {
ofstream ALIGN(Parameters.getOutputFile().c_str());
cout << "Outputing Final Alignment...\n";
for (int x = 0; x < (int)Original.size(); x++) {
for (int z = 0; z < (int)Original.size(); z++) {
if (Original[z].getName().compare(OutputOrder[x]) == 0) {
double* Region = new double[Parameters.getSlidingWindow()];
for(int a = 0; a < (int)Aligned.size(); a++) {
if (Aligned[a].getName().compare(Original[z].getName()) == 0) {
loadarray(Original, Region, Aligned[a].getShift(), z, Aligned[a].getRev());
ALIGN << Original[z].getName()<<"\t";
for (int y = 0; y < Parameters.getSlidingWindow(); y++) {
ALIGN << Region[y];
if (y + 1 == Parameters.getSlidingWindow()) {
ALIGN << "\n";
} else {
ALIGN << "\t";
}
}
delete[] Region;
}
}
}
}
}
cout << "Complete\n";
ALIGN.close();
}
void Output::OutputTree(vector<Node> Original, vector<Node> Aligned, vector<string> OutputOrder) {
ofstream ALIGN(Parameters.getOutputFile().c_str());
cout << "Outputing Final Alignment...\n";
ALIGN<<"YORF\tNAME\tGWEIGHT\t";
for(int x = 0; x < Parameters.getSlidingWindow(); x++) {
ALIGN<<x;
if(x + 1 == Parameters.getSlidingWindow()) { ALIGN<<endl; }
else { ALIGN<<"\t"; }
}
for (int x = 0; x < (int)Original.size(); x++) {
for (int z = 0; z < (int)Original.size(); z++) {
if (Original[z].getName().compare(OutputOrder[x]) == 0) {
double* Region = new double[Parameters.getSlidingWindow()];
for(int a = 0; a < (int)Aligned.size(); a++) {
if (Aligned[a].getName().compare(Original[z].getName()) == 0) {
loadarray(Original, Region, Aligned[a].getShift(), z, Aligned[a].getRev());
ALIGN << Original[z].getName()<<"\t"<<Original[z].getName()<<"\t"<<1<<"\t";
for (int y = 0; y < Parameters.getSlidingWindow(); y++) {
ALIGN << Region[y];
if (y + 1 == Parameters.getSlidingWindow()) {
ALIGN << "\n";
} else {
ALIGN << "\t";
}
}
delete[] Region;
}
}
}
}
}
cout << "Complete\n";
ALIGN.close();
}
void Output::OutputSHIFT(double Profile, vector<Node> Aligned, vector<string> OutputOrder) {
ofstream SHIFT(Parameters.getOutputCoordFile().c_str());
cout<<"Outputing Shifted Coordinates...\n";
SHIFT << "Average Pearson Profile:\t" << Profile << "\n";
for (int x = 0; x < (int)Aligned.size(); x++) {
for (int y = 0; y < (int)Aligned.size(); y++) {
if (Aligned[y].getName().compare(OutputOrder[x]) == 0) {
SHIFT << Aligned[y].getName() <<"\t"<< Aligned[y].getShift() << "\t";
if (Aligned[y].getRev()) {
SHIFT << "Rev\n";
} else {
SHIFT << "NA\n";
}
}
}
}
cout<<"Complete\n";
SHIFT.close();
}
void Output::loadarray(vector<Node> & Original, double currentregion[], int windowstart, int currentindex, bool reversal) {
vector<double> tempseq = Original[currentindex].getSeq();
if (!reversal) {
for (int x = windowstart; x < (windowstart + Parameters.getSlidingWindow()); x++) {
currentregion[x - windowstart] = tempseq[x];
}
} else {
int index = 0;
for (int x = (windowstart + Parameters.getSlidingWindow() - 1); x >= windowstart; x--) {
currentregion[index] = tempseq[x];
index++;
}
}
tempseq.clear();
}