def test_read_sample_data(self): schema = self.__get_example_schema("vcf_example.vcf") sample_schema = [key for key, _ in schema.iter_sample_data()] sample_data = SampleData(sample_schema, ['sample1']) sample_data.add_sample_data("sample1", "GT", GenotypeCall("1|0")) sample_data.add_sample_data("sample1", "PL", [3000, 0, 3000]) sample_data.add_sample_data("sample1", "GQ", [1000]) sample_data.add_sample_data("sample1", "PQ", [2000]) sample_data.add_sample_data("sample1", "PS", [60000]) sample_data.add_sample_data("sample1", "AD", [140, 110]) sample_data.add_sample_data("sample1", "DP", [250]) sample_data.add_sample_data("sample1", "VAF", [0.4]) self.assertTrue(sample_data.has_sample("sample1")) self.assertEqual(sample_data.genotypes(), {"sample1": GenotypeCall("1|0")}) self.assertEqual(sample_data.get_field("sample1", 'GT'), GenotypeCall("1|0")) self.assertEqual(sample_data.get_field("sample1", 'PL'), [3000, 0, 3000]) genotype_data = sample_data.get_genotype_data("sample1") self.assertEqual(genotype_data.genotype(), GenotypeCall("1|0")) self.assertEqual(genotype_data['GT'], GenotypeCall("1|0")) self.assertEqual(genotype_data['PL'], [3000, 0, 3000])
def test_should_merge_genotype_call_object_in_sample_data(self): sample_data1 = SampleData(['GT'], ['sample_name']) sample_data1.add_sample_data('sample_name', 'GT', GenotypeCall('0/1')) sample_data2 = SampleData(['GT'], ['sample_name']) sample_data2.add_sample_data('sample_name', 'GT', GenotypeCall('0/1')) sample_data1.merge_genotype_calls(sample_data2.genotypes()) self.assertEqual(sample_data1.get_field("sample_name", "GT"), GenotypeCall("1/1"))
def test_should_fail_if_sample_data_objects_have_different_sample(self): sample_data1 = SampleData(['GT'], ['sample_name_1']) sample_data1.add_sample_data('sample_name_1', 'GT', GenotypeCall('0/0')) sample_data2 = SampleData(['GT'], ['sample_name_2']) sample_data2.add_sample_data('sample_name_2', 'GT', GenotypeCall('0/0')) self.assertRaises(Exception, sample_data1.merge_genotype_calls, sample_data2.genotypes())
def test_should_return_default_diploid_genotype(self): sample_data = SampleData(['GT', 'GL'], ["NA12878"]) self.assertEqual(GenotypeCall("./."), GenotypeCall("./.")) self.assertTrue(sample_data.has_sample("NA12878")) self.assertEqual(sample_data.genotypes(), {"NA12878": GenotypeCall("./.")}) self.assertEqual(sample_data.get_field("NA12878", 'GT'), GenotypeCall("./.")) self.assertEqual(sample_data.get_field("NA12878", 'GL'), []) genotype_data = sample_data.get_genotype_data("NA12878") self.assertEqual(genotype_data.genotype(), GenotypeCall("./.")) self.assertEqual(genotype_data['GT'], GenotypeCall("./.")) self.assertEqual(genotype_data['GL'], [])