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 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790
|
/* massXpert - the true massist's program.
--------------------------------------
Copyright(C) 2006,2007 Filippo Rusconi
http://www.massxpert.org/massXpert
This file is part of the massXpert project.
The massxpert project is the successor to the "GNU polyxmass"
project that is an official GNU project package(see
www.gnu.org). The massXpert project is not endorsed by the GNU
project, although it is released ---in its entirety--- under the
GNU General Public License. A huge part of the code in massXpert
is actually a C++ rewrite of code in GNU polyxmass. As such
massXpert was started at the Centre National de la Recherche
Scientifique(FRANCE), that granted me the formal authorization to
publish it under this Free Software License.
This software is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License version 3, as published by the Free Software Foundation.
This software is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this software; if not, write to the
Free Software Foundation, Inc.,
51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/////////////////////// Local includes
#include "oligomer.hpp"
#include "polymer.hpp"
#include "ionizeRule.hpp"
namespace massXpert
{
//! Constructs an oligomer.
/*!
\param polymer Polymer in which \c this oligomer spans a region. Cannot
be 0.
\param ponderable Ponderable used to initialized the data in \c
this. Note that the initialization is shallow, as the data in the
property list are not copied.
\param name Name of the oligomer.
\param startIndex Index of the first monomer of \c this oligomer in
the polymer sequence(note that this index is stored in the very first
Coordinates item in the CoordinateList).
\param endIndex Index of the last monomer of \c this oligomer in the
polymer sequence(note that this index is stored in the very first
Coordinates item in the CoordinateList).
\param ionizeRule IonizeRule to be used to initialize the Ionizable ancestor.
\param isIonized Indicates if the oligomer should be considered
ionized.
*/
Oligomer::Oligomer(Polymer *polymer , const QString &name,
const Ponderable &ponderable,
const IonizeRule &ionizeRule, bool isIonized,
int startIndex, int endIndex)
: Ionizable(polymer->polChemDef(), name, ponderable,
ionizeRule, isIonized), mp_polymer(polymer)
{
setStartEndIndices(startIndex, endIndex);
}
//! Constructs an oligomer.
/*! The oligomer is constructed with its \c mp_polymer member set to
0. This means that no reference to the polymer can be done. This
constructor is useful when the oligomer must be created out of any
polymer context, like when oligomers are created starting from raw
text data in the MzLab window.
\param polChemDef Polymer chemistry definition on which \c this
oligomer is based. Cannot be 0.
\param ponderable Ponderable used to initialized the data in \c
this. Note that the initialization is shallow, as the data in the
property list are not copied.
\param name Name of the oligomer.
\param startIndex Index of the first monomer of \c this oligomer in
the polymer sequence(note that this index is stored in the very first
Coordinates item in the CoordinateList).
\param endIndex Index of the last monomer of \c this oligomer in the
polymer sequence(note that this index is stored in the very first
Coordinates item in the CoordinateList).
\param ionizeRule IonizeRule to be used to initialize the Ionizable ancestor.
\param isIonized Indicates if the oligomer should be considered
ionized.
*/
Oligomer::Oligomer(const PolChemDef *polChemDef, const QString &name,
const Ponderable &ponderable,
const IonizeRule &ionizeRule, bool isIonized,
int startIndex, int endIndex)
: Ionizable(polChemDef, name, ponderable, ionizeRule, isIonized),
mp_polymer(0)
{
setStartEndIndices(startIndex, endIndex);
}
//! Constructs an oligomer.
/*!
\param polymer Polymer in which \c this oligomer spans a region. Cannot
be 0.
\param ponderable Ponderable used to initialized the data in \c
this. Note that the initialization is shallow, as the data in the
property list are not copied.
\param name Name of the oligomer.
\param startIndex Index of the first monomer of \c this oligomer in
the polymer sequence(note that this index is stored in the very first
Coordinates item in the CoordinateList).
\param endIndex Index of the last monomer of \c this oligomer in the
polymer sequence(note that this index is stored in the very first
Coordinates item in the CoordinateList).
*/
Oligomer::Oligomer(Polymer *polymer, const QString &name,
const Ponderable &ponderable,
int startIndex, int endIndex)
: Ionizable(polymer->polChemDef(), name, ponderable),
mp_polymer(polymer)
{
setStartEndIndices(startIndex, endIndex);
}
//! Constructs an oligomer.
/*! The oligomer is constructed with its \c mp_polymer member set to
0. This means that no reference to the polymer can be done. This
constructor is useful when the oligomer must be created out of any
polymer context, like when oligomers are created starting from raw
text data in the MzLab window.
\param polChemDef Polymer chemistry definition on which \c this
oligomer is based. Cannot be 0.
\param ponderable Ponderable used to initialized the data in \c
this. Note that the initialization is shallow, as the data in the
property list are not copied.
\param name Name of the oligomer.
\param startIndex Index of the first monomer of \c this oligomer in
the polymer sequence(note that this index is stored in the very first
Coordinates item in the CoordinateList).
\param endIndex Index of the last monomer of \c this oligomer in the
polymer sequence(note that this index is stored in the very first
Coordinates item in the CoordinateList).
*/
Oligomer::Oligomer(const PolChemDef *polChemDef, const QString &name,
const Ponderable &ponderable,
int startIndex, int endIndex)
: Ionizable(polChemDef, name, ponderable), mp_polymer(0)
{
setStartEndIndices(startIndex, endIndex);
}
//! Constructs an oligomer.
/*!
\param polymer Polymer in which \c this oligomer spans a region. Cannot
be 0.
\param name Name of the oligomer.
\param startIndex Index of the first monomer of \c this oligomer in
the polymer sequence.
\param endIndex Index of the last monomer of \c this oligomer in the
polymer sequence.
\param mono Monoisotopic mass.
\param avg Average mass.
*/
Oligomer::Oligomer(Polymer *polymer , const QString &name,
double mono, double avg,
int startIndex, int endIndex)
: Ionizable(mp_polymer->polChemDef(), name, Ponderable(mono, avg)),
mp_polymer(polymer)
{
setStartEndIndices(startIndex, endIndex);
}
//! Constructs an oligomer.
/*! The oligomer is constructed with its \c mp_polymer member set to
0. This means that no reference to the polymer can be done. This
constructor is useful when the oligomer must be created out of any
polymer context, like when oligomers are created starting from raw
text data in the MzLab window.
\param polChemDef Polymer chemistry definition on which \c this
oligomer is based. Cannot be 0.
\param name Name of the oligomer.
\param startIndex Index of the first monomer of \c this oligomer in
the polymer sequence.
\param endIndex Index of the last monomer of \c this oligomer in the
polymer sequence.
\param mono Monoisotopic mass.
\param avg Average mass.
*/
Oligomer::Oligomer(const PolChemDef *polChemDef, const QString &name,
double mono, double avg,
int startIndex, int endIndex)
: Ionizable(polChemDef, name, Ponderable(mono, avg)),
mp_polymer(0)
{
setStartEndIndices(startIndex, endIndex);
}
//! Constructs a copy of \p other.
/*! The copying is shallow, as the data in the property list are not
copied.
\param other oligomer to be used as a mold.
*/
Oligomer::Oligomer(const Oligomer &other)
: CoordinateList(other), Ionizable(other),
mp_polymer(other.mp_polymer)
{
}
//! Destroys the oligomer.
Oligomer::~Oligomer()
{
// qDebug() << "~Oligomer()";
}
//! Returns the polymer.
/*! \return the polymer.
*/
const Polymer *
Oligomer::polymer() const
{
return mp_polymer;
}
//! Sets the start and end indices.
/*! \param value1 New start index
\param value2 New end index
*/
void
Oligomer::setStartEndIndices(int value1, int value2)
{
if (!CoordinateList::size())
{
Coordinates *coordinates = new Coordinates(value1, value2);
append(coordinates);
// qDebug() << __FILE__ << __LINE__
// << "[start--end]:" << startIndex() << endIndex();
}
else
{
Coordinates *coordinates = first();
coordinates->setStart(value1);
coordinates->setEnd(value2);
// qDebug() << __FILE__ << __LINE__
// << "[start--end]:" << startIndex() << endIndex();
}
}
//! Sets the start index.
/*! \param value New start index.
*/
void
Oligomer::setStartIndex(int value)
{
if (!CoordinateList::size())
{
Coordinates *coordinates = new Coordinates();
coordinates->setStart(value);
append(coordinates);
}
else
{
Coordinates *coordinates = first();
coordinates->setStart(value);
}
}
//! Returns the start index.
/*! \return the start index.
*/
int
Oligomer::startIndex() const
{
if (!CoordinateList::size())
return -1;
Coordinates *coordinates = first();
return coordinates->start();
}
//! Sets the end index.
/*! \param value New end index.
*/
void
Oligomer::setEndIndex(int value)
{
if (!CoordinateList::size())
{
Coordinates *coordinates = new Coordinates();
coordinates->setEnd(value);
append(coordinates);
}
else
{
Coordinates *coordinates = first();
coordinates->setEnd(value);
}
}
//! Returns the end index.
/*! \return the end index.
*/
int
Oligomer::endIndex() const
{
if (!CoordinateList::size())
return -1;
Coordinates *coordinates = first();
return coordinates->end();
}
int
Oligomer::appendCoordinates(CoordinateList *list)
{
Q_ASSERT(list);
int count = 0;
for (int iter = 0; iter < list->size(); ++iter)
{
Coordinates *iterCoordinates = list->at(iter);
Coordinates *coordinates = new Coordinates(*iterCoordinates);
append(coordinates);
++count;
}
return count;
}
void
Oligomer::setIonizeRule(IonizeRule &ionizeRule)
{
m_ionizeRule = ionizeRule;
}
IonizeRule &
Oligomer::ionizeRule()
{
return m_ionizeRule;
}
const Monomer &
Oligomer::atLeftEnd() const
{
// qDebug() << __FILE__ << __LINE__ << "Going to call at() with value"
// << startIndex();
return *(mp_polymer->at(startIndex()));
}
const Monomer &
Oligomer::atRightEnd() const
{
// qDebug() << __FILE__ << __LINE__ << "Going to call at() with value"
// << endIndex();
return *(mp_polymer->at(endIndex()));
}
const Monomer *
Oligomer::monomerAt(int index) const
{
Q_ASSERT(index >= 0);
Q_ASSERT(index < mp_polymer->size() - 1);
// qDebug() << __FILE__ << __LINE__ << "Going to call at() with value"
// << index;
return mp_polymer->at(index);
}
QList<CrossLink *> *
Oligomer::crossLinkList()
{
return &m_crossLinkList;
}
bool
Oligomer::addCrossLink(CrossLink *crossLink)
{
// Add the cross-link only if it does not exist already. Return true
// only if the crossLink has been added.
if (!m_crossLinkList.contains(crossLink))
{
m_crossLinkList.append(crossLink);
return true;
}
return false;
}
int
Oligomer::makeMonomerText()
{
// Prepare the text version of the oligomer's sequence by basing
// it on the coordinates of *this oligomer and set that text to
// m_monomerText.
if (!mp_polymer)
return 0;
QString *text = monomerText();
m_monomerText = *text;
delete(text);
return m_monomerText.size();
}
QString *
Oligomer::monomerText()
{
// Allocate a new string to hold the text version of *this
// oligomer's sequence.
// There are two situations:
// 1. The mp_polymer member is non-0, we can get access to it. Ask
// the polymer to do the work. This is the most faithful
// situation. But the caller must first ensure that the polymer
// actually exists.
// 2. The mp_polymer member is 0, we may have the oligomer
// sequence stored in *this oligomer. Test that.
QString *text = new QString();
if (mp_polymer)
{
// For each oligomer(if more than one, which is the case when the
// oligomer is actually a cross-linked oligomer), create a string...
int oligomerCount = CoordinateList::size();
for(int iter = 0; iter < oligomerCount; ++iter)
{
Coordinates *coordinates = CoordinateList::at(iter);
QString *local =
mp_polymer->monomerText(coordinates->start(),
coordinates->end(),
true);
text->append(*local);
// If this is a cross-linked oligomer and we are not appending
// text for the __last__ oligomer, then append "~" to let the
// user know that the sequences are cross-linked.
if (oligomerCount > 1 && iter < oligomerCount - 1)
text->append("~");
delete(local);
}
}
else
{
if(m_monomerText.size())
{
*text = m_monomerText;
return text;
}
else
{
if (m_monomerList.size())
return Sequence::monomerText(0, m_monomerList.size(), true);
}
}
return text;
}
//! Calculates the masses(mono and avg).
/*! The calculation is performed by computing the mono and avg masses
of the sequence stretch as described by the start and end indices in
the polymer sequence. Default calculation options are used.
\return true if calculations were successful, false otherwise.
\sa calculateMasses(const CalcOptions &calcOptions, const
IonizeRule &ionizeRule)
\sa Polymer::ionize()
\sa CalcOptions::CalcOptions()
*/
bool
Oligomer::calculateMasses()
{
CalcOptions calcOptions;
calcOptions.setCapping(MXT_CAP_NONE);
IonizeRule rule;
return calculateMasses(&calcOptions, &rule);
}
//! Calculates the masses(mono and avg).
/*! The calculation is performed by computing the mono and avg masses
of the sequence stretch as described by the start and end indices in
the polymer sequence.
\param calcOptions Calculation options to be used for the mass
calculation.
\param ionizeRule Ionization rule to be used for the mass
calculation.
\return true if calculations were successful, false otherwise.
\sa Polymer::calculateMasses()
\sa Polymer::ionize()
*/
bool
Oligomer::calculateMasses(const CalcOptions *calcOptions,
const IonizeRule *ionizeRule)
{
Q_ASSERT(calcOptions);
CalcOptions localOptions(*calcOptions);
// The coordinates of the oligomer are the following:
// MAMISGMSGRKAS
// For a tryptic peptide obtained from protein above, we'd have
// MAMISGMSGR, that is in the oligomer coordinates:
// [0] MAMISGMSGR [9]
// When computing the mass of the oligomer, we have to do a
// for (iter == [0] ; iter < [9 + 1]; ++iter)
// Which is why we increment add 1 to m_endIndex in the function below.
// A polymer might be something made of more than one residual chain
// in case it is a cross-linked oligomer. Compute the mass fore each
// residual chain, without accounting for the cross-links...
m_mono = 0;
m_avg = 0;
// An oligomer _is_ a CoordinateList, and we need that list in the
// calcOptions so that we can call the Polymer::accountMasses
// function.
localOptions.setCoordinateList(*this);
// We do not want to take into account the cross-links because
// we'll be doing this here and because it cannot work if the
// cross-links are taken into account from the polymer.
int flags = localOptions.monomerEntities();
flags &= ~MXT_MONOMER_CHEMENT_CROSS_LINK;
localOptions.setMonomerEntities(flags);
Polymer::accountMasses(mp_polymer,
localOptions, &m_mono, &m_avg);
// qDebug() << __FILE__ << __LINE__
// << "After accounting masses(prior to cross-links):"
// << "mono mass is:" << m_mono;
// At this point, we have added the mass of each constituent
// oligomer's residual chain. Let's deal with the cross-links.
for (int iter = 0; iter < m_crossLinkList.size(); ++iter)
{
CrossLink *crossLink = m_crossLinkList.at(iter);
if(!crossLink->accountMasses(&m_mono, &m_avg))
return false;
// qDebug() << __FILE__ << __LINE__
// << "After accounting cross-link:"
// << crossLink->name()
// << "mono mass is:" << m_mono;
}
// If an ionizeRule is provided, use it. Otherwise, ionize
// automatically using the ::Ionizable IonizeRule.
if (ionizeRule)
{
// Note that if ionizeRule is invalid, then the ionization is
// not performed.
if(ionizeRule->isValid())
{
/*
if (ionize(mp_polymer, *ionizeRule) == -1)
The line above is a huge bug. While we should be
ionizing this oligomer, we end up ionizing the polymer !
*/
if (ionize(*ionizeRule) == -1)
return false;
}
}
else
{
if(ionize() == -1)
return false;
}
// qDebug() << __FILE__ << __LINE__
// << "Coming out from the calculateMasses function:"
// << "mono mass is:" << m_mono;
return true;
}
//! Tells if the oligomer contains at least one modified monomer.
/*! Iterates in the polymer sequence from start index to end index and
if one of the iterated monomers contain a PxmModif modification,
returns true;
\return true if at least one monomer is modified, false otherwise.
*/
bool
Oligomer::isModified()
{
int oligomerCount = CoordinateList::size();
for (int iter = 0; iter < oligomerCount; ++iter)
{
Coordinates *coordinates = CoordinateList::at(iter);
for(int iter = coordinates->start();
iter < coordinates->end() + 1; ++iter)
{
// qDebug() << __FILE__ << __LINE__ << "Going to call at() with value"
// << iter;
const Monomer *monomer = mp_polymer->at(iter);
if (monomer->isModified())
return true;
}
}
return false;
}
int
Oligomer::size()
{
int sum = 0;
int oligomerCount = CoordinateList::size();
// The size of an oligomer is the sum of all its oligomeric
// components as described by the various coordinates.
for (int iter = 0; iter < oligomerCount; ++iter)
{
Coordinates *coordinates = CoordinateList::at(iter);
sum += coordinates->length();
}
return sum;
}
bool
Oligomer::encompasses(int index) const
{
int oligomerCount = CoordinateList::size();
for (int iter = 0; iter < oligomerCount; ++iter)
{
Coordinates *coordinates = CoordinateList::at(iter);
if(index <= coordinates->start() && index >= coordinates->end())
return true;
}
return false;
}
bool
Oligomer::encompasses(const Monomer *monomer) const
{
int oligomerCount = CoordinateList::size();
for (int iter = 0; iter < oligomerCount; ++iter)
{
Coordinates *coordinates = CoordinateList::at(iter);
for(int jter = coordinates->start();
jter < coordinates->end() + 1; ++jter)
{
// qDebug() << __FILE__ << __LINE__ << "Going to call at() with value"
// << jter;
if (mp_polymer->at(jter) == monomer)
return true;
}
}
return false;
}
} // namespace massXpert
|