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 77 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, 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 176 of file locationsaver.cpp.

177{
178}

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.

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

References locationCompare().

◆ 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 129 of file locationsaver.cpp.

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

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 154 of file locationsaver.cpp.

155{
156 if(m_tree_scores.size() == 0)
157 {
158 return m_locations_heap.begin()->score;
159 }
160 else
161 {
162 if(tree_id > (int)m_tree_scores.size())
163 {
164
166 QObject::tr("LocationSaver::getMinScore failed :\nout of "
167 "range access %1 with m_tree_scores.size() %2")
168 .arg(tree_id)
169 .arg(m_tree_scores.size()));
170 }
171
172 return std::max(m_tree_scores.at(tree_id), m_locations_heap.begin()->score);
173 }
174}

◆ getNextTree()

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

Creates a new alignment tree and returns its id.

Definition at line 146 of file locationsaver.cpp.

147{
149 m_tree_in_heap.push_back(false);
150 return m_tree_scores.size() - 1;
151}

References 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 181 of file locationsaver.cpp.

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

References pappso::specpeptidoms::Location::beginning, pappso::specpeptidoms::Location::length, 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 122 of file locationsaver.h.

◆ m_tree_in_heap

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

Definition at line 124 of file locationsaver.h.

◆ m_tree_scores

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

Definition at line 123 of file locationsaver.h.


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