14 vector<size_t> idx(v.size());
15 iota(idx.begin(), idx.end(), 0);
18 sort(idx.begin(), idx.end(),
19 [&v](
size_t i1,
size_t i2) {return v[i1] > v[i2];});
28 ifstream mtxfile (fname);
33 vector<int64_t> mclorder;
34 if (mtxfile.is_open())
36 while(mtxfile.peek()==
'%') getline (mtxfile,line);
37 mtxfile >> m >> n >> nnz;
39 vector<bool> nonisolated (m,
false);
41 while( mtxfile >> v1 >> v2 >> val)
43 if(!nonisolated[v1]) {nonisolated[v1] =
true; count++;}
44 if(!nonisolated[v2]) {nonisolated[v2] =
true; count++;}
49 cout <<
"vertices: " << m <<
" and non isolated vertices: " << count << endl;
52 mclorder.resize(count);
53 for(
int64_t i=0, j=0; i<m ; i++)
67 ifstream infile (ifname);
70 vector<vector<int64_t>> clusters;
73 infile >> item >> clustID;
74 while(infile >> item >> clustID)
76 nclust = max(nclust, clustID+1);
77 if(clustID >= clusters.size())
79 clusters.resize(clustID * 2 + 1);
81 clusters[clustID].push_back(item);
87 cout <<
"Unable to open " << ifname << endl;
91 cout <<
"Number of clusters from HipMCL: " << nclust << endl;
96 vector<int64_t> clustSize(nclust, 0);
97 for(
int64_t i=0; i< nclust; i++)
98 clustSize[i] = clusters[i].
size();
100 if (outfile.is_open())
102 for(
int64_t i=0; i<nclust; i++)
105 for(
uint64_t j=0; j<clusters[cl].size() ; j++)
107 outfile << clusters[cl][j] <<
"\t";
113 else cout <<
"Unable to open " <<
ofname << endl;
117 if (outfile.is_open())
119 for(
int64_t i=0; i<nclust; i++)
121 for(
uint64_t j=0; j<clusters[i].size() ; j++)
123 outfile << clusters[i][j] <<
"\t";
129 else cout <<
"Unable to open " <<
ofname << endl;
136int main(
int argc,
char* argv[])
139 string ifilename =
"";
140 string ofilename =
"";
141 string sort =
"revsize";
143 cout <<
"Reformatting HipMCL output to MCL format.....\n";
146 cout <<
"Usage: ./mclconvert -M <IN_FILENAME> -o <OUT_FILENAME>(required)\n";
147 cout <<
"-sort <Sort clusters by their sizes> (default:revsize)\n";
148 cout <<
"Example: ./mclconvert -M input.mtx" << endl;
152 for (
int i = 1; i < argc; i++)
154 if (strcmp(argv[i],
"-M")==0)
156 ifilename = string(argv[i+1]);
157 printf(
"Input filename: %s",ifilename.c_str());
159 else if (strcmp(argv[i],
"-o")==0)
161 ofilename = string(argv[i+1]);
162 printf(
"Output filename: %s",ofilename.c_str());
164 else if (strcmp(argv[i],
"-sort")==0)
166 sort = string(argv[i + 1]);
167 printf(
"\nSorting clusters by their size (revsize or none)? :%s",sort.c_str());
171 convert(ifilename, ofilename, sort);