IsoSpecPy 2.4.0__cp315-cp315-win32.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 +93 -0
- IsoSpecPy/Formulas.py +71 -0
- IsoSpecPy/IsoSpec++/aligned_ptr.h +622 -0
- IsoSpecPy/IsoSpec++/allocator.h +69 -0
- IsoSpecPy/IsoSpec++/btrd.h +206 -0
- IsoSpecPy/IsoSpec++/conf.h +38 -0
- IsoSpecPy/IsoSpec++/cwrapper.h +223 -0
- IsoSpecPy/IsoSpec++/dirtyAllocator.h +58 -0
- IsoSpecPy/IsoSpec++/element_tables.h +50 -0
- IsoSpecPy/IsoSpec++/fasta.h +70 -0
- IsoSpecPy/IsoSpec++/fixedEnvelopes.h +418 -0
- IsoSpecPy/IsoSpec++/isa_kernel_impl.h +192 -0
- IsoSpecPy/IsoSpec++/isa_kernels.h +172 -0
- IsoSpecPy/IsoSpec++/isoMath.h +107 -0
- IsoSpecPy/IsoSpec++/isoSpec++.h +772 -0
- IsoSpecPy/IsoSpec++/iso_simd.h +48 -0
- IsoSpecPy/IsoSpec++/marginalTrek++.h +617 -0
- IsoSpecPy/IsoSpec++/misc.h +226 -0
- IsoSpecPy/IsoSpec++/mman.h +67 -0
- IsoSpecPy/IsoSpec++/operators.h +150 -0
- IsoSpecPy/IsoSpec++/platform.h +180 -0
- IsoSpecPy/IsoSpec++/platform_incl.h +33 -0
- IsoSpecPy/IsoSpec++/pod_vector.h +401 -0
- IsoSpecPy/IsoSpec++/summator.h +118 -0
- IsoSpecPy/IsoSpecPy.py +924 -0
- IsoSpecPy/IsoSpecPyOld.py +290 -0
- IsoSpecPy/PeriodicTbl.py +34 -0
- IsoSpecPy/__init__.py +19 -0
- IsoSpecPy/__main__.py +25 -0
- IsoSpecPy/approximations.py +122 -0
- IsoSpecPy/confs_passthrough.py +16 -0
- IsoSpecPy/isoFFI.py +263 -0
- bin/IsoSpecCppPy.dll +0 -0
- isospecpy-2.4.0.dist-info/METADATA +159 -0
- isospecpy-2.4.0.dist-info/RECORD +39 -0
- isospecpy-2.4.0.dist-info/WHEEL +5 -0
- isospecpy-2.4.0.dist-info/licenses/LICENCE +35 -0
- lib/IsoSpecCppPy.lib +0 -0
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
/* This file was taken from Boost, as permitted by Boost licence,
|
|
2
|
+
* with slight modifications. The reason is: we don't want to introduce
|
|
3
|
+
* dependency on the whole Boost just for this one thing.
|
|
4
|
+
*
|
|
5
|
+
* Source: boost random/binomial_distribution.hpp header file, at version 1.71
|
|
6
|
+
*
|
|
7
|
+
* Copyright Steven Watanabe 2010
|
|
8
|
+
* Distributed under the Boost Software License, Version 1.0. (See
|
|
9
|
+
* accompanying file LICENSE_1_0.txt or copy at
|
|
10
|
+
* http://www.boost.org/LICENSE_1_0.txt)
|
|
11
|
+
*
|
|
12
|
+
* See http://www.boost.org for most recent version including documentation.
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
#pragma once
|
|
17
|
+
|
|
18
|
+
#include "isoMath.h"
|
|
19
|
+
#include <cstdlib>
|
|
20
|
+
#include <cstdint>
|
|
21
|
+
#include <cmath>
|
|
22
|
+
#include <limits>
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
namespace IsoSpec {
|
|
26
|
+
|
|
27
|
+
typedef double RealType;
|
|
28
|
+
typedef int64_t IntType;
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
static const RealType btrd_binomial_table[10] = {
|
|
32
|
+
0.08106146679532726,
|
|
33
|
+
0.04134069595540929,
|
|
34
|
+
0.02767792568499834,
|
|
35
|
+
0.02079067210376509,
|
|
36
|
+
0.01664469118982119,
|
|
37
|
+
0.01387612882307075,
|
|
38
|
+
0.01189670994589177,
|
|
39
|
+
0.01041126526197209,
|
|
40
|
+
0.009255462182712733,
|
|
41
|
+
0.008330563433362871
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The binomial distribution is an integer valued distribution with
|
|
47
|
+
* two parameters, @c t and @c p. The values of the distribution
|
|
48
|
+
* are within the range [0,t].
|
|
49
|
+
*
|
|
50
|
+
* The distribution function is
|
|
51
|
+
* \f$\displaystyle P(k) = {t \choose k}p^k(1-p)^{t-k}\f$.
|
|
52
|
+
*
|
|
53
|
+
* The algorithm used is the BTRD algorithm described in
|
|
54
|
+
*
|
|
55
|
+
* @blockquote
|
|
56
|
+
* "The generation of binomial random variates", Wolfgang Hormann,
|
|
57
|
+
* Journal of Statistical Computation and Simulation, Volume 46,
|
|
58
|
+
* Issue 1 & 2 April 1993 , pages 101 - 110
|
|
59
|
+
* @endblockquote
|
|
60
|
+
*/
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
// computes the correction factor for the Stirling approximation
|
|
64
|
+
// for log(k!)
|
|
65
|
+
static RealType fc(IntType k)
|
|
66
|
+
{
|
|
67
|
+
if(k < 10) { return btrd_binomial_table[k]; }
|
|
68
|
+
else
|
|
69
|
+
{
|
|
70
|
+
RealType ikp1 = RealType(1) / (k + 1);
|
|
71
|
+
return (RealType(1)/12
|
|
72
|
+
- (RealType(1)/360
|
|
73
|
+
- (RealType(1)/1260)*(ikp1*ikp1))*(ikp1*ikp1))*ikp1;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
IntType btrd(IntType _t, RealType p, IntType m, std::mt19937& urng = random_gen)
|
|
78
|
+
{
|
|
79
|
+
using std::floor;
|
|
80
|
+
using std::abs;
|
|
81
|
+
using std::log;
|
|
82
|
+
|
|
83
|
+
RealType btrd_r = p/(1-p);
|
|
84
|
+
RealType btrd_nr = (_t+1)*btrd_r;
|
|
85
|
+
RealType btrd_npq = _t*p*(1-p);
|
|
86
|
+
RealType sqrt_npq = sqrt(btrd_npq);
|
|
87
|
+
RealType btrd_b = 1.15 + 2.53 * sqrt_npq;
|
|
88
|
+
RealType btrd_a = -0.0873 + 0.0248*btrd_b + 0.01*p;
|
|
89
|
+
RealType btrd_c = _t*p + 0.5;
|
|
90
|
+
RealType btrd_alpha = (2.83 + 5.1/btrd_b) * sqrt_npq;
|
|
91
|
+
RealType btrd_v_r = 0.92 - 4.2/btrd_b;
|
|
92
|
+
RealType btrd_u_rv_r = 0.86*btrd_v_r;
|
|
93
|
+
|
|
94
|
+
while(true) {
|
|
95
|
+
RealType u;
|
|
96
|
+
RealType v = stdunif(urng);
|
|
97
|
+
if(v <= btrd_u_rv_r) {
|
|
98
|
+
u = v/btrd_v_r - 0.43;
|
|
99
|
+
return static_cast<IntType>(floor(
|
|
100
|
+
(2*btrd_a/(0.5 - abs(u)) + btrd_b)*u + btrd_c));
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if(v >= btrd_v_r) {
|
|
104
|
+
u = stdunif(urng) - 0.5;
|
|
105
|
+
} else {
|
|
106
|
+
u = v/btrd_v_r - 0.93;
|
|
107
|
+
u = ((u < 0)? -0.5 : 0.5) - u;
|
|
108
|
+
v = stdunif(urng) * btrd_v_r;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
RealType us = 0.5 - abs(u);
|
|
112
|
+
IntType k = static_cast<IntType>(floor((2*btrd_a/us + btrd_b)*u + btrd_c));
|
|
113
|
+
if(k < 0 || k > _t) continue;
|
|
114
|
+
v = v*btrd_alpha/(btrd_a/(us*us) + btrd_b);
|
|
115
|
+
RealType km = abs(k - m);
|
|
116
|
+
if(km <= 15) {
|
|
117
|
+
RealType f = 1;
|
|
118
|
+
if(m < k) {
|
|
119
|
+
IntType i = m;
|
|
120
|
+
do {
|
|
121
|
+
++i;
|
|
122
|
+
f = f*(btrd_nr/i - btrd_r);
|
|
123
|
+
} while(i != k);
|
|
124
|
+
} else if(m > k) {
|
|
125
|
+
IntType i = k;
|
|
126
|
+
do {
|
|
127
|
+
++i;
|
|
128
|
+
v = v*(btrd_nr/i - btrd_r);
|
|
129
|
+
} while(i != m);
|
|
130
|
+
}
|
|
131
|
+
if(v <= f) return k;
|
|
132
|
+
else continue;
|
|
133
|
+
} else {
|
|
134
|
+
// final acceptance/rejection
|
|
135
|
+
v = log(v);
|
|
136
|
+
RealType rho =
|
|
137
|
+
(km/btrd_npq)*(((km/3. + 0.625)*km + 1./6)/btrd_npq + 0.5);
|
|
138
|
+
RealType t = -km*km/(2*btrd_npq);
|
|
139
|
+
if(v < t - rho) return k;
|
|
140
|
+
if(v > t + rho) continue;
|
|
141
|
+
|
|
142
|
+
IntType nm = _t - m + 1;
|
|
143
|
+
RealType h = (m + 0.5)*log((m + 1)/(btrd_r*nm))
|
|
144
|
+
+ fc(m) + fc(_t - m);
|
|
145
|
+
|
|
146
|
+
IntType nk = _t - k + 1;
|
|
147
|
+
if(v <= h + (_t+1)*log(static_cast<RealType>(nm)/nk)
|
|
148
|
+
+ (k + 0.5)*log(nk*btrd_r/(k+1))
|
|
149
|
+
- fc(k)
|
|
150
|
+
- fc(_t - k))
|
|
151
|
+
{
|
|
152
|
+
return k;
|
|
153
|
+
} else {
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
IntType invert(IntType t, RealType p, std::mt19937& urng = random_gen)
|
|
161
|
+
{
|
|
162
|
+
RealType q = 1 - p;
|
|
163
|
+
RealType s = p / q;
|
|
164
|
+
RealType a = (t + 1) * s;
|
|
165
|
+
RealType r = pow((1 - p), static_cast<RealType>(t));
|
|
166
|
+
RealType u = stdunif(urng);
|
|
167
|
+
IntType x = 0;
|
|
168
|
+
while(u > r) {
|
|
169
|
+
u = u - r;
|
|
170
|
+
++x;
|
|
171
|
+
RealType r1 = ((a/x) - s) * r;
|
|
172
|
+
// If r gets too small then the round-off error
|
|
173
|
+
// becomes a problem. At this point, p(i) is
|
|
174
|
+
// decreasing exponentially, so if we just call
|
|
175
|
+
// it 0, it's close enough. Note that the
|
|
176
|
+
// minimum value of q_n is about 1e-7, so we
|
|
177
|
+
// may need to be a little careful to make sure that
|
|
178
|
+
// we don't terminate the first time through the loop
|
|
179
|
+
// for float. (Hence the test that r is decreasing)
|
|
180
|
+
if(r1 < std::numeric_limits<RealType>::epsilon() && r1 < r) {
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
183
|
+
r = r1;
|
|
184
|
+
}
|
|
185
|
+
return x;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
IntType boost_binomial_distribution_variate(IntType t_arg, RealType p_arg, std::mt19937& urng = random_gen)
|
|
190
|
+
{
|
|
191
|
+
bool other_side = p_arg > 0.5;
|
|
192
|
+
RealType fake_p = other_side ? 1.0 - p_arg : p_arg;
|
|
193
|
+
IntType m = static_cast<IntType>((t_arg+1)*fake_p);
|
|
194
|
+
IntType result;
|
|
195
|
+
if(m < 11)
|
|
196
|
+
result = invert(t_arg, fake_p, urng);
|
|
197
|
+
else
|
|
198
|
+
result = btrd(t_arg, fake_p, m, urng);
|
|
199
|
+
|
|
200
|
+
if(other_side)
|
|
201
|
+
return t_arg - result;
|
|
202
|
+
else
|
|
203
|
+
return result;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
} // namespace IsoSpec
|
|
@@ -0,0 +1,38 @@
|
|
|
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
|
+
namespace IsoSpec
|
|
20
|
+
{
|
|
21
|
+
|
|
22
|
+
typedef int* Conf;
|
|
23
|
+
|
|
24
|
+
struct ProbAndConfPtr
|
|
25
|
+
{
|
|
26
|
+
// For some reason std::pair isn't trivially copyable...
|
|
27
|
+
double first;
|
|
28
|
+
Conf second;
|
|
29
|
+
|
|
30
|
+
ProbAndConfPtr(double p, Conf c) : first(p), second(c) {}
|
|
31
|
+
|
|
32
|
+
bool operator<(const ProbAndConfPtr& other) const
|
|
33
|
+
{
|
|
34
|
+
return first < other.first;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
} // namespace IsoSpec
|
|
@@ -0,0 +1,223 @@
|
|
|
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 "platform.h"
|
|
20
|
+
|
|
21
|
+
#define ISOSPEC_ALGO_LAYERED 0
|
|
22
|
+
#define ISOSPEC_ALGO_ORDERED 1
|
|
23
|
+
#define ISOSPEC_ALGO_THRESHOLD_ABSOLUTE 2
|
|
24
|
+
#define ISOSPEC_ALGO_THRESHOLD_RELATIVE 3
|
|
25
|
+
#define ISOSPEC_ALGO_LAYERED_ESTIMATE 4
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
// Error reporting across the C ABI: these functions never let a C++ exception
|
|
29
|
+
// escape (that would be undefined behaviour for a C / cffi caller). On bad input
|
|
30
|
+
// or out-of-memory they instead return an out-of-band error value:
|
|
31
|
+
// * functions returning a handle/pointer return NULL,
|
|
32
|
+
// * functions returning a double return NaN,
|
|
33
|
+
// * functions returning an integer/bool return 0 / false.
|
|
34
|
+
// Callers should check the returned handle for NULL before using it.
|
|
35
|
+
|
|
36
|
+
#ifdef __cplusplus
|
|
37
|
+
extern "C" {
|
|
38
|
+
#else
|
|
39
|
+
#include <stdbool.h>
|
|
40
|
+
#endif
|
|
41
|
+
|
|
42
|
+
ISOSPEC_C_API void * setupIso(int dimNumber,
|
|
43
|
+
const int* isotopeNumbers,
|
|
44
|
+
const int* atomCounts,
|
|
45
|
+
const double* isotopeMasses,
|
|
46
|
+
const double* isotopeProbabilities);
|
|
47
|
+
|
|
48
|
+
ISOSPEC_C_API void * isoFromFasta(const char* fasta, bool use_nominal_masses, bool add_water);
|
|
49
|
+
|
|
50
|
+
ISOSPEC_C_API double getLightestPeakMassIso(void* iso);
|
|
51
|
+
ISOSPEC_C_API double getLightestPeakLProbIso(void* iso);
|
|
52
|
+
ISOSPEC_C_API void getLightestPeakSignature(void* iso, int* space);
|
|
53
|
+
ISOSPEC_C_API double getHeaviestPeakMassIso(void* iso);
|
|
54
|
+
ISOSPEC_C_API double getHeaviestPeakLProbIso(void* iso);
|
|
55
|
+
ISOSPEC_C_API void getHeaviestPeakSignature(void* iso, int* space);
|
|
56
|
+
ISOSPEC_C_API double getMonoisotopicPeakMassIso(void* iso);
|
|
57
|
+
ISOSPEC_C_API double getMonoisotopicPeakLProbIso(void* iso);
|
|
58
|
+
ISOSPEC_C_API void getMonoisotopicPeakSignature(void* iso, int* space);
|
|
59
|
+
ISOSPEC_C_API double getModeLProbIso(void* iso);
|
|
60
|
+
ISOSPEC_C_API double getModeMassIso(void* iso);
|
|
61
|
+
ISOSPEC_C_API double getTheoreticalAverageMassIso(void* iso);
|
|
62
|
+
ISOSPEC_C_API double getIsoVariance(void* iso);
|
|
63
|
+
ISOSPEC_C_API double getIsoStddev(void* iso);
|
|
64
|
+
ISOSPEC_C_API double* getMarginalLogSizeEstimates(void* iso, double target_total_prob);
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
ISOSPEC_C_API void deleteIso(void* iso);
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
// ______________________________________________________THRESHOLD GENERATOR
|
|
71
|
+
ISOSPEC_C_API void* setupIsoThresholdGenerator(void* iso,
|
|
72
|
+
double threshold,
|
|
73
|
+
bool _absolute,
|
|
74
|
+
int _tabSize,
|
|
75
|
+
int _hashSize,
|
|
76
|
+
bool reorder_marginals);
|
|
77
|
+
ISOSPEC_C_API double massIsoThresholdGenerator(void* generator);
|
|
78
|
+
ISOSPEC_C_API double lprobIsoThresholdGenerator(void* generator);
|
|
79
|
+
ISOSPEC_C_API double probIsoThresholdGenerator(void* generator);
|
|
80
|
+
ISOSPEC_C_API void get_conf_signatureIsoThresholdGenerator(void* generator, int* space);
|
|
81
|
+
ISOSPEC_C_API bool advanceToNextConfigurationIsoThresholdGenerator(void* generator);
|
|
82
|
+
ISOSPEC_C_API void deleteIsoThresholdGenerator(void* generator);
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
// ______________________________________________________LAYERED GENERATOR
|
|
86
|
+
ISOSPEC_C_API void* setupIsoLayeredGenerator(void* iso,
|
|
87
|
+
int _tabSize,
|
|
88
|
+
int _hashSize,
|
|
89
|
+
bool reorder_marginals,
|
|
90
|
+
double t_prob_hint);
|
|
91
|
+
ISOSPEC_C_API double massIsoLayeredGenerator(void* generator);
|
|
92
|
+
ISOSPEC_C_API double lprobIsoLayeredGenerator(void* generator);
|
|
93
|
+
ISOSPEC_C_API double probIsoLayeredGenerator(void* generator);
|
|
94
|
+
ISOSPEC_C_API void get_conf_signatureIsoLayeredGenerator(void* generator, int* space);
|
|
95
|
+
ISOSPEC_C_API bool advanceToNextConfigurationIsoLayeredGenerator(void* generator);
|
|
96
|
+
ISOSPEC_C_API void deleteIsoLayeredGenerator(void* generator);
|
|
97
|
+
|
|
98
|
+
// ______________________________________________________ORDERED GENERATOR
|
|
99
|
+
ISOSPEC_C_API void* setupIsoOrderedGenerator(void* iso,
|
|
100
|
+
int _tabSize,
|
|
101
|
+
int _hashSize);
|
|
102
|
+
ISOSPEC_C_API double massIsoOrderedGenerator(void* generator);
|
|
103
|
+
ISOSPEC_C_API double lprobIsoOrderedGenerator(void* generator);
|
|
104
|
+
ISOSPEC_C_API double probIsoOrderedGenerator(void* generator);
|
|
105
|
+
ISOSPEC_C_API void get_conf_signatureIsoOrderedGenerator(void* generator, int* space);
|
|
106
|
+
ISOSPEC_C_API bool advanceToNextConfigurationIsoOrderedGenerator(void* generator);
|
|
107
|
+
ISOSPEC_C_API void deleteIsoOrderedGenerator(void* generator);
|
|
108
|
+
|
|
109
|
+
// ______________________________________________________STOCHASTIC GENERATOR
|
|
110
|
+
ISOSPEC_C_API void* setupIsoStochasticGenerator(void* iso,
|
|
111
|
+
size_t no_molecules,
|
|
112
|
+
double precision,
|
|
113
|
+
double beta_bias);
|
|
114
|
+
ISOSPEC_C_API double massIsoStochasticGenerator(void* generator);
|
|
115
|
+
ISOSPEC_C_API double lprobIsoStochasticGenerator(void* generator);
|
|
116
|
+
ISOSPEC_C_API double probIsoStochasticGenerator(void* generator);
|
|
117
|
+
ISOSPEC_C_API void get_conf_signatureIsoStochasticGenerator(void* generator, int* space);
|
|
118
|
+
ISOSPEC_C_API bool advanceToNextConfigurationIsoStochasticGenerator(void* generator);
|
|
119
|
+
ISOSPEC_C_API void deleteIsoStochasticGenerator(void* generator);
|
|
120
|
+
|
|
121
|
+
ISOSPEC_C_API void* setupThresholdFixedEnvelope(void* iso,
|
|
122
|
+
double threshold,
|
|
123
|
+
bool absolute,
|
|
124
|
+
bool get_confs);
|
|
125
|
+
|
|
126
|
+
ISOSPEC_C_API void* setupTotalProbFixedEnvelope(void* iso,
|
|
127
|
+
double taget_coverage,
|
|
128
|
+
bool optimize,
|
|
129
|
+
bool get_confs);
|
|
130
|
+
|
|
131
|
+
ISOSPEC_C_API void* setupStochasticFixedEnvelope(void* iso,
|
|
132
|
+
size_t no_molecules,
|
|
133
|
+
double precision,
|
|
134
|
+
double beta_bias,
|
|
135
|
+
bool get_confs);
|
|
136
|
+
|
|
137
|
+
ISOSPEC_C_API void* setupBinnedFixedEnvelope(void* iso,
|
|
138
|
+
double target_total_prob,
|
|
139
|
+
double bin_width,
|
|
140
|
+
double bin_middle);
|
|
141
|
+
|
|
142
|
+
ISOSPEC_C_API void freeReleasedArray(void* array);
|
|
143
|
+
|
|
144
|
+
ISOSPEC_C_API void array_add(double* array, size_t N, double what);
|
|
145
|
+
ISOSPEC_C_API void array_mul(double* array, size_t N, double what);
|
|
146
|
+
ISOSPEC_C_API void array_fma(double* array, size_t N, double mul, double add);
|
|
147
|
+
|
|
148
|
+
ISOSPEC_C_API void* setupFixedEnvelope(double* masses, double* probs, size_t size, bool mass_sorted, bool prob_sorted, double total_prob);
|
|
149
|
+
ISOSPEC_C_API void* setupFixedEnvelopeWithConfs(double* masses, double* probs, int* confs, size_t size, int allDim, bool mass_sorted, bool prob_sorted, double total_prob);
|
|
150
|
+
ISOSPEC_C_API void* copyFixedEnvelope(void* other);
|
|
151
|
+
ISOSPEC_C_API void deleteFixedEnvelope(void* tabulator, bool releaseEverything);
|
|
152
|
+
|
|
153
|
+
/* These three hand the envelope's array over to the caller, who must free() it
|
|
154
|
+
(with freeReleasedArray) once done. That costs a copy of the whole array
|
|
155
|
+
whenever the envelope did not allocate it with plain malloc() -- which is the
|
|
156
|
+
normal case now that everything the library produces is SIMD-aligned, and one
|
|
157
|
+
that grew large enough is mapped straight from the OS. Prefer the *WithDeleter
|
|
158
|
+
variants below, which never copy. */
|
|
159
|
+
ISOSPEC_C_API const double* massesFixedEnvelope(void* tabulator);
|
|
160
|
+
ISOSPEC_C_API const double* probsFixedEnvelope(void* tabulator);
|
|
161
|
+
ISOSPEC_C_API const int* confsFixedEnvelope(void* tabulator);
|
|
162
|
+
ISOSPEC_C_API size_t confs_noFixedEnvelope(void* tabulator);
|
|
163
|
+
|
|
164
|
+
/* How a buffer obtained from one of the *WithDeleter entry points below has to
|
|
165
|
+
be given back: deleter(array, size), exactly once, with the very size that
|
|
166
|
+
came out alongside the pointer. free() is not, in general, the right answer.
|
|
167
|
+
Call it through freeReleasedArrayWithDeleter() rather than directly, so
|
|
168
|
+
callers that cannot invoke a raw function pointer (cffi, say) need not. */
|
|
169
|
+
typedef void (*IsoSpecArrayDeleter)(void* array, size_t size);
|
|
170
|
+
|
|
171
|
+
/* Zero-copy counterparts of the three getters above: each yields the array's
|
|
172
|
+
pointer and writes out the (size, deleter) pair needed to release it. Both
|
|
173
|
+
out-parameters may be NULL if not wanted -- but then the array can only be
|
|
174
|
+
leaked. A NULL return means either an empty envelope or an error. */
|
|
175
|
+
ISOSPEC_C_API double* massesFixedEnvelopeWithDeleter(void* tabulator, size_t* size_out, IsoSpecArrayDeleter* deleter_out);
|
|
176
|
+
ISOSPEC_C_API double* probsFixedEnvelopeWithDeleter(void* tabulator, size_t* size_out, IsoSpecArrayDeleter* deleter_out);
|
|
177
|
+
ISOSPEC_C_API int* confsFixedEnvelopeWithDeleter(void* tabulator, size_t* size_out, IsoSpecArrayDeleter* deleter_out);
|
|
178
|
+
|
|
179
|
+
ISOSPEC_C_API void freeReleasedArrayWithDeleter(void* array, size_t size, IsoSpecArrayDeleter deleter);
|
|
180
|
+
|
|
181
|
+
ISOSPEC_C_API double empiricAverageMass(void* tabulator);
|
|
182
|
+
ISOSPEC_C_API double empiricVariance(void* tabulator);
|
|
183
|
+
ISOSPEC_C_API double empiricStddev(void* tabulator);
|
|
184
|
+
|
|
185
|
+
ISOSPEC_C_API double wassersteinDistance(void* tabulator1, void* tabulator2);
|
|
186
|
+
ISOSPEC_C_API double orientedWassersteinDistance(void* tabulator1, void* tabulator2);
|
|
187
|
+
ISOSPEC_C_API double abyssalWassersteinDistance(void* tabulator1, void* tabulator2, double abyss_depth, double other_scale);
|
|
188
|
+
//ISOSPEC_C_API double abyssalWassersteinDistanceGrad(void* const* envelopes, const double* scales, double* ret_gradient, size_t N, double abyss_depth_exp, double abyss_depth_the);
|
|
189
|
+
|
|
190
|
+
struct ws_match_res{
|
|
191
|
+
double res1;
|
|
192
|
+
double res2;
|
|
193
|
+
double flow;
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
ISOSPEC_C_API struct ws_match_res wassersteinMatch(void* tabulator1, void* tabulator2, double flow_dist, double other_scale);
|
|
197
|
+
|
|
198
|
+
ISOSPEC_C_API void* addEnvelopes(void* tabulator1, void* tabulator2);
|
|
199
|
+
ISOSPEC_C_API void* convolveEnvelopes(void* tabulator1, void* tabulator2);
|
|
200
|
+
|
|
201
|
+
ISOSPEC_C_API double getTotalProbOfEnvelope(void* envelope);
|
|
202
|
+
ISOSPEC_C_API void scaleEnvelope(void* envelope, double factor);
|
|
203
|
+
ISOSPEC_C_API void normalizeEnvelope(void* envelope);
|
|
204
|
+
ISOSPEC_C_API void shiftMassEnvelope(void* envelope, double d_mass);
|
|
205
|
+
ISOSPEC_C_API void resampleEnvelope(void* envelope, size_t ionic_current, double beta_bias);
|
|
206
|
+
ISOSPEC_C_API void* binnedEnvelope(void* envelope, double width, double middle);
|
|
207
|
+
ISOSPEC_C_API void* linearCombination(void* const * const envelopes, const double* intensities, size_t count);
|
|
208
|
+
|
|
209
|
+
ISOSPEC_C_API void sortEnvelopeByMass(void* envelope);
|
|
210
|
+
ISOSPEC_C_API void sortEnvelopeByProb(void* envelope);
|
|
211
|
+
|
|
212
|
+
ISOSPEC_C_API void parse_fasta_c(const char* fasta, int atomCounts[6]);
|
|
213
|
+
|
|
214
|
+
/* What the library's batched kernels are vectorised to on this machine, as a
|
|
215
|
+
stable lowercase token: "scalar", "sse2", "avx", "avx2", "avx512", "neon", or
|
|
216
|
+
"simd" for a vector unit with no name here. Never NULL; a static string, so
|
|
217
|
+
it must NOT be freed. See active_simd_level() in isa_kernels.h. */
|
|
218
|
+
ISOSPEC_C_API const char* activeSimdLevel(void);
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
#ifdef __cplusplus
|
|
222
|
+
}
|
|
223
|
+
#endif
|
|
@@ -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,70 @@
|
|
|
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
|
+
#include <cstddef>
|
|
21
|
+
#include <cstring>
|
|
22
|
+
|
|
23
|
+
namespace IsoSpec{
|
|
24
|
+
|
|
25
|
+
// We will work with C H N O S Se tuples */
|
|
26
|
+
extern const int aa_isotope_numbers[6];
|
|
27
|
+
|
|
28
|
+
extern const double aa_elem_masses[19];
|
|
29
|
+
|
|
30
|
+
extern const double aa_elem_nominal_masses[19];
|
|
31
|
+
|
|
32
|
+
extern const double aa_elem_probabilities[19];
|
|
33
|
+
|
|
34
|
+
extern const int aa_symbol_to_elem_counts[256*6];
|
|
35
|
+
|
|
36
|
+
//! Count elemental composition of an unmodificed sequence of amino acids, resulting in CHNOSSe counts.
|
|
37
|
+
/*!
|
|
38
|
+
WARNING!!! This function does not add the terminating H and OH groups, resulting in a residue backbone skeleton formula.
|
|
39
|
+
If you don't know what that means, you should probably be using parse_fasta_full function.
|
|
40
|
+
*/
|
|
41
|
+
inline void parse_fasta(const char* fasta, int atomCounts[6])
|
|
42
|
+
{
|
|
43
|
+
memset(atomCounts, 0, sizeof(decltype(atomCounts[0]))*6);
|
|
44
|
+
|
|
45
|
+
for(size_t idx = 0; fasta[idx] != '\0'; ++idx)
|
|
46
|
+
{
|
|
47
|
+
const int* counts = &aa_symbol_to_elem_counts[static_cast<unsigned char>(fasta[idx])*6];
|
|
48
|
+
for(int ii = 0; ii < 6; ++ii)
|
|
49
|
+
atomCounts[ii] += counts[ii];
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
//! Turn an input FASTA aminoacid sequence into atom counts, in CHNOSSe order.
|
|
54
|
+
/*!
|
|
55
|
+
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.
|
|
56
|
+
*/
|
|
57
|
+
inline void parse_fasta_full(const char* fasta, int atomCounts[6])
|
|
58
|
+
{
|
|
59
|
+
parse_fasta(fasta, atomCounts);
|
|
60
|
+
// Add terminal water (H2O) for either precursor or fragment.
|
|
61
|
+
const int H_INDEX = 1; // Indexing: 0=C, 1=H, 2=N, 3=O, 4=S, 5=Se
|
|
62
|
+
const int O_INDEX = 3;
|
|
63
|
+
|
|
64
|
+
atomCounts[H_INDEX] += 2;
|
|
65
|
+
atomCounts[O_INDEX] += 1;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
} // namespace IsoSpec
|