1 """@namespace IMP.spatiotemporal.analysis
2 Functions to analyze spatiotemporal models.
8 output_fn=
'temporal_precision.txt'):
10 Function that reads in two labeled_pdfs from create_DAG and returns the
11 temporal_precision, defined as the probability overlap between two
14 @param labeled_pdf1_fn: string, labeled pdf file name (including the path);
15 labeled_pdf from one independent sampling
16 @param labeled_pdf2_fn: string, labeled pdf file name (including the path);
17 labeled_pdf from another independent sampling
18 @param output_fn: string, name of output file
19 (default: 'temporal_precision.txt')
20 @return temporal precision, written to output_fn
22 pdf_files = [labeled_pdf1_fn, labeled_pdf2_fn]
24 for pdf_file
in pdf_files:
28 old = open(pdf_file,
'r')
33 line_split = line.split()
36 if len(line_split) > 1:
38 if line_split[0] ==
'#':
42 prob = float(line_split[1])
48 dict_list.append(prob_dict)
50 key_list = dict_list[0].keys()
51 key_list2 = dict_list[1].keys()
53 if len(key_list) == 0
or len(key_list2) == 0:
54 raise Exception(
'Error reading labeled_pdf!!! Keys not found')
60 precision -= 0.5 * np.abs(dict_list[0][key] - dict_list[1][key])
64 precision -= 0.5 * np.abs(dict_list[1][key])
71 precision -= 0.5 * np.abs(dict_list[0][key])
72 with open(output_fn,
'w')
as new:
73 new.write(
'Temporal precision between ' + labeled_pdf1_fn +
' and '
74 + labeled_pdf2_fn +
':\n')
75 new.write(str(precision))
76 print(
'Temporal precision between ' + labeled_pdf1_fn +
' and '
77 + labeled_pdf2_fn +
':')
81 def precision(labeled_pdf_fn, output_fn='precision.txt'):
83 Function that reads in one labeled_pdf from create_DAG and returns the
84 precision, defined as the sum of the squared
85 probability of all trajectories.
87 @param labeled_pdf_fn: string, labeled pdf file name (including the path);
88 labeled_pdf from the total model
89 @param output_fn: string, name of output file
90 (default: 'temporal_precision.txt')
91 @return temporal precision, written to output_fn
96 old = open(labeled_pdf_fn,
'r')
101 line_split = line.split()
104 if len(line_split) > 1:
106 if line_split[0] ==
'#':
109 prob = float(line_split[1])
111 prob_list.append(prob)
112 line = old.readline()
115 for prob
in prob_list:
117 with open(output_fn,
'w')
as new:
118 new.write(
'Precision of ' + labeled_pdf_fn +
':\n')
120 print(
'Precision of ' + labeled_pdf_fn)
def temporal_precision
Function that reads in two labeled_pdfs from create_DAG and returns the temporal_precision, defined as the probability overlap between two pathway models.
def precision
Function that reads in one labeled_pdf from create_DAG and returns the precision, defined as the sum ...
The general base class for IMP exceptions.