24#include "marginalTrek++.h"
26#include "fixedEnvelopes.h"
34void * setupIso(
int dimNumber,
35 const int* isotopeNumbers,
36 const int* atomCounts,
37 const double* isotopeMasses,
38 const double* isotopeProbabilities)
40 Iso* iso =
new Iso(dimNumber, isotopeNumbers, atomCounts, isotopeMasses, isotopeProbabilities);
42 return reinterpret_cast<void*
>(iso);
45void * isoFromFasta(
const char* fasta,
bool use_nominal_masses,
bool add_water)
49 return reinterpret_cast<void*
>(iso);
52void deleteIso(
void* iso)
54 delete reinterpret_cast<Iso*
>(iso);
57double getLightestPeakMassIso(
void* iso)
59 return reinterpret_cast<Iso*
>(iso)->getLightestPeakMass();
62double getHeaviestPeakMassIso(
void* iso)
64 return reinterpret_cast<Iso*
>(iso)->getHeaviestPeakMass();
67double getMonoisotopicPeakMassIso(
void* iso)
69 return reinterpret_cast<Iso*
>(iso)->getMonoisotopicPeakMass();
72double getModeLProbIso(
void* iso)
74 return reinterpret_cast<Iso*
>(iso)->getModeLProb();
77double getModeMassIso(
void* iso)
79 return reinterpret_cast<Iso*
>(iso)->getModeMass();
82double getTheoreticalAverageMassIso(
void* iso)
84 return reinterpret_cast<Iso*
>(iso)->getTheoreticalAverageMass();
87double getIsoVariance(
void* iso)
89 return reinterpret_cast<Iso*
>(iso)->variance();
92double getIsoStddev(
void* iso)
94 return reinterpret_cast<Iso*
>(iso)->stddev();
98double* getMarginalLogSizeEstimates(
void* iso,
double target_total_prob)
100 Iso* i =
reinterpret_cast<Iso*
>(iso);
101 double* ret =
reinterpret_cast<double*
>(malloc(
sizeof(
double)*i->
getDimNumber()));
109#define ISOSPEC_C_FN_CODE(generatorType, dataType, method)\
110dataType method##generatorType(void* generator){ return reinterpret_cast<generatorType*>(generator)->method(); }
112#define ISOSPEC_C_FN_CODE_GET_CONF_SIGNATURE(generatorType)\
113void get_conf_signature##generatorType(void* generator, int* space)\
114{ reinterpret_cast<generatorType*>(generator)->get_conf_signature(space); }
117#define ISOSPEC_C_FN_DELETE(generatorType) void delete##generatorType(void* generator){ delete reinterpret_cast<generatorType*>(generator); }
119#define ISOSPEC_C_FN_CODES(generatorType)\
120ISOSPEC_C_FN_CODE(generatorType, double, mass) \
121ISOSPEC_C_FN_CODE(generatorType, double, lprob) \
122ISOSPEC_C_FN_CODE(generatorType, double, prob) \
123ISOSPEC_C_FN_CODE_GET_CONF_SIGNATURE(generatorType) \
124ISOSPEC_C_FN_CODE(generatorType, bool, advanceToNextConfiguration) \
125ISOSPEC_C_FN_DELETE(generatorType)
130void* setupIsoThresholdGenerator(
void* iso,
135 bool reorder_marginals)
138 std::move(*
reinterpret_cast<Iso*
>(iso)),
145 return reinterpret_cast<void*
>(iso_tmp);
151void* setupIsoLayeredGenerator(
void* iso,
154 bool reorder_marginals,
159 std::move(*
reinterpret_cast<Iso*
>(iso)),
166 return reinterpret_cast<void*
>(iso_tmp);
172void* setupIsoOrderedGenerator(
void* iso,
177 std::move(*
reinterpret_cast<Iso*
>(iso)),
181 return reinterpret_cast<void*
>(iso_tmp);
186void* setupIsoStochasticGenerator(
void* iso,
192 std::move(*
reinterpret_cast<Iso*
>(iso)),
197 return reinterpret_cast<void*
>(iso_tmp);
203void* setupThresholdFixedEnvelope(
void* iso,
209 FixedEnvelope::FromThreshold(
Iso(*
reinterpret_cast<const Iso*
>(iso),
true),
214 return reinterpret_cast<void*
>(ret);
217void* setupTotalProbFixedEnvelope(
void* iso,
218 double target_coverage,
223 FixedEnvelope::FromTotalProb(
Iso(*
reinterpret_cast<const Iso*
>(iso),
true),
228 return reinterpret_cast<void*
>(ret);
231void* setupStochasticFixedEnvelope(
void* iso,
238 FixedEnvelope::FromStochastic(
Iso(*
reinterpret_cast<const Iso*
>(iso),
true),
244 return reinterpret_cast<void*
>(ret);
248void* setupBinnedFixedEnvelope(
void* iso,
249 double target_total_prob,
254 FixedEnvelope::Binned(
Iso(*
reinterpret_cast<const Iso*
>(iso),
true),
259 return reinterpret_cast<void*
>(ret);
262void* setupFixedEnvelope(
double* masses,
double* probs,
size_t size,
bool mass_sorted,
bool prob_sorted,
double total_prob)
265 return reinterpret_cast<void*
>(ret);
268void deleteFixedEnvelope(
void* t,
bool release_everything)
271 if(release_everything)
273 tt->release_masses();
280void* copyFixedEnvelope(
void* other)
283 return reinterpret_cast<void*
>(ret);
286const double* massesFixedEnvelope(
void* tabulator)
288 return reinterpret_cast<FixedEnvelope*
>(tabulator)->release_masses();
291const double* probsFixedEnvelope(
void* tabulator)
293 return reinterpret_cast<FixedEnvelope*
>(tabulator)->release_probs();
296const int* confsFixedEnvelope(
void* tabulator)
298 return reinterpret_cast<FixedEnvelope*
>(tabulator)->release_confs();
301size_t confs_noFixedEnvelope(
void* tabulator)
303 return reinterpret_cast<FixedEnvelope*
>(tabulator)->confs_no();
306double empiricAverageMass(
void* tabulator)
308 return reinterpret_cast<FixedEnvelope*
>(tabulator)->empiric_average_mass();
311double empiricVariance(
void* tabulator)
313 return reinterpret_cast<FixedEnvelope*
>(tabulator)->empiric_variance();
316double empiricStddev(
void* tabulator)
318 return reinterpret_cast<FixedEnvelope*
>(tabulator)->empiric_stddev();
321double wassersteinDistance(
void* tabulator1,
void* tabulator2)
327 catch(std::logic_error&)
333double orientedWassersteinDistance(
void* tabulator1,
void* tabulator2)
337 return reinterpret_cast<FixedEnvelope*
>(tabulator1)->OrientedWassersteinDistance(*
reinterpret_cast<FixedEnvelope*
>(tabulator2));
339 catch(std::logic_error&)
345double abyssalWassersteinDistance(
void* tabulator1,
void* tabulator2,
double abyss_depth,
double other_scale)
347 return reinterpret_cast<FixedEnvelope*
>(tabulator1)->AbyssalWassersteinDistance(*
reinterpret_cast<FixedEnvelope*
>(tabulator2), abyss_depth, other_scale);
351double abyssalWassersteinDistanceGrad(
void*
const* envelopes,
const double* scales,
double* ret_gradient,
size_t N,
double abyss_depth_exp,
double abyss_depth_the)
353 return AbyssalWassersteinDistanceGrad(
reinterpret_cast<FixedEnvelope* const*
>(envelopes), scales, ret_gradient, N, abyss_depth_exp, abyss_depth_the);
357struct ws_match_res wassersteinMatch(void* tabulator1,
void* tabulator2,
double flow_dist,
double other_scale)
360 auto [t1, t2, t3] =
reinterpret_cast<FixedEnvelope*
>(tabulator1)->WassersteinMatch(*
reinterpret_cast<FixedEnvelope*
>(tabulator2), flow_dist, other_scale);
367void* addEnvelopes(
void* tabulator1,
void* tabulator2)
373void* convolveEnvelopes(
void* tabulator1,
void* tabulator2)
379double getTotalProbOfEnvelope(
void* envelope)
381 return reinterpret_cast<FixedEnvelope*
>(envelope)->get_total_prob();
384void scaleEnvelope(
void* envelope,
double factor)
389void normalizeEnvelope(
void* envelope)
394void shiftMassEnvelope(
void* envelope,
double d_mass)
396 reinterpret_cast<FixedEnvelope*
>(envelope)->shift_mass(d_mass);
399void resampleEnvelope(
void* envelope,
size_t ionic_current,
double beta_bias)
401 reinterpret_cast<FixedEnvelope*
>(envelope)->resample(ionic_current, beta_bias);
405void* binnedEnvelope(
void* envelope,
double width,
double middle)
411void* linearCombination(
void*
const *
const envelopes,
const double* intensities,
size_t count)
414 return reinterpret_cast<void*
>(
new FixedEnvelope(FixedEnvelope::LinearCombination(
reinterpret_cast<const FixedEnvelope*
const *
>(envelopes), intensities, count)));
417void sortEnvelopeByMass(
void* envelope)
422void sortEnvelopeByProb(
void* envelope)
427void freeReleasedArray(
void* array)
432void array_add(
double* array,
size_t N,
double what)
434 for(
size_t ii = 0; ii < N; ii++)
438void array_mul(
double* array,
size_t N,
double what)
440 for(
size_t ii = 0; ii < N; ii++)
444void array_fma(
double* array,
size_t N,
double mul,
double add)
446 for(
size_t ii = 0; ii < N; ii++)
447#
if defined(FP_FAST_FMA)
448 array[ii] = std::fma(array[ii], mul, add);
450 array[ii] += (array[ii] * mul) + add;
454void parse_fasta_c(
const char* fasta,
int atomCounts[6])
457 parse_fasta(fasta, atomCounts);
The Iso class for the calculation of the isotopic distribution.
void saveMarginalLogSizeEstimates(double *priorities, double target_total_prob) const
Save estimates of logarithms of target sizes of marginals using Gaussian approximation into argument ...
int getDimNumber() const
Get the number of elements in the chemical formula of the molecule.
static Iso FromFASTA(const char *fasta, bool use_nominal_masses=false, bool add_water=true)
Constructor (named) from aminoacid FASTA sequence as C string.
The generator of isotopologues sorted by their probability of occurrence.
The generator of isotopologues above a given threshold value.