def test_compound_multiple_2(self):
     """Reference case for the following ones"""
     genotypes = array(
         [[2, 1, 2, 2, 1, 1], [1, 2, 2, 2, 1, 1], [1, 2, 2, 2, 1, 1]],
         dtype=DTYPE)
     variants = VariantsCollection([
         Variant(variant_id=1, start=1, gene_symbol='B'),  # mother contrib
         Variant(variant_id=2, start=2,
                 gene_symbol='B'),  # father contrib 1, not transmitted
         Variant(variant_id=3, start=3,
                 gene_symbol='B'),  # father contrib 2, transmitted
     ])
     var = GenotypesFilterCompoundHeterozygous(self.ss).apply(
         variants, genotypes).variants
     self.assertEqual(len(var), 3)
 def test_compound_healty_homozygous(self):
     """Unaffected homozygous: exclude (because it will affect both alleles)"""
     genotypes = array(
         [[2, 1, 2, 2, 1, 1], [1, 2, 2, 2, 1, 4], [1, 2, 2, 2, 1, 1]],
         dtype=DTYPE)
     variants = VariantsCollection([
         Variant(variant_id=1, start=1, gene_symbol='B'),  # mother
         Variant(variant_id=2, start=2,
                 gene_symbol='B'),  # father 1 + unaffected hom
         Variant(variant_id=3, start=3, gene_symbol='B'),  # father 2
     ])
     var = GenotypesFilterCompoundHeterozygous(self.ss).apply(
         variants, genotypes).variants
     self.assertEqual(
         len(var), 2)  # would be 3 but we exclude 1 variant -> 1 pair left
    def test_active(self):
        """Should return what is not ref/ref (1) in at least one of the selected samples."""
        genotypes = array(
            [[2, 1, 2, 1, 1, 1], [1, 2, 2, 2, 1, 1], [1, 2, 2, 2, 1, 1],
             [1, 2, 2, 2, 1, 1], [1, 1, 2, 2, 1, 1]],
            dtype=DTYPE)
        variants = VariantsCollection(
            [Variant(variant_id=x + 1) for x in range(len(genotypes))],
            db='test')
        # the db parameter should be ignored
        # pk needs to start at 0 to emulate the array indexing
        groups = {"affected": ["Mother"]}
        ss = SamplesSelection(self.F.ss.samples, groups)
        var = GenotypesFilterActive(ss).apply(variants, genotypes).variants
        self.assertEqual(len(var), 1)
        self.assertTrue(any([genotypes[v.pk][i] > 1 for i in [0]]
                            for v in var))

        groups = {"affected": ["Mother", "Father"]}
        ss = SamplesSelection(self.F.ss.samples, groups)
        var = GenotypesFilterActive(ss).apply(variants, genotypes).variants
        self.assertEqual(len(var), 4)
        self.assertTrue(
            any([genotypes[v.pk][i] > 1 for i in [0, 1]] for v in var))

        groups = {"affected": ["Dasha", "Lena"], "not_affected": ["Lesha"]}
        ss = SamplesSelection(self.F.ss.samples, groups)
        var = GenotypesFilterActive(ss).apply(variants, genotypes).variants
        self.assertEqual(len(var), 4)
        self.assertTrue(
            any([genotypes[v.pk][i] > 1 for i in [3, 4, 5]] for v in var))
 def test_recessive(self):
     """All affected must be homozygous (4), the parents must be hererozygous,
     and all other not affected must be heterozygous or non-carriers."""
     genotypes = array(
         [
             [2, 1, 4, 2, 1, 1],  # X - Both parents must have it
             [2, 2, 4, 2, 1, 1],  # X - Affected but not homozygous
             [2, 2, 4, 4, 1, 1],  # V - OK
             [2, 2, 4, 4, 4, 1],  # X - Not affected homozygous
             [2, 2, 4, 4, 2, 1]
         ],  # V - Not affected carrier
         dtype=DTYPE)
     variants = VariantsCollection(
         [Variant(variant_id=x + 1) for x in range(len(genotypes))],
         db='test')
     groups = {
         "affected": ["Sasha", "Dasha"],
         "not_affected": ["Mother", "Father", "Lena", "Lesha"]
     }
     ss = SamplesSelection(self.F.samples, groups)
     var = GenotypesFilterRecessive(ss).apply(variants, genotypes).variants
     self.assertEqual(len(var), 2)
     for v in var:
         gts = genotypes[v.pk - 1]
         self.assertEqual(gts[0], 2)
         self.assertEqual(gts[1], 2)
         self.assertEqual(gts[2], 4)
         self.assertEqual(gts[3], 4)
         self.assertLessEqual(gts[4], 2)
         self.assertLessEqual(gts[5], 2)
 def test_compound_affected_nocompound(self):
     """Affected without the compound: exclude (the disease is not due to a compound).
     (!? When one affected has it but not the other, the disease cannot be due to this compound)."""
     genotypes = array(
         [[2, 1, 2, 2, 1, 1], [1, 2, 2, 2, 1, 1], [1, 2, 2, 1, 1, 1]],
         dtype=DTYPE)
     variants = VariantsCollection([
         Variant(variant_id=1, start=1,
                 gene_symbol='B'),  # } } father +  aff1  + aff2
         Variant(variant_id=2, start=2,
                 gene_symbol='B'),  # } } mother + (aff1) + aff2
         Variant(variant_id=3, start=3,
                 gene_symbol='B'),  # }   mother +  aff1
     ])
     var = GenotypesFilterCompoundHeterozygous(self.ss).apply(
         variants, genotypes).variants
     self.assertEqual(
         len(var), 2)  # would be 3, but we exclude 1 variant -> 1 pair left
 def test_compound_unaffected_compound(self):
     """Unaffected compound: exclude (the disease is not due to a compound)"""
     genotypes = array([[2, 1, 2, 2, 1, 1], [2, 1, 2, 2, 2, 1],
                        [1, 2, 2, 2, 1, 1], [1, 2, 2, 2, 2, 1]],
                       dtype=DTYPE)
     variants = VariantsCollection([
         Variant(variant_id=1, start=0, gene_symbol='B'),  # mother 1
         Variant(variant_id=2, start=1,
                 gene_symbol='B'),  # mother 2 + unaffected 1
         Variant(variant_id=3, start=2, gene_symbol='B'),  # father 1
         Variant(variant_id=4, start=3,
                 gene_symbol='B'),  # father 2 + unaffected 2
     ])
     var = GenotypesFilterCompoundHeterozygous(self.ss).apply(
         variants, genotypes).variants
     self.assertEqual(
         len(var),
         2)  # would be 4, but here we exclude an entire pair (2 variants):
 def setUp(self):
     self.F = Family()
     groups = {
         "affected": ["Sasha", "Dasha"],
         "not_affected": ["Mother", "Father", "Lesha", "Lena"]
     }
     self.ss = SamplesSelection(self.F.samples, groups)
     # Most standard case:
     self.genotypes = array(
         [
             [2, 1, 2, 2, 1, 1],  # mother and child carry var 1
             [1, 2, 2, 2, 1, 1]
         ],  # father and child carry var 2
         dtype=DTYPE)
     self.variants = VariantsCollection([
         Variant(variant_id=1, start=1, gene_symbol='B'),  # mother contrib
         Variant(variant_id=2, start=2, gene_symbol='B'),  # father contrib
     ])
 def test_compound_same_parent(self):
     """One of the affected gets a pair from the same parent: exclude"""
     genotypes = array([[2, 1, 2, 1, 1, 1], [1, 2, 2, 2, 1, 1],
                        [1, 2, 2, 2, 1, 1], [1, 2, 2, 2, 1, 1]],
                       dtype=DTYPE)
     variants = VariantsCollection([
         Variant(variant_id=1, start=1,
                 gene_symbol='B'),  # mother contrib   } }
         Variant(
             variant_id=2, start=2,
             gene_symbol='B'),  # father contrib 1 }    father + affected
         Variant(
             variant_id=3, start=3,
             gene_symbol='B'),  # father contrib 2   }  father + affected
         Variant(variant_id=4, start=4,
                 gene_symbol='B'),  # father contrib 3
     ])
     var = GenotypesFilterCompoundHeterozygous(self.ss).apply(
         variants, genotypes).variants
     self.assertEqual(len(var), 0)
 def test_compound_multiple_1(self):
     """There can be multiple combinations"""
     genotypes = array(
         [[2, 1, 2, 2, 1, 1], [2, 1, 2, 2, 1, 1], [1, 2, 2, 2, 1, 1],
          [1, 2, 2, 2, 1, 1], [1, 2, 2, 2, 1, 1]],
         dtype=DTYPE)
     variants = VariantsCollection([
         Variant(variant_id=1, start=1,
                 gene_symbol='B'),  # mother contrib 1
         Variant(variant_id=2, start=1,
                 gene_symbol='B'),  # mother contrib 2
         Variant(variant_id=3, start=2,
                 gene_symbol='B'),  # father contrib 1
         Variant(variant_id=4, start=3,
                 gene_symbol='B'),  # father contrib 2
         Variant(variant_id=5, start=4,
                 gene_symbol='B'),  # father contrib 3
     ])
     var = GenotypesFilterCompoundHeterozygous(self.ss).apply(
         variants, genotypes).variants
     self.assertEqual(len(var), 5)  # 6 pairs but 5 variants
