-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdoublemap.cpp
89 lines (74 loc) · 2.58 KB
/
doublemap.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
/*
This file has a simple functionality as well.
1. It takes in the output files from the filtering program as inputs.
2. It creates an adjacency matrix out of each pair in a file.
Example: if there are 4 entries in the first file, it will create 1 node of each entry (and hence a 4 node, complete graph).
If it encounters another file with 2 entries that are the same above, then two edges will increase in weight. If the entries
are not in the first file, then 2 new nodes will be created. Its remarkably simple actually.
*/
//Include the libraries
#include <algorithm>
#include <vector>
#include <iostream>
#include <string>
#include <fstream>
#include <boost/algorithm/string.hpp>
#include <ctime>
#include <map>
using namespace std;
//Function to add strings to a vector from an ifstream
void add_to_vector(std::ifstream &reference_file, std::vector<std::string> &vect) {
std::string str;
while (std::getline(reference_file, str)) {
vect.push_back(str);
}
return;
}
int main()
{
//A unique data structure. Its a 2D array, where each array element is accessed by a string rather than an integer
std::map <std::string, std::map <std::string, unsigned int> > map;
//create vector out of the brain structure names
vector<string> vect;
std::ifstream names("inputfiles/test_brain_names.txt");
add_to_vector(names, vect);
//initialize the matrix
for (uint64_t i=0; i<vect.size(); ++i) {
for (uint64_t j=0; j<vect.size(); ++j) {
map[vect[i]][vect[j]] = 0;
}
}
//create vector of file names
vector<string> file_names;
std::ifstream filenames_stream("inputfiles/processed_file_names.txt");
add_to_vector(filenames_stream, file_names);
filenames_stream.close();
//update the map if there are pairs
for (uint64_t i=0; i<file_names.size(); ++i) {
//Read in the file
std::ifstream val("inputfiles/datafiles/"+file_names[i]);
//Create a vector for the input file that has the nodes
vector<string> values;
//Add the strings to the vector
add_to_vector(val, values);
for (uint64_t j=0; j<values.size()-1; ++j) {
for (uint64_t k=j+1; k<values.size(); ++k) {
++map[values[j]][values[k]];
++map[values[k]][values[j]];
}
}
val.close();
}
ofstream out("output.csv");
//print it out to a csv file
for (uint64_t i=0; i<vect.size(); ++i) {
for (uint64_t j=0; j<vect.size(); ++j) {
cout<<map[vect[i]][vect[j]]<<" ";
out<<map[vect[i]][vect[j]]<<",";
}
cout<<" "<<endl;
out<<","<<endl;
}
out.close();
return 0;
}