24 #include "marginalTrek++.h"
25 #include "isoSpec++.h"
26 #include "fixedEnvelopes.h"
34 void * 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);
45 void * isoFromFasta(
const char* fasta,
bool use_nominal_masses,
bool add_water)
49 return reinterpret_cast<void*
>(iso);
52 void deleteIso(
void* iso)
54 delete reinterpret_cast<Iso*
>(iso);
57 double getLightestPeakMassIso(
void* iso)
59 return reinterpret_cast<Iso*
>(iso)->getLightestPeakMass();
62 double getHeaviestPeakMassIso(
void* iso)
64 return reinterpret_cast<Iso*
>(iso)->getHeaviestPeakMass();
67 double getMonoisotopicPeakMassIso(
void* iso)
69 return reinterpret_cast<Iso*
>(iso)->getMonoisotopicPeakMass();
72 double getModeLProbIso(
void* iso)
74 return reinterpret_cast<Iso*
>(iso)->getModeLProb();
77 double getModeMassIso(
void* iso)
79 return reinterpret_cast<Iso*
>(iso)->getModeMass();
82 double getTheoreticalAverageMassIso(
void* iso)
84 return reinterpret_cast<Iso*
>(iso)->getTheoreticalAverageMass();
87 double getIsoVariance(
void* iso)
89 return reinterpret_cast<Iso*
>(iso)->variance();
92 double getIsoStddev(
void* iso)
94 return reinterpret_cast<Iso*
>(iso)->stddev();
98 double* 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)\
110 dataType method##generatorType(void* generator){ return reinterpret_cast<generatorType*>(generator)->method(); }
112 #define ISOSPEC_C_FN_CODE_GET_CONF_SIGNATURE(generatorType)\
113 void 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)\
120 ISOSPEC_C_FN_CODE(generatorType, double, mass) \
121 ISOSPEC_C_FN_CODE(generatorType, double, lprob) \
122 ISOSPEC_C_FN_CODE(generatorType, double, prob) \
123 ISOSPEC_C_FN_CODE_GET_CONF_SIGNATURE(generatorType) \
124 ISOSPEC_C_FN_CODE(generatorType, bool, advanceToNextConfiguration) \
125 ISOSPEC_C_FN_DELETE(generatorType)
130 void* setupIsoThresholdGenerator(
void* iso,
135 bool reorder_marginals)
138 std::move(*
reinterpret_cast<Iso*
>(iso)),
145 return reinterpret_cast<void*
>(iso_tmp);
151 void* setupIsoLayeredGenerator(
void* iso,
154 bool reorder_marginals,
159 std::move(*
reinterpret_cast<Iso*
>(iso)),
166 return reinterpret_cast<void*
>(iso_tmp);
172 void* setupIsoOrderedGenerator(
void* iso,
177 std::move(*
reinterpret_cast<Iso*
>(iso)),
181 return reinterpret_cast<void*
>(iso_tmp);
186 void* setupIsoStochasticGenerator(
void* iso,
192 std::move(*
reinterpret_cast<Iso*
>(iso)),
197 return reinterpret_cast<void*
>(iso_tmp);
203 void* setupThresholdFixedEnvelope(
void* iso,
209 FixedEnvelope::FromThreshold(
Iso(*
reinterpret_cast<const Iso*
>(iso),
true),
214 return reinterpret_cast<void*
>(ret);
217 void* setupTotalProbFixedEnvelope(
void* iso,
218 double target_coverage,
223 FixedEnvelope::FromTotalProb(
Iso(*
reinterpret_cast<const Iso*
>(iso),
true),
228 return reinterpret_cast<void*
>(ret);
231 void* setupStochasticFixedEnvelope(
void* iso,
238 FixedEnvelope::FromStochastic(
Iso(*
reinterpret_cast<const Iso*
>(iso),
true),
244 return reinterpret_cast<void*
>(ret);
248 void* setupBinnedFixedEnvelope(
void* iso,
249 double target_total_prob,
254 FixedEnvelope::Binned(
Iso(*
reinterpret_cast<const Iso*
>(iso),
true),
259 return reinterpret_cast<void*
>(ret);
262 void* setupFixedEnvelope(
double* masses,
double* probs,
size_t size,
bool mass_sorted,
bool prob_sorted,
double total_prob)
265 return reinterpret_cast<void*
>(ret);
268 void deleteFixedEnvelope(
void* t,
bool release_everything)
271 if(release_everything)
273 tt->release_masses();
280 void* copyFixedEnvelope(
void* other)
283 return reinterpret_cast<void*
>(ret);
286 const double* massesFixedEnvelope(
void* tabulator)
288 return reinterpret_cast<FixedEnvelope*
>(tabulator)->release_masses();
291 const double* probsFixedEnvelope(
void* tabulator)
293 return reinterpret_cast<FixedEnvelope*
>(tabulator)->release_probs();
296 const int* confsFixedEnvelope(
void* tabulator)
298 return reinterpret_cast<FixedEnvelope*
>(tabulator)->release_confs();
301 size_t confs_noFixedEnvelope(
void* tabulator)
303 return reinterpret_cast<FixedEnvelope*
>(tabulator)->confs_no();
306 double empiricAverageMass(
void* tabulator)
308 return reinterpret_cast<FixedEnvelope*
>(tabulator)->empiric_average_mass();
311 double empiricVariance(
void* tabulator)
313 return reinterpret_cast<FixedEnvelope*
>(tabulator)->empiric_variance();
316 double empiricStddev(
void* tabulator)
318 return reinterpret_cast<FixedEnvelope*
>(tabulator)->empiric_stddev();
321 double wassersteinDistance(
void* tabulator1,
void* tabulator2)
327 catch(std::logic_error&)
333 double orientedWassersteinDistance(
void* tabulator1,
void* tabulator2)
337 return reinterpret_cast<FixedEnvelope*
>(tabulator1)->OrientedWassersteinDistance(*
reinterpret_cast<FixedEnvelope*
>(tabulator2));
339 catch(std::logic_error&)
345 double 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);
351 double 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);
357 struct 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);
367 void* addEnvelopes(
void* tabulator1,
void* tabulator2)
373 void* convolveEnvelopes(
void* tabulator1,
void* tabulator2)
379 double getTotalProbOfEnvelope(
void* envelope)
381 return reinterpret_cast<FixedEnvelope*
>(envelope)->get_total_prob();
384 void scaleEnvelope(
void* envelope,
double factor)
389 void normalizeEnvelope(
void* envelope)
394 void shiftMassEnvelope(
void* envelope,
double d_mass)
396 reinterpret_cast<FixedEnvelope*
>(envelope)->shift_mass(d_mass);
399 void resampleEnvelope(
void* envelope,
size_t ionic_current,
double beta_bias)
401 reinterpret_cast<FixedEnvelope*
>(envelope)->resample(ionic_current, beta_bias);
405 void* binnedEnvelope(
void* envelope,
double width,
double middle)
411 void* 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)));
417 void sortEnvelopeByMass(
void* envelope)
422 void sortEnvelopeByProb(
void* envelope)
427 void freeReleasedArray(
void* array)
432 void array_add(
double* array,
size_t N,
double what)
434 for(
size_t ii = 0; ii < N; ii++)
438 void array_mul(
double* array,
size_t N,
double what)
440 for(
size_t ii = 0; ii < N; ii++)
444 void 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;
454 void 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.