Beispiel #1
0
def test_phase_trio1():
	reads = """
	  A 111
	  A 010
	  A 110
	  B 001
	  B 110
	  B 101
	  C 001
	  C 010
	  C 010
	"""
	pedigree = Pedigree(NumericSampleIds())
	pedigree.add_individual('individual0', [1,2,1])
	pedigree.add_individual('individual1', [1,1,1])
	pedigree.add_individual('individual2', [0,1,1])
	pedigree.add_relationship('individual0', 'individual1', 'individual2')
	recombcost = [10,10,10]
	superreads_list, transmission_vector, cost = phase_pedigree(reads, recombcost, pedigree)
	assert cost == 2
	assert len(set(transmission_vector)) == 1
	all_expected_haplotypes = [
		('111','010'),
		('001','110'),
		('001','010')
	]
	assert_haplotypes(superreads_list, all_expected_haplotypes, 3)
Beispiel #2
0
def check_genotyping_single_individual(
    reads,
    weights=None,
    expected=None,
    genotypes=None,
    scaling=None,
    genotype_priors=None,
):
    # 0) set up read set
    readset = string_to_readset(s=reads, w=weights, scale_quality=scaling)
    positions = readset.get_positions()

    # 1) Genotype using forward backward algorithm
    recombcost = [1] * len(positions)
    numeric_sample_ids = NumericSampleIds()
    pedigree = Pedigree(numeric_sample_ids)
    genotype_likelihoods = [
        PhredGenotypeLikelihoods([1.0 / 3.0, 1.0 / 3.0, 1.0 / 3.0])
    ] * len(positions)

    if genotype_priors is not None:
        genotype_likelihoods = genotype_priors

    pedigree.add_individual(
        "individual0",
        [canonic_index_to_biallelic_gt(1) for i in range(len(positions))],
        genotype_likelihoods,
    )
    dp_forward_backward = GenotypeDPTable(numeric_sample_ids, readset,
                                          recombcost, pedigree)

    # check the results
    compare_to_expected(dp_forward_backward, positions, expected, genotypes)
Beispiel #3
0
def test_phase_trio5():
    reads = """
      B 101
      B 101
      B 101
      A 111
      A 111
      A 111
      C 111
      C 111
      C 111
    """
    pedigree = Pedigree(NumericSampleIds())
    pedigree.add_individual("individual0",
                            canonic_index_list_to_biallelic_gt_list([1, 1, 1]))
    pedigree.add_individual("individual1",
                            canonic_index_list_to_biallelic_gt_list([1, 1, 1]))
    pedigree.add_individual("individual2",
                            canonic_index_list_to_biallelic_gt_list([1, 1, 1]))
    pedigree.add_relationship("individual0", "individual1", "individual2")
    recombcost = [2, 2, 2]
    superreads_list, transmission_vector, cost = phase_pedigree(
        reads, recombcost, pedigree)
    assert cost == 3
    assert len(set(transmission_vector)) == 1
    all_expected_haplotypes = [("111", "000"), ("111", "000"), ("111", "000")]
    assert_haplotypes(superreads_list, all_expected_haplotypes, 3)
    assert_trio_allele_order(superreads_list, transmission_vector, 3)
def test_phase_doubletrio_pure_genetic():
    reads = ""
    pedigree = Pedigree(NumericSampleIds())
    pedigree.add_individual('individualA', [1, 2, 1, 0])
    pedigree.add_individual('individualB', [1, 0, 1, 1])
    pedigree.add_individual('individualC', [2, 1, 1, 0])
    pedigree.add_individual('individualD', [1, 2, 2, 1])
    pedigree.add_individual('individualE', [1, 1, 1, 0])
    pedigree.add_relationship('individualA', 'individualB', 'individualC')
    pedigree.add_relationship('individualC', 'individualD', 'individualE')
    recombcost = [2, 2, 2]
    superreads_list, transmission_vector, cost = phase_pedigree(
        reads, recombcost, pedigree, positions=[10, 20, 30, 40])
    assert cost == 0
    assert len(set(transmission_vector)) == 1
    all_expected_haplotypes = [('0100', '1110'), ('0011', '1000'),
                               ('1110', '1000'), ('1111', '0110'),
                               ('1000', '0110')]
    assert_haplotypes(superreads_list, all_expected_haplotypes, 4)
    trio_transmission_vectors = get_trio_transmission_vectors(
        transmission_vector, 4)
    assert_trio_allele_order(superreads_list[:3], trio_transmission_vectors[0],
                             4)
    assert_trio_allele_order(superreads_list[2:], trio_transmission_vectors[1],
                             4)
