NCBI C++ ToolKit
MSResponse.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: MSResponse.cpp 57972 2013-04-29 16:10:52Z grichenk $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Author: .......
27  *
28  * File Description:
29  * .......
30  *
31  * Remark:
32  * This code was originally generated by application DATATOOL
33  * using the following specifications:
34  * 'omssa.asn'.
35  */
36 
37 // standard includes
38 #include <ncbi_pch.hpp>
39 
40 // generated includes
42 
43 // generated classes
44 
46 
47 BEGIN_objects_SCOPE // namespace ncbi::objects::
48 
49 // destructor
51 {
52 }
53 
54 ///////////////////////////////////////////////////////////////////
55 // interfaces implementation for Print .csv
56 ///////////////////////////////////////////////////////////////////
57 string CMSResponse::CSVString(const string& in)
58 {
59 
60  string retval;
61  retval = NStr::Replace(in, "\"", "\"\"");
62  if(retval.find_first_of(",\"") < retval.size()) retval = "\"" + retval + "\"";
63  return retval;
64 }
65 
66 void CMSResponse::PrintCSV(ostream& os, CRef <CMSModSpecSet> ModSet)
67 {
68  if(!CanGetHitsets() ) return;
69 
70  os.precision(15);
71 
72  os << "Spectrum number, Filename/id, Peptide, E-value, Mass, gi, Accession, Start, Stop, Defline, Mods, Charge, Theo Mass, P-value, NIST score" << endl;
73  // read out hits
74 
75  CMSResponse::THitsets::const_iterator iHits;
76  iHits = GetHitsets().begin();
77  double fMZ_scale = CanGetScale() ? GetScale() : 100.0;
78  for(; iHits != GetHitsets().end(); iHits++)
79  {
80  CRef< CMSHitSet > HitSet = *iHits;
81  if( HitSet-> CanGetError() && HitSet->GetError() == eMSHitError_notenuffpeaks)
82  {
83  continue;
84  }
85 
86  CRef< CMSHits > Hit;
87  CMSHitSet::THits::const_iterator iHit;
88  CMSHits::TPephits::const_iterator iPephit;
89  for(iHit = HitSet->GetHits().begin(); iHit != HitSet->GetHits().end(); iHit++)
90  {
91  string id;
92  if (HitSet->GetIds().begin() != HitSet->GetIds().end())
93  id = *(HitSet->GetIds().begin());
94  double NISTScore (0.0L);
95  if ((*iHit)->CanGetScores()) {
96  ITERATE(CMSHits::TScores, iNISTScore, (*iHit)->GetScores()) {
97  if((*iNISTScore)->GetName() == "NIST Score")
98  NISTScore = (*iNISTScore)->GetValue();
99  }
100  }
101 
102  for(iPephit = (*iHit)->GetPephits().begin(); iPephit != (*iHit)->GetPephits().end(); iPephit++)
103  {
104  string PepString;
105  (*iHit)->MakePepString(PepString);
106  string ModString;
107  (*iHit)->MakeModString(ModString, ModSet);
108  string Accession("");
109  if((*iPephit)->CanGetAccession())
110  Accession = CSVString((*iPephit)->GetAccession());
111  TGi Gi = ZERO_GI;
112  if((*iPephit)->CanGetGi())
113  Gi = (*iPephit)->GetGi();
114  os << HitSet->GetNumber() << "," << CSVString(id) << "," <<
115  CSVString(PepString) << "," <<
116  (*iHit)->GetEvalue() << "," << (*iHit)->GetMass()/fMZ_scale << "," <<
117  Gi << "," << Accession << "," <<
118  (*iPephit)->GetStart() + 1 << "," << (*iPephit)->GetStop() + 1 << "," <<
119  CSVString((*iPephit)->GetDefline()) << "," << CSVString(ModString) <<
120  "," << (*iHit)->GetCharge() <<
121  "," << (*iHit)->GetTheomass()/fMZ_scale <<
122  "," << (*iHit)->GetPvalue() <<
123  "," << NISTScore << endl;
124  }
125  }
126  }
127 }
128 // ------------------------ END Print .csv ---------------------------------
129 
130 
131 void
133  const double Threshold) const
134 {
135  ITERATE(THitsets, iHitSet, GetHitsets()) {
136  ITERATE(CMSHitSet::THits, iHit, (*iHitSet)->GetHits()) {
137  ITERATE(CMSHits::TPephits, iPepHit, (*iHit)->GetPephits()) {
138  if((*iHit)->GetEvalue() <= Threshold) {
139  OidSet.insert((*iPepHit)->GetOid());
140  }
141  }
142  }
143  }
144 }
145 
146 
148 CMSResponse::FindHitSet(const int Number) const
149 {
150  ITERATE(THitsets, iHitSet, GetHitsets()) {
151  if((*iHitSet)->GetNumber() == Number) return *iHitSet;
152  }
153  return null;
154 }
155 
156 
157 END_objects_SCOPE // namespace ncbi::objects::
158 
160 
161 /* Original file checksum: lines: 65, chars: 1890, CRC32: 485ecdcb */
User-defined methods of the data storage class.
void PrintCSV(ostream &os, CRef< CMSModSpecSet > ModSet)
Definition: MSResponse.cpp:66
void GetOidsBelowThreshold(TOidSet &OidSet, const double Threshold) const
insert oids into oidset if hit is below threhold
Definition: MSResponse.cpp:132
CRef< CMSHitSet > FindHitSet(const int Number) const
Find hitset with given number.
Definition: MSResponse.cpp:148
string CSVString(const string &in)
Definition: MSResponse.cpp:57
~CMSResponse(void)
Definition: MSResponse.cpp:50
iterator_bool insert(const value_type &val)
Definition: set.hpp:149
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define ZERO_GI
Definition: ncbimisc.hpp:1088
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
static string & Replace(const string &src, const string &search, const string &replace, string &dst, SIZE_TYPE start_pos=0, SIZE_TYPE max_replace=0, SIZE_TYPE *num_replace=0)
Replace occurrences of a substring within a string.
Definition: ncbistr.cpp:3310
list< CRef< CMSScoreSet > > TScores
Definition: MSHits_.hpp:107
vector< CRef< CMSHits > > THits
Definition: MSHitSet_.hpp:97
TScale GetScale(void) const
Get the Scale member data.
const THitsets & GetHitsets(void) const
Get the Hitsets member data.
bool CanGetScale(void) const
Check if it is safe to call GetScale method.
vector< CRef< CMSHitSet > > THitsets
Definition: MSResponse_.hpp:93
bool CanGetError(void) const
Check if it is safe to call GetError method.
bool CanGetHitsets(void) const
Check if it is safe to call GetHitsets method.
list< CRef< CMSPepHit > > TPephits
Definition: MSHits_.hpp:97
@ eMSHitError_notenuffpeaks
not enough peaks to search
Definition: MSHitError_.hpp:68
std::istream & in(std::istream &in_, double &x_)
Modified on Thu Mar 28 17:06:04 2024 by modify_doxy.py rev. 669887