~ubuntu-branches/ubuntu/wily/openms/wily

« back to all changes in this revision

Viewing changes to source/TEST/FalseDiscoveryRate_test.C

  • Committer: Package Import Robot
  • Author(s): Filippo Rusconi
  • Date: 2012-11-12 15:58:12 UTC
  • Revision ID: package-import@ubuntu.com-20121112155812-vr15wtg9b50cuesg
Tags: upstream-1.9.0
ImportĀ upstreamĀ versionĀ 1.9.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// -*- mode: C++; tab-width: 2; -*-
 
2
// vi: set ts=2:
 
3
//
 
4
// --------------------------------------------------------------------------
 
5
//                   OpenMS Mass Spectrometry Framework
 
6
// --------------------------------------------------------------------------
 
7
//  Copyright (C) 2003-2011 -- Oliver Kohlbacher, Knut Reinert
 
8
//
 
9
//  This library is free software; you can redistribute it and/or
 
10
//  modify it under the terms of the GNU Lesser General Public
 
11
//  License as published by the Free Software Foundation; either
 
12
//  version 2.1 of the License, or (at your option) any later version.
 
13
//
 
14
//  This library is distributed in the hope that it will be useful,
 
15
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
17
//  Lesser General Public License for more details.
 
18
//
 
19
//  You should have received a copy of the GNU Lesser General Public
 
20
//  License along with this library; if not, write to the Free Software
 
21
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
22
//
 
23
// --------------------------------------------------------------------------
 
24
// $Maintainer: Chris Bielow $
 
25
// $Authors: Andreas Bertsch $
 
26
// --------------------------------------------------------------------------
 
27
 
 
28
#include <OpenMS/CONCEPT/ClassTest.h>
 
29
#include <OpenMS/FORMAT/IdXMLFile.h>
 
30
 
 
31
///////////////////////////
 
32
#include <OpenMS/ANALYSIS/ID/FalseDiscoveryRate.h>
 
33
///////////////////////////
 
34
 
 
35
using namespace OpenMS;
 
36
using namespace std;
 
37
 
 
38
START_TEST(FalseDiscoveryRate, "$Id: FalseDiscoveryRate_test.C 8907 2011-09-29 12:58:48Z aiche $")
 
39
 
 
40
/////////////////////////////////////////////////////////////
 
41
/////////////////////////////////////////////////////////////
 
42
 
 
43
FalseDiscoveryRate* ptr = 0;
 
44
FalseDiscoveryRate* nullPointer = 0;
 
45
START_SECTION(FalseDiscoveryRate())
 
46
{
 
47
        ptr = new FalseDiscoveryRate();
 
48
        TEST_NOT_EQUAL(ptr, nullPointer)
 
49
}
 
50
END_SECTION
 
51
 
 
52
START_SECTION(~FalseDiscoveryRate())
 
53
{
 
54
        delete ptr;
 
55
}
 
56
END_SECTION
 
57
 
 
58
START_SECTION((void apply(std::vector< PeptideIdentification > &fwd_ids, std::vector< PeptideIdentification > &rev_ids)))
 
59
{
 
60
  ptr = new FalseDiscoveryRate();
 
61
        vector<ProteinIdentification> fwd_prot_ids, rev_prot_ids;
 
62
        vector<PeptideIdentification> fwd_pep_ids, rev_pep_ids;
 
63
        String document_id;
 
64
        IdXMLFile().load(OPENMS_GET_TEST_DATA_PATH("XTandem_fwd_ids.idXML"), fwd_prot_ids, fwd_pep_ids, document_id);
 
65
        IdXMLFile().load(OPENMS_GET_TEST_DATA_PATH("XTandem_rev_ids.idXML"), rev_prot_ids, rev_pep_ids, document_id);
 
66
        ptr->apply(fwd_pep_ids, rev_pep_ids);
 
67
        TOLERANCE_ABSOLUTE(0.0001)
 
68
        for (vector<PeptideIdentification>::const_iterator it = fwd_pep_ids.begin(); it != fwd_pep_ids.end(); ++it)
 
69
        {
 
70
                if (it->getHits().size() > 0)
 
71
                {
 
72
                        PeptideHit hit(*it->getHits().begin());
 
73
                        DoubleReal fdr(hit.getScore());
 
74
                        DoubleReal orig_score((DoubleReal)hit.getMetaValue("XTandem_score"));
 
75
 
 
76
                        if (orig_score >= 39.4)
 
77
                        {
 
78
                                TEST_REAL_SIMILAR(fdr, 0)
 
79
                        }
 
80
                        if (orig_score <= 37.9 + 0.0001 && orig_score >= 37.9 - 0.0001)
 
81
                        {
 
82
                                TEST_REAL_SIMILAR(fdr, 0.08)
 
83
                        }
 
84
                }
 
85
        }
 
86
}
 
87
END_SECTION
 
88
 
 
89
START_SECTION((void apply(std::vector< ProteinIdentification > &fwd_ids, std::vector< ProteinIdentification > &rev_ids)))
 
