Skip to content

Commit

Permalink
Merge pull request #10 from corneliusroemer/add-parent-function
Browse files Browse the repository at this point in the history
Add `aliasor.parent(lineage)` method to get (compressed) parent lineage name
  • Loading branch information
corneliusroemer committed Feb 10, 2023
2 parents 21f30f2 + 147f8ce commit d4cc480
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# CHANGELOG

## 0.3.0 (2023-02-10)

- Add `aliasor.parent(lineage)` method to get (compressed) parent lineage name
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ aliasor.uncompress("XA") # 'XA'
# Go from unaliased lineage to aliased lineage
aliasor.compress("B.1.1.529.3.1") # 'BA.3.1'

# Find parent lineage
aliasor.parent("BQ.1") # 'BE.1.1.1'

aliasor.partial_compress("B.1.1.529.3.1",up_to=1) # 'BA.3.1'
aliasor.partial_compress("B.1.1.529.3.1.1.2",up_to=1) # 'BA.3.1.1.2'

Expand Down
3 changes: 2 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = pango_aliasor
version = 0.2.2
version = 0.3.0
description = Pango lineage aliasing and dealiasing
long_description = file: README.md
long_description_content_type = text/markdown
Expand All @@ -15,6 +15,7 @@ classifiers =
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Programming Language :: Python :: 3.11
Bug Tracker = https://github.com/corneliusroemer/pango_aliasor/issues
License = : OSI Approved :: MIT License
Operating System = : OS Independent
Expand Down
6 changes: 6 additions & 0 deletions src/pango_aliasor/aliasor.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ def uncompress(self, name):
else:
return unaliased + "." + ".".join(name_split[1:])

def parent(self, name):
"""
Returns parent lineage in aliased format or '' if at top level
"""
return self.compress(".".join(self.uncompress(name).split(".")[:-1]))

def partial_compress(self, name, up_to: int = 0, accepted_aliases: set = {}):
"""
aliasor.partial_compress("B.1.1.529.3.1",up_to=1) # 'BA.3.1'
Expand Down
12 changes: 11 additions & 1 deletion tests/test_aliasor.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,14 @@ def test_partial_alias_combination():
assert aliasor.partial_compress('B.1.617.2.3',up_to=1, accepted_aliases={"BA","AZ"}) == "AY.3"
assert aliasor.partial_compress('B.1.1.529.2.75.1.2',up_to=3, accepted_aliases={"BA"}) == 'BL.2'
assert aliasor.partial_compress('B.1.1.529.2.75.1.2',up_to=4, accepted_aliases={"BA"}) == 'BL.2'
assert aliasor.partial_compress('B.1.1.529.2.75.1.2',up_to=1, accepted_aliases={"BA"}) == 'BA.2.75.1.2'
assert aliasor.partial_compress('B.1.1.529.2.75.1.2',up_to=1, accepted_aliases={"BA"}) == 'BA.2.75.1.2'

def test_parent():
aliasor = Aliasor()
assert aliasor.parent('B.1.1.529.1') == 'B.1.1.529'
assert aliasor.parent('BQ.1') == 'BE.1.1.1'
assert aliasor.parent('XAA') == ''
assert aliasor.parent('') == ''
assert aliasor.parent('A') == ''
assert aliasor.parent('B') == ''
assert aliasor.parent('C.1') == 'B.1.1.1'

0 comments on commit d4cc480

Please sign in to comment.