Exemplo n.º 10
0
 def test_compound_same_gene(self):
     """Compounds be on the same gene"""
     genotypes = array(
         [[2, 1, 2, 2, 1, 1], [1, 2, 2, 2, 1, 1], [1, 2, 2, 2, 1, 1]],
         dtype=DTYPE)
     variants = VariantsCollection([
         Variant(variant_id=1, start=1, gene_symbol='B'),  # mother contrib
         Variant(variant_id=2, start=2, gene_symbol='B'),  # father contrib
         Variant(variant_id=3, start=2,
                 gene_symbol='C'),  # X - not the same transcript
     ])
     var = GenotypesFilterCompoundHeterozygous(self.ss).apply(
         variants, genotypes).variants
     self.assertEqual(
         len(var), 2)  # not 1 because they are reported on 2 separate lines
     for v in var:
         gts = genotypes[v.pk]
         self.assertTrue((gts[0] == 1 and gts[1] == 2)
                         or (gts[0] == 2 and gts[1] == 1))  # parents
         self.assertGreaterEqual(gts[2], 2)
         self.assertGreaterEqual(gts[3], 2)
         self.assertLessEqual(gts[4], 2)
         self.assertLessEqual(gts[5], 1)
Exemplo n.º 11
0
    def test_not_on_chrom_X(self):
        """Only variants on chrom X must pass"""
        genotypes = array([[2, 2, 2, 4, 1, 1]] * 10, dtype=DTYPE)
        groups = {
            "affected": ["Father", "Sasha", "Dasha"],
            "not_affected": ["Mother", "Lena", "Lesha"]
        }
        ss = SamplesSelection(self.F.samples, groups)

        variants = VariantsCollection([
            Variant(variant_id=x + 1, chrom=('chrX' if x > 5 else 'chrU'))
            for x in range(len(genotypes))
        ],
                                      db='test')
        var = GenotypesFilterXLinked(ss).apply(variants, genotypes).variants
        self.assertEqual(len(var), 4)

        variants = VariantsCollection([
            Variant(variant_id=x + 1, chrom=('chrX' if x % 2 else 'chrU'))
            for x in range(len(genotypes))
        ],
                                      db='test')
        var = GenotypesFilterXLinked(ss).apply(variants, genotypes).variants
        self.assertEqual(len(var), 5)
