Skip to content

Commit

Permalink
Fix bug in designation_helper.py when there are no children
Browse files Browse the repository at this point in the history
  • Loading branch information
corneliusroemer committed Apr 4, 2023
1 parent 9ac4960 commit 7f8ba07
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions utils/designation_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
- Add alias json if necessary
"""

import typer
import numpy as np
import pandas as pd
import typer
from pango_aliasor.aliasor import Aliasor
import numpy as np

LINEAGE_NOTES = "lineage_notes.txt"
LINEAGES_CSV = "lineages.csv"
Expand Down Expand Up @@ -110,16 +110,18 @@ def get_lineage_from_parent(parent_lineage: str):
unaliased_parent = aliasor.uncompress(parent_lineage)

# Filter to lineages descending from parent lineage
children=unaliased[np.vectorize(lambda x: x.startswith(unaliased_parent))(unaliased)]
children=unaliased[np.vectorize(lambda x: x.startswith(unaliased_parent + "."))(unaliased)]

# Find number of levels of parent lineage
parent_levels = unaliased_parent.count(".") + 1

# Find numbers of level below parent lineage
children_levels = np.vectorize(lambda x: extract_level(x, parent_levels))(children)

# Find last entry of 1 level below parent lineage
max_child = max(children_levels)
if len(children) == 0:
max_child = 0
else:
children_levels = np.vectorize(lambda x: extract_level(x, parent_levels))(children)
# Find last entry of 1 level below parent lineage
max_child = max(children_levels)

# Create compressd child
new_child_unaliased = f"{unaliased_parent}.{max_child+1}"
Expand Down

0 comments on commit 7f8ba07

Please sign in to comment.