Skip to content

Commit 6e988a6

Browse files
committed
Extened README file, and modified h2mmtest.py to process FRETbursts data structure
1 parent fa0caa7 commit 6e988a6

2 files changed

Lines changed: 48 additions & 32 deletions

File tree

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,16 @@ This repo is written in Python by Paul David Harris, with the objective of imple
88

99
The primary functions of this library are the EM_H2MM, and the equivalent EM_H2MM_par, which differ only in that EM_H2MM_par is accelerated by parallel processing.
1010
These functions use Maximum Likelihood Estimators to optimize a hidden Markov Model of data produced primarily by diffusing smFRET measurements- which are composed of arrival times of single photons at two or more detectors. This method is built off of well established hidden Markov modeling (HMM) but extends it to efficiently handel variable times between observations.
11-
Inputs to the functions are a h2mm_model object, which is composed of the prior or initial state vector, the transition probability matrix, and the observational likelihood matrix.
11+
Inputs to the functions are:
12+
h2mm_model object: an object of the h2mm_model class specific to H2MMpythonlib, which contains three numpy arrays:
13+
prior: initial state distribution
14+
trans: the transition probability matrix
15+
obs: the emmision proability matrix, giving the probability of a photon arriving at a given detector in a given state
16+
ArrivalColors: a list of numpy int arrays correspondig to the colors (detectors)(indexed from 0) of the photons
17+
ArrivalTimes: a list of numpy int arrays, 1 array per burst, corresponding to the arrival times of the photons
18+
The output of EM_H2MM and EM_H2MM_par is another h2mm_model object, which contains the optimized parameters.
19+
20+
This algorithm is both powerful and risky to use.
21+
The main difficulty arrises due to the strong potential of overfitting.
22+
Yet the potential to detect and quantify hidden dynamics is too good to pass up.
23+
I ask any researcher to apply this method cautiously, but hopefully.

h2mmtest.py

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,40 +9,44 @@
99
from H2MM import *
1010
from fretbursts import *
1111

12-
def H2MM_eval(h_model,data):
12+
def H2MM_eval(h_model,data):
1313
DAemDex_mask = data.get_ph_mask(ph_sel=Ph_sel(Dex='DAem'))
1414
AemDex_mask = data.get_ph_mask(ph_sel=Ph_sel(Dex='Aem'))
1515
AemDex_mask_red = AemDex_mask[DAemDex_mask]
1616
d_bursts = data.mburst[0]
17-
h_mod = EM_H2MM(h_model,data_ph_short,data_time_short)
18-
17+
ph_d = data.get_ph_times(ph_sel=Ph_sel(Dex='DAem'))
18+
d_bursts_red = d_bursts.recompute_index_reduce(ph_d)
19+
data_color = []
20+
data_time = []
21+
for start, stop in zip(d_bursts.istart,d_bursts.istop+1):
22+
temp_ph_mask = AemDex_mask_red[start:stop]
23+
temp_color = np.zeros((temp_ph_mask.shpae),dtype=int)
24+
temp_color[temp_ph_mask] = 1
25+
data_time.append(ph_d[start:stop])
26+
data_color.append(temp_color)
27+
h_mod = EM_H2MM_par(h_model,data_color,data_time)
28+
return h_mod
1929

20-
trans2 = np.array([[0.9999,0.0001],[0.001,0.999]])
21-
prior2 = np.array([0.3,0.7])
22-
obs2 = np.array([[0.1,0.9],[0.4,0.6]])
23-
h_mod2 = h2mm_model(prior2,trans2,obs2)
24-
trans3 = np.array([[0.98, 0.01, 0.01],[0.01, 0.98, 0.01],[0.01, 0.01, 0.98]])
25-
prior3 = np.array([0.2, 0.6, 0.2])
26-
obs3 = np.array([[0.1, 0.9],[0.5, 0.5],[0.7, 0.3]])
27-
h_mod3 = h2mm_model(prior3, trans3, obs3)
28-
data_time_short = np.zeros(12,dtype=int)
29-
30-
for i in range(1,12):
31-
if i != 4:
32-
data_time_short[i] = i + data_time_short[i-1]
30+
if __name__ == "__main__" :
31+
filename = './data/minus8TA_minus6NTD_RPo_T25C_G150uW_R100uW_1.hdf5'
32+
if os.path.isfile(filename):
33+
print('Perfect, I found the file!')
3334
else:
34-
data_time_short[i] = i + data_time_short[i-1] + 3
35-
36-
data_time_short = np.array([0, 4, 6, 13, 19, 21, 50, 54, 55, 59, 70, 72])
37-
data_ph_short = np.zeros(12,dtype=int)
38-
for i in range(1,len(data_time_short)):
39-
data_ph_short[i] = data_time_short[i] % 2
40-
41-
deltas_short = np.diff(data_time_short)
42-
R_short = ph_factors(deltas_short)
43-
deltas_short = np.diff(data_time_short)
44-
R_short = ph_factors(deltas_short)
45-
transmat_t_short = CalculatePowerofTransMatrices(h_mod2,R_short.R)
46-
transmat_t3_short = CalculatePowerofTransMatrices(h_mod3,R_short.R)
47-
48-
h_mod = EM_H2MM(h_mod2,[data_ph_short],[data_time_short])
35+
print('ERROR: file does not exist')
36+
d = loader.photon_hdf5(filename)
37+
d.add(det_donor_accept=(0, 1),
38+
alex_period=4000,
39+
D_ON=(2100, 3900),
40+
A_ON=(150, 1900),
41+
offset=700)
42+
loader.usalex_apply_period(d)
43+
d.calc_bg(fun=bg.exp_fit,time_s=50.1, tail_min_us='auto', F_bg=1.7)
44+
d.burst_search(m=10, F=6, ph_sel=Ph_sel(Dex='DAem'))
45+
d.fuse_bursts(ms=0)
46+
d_all = Sel(d, select_bursts.naa, th1=50)
47+
d_all = Sel(d_all, select_bursts.size, th1=50)
48+
prior2 = np.array([0.1, 0.9])
49+
trans2 = np.array([[0.998, 0.002],[0.0001, 0.9999]])
50+
obs2 = np.array([[0.3, 0.7],[0.8, 0.2]])
51+
h_mod2i = h2mm_model(prior2,trans2,obs2)
52+
h_model = H2MM_eval(h_mod,d_all)

0 commit comments

Comments
 (0)