Esempio n. 1
0
 def _remove_variant_set(self, variant_set_name):
     vs = VariantSet.objects.get(name=variant_set_name,
                                 reference_set=self.reference_set)
     for call_set in VariantCallSet.objects(variant_sets=vs):
         call_set.variant_sets.remove(vs)
         call_set.save()
         # Remove calls from callsets that only have this variantset
         if len(call_set.variant_sets) < 2:
             VariantCall.objects(call_set=call_set).delete()
             call_set.delete()
     # Remove variants that are ONLY from this variant set
     Variant.objects(variant_sets=vs, variant_sets__size=2).delete()
     VariantSetMetadata.objects(variant_set=vs).delete()
     vs.delete()
 def test_add_add_variants_and_calls(self):
     vcf = VCF(f="tests/vcf_tests/test.vcf",
               reference_set_id=self.reference_set.id,
               method="CORTEX")
     vcf.add_to_database()
     assert VariantCall.objects().count() == 21
     assert Variant.objects().count() == 21
Esempio n. 3
0
    def test_create_SNP_het_call(self):
        c1 = VariantCall.create(variant=self.variant_snp,
                                call_set=self.call_set,
                                genotype=[0, 1],
                                genotype_likelihoods=[0.1, 0.9, 0.12])
        assert c1.call_set_name == "C00123"
        assert c1.genotype == [0, 1]
        self.variant_snp.save()
        c1.save()
        assert c1 in self.variant_snp.calls

        c2 = VariantCall.create(variant=self.variant_snp,
                                call_set=self.call_set,
                                genotype="1/1",
                                genotype_likelihoods=[0.01, 0.1, 0.9])
        assert c2.call_set_name == "C00123"
        assert c2.genotype == [1, 1]

        c2.save()
        assert c2 in self.variant_snp.calls
Esempio n. 4
0
    def test_create_SNP_het_call(self):
        c1 = VariantCall.create(variant=self.variant_snp,
                                call_set=self.call_set,
                                genotype=[0, 1],
                                genotype_likelihoods=[0.1, 0.9, 0.12])
        assert c1.call_set_name == "C00123"
        assert c1.genotype == [0, 1]
        self.variant_snp.save()
        c1.save()
        assert c1 in self.variant_snp.calls

        c2 = VariantCall.create(variant=self.variant_snp,
                                call_set=self.call_set,
                                genotype="1/1",
                                genotype_likelihoods=[0.01, 0.1, 0.9])
        assert c2.call_set_name == "C00123"
        assert c2.genotype == [1, 1]

        c2.save()
        assert c2 in self.variant_snp.calls
Esempio n. 5
0
 def _create_call_sets(self):
     try:
         self.call_set = VariantCallSet.create_and_save(
             name=self.call_set_name,
             variant_sets=[self.global_variant_set],
             sample_id=self.sample,
             info={"variant_caller": self.method})
     except NotUniqueError:
         if self.force:
             # logger.info("There is already a call set for sample %s with method %s but add has been called with --force so this callset is being removed from the DB" %
             #     (self.sample, self.method))
             cs = VariantCallSet.objects.get(
                 name="_".join([self.sample, self.method]))
             VariantCall.objects(call_set=cs).delete()
             cs.delete()
             self._create_call_sets()
         else:
             raise ValueError(
                 "There is already a call set for sample %s with method %s "
                 % (self.sample, self.method))
Esempio n. 6
0
 def test_create_complex_call(self):
     c1 = VariantCall.create(
         variant=self.variant_snp_mult_alts,
         call_set=self.call_set,
         genotype="2/1",
         genotype_likelihoods=[0.01, 0.1, 0.9, 0.1, 0.2, 0.6])
     self.variant_snp.save()
     self.variant_snp_mult_alts.save()
     c1.save()
     assert c1.call_set_name == "C00123"
     assert c1.genotype == [2, 1]
     assert c1 not in self.variant_snp.calls
     assert c1 in self.variant_snp_mult_alts.calls
Esempio n. 7
0
    def _create_variants_and_calls(self):
        for record in self.vcf_reader:
            if not record.FILTER and self._is_record_valid(record):
                v = self._get_or_create_variant(record)
                for call in record.samples:
                    genotype_likelihoods = self._get_genotype_likelihoods(call)
                    c = VariantCall.create(
                        variant=v,
                        call_set=self.call_sets[call.sample],
                        genotype=call['GT'],
                        genotype_likelihoods=genotype_likelihoods)
                    self.calls.append(c)

        VariantCall.objects.insert(self.calls)
Esempio n. 8
0
 def _create_calls(self):
     calls = []
     for var_hash, call in self.data["variant_calls"].items():
         if sum(call["genotype"]) > 0:
             var_hash = var_hash[:64]
             v = Variant.objects.get(var_hash=var_hash)
             c = VariantCall.create(
                 variant=v,
                 call_set=self.call_set,
                 genotype=call["genotype"],
                 genotype_likelihoods=call["genotype_likelihoods"],
                 info=call["info"])
             calls.append(c)
     VariantCall.objects.insert(calls)
 def test_add_second_vcf_variant_set(self):
     # This VCF only has one Variant which is not in the first VCF
     vcf = VCF(f="tests/vcf_tests/test2.vcf",
               reference_set_id=self.reference_set.id,
               method="CORTEX")
     vcf.add_to_database()
     assert VariantSet.objects().count() == 3
     assert VariantCallSet.objects().count() == 2
     assert VariantCall.objects().count() == 42
     assert Variant.objects().count() == 22
     assert len(Variant.objects()[0].variant_sets) == 3
     assert len(
         Variant.objects.get(
             names="UNION_BC_k31_var_147").variant_sets) == 3
Esempio n. 10
0
 def test_add_second_vcf_variant_set(self):
     # This VCF only has one Variant which is not in the first VCF
     vcf = VCF(f="tests/vcf_tests/test3.vcf",
               reference_set_id=self.reference_set.id,
               method="CORTEX")
     vcf.add_to_database()
     assert VariantSet.objects().count() == 2
     assert VariantCallSet.objects().count() == 1
     assert VariantCall.objects().count() == 106
     assert Variant.objects().count() == 106
     assert Variant.snps().count() == 89
     assert Variant.indels().count() == 17
     assert Variant.insertions().count() == 8
     assert Variant.deletions().count() == 8
     assert Variant.ph_snps.count() == 1
Esempio n. 11
0
 def test_create_complex_call(self):
     c1 = VariantCall.create(
         variant=self.variant_snp_mult_alts,
         call_set=self.call_set,
         genotype="2/1",
         genotype_likelihoods=[
             0.01,
             0.1,
             0.9,
             0.1,
             0.2,
             0.6])
     self.variant_snp.save()
     self.variant_snp_mult_alts.save()
     c1.save()
     assert c1.call_set_name == "C00123"
     assert c1.genotype == [2, 1]
     assert c1 not in self.variant_snp.calls
     assert c1 in self.variant_snp_mult_alts.calls