def goldman_q_rna_pair(seq1, seq2): """Returns the Goldman rate matrix""" if len(seq1) != len(seq2): raise ValueError, "seq1 and seq2 are not the same length!" seq1, seq2 = ModelRnaSequence(seq1), ModelRnaSequence(seq2) m = Counts.fromPair(seq1, seq2, RnaPairs, average=True)._data q = m / m.sum(axis=1)[:, NewAxis] new_diag = -(q.sum(axis=1) - diag(q)) for i, v in enumerate(new_diag): q[i, i] = v return q
def goldman_q_rna_triple(seq1, seq2, outgroup): """Returns the Goldman rate matrix for seq1""" if len(seq1) != len(seq2) != len(outgroup): raise ValueError, "seq1,seq2 and outgroup are not the same length!" seq1 = ModelRnaSequence(seq1) seq2 = ModelRnaSequence(seq2) outgroup = ModelRnaSequence(outgroup) m = Counts.fromTriple(seq1, seq2, outgroup, RnaPairs)._data q = m / m.sum(axis=1)[:, NewAxis] new_diag = -(q.sum(axis=1) - diag(q)) for i, v in enumerate(new_diag): q[i, i] = v return q