libpappsomspp
Library for mass spectrometry
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< LocationgetLocations () 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< Locationm_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.

60{
61 Location location_zero;
62 location_zero.beginning = 0;
63 location_zero.length = 0;
64 location_zero.proteinPtr = nullptr;
65 location_zero.score = MIN_ALIGNMENT_SCORE;
66 location_zero.tree = -1;
67
68 m_locations_heap.resize(MAX_SAVED_ALIGNMENTS, location_zero);
69 // std::make_heap(m_locations_heap.begin(), m_locations_heap.end(),
70 // LocationSaver::locationCompare); ?
71 // m_tree_scores.reserve ?
72}
std::vector< Location > m_locations_heap
const uint MAX_SAVED_ALIGNMENTS(5)
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.

182{
183}

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.

84{
85 try
86 {
87 m_tree_scores.at(tree) = score;
88 if(m_tree_in_heap.at(tree))
89 {
90 for(std::vector<Location>::iterator iter = m_locations_heap.begin();
91 iter != m_locations_heap.end();
92 iter++)
93 {
94 if(iter->tree == tree)
95 {
96 iter->score = score;
97 iter->length = length;
98 }
99 }
100 std::make_heap(
102 }
103 else
104 {
105 if(m_locations_heap.begin()->tree >= 0)
106 {
107 m_tree_in_heap.at(m_locations_heap.begin()->tree) = false;
108 }
109 m_tree_in_heap.at(tree) = true;
110 std::pop_heap(
112 m_locations_heap.pop_back();
113 m_locations_heap.push_back({beginning, length, tree, score, protein_ptr});
114 std::push_heap(
116 }
117 }
118 catch(const std::exception &error)
119 {
120 throw pappso::PappsoException(
121 QObject::tr("addLocation failed std::exception :\n%1").arg(error.what()));
122 }
123}
static bool locationCompare(const Location &loc1, const Location &loc2)

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.

127{
128 std::vector<Location> locations;
129 locations.reserve(m_locations_heap.size());
130 for(std::vector<Location>::const_iterator iter = m_locations_heap.begin();
131 iter != m_locations_heap.end();
132 iter++)
133 {
134 if(iter->tree >= 0)
135 {
136 locations.push_back(*iter);
137 }
138 }
139 return locations;
140}

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.

152{
153 if(m_tree_scores.size() == 0)
154 {
155 return m_locations_heap.begin()->score;
156 }
157 else
158 {
159 if(tree_id > (int)m_tree_scores.size())
160 {
161
162 throw pappso::ExceptionOutOfRange(
163 QObject::tr("LocationSaver::getMinScore failed :\nout of "
164 "range access %1 with m_tree_scores.size() %2")
165 .arg(tree_id)
166 .arg(m_tree_scores.size()));
167 }
168
169 /*To be stored, an alignment's score must be higher than: its tree's current score, the
170 * current worse stored alignment's score and a score that depends of the current best
171 * alignment's score
172 */
173 return std::max(
174 m_tree_scores.at(tree_id),
175 std::max(m_locations_heap.begin()->score,
176 (int)std::ceil(ALIGNMENT_FILTER *
177 *(std::max_element(m_tree_scores.begin(), m_tree_scores.end())))));
178 }
179}
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.

144{
146 m_tree_in_heap.push_back(false);
147 return m_tree_scores.size() - 1;
148}

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 )
staticprivate

Definition at line 75 of file locationsaver.cpp.

76{
77 return loc1.score > loc2.score;
78}

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

Referenced by addLocation().

◆ resetLocationSaver()

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

Definition at line 186 of file locationsaver.cpp.

187{
188 Location location_zero;
189 location_zero.beginning = 0;
190 location_zero.length = 0;
191 location_zero.proteinPtr = nullptr;
192 location_zero.score = MIN_ALIGNMENT_SCORE;
193 location_zero.tree = -1;
194
195 std::fill(m_locations_heap.begin(), m_locations_heap.end(), location_zero);
196 m_tree_scores.clear();
197 m_tree_in_heap.clear();
198
199
200 // int m_min_score, m_max_score;
201}

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

◆ 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: