-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProteinCleaner.cpp
More file actions
162 lines (142 loc) · 2.92 KB
/
ProteinCleaner.cpp
File metadata and controls
162 lines (142 loc) · 2.92 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
// ProteinCleaner.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
using namespace std;
bool Find(string str, string piece)
{
int L = piece.size();
if (str.size() > piece.size())
{
for (int i = 0; i <= str.size() - L; i++)
{
string text = str.substr(i, L);
if (text == piece)
{
return true;
}
}
}
return false;
}
class CSVRow
{
private:
std::vector<std::string> m_data;
public:
std::string const& operator[](std::size_t index) const
{
return m_data[index];
}
std::size_t size() const
{
return m_data.size();
}
void readNextRow(std::istream& str)
{
std::string line;
std::getline(str, line);
std::stringstream lineStream(line);
std::string cell;
m_data.clear();
while (std::getline(lineStream, cell, ','))
{
m_data.push_back(cell);
}
// This checks for a trailing comma with no data after it.
if (!lineStream && cell.empty())
{
// If there was a trailing comma then add an empty element.
m_data.push_back("");
}
}
};
std::istream& operator>>(std::istream& str, CSVRow& data)
{
data.readNextRow(str);
return str;
}
int main()
{
vector <string> titles;
string hold;
vector <string> names;
vector <string> ColNames;
CSVRow row;
string str;
vector <int> PathwayBank;
vector <vector <double> > Data;
string name;
cout << "What is the name of your file." << endl;
cin >> name;
name += ".csv";
ifstream Microarray_Genes(name);
cout << "How many data columns?" << endl;
int j = 0;
cin >> j;
Data.resize(j);
int count = 0;
cout << "Start" << endl;
if (Microarray_Genes.is_open())
{
while (Microarray_Genes >> row)
{
if (count == 0)
{
for (int i = 0; i <= Data.size(); i++)
{
ColNames.push_back(row[i]);
}
}
if (count > 0)
{
string s = "GN=";
cout << count << endl;
int i = 0;
while (!Find(row[i], s))
{
i++;
}
stringstream ss(row[i]);
getline(ss, hold, '=');
getline(ss, hold, '=');
getline(ss, hold, ' ');
transform(hold.begin(), hold.end(), hold.begin(), toupper);
names.push_back(hold);
for (int k = 0; k < Data.size(); k++)
{
Data[k].push_back(stod(row[i + 1 + k]));
}
}
count++;
}
Microarray_Genes.close();
}
//Write into a csv file
cout << "What would you like to name your file?" << endl;
cin >> name;
name += ".csv";
ofstream myfile(name);
for (int i = 0; i < ColNames.size(); i++)
{
if (i < ColNames.size() - 1)
{
myfile << ColNames[i] << ",";
}
else
{
myfile << ColNames[i] << endl;
}
}
for (int i = 0; i < names.size(); i++)
{
myfile << names[i] << ",";
for (int j = 0; j < Data.size(); j++)
{
myfile << Data[j][i] << ",";
}
myfile << endl;
}
myfile.close();
cout << "Done!" << endl;
return 0;
}