def test_genotyping_trio1():
    reads = """
      A 00
      A 00
      B 11
      B 11
      C 11
      C 00
    """

    expected_genotypes = [
        canonic_index_list_to_biallelic_gt_list([0, 0]),
        canonic_index_list_to_biallelic_gt_list([2, 2]),
        canonic_index_list_to_biallelic_gt_list([1, 1]),
    ]
    numeric_sample_ids = NumericSampleIds()
    pedigree = Pedigree(numeric_sample_ids)
    pedigree.add_individual(
        "individual0",
        canonic_index_list_to_biallelic_gt_list([1, 1]),
        [PhredGenotypeLikelihoods([1.0 / 3.0, 1.0 / 3.0, 1.0 / 3.0])] * 2,
    )
    pedigree.add_individual(
        "individual1",
        canonic_index_list_to_biallelic_gt_list([1, 1]),
        [PhredGenotypeLikelihoods([1.0 / 3.0, 1.0 / 3.0, 1.0 / 3.0])] * 2,
    )
    pedigree.add_individual(
        "individual2",
        canonic_index_list_to_biallelic_gt_list([1, 1]),
        [PhredGenotypeLikelihoods([1.0 / 3.0, 1.0 / 3.0, 1.0 / 3.0])] * 2,
    )
    pedigree.add_relationship("individual0", "individual1", "individual2")
    recombcost = [10, 10]
    genotype_pedigree(numeric_sample_ids, reads, recombcost, pedigree, expected_genotypes)
def test_genotyping_trio13():
    reads = """
      A 1111
      A 0000
      B 1111
      B 0000
    """

    expected_genotypes = [
        canonic_index_list_to_biallelic_gt_list([1, 1, 1, 1, 1, 1]),
        canonic_index_list_to_biallelic_gt_list([1, 1, 1, 1, 1, 1]),
        canonic_index_list_to_biallelic_gt_list([1, 1, 1, 1, 1, 1]),
    ]
    numeric_sample_ids = NumericSampleIds()
    pedigree = Pedigree(numeric_sample_ids)
    pedigree.add_individual(
        "individual0",
        canonic_index_list_to_biallelic_gt_list([0, 0, 0, 0, 0, 0]),
        [PhredGenotypeLikelihoods([0, 1, 0])] * 6,
    )
    pedigree.add_individual(
        "individual1",
        canonic_index_list_to_biallelic_gt_list([0, 0, 0, 0, 0, 0]),
        [PhredGenotypeLikelihoods([0, 1, 0])] * 6,
    )
    pedigree.add_individual(
        "individual2",
        canonic_index_list_to_biallelic_gt_list([0, 0, 0, 0, 0, 0]),
        [PhredGenotypeLikelihoods([0.25, 0.5, 0.25])] * 6,
    )
    pedigree.add_relationship("individual0", "individual1", "individual2")
    recombcost = [1000000, 1000000, 1000000, 1000000, 1000000, 1000000]
    genotype_pedigree(
        numeric_sample_ids, reads, recombcost, pedigree, expected_genotypes, scaling=1000,
    )
Beispiel #7
0
def test_phase_doubletrio_pure_genetic():
    reads = ""
    pedigree = Pedigree(NumericSampleIds())
    pedigree.add_individual(
        "individualA", canonic_index_list_to_biallelic_gt_list([1, 2, 1, 0]))
    pedigree.add_individual(
        "individualB", canonic_index_list_to_biallelic_gt_list([1, 0, 1, 1]))
    pedigree.add_individual(
        "individualC", canonic_index_list_to_biallelic_gt_list([2, 1, 1, 0]))
    pedigree.add_individual(
        "individualD", canonic_index_list_to_biallelic_gt_list([1, 2, 2, 1]))
    pedigree.add_individual(
        "individualE", canonic_index_list_to_biallelic_gt_list([1, 1, 1, 0]))
    pedigree.add_relationship("individualA", "individualB", "individualC")
    pedigree.add_relationship("individualC", "individualD", "individualE")
    recombcost = [2, 2, 2]
    superreads_list, transmission_vector, cost = phase_pedigree(
        reads, recombcost, pedigree, positions=[10, 20, 30, 40])
    assert cost == 0
    assert len(set(transmission_vector)) == 1
    all_expected_haplotypes = [
        ("0100", "1110"),
        ("0011", "1000"),
        ("1110", "1000"),
        ("1111", "0110"),
        ("1000", "0110"),
    ]
    assert_haplotypes(superreads_list, all_expected_haplotypes, 4)
    trio_transmission_vectors = get_trio_transmission_vectors(
        transmission_vector, 4)
    assert_trio_allele_order(superreads_list[:3], trio_transmission_vectors[0],
                             4)
    assert_trio_allele_order(superreads_list[2:], trio_transmission_vectors[1],
                             4)
