Skip to content

Commit

Permalink
ex-161 (jebene) initial work on metaheader sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
jebene committed Mar 30, 2015
1 parent 223595d commit 8fa782f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
13 changes: 13 additions & 0 deletions jacquard/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ def round_two_digits(val):
return val
return val

def sort_metaheaders(metaheaders):
metaheader_dict = {"##fileformat": 1,
"##jacquard": 2,
"##contig": 3,
"##ALT": 4,
"##FILTER": 5,
"##INFO": 6,
"##FORMAT": 7,
"#CHROM": 8}

#pylint: disable=line-too-long
return sorted(metaheaders, key=lambda metaheader: metaheader_dict[metaheader.split("=")[0].split(".")[0]])

class JQException(Exception):
"""Base class for all run-time exceptions in this module."""
def __init__(self, msg, *args):
Expand Down
18 changes: 18 additions & 0 deletions test/utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,24 @@ def test_init(self):
self.assertIsInstance(actual, Exception)
self.assertEquals(actual.message, "msg:bar, [1, 2, 3]")

class SortMetaheadersTestCase(test_case.JacquardBaseTestCase):
def test_sort_metaheaders(self):
unsorted = ["##FORMAT", "##fileformat", "##INFO", "##jacquard.foo="]
actual = utils.sort_metaheaders(unsorted)
expected = ["##fileformat", "##jacquard.foo=", "##INFO", "##FORMAT"]
self.assertEquals(expected, actual)

def test_sort_metaheaders_completeList(self):
unsorted = ["##FORMAT", "##fileformat", "##INFO", "##jacquard.foo=", "##ALT", "#CHROM", "##contig", "##FILTER"]
actual = utils.sort_metaheaders(unsorted)
expected = ["##fileformat", "##jacquard.foo=", "##contig", "##ALT", "##FILTER", "##INFO", "##FORMAT", "#CHROM"]
self.assertEquals(expected, actual)

def xtest_sort_metaheaders_sortsWithinCategory(self):
unsorted = ["##FORMAT=DP", "##FORMAT=AF", "##jacquard.bar="]
actual = utils.sort_metaheaders(unsorted)
expected = ["##jacquard.bar=", "##FORMAT=AF", "##FORMAT=DP"]
self.assertEquals(expected, actual)

class NaturalSortTestCase(test_case.JacquardBaseTestCase):
def test_natsort(self):
Expand Down

0 comments on commit 8fa782f

Please sign in to comment.