Skip to content

Commit 1fe48cc

Browse files
committed
improve docs
1 parent b7a6c88 commit 1fe48cc

1 file changed

Lines changed: 18 additions & 7 deletions

File tree

preprocessing/nextclade/src/loculus_preprocessing/processing_functions.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,8 +1256,19 @@ def assign_custom_lineage( # noqa: C901
12561256
) -> ProcessingResult:
12571257
"""
12581258
Assign flu lineage based on seg4 and seg6.
1259-
Add reassortant flag if subtypes from different lineages are detected for other segments,
1259+
Add reassortant flag if different lineages are detected for internal segments,
12601260
add and variant flag if any segment is a variant.
1261+
It expects the following input_data fields to be present:
1262+
- subtype_seg4: the subtype assigned to seg4
1263+
- subtype_seg6: the subtype assigned to seg6
1264+
- reference_seg1,...,reference_seg8: the reference sequence assigned to each segment
1265+
- variant_seg1,...,variant_seg8: boolean flag indicating whether a segment is a variant
1266+
It expects the following args to be present:
1267+
- pattern: regex pattern to extract lineage from reference
1268+
e.g. ^(?P<segment>[^-]+)-(?P<lineage>[^-]+)$
1269+
- uppercase: boolean flag indicating whether to uppercase the extracted lineage
1270+
- capture_group: the name of the capture group in the regex pattern to extract
1271+
e.g. "lineage"
12611272
"""
12621273
logger.debug(
12631274
f"Starting custom lineage assignment with input_data: {input_data} and args: {args}"
@@ -1267,7 +1278,7 @@ def assign_custom_lineage( # noqa: C901
12671278
ha_subtype = input_data.get("subtype_seg4")
12681279
na_subtype = input_data.get("subtype_seg6")
12691280
references: dict[str, str | None] = {}
1270-
extracted_subtypes: dict[str, str | None] = {}
1281+
extracted_lineages: dict[str, str | None] = {}
12711282
variant: dict[str, bool | None] = {}
12721283
for i in range(1, 9):
12731284
segment = f"seg{i}"
@@ -1281,7 +1292,7 @@ def assign_custom_lineage( # noqa: C901
12811292
try:
12821293
for i in range(1, 9):
12831294
segment = f"seg{i}"
1284-
extracted_subtypes[segment] = ProcessingFunctions.call_function( # type: ignore
1295+
extracted_lineages[segment] = ProcessingFunctions.call_function( # type: ignore
12851296
"extract_regex",
12861297
{
12871298
"pattern": args["pattern"],
@@ -1292,13 +1303,13 @@ def assign_custom_lineage( # noqa: C901
12921303
"output_field",
12931304
["segment_name"],
12941305
).datum
1295-
logger.debug(f"Extracted subtypes: {extracted_subtypes} from references: {references}")
1306+
logger.debug(f"Extracted lineages: {extracted_lineages} from references: {references}")
12961307
if not ha_subtype or not na_subtype:
12971308
return ProcessingResult(datum=None, warnings=[], errors=[])
12981309
lineage = f"{ha_subtype}{na_subtype}"
12991310
if (
1300-
extracted_subtypes.get("seg4") == "H1N1PDM"
1301-
and extracted_subtypes.get("seg6") == "H1N1PDM"
1311+
extracted_lineages.get("seg4") == "H1N1PDM"
1312+
and extracted_lineages.get("seg6") == "H1N1PDM"
13021313
):
13031314
lineage = "H1N1pdm"
13041315
logger.debug(
@@ -1309,7 +1320,7 @@ def assign_custom_lineage( # noqa: C901
13091320
f"Lineage {lineage} is a human lineage, checking for reassortment and variants"
13101321
)
13111322
# only assign human lineages
1312-
if len({v for v in extracted_subtypes.values() if v is not None}) > 1:
1323+
if len({v for v in extracted_lineages.values() if v is not None}) > 1:
13131324
lineage += " reassortant"
13141325
if any(v for v in variant.values() if v):
13151326
lineage += " (variant)"

0 commit comments

Comments
 (0)