Beispiel #8
0
def test_phase_trio3():
	reads = """
	  A 1111
	  B 1010
	  C 111000
	  C 010101
	  B 0101
	  A  0000
	  B  1010
	  C  1010
	  C  1100
	  A   0000
	  A   1111
	  B   1010
	  B    010
	"""
	pedigree = Pedigree(NumericSampleIds())
	pedigree.add_individual('individual0', [1,1,1,1,1,1])
	pedigree.add_individual('individual1', [1,1,1,1,1,1])
	pedigree.add_individual('individual2', [1,2,1,1,0,1])
	pedigree.add_relationship('individual0', 'individual1', 'individual2')
	recombcost = [3,3,3,4,3,3]
	superreads_list, transmission_vector, cost = phase_pedigree(reads, recombcost, pedigree)
	assert cost == 4
	assert transmission_vector in ([0,0,0,1,1,1], [1,1,1,0,0,0], [2,2,2,3,3,3], [3,3,3,2,2,2])
	all_expected_haplotypes = [
		('111111','000000'),
		('010101','101010'),
		('111000','010101')
	]
	assert_haplotypes(superreads_list, all_expected_haplotypes, 6)
Beispiel #9
0
def bipartition(reads):
    positions = reads.get_positions()
    # create genotypes over your variants: all heterozygous (=1)
    genotypes = canonic_index_list_to_biallelic_gt_list([1] * len(positions))
    # genotype likelihoods are None
    genotype_likelihoods = [None] * len(positions)
    # create empty pedigree
    pedigree = Pedigree(NumericSampleIds())
    # add one individual to pedigree
    pedigree.add_individual('individual0', genotypes, genotype_likelihoods)
    # recombination cost vector, irrelevant if one using one individual
    recombcost = [1] * len(positions)

    # run the core phasing algorithm, creating a DP table
    dp_table = PedigreeDPTable(reads,
                               recombcost,
                               pedigree,
                               distrust_genotypes=False)
    phasing, transmission_vector = dp_table.get_super_reads()
    #print('PHASING')
    #print(phasing[0])
    #print(phasing[0][0])
    #print(phasing[0][1])
    mec_score = dp_table.get_optimal_cost()
    eprint("MEC Score:", mec_score)
    eprint("MEC Score / readset length:",
           float(mec_score) / float(readset_length))

    # In case the bi-partition of reads is of interest:
    partition = dp_table.get_optimal_partitioning()
    #print(partition)
    eprint("partition fraction:", sum(partition) / float(len(partition)))

    return phasing, partition
Beispiel #10
0
def test_genotyping_quartet3():
    reads = """
	  A 111111
	  A 000000
	  B 010101
	  B 101010
	  C 000000
	  C 010101
	  D 000000
	  D 010101
	"""
    expected_genotypes = [[1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1],
                          [0, 1, 0, 1, 0, 1], [0, 1, 0, 1, 0, 1]]
    numeric_sample_ids = NumericSampleIds()
    pedigree = Pedigree(numeric_sample_ids)
    pedigree.add_individual(
        'individual0', [0, 0, 0, 0, 0, 0],
        [PhredGenotypeLikelihoods(1.0 / 3.0, 1.0 / 3.0, 1.0 / 3.0)] * 6)
    pedigree.add_individual(
        'individual1', [0, 0, 0, 0, 0, 0],
        [PhredGenotypeLikelihoods(1.0 / 3.0, 1.0 / 3.0, 1.0 / 3.0)] * 6)
    pedigree.add_individual(
        'individual2', [0, 0, 0, 0, 0, 0],
        [PhredGenotypeLikelihoods(1.0 / 3.0, 1.0 / 3.0, 1.0 / 3.0)] * 6)
    pedigree.add_individual(
        'individual3', [0, 0, 0, 0, 0, 0],
        [PhredGenotypeLikelihoods(1.0 / 3.0, 1.0 / 3.0, 1.0 / 3.0)] * 6)
    pedigree.add_relationship('individual0', 'individual1', 'individual2')
    pedigree.add_relationship('individual0', 'individual1', 'individual3')
    recombcost = [3, 3, 3, 3, 3, 3]
    genotype_pedigree(numeric_sample_ids, reads, recombcost, pedigree,
                      expected_genotypes)
