IsoSpecPy 2.3.0.dev11__cp313-cp313-win_arm64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- IsoSpecPy/Advanced.py +32 -0
- IsoSpecPy/Distributions.py +94 -0
- IsoSpecPy/Formulas.py +71 -0
- IsoSpecPy/IsoSpec++/allocator.h +69 -0
- IsoSpecPy/IsoSpec++/btrd.h +206 -0
- IsoSpecPy/IsoSpec++/conf.h +38 -0
- IsoSpecPy/IsoSpec++/cwrapper.h +179 -0
- IsoSpecPy/IsoSpec++/dirtyAllocator.h +58 -0
- IsoSpecPy/IsoSpec++/element_tables.h +50 -0
- IsoSpecPy/IsoSpec++/fasta.h +67 -0
- IsoSpecPy/IsoSpec++/fixedEnvelopes.h +244 -0
- IsoSpecPy/IsoSpec++/isoMath.h +87 -0
- IsoSpecPy/IsoSpec++/isoSpec++.h +693 -0
- IsoSpecPy/IsoSpec++/marginalTrek++.h +573 -0
- IsoSpecPy/IsoSpec++/misc.h +204 -0
- IsoSpecPy/IsoSpec++/mman.h +67 -0
- IsoSpecPy/IsoSpec++/operators.h +150 -0
- IsoSpecPy/IsoSpec++/platform.h +111 -0
- IsoSpecPy/IsoSpec++/platform_incl.h +33 -0
- IsoSpecPy/IsoSpec++/pod_vector.h +399 -0
- IsoSpecPy/IsoSpec++/summator.h +118 -0
- IsoSpecPy/IsoSpecPy.py +840 -0
- IsoSpecPy/IsoSpecPyOld.py +294 -0
- IsoSpecPy/PeriodicTbl.py +38 -0
- IsoSpecPy/__init__.py +19 -0
- IsoSpecPy/__main__.py +25 -0
- IsoSpecPy/approximations.py +131 -0
- IsoSpecPy/confs_passthrough.py +16 -0
- IsoSpecPy/isoFFI.py +223 -0
- bin/IsoSpecCppPy.dll +0 -0
- isospecpy-2.3.0.dev11.dist-info/METADATA +43 -0
- isospecpy-2.3.0.dev11.dist-info/RECORD +35 -0
- isospecpy-2.3.0.dev11.dist-info/WHEEL +5 -0
- isospecpy-2.3.0.dev11.dist-info/licenses/LICENCE +35 -0
- lib/IsoSpecCppPy.lib +0 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2015-2020 Mateusz Łącki and Michał Startek.
|
|
3
|
+
*
|
|
4
|
+
* This file is part of IsoSpec.
|
|
5
|
+
*
|
|
6
|
+
* IsoSpec is free software: you can redistribute it and/or modify
|
|
7
|
+
* it under the terms of the Simplified ("2-clause") BSD licence.
|
|
8
|
+
*
|
|
9
|
+
* IsoSpec is distributed in the hope that it will be useful,
|
|
10
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
12
|
+
*
|
|
13
|
+
* You should have received a copy of the Simplified BSD Licence
|
|
14
|
+
* along with IsoSpec. If not, see <https://opensource.org/licenses/BSD-2-Clause>.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
#pragma once
|
|
18
|
+
|
|
19
|
+
#include <cstring>
|
|
20
|
+
#include "pod_vector.h"
|
|
21
|
+
|
|
22
|
+
namespace IsoSpec
|
|
23
|
+
{
|
|
24
|
+
|
|
25
|
+
class DirtyAllocator
|
|
26
|
+
{
|
|
27
|
+
private:
|
|
28
|
+
void* currentTab;
|
|
29
|
+
void* currentConf;
|
|
30
|
+
void* endOfTablePtr;
|
|
31
|
+
const int tabSize;
|
|
32
|
+
int cellSize;
|
|
33
|
+
pod_vector<void*> prevTabs;
|
|
34
|
+
|
|
35
|
+
public:
|
|
36
|
+
explicit DirtyAllocator(const int dim, const int tabSize = 10000);
|
|
37
|
+
~DirtyAllocator();
|
|
38
|
+
|
|
39
|
+
DirtyAllocator(const DirtyAllocator& other) = delete;
|
|
40
|
+
DirtyAllocator& operator=(const DirtyAllocator& other) = delete;
|
|
41
|
+
|
|
42
|
+
void shiftTables();
|
|
43
|
+
|
|
44
|
+
inline void* newConf()
|
|
45
|
+
{
|
|
46
|
+
if (currentConf >= endOfTablePtr)
|
|
47
|
+
{
|
|
48
|
+
shiftTables();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
void* ret = currentConf;
|
|
52
|
+
currentConf = reinterpret_cast<char*>(currentConf) + cellSize;
|
|
53
|
+
|
|
54
|
+
return ret;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
} // namespace IsoSpec
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2015-2020 Mateusz Łącki and Michał Startek.
|
|
3
|
+
*
|
|
4
|
+
* This file is part of IsoSpec.
|
|
5
|
+
*
|
|
6
|
+
* IsoSpec is free software: you can redistribute it and/or modify
|
|
7
|
+
* it under the terms of the Simplified ("2-clause") BSD licence.
|
|
8
|
+
*
|
|
9
|
+
* IsoSpec is distributed in the hope that it will be useful,
|
|
10
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
12
|
+
*
|
|
13
|
+
* You should have received a copy of the Simplified BSD Licence
|
|
14
|
+
* along with IsoSpec. If not, see <https://opensource.org/licenses/BSD-2-Clause>.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
#pragma once
|
|
18
|
+
|
|
19
|
+
#include <stddef.h>
|
|
20
|
+
|
|
21
|
+
#include "platform.h"
|
|
22
|
+
|
|
23
|
+
namespace IsoSpec
|
|
24
|
+
{
|
|
25
|
+
|
|
26
|
+
#ifdef __cplusplus
|
|
27
|
+
extern "C" {
|
|
28
|
+
#endif
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
#define ISOSPEC_NUMBER_OF_ISOTOPIC_ENTRIES 292
|
|
32
|
+
ISOSPEC_C_API extern const size_t isospec_number_of_isotopic_entries;
|
|
33
|
+
|
|
34
|
+
ISOSPEC_C_API extern const int elem_table_ID[ISOSPEC_NUMBER_OF_ISOTOPIC_ENTRIES];
|
|
35
|
+
ISOSPEC_C_API extern const int elem_table_atomicNo[ISOSPEC_NUMBER_OF_ISOTOPIC_ENTRIES];
|
|
36
|
+
ISOSPEC_C_API extern const double elem_table_probability[ISOSPEC_NUMBER_OF_ISOTOPIC_ENTRIES];
|
|
37
|
+
ISOSPEC_C_API extern const double elem_table_mass[ISOSPEC_NUMBER_OF_ISOTOPIC_ENTRIES];
|
|
38
|
+
ISOSPEC_C_API extern const double elem_table_massNo[ISOSPEC_NUMBER_OF_ISOTOPIC_ENTRIES];
|
|
39
|
+
ISOSPEC_C_API extern const int elem_table_extraNeutrons[ISOSPEC_NUMBER_OF_ISOTOPIC_ENTRIES];
|
|
40
|
+
ISOSPEC_C_API extern const char* elem_table_element[ISOSPEC_NUMBER_OF_ISOTOPIC_ENTRIES];
|
|
41
|
+
ISOSPEC_C_API extern const char* elem_table_symbol[ISOSPEC_NUMBER_OF_ISOTOPIC_ENTRIES];
|
|
42
|
+
ISOSPEC_C_API extern const bool elem_table_Radioactive[ISOSPEC_NUMBER_OF_ISOTOPIC_ENTRIES];
|
|
43
|
+
ISOSPEC_C_API extern const double elem_table_log_probability[ISOSPEC_NUMBER_OF_ISOTOPIC_ENTRIES];
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
#ifdef __cplusplus
|
|
47
|
+
}
|
|
48
|
+
#endif
|
|
49
|
+
|
|
50
|
+
} // namespace IsoSpec
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2015-2020 Mateusz Łącki and Michał Startek.
|
|
3
|
+
*
|
|
4
|
+
* This file is part of IsoSpec.
|
|
5
|
+
*
|
|
6
|
+
* IsoSpec is free software: you can redistribute it and/or modify
|
|
7
|
+
* it under the terms of the Simplified ("2-clause") BSD licence.
|
|
8
|
+
*
|
|
9
|
+
* IsoSpec is distributed in the hope that it will be useful,
|
|
10
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
12
|
+
*
|
|
13
|
+
* You should have received a copy of the Simplified BSD Licence
|
|
14
|
+
* along with IsoSpec. If not, see <https://opensource.org/licenses/BSD-2-Clause>.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
#pragma once
|
|
19
|
+
|
|
20
|
+
namespace IsoSpec{
|
|
21
|
+
|
|
22
|
+
// We will work with C H N O S Se tuples */
|
|
23
|
+
extern const int aa_isotope_numbers[6];
|
|
24
|
+
|
|
25
|
+
extern const double aa_elem_masses[19];
|
|
26
|
+
|
|
27
|
+
extern const double aa_elem_nominal_masses[19];
|
|
28
|
+
|
|
29
|
+
extern const double aa_elem_probabilities[19];
|
|
30
|
+
|
|
31
|
+
extern const int aa_symbol_to_elem_counts[256*6];
|
|
32
|
+
|
|
33
|
+
//! Count elemental composition of an unmodificed sequence of amino acids, resulting in CHNOSSe counts.
|
|
34
|
+
/*!
|
|
35
|
+
WARNING!!! This function does not add the terminating H and OH groups, resulting in a residue backbone skeleton formula.
|
|
36
|
+
If you don't know what that means, you should probably be using parse_fasta_full function.
|
|
37
|
+
*/
|
|
38
|
+
inline void parse_fasta(const char* fasta, int atomCounts[6])
|
|
39
|
+
{
|
|
40
|
+
memset(atomCounts, 0, sizeof(decltype(atomCounts[0]))*6);
|
|
41
|
+
|
|
42
|
+
for(size_t idx = 0; fasta[idx] != '\0'; ++idx)
|
|
43
|
+
{
|
|
44
|
+
const int* counts = &aa_symbol_to_elem_counts[fasta[idx]*6];
|
|
45
|
+
for(int ii = 0; ii < 6; ++ii)
|
|
46
|
+
atomCounts[ii] += counts[ii];
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
//! Turn an input FASTA aminoacid sequence into atom counts, in CHNOSSe order.
|
|
51
|
+
/*!
|
|
52
|
+
Unlike parse_fasta, this function includes the H and OH groups at the N- and C- termini of the skeleton, resulting in a formula of a full (inert) molecule.
|
|
53
|
+
*/
|
|
54
|
+
inline void parse_fasta_full(const char* fasta, int atomCounts[6])
|
|
55
|
+
{
|
|
56
|
+
parse_fasta(fasta, atomCounts);
|
|
57
|
+
// Add terminal water (H2O) for either precursor or fragment.
|
|
58
|
+
const int H_INDEX = 1; // Indexing: 0=C, 1=H, 2=N, 3=O, 4=S, 5=Se
|
|
59
|
+
const int O_INDEX = 3;
|
|
60
|
+
|
|
61
|
+
atomCounts[H_INDEX] += 2;
|
|
62
|
+
atomCounts[O_INDEX] += 1;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
} // namespace IsoSpec
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2015-2020 Mateusz Łącki and Michał Startek.
|
|
3
|
+
*
|
|
4
|
+
* This file is part of IsoSpec.
|
|
5
|
+
*
|
|
6
|
+
* IsoSpec is free software: you can redistribute it and/or modify
|
|
7
|
+
* it under the terms of the Simplified ("2-clause") BSD licence.
|
|
8
|
+
*
|
|
9
|
+
* IsoSpec is distributed in the hope that it will be useful,
|
|
10
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
12
|
+
*
|
|
13
|
+
* You should have received a copy of the Simplified BSD Licence
|
|
14
|
+
* along with IsoSpec. If not, see <https://opensource.org/licenses/BSD-2-Clause>.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
#pragma once
|
|
18
|
+
|
|
19
|
+
#include <cstdlib>
|
|
20
|
+
#include <algorithm>
|
|
21
|
+
#include <vector>
|
|
22
|
+
#include <utility>
|
|
23
|
+
|
|
24
|
+
#include "isoSpec++.h"
|
|
25
|
+
|
|
26
|
+
#ifdef DEBUG
|
|
27
|
+
#define ISOSPEC_INIT_TABLE_SIZE 16
|
|
28
|
+
#else
|
|
29
|
+
#define ISOSPEC_INIT_TABLE_SIZE 1024
|
|
30
|
+
#endif
|
|
31
|
+
|
|
32
|
+
namespace IsoSpec
|
|
33
|
+
{
|
|
34
|
+
|
|
35
|
+
class FixedEnvelope;
|
|
36
|
+
|
|
37
|
+
double AbyssalWassersteinDistanceGrad(FixedEnvelope* const* envelopes, const double* scales, double* ret_gradient, size_t N, double abyss_depth_exp, double abyss_depth_the);
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class ISOSPEC_EXPORT_SYMBOL FixedEnvelope {
|
|
41
|
+
protected:
|
|
42
|
+
double* _masses;
|
|
43
|
+
double* _probs;
|
|
44
|
+
int* _confs;
|
|
45
|
+
size_t _confs_no;
|
|
46
|
+
int allDim;
|
|
47
|
+
bool sorted_by_mass;
|
|
48
|
+
bool sorted_by_prob;
|
|
49
|
+
double total_prob;
|
|
50
|
+
size_t current_size;
|
|
51
|
+
double* tmasses;
|
|
52
|
+
double* tprobs;
|
|
53
|
+
int* tconfs;
|
|
54
|
+
int allDimSizeofInt;
|
|
55
|
+
|
|
56
|
+
public:
|
|
57
|
+
ISOSPEC_FORCE_INLINE FixedEnvelope() : _masses(nullptr),
|
|
58
|
+
_probs(nullptr),
|
|
59
|
+
_confs(nullptr),
|
|
60
|
+
_confs_no(0),
|
|
61
|
+
allDim(0),
|
|
62
|
+
sorted_by_mass(false),
|
|
63
|
+
sorted_by_prob(false),
|
|
64
|
+
total_prob(0.0),
|
|
65
|
+
current_size(0),
|
|
66
|
+
allDimSizeofInt(0)
|
|
67
|
+
// Deliberately not initializing tmasses, tprobs, tconfs
|
|
68
|
+
{};
|
|
69
|
+
|
|
70
|
+
FixedEnvelope(const FixedEnvelope& other);
|
|
71
|
+
FixedEnvelope(FixedEnvelope&& other);
|
|
72
|
+
|
|
73
|
+
FixedEnvelope(double* masses, double* probs, size_t confs_no, bool masses_sorted = false, bool probs_sorted = false, double _total_prob = NAN);
|
|
74
|
+
|
|
75
|
+
virtual ~FixedEnvelope()
|
|
76
|
+
{
|
|
77
|
+
free(_masses);
|
|
78
|
+
free(_probs);
|
|
79
|
+
free(_confs);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
FixedEnvelope operator+(const FixedEnvelope& other) const;
|
|
83
|
+
FixedEnvelope operator*(const FixedEnvelope& other) const;
|
|
84
|
+
|
|
85
|
+
inline size_t confs_no() const { return _confs_no; }
|
|
86
|
+
inline int getAllDim() const { return allDim; }
|
|
87
|
+
|
|
88
|
+
inline const double* masses() const { return _masses; }
|
|
89
|
+
inline const double* probs() const { return _probs; }
|
|
90
|
+
inline const int* confs() const { return _confs; }
|
|
91
|
+
|
|
92
|
+
inline double* release_masses() { double* ret = _masses; _masses = nullptr; return ret; }
|
|
93
|
+
inline double* release_probs() { double* ret = _probs; _probs = nullptr; return ret; }
|
|
94
|
+
inline int* release_confs() { int* ret = _confs; _confs = nullptr; return ret; }
|
|
95
|
+
inline void release_everything() { _confs = nullptr; _probs = _masses = nullptr; }
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
inline double mass(size_t i) const { return _masses[i]; }
|
|
99
|
+
inline double prob(size_t i) const { return _probs[i]; }
|
|
100
|
+
inline const int* conf(size_t i) const { return _confs + i*allDim; }
|
|
101
|
+
|
|
102
|
+
void sort_by_mass();
|
|
103
|
+
void sort_by_prob();
|
|
104
|
+
|
|
105
|
+
double get_total_prob();
|
|
106
|
+
void scale(double factor);
|
|
107
|
+
void normalize();
|
|
108
|
+
void shift_mass(double shift);
|
|
109
|
+
void resample(size_t ionic_current, double beta_bias = 1.0);
|
|
110
|
+
|
|
111
|
+
double empiric_average_mass();
|
|
112
|
+
double empiric_variance();
|
|
113
|
+
double empiric_stddev() { return sqrt(empiric_variance()); }
|
|
114
|
+
|
|
115
|
+
double WassersteinDistance(FixedEnvelope& other);
|
|
116
|
+
double OrientedWassersteinDistance(FixedEnvelope& other);
|
|
117
|
+
double AbyssalWassersteinDistance(FixedEnvelope& other, double abyss_depth, double other_scale = 1.0);
|
|
118
|
+
std::tuple<double, double, double> WassersteinMatch(FixedEnvelope& other, double flow_distance, double other_scale = 1.0);
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
static FixedEnvelope LinearCombination(const std::vector<const FixedEnvelope*>& spectra, const std::vector<double>& intensities);
|
|
122
|
+
static FixedEnvelope LinearCombination(const FixedEnvelope* const * spectra, const double* intensities, size_t size);
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
FixedEnvelope bin(double bin_width = 1.0, double middle = 0.0);
|
|
126
|
+
|
|
127
|
+
private:
|
|
128
|
+
void sort_by(double* order);
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
protected:
|
|
132
|
+
template<typename T, bool tgetConfs> ISOSPEC_FORCE_INLINE void store_conf(const T& generator)
|
|
133
|
+
{
|
|
134
|
+
*tmasses = generator.mass(); tmasses++;
|
|
135
|
+
*tprobs = generator.prob(); tprobs++;
|
|
136
|
+
constexpr_if(tgetConfs) { generator.get_conf_signature(tconfs); tconfs += allDim; }
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
ISOSPEC_FORCE_INLINE void store_conf(double _mass, double _prob)
|
|
140
|
+
{
|
|
141
|
+
if(_confs_no == current_size)
|
|
142
|
+
reallocate_memory<false>(current_size*2);
|
|
143
|
+
|
|
144
|
+
*tprobs = _prob;
|
|
145
|
+
*tmasses = _mass;
|
|
146
|
+
tprobs++;
|
|
147
|
+
tmasses++;
|
|
148
|
+
|
|
149
|
+
_confs_no++;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
template<bool tgetConfs> ISOSPEC_FORCE_INLINE void swap(size_t idx1, size_t idx2, ISOSPEC_MAYBE_UNUSED int* conf_swapspace)
|
|
153
|
+
{
|
|
154
|
+
std::swap<double>(this->_probs[idx1], this->_probs[idx2]);
|
|
155
|
+
std::swap<double>(this->_masses[idx1], this->_masses[idx2]);
|
|
156
|
+
constexpr_if(tgetConfs)
|
|
157
|
+
{
|
|
158
|
+
int* c1 = this->_confs + (idx1*this->allDim);
|
|
159
|
+
int* c2 = this->_confs + (idx2*this->allDim);
|
|
160
|
+
memcpy(conf_swapspace, c1, this->allDimSizeofInt);
|
|
161
|
+
memcpy(c1, c2, this->allDimSizeofInt);
|
|
162
|
+
memcpy(c2, conf_swapspace, this->allDimSizeofInt);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
template<bool tgetConfs> void reallocate_memory(size_t new_size);
|
|
167
|
+
void slow_reallocate_memory(size_t new_size);
|
|
168
|
+
|
|
169
|
+
public:
|
|
170
|
+
template<bool tgetConfs> void threshold_init(Iso&& iso, double threshold, bool absolute);
|
|
171
|
+
|
|
172
|
+
template<bool tgetConfs, typename GenType = IsoLayeredGenerator> void addConfILG(const GenType& generator)
|
|
173
|
+
{
|
|
174
|
+
if(this->_confs_no == this->current_size)
|
|
175
|
+
this->template reallocate_memory<tgetConfs>(this->current_size*2);
|
|
176
|
+
|
|
177
|
+
this->template store_conf<GenType, tgetConfs>(generator);
|
|
178
|
+
this->_confs_no++;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
template<bool tgetConfs> void total_prob_init(Iso&& iso, double target_prob, bool trim);
|
|
182
|
+
|
|
183
|
+
static FixedEnvelope FromThreshold(Iso&& iso, double threshold, bool absolute, bool tgetConfs = false)
|
|
184
|
+
{
|
|
185
|
+
FixedEnvelope ret;
|
|
186
|
+
|
|
187
|
+
if(tgetConfs)
|
|
188
|
+
ret.threshold_init<true>(std::move(iso), threshold, absolute);
|
|
189
|
+
else
|
|
190
|
+
ret.threshold_init<false>(std::move(iso), threshold, absolute);
|
|
191
|
+
return ret;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
inline static FixedEnvelope FromThreshold(const Iso& iso, double _threshold, bool _absolute, bool tgetConfs = false)
|
|
195
|
+
{
|
|
196
|
+
return FromThreshold(Iso(iso, false), _threshold, _absolute, tgetConfs);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
static FixedEnvelope FromTotalProb(Iso&& iso, double target_total_prob, bool optimize, bool tgetConfs = false)
|
|
200
|
+
{
|
|
201
|
+
FixedEnvelope ret;
|
|
202
|
+
|
|
203
|
+
if(tgetConfs)
|
|
204
|
+
ret.total_prob_init<true>(std::move(iso), target_total_prob, optimize);
|
|
205
|
+
else
|
|
206
|
+
ret.total_prob_init<false>(std::move(iso), target_total_prob, optimize);
|
|
207
|
+
|
|
208
|
+
return ret;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
inline static FixedEnvelope FromTotalProb(const Iso& iso, double _target_total_prob, bool _optimize, bool tgetConfs = false)
|
|
212
|
+
{
|
|
213
|
+
return FromTotalProb(Iso(iso, false), _target_total_prob, _optimize, tgetConfs);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
template<bool tgetConfs> void stochastic_init(Iso&& iso, size_t _no_molecules, double _precision, double _beta_bias);
|
|
217
|
+
|
|
218
|
+
inline static FixedEnvelope FromStochastic(Iso&& iso, size_t _no_molecules, double _precision = 0.9999, double _beta_bias = 5.0, bool tgetConfs = false)
|
|
219
|
+
{
|
|
220
|
+
FixedEnvelope ret;
|
|
221
|
+
|
|
222
|
+
if(tgetConfs)
|
|
223
|
+
ret.stochastic_init<true>(std::move(iso), _no_molecules, _precision, _beta_bias);
|
|
224
|
+
else
|
|
225
|
+
ret.stochastic_init<false>(std::move(iso), _no_molecules, _precision, _beta_bias);
|
|
226
|
+
|
|
227
|
+
return ret;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
static FixedEnvelope FromStochastic(const Iso& iso, size_t _no_molecules, double _precision = 0.9999, double _beta_bias = 5.0, bool tgetConfs = false)
|
|
231
|
+
{
|
|
232
|
+
return FromStochastic(Iso(iso, false), _no_molecules, _precision, _beta_bias, tgetConfs);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
static FixedEnvelope Binned(Iso&& iso, double target_total_prob, double bin_width, double bin_middle = 0.0);
|
|
236
|
+
static FixedEnvelope Binned(const Iso& iso, double target_total_prob, double bin_width, double bin_middle = 0.0)
|
|
237
|
+
{
|
|
238
|
+
return Binned(Iso(iso, false), target_total_prob, bin_width, bin_middle);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
friend double AbyssalWassersteinDistanceGrad(FixedEnvelope* const* envelopes, const double* scales, double* ret_gradient, size_t N, double abyss_depth_exp, double abyss_depth_the);
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
} // namespace IsoSpec
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2015-2020 Mateusz Łącki and Michał Startek.
|
|
3
|
+
*
|
|
4
|
+
* This file is part of IsoSpec.
|
|
5
|
+
*
|
|
6
|
+
* IsoSpec is free software: you can redistribute it and/or modify
|
|
7
|
+
* it under the terms of the Simplified ("2-clause") BSD licence.
|
|
8
|
+
*
|
|
9
|
+
* IsoSpec is distributed in the hope that it will be useful,
|
|
10
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
12
|
+
*
|
|
13
|
+
* You should have received a copy of the Simplified BSD Licence
|
|
14
|
+
* along with IsoSpec. If not, see <https://opensource.org/licenses/BSD-2-Clause>.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
#pragma once
|
|
18
|
+
|
|
19
|
+
#include <cmath>
|
|
20
|
+
#include <random>
|
|
21
|
+
|
|
22
|
+
#if !defined(ISOSPEC_G_FACT_TABLE_SIZE)
|
|
23
|
+
// 10M should be enough for anyone, right?
|
|
24
|
+
// Actually, yes. If anyone tries to input a molecule that has more than 10M atoms,
|
|
25
|
+
// he deserves to get an exception thrown in his face. OpenMS guys don't want to alloc
|
|
26
|
+
// a table of 10M to memoize the necessary values though, use something smaller for them.
|
|
27
|
+
#if ISOSPEC_BUILDING_OPENMS
|
|
28
|
+
#define ISOSPEC_G_FACT_TABLE_SIZE 1024
|
|
29
|
+
#else
|
|
30
|
+
#define ISOSPEC_G_FACT_TABLE_SIZE 1024*1024*10
|
|
31
|
+
#endif
|
|
32
|
+
#endif
|
|
33
|
+
|
|
34
|
+
namespace IsoSpec
|
|
35
|
+
{
|
|
36
|
+
|
|
37
|
+
extern double* g_lfact_table;
|
|
38
|
+
|
|
39
|
+
static inline double minuslogFactorial(int n)
|
|
40
|
+
{
|
|
41
|
+
if (n < 2)
|
|
42
|
+
return 0.0;
|
|
43
|
+
#if ISOSPEC_BUILDING_OPENMS
|
|
44
|
+
if (n >= ISOSPEC_G_FACT_TABLE_SIZE)
|
|
45
|
+
return -lgamma(n+1);
|
|
46
|
+
#endif
|
|
47
|
+
if (g_lfact_table[n] == 0.0)
|
|
48
|
+
g_lfact_table[n] = -lgamma(n+1);
|
|
49
|
+
|
|
50
|
+
return g_lfact_table[n];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const double pi = 3.14159265358979323846264338328;
|
|
54
|
+
const double logpi = 1.144729885849400174143427351353058711647294812915311571513623071472137769884826079783623270275489708;
|
|
55
|
+
|
|
56
|
+
double NormalCDFInverse(double p);
|
|
57
|
+
double NormalCDFInverse(double p, double mean, double stdev);
|
|
58
|
+
double NormalCDF(double x, double mean, double stdev);
|
|
59
|
+
double NormalPDF(double x, double mean = 0.0, double stdev = 1.0);
|
|
60
|
+
|
|
61
|
+
// Returns lower incomplete gamma function of a/2, x, where a is int and > 0.
|
|
62
|
+
double LowerIncompleteGamma2(int a, double x);
|
|
63
|
+
|
|
64
|
+
// Returns y such that LowerIncompleteGamma2(a, y) == x. Approximately.
|
|
65
|
+
double InverseLowerIncompleteGamma2(int a, double x);
|
|
66
|
+
|
|
67
|
+
// Computes the inverse Cumulative Distribution Funcion of the Chi-Square distribution with k degrees of freedom
|
|
68
|
+
inline double InverseChiSquareCDF2(int k, double x)
|
|
69
|
+
{
|
|
70
|
+
return InverseLowerIncompleteGamma2(k, x*tgamma(static_cast<double>(k)/2.0)) * 2.0;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
extern thread_local std::mt19937 random_gen;
|
|
74
|
+
extern thread_local std::uniform_real_distribution<double> stdunif;
|
|
75
|
+
|
|
76
|
+
inline double rdvariate_beta_1_b(double b, std::mt19937& rgen = random_gen)
|
|
77
|
+
{
|
|
78
|
+
return 1.0 - pow(stdunif(rgen), 1.0/b);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
size_t rdvariate_binom(size_t tries, double succ_prob, std::mt19937& rgen = random_gen);
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
} // namespace IsoSpec
|