Exemplo n.º 12
0
 def setUp(self):
     self.F = Family()
     self.genotypes = array(
         [
             [2, 1, 2, 2, 1, 1],  # X - Mother carrier
             [1, 2, 2, 2, 1, 1],  # X - Father carrier
             [1, 1, 2, 2, 1, 1],  # V - OK
             [1, 1, 2, 2, 1, 2],  # X - Not affected mutant
             [1, 1, 2, 1, 1, 1],  # X - Affected non carrier
             [1, 1, 2, 2, 1, 1]
         ],  # V - Actually the only working situation
         dtype=DTYPE)
     self.variants = VariantsCollection(
         [Variant(variant_id=x + 1) for x in range(len(self.genotypes))],
         db='test')
Exemplo n.º 13
0
 def setUp(self):
     self.F = Family()
     self.genotypes = array(
         [
             [2, 1, 2, 2, 1, 1],  # X - from unaffected mother
             [1, 2, 2, 2, 1, 1],  # V - from affected father
             [1, 2, 2, 1, 1, 1],  # X - affected without the mutation
             [1, 2, 2, 2, 2, 1],  # X - not affected with the mutation
             [1, 1, 2, 1, 1, 1],  # X - de novo
             [2, 2, 4, 1, 1, 1
              ],  # X - recessive, both parents have it (unaffected)
             [1, 2, 2, 2, 1, 1]
         ],  # V - Actually the only working situation
         dtype=DTYPE)
     self.variants = VariantsCollection(
         [Variant(variant_id=x + 1) for x in range(len(self.genotypes))],
         db='test')