Beispiel #11
0
def test_pedigree_with_gls():
    ped = Pedigree(NumericSampleIds())
    genotypes1 = [0, 1, 0, 2]
    gls1 = [
        PhredGenotypeLikelihoods(0, 1, 2),
        PhredGenotypeLikelihoods(215, 81, 147),
        PhredGenotypeLikelihoods(199, 49, 253),
        PhredGenotypeLikelihoods(167, 200, 163),
    ]
    genotypes5 = [1, 2, 2, 0]
    gls5 = [
        PhredGenotypeLikelihoods(184, 71, 233),
        PhredGenotypeLikelihoods(65, 32, 87),
        PhredGenotypeLikelihoods(28, 215, 131),
        PhredGenotypeLikelihoods(98, 250, 137),
    ]
    ped.add_individual('sample1', genotypes1, gls1)
    assert len(ped) == 1
    assert ped.variant_count == 4, str(ped.variant_count)
    ped.add_individual('sample5', genotypes5, gls5)
    assert len(ped) == 2
    assert ped.variant_count == 4, str(ped.variant_count)
    for i in range(ped.variant_count):
        assert ped.genotype('sample1', i) == genotypes1[i]
        assert list(ped.genotype_likelihoods('sample1', i)) == list(gls1[i])
        assert ped.genotype('sample5', i) == genotypes5[i]
        assert list(ped.genotype_likelihoods('sample5', i)) == list(gls5[i])
Beispiel #12
0
def test_phase_trio4():
	reads = """
	  B 101
	  B 101
	  B 101
	  A 111
	  A 111
	  A 111
	  C 111
	  C 111
	  C 111
	"""
	pedigree = Pedigree(NumericSampleIds())
	pedigree.add_individual('individual0', [1,1,1])
	pedigree.add_individual('individual1', [1,1,1])
	pedigree.add_individual('individual2', [1,1,1])
	pedigree.add_relationship('individual0', 'individual1', 'individual2')
	recombcost = [1,1,1]
	superreads_list, transmission_vector, cost = phase_pedigree(reads, recombcost, pedigree)
	assert cost == 2
	assert transmission_vector in ([0,2,0], [2,0,2], [1,3,1], [3,1,3])
	all_expected_haplotypes = [
		('111','000'),
		('101','010'),
		('111','000')
	]
	assert_haplotypes(superreads_list, all_expected_haplotypes, 3)
Beispiel #13
0
def test_genotyping_trio10():
    reads = """
	  B 0000
	  B 0000
	  B 0000
	  B 0000
	  B 0000
	  B 0000
	  A 1111
	  A 1111
	  A 1111
	  A 1111
	  A 1111
	  A 1111
	"""

    # no reads for child, but genotype must be 1/0 for each pos. (due to inheritance)
    expected_genotypes = [[2, 2, 2, 2], [0, 0, 0, 0], [1, 1, 1, 1]]
    numeric_sample_ids = NumericSampleIds()
    pedigree = Pedigree(numeric_sample_ids)
    pedigree.add_individual(
        'individual0', [0, 0, 0, 0],
        [PhredGenotypeLikelihoods(1.0 / 3.0, 1.0 / 3.0, 1.0 / 3.0)] * 4)
    pedigree.add_individual(
        'individual1', [0, 0, 0, 0],
        [PhredGenotypeLikelihoods(1.0 / 3.0, 1.0 / 3.0, 1.0 / 3.0)] * 4)
    pedigree.add_individual(
        'individual2', [0, 0, 0, 0],
        [PhredGenotypeLikelihoods(1.0 / 3.0, 1.0 / 3.0, 1.0 / 3.0)] * 4)
    pedigree.add_relationship('individual0', 'individual1', 'individual2')
    recombcost = [10, 10, 10, 10]
    genotype_pedigree(numeric_sample_ids, reads, recombcost, pedigree,
                      expected_genotypes)
Beispiel #14
0
def test_phase_trio_genotype_likelihoods():
	reads = """
	  A 111
	  A 010
	  A 110
	  B 001
	  B 110
	  B 101
	  C 001
	  C 010
	  C 010
	"""
	pedigree = Pedigree(NumericSampleIds())
	genotype_likelihoods_mother = [
		PhredGenotypeLikelihoods(0,0,0),
		PhredGenotypeLikelihoods(0,0,1),
		PhredGenotypeLikelihoods(5,0,5)
	]
	genotype_likelihoods0 = [PhredGenotypeLikelihoods(0,0,0)] * 3
	pedigree.add_individual('individual0', [0,0,0], genotype_likelihoods_mother)
	pedigree.add_individual('individual1', [0,0,0], genotype_likelihoods0)
	pedigree.add_individual('individual2', [0,0,0], genotype_likelihoods0)
	pedigree.add_relationship('individual0', 'individual1', 'individual2')
	recombcost = [10,10,10]
	superreads_list, transmission_vector, cost = phase_pedigree(reads, recombcost, pedigree, True)
	assert cost == 3
	assert len(set(transmission_vector)) == 1
	all_expected_haplotypes = [
		('111','010'),
		('001','110'),
		('001','010')
	]
	assert_haplotypes(superreads_list, all_expected_haplotypes, 3)
Beispiel #15
0
def test_genotyping_trio14():
    reads = """
	  A 111111
	  A 111111
	  B 111111
	  B 000000
	  C 000000
	"""

    expected_genotypes = [[2, 2, 2, 2, 2, 2], [1, 1, 1, 1, 1, 1],
                          [1, 1, 1, 1, 1, 1]]
    numeric_sample_ids = NumericSampleIds()
    pedigree = Pedigree(numeric_sample_ids)
    pedigree.add_individual(
        'individual0', [0, 0, 0, 0, 0, 0],
        [PhredGenotypeLikelihoods(1 / 3.0, 1 / 3.0, 1 / 3.0)] * 6)
    pedigree.add_individual(
        'individual1', [0, 0, 0, 0, 0, 0],
        [PhredGenotypeLikelihoods(1 / 3.0, 1 / 3.0, 1 / 3.0)] * 6)
    pedigree.add_individual(
        'individual2', [0, 0, 0, 0, 0, 0],
        [PhredGenotypeLikelihoods(1 / 3.0, 1 / 3.0, 1 / 3.0)] * 6)
    pedigree.add_relationship('individual0', 'individual1', 'individual2')
    recombcost = [1000000, 1000000, 1000000, 1000000, 1000000, 1000000]
    genotype_pedigree(numeric_sample_ids,
                      reads,
                      recombcost,
                      pedigree,
                      expected_genotypes,
                      scaling=1000)
Beispiel #16
0
def test_genotyping_trio1():
    reads = """
	  A 00
	  A 00
	  B 11
	  B 11
	  C 11
	  C 00
	"""

    expected_genotypes = [[0, 0], [2, 2], [1, 1]]
    numeric_sample_ids = NumericSampleIds()
    pedigree = Pedigree(numeric_sample_ids)
    pedigree.add_individual(
        'individual0', [1, 1],
        [PhredGenotypeLikelihoods(1.0 / 3.0, 1.0 / 3.0, 1.0 / 3.0)] * 2)
    pedigree.add_individual(
        'individual1', [1, 1],
        [PhredGenotypeLikelihoods(1.0 / 3.0, 1.0 / 3.0, 1.0 / 3.0)] * 2)
    pedigree.add_individual(
        'individual2', [1, 1],
        [PhredGenotypeLikelihoods(1.0 / 3.0, 1.0 / 3.0, 1.0 / 3.0)] * 2)
    pedigree.add_relationship('individual0', 'individual1', 'individual2')
    recombcost = [10, 10]
    genotype_pedigree(numeric_sample_ids, reads, recombcost, pedigree,
                      expected_genotypes)
Beispiel #17
0
def test_phase_quartet2():
	reads = """
	  A 111111
	  A 000000
	  B 010101
	  B 101010
	  C 000000
	  C 010101
	  D 000000
	  D 010101
	"""
	pedigree = Pedigree(NumericSampleIds())
	pedigree.add_individual('individual0', [1,1,1,1,1,1])
	pedigree.add_individual('individual1', [1,1,1,1,1,1])
	pedigree.add_individual('individual2', [0,1,0,1,0,1])
	pedigree.add_individual('individual3', [0,1,0,1,0,1])
	pedigree.add_relationship('individual0', 'individual1', 'individual2')
	pedigree.add_relationship('individual0', 'individual1', 'individual3')
	recombcost =[3,3,3,3,3,3]

	superreads_list, transmission_vector, cost = phase_pedigree(reads, recombcost, pedigree)
	assert cost == 0
	assert len(set(transmission_vector)) == 1
	all_expected_haplotypes = [
		('111111','000000'),
		('010101','101010'),
		('000000','010101'),
		('000000','010101')
	]
	assert_haplotypes(superreads_list, all_expected_haplotypes, 6)
