Skip to content

Commit

Permalink
ex-264 (cgates\dkriti) modifying how jacquard tags work
Browse files Browse the repository at this point in the history
  • Loading branch information
dkriti committed May 22, 2015
1 parent 45be6dd commit ece8f5d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
16 changes: 15 additions & 1 deletion jacquard/variant_caller_transforms/common_tags.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Common tags used by several callers."""
from __future__ import print_function, absolute_import, division
import abc
from abc import abstractmethod

CALLER_REPORTED_TAG = "CALLER_REPORTED"
CALLER_PASSED_TAG = "CALLER_PASSED"
Expand All @@ -9,6 +10,9 @@
class JacquardTag(object):
__metaclass__ = abc.ABCMeta

FORMAT = ('##FORMAT=<ID=JQ_{}_{},Number={},'
'Type={},Description="{}">')

class _TagType(object):
def __init__(self, abbreviation, vcf_type, vcf_number):
self.abbreviation = abbreviation
Expand All @@ -17,8 +21,18 @@ def __init__(self, abbreviation, vcf_type, vcf_number):

DEPTH_TAG = _TagType("DP", "Integer", "1")
GENOTYPE_TAG = _TagType("GT", "String", "A")

ALLELE_FREQ_TAG = _TagType("AF", "String", "A")
SOMATIC_TAG = _TagType("HC_SOM", "Integer", "1")

def __init__(self, variant_caller_abbrev, tag_type, description):
self.metaheader = JacquardTag.FORMAT.format(variant_caller_abbrev,
tag_type.abbreviation,
tag_type.vcf_number,
tag_type.vcf_type,
description)

@abstractmethod
def add_tag_values(self):
pass


Expand Down
26 changes: 24 additions & 2 deletions test/variant_caller_transforms/common_tags_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@


class JacquardTagTestCase(test_case.JacquardBaseTestCase):
def xtest_allele_freq_tag(self):
def test_allele_freq_tag(self):
tag = common_tags.JacquardTag.ALLELE_FREQ_TAG
self.assertEquals("AF", tag.abbreviation)
self.assertEquals("Float", tag.vcf_type)
self.assertEquals("String", tag.vcf_type)
self.assertEquals("A", tag.vcf_number)

def test_depth_tag(self):
Expand All @@ -25,6 +25,28 @@ def test_genotype_tag(self):
self.assertEquals("String", tag.vcf_type)
self.assertEquals("A", tag.vcf_number)

def test_somatic_tag(self):
tag = common_tags.JacquardTag.SOMATIC_TAG
self.assertEquals("HC_SOM", tag.abbreviation)
self.assertEquals("Integer", tag.vcf_type)
self.assertEquals("1", tag.vcf_number)

def test_add_tag_values_is_abstract(self):
try:
class FakeTag(common_tags.JacquardTag):
def __init__(self): pass
FakeTag()
self.fail("Should not be able to instantiate JacquardTag without overrideing abstract methods.")
except TypeError: pass

def test_metaheader(self):
tag_type = common_tags.JacquardTag.GENOTYPE_TAG
class MyTag(common_tags.JacquardTag):
def add_tag_values(self, vcf_record): pass
actual_tag = MyTag("SK", tag_type, "foo bar baz")
expected_metaheader = '##FORMAT=<ID=JQ_SK_GT,Number=A,Type=String,Description="foo bar baz">'
self.assertEquals(expected_metaheader, actual_tag.metaheader)

class ReportedTagTestCase(test_case.JacquardBaseTestCase):
def test_reported_tag_metaheader(self):
reported_tag = common_tags.ReportedTag("foo_")
Expand Down

0 comments on commit ece8f5d

Please sign in to comment.