def test_to_freqs_pseudocount(self): """produces a freqs array with pseudocount""" data = array([[2, 4], [3, 5], [0, 8]]) marr = MotifCountsArray(array(data), "AB") got = marr.to_freq_array(pseudocount=1) adj = data + 1 expect = adj / vstack(adj.sum(axis=1)) assert_allclose(got.array, expect) got = marr.to_freq_array(pseudocount=0.5) adj = data + 0.5 expect = adj / vstack(adj.sum(axis=1)) assert_allclose(got.array, expect)
def test_to_freqs_1d(self): """produce a freqs array from 1D counts""" data = [43, 48, 114, 95] total = sum(data) a = MotifCountsArray([43, 48, 114, 95], motifs=("T", "C", "A", "G")) f = a.to_freq_array() assert_allclose(f.array, array([v / total for v in data], dtype=float))
def test_to_freqs(self): """produces a freqs array""" data = array([[2, 4], [3, 5], [4, 8]]) marr = MotifCountsArray(array(data), "AB") expect = data / vstack(data.sum(axis=1)) got = marr.to_freq_array() assert_allclose(got.array, expect)
def test_slicing(self): """slice by keys should work""" counts = MotifCountsArray( [[3, 2, 3, 2], [3, 2, 3, 2]], ["A", "C", "G", "T"], row_indices=["DogFaced", "FlyingFox"], ) freqs = counts.to_freq_array() got = freqs["FlyingFox"].to_array() assert_allclose(got, [0.3, 0.2, 0.3, 0.2])