Beispiel #1
0
def should_drop_packet(packet, add_line=True, scale=1.0):
    rand = random()
    dna_data = "".join(string2QUATS(packet))
    drop_chance, data, _ = DNARules.apply_all_rules_with_data(dna_data)
    drop_chance = scale * drop_chance
    if add_line:
        line = ("random_bytes," + ",".join([str(round(x, 4)) for x in data]) +
                "," + str(drop_chance) + "," + str(rand) + "," +
                str(drop_chance > rand))
        lines.append(line)
    # drop packet if rand bigger than the drop_chance for this Packet.
    return drop_chance > rand
Beispiel #2
0
def should_drop_packet(packet, add_line=True, scale=1.0):
    if not useDNARules:
        return False
    rand = random()
    drop_chance, data, _ = DNARules.apply_all_rules_with_data(packet)
    drop_chance = scale * drop_chance
    if add_line:
        line = (algo_type[0] + "," + str(hex(packet.getCRC())) + "," +
                ",".join([str(round(x, 4))
                          for x in data]) + "," + str(drop_chance) + "," +
                str(rand) + "," + str(drop_chance > rand))
        lines.append(line)
    return drop_chance > rand
Beispiel #3
0
def permute(data, add_line=True):
    dna_data = "".join(string2QUATS(data))
    drop_chance, data, _ = DNARules.apply_all_rules_with_data(dna_data)
    drop_chance = 0.01 * drop_chance
    if add_line:
        line = ("ReedSolomon" + "," + str() + "," +
                ",".join([str(round(x, 4))
                          for x in data]) + "," + str(drop_chance))
        lines.append(line)
    lim_drop_chance = min(drop_chance, 0.9999999)
    number_of_permutations = int(math.ceil(lim_drop_chance * len(dna_data)))
    dna_data = list(dna_data)
    for i in range(number_of_permutations):
        dna_data[i] = flip_base(
            dna_data[i])  # flip the dna-base to an incorrrect one
    data = b""
    for x in list(zip(*[iter(dna_data)] * 4)):
        data += quats_to_bytes("".join(x))
    return data
Beispiel #4
0
def test_c_permutation(params):
    assert fast_comp(DNARules.c_permutation(params[0])) == fast_comp(
        FastDNARules.c_permutation(params[0])) == params[1]
Beispiel #5
0
def test_homopolymers(params):
    assert fast_comp(DNARules.homopolymers(params[0]), 3) == fast_comp(
        FastDNARules.homopolymers(params[0])) == params[1]
Beispiel #6
0
def test_illegal_symbols(params):
    assert DNARules.illegal_symbols(params[0]) == FastDNARules.illegal_symbols(
        params[0]) == params[1]
Beispiel #7
0
def test_random_permutations(params):
    assert DNARules.random_permutations(
        params[0]) == FastDNARules.random_permutations(params[0]) == params[1]
Beispiel #8
0
def test_long_strands(params):
    assert abs(
        DNARules.long_strands(params) -
        FastDNARules.long_strands(params) < 0.01)
Beispiel #9
0
def test_trinucleotid_runs(params):
    assert fast_comp(DNARules.trinucleotid_runs(params[0])) == fast_comp(FastDNARules.trinucleotid_runs(params[0])) == \
           params[1]
Beispiel #10
0
def test_small_repeat_region(params):
    assert fast_comp(DNARules.smallRepeatRegion(params[0])) == fast_comp(FastDNARules.smallRepeatRegion(params[0])) == \
           params[1]
Beispiel #11
0
def test_repeat_region(params):
    assert fast_comp(DNARules.repeatRegion(params[0])) == fast_comp(
        FastDNARules.repeatRegion(params[0])) == params[1]
Beispiel #12
0
def test_gc_content(params):
    assert round(DNARules.overall_gc_content(params[0]), 2) == round(FastDNARules.overall_gc_content(params[0]), 2) == \
           params[1]
Beispiel #13
0
def test_simple_motif_search(params):
    assert fast_comp(DNARules.simple_motif_search(params[0])) == fast_comp(
        FastDNARules.simple_motif_search(params[0])) == params[1]
Beispiel #14
0
def test_motif_regex_search(params):
    assert fast_comp(DNARules.motif_regex_search(params[0])) == fast_comp(FastDNARules.motif_regex_search(params[0])) == \
           params[1]
Beispiel #15
0
def test_windowed_gc_content(params):
    assert abs(
        DNARules.windowed_gc_content(params) -
        FastDNARules.windowed_gc_content(params)) == 0
Beispiel #16
0
    os.remove(file)
    decoder.saveDecodedFile(print_to_output=False)
    if headerchunk:
        assert os.path.exists(file) and filecmp.cmp(file, cmp_file)
    else:
        assert os.path.exists("DEC_RU10_logo.jpg") and filecmp.cmp(
            "DEC_RU10_logo.jpg", cmp_file)
    shutil.rmtree(out_dir)


# testing error_correction methods with both dna_rules
@pytest.mark.parametrize("as_dna", [True])
@pytest.mark.parametrize("chunk_size", [100])
@pytest.mark.parametrize(
    "dna_rules",
    [DNARules(), DNARules2(), FastDNARules()])
@pytest.mark.parametrize("error_correction_pair",
                         [(nocode, nocode), (crc32, crc32_decode),
                          (reed_solomon_encode, reed_solomon_decode)])
def test_suite2(as_dna, chunk_size, dna_rules, error_correction_pair):
    chunksize = chunk_size
    number_of_chunks = Encoder.get_number_of_chunks_for_file_with_chunk_size(
        file, chunksize)
    dist = RaptorDistribution(number_of_chunks)
    decoder_instance = RU10Decoder
    pseudo_decoder = decoder_instance.pseudo_decoder(
        number_of_chunks=number_of_chunks)
    rules = dna_rules if as_dna else None
    encoder = RU10Encoder(
        file,
        number_of_chunks,