From 1988214cde67a0b14a20938c6354fdce8216f292 Mon Sep 17 00:00:00 2001 From: Steven Weaver Date: Tue, 14 Oct 2025 14:37:55 -0700 Subject: [PATCH] Fix tn93_args parameter handling in true_append The tn93_args parameter in the run_tn93 function was not handling both string and list inputs correctly. When called from hivtrace.py, the parameter is passed as a list of arguments, but the previous implementation tried to iterate over the parameter and call .strip() on each element, which would fail for lists. This fix adds type checking to handle both interfaces: - String input (from CLI): splits on whitespace to create argument list - List input (from hivtrace.py): converts all elements to strings This resolves issues when true_append is executed as part of a pipeline from hivtrace.py, ensuring tn93 arguments are properly constructed for subprocess calls. --- hivtrace/true_append.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/hivtrace/true_append.py b/hivtrace/true_append.py index 8ca6a53..1d71e2d 100755 --- a/hivtrace/true_append.py +++ b/hivtrace/true_append.py @@ -146,11 +146,16 @@ def remove_IDs_tn93(in_dists_fn, out_dists_file, to_keep, remove_header=True): # Argument: `to_add` = `set` containing IDs to add to TN93 distances file # Argument: `to_replace` = `set` containing IDs in `seqs_old` whose sequences need to be updated with those in `seqs_new` # Argument: `to_keep` = `set` containing IDs to keep in TN93 distances file -# Argument: `tn93_args` = string containing optional tn93 arguments +# Argument: `tn93_args` = string (CLI) or list (programmatic) containing optional tn93 arguments # Argument: `tn93_path` = path to tn93 executable def run_tn93(seqs_new, seqs_old, out_dists_file, to_add, to_replace, to_keep, remove_header=True, tn93_args=DEFAULT_TN93_ARGS, tn93_path=DEFAULT_TN93_PATH): # set things up - tn93_base_command = [tn93_path] + [v.strip() for v in tn93_args] + # Handle tn93_args as either a string (from CLI) or a list (from programmatic call) + if isinstance(tn93_args, str): + tn93_base_command = [tn93_path] + (tn93_args.split() if tn93_args else []) + else: + # Assume it's a list, convert all elements to strings + tn93_base_command = [tn93_path] + [str(v) for v in tn93_args] new_fasta_data = ''.join('>%s\n%s\n' % (k,seqs_new[k]) for k in (to_add | to_replace)).encode('utf-8') # calculate new-new distances