Exemplo n.º 1
0
def test_sum_mat_bins(mat):
    """Check if bin sum on upper triangle matrix yields expected results."""
    sym_mat = mat + mat.T
    sym_mat.setdiag(sym_mat.diagonal() / 2)
    summed = preproc.sum_mat_bins(sym_mat)
    exp_sum = 2 * sym_mat.sum(axis=1).A1 - sym_mat.diagonal()
    assert np.all(np.isclose(exp_sum, summed, rtol=0.1))
Exemplo n.º 2
0
def test_hic_genome_normalize(path):
    """Test if normalization of HicGenome object yields expected results"""
    hic_genome = ccm.HicGenome(path)
    valid_bins = preproc.get_detectable_bins(hic_genome.matrix, n_mads=5)
    hic_genome.normalize(iterations=100)
    filtered_mat = hic_genome.matrix.tocsr()[valid_bins[0], :]
    filtered_mat = filtered_mat[:, valid_bins[1]]
    bin_sums = preproc.sum_mat_bins(filtered_mat)
    assert np.allclose(bin_sums, 1, rtol=0.05)
Exemplo n.º 3
0
def test_contact_map_intra(size, max_dist, kernel_size):
    """Test preprocessing for intra matrices"""
    rand_mat = sp.random(size, size, density=0.95)
    contact_map = ccm.ContactMap(rand_mat)
    # Check if detrending yields average values of 1 (in upper triangle)
    assert np.isclose(np.mean(preproc.sum_mat_bins(contact_map.matrix)) / size,
                      1,
                      rtol=0.1)

    contact_map = ccm.ContactMap(rand_mat,
                                 max_dist=max_dist,
                                 largest_kernel=kernel_size)
    diagomeans = np.array(
        [np.mean(d[d != 0]) for d in contact_map.matrix.todia().data])
    diagoffsets = contact_map.matrix.todia().offsets
    # Check if matrix is trimmed after max dist + largest kernel
    assert max(diagoffsets) == max_dist + kernel_size
    # Check if a margin of ones was inserted below diagonal
    assert np.allclose(np.mean(diagomeans[np.where(diagoffsets < 0)[0]]), 1)