Skip to content

Commit aa9e5b1

Browse files
src/radmeth/radmeth_model.cpp: parsing initial part of rowname as just one field 'rowname' but with parts separated by colons converted to tabs in the output; previous behavior retained but rownames without colons will be allowed and retained in the output
1 parent 75abcdc commit aa9e5b1

File tree

1 file changed

+4
-37
lines changed

1 file changed

+4
-37
lines changed

src/radmeth/radmeth_model.cpp

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -33,45 +33,12 @@ SiteProp::parse(const std::string &line) {
3333
const auto first_ws = line.find_first_of(" \t");
3434

3535
// Parse the row name (must be like: "chr:position:strand:context")
36-
bool failed = false;
36+
bool failed = (first_ws == std::string::npos);
3737

38-
const auto label_end = line.data() + first_ws;
3938
auto field_s = line.data();
40-
auto field_e = std::find(field_s + 1, label_end, ':');
41-
if (field_e == label_end)
42-
failed = true;
43-
44-
{
45-
const std::uint32_t d = std::distance(field_s, field_e);
46-
chrom = std::string{field_s, d};
47-
}
48-
49-
field_s = field_e + 1;
50-
field_e = std::find(field_s + 1, label_end, ':');
51-
failed = failed || (field_e == label_end);
52-
53-
{
54-
const auto [ptr, ec] = std::from_chars(field_s, field_e, position);
55-
failed = failed || (ptr == field_s);
56-
}
57-
58-
field_s = field_e + 1;
59-
field_e = std::find(field_s + 1, label_end, ':');
60-
failed = failed || (field_e != field_s + 1 || field_e == label_end);
61-
62-
strand = *field_s;
63-
failed = failed || (strand != '-' && strand != '+');
64-
65-
field_s = field_e + 1;
66-
field_e = std::find_if(field_s + 1, label_end,
67-
[](const auto x) { return x == ' ' || x == '\t'; });
68-
failed = failed || (field_e != label_end);
69-
70-
{
71-
const std::uint32_t d = std::distance(field_s, field_e);
72-
context = std::string{field_s, d};
73-
}
74-
39+
auto field_e = line.data() + first_ws;
40+
rowname = std::string{field_s, field_e};
41+
std::replace(std::begin(rowname), std::end(rowname), ':', '\t');
7542
if (failed)
7643
throw std::runtime_error("failed to parse label from:\n" + line);
7744

0 commit comments

Comments
 (0)