IsoSpec  2.2.1
cwrapper.h
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 #define ISOSPEC_ALGO_LAYERED 0
20 #define ISOSPEC_ALGO_ORDERED 1
21 #define ISOSPEC_ALGO_THRESHOLD_ABSOLUTE 2
22 #define ISOSPEC_ALGO_THRESHOLD_RELATIVE 3
23 #define ISOSPEC_ALGO_LAYERED_ESTIMATE 4
24 
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #else
29 #include <stdbool.h>
30 #endif
31 
32 ISOSPEC_C_API void * setupIso(int dimNumber,
33  const int* isotopeNumbers,
34  const int* atomCounts,
35  const double* isotopeMasses,
36  const double* isotopeProbabilities);
37 
38 ISOSPEC_C_API void * isoFromFasta(const char* fasta, bool use_nominal_masses, bool add_water);
39 
40 ISOSPEC_C_API double getLightestPeakMassIso(void* iso);
41 ISOSPEC_C_API double getHeaviestPeakMassIso(void* iso);
42 ISOSPEC_C_API double getMonoisotopicPeakMassIso(void* iso);
43 ISOSPEC_C_API double getModeLProbIso(void* iso);
44 ISOSPEC_C_API double getModeMassIso(void* iso);
45 ISOSPEC_C_API double getTheoreticalAverageMassIso(void* iso);
46 ISOSPEC_C_API double getIsoVariance(void* iso);
47 ISOSPEC_C_API double getIsoStddev(void* iso);
48 ISOSPEC_C_API double* getMarginalLogSizeEstimates(void* iso, double target_total_prob);
49 
50 
51 ISOSPEC_C_API void deleteIso(void* iso);
52 
53 #define ISOSPEC_C_FN_HEADER(generatorType, dataType, method)\
54 ISOSPEC_C_API dataType method##generatorType(void* generator);
55 
56 #define ISOSPEC_C_FN_HEADER_GET_CONF_SIGNATURE(generatorType)\
57 ISOSPEC_C_API void method##generatorType(void* generator);
58 
59 #define ISOSPEC_C_FN_HEADERS(generatorType)\
60 ISOSPEC_C_FN_HEADER(generatorType, double, mass) \
61 ISOSPEC_C_FN_HEADER(generatorType, double, lprob) \
62 ISOSPEC_C_FN_HEADER(generatorType, double, prob) \
63 ISOSPEC_C_FN_HEADER_GET_CONF_SIGNATURE(generatorType) \
64 ISOSPEC_C_FN_HEADER(generatorType, bool, advanceToNextConfiguration) \
65 ISOSPEC_C_FN_HEADER(generatorType, void, delete)
66 
67 
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_FN_HEADERS(IsoThresholdGenerator)
78 
79 
80 // ______________________________________________________LAYERED GENERATOR
81 ISOSPEC_C_API void* setupIsoLayeredGenerator(void* iso,
82  int _tabSize,
83  int _hashSize,
84  bool reorder_marginals,
85  double t_prob_hint);
86 ISOSPEC_C_FN_HEADERS(IsoLayeredGenerator)
87 
88 // ______________________________________________________ORDERED GENERATOR
89 ISOSPEC_C_API void* setupIsoOrderedGenerator(void* iso,
90  int _tabSize,
91  int _hashSize);
92 ISOSPEC_C_FN_HEADERS(IsoOrderedGenerator)
93 
94 ISOSPEC_C_API void* setupIsoStochasticGenerator(void* iso,
95  size_t no_molecules,
96  double precision,
97  double beta_bias);
98 ISOSPEC_C_FN_HEADERS(IsoStochasticGenerator)
99 
100 
101 ISOSPEC_C_API void* setupThresholdFixedEnvelope(void* iso,
102  double threshold,
103  bool absolute,
104  bool get_confs);
105 
106 ISOSPEC_C_API void* setupTotalProbFixedEnvelope(void* iso,
107  double taget_coverage,
108  bool optimize,
109  bool get_confs);
110 
111 ISOSPEC_C_API void* setupStochasticFixedEnvelope(void* iso,
112  size_t no_molecules,
113  double precision,
114  double beta_bias,
115  bool get_confs);
116 
117 ISOSPEC_C_API void* setupBinnedFixedEnvelope(void* iso,
118  double target_total_prob,
119  double bin_width,
120  double bin_middle);
121 
122 ISOSPEC_C_API void freeReleasedArray(void* array);
123 
124 ISOSPEC_C_API void array_add(double* array, size_t N, double what);
125 ISOSPEC_C_API void array_mul(double* array, size_t N, double what);
126 ISOSPEC_C_API void array_fma(double* array, size_t N, double mul, double add);
127 
128 ISOSPEC_C_API void* setupFixedEnvelope(double* masses, double* probs, size_t size, bool mass_sorted, bool prob_sorted, double total_prob);
129 ISOSPEC_C_API void* copyFixedEnvelope(void* other);
130 ISOSPEC_C_API void deleteFixedEnvelope(void* tabulator, bool releaseEverything);
131 
132 ISOSPEC_C_API const double* massesFixedEnvelope(void* tabulator);
133 ISOSPEC_C_API const double* probsFixedEnvelope(void* tabulator);
134 ISOSPEC_C_API const int* confsFixedEnvelope(void* tabulator);
135 ISOSPEC_C_API size_t confs_noFixedEnvelope(void* tabulator);
136 
137 ISOSPEC_C_API double empiricAverageMass(void* tabulator);
138 ISOSPEC_C_API double empiricVariance(void* tabulator);
139 ISOSPEC_C_API double empiricStddev(void* tabulator);
140 
141 ISOSPEC_C_API double wassersteinDistance(void* tabulator1, void* tabulator2);
142 ISOSPEC_C_API double orientedWassersteinDistance(void* tabulator1, void* tabulator2);
143 ISOSPEC_C_API double abyssalWassersteinDistance(void* tabulator1, void* tabulator2, double abyss_depth, double other_scale);
144 //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);
145 
146 ISOSPEC_C_API struct ws_match_res{
147 double res1;
148 double res2;
149 double flow;
150 };
151 
152 ISOSPEC_C_API struct ws_match_res wassersteinMatch(void* tabulator1, void* tabulator2, double flow_dist, double other_scale);
153 
154 ISOSPEC_C_API void* addEnvelopes(void* tabulator1, void* tabulator2);
155 ISOSPEC_C_API void* convolveEnvelopes(void* tabulator1, void* tabulator2);
156 
157 ISOSPEC_C_API double getTotalProbOfEnvelope(void* envelope);
158 ISOSPEC_C_API void scaleEnvelope(void* envelope, double factor);
159 ISOSPEC_C_API void normalizeEnvelope(void* envelope);
160 ISOSPEC_C_API void shiftMassEnvelope(void* envelope, double d_mass);
161 ISOSPEC_C_API void resampleEnvelope(void* envelope, size_t ionic_current, double beta_bias);
162 ISOSPEC_C_API void* binnedEnvelope(void* envelope, double width, double middle);
163 ISOSPEC_C_API void* linearCombination(void* const * const envelopes, const double* intensities, size_t count);
164 
165 ISOSPEC_C_API void sortEnvelopeByMass(void* envelope);
166 ISOSPEC_C_API void sortEnvelopeByProb(void* envelope);
167 
168 ISOSPEC_C_API void parse_fasta_c(const char* fasta, int atomCounts[6]);
169 
170 
171 #ifdef __cplusplus
172 }
173 #endif