def remake_with_star(in_path, out_path, title, comments='* added'): '''Parses one of David Jimenez-Morales's BBTM matrices. Adds a * column, which is equal to the minimum entry in the matrix. ''' # Retrieve the matrix as a dictionary mat = matrices.parse(in_path) # Find the minimum entry min_entry = min(mat.values()) # Make keys (i, *) and (*, i) map to that minimum entry for all # letters i in complete_bbtm_ordering (including (*, *)) for i in complete_bbtm_ordering: mat.update({(i, '*'): min_entry}) mat.update({('*', i): min_entry}) # Write the matrix write_matrix(mat, out_path, title=title, comments=comments)
'Q': 3.7e-2, 'G': 7.4e-2, 'H': 2.9e-2, 'I': 3.8e-2, 'L': 7.6e-2, 'K': 7.2e-2, 'M': 1.8e-2, 'F': 4.0e-2, 'P': 5.0e-2, 'S': 8.1e-2, 'T': 6.2e-2, 'W': 1.3e-2, 'Y': 3.3e-2, 'V': 6.8e-2}) <<<<<<< HEAD pam1 = 10**-4 * matrices.parse('pam1.txt') ======= def expected_changes(mat, pi): '''Expected fraction of positions different from original, after update with mat, given original frequency distribution pi. Very different from expected number of TRANSITIONS.''' return sum((1 - mat[i,i])*pi[i] for i in pi.keys()) def avg_rate(q, pi): return -1 * sum(q[i,i] *pi[i] for i in pi.keys()) def parse(mat_filename): '''Take filename of a file in the format in which matrices are presented in "Patterns of Amino Acid Substitutions..." Jimenez-Morales, Jie Liang