-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main_Header.h
220 lines (200 loc) · 3.56 KB
/
Main_Header.h
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
#ifndef MAIN_HEADER_H
#define MAIN_HEADER_H
#endif
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <string.h>
using namespace std;
class Main_Data{
public:
char** head;
char** dataseq;
int noflines;
string filepath;
ifstream input;
Main_Data(){
cout<< "constructor called"<< endl;
}
Main_Data(string fp){
filepath=fp;
input.open(filepath.c_str());
}
void read(int no_lines){
noflines=no_lines;
head=new char*[no_lines];
dataseq= new char*[no_lines];
for(int i=0;i<=no_lines;i++){
head[i]=new char[50];
dataseq[i]=new char[50];
}
for(int i=0;i<=no_lines;i++){
input>>head[i];
input>>dataseq[i];
}
}
int strcmps(char *p, char*q){
for(int i=0;i<50;i++){
if(p[i]-q[i]>0){
return 1;
}
else if (p[i]-q[i]<0){
return -1;
}
else{
continue;
}
}
return 1;
}
void merge_sort(char *arr[], int a, int b, int c)
{
int x, y, z;
int f1 = b - a + 1;
int f2 = c - b;
char *left[f1];
char *right[f2];
for (x = 0; x < f1; x++)
left[x] = arr[a + x];
for (y = 0; y < f2; y++)
right[y] = arr[b + 1+ y];
x = 0;
y = 0;
z = a;
while (x < f1 && y < f2)
{
if (strcmps(left[x],right[y])<0)
{
arr[z] = left[x];
x++;
}
else
{
arr[z] = right[y];
y++;
}
z++;
}
while (x < f1)
{
arr[z] = left[x];
x++;
z++;
}
while (y < f2)
{
arr[z] = right[y];
y++;
z++;
}
}
void my_merge_sort(char *arr[], int a, int c)
{
if (a < c)
{
int b = a+(c-a)/2;
my_merge_sort(arr, a, b);
my_merge_sort(arr, b+1, c);
merge_sort(arr, a, b, c);
}
}
void sort_data(){
cout << "sorting started" << endl;
my_merge_sort(dataseq,0,noflines-1);
cout << "after sorting" << endl;
for(int i=0;i<20;i++){
cout << dataseq[i] << endl;
}
}
void compute_statistics()
{
no_char_cnt();
no_reads();
unique_sequence_count();
}
void no_char_cnt(){
int counta=0;
int countc=0;
int countg=0;
int countt=0;
for(int i=0;i<noflines;i++)
{
for(int j=0;j<50;j++)
{
if(dataseq[i][j]=='A')
counta++;
else if(dataseq[i][j]=='C')
countc++;
else if(dataseq[i][j]=='G')
countg++;
else if(dataseq[i][j]=='T')
countt++;
else{
int n=0;
n++;
}
}
}
cout << "A:"<<counta << endl;
cout << "C:"<<countc << endl;
cout << "G:"<<countg << endl;
cout << "T:"<<countt << endl;
}
void no_reads()
{
cout << "entered read:" << endl;
int outarr[14] = {0};
for(int i=0;i<noflines;i++)
{
int l=0;
int j=0;
int cnt = 11;
while(cnt != 0){
if(head[i][j] == '_'){
j= j + 1;
break;
}
cnt--;
j++;
}
int c = 0;
for(int k = 0; k < 28;k++){
if(head[i][j] != '_'){
outarr[c] = outarr[c] + (int)head[i][j] - '0';
c++;
}
j++;
}
}
for(int t = 0 ; t < 14; t++)
{
cout <<" = > Data_Set " << t+1 << "is : " << outarr[t] << endl;
}
}
void unique_sequence_count(){
int counter;
int final_counter = 0;
for(int seq = 0 ; seq < noflines ; seq++){
for(int i = 0; i <= seq ; i++){
counter=0;
for(int j = 0 ; j < 50 ; j++){
if(dataseq[seq][j] == dataseq[i][j]){
counter+=1;
}
}
if(counter == 50){
final_counter++;
}
}
}
cout << "Unique seq coun: " << final_counter << endl;
}
void delete_my_array(){
cout << "Array deleted sucessfully" << endl;
}
~Main_Data(){
delete[] head;
delete[] dataseq;
delete_my_array();
}
};