IsoSpecPy 2.3.3__tar.gz → 2.3.4__tar.gz

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.
Files changed (48) hide show
  1. {isospecpy-2.3.3 → isospecpy-2.3.4}/PKG-INFO +1 -1
  2. {isospecpy-2.3.3 → isospecpy-2.3.4}/pyproject.toml +1 -1
  3. {isospecpy-2.3.3 → isospecpy-2.3.4}/src/IsoSpec++/cwrapper.cpp +36 -0
  4. {isospecpy-2.3.3 → isospecpy-2.3.4}/src/IsoSpec++/cwrapper.h +7 -0
  5. {isospecpy-2.3.3 → isospecpy-2.3.4}/src/IsoSpec++/fixedEnvelopes.cpp +16 -3
  6. {isospecpy-2.3.3 → isospecpy-2.3.4}/src/IsoSpec++/fixedEnvelopes.h +1 -0
  7. {isospecpy-2.3.3 → isospecpy-2.3.4}/src/IsoSpec++/isoSpec++.cpp +57 -0
  8. {isospecpy-2.3.3 → isospecpy-2.3.4}/src/IsoSpec++/isoSpec++.h +31 -0
  9. {isospecpy-2.3.3 → isospecpy-2.3.4}/src/IsoSpec++/marginalTrek++.cpp +53 -0
  10. {isospecpy-2.3.3 → isospecpy-2.3.4}/src/IsoSpec++/marginalTrek++.h +21 -0
  11. {isospecpy-2.3.3 → isospecpy-2.3.4}/src/IsoSpec++/misc.h +18 -0
  12. {isospecpy-2.3.3 → isospecpy-2.3.4}/src/IsoSpecPy/IsoSpecPy.py +43 -18
  13. {isospecpy-2.3.3 → isospecpy-2.3.4}/src/IsoSpecPy/IsoSpecPyOld.py +6 -10
  14. {isospecpy-2.3.3 → isospecpy-2.3.4}/src/IsoSpecPy/PeriodicTbl.py +1 -5
  15. {isospecpy-2.3.3 → isospecpy-2.3.4}/src/IsoSpecPy/isoFFI.py +49 -18
  16. {isospecpy-2.3.3 → isospecpy-2.3.4}/LICENCE +0 -0
  17. {isospecpy-2.3.3 → isospecpy-2.3.4}/README.md +0 -0
  18. {isospecpy-2.3.3 → isospecpy-2.3.4}/skbuild/CMakeLists.txt +0 -0
  19. {isospecpy-2.3.3 → isospecpy-2.3.4}/src/IsoSpec++/allocator.cpp +0 -0
  20. {isospecpy-2.3.3 → isospecpy-2.3.4}/src/IsoSpec++/allocator.h +0 -0
  21. {isospecpy-2.3.3 → isospecpy-2.3.4}/src/IsoSpec++/btrd.h +0 -0
  22. {isospecpy-2.3.3 → isospecpy-2.3.4}/src/IsoSpec++/conf.h +0 -0
  23. {isospecpy-2.3.3 → isospecpy-2.3.4}/src/IsoSpec++/dirtyAllocator.cpp +0 -0
  24. {isospecpy-2.3.3 → isospecpy-2.3.4}/src/IsoSpec++/dirtyAllocator.h +0 -0
  25. {isospecpy-2.3.3 → isospecpy-2.3.4}/src/IsoSpec++/element_tables.cpp +0 -0
  26. {isospecpy-2.3.3 → isospecpy-2.3.4}/src/IsoSpec++/element_tables.h +0 -0
  27. {isospecpy-2.3.3 → isospecpy-2.3.4}/src/IsoSpec++/fasta.cpp +0 -0
  28. {isospecpy-2.3.3 → isospecpy-2.3.4}/src/IsoSpec++/fasta.h +0 -0
  29. {isospecpy-2.3.3 → isospecpy-2.3.4}/src/IsoSpec++/isoMath.cpp +0 -0
  30. {isospecpy-2.3.3 → isospecpy-2.3.4}/src/IsoSpec++/isoMath.h +0 -0
  31. {isospecpy-2.3.3 → isospecpy-2.3.4}/src/IsoSpec++/misc.cpp +0 -0
  32. {isospecpy-2.3.3 → isospecpy-2.3.4}/src/IsoSpec++/mman.cpp +0 -0
  33. {isospecpy-2.3.3 → isospecpy-2.3.4}/src/IsoSpec++/mman.h +0 -0
  34. {isospecpy-2.3.3 → isospecpy-2.3.4}/src/IsoSpec++/operators.cpp +0 -0
  35. {isospecpy-2.3.3 → isospecpy-2.3.4}/src/IsoSpec++/operators.h +0 -0
  36. {isospecpy-2.3.3 → isospecpy-2.3.4}/src/IsoSpec++/platform.h +0 -0
  37. {isospecpy-2.3.3 → isospecpy-2.3.4}/src/IsoSpec++/platform_incl.h +0 -0
  38. {isospecpy-2.3.3 → isospecpy-2.3.4}/src/IsoSpec++/pod_vector.h +0 -0
  39. {isospecpy-2.3.3 → isospecpy-2.3.4}/src/IsoSpec++/python-build.cpp +0 -0
  40. {isospecpy-2.3.3 → isospecpy-2.3.4}/src/IsoSpec++/summator.h +0 -0
  41. {isospecpy-2.3.3 → isospecpy-2.3.4}/src/IsoSpec++/unity-build.cpp +0 -0
  42. {isospecpy-2.3.3 → isospecpy-2.3.4}/src/IsoSpecPy/Advanced.py +0 -0
  43. {isospecpy-2.3.3 → isospecpy-2.3.4}/src/IsoSpecPy/Distributions.py +0 -0
  44. {isospecpy-2.3.3 → isospecpy-2.3.4}/src/IsoSpecPy/Formulas.py +0 -0
  45. {isospecpy-2.3.3 → isospecpy-2.3.4}/src/IsoSpecPy/__init__.py +0 -0
  46. {isospecpy-2.3.3 → isospecpy-2.3.4}/src/IsoSpecPy/__main__.py +0 -0
  47. {isospecpy-2.3.3 → isospecpy-2.3.4}/src/IsoSpecPy/approximations.py +0 -0
  48. {isospecpy-2.3.3 → isospecpy-2.3.4}/src/IsoSpecPy/confs_passthrough.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: IsoSpecPy