Beispiel #18
0
def test_phase_trio5():
	reads = """
	  B 101
	  B 101
	  B 101
	  A 111
	  A 111
	  A 111
	  C 111
	  C 111
	  C 111
	"""
	pedigree = Pedigree(NumericSampleIds())
	pedigree.add_individual('individual0', [1,1,1])
	pedigree.add_individual('individual1', [1,1,1])
	pedigree.add_individual('individual2', [1,1,1])
	pedigree.add_relationship('individual0', 'individual1', 'individual2')
	recombcost = [2,2,2]
	superreads_list, transmission_vector, cost = phase_pedigree(reads, recombcost, pedigree)
	assert cost == 3
	assert len(set(transmission_vector)) == 1
	all_expected_haplotypes = [
		('111','000'),
		('111','000'),
		('111','000')
	]
	assert_haplotypes(superreads_list, all_expected_haplotypes, 3)
Beispiel #19
0
def test_genotyping_trio5():
    reads = """
	  B 101
	  B 101
	  B 101
	  A 111
	  A 111
	  A 111
	  C 111
	  C 111
	  C 101
	  C 101
	"""
    expected_genotypes = [[2, 2, 2], [2, 0, 2], [2, 1, 2]]
    numeric_sample_ids = NumericSampleIds()
    pedigree = Pedigree(numeric_sample_ids)
    pedigree.add_individual(
        'individual0', [0, 0, 0],
        [PhredGenotypeLikelihoods(1.0 / 3.0, 1.0 / 3.0, 1.0 / 3.0)] * 3)
    pedigree.add_individual(
        'individual1', [0, 0, 0],
        [PhredGenotypeLikelihoods(1.0 / 3.0, 1.0 / 3.0, 1.0 / 3.0)] * 3)
    pedigree.add_individual(
        'individual2', [0, 0, 0],
        [PhredGenotypeLikelihoods(1.0 / 3.0, 1.0 / 3.0, 1.0 / 3.0)] * 3)
    pedigree.add_relationship('individual0', 'individual1', 'individual2')
    recombcost = [2, 2, 2]
    genotype_pedigree(numeric_sample_ids, reads, recombcost, pedigree,
                      expected_genotypes)
def test_weighted_genotyping():
    reads = """
      B 00
      B 11
      A 11
      A 00
      C 11
      C 11
    """
    weights = """
      99
      99
      99
      99
      99
      99
    """
    expected_genotypes = [
        canonic_index_list_to_biallelic_gt_list([1, 1]),
        canonic_index_list_to_biallelic_gt_list([1, 1]),
        canonic_index_list_to_biallelic_gt_list([2, 2]),
    ]
    numeric_sample_ids = NumericSampleIds()
    pedigree = Pedigree(numeric_sample_ids)
    pedigree.add_individual(
        "individual0",
        canonic_index_list_to_biallelic_gt_list([0, 0, 0, 0]),
        [PhredGenotypeLikelihoods([0.25, 0.5, 0.25])] * 4,
    )
    pedigree.add_individual(
        "individual1",
        canonic_index_list_to_biallelic_gt_list([0, 0, 0, 0]),
        [PhredGenotypeLikelihoods([0.25, 0.5, 0.25])] * 4,
    )
    pedigree.add_individual(
        "individual2",
        canonic_index_list_to_biallelic_gt_list([0, 0, 0, 0]),
        [PhredGenotypeLikelihoods([0.25, 0.5, 0.25])] * 4,
    )
    pedigree.add_relationship("individual0", "individual1", "individual2")
    # recombination is extremely unlikely
    recombcost = [1000, 1000, 1000, 1000]

    expected = {
        0: [[0, 1, 0], [0, 1, 0]],
        1: [[0, 1, 0], [0, 1, 0]],
        2: [[0, 1.0 / 3.0, 2 / 3.0], [0, 1.0 / 3.0, 2 / 3.0]],
    }
    genotype_pedigree(
        numeric_sample_ids,
        reads,
        recombcost,
        pedigree,
        expected_genotypes,
        weights,
        expected,
        scaling=500,
    )
