Repository navigation
Expand file tree
/
Copy pathsfs.cpp
More file actions
105 lines (98 loc) · 2.52 KB
/
Copy pathsfs.cpp
File metadata and controls
105 lines (98 loc) · 2.52 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
#include "sfs.hpp"
std::vector<std::string> split(const std::string &s, char delimiter) {
std::vector<std::string> tokens;
std::string token;
std::istringstream tokenStream(s);
while (std::getline(tokenStream, token, delimiter))
tokens.push_back(token);
return tokens;
}
std::string sfs_to_string(const sfs_t &s, const std::string &v1,
const std::string &v2) {
std::ostringstream oss;
oss << (int)s.flag << "\t" << s.rname << "\t" << s.s << "\t" << s.l << "\t"
<< s.s + s.l << "\t";
if (s.flag == 0) {
oss << s.sv << "\t" << s.ev << "\t" << s.soff << "\t" << s.eoff << "\t"
<< (v1 == "" ? "." : v1) << "\t" << (v2 == "" ? "." : v2) << "\t"
<< s.skmer << "\t" << s.ekmer << "\t";
if (s.paths.size() == 0) {
oss << ".";
} else {
oss << s.paths[0];
for (size_t p = 1; p < s.paths.size(); ++p)
oss << "," << s.paths[p];
}
oss << "\t" << s.plain_seq;
} else {
oss << "."
<< "\t"
<< "."
<< "\t"
<< "."
<< "\t"
<< "."
<< "\t"
<< "."
<< "\t"
<< "."
<< "\t"
<< "."
<< "\t"
<< "."
<< "\t"
<< "."
<< "\t"
<< ".";
}
oss << "\n";
return oss.str();
}
sfs_t read_sfs_line(const std::string &line) {
std::vector<std::string> tokens = split(line, '\t');
sfs_t s;
s.flag = 0;
s.rname = tokens[1];
s.s = std::stoi(tokens[2]);
s.l = std::stoi(tokens[3]);
// s.end = std::stoi(tokens[4]);
//
s.sv = std::stoi(tokens[5]);
s.ev = std::stoi(tokens[6]);
//
s.soff = std::stoi(tokens[7]);
s.eoff = std::stoi(tokens[8]);
//
// GFA identifiers, 9/10
//
s.skmer = std::stoul(tokens[11]);
s.ekmer = std::stoul(tokens[12]);
//
std::vector<std::string> paths = split(tokens[13], ',');
for (const std::string &p : paths)
s.paths.push_back(std::stoi(p));
//
s.plain_seq = tokens[14];
s.seq = (uint8_t *)malloc(s.l + 1);
for (int i = 0; i < s.l; ++i)
s.seq[i] = s.plain_seq[i] < 128 ? to_int[(int)s.plain_seq[i]] - 1 : 4;
s.seq[s.l] = '\0';
return s;
}
std::vector<sfs_t> load_sfs(const std::string &fn) {
std::ifstream fp(fn);
std::string line;
std::vector<sfs_t> specific_strings;
if (!fp.is_open()) {
fprintf(stderr, "Unable to open SFS file!");
return specific_strings;
}
while (getline(fp, line)) {
if (line[0] != '0')
continue;
sfs_t s = read_sfs_line(line);
specific_strings.push_back(s);
}
fp.close();
return specific_strings;
}