6 Decorator to wrap functions that take a list of float values. In addition to
7 passing in a list of float values directly, it is possible to extract the
8 values from attributes or generic properties.
10 def _dec(xs, prop=None, attr=None):
15 level=mol.Prop.Level.UNSPECIFIED
17 level=mol.Prop.Level.ATOM
19 level=mol.Prop.Level.RESIDUE
21 level=mol.Prop.Level.CHAIN
26 vals.append(epm.Get(x))
34 vals.append(getattr(x, attr))
44 Calculate mean of dataset
47 raise RuntimeError(
"Can't calculate mean of empty sequence")
48 return float(sum(xs))/len(xs)
53 Calculate median of dataset
56 raise RuntimeError(
"Can't calculate median of empty sequence")
59 return (sorted_xs[(len(xs)-1)/2]+sorted_xs[(len(xs)-1)/2+1])/2.0
61 return sorted_xs[(len(xs)-1)/2]
66 Calculate standard-deviation of dataset
69 sigma=sqrt|---------------|
73 return math.sqrt(sum([(x-mean)**2
for x
in xs])/len(xs))
85 Calculates the correlation coefficient between xs and ys as
87 sum[(xi-<x>)*(yi-<y>)]
88 r=----------------------
91 where <x>, <y> are the mean of dataset xs and ys, and, sx and sy are the
95 raise RuntimeError(
"Can't calculate correl. Sequence lengths do not match.")
97 raise RuntimeError(
"Can't calculate correl of sequences with length 1.")
100 sigma_x, sigma_y=(0.0, 0.0)
102 for x, y
in zip(xs, ys):
103 cross_term+=(x-mean_x)*(y-mean_y)
104 sigma_x+=(x-mean_x)**2
105 sigma_y+=(y-mean_y)**2
106 sigma_x=math.sqrt(sigma_x)
107 sigma_y=math.sqrt(sigma_y)
108 return cross_term/(sigma_x*sigma_y)
111 bins=[0
for i
in range(num_bins)]
112 d=1.0*num_bins/(bounds[1]-bounds[0])
114 index=int((x-bounds[0])*d)
115 if index>num_bins-1
or index<0: