-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileData.cpp
More file actions
92 lines (61 loc) · 1.99 KB
/
FileData.cpp
File metadata and controls
92 lines (61 loc) · 1.99 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
#include "filedata.h"
#include <fstream>
#include <sstream>
FileData::FileData()
{
}
bool FileData::readData(std::string fileName){
/*This function opens a file and reads it into three vectors for x, y, and p values.
* It is used for the inital data upload, and then the data is used for plotting the scatterplot
* and heatmaps.
*/
//clears the three vectors in case they had been used before
xCoordinates.clear();
yCoordinates.clear();
pValues.clear();
//opens the file
std::ifstream coordinates;
coordinates.open(fileName);
if(coordinates.fail()){return false;}; //in case the file is not found
std::string line = "";
//reads and parses the file datapoint by datapoint into the vectors
while(getline(coordinates, line)){
std::stringstream s(line);
getline(s, x, ',');
getline(s, y, ',');
getline(s, p);
double xx = atof(x.c_str());
double yy = atof(y.c_str());
double pp = atof(p.c_str());
xCoordinates.push_back(xx);
yCoordinates.push_back(yy);
pValues.push_back(pp);
x="";
y="";
p="";
line="";
}
coordinates.close();
return true;
}
bool FileData::readGenes(std::string fileName){
/*This function opens a file and reads it into one vector with the names of the genes to analyze.
* It is used in the colocalization window, because the user will upload a file with the genes
* that they want to analyze. This function handles the parsing of that file.
*/
genesToAnalyze.clear();
std::ifstream genes;
genes.open(fileName);
if(genes.fail()){return false;}; //in case the file is not found
std::string line = "";
//reads and parses the file gene by gene into the vector
while(getline(genes, line)){
std::stringstream s(line);
getline(s, g, ',');
genesToAnalyze.push_back(g);
g="";
line="";
}
genes.close();
return true;
}