Skip to content

Commit

Permalink
Replace _ to - for file name #39
Browse files Browse the repository at this point in the history
  • Loading branch information
akikuno committed May 30, 2024
1 parent 4f2487f commit f709483
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/DAJIN2/utils/fastx_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ def sanitize_filename(path_file: Path | str) -> str:
"""
Sanitize the path_file by replacing invalid characters on Windows OS with '-'
"""
path_file = str(path_file).lstrip()
path_file = str(path_file).strip()
if not path_file:
raise ValueError("Provided FASTA/FASTQ is empty or consists only of whitespace")
forbidden_chars = r'[<>:"/\\|?*\x00-\x1F .]'
forbidden_chars = r'[<>:"/\\|?*\x00-\x1F ._]'
return re.sub(forbidden_chars, "-", path_file)


Expand Down Expand Up @@ -53,9 +53,9 @@ def dictionize_allele(path_fasta: str | Path) -> dict[str, str]:
def export_fasta_files(TEMPDIR: Path, FASTA_ALLELES: dict, NAME: str) -> None:
"""Save multiple FASTAs in separate single-FASTA format files."""
for identifier, sequence in FASTA_ALLELES.items():
identifier = sanitize_filename(identifier)
contents = "\n".join([">" + identifier, sequence]) + "\n"
path_output_fasta = Path(TEMPDIR, NAME, "fasta", f"{identifier}.fasta")
path_output_fasta = Path(sanitize_filename(path_output_fasta))
path_output_fasta.write_text(contents)


Expand Down

0 comments on commit f709483

Please sign in to comment.