예제 #1
0
def test_propose_string(seq):
    new_seq = propose(seq)
    assert new_seq != seq
    assert len(new_seq) == len(seq)

    # Check that only one position is different
    different_positions = []
    for i, (l1, l2) in enumerate(zip(seq, new_seq)):
        if l1 != l2:
            different_positions.append(i)
    assert len(different_positions) == 1
Sequence sampler test.

In this Python script, we start with a sequence,
and try to optimize for a better version of it,
as measured by the sum over reps.
It's a silly task,
but I think it gives us ability to sanity-check that we have
the right thing going.
"""

from jax_unirep import get_reps
from jax_unirep.sampler import is_accepted, propose

starting_sequence = "ASDFGHJKL"

current_sequence = starting_sequence
current_score = get_reps(current_sequence)[0].sum()
sequences = [current_sequence]
scores = [current_score]


for i in range(100):
    new_sequence = propose(current_sequence)
    new_score = get_reps(new_sequence)[0].sum()

    if is_accepted(best=current_score, candidate=new_score, temperature=1):
        current_sequence = new_sequence

    sequences.append(current_sequence)
    print(i, new_sequence, new_score)
예제 #3
0
def test_propose_wrong_pos_prob_shape():
    """Check that ValueError is raised when pos_prob of wrong shape is added."""
    with pytest.raises(ValueError):
        new_seq = propose("ADSV", pos_prob=np.array([0.2] * 5))
예제 #4
0
def test_propose_wrong_pwm_shape():
    """Check that ValueError is raised when pwm of wrong shape is passed in."""
    with pytest.raises(ValueError):
        new_seq = propose("ASDV", pwm=np.array([0.2] * 5))
예제 #5
0
def test_propose_empty_string():
    """Check that ValueError is raised with an empty string."""
    with pytest.raises(ValueError):
        new_seq = propose("")