Exemple #1
0
def test_cudapoa_complex_batch():
    random.seed(2)
    read_len = 500
    ref = ''.join([random.choice(['A', 'C', 'G', 'T']) for _ in range(read_len)])
    num_reads = 100
    mutation_rate = 0.02
    reads = []
    for _ in range(num_reads):
        new_read = ''.join([r if random.random() > mutation_rate else random.choice(['A', 'C', 'G', 'T']) for r in ref])
        reads.append(new_read)

    device = cuda.cuda_get_device()
    free, total = cuda.cuda_get_mem_info(device)
    stream = cuda.CudaStream()
    batch = CudaPoaBatch(1000, 0.9 * free, stream=stream, device_id=device)
    (add_status, seq_status) = batch.add_poa_group(reads)
    batch.generate_poa()

    consensus, coverage, status = batch.get_consensus()

    consensus = consensus[0]
    assert(len(consensus) == len(ref))

    match_ratio = SequenceMatcher(None, ref, consensus).ratio()
    assert(match_ratio == 1.0)
Exemple #2
0
def poa(groups, max_sequences_per_poa=100, gpu_mem_per_batch=0.9):
    """
    Generate consensus for POA groups.

    Args:
        groups : A list of lists of sequences for which consensus is to be generated.
    """
    free, total = cuda.cuda_get_mem_info(cuda.cuda_get_device())
    gpu_mem_per_batch *= free
    batch = CudaPoaBatch(max_sequences_per_poa,
                         gpu_mem_per_batch,
                         stream=None,
                         output_type="consensus")
    results = []

    for i, group in enumerate(groups, start=1):
        group_status, seq_status = batch.add_poa_group(group)

        # Once batch is full, run POA processing
        if group_status == 1 or i == len(groups):
            batch.generate_poa()

            consensus, coverage, status = batch.get_consensus()
            results.extend(consensus)

            batch.reset()
            group_status, seq_status = batch.add_poa_group(group)

    return results
def test_cudapoa_valid_output_type():
    device = cuda.cuda_get_device()
    free, total = cuda.cuda_get_mem_info(device)
    try:
        CudaPoaBatch(10,
                     1024,
                     0.9 * free,
                     deivce_id=device,
                     output_type='consensus')
    except RuntimeError:
        assert (False)
Exemple #4
0
def test_cudaaligner_simple_batch(query, target, cigar):
    """Test valid calculation of alignments by checking cigar strings.
    """
    device = cuda.cuda_get_device()
    stream = cuda.CudaStream()
    batch = CudaAlignerBatch(len(query), len(target), 1, alignment_type="global", stream=stream, device_id=device)
    batch.add_alignment(query, target)
    batch.align_all()
    alignments = batch.get_alignments()

    assert(len(alignments) == 1)
    assert(alignments[0].cigar == cigar)
def test_cudapoa_incorrect_output_type():
    device = cuda.cuda_get_device()
    free, total = cuda.cuda_get_mem_info(device)
    try:
        CudaPoaBatch(10,
                     1024,
                     0.9 * free,
                     deivce_id=device,
                     output_type='error_input')
        assert (False)
    except RuntimeError:
        pass
Exemple #6
0
def test_cudapoa_simple_batch():
    free, total = cuda.cuda_get_mem_info(cuda.cuda_get_device())
    batch = CudaPoaBatch(10, 0.9 * free)
    poa_1 = ["ACTGACTG", "ACTTACTG", "ACGGACTG", "ATCGACTG"]
    poa_2 = ["ACTGAC", "ACTTAC", "ACGGAC", "ATCGAC"]
    batch.add_poa_group(poa_1)
    batch.add_poa_group(poa_2)
    batch.generate_poa()
    consensus, coverage, status = batch.get_consensus()

    assert(len(consensus) == 2)
    assert(batch.total_poas == 2)
