def get_response_content(fs): M, R = get_input_matrices(fs) # create the R table string and scripts headers = [ 't', 'mi.true.mut', 'mi.true.mutsel', 'mi.analog.mut', 'mi.analog.mutsel' ] npoints = 100 t_low = 0.0 t_high = 5.0 t_incr = (t_high - t_low) / (npoints - 1) t_values = [t_low + t_incr * i for i in range(npoints)] # get the data for the R table arr = [] for t in t_values: mi_mut = ctmcmi.get_mutual_information(M, t) mi_mutsel = ctmcmi.get_mutual_information(R, t) mi_analog_mut = ctmcmi.get_ll_ratio_wrong(M, t) mi_analog_mutsel = ctmcmi.get_ll_ratio_wrong(R, t) row = [t, mi_mut, mi_mutsel, mi_analog_mut, mi_analog_mutsel] arr.append(row) # get the R table table_string = RUtil.get_table_string(arr, headers) # get the R script script = get_ggplot() # create the R plot image device_name = Form.g_imageformat_to_r_function[fs.imageformat] retcode, r_out, r_err, image_data = RUtil.run_plotter( table_string, script, device_name) if retcode: raise RUtil.RError(r_err) return image_data
def get_response_content(fs): M, R = get_input_matrices(fs) # create the R table string and scripts headers = [ 't', 'mi.true.mut', 'mi.true.mutsel', 'mi.analog.mut', 'mi.analog.mutsel'] npoints = 100 t_low = 0.0 t_high = 5.0 t_incr = (t_high - t_low) / (npoints - 1) t_values = [t_low + t_incr*i for i in range(npoints)] # get the data for the R table arr = [] for t in t_values: mi_mut = ctmcmi.get_mutual_information(M, t) mi_mutsel = ctmcmi.get_mutual_information(R, t) mi_analog_mut = ctmcmi.get_ll_ratio_wrong(M, t) mi_analog_mutsel = ctmcmi.get_ll_ratio_wrong(R, t) row = [t, mi_mut, mi_mutsel, mi_analog_mut, mi_analog_mutsel] arr.append(row) # get the R table table_string = RUtil.get_table_string(arr, headers) # get the R script script = get_ggplot() # create the R plot image device_name = Form.g_imageformat_to_r_function[fs.imageformat] retcode, r_out, r_err, image_data = RUtil.run_plotter( table_string, script, device_name) if retcode: raise RUtil.RError(r_err) return image_data
def get_response_content(fs): M, R = get_input_matrices(fs) M_v = mrate.R_to_distn(M) R_v = mrate.R_to_distn(R) t = fs.t mi_mut = ctmcmi.get_mutual_information(M, t) mi_bal = ctmcmi.get_mutual_information(R, t) fi_mut = divtime.get_fisher_information(M, t) fi_bal = divtime.get_fisher_information(R, t) if fs.info_mut: information_sign = np.sign(mi_mut - mi_bal) elif fs.info_fis: information_sign = np.sign(fi_mut - fi_bal) out = StringIO() print >> out, '<html>' print >> out, '<body>' print >> out print >> out, '<pre>' print >> out, 'Explicitly computed answer', print >> out, '(not a heuristic but may be numerically imprecise):' if information_sign == 1: print >> out, '* pure mutation', print >> out, 'is more informative' elif information_sign == -1: print >> out, '* the balance of mutation and selection', print >> out, 'is more informative' else: print >> out, ' the information contents of the two processes', print >> out, 'are numerically indistinguishable' print >> out print >> out if fs.info_mut: print >> out, 'Mutual information properties', print >> out, 'at very small and very large times:' print >> out print >> out, get_mi_asymptotics(M, R) print >> out print >> out print >> out, 'Heuristics without regard to time or to the selected', print >> out, 'information variant (Fisher vs. mutual information):' print >> out print >> out, get_heuristics(M, R) print >> out print >> out print >> out, 'Input summary:' print >> out print >> out, 'mutation rate matrix:' print >> out, M print >> out print >> out, 'mutation process stationary distribution:' print >> out, M_v print >> out print >> out, 'mutation-selection balance rate matrix:' print >> out, R print >> out print >> out, 'mutation-selection balance stationary distribution:' print >> out, R_v print >> out print >> out, 'mutation process expected rate:' print >> out, mrate.Q_to_expected_rate(M) print >> out print >> out, 'mutation-selection balance expected rate:' print >> out, mrate.Q_to_expected_rate(R) print >> out print >> out print >> out, 'The following information calculations', print >> out, 'depend on t = %s:' % t print >> out print >> out, 'log(ratio(E(L))) for pure mutation:' print >> out, ctmcmi.get_ll_ratio_wrong(M, t) print >> out print >> out, 'log(ratio(E(L))) for mut-sel balance:' print >> out, ctmcmi.get_ll_ratio_wrong(R, t) print >> out print >> out, 'mutual information for pure mutation:' print >> out, mi_mut print >> out print >> out, 'mutual information for mut-sel balance:' print >> out, mi_bal print >> out print >> out, 'pinsker lower bound mi for pure mutation:' print >> out, ctmcmi.get_pinsker_lower_bound_mi(M, t) print >> out print >> out, 'pinsker lower bound mi for mut-sel balance:' print >> out, ctmcmi.get_pinsker_lower_bound_mi(R, t) print >> out print >> out, 'row based pinsker lower bound mi for pure mutation:' print >> out, ctmcmi.get_row_based_plb_mi(M, t) print >> out print >> out, 'row based pinsker lower bound mi for mut-sel balance:' print >> out, ctmcmi.get_row_based_plb_mi(R, t) print >> out print >> out, 'row based hellinger lower bound mi for pure mutation:' print >> out, ctmcmi.get_row_based_hellinger_lb_mi(M, t) print >> out print >> out, 'row based hellinger lower bound mi for mut-sel balance:' print >> out, ctmcmi.get_row_based_hellinger_lb_mi(R, t) print >> out print >> out, 'Fisher information for pure mutation:' print >> out, fi_mut print >> out print >> out, 'Fisher information for mut-sel balance:' print >> out, fi_bal print >> out print >> out, '</pre>' # # create the summaries summaries = (RateMatrixSummary(M), RateMatrixSummary(R)) print >> out, get_html_table(summaries) print >> out print >> out, '<html>' print >> out, '<body>' return out.getvalue()