def setUp(self):
     """ define a family and variant, and start the Allosomal class
     """
     
     # generate a test family
     child_gender = "F"
     mom_aff = "1"
     dad_aff = "1"
     
     self.trio = self.create_family(child_gender, mom_aff, dad_aff)
     
     # generate a test variant
     child_var = self.create_snv(child_gender, "0/1")
     mom_var = self.create_snv("F", "0/0")
     dad_var = self.create_snv("M", "0/0")
     
     var = TrioGenotypes(child_var)
     var.add_mother_variant(mom_var)
     var.add_father_variant(dad_var)
     self.variants = [var]
     
     # make sure we've got known genes data
     self.known_genes = {"TEST": {"inh": ["Monoallelic"], "confirmed_status": ["Confirmed DD Gene"]}}
     
     self.inh = Allosomal(self.variants, self.trio, self.known_genes, "TEST")
     self.inh.is_lof = var.child.is_lof()
Exemplo n.º 2
0
    def setUp(self):
        """ define a family and variant, and start the Allosomal class
        """

        # generate a test family
        child_gender = "F"
        mom_aff = "1"
        dad_aff = "1"

        self.trio = self.create_family(child_gender, mom_aff, dad_aff)

        # generate a test variant
        child = create_snv(child_gender, "0/1")
        mom = create_snv("F", "0/0")
        dad = create_snv("M", "0/0")

        var = TrioGenotypes(child.get_chrom(), child.get_position(), child,
                            mom, dad)
        self.variants = [var]

        # make sure we've got known genes data
        self.known_gene = {
            "inh": ["Monoallelic"],
            "confirmed_status": ["confirmed dd gene"]
        }

        self.inh = Allosomal(self.variants, self.trio, self.known_gene, "1001")
        self.inh.is_lof = var.child.is_lof()
Exemplo n.º 3
0
    def test_check_homozygous_male(self):
        """ test that check_homozygous() works correctly for males
        """

        # check for trio with de novo on male X chrom
        var = TrioGenotypes('X', 100, create_snv('M', "1/1"),
                            create_snv('F', "0/0"), create_snv('M', "0/0"))

        trio = self.create_family('male', '1', '1')
        self.inh = Allosomal([var], trio, self.known_gene, "TEST")
        self.inh.set_trio_genotypes(var)

        self.assertEqual(self.inh.check_homozygous("X-linked dominant"),
                         "single_variant")
        self.assertEqual(self.inh.log_string, "male X chrom de novo")

        # check for trio = 210, with unaffected mother
        var = TrioGenotypes('X', 100, create_snv('M', "1/1"),
                            create_snv('F', "1/0"), create_snv('M', "0/0"))
        self.inh.set_trio_genotypes(var)

        self.assertEqual(self.inh.check_homozygous("X-linked dominant"),
                         "single_variant")
        self.assertEqual(
            self.inh.log_string,
            "male X chrom inherited from het mother or hom affected mother")

        # check for trio = 210, with affected mother, which should also pass
        self.inh.mother_affected = True
        self.assertEqual(self.inh.check_homozygous("X-linked dominant"),
                         "single_variant")
        self.assertEqual(
            self.inh.log_string,
            "male X chrom inherited from het mother or hom affected mother")

        # check for trio = 220, with affected mother
        var = TrioGenotypes('X', 100, create_snv('M', "1/1"),
                            create_snv('F', "1/1"), create_snv('M', "0/0"))
        self.inh.set_trio_genotypes(var)
        self.assertEqual(self.inh.check_homozygous("X-linked dominant"),
                         "single_variant")
        self.assertEqual(
            self.inh.log_string,
            "male X chrom inherited from het mother or hom affected mother")

        # check for trio = 220, with unaffected mother, which should not pass
        self.inh.mother_affected = False
        self.assertEqual(self.inh.check_homozygous("X-linked dominant"),
                         "nothing")
        self.assertEqual(self.inh.log_string,
                         "variant not compatible with being causal")

        # check that homozygous X-linked over-dominance doesn't pass
        self.assertEqual(self.inh.check_homozygous("X-linked over-dominance"),
                         'nothing')

        # check we raise errors with unknown inheritance modes
        with self.assertRaises(ValueError):
            self.inh.check_homozygous("Digenic")