3
- Version: 2.3.3
3
+ Version: 2.3.4
4
4
  Summary: IsoSpecPy is a Python library for computing isotopic distributions of molecules.
5
5
  Keywords: isotopic distribution,mass spectrometry,chemistry,isotopic envelope,isotopologues
6
6
  Author: Michał Startek, Mateusz Łącki
@@ -9,7 +9,7 @@ cmake.source-dir = "skbuild"
9
9
  name = "IsoSpecPy"
10
10
  dependencies = ["cffi"]
11
11
  description = "IsoSpecPy is a Python library for computing isotopic distributions of molecules."
12
- version = "2.3.3"
12
+ version = "2.3.4"
13
13
  license = "BSD-2-Clause"
14
14
  license-files = ["LICENCE"]
15
15
  authors = [{name = "Michał Startek"}, {name = "Mateusz Łącki"}]
@@ -59,16 +59,46 @@ double getLightestPeakMassIso(void* iso)
59
59
  return reinterpret_cast<Iso*>(iso)->getLightestPeakMass();
60
60
  }
61
61
 
62
+ double getLightestPeakLProbIso(void* iso)
63
+ {
64
+ return reinterpret_cast<Iso*>(iso)->getLightestPeakLProb();
65
+ }
66
+
67
+ void getLightestPeakSignature(void* iso, int* space)
68
+ {
69
+ reinterpret_cast<Iso*>(iso)->getLightestPeakSignature(space);
70
+ }
71
+
62
72
  double getHeaviestPeakMassIso(void* iso)
63
73
  {
64
74
  return reinterpret_cast<Iso*>(iso)->getHeaviestPeakMass();
65
75
  }
66
76
 
77
+ double getHeaviestPeakLProbIso(void* iso)
78
+ {
79
+ return reinterpret_cast<Iso*>(iso)->getHeaviestPeakLProb();
80
+ }
81
+
82
+ void getHeaviestPeakSignature(void* iso, int* space)
83
+ {
84
+ reinterpret_cast<Iso*>(iso)->getHeaviestPeakSignature(space);
85
+ }
86
+
67
87
  double getMonoisotopicPeakMassIso(void* iso)
68
88
  {
69
89
  return reinterpret_cast<Iso*>(iso)->getMonoisotopicPeakMass();
70
90
  }
71
91
 
92
+ double getMonoisotopicPeakLProbIso(void* iso)
93
+ {
94
+ return reinterpret_cast<Iso*>(iso)->getMonoisotopicPeakLProb();
95
+ }
96
+
97
+ void getMonoisotopicPeakSignature(void* iso, int* space)
98
+ {
99
+ reinterpret_cast<Iso*>(iso)->getMonoisotopicPeakSignature(space);
100
+ }
101
+
72
102
  double getModeLProbIso(void* iso)
