IsoSpecPy 2.2.2__pp310-pypy310_pp73-win_amd64.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.
- IsoSpecCppPy.pypy310-pp73-win_amd64.pyd +0 -0
- IsoSpecPy/Advanced.py +32 -0
- IsoSpecPy/Distributions.py +94 -0
- IsoSpecPy/Formulas.py +71 -0
- IsoSpecPy/IsoSpecPy.py +827 -0
- IsoSpecPy/IsoSpecPyOld.py +291 -0
- IsoSpecPy/PeriodicTbl.py +38 -0
- IsoSpecPy/__init__.py +19 -0
- IsoSpecPy/approximations.py +131 -0
- IsoSpecPy/confs_passthrough.py +16 -0
- IsoSpecPy/isoFFI.py +202 -0
- IsoSpecPy-2.2.2.dist-info/LICENCE +35 -0
- IsoSpecPy-2.2.2.dist-info/METADATA +31 -0
- IsoSpecPy-2.2.2.dist-info/RECORD +16 -0
- IsoSpecPy-2.2.2.dist-info/WHEEL +5 -0
- IsoSpecPy-2.2.2.dist-info/top_level.txt +2 -0
|
Binary file
|
IsoSpecPy/Advanced.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'''This file contains a set of functions useful for the analysis of properties of
|
|
2
|
+
isotopic envelopes. These are unlikely to be of any interest to end-users, only
|
|
3
|
+
for developers interested in testing some properties of the isotopic envelopes.
|
|
4
|
+
These are implemented mostly in Python, and so, not as fast as the rest of the
|
|
5
|
+
package.'''
|
|
6
|
+
|
|
7
|
+
def _int_neighbours(subisotopologue_conf):
|
|
8
|
+
conf = list(subisotopologue_conf)
|
|
9
|
+
for i in range(len(conf)):
|
|
10
|
+
for j in range(len(conf)):
|
|
11
|
+
if i != j and conf[i] > 0:
|
|
12
|
+
conf[i] -= 1
|
|
13
|
+
conf[j] += 1
|
|
14
|
+
yield tuple(conf)
|
|
15
|
+
conf[i] += 1
|
|
16
|
+
conf[j] -= 1
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def neighbours(conf):
|
|
20
|
+
for i in range(len(conf)):
|
|
21
|
+
for si_neigh in _int_neighbours(conf[i]):
|
|
22
|
+
yield tuple(conf[j] if j != i else si_neigh for j in range(len(conf)))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def conf_mass(iso, conf):
|
|
28
|
+
return sum(sum(mass * cnt for mass, cnt in zip(masses, cnts)) for masses, cnts in zip(iso.isotopeMasses, conf))
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
from IsoSpecPy import Iso
|
|
32
|
+
Iso.conf_mass = conf_mass
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import math
|
|
2
|
+
|
|
3
|
+
from .IsoSpecPy import IsoDistribution
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def simple_inverse(fun, prec = 0.01):
|
|
9
|
+
|
|
10
|
+
def inverse(x):
|
|
11
|
+
start = -1.0
|
|
12
|
+
while fun(start) > x:
|
|
13
|
+
start *= 2.0
|
|
14
|
+
end = 1.0
|
|
15
|
+
while fun(end) < x:
|
|
16
|
+
end *= 2.0
|
|
17
|
+
|
|
18
|
+
while (end - start) > prec:
|
|
19
|
+
print(start, end)
|
|
20
|
+
mid = (end + start) * 0.5
|
|
21
|
+
if fun(mid) < x:
|
|
22
|
+
start = mid
|
|
23
|
+
else:
|
|
24
|
+
end = mid
|
|
25
|
+
|
|
26
|
+
return (end + start) * 0.5
|
|
27
|
+
|
|
28
|
+
return inverse
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class Distribution(IsoDistribution):
|
|
33
|
+
def __init__(self, cdf, bin_width = 0.01, precision = 0.99, inverse_cdf = None):
|
|
34
|
+
if inverse_cdf is None:
|
|
35
|
+
inverse_cdf = simple_inverse(cdf, prec = bin_width*0.125)
|
|
36
|
+
|
|
37
|
+
prec_missing = 0.5 * (1.0 - precision)
|
|
38
|
+
|
|
39
|
+
start = inverse_cdf(prec_missing)
|
|
40
|
+
end = inverse_cdf(1.0 - prec_missing)
|
|
41
|
+
|
|
42
|
+
half_bin_width = 0.5*bin_width
|
|
43
|
+
|
|
44
|
+
bw_inverse = 1.0 / bin_width
|
|
45
|
+
|
|
46
|
+
def bw_round(x):
|
|
47
|
+
return math.floor(x*bw_inverse + 0.5) / bw_inverse
|
|
48
|
+
|
|
49
|
+
start = bw_round(start)
|
|
50
|
+
end = bw_round(end)
|
|
51
|
+
|
|
52
|
+
last_bin_start = start - half_bin_width
|
|
53
|
+
last_cdf = cdf(last_bin_start)
|
|
54
|
+
|
|
55
|
+
probs = [0.0]
|
|
56
|
+
masses = [last_bin_start - half_bin_width]
|
|
57
|
+
|
|
58
|
+
while last_bin_start < end:
|
|
59
|
+
next_bin_start = last_bin_start + bin_width
|
|
60
|
+
next_cdf = cdf(next_bin_start)
|
|
61
|
+
|
|
62
|
+
masses.append(last_bin_start + half_bin_width)
|
|
63
|
+
probs.append(next_cdf - last_cdf)
|
|
64
|
+
|
|
65
|
+
last_cdf = next_cdf
|
|
66
|
+
last_bin_start = next_bin_start
|
|
67
|
+
|
|
68
|
+
sprobs = 1.0/sum(probs)
|
|
69
|
+
probs = [p*sprobs for p in probs]
|
|
70
|
+
|
|
71
|
+
probs.append(0.0)
|
|
72
|
+
masses.append(last_bin_start + half_bin_width)
|
|
73
|
+
|
|
74
|
+
super(Distribution, self).__init__(masses = masses, probs = probs)
|
|
75
|
+
|
|
76
|
+
self.mass_sorted = True
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
class Gaussian(Distribution):
|
|
81
|
+
def __init__(self, stdev, bin_width = 0.01, precision = 0.99):
|
|
82
|
+
varfactor = 1.0/(stdev * 1.4142135623730951)
|
|
83
|
+
cdf = lambda x: 0.5*(1.0+math.erf(x*varfactor))
|
|
84
|
+
inv_cdf = None
|
|
85
|
+
try:
|
|
86
|
+
# If scipy is available, use its ppf
|
|
87
|
+
from scipy.stats import norm
|
|
88
|
+
inv_cdf = lambda x: norm.ppf(x, loc = 0.0, scale = stdev)
|
|
89
|
+
except ImportError:
|
|
90
|
+
pass # oh well, no scipy, we'll just use binsearch-based inversion
|
|
91
|
+
|
|
92
|
+
super(Gaussian, self).__init__(cdf = cdf, bin_width = bin_width, precision = precision, inverse_cdf = inv_cdf)
|
|
93
|
+
|
|
94
|
+
|
IsoSpecPy/Formulas.py
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
from .IsoSpecPy import Iso
|
|
2
|
+
from collections import Counter
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
loratadine = "C22H23N2O2Cl1"
|
|
7
|
+
desloratadine = "C19H19N2Cl1"
|
|
8
|
+
titin = "C169719H270466N45688O52238S911"
|
|
9
|
+
bovine_insulin = "C254H377N65O75S6"
|
|
10
|
+
ubiquitin = "C378H629N105O118S1"
|
|
11
|
+
substance_p = "C63H98N18O13S1"
|
|
12
|
+
protein_p16 = "C681H1100N216O208S5"
|
|
13
|
+
cholesterol = "C27H46O1"
|
|
14
|
+
caffeine = "C8H10N4O2"
|
|
15
|
+
water = "H2O1"
|
|
16
|
+
glucose = "C6H12O6"
|
|
17
|
+
sucrose = "C12H22O11"
|
|
18
|
+
horse_myoglobin = "C769H1212N210O218S2"
|
|
19
|
+
oxygen = "O2"
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
averagine_unit = Counter({
|
|
26
|
+
'C' : 4.9384,
|
|
27
|
+
'H' : 7.7583,
|
|
28
|
+
'N' : 1.3577,
|
|
29
|
+
'O' : 1.4773,
|
|
30
|
+
'S' : 0.0417})
|
|
31
|
+
|
|
32
|
+
averagine_mass = 111.1254
|
|
33
|
+
|
|
34
|
+
def fillHs(d, target_avg_mass):
|
|
35
|
+
while True:
|
|
36
|
+
i = Iso(formula = d)
|
|
37
|
+
if i.getTheoreticalAverageMass() > target_avg_mass:
|
|
38
|
+
break
|
|
39
|
+
d['H'] += 1
|
|
40
|
+
|
|
41
|
+
def averagine_dct(target_avg_mass):
|
|
42
|
+
units = float(target_avg_mass) / averagine_mass
|
|
43
|
+
d = dict((key, int(units*val)) for key, val in averagine_unit.items())
|
|
44
|
+
fillHs(d, target_avg_mass)
|
|
45
|
+
for x in list(d.keys()):
|
|
46
|
+
if d[x] == 0:
|
|
47
|
+
del d[x]
|
|
48
|
+
return d
|
|
49
|
+
|
|
50
|
+
def averagine(target_avg_mass):
|
|
51
|
+
return ''.join(str(key)+str(val) for key, val in sorted(averagine_dct(target_avg_mass).items(), key= lambda x: x[0]))
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
acgt_avg_base = Counter({
|
|
55
|
+
'C' : 9.75,
|
|
56
|
+
'H' : 12.25,
|
|
57
|
+
'N' : 3.75,
|
|
58
|
+
'O' : 6.0,
|
|
59
|
+
'P' : 1.0
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
def acgt_dct(no_bases, add_water = True):
|
|
63
|
+
c = {key : int(val*no_bases+0.5) for key, val in acgt_avg_base.items()}
|
|
64
|
+
if add_water:
|
|
65
|
+
c['H'] += 2
|
|
66
|
+
c['O'] += 1
|
|
67
|
+
return c
|
|
68
|
+
|
|
69
|
+
def acgt(no_bases, add_water = True):
|
|
70
|
+
c = acgt_dct(no_bases, add_water = add_water)
|
|
71
|
+
return ''.join(str(key)+str(val) for key, val in sorted(c.items(), key= lambda x: x[0]))
|