Loading...
Searching...
No Matches
pappso::specpeptidoms::LocationSaver Class Reference

`#include <locationsaver.h>`

## Public Member Functions

| LocationSaver ()
| ~LocationSaver ()
void | addLocation (std::size_t beginning, std::size_t length, int tree, int score, const SpOMSProtein *protein_ptr)
| Adds a location to the locations heap. If a saved location has the same tree_id, it will replace it. Otherwise, it replaces the location with the lowest score.
std::vector< Location > | getLocations () const
| Returns a vector containing the saved locations.
std::size_t | getNextTree ()
| Creates a new alignment tree and returns its id.
int | getMinScore (int tree_id) const
| Returns the minimum score for a location with the provided tree_id to be saved in the heap.
void | resetLocationSaver ()

## Static Private Member Functions

static bool | locationCompare (const Location &loc1, const Location &loc2)

## Private Attributes

std::vector< Location > | m_locations_heap
std::vector< int > | m_tree_scores
std::vector< bool > | m_tree_in_heap

## Detailed Description

Definition at line 78 of file locationsaver.h.

## Constructor & Destructor Documentation

## LocationSaver()

pappso::specpeptidoms::LocationSaver::LocationSaver | ( |  | ) |

Constructor

Definition at line 59 of file locationsaver.cpp.

{
Location location_zero;
location_zero.beginning = 0;
location_zero.length = 0;
location_zero.proteinPtr = nullptr;
location_zero.score = MIN_ALIGNMENT_SCORE;
location_zero.tree = -1;
m_locations_heap.resize(MAX_SAVED_ALIGNMENTS, location_zero);
// std::make_heap(m_locations_heap.begin(), m_locations_heap.end(),
// LocationSaver::locationCompare); ?
// m_tree_scores.reserve ?
}
pappso::specpeptidoms::LocationSaver::m_locations_heap
std::vector< Location > m_locations_heap
Definition locationsaver.h:123
pappso::specpeptidoms::MAX_SAVED_ALIGNMENTS
const uint MAX_SAVED_ALIGNMENTS(5)
pappso::specpeptidoms::MIN_ALIGNMENT_SCORE
const int MIN_ALIGNMENT_SCORE(15)

References pappso::specpeptidoms::Location::beginning, pappso::specpeptidoms::Location::length, m_locations_heap, pappso::specpeptidoms::MAX_SAVED_ALIGNMENTS(), pappso::specpeptidoms::MIN_ALIGNMENT_SCORE(), pappso::specpeptidoms::Location::proteinPtr, pappso::specpeptidoms::Location::score, and pappso::specpeptidoms::Location::tree.

## ~LocationSaver()

pappso::specpeptidoms::LocationSaver::~LocationSaver | ( |  | ) |

Destructor

Definition at line 181 of file locationsaver.cpp.

{
}

## Member Function Documentation

## addLocation()

void pappso::specpeptidoms::LocationSaver::addLocation | ( | std::size_t | beginning,
|  | std::size_t | length,
|  | int | tree,
|  | int | score,
|  | const SpOMSProtein * | protein_ptr )

Adds a location to the locations heap. If a saved location has the same tree_id, it will replace it. Otherwise, it replaces the location with the lowest score.

Definition at line 82 of file locationsaver.cpp.

{
try
{
m_tree_scores.at(tree) = score;
if(m_tree_in_heap.at(tree))
{
for(std::vector<Location>::iterator iter = m_locations_heap.begin();
iter != m_locations_heap.end();
iter++)
{
if(iter->tree == tree)
{
iter->score = score;
iter->length = length;
}
}
std::make_heap(
m_locations_heap.begin(), m_locations_heap.end(), LocationSaver::locationCompare);
}
else
{
if(m_locations_heap.begin()->tree >= 0)
{
m_tree_in_heap.at(m_locations_heap.begin()->tree) = false;
}
m_tree_in_heap.at(tree) = true;
std::pop_heap(
m_locations_heap.begin(), m_locations_heap.end(), LocationSaver::locationCompare);
m_locations_heap.pop_back();
m_locations_heap.push_back({beginning, length, tree, score, protein_ptr});
std::push_heap(
m_locations_heap.begin(), m_locations_heap.end(), LocationSaver::locationCompare);
}
}
catch(const std::exception &error)
{
throw pappso::PappsoException(
QObject::tr("addLocation failed std::exception :\n%1").arg(error.what()));
}
}
pappso::specpeptidoms::LocationSaver::m_tree_scores
std::vector< int > m_tree_scores
Definition locationsaver.h:124
pappso::specpeptidoms::LocationSaver::locationCompare
static bool locationCompare(const Location &loc1, const Location &loc2)
Definition locationsaver.cpp:75
pappso::specpeptidoms::LocationSaver::m_tree_in_heap
std::vector< bool > m_tree_in_heap
Definition locationsaver.h:125

References locationCompare(), m_locations_heap, m_tree_in_heap, and m_tree_scores.