Exemple #7
0
def test_cudapoa_reset_batch():
    device = cuda.cuda_get_device()
    free, total = cuda.cuda_get_mem_info(device)
    batch = CudaPoaBatch(10, 0.9 * free, device_id=device)
    poa_1 = ["ACTGACTG", "ACTTACTG", "ACGGACTG", "ATCGACTG"]
    batch.add_poa_group(poa_1)
    batch.generate_poa()
    consensus, coverage, status = batch.get_consensus()

    assert(batch.total_poas == 1)

    batch.reset()

    assert(batch.total_poas == 0)
def test_cudapoa_simple_batch():
    device = cuda.cuda_get_device()
    free, total = cuda.cuda_get_mem_info(device)
    batch = CudaPoaBatch(10,
                         1024,
                         0.9 * free,
                         deivce_id=device,
                         output_mask='consensus')
    poa_1 = ["ACTGACTG", "ACTTACTG", "ACGGACTG", "ATCGACTG"]
    poa_2 = ["ACTGAC", "ACTTAC", "ACGGAC", "ATCGAC"]
    batch.add_poa_group(poa_1)
    batch.add_poa_group(poa_2)
    batch.generate_poa()
    consensus, coverage, status = batch.get_consensus()

    assert (len(consensus) == 2)
    assert (batch.total_poas == 2)
Exemple #9
0
def test_cudaaligner_various_arguments(max_seq_len, max_alignments, seq_len, num_alignments, should_succeed):
    """
    Pass legal and illegal arguments, and test for correct exception throwing behavior.
    """
    device = cuda.cuda_get_device()
    genome_sim = PoissonGenomeSimulator()
    read_sim = NoisyReadSimulator()

    batch = CudaAlignerBatch(max_seq_len, max_seq_len, max_alignments, device_id=device)

    success = True
    for _ in range(num_alignments):
        reference = genome_sim.build_reference(seq_len)
        query, start, end = read_sim.generate_read(reference, seq_len, insertion_error_rate=0.0)
        target, start, end = read_sim.generate_read(reference, seq_len, insertion_error_rate=0.0)

        status = batch.add_alignment(query, target)
        if status != 0:
            success &= False

    batch.align_all()

    assert(success is should_succeed)
Exemple #10
0
def test_cudaaligner_long_alignments(ref_length, num_alignments):
    """Test varying batches of long and short alignments and check for successful
    completion of alignment.
    """
    device = cuda.cuda_get_device()
    genome_sim = PoissonGenomeSimulator()
    read_sim = NoisyReadSimulator()

    batch = CudaAlignerBatch(ref_length, ref_length, num_alignments, device_id=device)

    for _ in range(num_alignments):
        reference = genome_sim.build_reference(ref_length)
        query, start, end = read_sim.generate_read(reference, ref_length, insertion_error_rate=0.0)
        target, start, end = read_sim.generate_read(reference, ref_length, insertion_error_rate=0.0)

        batch.add_alignment(query, target)

    batch.align_all()
    batch.get_alignments()

    # Test reset
    batch.reset()
    assert(len(batch.get_alignments()) == 0)
Exemple #11
0
def test_cudapoa_graph():
    device = cuda.cuda_get_device()
    free, total = cuda.cuda_get_mem_info(device)
    batch = CudaPoaBatch(10, 0.9 * free, device_id=device)
    poa_1 = ["ACTGACTG", "ACTTACTG", "ACTCACTG"]
    batch.add_poa_group(poa_1)
    batch.generate_poa()
    consensus, coverage, status = batch.get_consensus()

    assert (batch.total_poas == 1)

    # Expected graph
    #           - -> G -> -
    #           |         |
    # A -> C -> T -> T -> A -> C -> T -> G
    #           |         |
    #           - -> C -> -

    graphs, status = batch.get_graphs()
    assert (len(graphs) == 1)

    digraph = graphs[0]
    assert (digraph.number_of_nodes() == 10)
    assert (digraph.number_of_edges() == 11)
def test_cuda_device_selection():
    device_count = cuda.cuda_get_device_count()
    if (device_count > 0):
        for device in range(device_count):
            cuda.cuda_set_device(device)
            assert(cuda.cuda_get_device() == device)