File: test_natural_isotope_average.cpp

package info (click to toggle)
libpappsomspp 0.11.9-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 18,580 kB
  • sloc: cpp: 82,463; xml: 44,164; python: 668; sql: 186; sh: 33; makefile: 32
file content (184 lines) | stat: -rw-r--r-- 7,380 bytes parent folder | download | duplicates (2)
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

/*******************************************************************************
 * Copyright (c) 2015 Olivier Langella <Olivier.Langella@moulon.inra.fr>.
 *
 * This file is part of the PAPPSOms++ library.
 *
 *     PAPPSOms++ is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 *
 *     PAPPSOms++ 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 PAPPSOms++.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Contributors:
 *     Olivier Langella <Olivier.Langella@moulon.inra.fr> - initial API and
 *implementation
 ******************************************************************************/
// ./tests/catch2-only-tests [peptidenaturalisotopeaverage] -s


#include <catch2/catch_test_macros.hpp>
#include <catch2/catch_approx.hpp>

#include <iostream>
#include <pappsomspp/core/peptide/peptidenaturalisotopeaverage.h>
#include <pappsomspp/core/peptide/peptidenaturalisotopelist.h>
#include <pappsomspp/core/peptide/peptidestrparser.h>
// #include "common.h"
#include "config.h"

using namespace pappso;
using namespace std;
// using namespace pwiz::msdata;

// make test ARGS="-V -I 8,8"

TEST_CASE("Test peptidenaturalisotopeaverage", "[peptidenaturalisotopeaverage]")
{
  // Set the debugging message formatting pattern.
  qSetMessagePattern(QString("%{file}@%{line}, %{function}(): %{message}"));

  SECTION("..:: Test peptidenaturalisotopeaverage ::..",
          "[peptidenaturalisotopeaverage]")
  {

    std::cout << std::endl
              << "..:: Test natural isotope average ::.." << std::endl;

    Peptide peptide("ALLDEMAVVATEEYR");
    peptide.addAaModification(AaModification::getInstance("MOD:00397"), 0);

    pappso_double check_mass = 1747.84;
    MzRange test_mass(check_mass, PrecisionFactory::getDaltonInstance(0.01));
    REQUIRE(test_mass.contains(peptide.getMass() - MASSH2O));


    unsigned int askedIsotopeRank = 1;
    unsigned int isotopeLevel     = 2;
    unsigned int charge           = 1;
    PrecisionPtr precision        = PrecisionFactory::getPpmInstance(5);
    PeptideNaturalIsotopeAverage isotopeAverageMono(
      peptide.makePeptideSp(), askedIsotopeRank, 0, 1, precision);
    REQUIRE(MzRange(peptide.getMz(1), PrecisionFactory::getDaltonInstance(0.01))
              .contains(isotopeAverageMono.getMz()));


    PeptideNaturalIsotopeAverage isotopeAverage(peptide.makePeptideSp(),
                                                askedIsotopeRank,
                                                isotopeLevel,
                                                charge,
                                                precision);


    std::cout << "monosiotope mz=" << peptide.getMz(charge)
              << "average mz=" << isotopeAverage.getMz() << std::endl;
    std::cout << "intensity ratio =" << isotopeAverage.getIntensityRatio()
              << std::endl;

    std::cout << "z=" << isotopeAverage.getCharge() << std::endl;

    std::cout << "sum of :" << std::endl;
    unsigned int rank = 1;
    for(auto &&peptideNaturalIsotope : isotopeAverage.getComponents())
      {
        std::cout
          << "number=" << isotopeAverage.getIsotopeNumber() << " rank=" << rank
          << " mz=" << peptideNaturalIsotope.get()->getMz(charge)
          << " ratio=" << peptideNaturalIsotope.get()->getIntensityRatio(charge)
          << " formula="
          << peptideNaturalIsotope.get()->getFormula(charge).toStdString()
          << std::endl;
        rank++;
      }
    REQUIRE(isotopeAverage.getComponents().size() == 8);

    PrecisionPtr precision2 = PrecisionFactory::getDaltonInstance(0.2);
    PeptideNaturalIsotopeAverage isotopeAverage2(
      peptide.makePeptideSp(), 1, isotopeLevel, charge, precision2);

    std::cout << "monosiotope mz=" << peptide.getMz(charge)
              << "average mz=" << isotopeAverage2.getMz() << std::endl;
    std::cout << "intensity ratio =" << isotopeAverage2.getIntensityRatio()
              << std::endl;
    std::cout << "z=" << isotopeAverage2.getCharge() << std::endl;

    std::cout << "sum of :" << std::endl;
    rank = 1;
    for(auto &&peptideNaturalIsotope : isotopeAverage2.getComponents())
      {
        std::cout
          << "number=" << isotopeAverage2.getIsotopeNumber() << " rank=" << rank
          << " mz=" << peptideNaturalIsotope.get()->getMz(charge)
          << " ratio=" << peptideNaturalIsotope.get()->getIntensityRatio(charge)
          << " formula="
          << peptideNaturalIsotope.get()->getFormula(charge).toStdString()
          << std::endl;
        rank++;
      }
    REQUIRE(isotopeAverage2.getComponents().size() == 11);
    /*
    Spectrum spectrum_low_masses(spectrum_parent.applyCutOff(150));
    if (! spectrum_low_masses.equals(sremove_low_masses, precision)) {
       std::cerr << "spectrum_low_masses() != tandem"<< std::endl;
       return 1;
    }*/


    std::cout << std::endl
              << "..:: Test natural isotope average on labelled peptide ::.."
              << std::endl;

    peptide.addAaModification(AaModification::getInstance("MOD:00587"), 14);

    std::cout << std::endl
              << "labelled formula " << peptide.getFormula(1).toStdString()
              << std::endl;

    PeptideNaturalIsotopeAverage isotopeAverage_labeled(peptide.makePeptideSp(),
                                                        askedIsotopeRank,
                                                        isotopeLevel,
                                                        charge,
                                                        precision);


    std::cout << "labeled monosiotope mz=" << peptide.getMz(charge)
              << "average mz=" << isotopeAverage_labeled.getMz() << std::endl;
    std::cout << "intensity ratio ="
              << isotopeAverage_labeled.getIntensityRatio() << std::endl;
    std::cout << "z=" << isotopeAverage_labeled.getCharge() << std::endl;

    std::cout << "sum of :" << std::endl;
    rank = 1;
    for(auto &&peptideNaturalIsotope : isotopeAverage_labeled.getComponents())
      {
        std::cout
          << "labeled number=" << isotopeAverage_labeled.getIsotopeNumber()
          << " rank=" << rank
          << " mz=" << peptideNaturalIsotope.get()->getMz(charge)
          << " ratio=" << peptideNaturalIsotope.get()->getIntensityRatio(charge)
          << " formula="
          << peptideNaturalIsotope.get()->getFormula(charge).toStdString()
          << std::endl;
        rank++;
      }


    // peptideSp.get()->getSequence()= "AGYEVRDVHYSHYGR"  max_isotope_number= 3
    // spectrum.size= 307  parent_charge= 3
    ////ion_type_list.size= 9  max_isotope_rank= 2

    PeptideNaturalIsotopeList isotope_list(peptide.makePeptideSp());
    PeptideNaturalIsotopeAverage isotopeAverage_labeled2(
      isotope_list, askedIsotopeRank, isotopeLevel, charge, precision);

    REQUIRE(isotopeAverage_labeled.getMz() ==
            Catch::Approx(isotopeAverage_labeled2.getMz()));
  }
}