-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9be20f2
Showing
6 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
__pycache__/ | ||
*.egg-info/ | ||
.pytest_cache/ | ||
dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[build-system] | ||
build-backend = 'setuptools.build_meta' | ||
requires = ['setuptools >= 43.0.0'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
[metadata] | ||
name = pango_aliasor | ||
version = 0.0.1 | ||
author = Cornelius Roemer | ||
author_email = [email protected] | ||
description = Pango lineage aliasing and dealiasing | ||
url = https://github.com/corneliusroemer/pango_aliasor | ||
# project_urls = | ||
# Bug Tracker = https://github.com/pypa/sampleproject/issues | ||
classifiers = | ||
Programming Language :: Python :: 3 | ||
Operating System :: OS Independent | ||
|
||
[options] | ||
package_dir = | ||
= src | ||
packages = find: | ||
python_requires = >=3.7 | ||
|
||
[options.packages.find] | ||
where = src |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#%% | ||
class Aliasor: | ||
def __init__(self, alias_file=None): | ||
import pandas as pd | ||
|
||
if alias_file is None: | ||
import importlib.resources | ||
|
||
with importlib.resources.open_text("pango_designation", "alias_key.json") as file: | ||
aliases = pd.read_json(file) | ||
|
||
else: | ||
aliases = pd.read_json(alias_file) | ||
|
||
self.alias_dict = {} | ||
for column in aliases.columns: | ||
if column.startswith('X'): | ||
self.alias_dict[column] = column | ||
else: | ||
self.alias_dict[column] = aliases[column][0] | ||
|
||
self.alias_dict['A'] = 'A' | ||
self.alias_dict['B'] = 'B' | ||
|
||
self.realias_dict = {v: k for k, v in self.alias_dict.items()} | ||
|
||
def compress(self,name): | ||
name_split = name.split('.') | ||
if len(name_split) < 5: | ||
return name | ||
letter = self.realias_dict[".".join(name_split[0:4])] | ||
if len(name_split) == 5: | ||
return letter + '.' + name_split[4] | ||
else: | ||
return letter + '.' + ".".join(name_split[4:]) | ||
|
||
def uncompress(self,name): | ||
name_split = name.split('.') | ||
letter = name_split[0] | ||
unaliased = self.alias_dict[letter] | ||
if len(name_split) == 1: | ||
return name | ||
if len(name_split) == 2: | ||
return unaliased + '.' + name_split[1] | ||
else: | ||
return unaliased + '.' + ".".join(name_split[1:]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from pango_aliasor.aliasor import Aliasor | ||
|
||
def test_pango_designation_init(): | ||
aliasor = Aliasor() | ||
|
||
def test_decompression(): | ||
aliasor = Aliasor() | ||
assert aliasor.uncompress('BA.1') == 'B.1.1.529.1' | ||
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' | ||
|
||
def test_compression(): | ||
aliasor = Aliasor() | ||
assert aliasor.compress('B.1.1.529.1') == 'BA.1' | ||
assert aliasor.compress('B.1.617.2.4') == 'AY.4' | ||
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' | ||
|
||
def test_except_recombinants(): | ||
aliasor = Aliasor() | ||
assert aliasor.uncompress('XA.1') == 'XA.1' | ||
assert aliasor.compress('XA.1') == 'XA.1' |