Example #1
0
def test_sparse_filter_low_counts_real_data():
    counts, lengths = load_sample_yeast()
    counts_sparse = sparse.csr_matrix(counts)
    counts_dense = filter_low_counts(counts, sparsity=False, percentage=0.1)
    counts_sparse = filter_low_counts(counts_sparse, sparsity=False,
                                      percentage=0.1)
    counts_dense[np.isnan(counts_dense)] = 0
    assert_array_equal(counts_dense, counts_sparse.toarray())

    triu_counts_sparse = sparse.csr_matrix(np.triu(counts))
    triu_counts_sparse = filter_low_counts(triu_counts_sparse, sparsity=False,
                                           percentage=0.1)
    assert_array_equal(np.triu(counts), triu_counts_sparse.toarray())
Example #2
0
def test_sparse_filter_low_counts_real_data():
    counts, lengths = load_sample_yeast()
    counts_sparse = sparse.csr_matrix(counts)
    counts_dense = filter_low_counts(counts, sparsity=False, percentage=0.1)
    counts_sparse = filter_low_counts(counts_sparse, sparsity=False,
                                      percentage=0.1)
    counts_dense[np.isnan(counts_dense)] = 0
    assert_array_equal(counts_dense, counts_sparse.toarray())

    triu_counts_sparse = sparse.csr_matrix(np.triu(counts))
    triu_counts_sparse = filter_low_counts(triu_counts_sparse, sparsity=False,
                                           percentage=0.1)
    assert_array_equal(np.triu(counts_dense), triu_counts_sparse.toarray())
Example #3
0
def test_downsample_contact_map():
    counts, lengths = datasets.load_sample_yeast()
    nreads = int(np.round(0.8 * np.triu(counts).sum()))
    downsampled_counts = downsample_contact_map(counts,
                                                random_state=42)
    assert nreads == downsampled_counts.sum()

    downsampled_counts = downsample_contact_map(counts, nreads=nreads,
                                                random_state=42)
    assert nreads == downsampled_counts.sum()

    downsampled_counts = downsample_contact_map(counts, proportion=0.8,
                                                random_state=42)
    assert nreads == downsampled_counts.sum()

    with pytest.raises(ValueError):
        downsample_contact_map(counts*.3, nreads=nreads,
                               random_state=42)

    with pytest.raises(ValueError):
        downsample_contact_map(counts, nreads=nreads,
                               proportion=0.5,
                               random_state=42)

    # Test that it works with COO matrices
    counts = sparse.coo_matrix(np.triu(counts))
    downsampled_counts = downsample_contact_map(counts, nreads=nreads,
                                                random_state=42)
    assert nreads == downsampled_counts.sum()

    # Test that it works with CSR matrices
    counts = sparse.csr_matrix(counts)
    downsampled_counts = downsample_contact_map(counts, nreads=nreads,
                                                random_state=42)
    assert nreads == downsampled_counts.sum()

    with pytest.raises(ValueError):
        downsample_contact_map(counts, proportion=-0.1)

    with pytest.raises(ValueError):
        downsample_contact_map(counts, proportion=1.5)

    downsample_contact_map(counts)
Example #4
0
def test_bootstrap_contact_map():
    counts, lengths = datasets.load_sample_yeast()
    bootstrap_contact_map(counts,
                          random_state=42)
    with pytest.raises(ValueError):
        bootstrap_contact_map(counts*.3,
                              random_state=42)

    # Test that it works with COO matrices
    counts = sparse.coo_matrix(np.triu(counts))
    bootstrap_contact_map(counts,
                          random_state=42)

    # Test that it works with CSR matrices
    counts = sparse.csr_matrix(counts)
    bootstrap_contact_map(counts,
                          random_state=42)

    bootstrap_contact_map(counts)
Example #5
0
"""
=================================
Extracting parts of a contact map
=================================

This example shows how to extract contact counts associated to some chromosomes
of the contact maps. Here, we extract chromosomes 1, 4 and 5 of the budding
yeasts contact map
"""
import matplotlib.pyplot as plt
from matplotlib import colors

from iced import datasets
from iced.utils import extract_sub_contact_map

# Loading a sample dataset
counts, lengths = datasets.load_sample_yeast()
sub_counts, sub_lengths = extract_sub_contact_map(counts, lengths, [0, 3, 4])

fig, ax = plt.subplots()
m = ax.matshow(sub_counts,
               cmap="Blues",
               norm=colors.SymLogNorm(1),
               origin="bottom",
               extent=(0, len(sub_counts), 0, len(sub_counts)))
[ax.axhline(i, linewidth=1, color="#000000") for i in sub_lengths.cumsum()]
[ax.axvline(i, linewidth=1, color="#000000") for i in sub_lengths.cumsum()]
cb = fig.colorbar(m)
ax.set_title("Chromosomes I, IV and V of yeast")
Example #6
0
import matplotlib.pyplot as plt
from matplotlib import colors

from iced import datasets
from iced import filter
from iced import normalization

"""
Normalizing a contact count matrix.
"""

# Loading a sample dataset
counts, lengths = datasets.load_sample_yeast()

# Filtering and normalizing contact count data
normed = filter.filter_low_counts(counts, lengths=lengths, percentage=0.04)
normed = normalization.ICE_normalization(normed)

# Plotting the results using matplotlib
chromosomes = ["I", "II", "III", "IV", "V", "VI"]

fig, axes = plt.subplots(ncols=2, figsize=(12, 4))

axes[0].imshow(counts, cmap="Blues", norm=colors.SymLogNorm(1),
               origin="bottom",
               extent=(0, len(counts), 0, len(counts)))

[axes[0].axhline(i, linewidth=1, color="#000000") for i in lengths.cumsum()]
[axes[0].axvline(i, linewidth=1, color="#000000") for i in lengths.cumsum()]
axes[0].set_title("Raw contact counts")
Example #7
0
def test_data_sub_yeast():
    counts, lengths = load_sample_yeast()
Example #8
0
def test_data_sub_yeast():
    counts, lengths = load_sample_yeast()