NCBI C++ ToolKit
msladder.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: msladder.hpp 34257 2007-06-13 21:12:09Z lewisg $
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 authors in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors: Lewis Y. Geer
27  *
28  * File Description:
29  * Classes to deal with ladders of m/z values
30  *
31  * ===========================================================================
32  */
33 
34 #ifndef MSLADDER__HPP
35 #define MSLADDER__HPP
36 
37 #include <corelib/ncbimisc.hpp>
39 
40 #include <set>
41 #include <iostream>
42 #include <vector>
43 
44 #include "msms.hpp"
45 #include "omssascore.hpp"
46 
49 BEGIN_SCOPE(omssa)
50 
51 
52 // container for mass ladders
53 typedef int THit;
54 
55 // max size of ladder
56 const int kMSLadderMax = 10000;
57 
58 /** container for intensity */
59 typedef AutoArray <unsigned> TIntensity;
60 
61 /** container for mass deltas */
62 typedef AutoArray <int> TDelta;
63 
64 /** container for ion series number */
66 
67 /////////////////////////////////////////////////////////////////////////////
68 //
69 // CLadder::
70 //
71 // Contains a theoretical m/z ladder
72 //
73 
75 public:
76 
77  // 'tor's
78  ~CLadder();
79  CLadder(void);
80  CLadder(int SizeIn);
81  CLadder(const CLadder& Old);
82 
83  // vector operations on the ladder
84  int& operator [] (int n);
85  int size(void);
86  void clear(void);
87 
88  /**
89  * make a ladder
90  *
91  * @param IonType the ion series to create
92  * @param Charge the charge of the series
93  * @param Sequence the protein sequence
94  * @param SeqIndex the position in the blast library
95  * @param start start position in the sequence
96  * @param stop the stop position in the sequence
97  * @param MassArray AA masses
98  * @param AA used for mass calculation
99  * @param ModMask bit mask of modifications to use
100  * @param ModList modification information
101  * @param NumMod the total number of mods
102  * @param Settings search settings
103  * @param NoProline do not create ions nterm to prolines
104  *
105  * @return false if fails
106  */
107  const bool CreateLadder(const int IonType,
108  const int Charge,
109  const char * const Sequence,
110  const int SeqIndex,
111  const int start,
112  const int stop,
113  const int mass,
114  const CMassArray& MassArray,
115  const CAA &AA,
116  const unsigned ModMask,
117  const CMod ModList[],
118  const int NumMod,
119  const CMSSearchSettings& Settings,
120  const bool NoProline
121  );
122 
123  /**
124  * calculate the mass difference
125  *
126  * @param IntMassArray amino acid masses
127  * @param AAMap convert aa to index
128  * @param Sequence the sequence
129  * @param Offset start position in the sequence
130  * @param Direction the direction of the ion series
131  * @param NumMod number of modifications
132  * @param ModIndex position of the modifications
133  * @param ModList modification info
134  * @param ModMask modification mask
135  * @param i index into sequence
136  * @param ion the ladder
137  * @param ChargeIn charge state
138  * @param SearchType what type of mass search (exact, ...)
139  * @param ExactMass exact mass threshold
140  */
141  bool CalcDelta(const int *IntMassArray,
142  const char * const AAMap,
143  const char *Sequence,
144  int Offset,
145  int Direction,
146  int NumMod,
147  int &ModIndex,
148  const CMod ModList[],
149  unsigned ModMask,
150  int i,
151  int& ion,
152  const int ChargeIn,
153  EMSSearchType SearchType,
154  double ExactMass);
155 
156 
157  // check if modification mask position is set
158  bool MaskSet(unsigned ModMask, int ModIndex);
159 
160  // getter setters
161  THit * GetHit(void);
162  int GetStart(void);
163  int GetStop(void);
164  int GetSeqIndex(void);
165  int GetType(void);
166  int GetMass(void);
167  int GetCharge(void);
168 
169  // sees if ladder contains the given mass value
170  bool Contains(int MassIndex, int Tolerance);
171  bool ContainsFast(int MassIndex, int Tolerance);
172 
173  // or's hitlist with hitlist from other ladder
174  // takes into account direction
175  void Or(CLadder& LadderIn);
176 
177  // count the number of matches
178  int HitCount(void);
179 
180  // clear the Hitlist
181  void ClearHits(void);
182 
183  /**
184  * Get the intensity array
185  */
186  const TIntensity& GetIntensity(void) const;
187 
188  /**
189  * Set the intensity array
190  */
191  TIntensity& SetIntensity(void);
192 
193  /**
194  * Get the mass delta array
195  */
196  const TDelta& GetDelta(void) const;
197 
198  /**
199  * Set the mass delta array
200  */
201  TDelta& SetDelta(void);
202 
203  /**
204  * Get the number of matches
205  */
206  const int GetM(void) const;
207 
208  /**
209  * Set the number of matches
210  */
211  int& SetM(void);
212 
213  /**
214  * Get the sum of ranks of matched peaks
215  */
216  const int GetSum(void) const;
217 
218  /**
219  * Set the sum of ranks of matched peaks
220  */
221  int& SetSum(void);
222 
223  /**
224  * Return the array containing the number of the ions
225  *
226  * @return const TMSNumber
227  */
228  const TLadderNumber& GetLadderNumber(void) const;
229 
230  /**
231  * Return the array containing the number of the ions
232  *
233  * @return TMSNumber&
234  */
235  TLadderNumber& SetLadderNumber(void);
236 
237 private:
238  int LadderIndex; // current end of the ladder
239 
240  /** mass ladder */
242 
243  /** hit count for a given m/z value */
245 
246  /** number of ion in the series */
248 
249  /** intensity of matched peaks */
251 
252  /** mass deltas between theoretical and experimental */
254 
255  int LadderSize; // size of allocated buffer
256  int Start, Stop; // inclusive start and stop position in sequence
257  int Index; // gi or position in blastdb
258  int Type; // ion type
259  int Mass; // *neutral* precursor mass (Mr)
260  int Charge;
261  /** number of matched peaks */
262  int M;
263  /** sum of ranks of matched peaks */
264  int Sum;
265 };
266 
267 
268 /////////////////// CLadder inline methods
269 
270 inline
271 bool CLadder::CalcDelta(const int *IntMassArray,
272  const char * const AAMap,
273  const char *Sequence,
274  int Offset,
275  int Direction,
276  int NumMod,
277  int &ModIndex,
278  const CMod ModList[],
279  unsigned ModMask,
280  int i,
281  int& ion,
282  const int ChargeIn,
283  EMSSearchType SearchType,
284  double ExactMass)
285 {
286  int delta = IntMassArray[AAMap[Sequence[Offset + Direction*i]]];
287  if(!delta) return false; // unusable char (-BXZ*)
288 
289  // check for mods
290  while(NumMod > 0 && ModIndex >= 0 && ModIndex < NumMod &&
291  ModList[ModIndex].GetSite() == &(Sequence[Offset + Direction*i])) {
292  if (MaskSet(ModMask, ModIndex)) {
293  delta += ModList[ModIndex].GetProductDelta();
294  }
295  ModIndex += Direction;
296  }
297 
298  // increment the ladder
299 
300  // first check to see if exact mass increment needed
301  if(SearchType == eMSSearchType_exact) {
302  if ((ion * ChargeIn)/MSSCALE2INT(ExactMass) !=
303  (ion * ChargeIn + delta) / MSSCALE2INT(ExactMass))
304  ion += MSSCALE2INT(kNeutron)/ChargeIn;
305  }
306 
307  ion += delta/ChargeIn;
308  return true;
309 }
310 
311 inline int& CLadder::operator [] (int n)
312 {
313  return *(Ladder.get() + n);
314 }
315 
316 inline int CLadder::size(void)
317 {
318  return LadderIndex;
319 }
320 
321 inline void CLadder::clear(void)
322 {
323  LadderIndex = 0;
324 }
325 
326 inline THit * CLadder::GetHit(void)
327 {
328  return Hit.get();
329 }
330 
331 inline int CLadder::GetStart(void)
332 {
333  return Start;
334 }
335 
336 inline int CLadder::GetStop(void)
337 {
338  return Stop;
339 }
340 
341 inline int CLadder::GetSeqIndex(void)
342 {
343  return Index;
344 }
345 
346 inline int CLadder::GetType(void)
347 {
348  return Type;
349 }
350 
351 inline int CLadder::GetMass(void)
352 {
353  return Mass;
354 }
355 
356 inline int CLadder::GetCharge(void)
357 {
358  return Charge;
359 }
360 
361 // count the number of matches
362 inline int CLadder::HitCount(void)
363 {
364  int i, retval(0);
365  for(i = 0; i < LadderIndex && i < LadderSize; i++)
366  retval += *(Hit.get() + i);
367  return retval;
368 }
369 
370 // clear the Hitlist
371 inline void CLadder::ClearHits(void)
372 {
373  int i;
374  for(i = 0; i < LadderIndex && i < LadderSize; i++)
375  *(Hit.get() + i) = 0;
376 }
377 
378 inline bool CLadder::MaskSet(unsigned ModMask, int ModIndex)
379 {
380  return (bool) (ModMask & (1 << ModIndex));
381 }
382 
383 inline
385 {
386  return Intensity;
387 }
388 
389 inline
391 {
392  return Intensity;
393 }
394 
395 inline
396 const TDelta& CLadder::GetDelta(void) const
397 {
398  return Delta;
399 }
400 
401 inline
403 {
404  return Delta;
405 }
406 
407 inline
408 const int CLadder::GetM(void) const
409 {
410  return M;
411 }
412 
413 inline
414 int& CLadder::SetM(void)
415 {
416  return M;
417 }
418 
419 inline
420 const int CLadder::GetSum(void) const
421 {
422  return Sum;
423 }
424 
425 inline
426 int& CLadder::SetSum(void)
427 {
428  return Sum;
429 }
430 
431 inline
433 {
434  return LadderNumber;
435 }
436 
437 inline
439 {
440  return LadderNumber;
441 }
442 
443 /////////////////// end of CLadder inline methods
444 
445 
446 
447 typedef vector < CRef <CLadder> > TLadderList;
449 typedef pair <int, TLadderListPtr > TLadderMapPair;
451 typedef list <TSeriesChargePair> TSeriesChargePairList;
452 
453 
455  public:
456 
457  /**
458  * returns the laddermap (maps key based on charge and series type to a vector of CLadder)
459  */
460  TLadderMap& SetLadderMap(void);
461 
462  /**
463  * returns const laddermap
464  */
465  const TLadderMap& GetLadderMap(void) const;
466 
467  /**
468  * return the list of charge, series type pairs that are used to
469  * initialize the maps
470  */
471  TSeriesChargePairList& SetSeriesChargePairList(void);
472 
473  /**
474  * return the list of charge, series type pairs that are used to
475  * initialize the maps
476  */
477  const TSeriesChargePairList& GetSeriesChargePairList(void) const;
478 
479  /**
480  * iterate over the ladder map over the charge range and series type indicated
481  *
482  * @param Iter the iterator
483  * @param BeginCharge the minimum charge to look for (0=all)
484  * @param EndCharge the maximum charge to look for (0=all)
485  * @param SeriesType the type of the ion series
486  */
487  void Next(TLadderMap::iterator& Iter,
488  TMSCharge BeginCharge = 0,
489  TMSCharge EndCharge = 0,
490  TMSIonSeries SeriesType = eMSIonTypeUnknown);
491 
492 
493  void Begin(TLadderMap::iterator& Iter,
494  TMSCharge BeginCharge = 0,
495  TMSCharge EndCharge = 0,
496  TMSIonSeries SeriesType = eMSIonTypeUnknown);
497 
498 
499  /**
500  * populate the Ladder Map with arrays based on the ladder
501  *
502  * @param MaxModPerPep size of the arrays
503  * @param MaxLadderSize size of the ladders
504  */
505  void CreateLadderArrays(int MaxModPerPep, int MaxLadderSize);
506 
507 
508  private:
509 
510  /**
511  * see if key of the map element pointed to by Iter matches the conditions
512  *
513  * @param Iter the iterator
514  * @param BeginCharge the minimum charge to look for (0=all)
515  * @param EndCharge the maximum charge to look for (0=all)
516  * @param SeriesType the type of the ion series
517  */
518  bool MatchIter(TLadderMap::iterator& Iter,
519  TMSCharge BeginCharge = 0,
520  TMSCharge EndCharge = 0,
521  TMSIonSeries SeriesType = eMSIonTypeUnknown);
522  /**
523  * contains a map from charge, ion series to the CLadderArrays
524  * the key is gotten from CMSMatchedPeakSetMap::ChargeSeries2Key
525  */
527 
528  /**
529  * contains the series, charge of the ion series to be generated
530  */
532 };
533 
534 inline
535 TLadderMap&
537 {
538  return LadderMap;
539 }
540 
541 inline
542 const TLadderMap&
544 {
545  return LadderMap;
546 }
547 
548 inline
551 {
552  return SeriesChargePairList;
553 }
554 
555 inline
556 const TSeriesChargePairList&
558 {
559  return SeriesChargePairList;
560 }
561 
562 
563 END_SCOPE(omssa)
566 
567 #endif
568 
#define MSSCALE2INT(x)
Definition: MSMod.hpp:64
AutoArray –.
Definition: ncbimisc.hpp:527
AutoPtr –.
Definition: ncbimisc.hpp:401
Definition: msms.hpp:143
TSeriesChargePairList & SetSeriesChargePairList(void)
return the list of charge, series type pairs that are used to initialize the maps
Definition: msladder.hpp:550
TLadderMap LadderMap
contains a map from charge, ion series to the CLadderArrays the key is gotten from CMSMatchedPeakSetM...
Definition: msladder.hpp:526
const TLadderMap & GetLadderMap(void) const
returns const laddermap
Definition: msladder.hpp:543
TSeriesChargePairList SeriesChargePairList
contains the series, charge of the ion series to be generated
Definition: msladder.hpp:531
TLadderMap & SetLadderMap(void)
returns the laddermap (maps key based on charge and series type to a vector of CLadder)
Definition: msladder.hpp:536
const TSeriesChargePairList & GetSeriesChargePairList(void) const
return the list of charge, series type pairs that are used to initialize the maps
Definition: msladder.hpp:557
void ClearHits(void)
Definition: msladder.hpp:371
int GetMass(void)
Definition: msladder.hpp:351
int Mass
Definition: msladder.hpp:259
int LadderSize
Definition: msladder.hpp:255
TIntensity & SetIntensity(void)
Set the intensity array.
Definition: msladder.hpp:390
int Stop
Definition: msladder.hpp:256
int HitCount(void)
Definition: msladder.hpp:362
const TDelta & GetDelta(void) const
Get the mass delta array.
Definition: msladder.hpp:396
bool CalcDelta(const int *IntMassArray, const char *const AAMap, const char *Sequence, int Offset, int Direction, int NumMod, int &ModIndex, const CMod ModList[], unsigned ModMask, int i, int &ion, const int ChargeIn, EMSSearchType SearchType, double ExactMass)
calculate the mass difference
Definition: msladder.hpp:271
int & SetSum(void)
Set the sum of ranks of matched peaks.
Definition: msladder.hpp:426
const TIntensity & GetIntensity(void) const
Get the intensity array.
Definition: msladder.hpp:384
int GetType(void)
Definition: msladder.hpp:346
int LadderIndex
Definition: msladder.hpp:238
TLadderNumber LadderNumber
number of ion in the series
Definition: msladder.hpp:247
AutoPtr< int, ArrayDeleter< int > > Ladder
mass ladder
Definition: msladder.hpp:241
int GetStop(void)
Definition: msladder.hpp:336
int Charge
Definition: msladder.hpp:260
const int GetSum(void) const
Get the sum of ranks of matched peaks.
Definition: msladder.hpp:420
TDelta Delta
mass deltas between theoretical and experimental
Definition: msladder.hpp:253
AutoPtr< THit, ArrayDeleter< THit > > Hit
hit count for a given m/z value
Definition: msladder.hpp:244
int GetCharge(void)
Definition: msladder.hpp:356
int & SetM(void)
Set the number of matches.
Definition: msladder.hpp:414
int Start
Definition: msladder.hpp:256
void clear(void)
Definition: msladder.hpp:321
int GetSeqIndex(void)
Definition: msladder.hpp:341
TLadderNumber & SetLadderNumber(void)
Return the array containing the number of the ions.
Definition: msladder.hpp:438
TDelta & SetDelta(void)
Set the mass delta array.
Definition: msladder.hpp:402
int Sum
sum of ranks of matched peaks
Definition: msladder.hpp:264
int Index
Definition: msladder.hpp:257
int Type
Definition: msladder.hpp:258
bool MaskSet(unsigned ModMask, int ModIndex)
Definition: msladder.hpp:378
THit * GetHit(void)
Definition: msladder.hpp:326
int GetStart(void)
Definition: msladder.hpp:331
int & operator[](int n)
Definition: msladder.hpp:311
const int GetM(void) const
Get the number of matches.
Definition: msladder.hpp:408
int size(void)
Definition: msladder.hpp:316
const TLadderNumber & GetLadderNumber(void) const
Return the array containing the number of the ions.
Definition: msladder.hpp:432
int M
number of matched peaks
Definition: msladder.hpp:262
TIntensity Intensity
intensity of matched peaks
Definition: msladder.hpp:250
@MSSearchSettings.hpp User-defined methods of the data storage class.
contains information for a post translational modification at a particular sequence site
Definition: msms.hpp:172
TMass GetProductDelta(void) const
Get the mass to be added to the product mass.
Definition: msms.hpp:379
CObject –.
Definition: ncbiobj.hpp:180
string Offset()
element_type * get(void) const
Get pointer.
Definition: ncbimisc.hpp:469
CBeginInfo Begin(C &obj)
Get starting point of object hierarchy.
Definition: iterator.hpp:1004
TSeqPos GetStop(const CSeq_loc &loc, CScope *scope, ESeqLocExtremes ext=eExtreme_Positional)
If only one CBioseq is represented by CSeq_loc, returns the position at the stop of the location.
TSeqPos GetStart(const CSeq_loc &loc, CScope *scope, ESeqLocExtremes ext=eExtreme_Positional)
If only one CBioseq is represented by CSeq_loc, returns the position at the start of the location.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define END_SCOPE(ns)
End the previously defined scope.
Definition: ncbistl.hpp:75
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define BEGIN_SCOPE(ns)
Define a new scope.
Definition: ncbistl.hpp:72
#define NCBI_XOMSSA_EXPORT
Definition: ncbi_export.h:1355
EMSSearchType
what type of atomic mass to use
@ eMSSearchType_exact
int i
yy_size_t n
map< int, TLadderListPtr > TLadderMap
Definition: msladder.hpp:450
list< TSeriesChargePair > TSeriesChargePairList
Definition: msladder.hpp:451
AutoPtr< TLadderList > TLadderListPtr
Definition: msladder.hpp:448
const int kMSLadderMax
Definition: msladder.hpp:56
pair< int, TLadderListPtr > TLadderMapPair
Definition: msladder.hpp:449
vector< CRef< CLadder > > TLadderList
Definition: msladder.hpp:447
const double kNeutron
neutron mass
Definition: msms.hpp:70
@ eMSIonTypeUnknown
Definition: msscore.hpp:78
const struct ncbi::grid::netcache::search::fields::SIZE size
static bool Contains(const CSeq_loc &a, const CSeq_loc &b, CScope *scope)
Miscellaneous common-use basic types and functionality.
Int4 delta(size_t dimension_, const Int4 *score_)
signed char TMSCharge
charge type
Definition: omssascore.hpp:64
short TMSNumber
ion sequence number, starting from 0.
Definition: omssascore.hpp:67
signed char TMSIonSeries
ion type, e.g.
Definition: omssascore.hpp:61
int GetCharge(char code)
#define const
Definition: zconf.h:232
Modified on Sat Apr 20 12:14:25 2024 by modify_doxy.py rev. 669887