Beispiel #21
0
def test_genotyping_empty_readset():
	rs = ReadSet()
	genotypes = [1,1]
	recombcost = [1,1]
	numeric_sample_ids = NumericSampleIds()
	pedigree = Pedigree(numeric_sample_ids)
	genotype_likelihoods = [None, None]
	pedigree.add_individual('individual0', genotypes, genotype_likelihoods)
	dp_forward_backward = GenotypeDPTable(numeric_sample_ids,rs, recombcost, pedigree)
Beispiel #22
0
def test_phase_quartet3():
    reads = """
      A 1111
      A 0000
      B 1010
      C 111000
      C 010101
      D 000000
      D 010
      B 0101
      C  1100
      D  10010
      A   0000
      A   1111
      B   1010
      B   0101
    """
    pedigree = Pedigree(NumericSampleIds())
    pedigree.add_individual(
        "individual0",
        canonic_index_list_to_biallelic_gt_list([1, 1, 1, 1, 1, 1]))
    pedigree.add_individual(
        "individual1",
        canonic_index_list_to_biallelic_gt_list([1, 1, 1, 1, 1, 1]))
    pedigree.add_individual(
        "individual2",
        canonic_index_list_to_biallelic_gt_list([1, 2, 1, 1, 0, 1]))
    pedigree.add_individual(
        "individual3",
        canonic_index_list_to_biallelic_gt_list([0, 1, 0, 0, 1, 0]))
    pedigree.add_relationship("individual0", "individual1", "individual2")
    pedigree.add_relationship("individual0", "individual1", "individual3")
    recombcost = [3, 3, 3, 4, 3, 3]
    superreads_list, transmission_vector, cost = phase_pedigree(
        reads, recombcost, pedigree)
    print(cost)
    print(transmission_vector)
    assert cost == 8
    # TODO: expect transmission in both trio relations. Update once transmission vectors
    #       are returned per trio relationship
    # assert transmission_vector in ([0,0,0,1,1,1], [1,1,1,0,0,0], [2,2,2,3,3,3], [3,3,3,2,2,2])
    all_expected_haplotypes = [
        ("111111", "000000"),
        ("010101", "101010"),
        ("111000", "010101"),
        ("000000", "010010"),
    ]
    assert_haplotypes(superreads_list, all_expected_haplotypes, 6)
    trio_transmission_vectors = get_trio_transmission_vectors(
        transmission_vector, 6)
    assert_trio_allele_order(superreads_list[:3], trio_transmission_vectors[0],
                             6)
    assert_trio_allele_order(
        [superreads_list[0], superreads_list[1], superreads_list[3]],
        trio_transmission_vectors[1],
        6,
    )
Beispiel #23
0
def test_genotyping_empty_readset():
    rs = ReadSet()
    genotypes = canonic_index_list_to_biallelic_gt_list([1, 1])
    recombcost = [1, 1]
    numeric_sample_ids = NumericSampleIds()
    pedigree = Pedigree(numeric_sample_ids)
    genotype_likelihoods = [None, None]
    pedigree.add_individual("individual0", genotypes, genotype_likelihoods)
    _ = GenotypeDPTable(numeric_sample_ids, rs, recombcost, pedigree)
Beispiel #24
0
	def test_parse(self):
		numeric_sample_ids = NumericSampleIds()
		assert len(numeric_sample_ids) == 0
		trios = list(PedReader('tests/data/pedigree.ped', numeric_sample_ids))
		assert trios[0] == Trio(child='child1', mother='mother', father='father')
		assert trios[1] == Trio(child='child2', mother='mother', father='father')
		assert trios[2] == Trio(child='father', mother=None, father=None)
		assert trios[3] == Trio(child='mother', mother=None, father=None)
		assert trios[4] == Trio(child='orphan', mother=None, father=None)
		assert len(numeric_sample_ids) == 5
Beispiel #25
0
def test_phase_empty_trio():
	rs = ReadSet()
	recombcost = []
	pedigree = Pedigree(NumericSampleIds())
	pedigree.add_individual('individual0', [])
	pedigree.add_individual('individual1', [])
	pedigree.add_individual('individual2', [])
	pedigree.add_relationship('individual0', 'individual1', 'individual2')
	dp_table = PedigreeDPTable(rs, recombcost, pedigree)
	(superreadsm, superreadsf, superreadsc), transmission_vector = dp_table.get_super_reads()
