Skip to content

Commit

Permalink
#2331 - System should throw an error in case of wrong IUBcode
Browse files Browse the repository at this point in the history
Fix code. Add UT.
  • Loading branch information
AliaksandrDziarkach committed Oct 17, 2024
1 parent 13d2d36 commit 1810087
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions api/tests/integration/ref/formats/idt_to_ket.py.out
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ idt_unresolved.ket:SUCCEED
idt_unresolved_many.ket:SUCCEED
idt_unsplit.ket:SUCCEED
Test '!+A-$#12w12r23e32e33': got expected error 'Invalid symbols in the sequence: !,-,$,#,1,2,w,1,2,2,3,e,3,2,e,3,3'
Test '(YY:00330067)': got expected error 'Invalid mixed base - only numerical index allowed.'
Test '+/5Phos/A': got expected error 'Sugar prefix could not be used with modified monomer.'
Test '/': got expected error 'Unexpected end of data'
Test '//': got expected error 'Invalid modification: empty string.'
Expand Down
1 change: 1 addition & 0 deletions api/tests/integration/tests/formats/idt_to_ket.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def find_diff(a, b):
"/52MOErA//32MOErA/*": "Monomer /32MOErA/ doesn't have phosphate, so '*' couldn't be applied.",
"/3Phos/*": "Symbol '*' could be placed only between two nucleotides/nucleosides.",
"r(B1:50003000)(B1)": "Unknown mixed base 'B1'",
"(YY:00330067)": "Invalid mixed base - only numerical index allowed.",
}
for idt_seq in sorted(idt_errors.keys()):
error = idt_errors[idt_seq]
Expand Down
15 changes: 15 additions & 0 deletions core/indigo-core/molecule/src/sequence_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1081,17 +1081,32 @@ void SequenceLoader::loadIdt(KetDocument& document)
if (mixed_base.back() == ')')
{
mixed_base = idt_alias.substr(1, idt_alias.size() - 2);
auto check_mixed_base = [](const std::string& base) {
if (base.size() < 2)
return;
auto count = base.substr(1, base.size() - 1);
for (auto ch : count)
{
if (!std::isdigit(ch))
throw Error("Invalid mixed base - only numerical index allowed.");
}
};
if (auto pos = mixed_base.find(':'); pos != std::string::npos)
{
auto ratios_str = mixed_base.substr(pos + 1, mixed_base.size() - pos - 1);
mixed_base = mixed_base.substr(0, pos);
check_mixed_base(mixed_base);
if (ratios_str.size() != 8)
throw Exception("Invalid IDT variant monomer %s", idt_alias.c_str());
ratios.emplace(std::array<float, 4>{std::stof(ratios_str.substr(0, 2)), std::stof(ratios_str.substr(2, 2)),
std::stof(ratios_str.substr(4, 2)), std::stof(ratios_str.substr(6, 2))});
idt_alias = '(' + mixed_base + ')';
mixed_base = mixed_base[0];
}
else
{
check_mixed_base(mixed_base);
}
}
if (sugar == "R" && RNA_DNA_MIXED_BASES.count(mixed_base) == 0)
idt_alias = 'r' + idt_alias;
Expand Down

0 comments on commit 1810087

Please sign in to comment.