COMBINATORIAL_BLAS 1.6
 
Loading...
Searching...
No Matches
mer_to_graph.cpp
Go to the documentation of this file.
1#include <iostream>
2#include <string>
3#include <fstream>
4#include <sstream>
5#include <vector>
6#include <algorithm>
7#include <chrono>
8#include <functional>
9#include <cmath>
10#include <map>
11#include <tuple>
12#include <cstdlib>
13#include <cstdio>
14#include <limits>
15#include <cassert>
16
17using namespace std;
18
19map<string, int> vertexmap;
21
22
23void ParseSplint(string locline, uint32_t & vertexid, ofstream & out)
24{
25 string name;
26 string splint;
27 std::tuple<string, string, int64_t> triple;
28
29 stringstream ssline(locline);
30 ssline >> name;
31 assert((name == "SPLINT") || (name == "SPAN") );
32 ssline >> splint;
33 vector<string> contigpair(2);
34 size_t pos = splint.find("<=>");
35 contigpair[1] = splint.substr(pos+3);
36 contigpair[0] = splint.substr(0, pos);
37
38 pos = contigpair[0].find(".");
39 contigpair[0] = contigpair[0].substr(0,pos);
40 pos = contigpair[1].find(".");
41 contigpair[1] = contigpair[1].substr(0,pos);
42
43 auto ret = vertexmap.insert(make_pair(contigpair[0], vertexid));
44
45 if (ret.second) // successfully inserted
46 ++vertexid;
47
48 get<0>(triple) = ret.first->first;
49 ret = vertexmap.insert(make_pair(contigpair[1], vertexid));
50 if (ret.second) ++vertexid;
51
52 get<1>(triple) = ret.first->first;
53 get<2>(triple) = 1;
54
55 out << get<0>(triple) << "\t" << get<1>(triple) << "\t" << get<2>(triple) << "\n";
56 numlines++;
57}
58
59int main(int argc, char* argv[])
60{
61 if(argc < 4)
62 {
63 cout << "Usage: ./mer2gr <splint_file> <kmer_file> <span_file" << endl;
64 return 0;
65 }
66
67 numlines = 0;
68 uint32_t vertexid = 0;
69 string locline;
70 ofstream out("contig_graph.txt");
71
72 ifstream input1(argv[1]);
73 while(getline(input1,locline))
74 {
75 ParseSplint(locline, vertexid, out);
76 }
77 input1.close();
78
79 ifstream input2(argv[2]);
80 while(getline(input2,locline))
81 {
82 ParseSplint(locline, vertexid, out);
83 }
84 input2.close();
85
86 ifstream input3(argv[3]);
87 while(getline(input3,locline))
88 {
89 ParseSplint(locline, vertexid, out);
90 }
91 input3.close();
92
93
94 ofstream dictout("vertex_dict.txt");
95 int max = 0;
96 for (auto it = vertexmap.begin(); it != vertexmap.end(); ++it)
97 {
98 max = std::max(max, it->second);
99 dictout << it ->first << endl;
100 }
101 cout << (max+1) << "\t" << (max+1) << "\t" << numlines << endl;
102 dictout.close();
103
104}
int main()
Definition Driver.cpp:12
void ParseSplint(string locline, uint32_t &vertexid, ofstream &out)
uint32_t numlines
map< string, int > vertexmap
unsigned int uint32_t
Definition stdint.h:80