Exemplo n.º 4
0
    def find_variants(self, variants, gene):
        """ finds variants that fit inheritance models
        
        Args:
            variants: list of TrioGenotype objects
            gene: gene ID as string
        
        Returns:
            list of variants that pass inheritance checks
        """

        # get the inheritance for the gene (monoalleleic, biallelic, hemizygous
        # etc), but allow for times when we haven't specified a list of genes
        # to use
        gene_inh = None
        if self.known_genes is not None and gene in self.known_genes:
            gene_inh = self.known_genes[gene]["inh"]

        # If we are looking for variants in a set of known genes, and the gene
        # isn't part of that set, then we don't ant to examine the variant for
        # that gene, UNLESS the variant is a CNV, since CNVs can be included
        # purely from size thresholds, regardless of which gene they overlap.
        if self.known_genes is not None and gene not in self.known_genes:
            variants = [x for x in variants if x.is_cnv()]

        # ignore intergenic variants
        if gene is None:
            for var in variants:
                if var.get_chrom() == self.debug_chrom and var.get_position(
                ) == self.debug_pos:
                    print(var, "lacks HGNC/gene symbol")
            return []

        # Now that we are examining a single gene, check that the consequences
        # for the gene are in the required functional categories.
        variants = [
            var for var in variants
            if var.child.is_lof(gene) or var.child.is_missense(gene)
        ]
        if variants == []:
            return []

        logging.debug("{} {} {} {}".format(self.family.child.get_id(), gene,
                                           variants, gene_inh))
        chrom_inheritance = variants[0].get_inheritance_type()

        if chrom_inheritance == "autosomal":
            finder = Autosomal(variants, self.family, self.known_genes, gene,
                               self.cnv_regions)
        elif chrom_inheritance in ["XChrMale", "XChrFemale", "YChrMale"]:
            finder = Allosomal(variants, self.family, self.known_genes, gene,
                               self.cnv_regions)

        variants = finder.get_candidate_variants()
        variants = [(x[0], list(x[1]), list(x[2]), [gene]) for x in variants]

        return variants
Exemplo n.º 5
0
 def find_variants(self, variants, gene, family):
     """ finds variants that fit inheritance models
     
     Args:
         variants: list of TrioGenotype objects
         gene: gene ID as string
     
     Returns:
         list of variants that pass inheritance checks
     """
     
     # get the inheritance for the gene (monoalleleic, biallelic, hemizygous
     # etc), but allow for times when we haven't specified a list of genes
     # to use
     known_gene = None
     gene_inh = None
     if self.known_genes is not None and gene in self.known_genes:
         known_gene = self.known_genes[gene]
         gene_inh = known_gene['inh']
     
     chrom_inheritance = variants[0].get_inheritance_type()
     
     # If we are looking for variants in a set of known genes, and the gene
     # isn't part of that set, then we don't ant to examine the variant for
     # that gene, UNLESS the variant is a CNV, since CNVs can be included
     # purely from size thresholds, regardless of which gene they overlap.
     if self.known_genes is not None and gene not in self.known_genes:
         variants = [ x for x in variants if x.is_cnv() ]
     
     # ignore intergenic variants
     if gene is None:
         for var in variants:
             if var.get_chrom() == self.debug_chrom and var.get_position() == self.debug_pos:
                 print(var, "lacks HGNC/gene symbol")
         return []
     
     # Now that we are examining a single gene, check that the consequences
     # for the gene are in the required functional categories.
     variants = [ var for var in variants if var.child.is_lof(gene) or var.child.is_missense(var.child.is_cnv(), gene) ]
     if variants == []:
         return []
     
     for x in variants[0].child.info.symbols:
         try:
             symbol = x.get(gene, ['HGNC', 'SYMBOL', 'ENSG'])
             break
         except KeyError:
             continue
     logging.info("{}\t{}\tvariants: {}\trequired_mode: {}".format(
         family.child.get_id(), symbol, [str(x) for x in variants], gene_inh))
     
     if chrom_inheritance == "autosomal":
         finder = Autosomal(variants, family, known_gene, gene, self.cnv_regions)
     elif chrom_inheritance in ["XChrMale", "XChrFemale", "YChrMale"]:
         finder = Allosomal(variants, family, known_gene, gene, self.cnv_regions)
     
     return finder.get_candidate_variants()
