Ejemplo n.º 1
0
    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])
Ejemplo n.º 2
0
 def test_should_allow_multiple_samples_for_add_sample_data(self):
     sample_data = SampleData(['genotype_key1'],
                              ['sample_name1', 'sample_name2'])
     sample_data.add_sample_data('sample_name1', 'genotype_key1', [1])
     sample_data.add_sample_data('sample_name2', 'genotype_key1', [3, 4])
     self.assertEqual(
         sample_data.get_field('sample_name1', 'genotype_key1'), [1])
     self.assertEqual(
         sample_data.get_field('sample_name2', 'genotype_key1'), [3, 4])
Ejemplo n.º 3
0
 def test_default_values_are_assigned_when_sample_data_is_constructed(self):
     sample_data = SampleData(['GT', 'key1', 'key2'],
                              ['sample_name1', 'sample_name2'])
     self.assertEqual(sample_data.get_field('sample_name1', 'GT'),
                      GenotypeCall("./."))
     self.assertEqual(sample_data.get_field('sample_name2', 'GT'),
                      GenotypeCall("./."))
     self.assertEqual(sample_data.get_field('sample_name1', 'key1'), [])
     self.assertEqual(sample_data.get_field('sample_name2', 'key1'), [])
     self.assertEqual(sample_data.get_field('sample_name1', 'key2'), [])
     self.assertEqual(sample_data.get_field('sample_name2', 'key2'), [])
Ejemplo n.º 4
0
 def test_sample_data_copes_with_mixed_missing_values_in_PL(self):
     sample_name = 'sample_name'
     sample_data = SampleData(['PL'], [sample_name])
     sample_data.set_genotype_likelihoods(sample_name,
                                          [-0.1, '.', -0.2, None, -0.3])
     self.assertEqual(sample_data.get_field(sample_name, 'PL'),
                      [1.0, None, 2.0, None, 3.0])
Ejemplo n.º 5
0
    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'], [])
Ejemplo n.º 6
0
    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"))
Ejemplo n.º 7
0
 def test_should_add_sample_data(self):
     sample_data = SampleData(['genotype_key1'], ['sample_name'])
     sample_data.add_sample_data('sample_name', 'genotype_key1', [1])
     self.assertEqual(sample_data.get_field('sample_name', 'genotype_key1'),
                      [1])
Ejemplo n.º 8
0
 def test_gets_dot_if_key_is_PL(self):
     sample_name = 'sample_name'
     sample_data = SampleData(['PL'], [sample_name])
     sample_data.set_genotype_likelihoods(sample_name, '.')
     self.assertEqual(sample_data.get_field(sample_name, 'PL'), '.')
Ejemplo n.º 9
0
 def test_gets_exact_values_if_key_is_PL(self):
     sample_name = 'sample_name'
     sample_data = SampleData(['PL'], [sample_name])
     sample_data.set_genotype_likelihoods(sample_name, [-0.1, -0.2, -0.3])
     self.assertEqual(sample_data.get_field(sample_name, 'PL'), [1, 2, 3])
Ejemplo n.º 10
0
 def test_genotype_field_default_value_is_assigned_when_sample_data_is_constructed(
         self):
     sample_data = SampleData(['GT'], ['sample_name'])
     self.assertEqual(sample_data.get_field('sample_name', 'GT'),
                      GenotypeCall("./."))
Ejemplo n.º 11
0
 def test_default_field_value_is_assigned_when_sample_data_is_constructed(
         self):
     sample_data = SampleData(['key1'], ['sample_name'])
     self.assertEqual(sample_data.get_field('sample_name', 'key1'), [])