Skip to content

Commit

Permalink
added check for same number of double bonds and double bond positions
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominik Kopczynski committed May 20, 2020
1 parent 8054025 commit 675865b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
8 changes: 7 additions & 1 deletion cppgoslin/domain/FattyAcid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ SOFTWARE.

#include "FattyAcid.h"


FattyAcid::FattyAcid(string _name, int _num_carbon, int _num_double_bonds, int _num_hydroxyl, LipidFaBondType _lipid_FA_bond_type, bool _lcb, int _position, map<int, string> *_double_bond_positions){
name = _name;
position = _position;
Expand All @@ -36,6 +35,9 @@ FattyAcid::FattyAcid(string _name, int _num_carbon, int _num_double_bonds, int _
lipid_FA_bond_type = _lipid_FA_bond_type;
lcb = _lcb;
if (_double_bond_positions != NULL){
if (num_double_bonds != (int)_double_bond_positions->size()) {
throw ConstraintViolationException("Isomeric FattyAcid must receive double bond positions for all double bonds! Got " + std::to_string(num_double_bonds) + " double bonds and " + std::to_string(_double_bond_positions->size()) + " positions.");
}
for (auto kv : *_double_bond_positions){
double_bond_positions.insert({kv.first, kv.second});
}
Expand Down Expand Up @@ -110,6 +112,10 @@ string FattyAcid::to_string(bool special_case){
if (special_case && lipid_suffix.length() > 0) s << "O-";
s << num_carbon << ":" << num_double_bonds;

if (double_bond_positions.size() > 0 && num_double_bonds != (int)double_bond_positions.size()) {
throw ConstraintViolationException("Isomeric FattyAcid must receive double bond positions for all double bonds! Got " + std::to_string(num_double_bonds) + " double bonds and " + std::to_string(double_bond_positions.size()) + " positions.");
}

if (double_bond_positions.size()){
stringstream db;
db << "(";
Expand Down
2 changes: 1 addition & 1 deletion cppgoslin/parser/GoslinParserEventHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ void GoslinParserEventHandler::set_isomeric_level(TreeNode* node){

void GoslinParserEventHandler::add_db_position(TreeNode* node){
if (current_fa != NULL){
current_fa->double_bond_positions.insert({db_position, db_cistrans});
current_fa->double_bond_positions.insert({db_position, db_cistrans});
}
}

Expand Down
21 changes: 19 additions & 2 deletions cppgoslin/tests/ParserTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ int main(int argc, char** argv){




// check lipid maps and swiss lipids parser with illegal lipid name
string failLipidSL = "TG(16::1_18:1_24:0)";
try {
Expand Down Expand Up @@ -157,6 +156,7 @@ int main(int argc, char** argv){
assert (lipid->get_sum_formula() == "C42H83NO4");
assert (abs(lipid->get_mass() - 665.632209) < 1e-3);
delete lipid;



lipid = lipid_maps_parser.parse("Cer(d18:1(4E)/24:0(2OH))");
Expand Down Expand Up @@ -194,13 +194,15 @@ int main(int argc, char** argv){
assert (lipid->get_lipid_string() == "PG 22:1(5Z)/12:0");
delete lipid;


lipid_name = "PG(22:1/12:0)";
lipid = swiss_lipids_parser.parse(lipid_name);
assert (lipid);
assert (lipid->lipid->info.level == STRUCTURAL_SUBSPECIES);
assert (lipid->get_lipid_string() == "PG 22:1/12:0");
delete lipid;


lipid_name = "PG(22:1_12:0)";
lipid = swiss_lipids_parser.parse(lipid_name);
assert (lipid);
Expand Down Expand Up @@ -231,7 +233,22 @@ int main(int argc, char** argv){
lipid = lipid_parser.parse(lipid_name);
assert (false);
}
catch(LipidException &e){ }
catch(LipidException &e){
}



lipid_name = "PA 19:2(12E)/12:0";
lipid = lipid_parser.parse(lipid_name);
try {
string l = lipid->get_lipid_string();
assert (false);
assert(l == "foo");
}
catch(LipidException &e){
delete lipid;
}




Expand Down

0 comments on commit 675865b

Please sign in to comment.