Skip to content

Commit

Permalink
Add edge case to test
Browse files Browse the repository at this point in the history
  • Loading branch information
corneliusroemer committed Oct 18, 2024
1 parent f480d67 commit 03221f2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
10 changes: 9 additions & 1 deletion ena-submission/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,17 @@ requires-python = ">=3.12"
[project.scripts]
ena_deposition = "ena_deposition.__main__:run"

[project.optional-dependencies]
test = [
"types-pytz",
"types-xmltodict",
"types-requests",
"types-PyYAML",
]

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.hatch.build.targets.wheel]
packages = ["src/ena_deposition"]
packages = ["src/ena_deposition"]
4 changes: 2 additions & 2 deletions ena-submission/scripts/test_ena_submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,9 @@ def setUp(self):
self.seq_key = {"accession": "test_accession", "version": "test_version"}

def test_format_authors(self):
authors = "Xi,L.;Smith, Anna Maria; Perez Gonzalez, Anthony J.;"
authors = "Xi,L.;Smith, Anna Maria; Perez Gonzalez, Anthony J.;Doe,;von Doe, John"
result = reformat_authors_from_loculus_to_embl_style(authors)
desired_result = "Xi L., Smith A.M., Perez Gonzalez A.J.;"
desired_result = "Xi L., Smith A.M., Perez Gonzalez A.J., Doe, von Doe J.;"
self.assertEqual(result, desired_result)

def test_create_chromosome_list_multi_segment(self):
Expand Down
11 changes: 5 additions & 6 deletions ena-submission/src/ena_deposition/ena_submission_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import logging
import os
import re
import subprocess
import subprocess # noqa: S404
import tempfile
from collections import defaultdict
from dataclasses import dataclass
Expand Down Expand Up @@ -129,7 +129,7 @@ def get_project_xml(project_set):

def reformat_authors_from_loculus_to_embl_style(authors: str) -> str:
"""This function reformats the Loculus authors string to the format expected by ENA
Loculus format: `Doe, John A.; Roe, Jane B. C.`
Loculus format: `Doe, John A.; Roe, Jane Britt C.`
EMBL expected: `Doe J.A., Roe J.B.C.;`
EMBL spec: "The names are listed surname first followed by a blank
Expand All @@ -142,10 +142,9 @@ def reformat_authors_from_loculus_to_embl_style(authors: str) -> str:
authors_list = [author for author in authors.split(";") if author]
ena_authors = []
for author in authors_list:
last_name, first_name = author.split(",")[0].strip(), author.split(",")[1]
initials = ".".join([name[0] for name in first_name.split(" ") if name])
initials = initials + "." if initials else initials
ena_authors.append(f"{last_name} {initials}")
last_names, first_names = author.split(",")[0].strip(), author.split(",")[1].strip()
initials = "".join([name[0] + "." for name in first_names.split() if name])
ena_authors.append(f"{last_names} {initials}".strip())
return ", ".join(ena_authors) + ";"


Expand Down

0 comments on commit 03221f2

Please sign in to comment.