## getLocations()

std::vector< pappso::specpeptidoms::Location > pappso::specpeptidoms::LocationSaver::getLocations | ( |  | ) | const

Returns a vector containing the saved locations.

Returns
  vector of Location of size MAX_SAVED_ALIGNMENTS

Definition at line 126 of file locationsaver.cpp.

{
std::vector<Location> locations;
locations.reserve(m_locations_heap.size());
for(std::vector<Location>::const_iterator iter = m_locations_heap.begin();
iter != m_locations_heap.end();
iter++)
{
if(iter->tree >= 0)
{
locations.push_back(*iter);
}
}
return locations;
}

References m_locations_heap.

Referenced by pappso::cbor::psm::PsmSpecPeptidOmsScan::sequenceAlignment().

## getMinScore()

int pappso::specpeptidoms::LocationSaver::getMinScore | ( | int | tree_id | ) | const

Returns the minimum score for a location with the provided tree_id to be saved in the heap.

Definition at line 151 of file locationsaver.cpp.

{
if(m_tree_scores.size() == 0)
{
return m_locations_heap.begin()->score;
}
else
{
if(tree_id > (int)m_tree_scores.size())
{
throw pappso::ExceptionOutOfRange(
QObject::tr("LocationSaver::getMinScore failed :\nout of "
"range access %1 with m_tree_scores.size() %2")
.arg(tree_id)
.arg(m_tree_scores.size()));
}
/*To be stored, an alignment's score must be higher than: its tree's current score, the
* current worse stored alignment's score and a score that depends of the current best
* alignment's score
*/
return std::max(
m_tree_scores.at(tree_id),
std::max(m_locations_heap.begin()->score,
(int)std::ceil(ALIGNMENT_FILTER *
*(std::max_element(m_tree_scores.begin(), m_tree_scores.end())))));
}
}
pappso::specpeptidoms::ALIGNMENT_FILTER
const float ALIGNMENT_FILTER(0.9)

References pappso::specpeptidoms::ALIGNMENT_FILTER(), m_locations_heap, and m_tree_scores.

## getNextTree()

std::size_t pappso::specpeptidoms::LocationSaver::getNextTree | ( |  | ) |

Creates a new alignment tree and returns its id.

Definition at line 143 of file locationsaver.cpp.

{
m_tree_scores.push_back(MIN_ALIGNMENT_SCORE);
m_tree_in_heap.push_back(false);
return m_tree_scores.size() - 1;
}

References m_tree_in_heap, m_tree_scores, and pappso::specpeptidoms::MIN_ALIGNMENT_SCORE().

## locationCompare()

bool pappso::specpeptidoms::LocationSaver::locationCompare | ( | const Location & | loc1,
|  | const Location & | loc2 )

static private

Definition at line 75 of file locationsaver.cpp.

{
return loc1.score > loc2.score;
}

References pappso::specpeptidoms::Location::score.

Referenced by addLocation().

## resetLocationSaver()

void pappso::specpeptidoms::LocationSaver::resetLocationSaver | ( |  | ) |

Definition at line 186 of file locationsaver.cpp.

{
Location location_zero;
location_zero.beginning = 0;
location_zero.length = 0;
location_zero.proteinPtr = nullptr;
location_zero.score = MIN_ALIGNMENT_SCORE;
location_zero.tree = -1;
std::fill(m_locations_heap.begin(), m_locations_heap.end(), location_zero);
m_tree_scores.clear();
m_tree_in_heap.clear();
// int m_min_score, m_max_score;
}

References pappso::specpeptidoms::Location::beginning, pappso::specpeptidoms::Location::length, m_locations_heap, m_tree_in_heap, m_tree_scores, pappso::specpeptidoms::MIN_ALIGNMENT_SCORE(), pappso::specpeptidoms::Location::proteinPtr, pappso::specpeptidoms::Location::score, and pappso::specpeptidoms::Location::tree.

## Member Data Documentation

## m_locations_heap

std::vector<Location> pappso::specpeptidoms::LocationSaver::m_locations_heap

private

Definition at line 123 of file locationsaver.h.

Referenced by LocationSaver(), addLocation(), getLocations(), getMinScore(), and resetLocationSaver().

## m_tree_in_heap

std::vector<bool> pappso::specpeptidoms::LocationSaver::m_tree_in_heap

private

Definition at line 125 of file locationsaver.h.

Referenced by addLocation(), getNextTree(), and resetLocationSaver().

## m_tree_scores

std::vector<int> pappso::specpeptidoms::LocationSaver::m_tree_scores

private

Definition at line 124 of file locationsaver.h.

Referenced by addLocation(), getMinScore(), getNextTree(), and resetLocationSaver().

The documentation for this class was generated from the following files:

- pappsomspp/core/processing/specpeptidoms/locationsaver.h
- pappsomspp/core/processing/specpeptidoms/locationsaver.cpp