def snapshot():
    cutoff = 1
    k = 28
    r = Redis(**TEST_REDIS_ARGS)
    r.flushdb()
    host_path = os.path.join("data", "test", "unit_test_host.fa")
    hosts_results_path = os.path.join("data", "snapshots", "hosts")
    hosts = make_hosts(path=host_path, k=k)
    print("hosts:")
    print(hosts)
    print("")
    with open(hosts_results_path, "w+") as hosts_results_file:
        hosts_results_file.writelines([f"{h}\n" for h in hosts])
    alignment_path = os.path.join("data", "test", "unit_test_target.clu")
    targets_results_path = os.path.join("data", "snapshots", "targets")
    targets = make_targets(path=alignment_path, k=k)
    print("targets:")
    print(targets)
    print("")
    with open(targets_results_path, "w+") as targets_results_file:
        targets_results_file.writelines([f"{t[0]}, {t[1]}\n" for t in targets])
    good_targets = predict_side_effects(k=k, cutoff=cutoff)
    good_targets_results_path = os.path.join("data", "snapshots",
                                             "good_targets")
    print("good_targets:")
    print(good_targets)
    print("")
    with open(good_targets_results_path, "w+") as good_targets_results_file:
        good_targets_results_file.writelines(
            [f"{gt[0]}, {gt[1]}\n" for gt in good_targets])
def test_predict_side_effects():
    k, cutoff = 28, 1
    r = Redis(**TEST_REDIS_ARGS)
    r.flushdb()
    test_host_path = os.path.join("data", "test", "unit_test_host.fa")
    make_hosts(path=test_host_path, k=k, redis_args=TEST_REDIS_ARGS)
    test_alignment_path = os.path.join("data", "test", "unit_test_target.clu")
    make_targets(path=test_alignment_path, id="nCoV", k=k, db=r)
    good_targets_snapshot_path = os.path.join("data", "snapshots",
                                              "good_targets")
    with open(good_targets_snapshot_path, "r") as good_targets_snapshot_file:
        good_targets_snapshot = list(csv.reader(good_targets_snapshot_file))
    good_targets = predict_side_effects(k=k, cutoff=cutoff, db=r)
    print("good_targets", good_targets)
    print("good_targets_snapshot", good_targets_snapshot)
    for good_target, snapshot in zip(good_targets, good_targets_snapshot):
        assert good_target[0] == snapshot[0]
        assert str(good_target[1]).strip(' ') == snapshot[1].strip(' ')
def test_predict_side_effects():
    k, cutoff = 5, 1
    r = Redis()
    r.flushall()
    test_host_path = os.path.join("data", "test", "unit_test_host.fa")
    make_hosts(path=test_host_path, k=k)
    test_alignment_path = os.path.join("data", "test", "unit_test_target.clu")
    make_targets(path=test_alignment_path, id="nCoV", k=k)
    good_targets_snapshot_path = os.path.join("data", "snapshots",
                                              "good_targets")
    with open(good_targets_snapshot_path, "r") as good_targets_snapshot_file:
        good_targets_snapshot = list(csv.reader(good_targets_snapshot_file))
    good_targets = predict_side_effects(k=k, cutoff=cutoff)
    print("good_targets", good_targets)
    print("good_targets_snapshot", good_targets_snapshot)
    for good_target, snapshot in zip(good_targets, good_targets_snapshot):
        assert good_target[0] == snapshot[0]
        assert str(good_target[1]) == snapshot[1]
def test_make_hosts():
    r, k = Redis(**TEST_REDIS_ARGS), 28
    r.flushdb()
    path = os.path.join("data", "test", "unit_test_host.fa")
    hosts = make_hosts(path=path, k=k, redis_args=TEST_REDIS_ARGS)
    hosts_snapshot_path = os.path.join("data", "snapshots", "hosts")
    with open(hosts_snapshot_path, "r") as hosts_snapshot_file:
        hosts_snapshot = hosts_snapshot_file.read().splitlines()
    print("hosts", hosts)
    print("hosts_snapshot", hosts_snapshot)
    for host in hosts:
        assert host in hosts_snapshot
def test_make_hosts():
    r, k = Redis(), 5
    r.flushall()
    path = os.path.join("data", "test", "unit_test_host.fa")
    hosts = make_hosts(path=path, k=k)
    hosts_snapshot_path = os.path.join("data", "snapshots", "hosts")
    with open(hosts_snapshot_path, "r") as hosts_snapshot_file:
        hosts_snapshot = hosts_snapshot_file.read().splitlines()
    print("hosts", hosts)
    print("hosts_snapshot", hosts_snapshot)
    for host in hosts:
        assert host in hosts_snapshot