45 vector<vector<pair<float, float> > > massDistributions;
46 vector<unsigned int> sourceIonID;
51 set<SIMPLE_SPECIES> molecule;
54 vector<size_t> elementIdx, frequency;
55 for(
auto &v : molecule)
59 frequency.push_back(v.count);
61 sourceIonID.push_back(ui);
65 vector<pair<float,float> > massDist;
73 killVec.resize(massDist.size(),
false);
74 for(
auto uj=0; uj<massDist.size();uj++)
89 vector<pair<float,float> > tmpDist;
93 massDistributions.push_back(tmpDist);
100 vector<pair<unsigned int, float> > massPositions;
101 for(
auto ui=0;ui<massDistributions.size();ui++)
103 for(
auto v : massDistributions[ui] )
105 massPositions.push_back(
106 std::make_pair(sourceIonID[ui],v.first));
112 std::sort(massPositions.begin(),massPositions.end(),cmp);
114 vector<unsigned int> currentPositions;
115 gsl_matrix *massDistAdjacency = gsl_matrix_alloc(massPositions.size(),
116 massPositions.size());
117 vMass = gsl_vector_alloc(massPositions.size());
118 vOwner= gsl_vector_alloc(massPositions.size());
121 for(
unsigned int ui=0;ui<massPositions.size();ui++)
124 m1=massPositions[ui].second;
127 for(
unsigned int uj=0;uj<massPositions.size();uj++)
131 m2 = massPositions[uj].second;
133 gsl_matrix_set(massDistAdjacency,ui,uj,1);
135 gsl_matrix_set(massDistAdjacency,ui,uj,0);
139 for(
unsigned int ui=0;ui<massPositions.size();ui++)
142 gsl_vector_set(vMass,ui,massPositions[ui].second);
143 gsl_vector_set(vOwner,ui,massPositions[ui].first);
151 const pair<float,float> &r2)
154 if(r1.first >=r2.first && r1.first <=r2.second)
158 if(r1.second <= r2.second && r1.second >= r2.first)
162 if(r1.first <=r2.first && r1.second >=r2.second)
166 if(r2.first <=r1.first && r2.second >=r1.second)
180 pair<float,float> rng1;
188 pair<float,float> rng2;
194 gsl_matrix_set(m,ui,uj,1);
196 gsl_matrix_set(m,ui,uj,0);
205 bool testIonDistAdjacency()
208 if(abundance.
open(
"naturalAbundance.xml"))
210 WARN(
false,
"Unable to test overlap adjacency matrix generation - no abundance data found");
238 gsl_vector *vOwner,*vMass;
244 TEST(m->size1 == m->size2,
"Matrix should be square");
245 TEST(gsl_matrix_max(m) ==1,
"matrix should be max 1");
246 TEST(gsl_matrix_min(m) >=0,
"matrix should be min 0");
248 for(
auto ui=0;ui<m->size1; ui++)
251 TEST(fabs(gsl_matrix_get(m,ui,ui)-1) < 0.01,
"Unitary diagonal");
253 for(
auto uj=ui;uj<m->size1; uj++)
256 TEST(gsl_matrix_get(m,ui,uj) == gsl_matrix_get(m,uj,ui),
"Symmetric test");
268 bool testRangeAdjancency()
271 if(abundance.
open(
"naturalAbundance.xml"))
273 WARN(
false,
"Unable to test overlap adjacency matrix generation - no abundance data found");
286 auto hIdx=mrf.
addIon(s,
"H",col);
301 TEST(m->size1 == m->size2,
"Matrix should be square");
302 TEST(gsl_matrix_max(m) ==1,
"matrix should be max 1");
303 TEST(gsl_matrix_min(m) >=0,
"matrix should be min 0");
308 for(
auto ui=0;ui<m->size1; ui++)
311 TEST(fabs(gsl_matrix_get(m,ui,ui)-1) < 0.01,
"Unitary diagonal");
313 for(
auto uj=ui;uj<m->size1; uj++)
316 TEST(gsl_matrix_get(m,ui,uj) == gsl_matrix_get(m,uj,ui),
"Symmetric test");
325 bool testComponentAnalysis()
327 TEST(testIonDistAdjacency(),
"Ion adjacency matrix generation");
328 TEST(testRangeAdjancency(),
"Range adjacency matrix generation");
unsigned int atomicNumber
Number of protons (element number)
std::set< SIMPLE_SPECIES > getMolecule(unsigned int ionID) const
Return the molecule that is associated with this ion.
size_t symbolIndex(const char *symbol, bool caseSensitive=true) const
Return the element's position in table, starting from 0.
float massTolerance
Tolerance in Da, above which we consider problems to be.
void computeIonDistAdjacency(const MultiRange &mrf, const AbundanceData &abundance, const OVERLAP_PROBLEM_SETTINGS &settings, gsl_matrix *&m, gsl_vector *&vOwnership, gsl_vector *&vMass)
Calculate the adjacency matrix for the ions in a multirange.
bool rangeOverlaps(const pair< float, float > &r1, const pair< float, float > &r2)
Data holder for colour as float.
void gsl_print_matrix(const gsl_matrix *m)
void generateIsotopeDist(const std::vector< size_t > &elementIdx, const std::vector< size_t > &frequency, std::vector< std::pair< float, float > > &massDist) const
Compute the mass-probability distribution for the grouped set of ions.
unsigned int addRange(float start, float end, unsigned int ionID)
Add a range to the rangefile. Returns ID number of added range if adding successful, (unsigned int)-1 otherwise.
unsigned int maxDefaultCharge
Maximum charge state to consider.
void vectorMultiErase(std::vector< T > &vec, const std::vector< bool > &wantKill)
Remove elements from the vector, without preserving order.
unsigned int addIon(const std::set< SIMPLE_SPECIES > &molecule, const std::string &name, const RGBf &ionCol)
Add the ion to the database returns ion ID if successful, -1 otherwise.
Data storage and retrieval class for "ranging" a spectra, where overlapping ranges are permitted...
unsigned int getNumRanges() const
Get the number of unique ranges.
size_t open(const char *file, bool strict=false)
Attempt to open the abundance data file, return 0 on success, nonzero on failure. ...
Class to load abundance information for natural isotopes.
unsigned int getNumIons() const
Get the number of unique ions.
std::pair< float, float > getRange(unsigned int rangeID) const
Retrieve the start and end of a given range as a pair(start,end)
float intensityTolerance
The minimal natural abundance for which we consider the ions.
unsigned int count
Number of copies of this isotope.
unsigned int getAtomicNumber(size_t elemIdx) const
Obtain the atomic number for the given element, by element index.
size_t symbolIdxFromAtomicNumber(size_t atomicNumber) const
Return the symbol index (offset in vector) for the given atomic number, -1 if it cannot be found...
void computeRangeAdjacency(const MultiRange &mrf, const OVERLAP_PROBLEM_SETTINGS &settings, gsl_matrix *&m)