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 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444
|
// --------------------------------------------------------------------------
// OpenMS -- Open-Source Mass Spectrometry
// --------------------------------------------------------------------------
// Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
// ETH Zurich, and Freie Universitaet Berlin 2002-2013.
//
// This software is released under a three-clause BSD license:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of any author or any participating institution
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
// For a full list of authors, refer to the file AUTHORS.
// --------------------------------------------------------------------------
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
// INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// --------------------------------------------------------------------------
// $Maintainer: Chris Bielow $
// $Authors: Chris Bielow $
// --------------------------------------------------------------------------
#include <OpenMS/CONCEPT/ClassTest.h>
///////////////////////////
#include <OpenMS/DATASTRUCTURES/Compomer.h>
#include <OpenMS/DATASTRUCTURES/Adduct.h>
#include <OpenMS/CHEMISTRY/EmpiricalFormula.h>
using namespace OpenMS;
using namespace std;
START_TEST(Compomer, "$Id: Compomer_test.C 10915 2013-04-04 20:14:57Z aiche $")
/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
Compomer* ptr = 0;
Compomer* nullPointer = 0;
START_SECTION(Compomer())
{
ptr = new Compomer();
TEST_NOT_EQUAL(ptr, nullPointer)
}
END_SECTION
START_SECTION(~Compomer())
{
delete ptr;
}
END_SECTION
START_SECTION((Compomer(Int net_charge, DoubleReal mass, DoubleReal log_p)))
{
Compomer c(34, 45.32f, 12.34f);
TEST_EQUAL(c.getNetCharge(), 34);
TEST_REAL_SIMILAR(c.getMass(), 45.32);
TEST_REAL_SIMILAR(c.getLogP(), 12.34);
}
END_SECTION
START_SECTION((Compomer(const Compomer& p) ))
{
Compomer c(34, 45.32f, 12.34f);
Adduct a1(123, 3, 123.456f, "S", -0.3453f, 0);
Adduct b1(3, -2, 1.456f, "H", -0.13f, 0);
c.setID(434);
c.add(a1, Compomer::RIGHT);
c.add(b1, Compomer::LEFT);
Compomer c2(c);
TEST_EQUAL(c2.getNetCharge(), c.getNetCharge());
TEST_REAL_SIMILAR(c2.getMass(), c.getMass());
TEST_EQUAL(c2.getPositiveCharges(), c.getPositiveCharges());
TEST_EQUAL(c2.getNegativeCharges(), c.getNegativeCharges());
TEST_REAL_SIMILAR(c2.getLogP(), c.getLogP());
TEST_EQUAL(c2.getID(), c.getID());
}
END_SECTION
START_SECTION((Compomer& operator=(const Compomer &source)))
{
Compomer c(34, 45.32f, 12.34f);
Adduct a1(123, 3, 123.456f, "S", -0.3453f, 0);
Adduct b1(3, -2, 1.456f, "H", -0.13f, 0);
c.setID(434);
c.add(a1, Compomer::RIGHT);
c.add(b1, Compomer::LEFT);
Compomer c2 = c;
TEST_EQUAL(c2.getNetCharge(), c.getNetCharge());
TEST_REAL_SIMILAR(c2.getMass(), c.getMass());
TEST_EQUAL(c2.getPositiveCharges(), c.getPositiveCharges());
TEST_EQUAL(c2.getNegativeCharges(), c.getNegativeCharges());
TEST_REAL_SIMILAR(c2.getLogP(), c.getLogP());
TEST_EQUAL(c2.getID(), c.getID());
}
END_SECTION
START_SECTION([EXTRA] friend OPENMS_DLLAPI bool operator==(const Compomer& a, const Compomer& b))
{
Compomer c(34, 45.32f, 12.34f);
Adduct a1(123, 3, 123.456f, "S", -0.3453f, 0);
Adduct b1(3, -2, 1.456f, "H", -0.13f, 0);
c.setID(434);
c.add(a1, Compomer::RIGHT);
Compomer c2(c);
TEST_EQUAL(c==c2, true);
c.setID(2);
TEST_EQUAL(c==c2, false);
}
END_SECTION
START_SECTION((void add(const Adduct &a, UInt side)))
{
//Adduct(Int charge, Int amount, DoubleReal singleMass, String formula, DoubleReal log_prob
Adduct a1(123, 43, 123.456f, "S", -0.3453f, 0);
Adduct a2(123, 3, 123.456f, "S", -0.3453f, 0);
Adduct b1(3, -2, 1.456f, "H", -0.13f, 0);
Compomer c;
c.add(a1, Compomer::RIGHT);
//PRECISION(0.0001);
TEST_EQUAL(c.getNetCharge(), 123*43);
TEST_REAL_SIMILAR(c.getMass(), 123.456*43);
TEST_REAL_SIMILAR(c.getLogP(), -0.3453*43);
TEST_EQUAL(c.getPositiveCharges(), 123*43);
TEST_EQUAL(c.getNegativeCharges(), 0);
c.add(a2, Compomer::RIGHT);
TEST_EQUAL(c.getNetCharge(), 123*46);
TEST_REAL_SIMILAR(c.getMass(), 123.456*46);
TEST_REAL_SIMILAR(c.getLogP(), -0.3453*46);
TEST_EQUAL(c.getPositiveCharges(), 123*46);
TEST_EQUAL(c.getNegativeCharges(), 0);
c.add(b1, Compomer::RIGHT);
TEST_EQUAL(c.getNetCharge(), 123*46+ 3*(-2));
TEST_REAL_SIMILAR(c.getMass(), 123.456*46 - 2*1.456);
TEST_REAL_SIMILAR(c.getLogP(), -0.3453*46 -0.13*2);
TEST_EQUAL(c.getPositiveCharges(), 123*46);
TEST_EQUAL(c.getNegativeCharges(), 6);
}
END_SECTION
START_SECTION(bool isConflicting(const Compomer &cmp, UInt side_this, UInt side_other) const)
{
EmpiricalFormula ef("H");
Adduct default_adduct(1, 1, ef.getMonoWeight(), ef.getString(), log(0.7f), 0);
{
Adduct a1(1, 1, 1.007f, "H1", -0.13f, 0);
Adduct a2(1, 2, 123.456f, "NH4", -0.3453f, 0);
Compomer c,d;
c.add(a1, Compomer::RIGHT);
d.add(a1, Compomer::RIGHT);
TEST_EQUAL(c.isConflicting(d,Compomer::RIGHT,Compomer::RIGHT), false);
TEST_EQUAL(c.isConflicting(d,Compomer::LEFT,Compomer::RIGHT), true);
TEST_EQUAL(c.isConflicting(d,Compomer::RIGHT,Compomer::LEFT), true);
// this should not change the result
c.add(a1, Compomer::RIGHT);
d.add(a1, Compomer::RIGHT);
TEST_EQUAL(c.isConflicting(d,Compomer::RIGHT,Compomer::RIGHT), false);
TEST_EQUAL(c.isConflicting(d,Compomer::LEFT,Compomer::RIGHT), true);
TEST_EQUAL(c.isConflicting(d,Compomer::RIGHT,Compomer::LEFT), true);
// this neither
c.add(a2, Compomer::LEFT);
TEST_EQUAL(c.isConflicting(d,Compomer::RIGHT,Compomer::RIGHT), false);
TEST_EQUAL(c.isConflicting(d,Compomer::LEFT,Compomer::RIGHT), true);
TEST_EQUAL(c.isConflicting(d,Compomer::RIGHT,Compomer::LEFT), true);
}
{
Adduct a1(1, -2, 123.456f, "NH4", -0.3453f, 0);
Adduct a2(1, 1, 1.007f, "H1", -0.13f, 0);
Adduct b1(1, 2, 1.007f, "H1", -0.13f, 0);
Compomer c,d;
c.add(a1, Compomer::RIGHT);
c.add(a2, Compomer::RIGHT);
d.add(b1, Compomer::RIGHT);
TEST_EQUAL(c.isConflicting(d,Compomer::RIGHT,Compomer::RIGHT), true);
TEST_EQUAL(c.isConflicting(d,Compomer::RIGHT,Compomer::LEFT), true);
TEST_EQUAL(c.isConflicting(d,Compomer::LEFT,Compomer::RIGHT), true);
TEST_EQUAL(c.isConflicting(d,Compomer::LEFT,Compomer::LEFT), false);
}
{
Adduct a1(1, 3, 123.456f, "NH4", -0.3453f, 0);
Adduct a2(1, 3, 1.007f, "H1", -0.13f, 0);
Compomer c,d;
c.add(a1, Compomer::RIGHT);
d.add(a1, Compomer::LEFT);
TEST_EQUAL(c.isConflicting(d,Compomer::RIGHT,Compomer::LEFT), false);
TEST_EQUAL(c.isConflicting(d,Compomer::RIGHT,Compomer::RIGHT), true);
TEST_EQUAL(c.isConflicting(d,Compomer::LEFT,Compomer::RIGHT), false);
TEST_EQUAL(c.isConflicting(d,Compomer::LEFT,Compomer::LEFT), true);
c.add(a1, Compomer::LEFT);
c.add(a2, Compomer::RIGHT);
d.add(a1, Compomer::LEFT);
d.add(a2, Compomer::RIGHT);
// C D
//a1 a1a2 ; a1a1 a2
TEST_EQUAL(c.isConflicting(d,Compomer::RIGHT,Compomer::LEFT), true);
TEST_EQUAL(c.isConflicting(d,Compomer::RIGHT,Compomer::RIGHT), true);
TEST_EQUAL(c.isConflicting(d,Compomer::LEFT,Compomer::RIGHT), true);
TEST_EQUAL(c.isConflicting(d,Compomer::LEFT,Compomer::LEFT), true);
c.add(a1, Compomer::RIGHT);
d.add(a2, Compomer::LEFT);
d.add(a1, Compomer::RIGHT);
d.add(a1, Compomer::RIGHT);
// C D
//a1 a1a2a1 ; a1a1a2 a2a1a1
TEST_EQUAL(c.isConflicting(d,Compomer::RIGHT,Compomer::LEFT), false);
TEST_EQUAL(c.isConflicting(d,Compomer::RIGHT,Compomer::RIGHT), false);
TEST_EQUAL(c.isConflicting(d,Compomer::LEFT,Compomer::RIGHT), true);
TEST_EQUAL(c.isConflicting(d,Compomer::LEFT,Compomer::LEFT), true);
}
}
END_SECTION
START_SECTION((void setID(const Size &id)))
{
NOT_TESTABLE //well.. tested below...
}
END_SECTION
START_SECTION((const Size& getID() const))
{
Compomer c;
c.setID(123);
TEST_EQUAL(c.getID(), 123)
}
END_SECTION
START_SECTION((const Int& getNetCharge() const))
{
Compomer c(-123,1.23,-0.12);
TEST_EQUAL(c.getNetCharge(), -123)
}
END_SECTION
START_SECTION((const DoubleReal& getMass() const))
{
Compomer c(1,-123.12, 0.23);
TEST_REAL_SIMILAR(c.getMass(), -123.12)
}
END_SECTION
START_SECTION((const Int& getPositiveCharges() const))
{
Compomer c;
Adduct a1(3, -2, 123.456f, "NH4", -0.3453f, 0);
Adduct a2(6, 1, 1.007f, "H1", -0.13f, 0);
c.add(a1, Compomer::RIGHT);
c.add(a2, Compomer::RIGHT);
TEST_EQUAL(c.getPositiveCharges(), 6)
}
END_SECTION
START_SECTION((const Int& getNegativeCharges() const))
{
Compomer c;
Adduct a1(3, -2, 123.456f, "NH4", -0.3453f, 0);
Adduct a2(6, 1, 1.007f, "H1", -0.13f, 0);
c.add(a1, Compomer::RIGHT);
c.add(a2, Compomer::RIGHT);
TEST_EQUAL(c.getNegativeCharges(), 6)
}
END_SECTION
START_SECTION((const DoubleReal& getLogP() const))
{
Compomer c(1,1,-123.12);
TEST_REAL_SIMILAR(c.getLogP(), -123.12)
}
END_SECTION
START_SECTION((const DoubleReal& getRTShift() const))
{
Compomer c(1,1,-123.12);
Adduct a(123, 43, 123.456f, "S", -0.3453, -10.12);
c.add(a,0);
TEST_REAL_SIMILAR(c.getRTShift(), 435.16)
}
END_SECTION
START_SECTION((StringList getLabels(const UInt side) const))
{
Compomer c(1,1,-123.12);
TEST_EQUAL(c.getLabels(0).size(), 0)
Adduct a(123, 43, 123.456f, "S", -0.3453, -10.12, "testlabel");
c.add(a,0);
TEST_EQUAL(c.getLabels(0).size(), 1)
TEST_EQUAL(c.getLabels(1).size(), 0)
}
END_SECTION
START_SECTION((String getAdductsAsString() const))
{
Adduct a1(1, 2, 123.456f, "NH4", -0.3453f, 0);
Adduct a2(1, -1, 1.007f, "H1", -0.13f, 0);
Compomer c;
c.add(a1, Compomer::RIGHT);
c.add(a2, Compomer::RIGHT);
TEST_EQUAL(c.getAdductsAsString(), "() --> (H-1H8N2)");
c.add(a1, Compomer::LEFT);
TEST_EQUAL(c.getAdductsAsString(), "(H8N2) --> (H-1H8N2)");
}
END_SECTION
START_SECTION((String getAdductsAsString(UInt side) const))
{
Adduct a1(1, 2, 123.456f, "NH4", -0.3453f, 0);
Adduct a2(1, -1, 1.007f, "H1", -0.13f, 0);
Compomer c;
c.add(a1, Compomer::RIGHT);
c.add(a2, Compomer::RIGHT);
TEST_EQUAL(c.getAdductsAsString(Compomer::LEFT), "");
TEST_EQUAL(c.getAdductsAsString(Compomer::RIGHT), "H-1H8N2");
c.add(a1, Compomer::LEFT);
TEST_EQUAL(c.getAdductsAsString(Compomer::LEFT), "H8N2");
TEST_EQUAL(c.getAdductsAsString(Compomer::RIGHT), "H-1H8N2");
}
END_SECTION
START_SECTION((const CompomerComponents& getComponent() const))
{
Adduct a1(1, 2, 123.456f, "NH4", -0.3453f, 0);
Adduct a2(1, -1, 1.007f, "H1", -0.13f, 0);
Compomer c;
Compomer::CompomerComponents comp(2);
TEST_EQUAL(c.getComponent()==comp, true);
c.add(a1, Compomer::RIGHT);
c.add(a2, Compomer::RIGHT);
c.add(a1, Compomer::LEFT);
comp[Compomer::RIGHT][a1.getFormula()] = a1;
comp[Compomer::RIGHT][a2.getFormula()] = a2;
comp[Compomer::LEFT][a1.getFormula()] = a1;
TEST_EQUAL(c.getComponent()==comp, true);
}
END_SECTION
START_SECTION((Compomer removeAdduct(const Adduct& a) const))
{
Adduct a1(1, 2, 123.456f, "NH4", -0.3453f, 0);
Adduct a2(1, -1, 1.007f, "H1", -0.13f, 0);
Compomer c;
c.add(a1, Compomer::RIGHT);
c.add(a2, Compomer::RIGHT);
c.add(a1, Compomer::LEFT);
Compomer tmp = c.removeAdduct(a1);
TEST_EQUAL(tmp.getAdductsAsString(), "() --> (H-1)");
}
END_SECTION
START_SECTION((Compomer removeAdduct(const Adduct& a, const UInt side) const))
{
Adduct a1(1, 2, 123.456f, "NH4", -0.3453f, 0);
Adduct a2(1, -1, 1.007f, "H1", -0.13f, 0);
Compomer c;
c.add(a1, Compomer::RIGHT);
c.add(a2, Compomer::RIGHT);
c.add(a1, Compomer::LEFT);
Compomer tmp = c.removeAdduct(a1, Compomer::RIGHT);
TEST_EQUAL(tmp.getAdductsAsString(), "(H8N2) --> (H-1)");
tmp = c.removeAdduct(a1, Compomer::LEFT);
TEST_EQUAL(tmp.getAdductsAsString(), "() --> (H-1H8N2)");
}
END_SECTION
START_SECTION((void add(const CompomerSide& add_side, UInt side)))
{
Adduct a1(1, 2, 123.456f, "NH4", -0.3453f, 0);
Adduct a2(1, -1, 1.007f, "H1", -0.13f, 0);
Compomer c;
c.add(a1, Compomer::RIGHT);
c.add(a2, Compomer::RIGHT);
c.add(a1, Compomer::LEFT);
TEST_EQUAL(c.getAdductsAsString(), "(H8N2) --> (H-1H8N2)");
Compomer tmp = c;
tmp.add(c.getComponent()[Compomer::RIGHT], Compomer::RIGHT);
TEST_EQUAL(tmp.getAdductsAsString(), "(H8N2) --> (H-2H16N4)");
tmp.add(c.getComponent()[Compomer::RIGHT], Compomer::LEFT);
TEST_EQUAL(tmp.getAdductsAsString(), "(H-1H16N4) --> (H-2H16N4)");
}
END_SECTION
START_SECTION((bool isSingleAdduct(Adduct &a, const UInt side) const))
Adduct a1(1, 2, 123.456f, "NH4", -0.3453f, 0);
Adduct a2(1, -1, 1.007f, "H1", -0.13f, 0);
Compomer c;
c.add(a1, Compomer::RIGHT);
c.add(a2, Compomer::RIGHT);
c.add(a1, Compomer::LEFT);
TEST_EQUAL(c.isSingleAdduct(a1,Compomer::LEFT), true);
TEST_EQUAL(c.isSingleAdduct(a2,Compomer::LEFT), false);
TEST_EQUAL(c.isSingleAdduct(a1,Compomer::RIGHT), false);
TEST_EQUAL(c.isSingleAdduct(a2,Compomer::RIGHT), false);
END_SECTION
/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
END_TEST
|