-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
132 lines (118 loc) · 2.78 KB
/
Copy pathmain.cpp
File metadata and controls
132 lines (118 loc) · 2.78 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
#include "snp.h"
#include "HashTable.h"
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
#include <stdlib.h>
#include <time.h>
using namespace std;
bool getSNP(ifstream&, snp*&);
string menu(void) {
string input;
cout << endl << "\tENTER MENU SELECTION:" << endl;
cout << "EXIT" << endl;
cout << "SHOW: SEARCH BY RSID" << endl;
cout << "OPEN: OPEN SNP PAGE IN SNPEDIA" << endl;
cout << "RANDOM: PICK RANDOM SNP AND OPEN IN SNPEDIA" << endl;
getline(cin,input);
for(unsigned i = 0; i < input.size(); i++) {
input.at(i) = tolower(input.at(i));
}
return input;
}
int main() {
srand(time(NULL));
HashTable Table = HashTable(50000);
string file = "AncestryDNA.txt";
ifstream input;
input.open(file);
if(!input.is_open()) {
cout << "ERROR OPENING DNA FILE" << endl;
return -1;
}
snp* newSNP;
while(getSNP(input, newSNP)) {
if(newSNP->getRS() != "NULL") {
Table.put(newSNP);
}
if(newSNP->getRSCode() == 869031877) {
break;
}
}
string choice = menu();
string rsid;
int RSCode;
while(choice != "exit") {
if(choice == "show") {
getline(cin,rsid);
while(rsid.size() == 0) {
cout << "ERROR READING RSID, PLEASE ENTER AGAIN" << endl;
getline(cin,rsid);
}
if(rsid.at(0) == 'r') {
newSNP = Table.find(rsid);
} else {
newSNP = Table.find("rs"+rsid);
}
if(newSNP == nullptr) {
cout << "NOT FOUND" << endl;
} else {
newSNP->display();
}
} else if(choice == "open") {
getline(cin,rsid);
if(rsid.at(0) == 'r') {
newSNP = Table.find(rsid);
} else {
newSNP = Table.find("rs"+rsid);
}
if(newSNP == nullptr) {
cout << "NOT FOUND" << endl;
} else {
newSNP->display();
newSNP->openSNPedia();
}
} else if(choice == "random") {
newSNP = Table.getRandom();
if(newSNP == nullptr) {
cout << "ERROR WITH RANDOM SNP" << endl;
} else {
newSNP->display();
newSNP->openSNPedia();
}
} else {
cout << "INVALID CHOICE" << endl;
}
choice = menu();
}
}
bool getSNP(ifstream& in, snp*& node) {
string line;
string inputString;
string rs;
unsigned rsCode;
unsigned chromosome;
unsigned position;
string allele1;
string allele2;
getline(in,line);
if(line.size() == 0 || line.at(0) == '#' || line.at(2) == 'i') {
node = new snp("NULL",0,0,0,"","");
return !in.eof();
}
stringstream currLine(line);
getline(currLine,inputString,'\t');
rs = inputString;
rsCode = (unsigned)stoi(rs.substr(2));
getline(currLine,inputString,'\t');
chromosome = (unsigned)stoi(inputString);
getline(currLine,inputString,'\t');
position = (unsigned)stoi(inputString);
getline(currLine,inputString,'\t');
allele1 = inputString;
getline(currLine,inputString,'\t');
allele2 = inputString;
node = new snp(rs, rsCode, chromosome, position, allele1, allele2);
return !in.eof();
}