73
103
  {
74
104
  return reinterpret_cast<Iso*>(iso)->getModeLProb();
@@ -265,6 +295,12 @@ void* setupFixedEnvelope(double* masses, double* probs, size_t size, bool mass_s
265
295
  return reinterpret_cast<void*>(ret);
266
296
  }
267
297
 
298
+ void* setupFixedEnvelopeWithConfs(double* masses, double* probs, int* confs, size_t size, int allDim, bool mass_sorted, bool prob_sorted, double total_prob)
299
+ {
300
+ FixedEnvelope* ret = new FixedEnvelope(masses, probs, confs, size, allDim, mass_sorted, prob_sorted, total_prob);
301
+ return reinterpret_cast<void*>(ret);
302
+ }
303
+
268
304
  void deleteFixedEnvelope(void* t, bool release_everything)
269
305
  {
270
306
  FixedEnvelope* tt = reinterpret_cast<FixedEnvelope*>(t);
@@ -40,8 +40,14 @@ ISOSPEC_C_API void * setupIso(int dimNumber,
40
40
  ISOSPEC_C_API void * isoFromFasta(const char* fasta, bool use_nominal_masses, bool add_water);
41
41
 
42
42
  ISOSPEC_C_API double getLightestPeakMassIso(void* iso);
43
+ ISOSPEC_C_API double getLightestPeakLProbIso(void* iso);
44
+ ISOSPEC_C_API void getLightestPeakSignature(void* iso, int* space);
43
45
  ISOSPEC_C_API double getHeaviestPeakMassIso(void* iso);
46
+ ISOSPEC_C_API double getHeaviestPeakLProbIso(void* iso);
47
+ ISOSPEC_C_API void getHeaviestPeakSignature(void* iso, int* space);
44
48
  ISOSPEC_C_API double getMonoisotopicPeakMassIso(void* iso);
49
+ ISOSPEC_C_API double getMonoisotopicPeakLProbIso(void* iso);
50
+ ISOSPEC_C_API void getMonoisotopicPeakSignature(void* iso, int* space);
45
51
  ISOSPEC_C_API double getModeLProbIso(void* iso);
46
52
  ISOSPEC_C_API double getModeMassIso(void* iso);
47
53
  ISOSPEC_C_API double getTheoreticalAverageMassIso(void* iso);
@@ -132,6 +138,7 @@ ISOSPEC_C_API void array_mul(double* array, size_t N, double what);
132
138
  ISOSPEC_C_API void array_fma(double* array, size_t N, double mul, double add);
133
139
 
134
140
  ISOSPEC_C_API void* setupFixedEnvelope(double* masses, double* probs, size_t size, bool mass_sorted, bool prob_sorted, double total_prob);
141
+ 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);
135
142
  ISOSPEC_C_API void* copyFixedEnvelope(void* other);
136
143
  ISOSPEC_C_API void deleteFixedEnvelope(void* tabulator, bool releaseEverything);
137
144
 
@@ -23,9 +23,9 @@ namespace IsoSpec
23
23
  {
24
24
 
25
25
  FixedEnvelope::FixedEnvelope(const FixedEnvelope& other) :
26
- _masses(array_copy<double>(other._masses, other._confs_no)),
27
- _probs(array_copy<double>(other._probs, other._confs_no)),
28
- _confs(array_copy_nptr<int>(other._confs, other._confs_no*other.allDim)),
26
+ _masses(array_copy_malloc<double>(other._masses, other._confs_no)),
27
+ _probs(array_copy_malloc<double>(other._probs, other._confs_no)),
28
+ _confs(array_copy_nptr_malloc<int>(other._confs, other._confs_no*other.allDim)),
29
29
  _confs_no(other._confs_no),
30
30
  allDim(other.allDim),
31
31
  sorted_by_mass(other.sorted_by_mass),
@@ -56,6 +56,19 @@ _probs(in_probs),
56
56
  _confs(nullptr),
57
57
  _confs_no(in_confs_no),
58
58
  allDim(0),
59
+ allDimSizeofInt(0),
60
+ sorted_by_mass(masses_sorted),
61
+ sorted_by_prob(probs_sorted),
62
+ total_prob(_total_prob)
63
+ {}
64
+
65
+ FixedEnvelope::FixedEnvelope(double* in_masses, double* in_probs, int* in_confs, size_t in_confs_no, int _allDim, bool masses_sorted, bool probs_sorted, double _total_prob) :
66
+ _masses(in_masses),
67
+ _probs(in_probs),
68
+ _confs(in_confs),
69
+ _confs_no(in_confs_no),
70
+ allDim(_allDim),
71
+ allDimSizeofInt(_allDim * sizeof(int)),
59
72
  sorted_by_mass(masses_sorted),
60
73
  sorted_by_prob(probs_sorted),
61
74
  total_prob(_total_prob)
@@ -71,6 +71,7 @@ class ISOSPEC_EXPORT_SYMBOL FixedEnvelope {
71
71
  FixedEnvelope(FixedEnvelope&& other);
72
72
 
73
73
  FixedEnvelope(double* masses, double* probs, size_t confs_no, bool masses_sorted = false, bool probs_sorted = false, double _total_prob = NAN);
74
+ FixedEnvelope(double* masses, double* probs, int* confs, size_t confs_no, int _allDim, bool masses_sorted = false, bool probs_sorted = false, double _total_prob = NAN);
74
75
 
75
76
  virtual ~FixedEnvelope()
76
77
  {
@@ -250,6 +250,25 @@ double Iso::getLightestPeakMass() const
250
250
  return mass;
251
251
  }
252
252
 
253
+ double Iso::getLightestPeakLProb() const
254
+ {
255
+ double lprob = 0.0;
256
+ for (int ii = 0; ii < dimNumber; ii++)
257
+ lprob += marginals[ii]->getLightestConfLProb();
258
+ return lprob;
259
+ }
260
+
261
+ void Iso::getLightestPeakSignature(int* space) const
262
+ {
263
+ for (int ii = 0; ii < dimNumber; ii++)
264
+ {
265
+ size_t lightest_idx = marginals[ii]->getLightestAtomIndex();
266
+ for(int jj = 0; jj < isotopeNumbers[ii]; jj++)
267
+ space[jj] = (jj == lightest_idx ? atomCounts[ii] : 0);
268
+ space += isotopeNumbers[ii];
269
+ }
270
+ }
271
+
253
272
  double Iso::getHeaviestPeakMass() const
254
273
  {
255
274
  double mass = 0.0;
@@ -258,6 +277,25 @@ double Iso::getHeaviestPeakMass() const
258
277
  return mass;
259
278
  }
260
279
 
280
+ double Iso::getHeaviestPeakLProb() const
281
+ {
282
+ double lprob = 0.0;
283
+ for (int ii = 0; ii < dimNumber; ii++)
284
+ lprob += marginals[ii]->getHeaviestConfLProb();
285
+ return lprob;
286
+ }
287
+
288
+ void Iso::getHeaviestPeakSignature(int* space) const
289
+ {
290
+ for (int ii = 0; ii < dimNumber; ii++)
291
+ {
292
+ size_t heaviest_idx = marginals[ii]->getHeaviestAtomIndex();
293
+ for(int jj = 0; jj < isotopeNumbers[ii]; jj++)
294
+ space[jj] = (jj == heaviest_idx ? atomCounts[ii] : 0);
295
+ space += isotopeNumbers[ii];
296
+ }
297
+ }
298
+
261
299
  double Iso::getMonoisotopicPeakMass() const
262
300
  {
263
301
  double mass = 0.0;
@@ -266,6 +304,25 @@ double Iso::getMonoisotopicPeakMass() const
266
304
  return mass;
267
305
  }
268
306
 
307
+ double Iso::getMonoisotopicPeakLProb() const
308
+ {
309
+ double lprob = 0.0;
310
+ for (int ii = 0; ii < dimNumber; ii++)
311
+ lprob += marginals[ii]->getMonoisotopicConfLProb();
312
+ return lprob;
313
+ }
314
+
315
+ void Iso::getMonoisotopicPeakSignature(int* space) const
316
+ {
317
+ for (int ii = 0; ii < dimNumber; ii++)
318
+ {
319
+ size_t monoisotopic_idx = marginals[ii]->getMonoisotopicAtomIndex();
320
+ for(int jj = 0; jj < isotopeNumbers[ii]; jj++)
321
+ space[jj] = (jj == monoisotopic_idx ? atomCounts[ii] : 0);
322
+ space += isotopeNumbers[ii];
323
+ }
324
+ }
325
+
269
326
  double Iso::getUnlikeliestPeakLProb() const
270
327
  {
271
328
  double lprob = 0.0;
@@ -135,9 +135,27 @@ class ISOSPEC_EXPORT_SYMBOL Iso {
135
135
  //! Get the mass of the lightest peak in the isotopic distribution.
136
136
  double getLightestPeakMass() const;
137
137
 
138
+ //! Get the log-probability of the lightest peak in the isotopic distribution.
139
+ double getLightestPeakLProb() const;
140
+
141
+ /*!
142
+ Write the counts of isotopes in the lightest peak into target memory location. It must be large enough to accomodate it.
143
+ \param space An array where counts of isotopes shall be written. Must be as big as the overall number of isotopes.
144
+ */
145
+ void getLightestPeakSignature(int* space) const;
146
+
138
147
  //! Get the mass of the heaviest peak in the isotopic distribution.
139
148
  double getHeaviestPeakMass() const;
140
149
 
150
+ //! Get the log-probability of the heaviest peak in the isotopic distribution.
151
+ double getHeaviestPeakLProb() const;
152
+
153
+ /*!
154
+ Write the counts of isotopes in the heaviest peak into target memory location. It must be large enough to accomodate it.
155
+ \param space An array where counts of isotopes shall be written. Must be as big as the overall number of isotopes.
156
+ */
157
+ void getHeaviestPeakSignature(int* space) const;
158
+
141
159
  /*!
142
160
  Get the mass of the monoisotopic peak in the isotopic distribution. Monoisotopc molecule is defined as
143
161
  consisting only of the most frequent isotopes of each element. These are often (but not always) the
@@ -145,6 +163,19 @@ class ISOSPEC_EXPORT_SYMBOL Iso {
145
163
  */
146
164
  double getMonoisotopicPeakMass() const;
147
165
 
166
+ /*!
167
+ Get the log-probability of the monoisotopic peak in the isotopic distribution. Monoisotopc molecule is defined as
168
+ consisting only of the most frequent isotopes of each element. These are often (but not always) the
169
+ lightest ones. Making this often (but again, not always) equal to getLightestPeakLProb()
170
+ */
171
+ double getMonoisotopicPeakLProb() const;
172
+
173
+ /*!
174
+ Write the counts of isotopes in the monoisotopic peak into target memory location. It must be large enough to accomodate it.
175
+ \param space An array where counts of isotopes shall be written. Must be as big as the overall number of isotopes.
176
+ */
177
+ void getMonoisotopicPeakSignature(int* space) const;
178
+
148
179
  //! Get the log-probability of the mode-configuration (if there are many modes, they share this value).
149
180
  double getModeLProb() const;
150
181
 
@@ -256,6 +256,15 @@ double Marginal::getLightestConfMass() const
256
256
  return ret_mass*atomCnt;
257
257
  }
258
258
 
259
+ double Marginal::getLightestConfLProb() const
260
+ {
261
+ std::unique_ptr<int[]> lightest_conf = std::make_unique<int[]>(isotopeNo);
262
+ size_t lightest_idx = getLightestAtomIndex();
263
+ for(unsigned int ii = 0; ii < isotopeNo; ii++)
264
+ lightest_conf[ii] = (ii == lightest_idx ? atomCnt : 0);
265
+ return logProb(lightest_conf.get());
266
+ }
267
+
259
268
  double Marginal::getHeaviestConfMass() const
260
269
  {
261
270
  double ret_mass = 0.0;
@@ -265,6 +274,15 @@ double Marginal::getHeaviestConfMass() const
265
274
  return ret_mass*atomCnt;
266
275
  }
267
276
 
277
+ double Marginal::getHeaviestConfLProb() const
278
+ {
279
+ std::unique_ptr<int[]> heaviest_conf = std::make_unique<int[]>(isotopeNo);
280
+ size_t heaviest_idx = getHeaviestAtomIndex();
281
+ for(unsigned int ii = 0; ii < isotopeNo; ii++)
282
+ heaviest_conf[ii] = (ii == heaviest_idx ? atomCnt : 0);
283
+ return logProb(heaviest_conf.get());
284
+ }
285
+
268
286
  size_t Marginal::getMonoisotopicAtomIndex() const
269
287
  {
270
288
  double found_prob = -std::numeric_limits<double>::infinity();
@@ -278,12 +296,47 @@ size_t Marginal::getMonoisotopicAtomIndex() const
278
296
  return found_idx;
279
297
  }
280
298
 
299
+ size_t Marginal::getLightestAtomIndex() const
300
+ {
301
+ double found_mass = std::numeric_limits<double>::infinity();
302
+ size_t found_idx = 0;
303
+ for(unsigned int ii = 0; ii < isotopeNo; ii++)
304
+ if( found_mass > atom_masses[ii] )
305
+ {
306
+ found_mass = atom_masses[ii];
307
+ found_idx = ii;
308
+ }
309
+ return found_idx;
310
+ }
311
+
312
+ size_t Marginal::getHeaviestAtomIndex() const
313
+ {
314
+ double found_mass = -std::numeric_limits<double>::infinity();
315
+ size_t found_idx = 0;
316
+ for(unsigned int ii = 0; ii < isotopeNo; ii++)
317
+ if( found_mass < atom_masses[ii] )
318
+ {
319
+ found_mass = atom_masses[ii];
320
+ found_idx = ii;
321
+ }
322
+ return found_idx;
323
+ }
324
+
281
325
  double Marginal::getMonoisotopicConfMass() const
282
326
  {
283
327
  size_t idx = getMonoisotopicAtomIndex();
284
328
  return atom_masses[idx]*atomCnt;
285
329
  }
286
330
 
331
+ double Marginal::getMonoisotopicConfLProb() const
332
+ {
333
+ size_t idx = getMonoisotopicAtomIndex();
334
+ std::unique_ptr<int[]> monoisotopic_conf = std::make_unique<int[]>(isotopeNo);
335
+ for(unsigned int ii = 0; ii < isotopeNo; ii++)
336
+ monoisotopic_conf[ii] = (ii == idx ? atomCnt : 0);
337
+ return logProb(monoisotopic_conf.get());
338
+ }
339
+
287
340
  double Marginal::getAtomAverageMass() const
288
341
  {
289
342
  double ret = 0.0;
@@ -96,12 +96,18 @@ class Marginal
96
96
  */
97
97
  double getLightestConfMass() const;
98
98
 
99
+ //! Get the log-probability of the lightest subisotopologue.
100
+ double getLightestConfLProb() const;
101
+
99
102
  //! Get the mass of the heaviest subisotopologue.
100
103
  /*! This is trivially obtained by considering all atomNo atoms to be the heaviest isotope possible.
101
104
  \return The mass of the heaviest subisotopologue.
102
105
  */
103
106
  double getHeaviestConfMass() const;
104
107
 
108
+ //! Get the log-probability of the heaviest subisotopologue.
109
+ double getHeaviestConfLProb() const;
110
+
105
111
  //! Get the mass of the monoisotopic subisotopologue.
106
112
  /*! The monoisotopic subisotopologue is defined as the molecule consiting only
107
113
  of the most likely isotope. This is frequently the lightest subisotopologue,
@@ -109,12 +115,27 @@ class Marginal
109
115
  */
110
116
  double getMonoisotopicConfMass() const;
111
117
 
118
+ //! Get the log-probability of the monoisotopic subisotopologue.
119
+ double getMonoisotopicConfLProb() const;
120
+
112
121
  //! Get the index of the monoisotopic (most probable) atom.
113
122
  /*!
114
123
  \return The index of the most probable isotope of the element.
115
124
  */
116
125
  size_t getMonoisotopicAtomIndex() const;
117
126
 
127
+ //! Get the index of the lightest atom.
128
+ /*!
129
+ \return The index of the lightest isotope of the element.
130
+ */
131
+ size_t getLightestAtomIndex() const;
132
+
133
+ //! Get the index of the heaviest atom.
134
+ /*!
135
+ \return The index of the heaviest isotope of the element.
136
+ */
137
+ size_t getHeaviestAtomIndex() const;
138
+
118
139
  //! The the mass of the mode subisotopologue.
119
140
  /*!
120
141
  \return The mass of one of the most probable subisotopologues.
@@ -128,6 +128,16 @@ template <typename T> inline static T* array_copy(const T* A, size_t size)
128
128
  return ret;
129
129
  }
130
130
 
131
+ template <typename T> inline static T* array_copy_malloc(const T* A, size_t size)
132
+ {
133
+ T* ret = reinterpret_cast<T*>(malloc(size * sizeof(T)));
134
+ if(ret == nullptr)
135
+ throw std::bad_alloc();
136
+ memcpy(ret, A, size*sizeof(T));
137
+ return ret;
138
+ }
139
+
140
+
131
141
  template <typename T> static T* array_copy_nptr(const T* A, size_t size)
132
142
  {
133
143
  if(A == nullptr)
@@ -135,6 +145,14 @@ template <typename T> static T* array_copy_nptr(const T* A, size_t size)
135
145
  return array_copy(A, size);
136
146
  }
137
147
 
148
+ template <typename T> static T* array_copy_nptr_malloc(const T* A, size_t size)
149
+ {
150
+ if(A == nullptr)
151
+ return nullptr;
152
+ return array_copy_malloc(A, size);
153
+ }
154
+
155
+
138
156
  template<typename T> void dealloc_table(T* tbl, int dim)
139
157
  {
140
158
  for(int i = 0; i < dim; i++)
@@ -23,11 +23,6 @@ from .confs_passthrough import ConfsPassthrough
23
23
  from collections import namedtuple, OrderedDict
24
24
  import math
25
25
 
26
- try:
27
- xrange
28
- except NameError:
29
- xrange = range
30
-
31
26
  regex_pattern = re.compile('([A-Z][a-z]?)(-?[0-9]*)')
32
27
  ParsedFormula = namedtuple('ParsedFormula', 'atomCounts masses probs elems')
33
28
 
@@ -198,15 +193,16 @@ class Iso(object):
198
193
 
199
194
  offsets = []
200
195
 
201
- if get_confs:
202
- i = 0
203
- for j in xrange(self.dimNumber):
204
- newl = []
205
- for k in xrange(self.isotopeNumbers[j]):
206
- newl.append(i)
207
- i += 1
208
- offsets.append(tuple(newl))
209
- self.offsets = tuple(offsets)
196
+ i = 0
197
+ for j in range(self.dimNumber):
198
+ newl = []
199
+ for k in range(self.isotopeNumbers[j]):
200
+ newl.append(i)
201
+ i += 1
202
+ offsets.append(tuple(newl))
203
+ self.offsets = tuple(offsets)
204
+
205
+ self.conf_space = isoFFI.ffi.new("int[" + str(sum(self.isotopeNumbers)) + "]")
210
206
 
211
207
  self.iso = self.ffi.setupIso(self.dimNumber, self.isotopeNumbers,
212
208
  self.atomCounts,
@@ -225,14 +221,41 @@ class Iso(object):
225
221
  """Get the lightest peak in the isotopic distribution."""
226
222
  return self.ffi.getLightestPeakMassIso(self.iso)
227
223
 
224
+ def getLightestPeakLProb(self):
225
+ """Get the log probability of the lightest peak in the isotopic distribution."""
226
+ return self.ffi.getLightestPeakLProbIso(self.iso)
227
+
228
+ def getLightestPeakConf(self):
229
+ """Get the isotopic configuration of the lightest peak in the isotopic distribution."""
230
+ self.ffi.getLightestPeakSignature(self.iso, self.conf_space)
231
+ return self.parse_conf(self.conf_space)
232
+
228
233
  def getHeaviestPeakMass(self):
229
234
  """Get the heaviest peak in the isotopic distribution."""
230
235
  return self.ffi.getHeaviestPeakMassIso(self.iso)
231
236
 
237
+ def getHeaviestPeakLProb(self):
238
+ """Get the log probability of the heaviest peak in the isotopic distribution."""
239
+ return self.ffi.getHeaviestPeakLProbIso(self.iso)
240
+
241
+ def getHeaviestPeakConf(self):
242
+ """Get the isotopic configuration of the heaviest peak in the isotopic distribution."""
243
+ self.ffi.getHeaviestPeakSignature(self.iso, self.conf_space)
244
+ return self.parse_conf(self.conf_space)
245
+
232
246
  def getMonoisotopicPeakMass(self):
233
247
  """Get the monoisotopic mass of the peak."""
234
248
  return self.ffi.getMonoisotopicPeakMassIso(self.iso)
235
249
 
250
+ def getMonoisotopicPeakLProb(self):
251
+ """Get the log probability of the monoisotopic peak in the isotopic distribution."""
252
+ return self.ffi.getMonoisotopicPeakLProbIso(self.iso)
253
+
254
+ def getMonoisotopicPeakConf(self):
255
+ """Get the isotopic configuration of the monoisotopic peak in the isotopic distribution."""
256
+ self.ffi.getMonoisotopicPeakSignature(self.iso, self.conf_space)
257
+ return self.parse_conf(self.conf_space)
258
+
236
259
  def getModeLProb(self):
237
260
  """Get the log probability of the most probable peak(s) in the isotopic distribution."""
238
261
  return self.ffi.getModeLProbIso(self.iso)
@@ -289,10 +312,10 @@ class IsoDistribution(object):
289
312
 
290
313
  def __iter__(self):
291
314
  if hasattr(self, "confs") and self.confs is not None:
292
- for i in xrange(self.size):
315
+ for i in range(self.size):
293
316
  yield(self.masses[i], self.probs[i], self.confs[i])
294
317
  else:
295
- for i in xrange(self.size):
318
+ for i in range(self.size):
296
319
  yield (self.masses[i], self.probs[i])
297
320
 
298
321
  def __getitem__(self, idx):
@@ -353,7 +376,10 @@ class IsoDistribution(object):
353
376
  raise RuntimeError("Invalid arguments for IsoDistribution constructor")
354
377
 
355
378
  def _get_cobject(self):
356
- return isoFFI.clib.setupFixedEnvelope(self.masses, self.probs, len(self.masses), self.mass_sorted, self.prob_sorted, self._total_prob)
379
+ if hasattr(self, 'raw_confs') and self.raw_confs is not None:
380
+ return isoFFI.clib.setupFixedEnvelopeWithConfs(self.masses, self.probs, self.raw_confs, len(self.masses), self.sum_isotope_numbers, self.mass_sorted, self.prob_sorted, self._total_prob)
381
+ else:
382
+ return isoFFI.clib.setupFixedEnvelope(self.masses, self.probs, len(self.masses), self.mass_sorted, self.prob_sorted, self._total_prob)
357
383
 
358
384
  def copy(self):
359
385
  x = self._get_cobject()
@@ -694,7 +720,6 @@ class IsoGenerator(Iso):
694
720
  """
695
721
  self.cgen = None
696
722
  super(IsoGenerator, self).__init__(formula=formula, get_confs=get_confs, **kwargs)
697
- self.conf_space = isoFFI.ffi.new("int[" + str(sum(self.isotopeNumbers)) + "]")
698
723
  self.firstuse = True
699
724
 
700
725
  def __iter__(self):
@@ -9,7 +9,7 @@
9
9
  #
10
10
  # IsoSpec is distributed in the hope that it will be useful,
11
11
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
13
  #
14
14
  # You should have received a copy of the Simplified BSD Licence
15
15
  # along with IsoSpec. If not, see <https://opensource.org/licenses/BSD-2-Clause>.
@@ -26,10 +26,6 @@ tested too...
26
26
  The current API is implemented in __init__.py, use that instead
27
27
  '''
28
28
 
29
- try:
30
- xrange
31
- except NameError:
32
- xrange = range
33
29
 
34
30
  import re
35
31
  from .IsoSpecPy import IsoTotalProb, IsoThreshold
@@ -80,7 +76,7 @@ class IsoSpec():
80
76
  except KeyError:
81
77
  raise Exception("Invalid ISO method")
82
78
 
83
- # Reference to iso needs to be held in this object: it will deallocate masses/lprobs/etc arrays on C++ side if we
79
+ # Reference to iso needs to be held in this object: it will deallocate masses/lprobs/etc arrays on C++ side if we
84
80
  # allow GC to collect it prematurely
85
81
  self.iso = algo(_stopCondition)
86
82
 
@@ -136,7 +132,7 @@ class IsoSpec():
136
132
  masses = list(masses)
137
133
  logProbs= list(logProbs)
138
134
  confs = []
139
- for i in xrange(rows_no):
135
+ for i in range(rows_no):
140
136
  confs.append([x for sublist in isoCounts[i] for x in sublist])
141
137
  return masses, logProbs, confs
142
138
 
@@ -157,7 +153,7 @@ class IsoSpec():
157
153
  def splitConf(self, l, offset = 0):
158
154
  conf = []
159
155
  idx = self.allIsotopeNumber * offset
160
- for i in xrange(self.dimNumber):
156
+ for i in range(self.dimNumber):
161
157
  conf.append(tuple(l[idx:idx+self._isotopeNumbers[i]]))
162
158
  idx += self._isotopeNumbers[i]
163
159
  return tuple(conf)
@@ -169,7 +165,7 @@ class IsoSpec():
169
165
  masses, logProbs, isoCounts = self.getConfsRaw()
170
166
  confs = []
171
167
  step = sum(self._isotopeNumbers)
172
- for i in xrange(len(masses)):
168
+ for i in range(len(masses)):
173
169
  confs.append((masses[i], logProbs[i], self.splitConf(isoCounts, i)))
174
170
 
175
171
  for conf in confs:
@@ -184,7 +180,7 @@ class IsoPlot(dict):
184
180
  self.bin_w = bin_w
185
181
  masses, logProbs, _isoCounts = iso.getConfsRaw()
186
182
  dd = defaultdict(Summator)
187
- for i in xrange(len(masses)):
183
+ for i in range(len(masses)):
188
184
  dd[float(int(masses[i]/bin_w))*bin_w].add(math.exp(logProbs[i]))
189
185
  for key, val in dd.items():
190
186
  self[key] = val.get()
@@ -1,10 +1,6 @@
1
1
  from .isoFFI import isoFFI
2
2
  from collections import defaultdict
3
3
 
4
- try:
5
- xrange
6
- except NameError:
7
- xrange = range
8
4
 
9
5
  number_of_isotopic_entries = isoFFI.clib.NUMBER_OF_ISOTOPIC_ENTRIES
10
6
 
@@ -13,7 +9,7 @@ symbol_to_massNo = defaultdict(tuple)
13
9
  symbol_to_probs = defaultdict(tuple)
14
10
  symbol_to_atomic_number = {}
15
11
 
16
- for i in xrange(number_of_isotopic_entries):
12
+ for i in range(number_of_isotopic_entries):
17
13
  symbol = isoFFI.ffi.string(isoFFI.clib.elem_table_symbol[i]).decode("ascii")
18
14
  symbol_to_masses[symbol] += (isoFFI.clib.elem_table_mass[i],)
19
15
  symbol_to_massNo[symbol] += (isoFFI.clib.elem_table_massNo[i],)
@@ -3,13 +3,16 @@ import platform
3
3
  import sys
4
4
  import glob
5
5
  from pathlib import Path
6
+
6
7
  if False:
7
8
  import IsoSpecCppPy
8
9
 
10
+
9
11
  class IsoFFI:
10
12
  def __init__(self):
11
13
  self.ffi = cffi.FFI()
12
- self.ffi.cdef('''
14
+ self.ffi.cdef(
15
+ """
13
16
  void * setupIso(int dimNumber,
14
17
  const int* isotopeNumbers,
15
18
  const int* atomCounts,
@@ -19,8 +22,14 @@ class IsoFFI:
19
22
  void * isoFromFasta(const char* fasta, bool use_nominal_masses, bool add_water);
20
23
 
21
24
  double getLightestPeakMassIso(void* iso);
25
+ double getLightestPeakLProbIso(void* iso);
26
+ void getLightestPeakSignature(void* iso, int* space);
22
27
  double getHeaviestPeakMassIso(void* iso);
28
+ double getHeaviestPeakLProbIso(void* iso);
29
+ void getHeaviestPeakSignature(void* iso, int* space);
23
30
  double getMonoisotopicPeakMassIso(void* iso);
31
+ double getMonoisotopicPeakLProbIso(void* iso);
32
+ void getMonoisotopicPeakSignature(void* iso, int* space);
24
33
  double getModeLProbIso(void* iso);
25
34
  double getModeMassIso(void* iso);
26
35
  double getTheoreticalAverageMassIso(void* iso);
@@ -101,6 +110,7 @@ class IsoFFI:
101
110
  double bin_middle);
102
111
 
103
112
  void* setupFixedEnvelope(double* masses, double* probs, size_t size, bool mass_sorted, bool prob_sorted, double total_prob);
113
+ void* setupFixedEnvelopeWithConfs(double* masses, double* probs, int* confs, size_t size, int allDim, bool mass_sorted, bool prob_sorted, double total_prob);
104
114
  void* copyFixedEnvelope(void* other);
105
115
  void deleteFixedEnvelope(void* tabulator, bool releaseEverything);
106
116
 
@@ -157,39 +167,47 @@ class IsoFFI:
157
167
  extern const char* elem_table_element[NUMBER_OF_ISOTOPIC_ENTRIES];
158
168
  extern const char* elem_table_symbol[NUMBER_OF_ISOTOPIC_ENTRIES];
159
169
  extern const bool elem_table_Radioactive[NUMBER_OF_ISOTOPIC_ENTRIES];
160
- ''');
170
+ """
171
+ )
161
172
 
162
173
  mod_dir = Path(__file__).resolve().parent
163
174
 
164
- if (mod_dir.parent / 'setup.py').exists():
165
- raise ImportError('''Attempted to load IsoSpecPy module from its build directory. This usually
175
+ if (mod_dir.parent / "setup.py").exists():
176
+ raise ImportError(
177
+ """Attempted to load IsoSpecPy module from its build directory. This usually
166
178
  won't work and is generally a Bad Idea. Please cd somewhere else, or, if you're really
167
- sure you want to do that, edit the source and disable this check.''')
179
+ sure you want to do that, edit the source and disable this check."""
180
+ )
168
181
 
169
- libnames = ['IsoSpecCppPy*', 'IsoSpec++*']
170
- libprefix = ['', 'lib', 'Lib']
171
- extension = ['.so', '.dylib', '.dll']
182
+ libnames = ["IsoSpecCppPy*", "IsoSpec++*"]
183
+ libprefix = ["", "lib", "Lib"]
184
+ extension = [".so", ".dylib", ".dll"]
172
185
  try:
173
- if platform.system() == 'Linux':
174
- extension = ['.so', 'pyd']
175
- elif platform.system() == 'Windows':
176
- extension = ['.dll', '.pyd']
186
+ if platform.system() == "Linux":
187
+ extension = [".so", "pyd"]
188
+ elif platform.system() == "Windows":
189
+ extension = [".dll", ".pyd"]
177
190
  except:
178
191
  pass
179
192
 
180
- prebuilt = ['', 'prebuilt-']
193
+ prebuilt = ["", "prebuilt-"]
181
194
 
182
195
  def cprod(ll1, ll2):
183
196
  res = []
184
197
  for l1 in ll1:
185
198
  for l2 in ll2:
186
- res.append(l1+l2)
199
+ res.append(l1 + l2)
187
200
  return res
188
201
 
189
202
  paths_to_check = cprod(prebuilt, cprod(libprefix, cprod(libnames, extension)))
190
203
  dpc = []
191
204
 
192
- for dirpath in [mod_dir, mod_dir.parent, mod_dir.parent / 'bin', mod_dir.parent / 'lib']:
205
+ for dirpath in [
206
+ mod_dir,
207
+ mod_dir.parent,
208
+ mod_dir.parent / "bin",
209
+ mod_dir.parent / "lib",
210
+ ]:
193
211
  dpc.extend([dirpath / p for p in paths_to_check])
194
212
 
195
213
  paths_to_check = dpc
@@ -200,7 +218,10 @@ sure you want to do that, edit the source and disable this check.''')
200
218
  paths_to_check = expanded
201
219
  try:
202
220
  import importlib
203
- paths_to_check.insert(0, Path(importlib.util.find_spec("IsoSpecCppPy").origin))
221
+
222
+ paths_to_check.insert(
223
+ 0, Path(importlib.util.find_spec("IsoSpecCppPy").origin)
224
+ )
204
225
  except (ImportError, AttributeError):
205
226
  pass
206
227
 
@@ -213,11 +234,21 @@ sure you want to do that, edit the source and disable this check.''')
213
234
  self.libpath = libpath
214
235
  break
215
236
  except (IndexError, OSError) as e:
216
- errmsg = "Load libIsoSpec++.so, tried: " + libpath + '\n' + "Got error: " + str(type(e)) + ": " + str(e)
237
+ errmsg = (
238
+ "Load libIsoSpec++.so, tried: "
239
+ + libpath
240
+ + "\n"
241
+ + "Got error: "
242
+ + str(type(e))
243
+ + ": "
244
+ + str(e)
245
+ )
217
246
  errors.append(errmsg)
218
247
 
219
248
  if self.clib == None:
220
- raise ImportError("Cannot find or load the C++ part of the library\n" + '\n'.join(errors))
249
+ raise ImportError(
250
+ "Cannot find or load the C++ part of the library\n" + "\n".join(errors)
251
+ )
221
252
 
222
253
 
223
254
  isoFFI = IsoFFI() # This is done while including the module
File without changes
File without changes