def test_genotyping_empty_trio():
    rs = ReadSet()
    recombcost = []
    numeric_sample_ids = NumericSampleIds()
    pedigree = Pedigree(numeric_sample_ids)
    pedigree.add_individual("individual0", [], [])
    pedigree.add_individual("individual1", [], [])
    pedigree.add_individual("individual2", [], [])
    pedigree.add_relationship("individual0", "individual1", "individual2")
    _ = GenotypeDPTable(numeric_sample_ids, rs, recombcost, pedigree)
Beispiel #27
0
def test_genotyping_empty_trio():
    rs = ReadSet()
    recombcost = []
    numeric_sample_ids = NumericSampleIds()
    pedigree = Pedigree(numeric_sample_ids)
    pedigree.add_individual('individual0', [], [])
    pedigree.add_individual('individual1', [], [])
    pedigree.add_individual('individual2', [], [])
    pedigree.add_relationship('individual0', 'individual1', 'individual2')
    dp_forward_backward = GenotypeDPTable(numeric_sample_ids, rs, recombcost,
                                          pedigree)
Beispiel #28
0
def test_phase_empty_readset(algorithm):
    rs = ReadSet()
    recombcost = [1, 1]
    genotypes = canonic_index_list_to_biallelic_gt_list([1, 1])
    pedigree = Pedigree(NumericSampleIds())
    genotype_likelihoods = [None, None]
    pedigree.add_individual("individual0", genotypes, genotype_likelihoods)

    if algorithm == "hapchat":
        dp_table = HapChatCore(rs)
    else:
        dp_table = PedigreeDPTable(rs, recombcost, pedigree)

    _ = dp_table.get_super_reads()
def test_genotyping_quartet4():
    reads = """
      A 1111
      A 0000
      B 1010
      C 111000
      C 010101
      D 000000
      D 010
      B 0101
      C  1100
      D  10010
      A   0000
      A   1111
      B   1010
      B   0101
    """
    expected_genotypes = [
        canonic_index_list_to_biallelic_gt_list([1, 1, 1, 1, 1, 1]),
        canonic_index_list_to_biallelic_gt_list([1, 1, 1, 1, 1, 1]),
        canonic_index_list_to_biallelic_gt_list([1, 2, 1, 1, 0, 1]),
        canonic_index_list_to_biallelic_gt_list([0, 1, 0, 0, 1, 0]),
    ]
    numeric_sample_ids = NumericSampleIds()
    pedigree = Pedigree(numeric_sample_ids)
    pedigree.add_individual(
        "individual0",
        canonic_index_list_to_biallelic_gt_list([0, 0, 0, 0, 0, 0]),
        [PhredGenotypeLikelihoods([1.0 / 3.0, 1.0 / 3.0, 1.0 / 3.0])] * 6,
    )
    pedigree.add_individual(
        "individual1",
        canonic_index_list_to_biallelic_gt_list([0, 0, 0, 0, 0, 0]),
        [PhredGenotypeLikelihoods([1.0 / 3.0, 1.0 / 3.0, 1.0 / 3.0])] * 6,
    )
    pedigree.add_individual(
        "individual2",
        canonic_index_list_to_biallelic_gt_list([0, 0, 0, 0, 0, 0]),
        [PhredGenotypeLikelihoods([1.0 / 3.0, 1.0 / 3.0, 1.0 / 3.0])] * 6,
    )
    pedigree.add_individual(
        "individual3",
        canonic_index_list_to_biallelic_gt_list([0, 0, 0, 0, 0, 0]),
        [PhredGenotypeLikelihoods([1.0 / 3.0, 1.0 / 3.0, 1.0 / 3.0])] * 6,
    )
    pedigree.add_relationship("individual0", "individual1", "individual2")
    pedigree.add_relationship("individual0", "individual1", "individual3")
    recombcost = [3, 3, 3, 4, 3, 3]
    genotype_pedigree(numeric_sample_ids, reads, recombcost, pedigree, expected_genotypes)
Beispiel #30
0
def verify(rs, all_heterozygous=False):
    positions = rs.get_positions()
    recombcost = [1] * len(
        positions)  # recombination costs 1, should not occur
    pedigree = Pedigree(NumericSampleIds())
    genotype_likelihoods = [
        None if all_heterozygous else PhredGenotypeLikelihoods(0, 0, 0)
    ] * len(positions)
    pedigree.add_individual('individual0', [1] * len(positions),
                            genotype_likelihoods)  # all genotypes heterozygous
    dp_table = PedigreeDPTable(rs,
                               recombcost,
                               pedigree,
                               distrust_genotypes=not all_heterozygous)
    verify_mec_score_and_partitioning(dp_table, rs)