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 QString &protein)
 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
 
int m_min_score
 
int m_max_score
 

Detailed Description

Definition at line 54 of file locationsaver.h.

Constructor & Destructor Documentation

◆ LocationSaver()

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

Constructor

Definition at line 36 of file locationsaver.cpp.

37{
39 for(std::size_t i = 0; i < MAX_SAVED_ALIGNMENTS; i++)
40 {
41 m_locations_heap.push_back({0, 0, -1, MIN_ALIGNMENT_SCORE, ""});
42 }
43 // std::make_heap(m_locations_heap.begin(), m_locations_heap.end(),
44 // LocationSaver::locationCompare); ?
45 // m_tree_scores.reserve ?
46}
std::vector< Location > m_locations_heap
const uint MAX_SAVED_ALIGNMENTS(5)
const int MIN_ALIGNMENT_SCORE(15)

References m_locations_heap, pappso::specpeptidoms::MAX_SAVED_ALIGNMENTS(), and pappso::specpeptidoms::MIN_ALIGNMENT_SCORE().

◆ ~LocationSaver()

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

Destructor

Definition at line 129 of file locationsaver.cpp.

130{
131}

Member Function Documentation

◆ addLocation()

void pappso::specpeptidoms::LocationSaver::addLocation ( std::size_t beginning,
std::size_t length,
int tree,
int score,
const QString & protein )

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

58{
59 m_tree_scores.at(tree) = score;
60 if(m_tree_in_heap.at(tree))
61 {
62 for(std::vector<Location>::iterator iter = m_locations_heap.begin();
63 iter != m_locations_heap.end();
64 iter++)
65 {
66 if(iter->tree == tree)
67 {
68 iter->score = score;
69 iter->length = length;
70 }
71 }
72 std::make_heap(
74 }
75 else
76 {
77 if(m_locations_heap.begin()->tree >= 0)
78 {
79 m_tree_in_heap.at(m_locations_heap.begin()->tree) = false;
80 }
81 m_tree_in_heap.at(tree) = true;
82 std::pop_heap(
84 m_locations_heap.pop_back();
85 m_locations_heap.push_back({beginning, length, tree, score, protein});
86 std::push_heap(
88 }
89}
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 92 of file locationsaver.cpp.

93{
94 std::vector<Location> locations;
95 locations.reserve(m_locations_heap.size());
96 for(std::vector<Location>::const_iterator iter = m_locations_heap.begin();
97 iter != m_locations_heap.end();
98 iter++)
99 {
100 if(iter->tree >= 0)
101 {
102 locations.push_back(*iter);
103 }
104 }
105 return locations;
106}

References m_locations_heap.

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

118{
119 if(m_tree_scores.size() == 0)
120 {
121 return m_locations_heap.begin()->score;
122 }
123 else
124 {
125 return std::max(m_tree_scores.at(tree_id), m_locations_heap.begin()->score);
126 }
127}

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

110{
112 m_tree_in_heap.push_back(false);
113 return m_tree_scores.size() - 1;
114}

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

50{
51 return loc1.score > loc2.score;
52}

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

Referenced by addLocation().

◆ resetLocationSaver()

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

Definition at line 134 of file locationsaver.cpp.

135{
136 for(auto iter = m_locations_heap.begin(); iter != m_locations_heap.end(); iter++)
137 {
138 *(iter) = {0, 0, -1, MIN_ALIGNMENT_SCORE, ""};
139 }
140 m_tree_scores.clear();
141 m_tree_in_heap.clear();
142}

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

Member Data Documentation

◆ m_locations_heap

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

◆ m_max_score

int pappso::specpeptidoms::LocationSaver::m_max_score
private

Definition at line 99 of file locationsaver.h.

◆ m_min_score

int pappso::specpeptidoms::LocationSaver::m_min_score
private

Definition at line 99 of file locationsaver.h.

◆ m_tree_in_heap

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

Definition at line 98 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 97 of file locationsaver.h.

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


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