Exemplo n.º 14
0
 def test_both_parents_carriers_unaffected(self):
     """Both parents are carriers"""
     genotypes = array(
         [
             [2, 2, 2, 4, 1, 1
              ],  # V - Both parents carriers, affected children have it
             [4, 2, 2, 4, 1, 1
              ],  # X - Both parents carriers, mother carrier hom
             [2, 2, 2, 4, 2, 1
              ],  # X - Both parents carriers, non-affected son carrier
             [
                 2, 2, 2, 4, 1, 4
             ],  # X - Both parents carriers, non-affected external female carrier hom
             [
                 2, 4, 2, 4, 1, 2
             ],  # X - Both parents carriers, mother is carrier hom (should be affected)
             [
                 4, 2, 2, 4, 1, 2
             ],  # X - Both parents carriers, father is carrier hom (can't be)
             [
                 2, 2, 2, 2, 1, 1
             ],  # X - Both parents carriers, affected daughter is carrier het only
             [2, 2, 4, 4, 1, 1]
         ],  # X - Both parents carriers, affected male is carrier hom
         dtype=DTYPE)
     variants = VariantsCollection([
         Variant(variant_id=x + 1, chrom='chrX')
         for x in range(len(genotypes))
     ],
                                   db='test')
     groups = {
         "affected": ["Father", "Sasha", "Dasha"],
         "not_affected": ["Mother", "Lena", "Lesha"]
     }
     ss = SamplesSelection(self.F.samples, groups)
     var = GenotypesFilterXLinked(ss).apply(variants, genotypes).variants
     self.assertEqual(len(var), 1)
     for v in var:
         gts = genotypes[v.pk - 1]
         self.assertLessEqual(gts[0], 6)  # mother
         self.assertEqual(gts[1], 2)  # father
         self.assertEqual(gts[2], 2)  # Sasha
         self.assertEqual(gts[3], 4)  # Dasha
         self.assertEqual(gts[4], 1)  # Lesha
         self.assertLessEqual(gts[5], 3)  # Lena
Exemplo n.º 15
0
    def test_mother_only_carrier(self):
        """Only the mother carries the variant. Father is unaffected."""
        variants = VariantsCollection([Variant(variant_id=1, chrom='chrX')],
                                      db='test')

        # X - Mother carrier, father not, affected daughter (cannot be, she needs 2 copies)
        groups = {
            "affected": ["Dasha"],
            "not_affected": ["Mother", "Father", "Sasha", "Lena", "Lesha"]
        }
        ss = SamplesSelection(self.F.samples, groups)
        genotypes = array([[2, 1, 1, 4, 1, 1]], dtype=DTYPE)
        var = GenotypesFilterXLinked(ss).apply(variants, genotypes).variants
        self.assertEqual(len(var), 0)

        # V - Mother carrier, father not, affected son carrier het
        groups = {
            "affected": ["Sasha"],
            "not_affected": ["Mother", "Father", "Dasha", "Lena", "Lesha"]
        }
        ss = SamplesSelection(self.F.samples, groups)
        genotypes = array([[2, 1, 2, 1, 1, 1]], dtype=DTYPE)
        var = GenotypesFilterXLinked(ss).apply(variants, genotypes).variants
        self.assertEqual(len(var), 1)
Exemplo n.º 16
0
    def test_father_only_carrier(self):
        """Only the father carries the variant - so he is affected."""
        variants = VariantsCollection([Variant(variant_id=1, chrom='chrX')],
                                      db='test')

        # X - Father carrier, mother not, daughter affected
        groups = {
            "affected": ["Father", "Dasha"],
            "not_affected": ["Mother", "Sasha", "Lena", "Lesha"]
        }
        ss = SamplesSelection(self.F.samples, groups)
        genotypes = array([[1, 2, 1, 4, 1, 1]], dtype=DTYPE)
        var = GenotypesFilterXLinked(ss).apply(variants, genotypes).variants
        self.assertEqual(len(var), 0)

        # X - Father carrier, mother not, son affected
        groups = {
            "affected": ["Father", "Sasha"],
            "not_affected": ["Mother", "Dasha", "Lena", "Lesha"]
        }
        ss = SamplesSelection(self.F.samples, groups)
        genotypes = array([[1, 2, 2, 1, 1, 1]], dtype=DTYPE)
        var = GenotypesFilterXLinked(ss).apply(variants, genotypes).variants
        self.assertEqual(len(var), 0)