def test_add_new_call_set(self): vcf = VCF(f="tests/vcf_tests/test.vcf", reference_set_id=self.reference_set.id, method="CORTEX") vcf.add_to_database() # Only one callset but the callset should belong to multiple variant # sets assert VariantCallSet.objects().count() == 1 assert VariantCallSet.objects()[0].created_at <= datetime.datetime.now( ) assert len(VariantCallSet.objects()[0].variant_sets) == 2
def setup(self): DB.drop_database('mykrobe-test') self.reference_set = ReferenceSet().create_and_save(name="ref_set") self.variant_set = VariantSet.create_and_save( name="this_vcf_file2", reference_set=self.reference_set) self.variant_sets = [self.variant_set] self.reference = Reference().create_and_save( name="ref", md5checksum="sre", reference_sets=[self.reference_set]) self.call_set = VariantCallSet.create(sample_id="C00123", name="C00123", variant_sets=self.variant_sets) self.variant_snp = Variant.create(variant_sets=self.variant_sets, start=0, end=1, reference_bases="A", alternate_bases=["T"], reference=self.reference) self.variant_snp_mult_alts = Variant.create( variant_sets=self.variant_sets, start=0, end=1, reference_bases="T", alternate_bases=["A", "C"], reference=self.reference)
def test_create_call_set(self): call_set = VariantCallSet.create_and_save( name="call_set", sample_id="C00123", variant_sets=self.variant_sets) cs = VariantCallSet.objects.get(name="call_set") assert call_set == cs assert cs.name == "call_set" assert cs.variant_sets[0].reference_set.name == "ref_set"
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
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_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
def _create_call_sets(self): for sample in self.vcf_reader.samples: try: cs = VariantCallSet.create_and_save( name="_".join([sample, self.method]), variant_sets=self.variant_sets, sample_id=sample, info={"variant_caller": self.method}, ) except NotUniqueError: raise ValueError( "There is already a call set for sample %s with method %s " % (sample, self.method)) else: self.call_sets[sample] = cs