Exemplo n.º 6
0
    def test_check_variant_without_parents_male(self):
        """ test that check_variant_without_parents() works correctly for males
        """

        var = TrioGenotypes('X', 100, create_snv('M', "1/1"), None, None)
        trio = self.create_family('male', '1', '1')

        self.inh = Allosomal([var], trio, self.known_gene, "TEST")
        self.inh.set_trio_genotypes(var)

        # check for X-linked dominant inheritance
        self.assertEqual(
            self.inh.check_variant_without_parents("X-linked dominant"),
            "single_variant")

        # and check for hemizygous inheritance
        self.assertEqual(self.inh.check_variant_without_parents("Hemizygous"),
                         "single_variant")
Exemplo n.º 7
0
    def test_check_compound_hets_allosomal(self):
        """ test that check_compound_hets() works correctly for allosomal vars
        """

        # set some X chrom variants, so we can alter them later
        var1 = self.create_variant("F", chrom="X", position="15000000")
        var2 = self.create_variant("F", chrom="X", position="16000000")

        # set the inheritance type, the compound het type ("hemizygous"
        # for allosomal variants, and start allosomal inheritance)
        inh = "Hemizygous"
        compound = "hemizygous"
        self.inh = Allosomal([var1, var2], self.trio, inh)

        variants = ["", ""]

        # check that de novo containing "110, 100" combos pass
        variants[0] = self.set_compound_het_var(var1, "110", compound)
        variants[1] = self.set_compound_het_var(var2, "100", compound)
        if IS_PYTHON3:
            self.assertCountEqual(self.inh.check_compound_hets(variants),
                                  variants)
        elif IS_PYTHON2:
            self.assertEqual(sorted(self.inh.check_compound_hets(variants)),
                             sorted(variants))

        # check that "110, 102" combo fails if the father is unaffected
        variants[0] = self.set_compound_het_var(var1, "110", compound)
        variants[1] = self.set_compound_het_var(var2, "102", compound)
        self.assertEqual(self.inh.check_compound_hets(variants), [])

        # check that "110, 102" combo passes if the father is affected
        self.inh.father_affected = True
        if IS_PYTHON3:
            self.assertCountEqual(self.inh.check_compound_hets(variants),
                                  variants)
        elif IS_PYTHON2:
            self.assertEqual(sorted(self.inh.check_compound_hets(variants)),
                             sorted(variants))

        # make sure we can't set the father as het on the X chrom
        with self.assertRaises(ValueError):
            self.set_compound_het_var(var2, "101", compound)
Exemplo n.º 8
0
    def find_variants(self, variants, gene):
        """ finds variants that fit inheritance models
        
        Args:
            variants: list of TrioGenotype objects
            gene: gene ID as string
        
        Returns:
            list of variants that pass inheritance checks
        """

        # get the inheritance for the gene (monoalleleic, biallelic, hemizygous
        # etc), but allow for times when we haven't specified a list of genes
        # to use
        gene_inh = None
        if self.known_genes is not None and gene in self.known_genes:
            gene_inh = self.known_genes[gene]["inh"]

        # ignore intergenic variants
        if gene is None:
            for var in variants:
                if var.get_chrom() == self.debug_chrom and var.get_position(
                ) == self.debug_pos:
                    print(var, "lacks HGNC/gene symbol")
            return []

        logging.debug(self.family.child.get_id() + " " + gene + " " + \
            str(variants) + " " + str(gene_inh))
        chrom_inheritance = variants[0].get_inheritance_type()

        if chrom_inheritance == "autosomal":
            finder = Autosomal(variants, self.family, self.known_genes,
                               gene_inh, self.cnv_regions)
        elif chrom_inheritance in ["XChrMale", "XChrFemale", "YChrMale"]:
            finder = Allosomal(variants, self.family, self.known_genes,
                               gene_inh, self.cnv_regions)

        return finder.get_candidate_variants()