Skip to content

Commit

Permalink
fix: empty lineages can be uncompressed
Browse files Browse the repository at this point in the history
  • Loading branch information
corneliusroemer committed Jun 2, 2022
1 parent 9c6d943 commit 1fbeb4e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
13 changes: 13 additions & 0 deletions src/pango_aliasor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## Testing

Run `pytest` from the project root to run all tests.

## Release

```bash
pip install build
python -m build --sdist --outdir dist .
pip install twine
rm -rf dist
twine upload dist/*
```
7 changes: 5 additions & 2 deletions src/pango_aliasor/aliasor.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def compress(self,name):
name_split = name.split('.')
levels = len(name_split) - 1
num_indirections = (levels -1) // 3
if num_indirections == 0:
if num_indirections <= 0:
return name
alias = ".".join(name_split[0:(3*num_indirections + 1)])
ending = ".".join(name_split[(3*num_indirections + 1):])
Expand All @@ -38,7 +38,10 @@ def compress(self,name):
def uncompress(self,name):
name_split = name.split('.')
letter = name_split[0]
unaliased = self.alias_dict[letter]
try:
unaliased = self.alias_dict[letter]
except KeyError:
return name
if len(name_split) == 1:
return name
if len(name_split) == 2:
Expand Down
4 changes: 4 additions & 0 deletions tests/test_aliasor.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ def test_uncompression():
assert aliasor.uncompress('AY.4') == 'B.1.617.2.4'
assert aliasor.uncompress('AY.4.3.2') == 'B.1.617.2.4.3.2'
assert aliasor.uncompress('B.1') == 'B.1'
assert aliasor.uncompress('B') == 'B'
assert aliasor.uncompress('') == ''

def test_compression():
aliasor = Aliasor()
Expand All @@ -17,6 +19,8 @@ def test_compression():
assert aliasor.compress('B.1.617.2.4.3.1') == 'AY.4.3.1'
assert aliasor.compress('B.1.617.2') == 'B.1.617.2'
assert aliasor.compress('B.1') == 'B.1'
assert aliasor.compress('B') == 'B'
assert aliasor.compress('') == ''

def test_except_recombinants():
aliasor = Aliasor()
Expand Down

0 comments on commit 1fbeb4e

Please sign in to comment.