PSEUDOCODE TASK: Implement subtraction utilities in module virtool/subtractions/utils.py using four functions with the following specifications.
FUNCTION join_subtraction_path(config, subtraction) RETURNS Path
// Determine base path from config
IF config has attribute "root_path" THEN
base_path ← config.root_path
ELSE IF config has attribute "data_path" THEN
base_path ← config.data_path
ELSE
RAISE ValueError("Config must provide a root_path or data_path")
ENDIF
// Compute and return the full path without creating directories
RETURN Path(base_path) / "subtractions" / subtraction
END FUNCTION
FUNCTION rename_bowtie_files(sub_dir: Path) RETURNS None
// In the directory sub_dir, rename files named: reference<N>.bt2 to subtraction<N>.bt2
FOR each entry in sub_dir.listed_files() DO
IF entry is a file AND filename matches regex "^reference.(\d+).bt2$" THEN
digits ← captured group from regex
new_name ← "subtraction." + digits + ".bt2"
RENAME entry to sub_dir / new_name
ENDIF
ENDFOR
// If no matching files exist, perform no action
END FUNCTION
FUNCTION check_subtraction_file_type(filename: str) RETURNS str
// Infer file type by extension
IF filename ends with ".bt2" THEN
RETURN "bowtie2"
ELSE IF filename ends with ".fa.gz" OR filename ends with ".fasta.gz" THEN
RETURN "fasta"
ELSE IF filename ends with ".fa" OR filename ends with ".fasta" THEN
// Optional robustness
RETURN "fasta"
ELSE
RAISE ValueError("Unrecognized subtraction file extension")
ENDIF
END FUNCTION
ASYNC FUNCTION get_subtraction_files(pg, subtraction: str) RETURNS List[Dict[str, Any]]
// Query PostgreSQL for metadata rows related to the given subtraction
sql ← "SELECT * FROM subtraction_files WHERE subtraction = $1"
rows ← await pg.fetch(sql, subtraction)
result ← empty list of dictionaries
FOR each row IN rows DO
// Convert each row to a dict mapping column names to values
dict_row ← dictionary from row (e.g., dict(row))
APPEND dict_row to result
ENDFOR
RETURN result
END FUNCTION
DELIVERABLE
Produce the module virtool/subtractions/utils.py implementing the four functions with the described behavior and robust edge-case handling.