90
{
 
91
  vector<ProteinIdentification> fwd_prot_ids, rev_prot_ids;
 
92
  vector<PeptideIdentification> fwd_pep_ids, rev_pep_ids;
 
93
  String document_id;
 
94
  IdXMLFile().load(OPENMS_GET_TEST_DATA_PATH("XTandem_fwd_ids_withProtScores.idXML"), fwd_prot_ids, fwd_pep_ids, document_id);
 
95
  IdXMLFile().load(OPENMS_GET_TEST_DATA_PATH("XTandem_rev_ids_withProtScores.idXML"), rev_prot_ids, rev_pep_ids, document_id);
 
96
  ptr->apply(fwd_prot_ids, rev_prot_ids);
 
97
  TOLERANCE_ABSOLUTE(0.001)
 
98
        
 
99
        for (vector<ProteinIdentification>::const_iterator prot_it = fwd_prot_ids.begin(); prot_it != fwd_prot_ids.end(); ++prot_it)
 
100
        {
 
101
                if (prot_it->getHits().size() > 0)
 
102
                {
 
103
                        for (vector<ProteinHit>::const_iterator it = prot_it->getHits().begin(); it != prot_it->getHits().end(); ++it)
 
104
                        {
 
105
                                ProteinHit hit(*it);
 
106
                                DoubleReal fdr(hit.getScore());
 
107
                                DoubleReal orig_score((DoubleReal)hit.getMetaValue("XTandem_score"));
 
108
        
 
109
        // it gets here, but neither of the conditions below are ever satisfied
 
110
                                if (orig_score < -1.8)
 
111
                                {
 
112
                                        TEST_REAL_SIMILAR(fdr, 0)
 
113
                                }
 
114
        if (orig_score == 0.0)
 
115
                                {
 
116
                                        TEST_REAL_SIMILAR(fdr, 0.897384)
 
117
                                }
 
118
                        }
 
119
                }
 
120
        }
 
121
}
 
122
END_SECTION
 
123
 
 
124
START_SECTION((void apply(std::vector< PeptideIdentification > &id)))
 
125
{
 
126
        vector<ProteinIdentification> prot_ids;
 
127
  vector<PeptideIdentification> pep_ids;
 
128
  IdXMLFile().load(OPENMS_GET_TEST_DATA_PATH("FalseDiscoveryRate_OMSSA.idXML"), prot_ids, pep_ids);
 
129
 
 
130
  ptr->apply(pep_ids);
 
131
  TOLERANCE_ABSOLUTE(0.001)
 
132
        for (Size z = 1; z <= 4; ++z)
 
133
        {
 
134
                for (vector<PeptideIdentification>::const_iterator it = pep_ids.begin(); it != pep_ids.end(); ++it)
 
135
        {
 
136
                        for (vector<PeptideHit>::const_iterator pit = it->getHits().begin(); pit != it->getHits().end(); ++pit)
 
137
                        {
 
138
        DoubleReal fdr(pit->getScore());
 
139
        DoubleReal orig_score((DoubleReal)pit->getMetaValue("OMSSA_score"));
 
140
 
 
141
        if (orig_score <= 10e-4)
 
142
        {
 
143
                TEST_REAL_SIMILAR(fdr, 0)
 
144
        }
 
145
        if (orig_score >= 1000 && pit->getCharge() != 1)
 
146
        {
 
147
                TEST_EQUAL(fdr > 0.1, true)
 
148
        }
 
149
                        }
 
150
    }
 
151
  }
 
152
}
 
153
END_SECTION
 
154
 
 
155
START_SECTION((void apply(std::vector<ProteinIdentification>& ids)))
 
156
{
 
157
        vector<ProteinIdentification> fwd_prot_ids, rev_prot_ids, prot_ids;
 
158
  vector<PeptideIdentification> fwd_pep_ids, rev_pep_ids, pep_ids;
 
159
  String document_id;
 
160
  IdXMLFile().load(OPENMS_GET_TEST_DATA_PATH("XTandem_fwd_ids.idXML"), fwd_prot_ids, fwd_pep_ids, document_id);
 
161
  IdXMLFile().load(OPENMS_GET_TEST_DATA_PATH("XTandem_rev_ids.idXML"), rev_prot_ids, rev_pep_ids, document_id);
 
162
 
 
163
        for (vector<ProteinIdentification>::const_iterator it = fwd_prot_ids.begin(); it != fwd_prot_ids.end(); ++it)
 
164
        {
 
165
                prot_ids.push_back(*it);
 
166
        }
 
167
 
 
168
        for (vector<ProteinIdentification>::const_iterator it = rev_prot_ids.begin(); it != rev_prot_ids.end(); ++it)
 
169
        {
 
170
                prot_ids.push_back(*it);
 
171
        }
 
172
 
 
173
        ptr->apply(prot_ids);
 
174
 
 
175
  TOLERANCE_ABSOLUTE(0.001)
 
176
 
 
177
  for (vector<ProteinIdentification>::const_iterator prot_it = prot_ids.begin(); prot_it != prot_ids.end(); ++prot_it)
 
178
  {
 
179
    if (prot_it->getHits().size() > 0)
 
180
    {
 
181
      for (vector<ProteinHit>::const_iterator it = prot_it->getHits().begin(); it != prot_it->getHits().end(); ++it)
 
182
      {
 
183
        ProteinHit hit(*it);
 
184
        DoubleReal fdr(hit.getScore());
 
185
        DoubleReal orig_score((DoubleReal)hit.getMetaValue("XTandem_score"));
 
186
 
 
187
        if (orig_score < -1.8)
 
188
        {
 
189
          TEST_REAL_SIMILAR(fdr, 0)
 
190
        }
 
191
        if (orig_score == -1.7)
 
192
        {
 
193
          TEST_REAL_SIMILAR(fdr, 0.0617284)
 
194
        }
 
195
                                if (orig_score > -1.2)
 
196
                                {
 
197
                                        TEST_EQUAL(fdr > 0.1, true)
 
198
                                }
 
199
      }
 
200
    }
 
201
  }
 
202
}
 
203
END_SECTION
 
204
 
 
205
/////////////////////////////////////////////////////////////
 
206
/////////////////////////////////////////////////////////////
 
207
END_TEST
 
208
 
 
209
 
 
210