From 199f3a50f183dc3acd3d0d55fa0d339e0becf91e Mon Sep 17 00:00:00 2001 From: Vitaliy Mysak Date: Fri, 6 Dec 2024 16:16:02 -0800 Subject: [PATCH] Improve typing in fasta_to_csv --- micall/tests/test_fasta_to_csv.py | 4 ++-- micall/utils/contig_summary.py | 2 +- micall/utils/fasta_to_csv.py | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/micall/tests/test_fasta_to_csv.py b/micall/tests/test_fasta_to_csv.py index 4ab951b6d..0fe8a92c1 100644 --- a/micall/tests/test_fasta_to_csv.py +++ b/micall/tests/test_fasta_to_csv.py @@ -16,7 +16,7 @@ def DEFAULT_DATABASE(): @pytest.fixture(scope='session', name='hcv_db') def check_hcv_db(DEFAULT_DATABASE): - db_path = Path(DEFAULT_DATABASE) + db_path = DEFAULT_DATABASE index_path = db_path.parent / "refs.fasta.nin" build_needed = not index_path.exists() if not build_needed: @@ -32,7 +32,7 @@ def check_hcv_db(DEFAULT_DATABASE): def test_make_blast_db_excludes_hivgha(hcv_db, DEFAULT_DATABASE): - fasta_path = Path(DEFAULT_DATABASE) + fasta_path = DEFAULT_DATABASE with fasta_path.open() as f: for reference in SeqIO.parse(f, 'fasta'): # Exclude the Ghana project, because they're recombinant. diff --git a/micall/utils/contig_summary.py b/micall/utils/contig_summary.py index e4ba399d2..7b8529b99 100644 --- a/micall/utils/contig_summary.py +++ b/micall/utils/contig_summary.py @@ -52,7 +52,7 @@ def main(): with default_database() as DEFAULT_DATABASE: stdout = Blastn().genotype( contigs_fasta=contigs_fasta_path, - database=Path(DEFAULT_DATABASE), + database=DEFAULT_DATABASE, ) plot_contigs(sample_dir, stdout) plot_path = contig_plots_path / (sample_dir.name + '.png') diff --git a/micall/utils/fasta_to_csv.py b/micall/utils/fasta_to_csv.py index cd7616e19..fcd762ea6 100644 --- a/micall/utils/fasta_to_csv.py +++ b/micall/utils/fasta_to_csv.py @@ -55,9 +55,9 @@ def reference_dir() -> Iterator[Path]: @contextlib.contextmanager -def default_database() -> Iterator[str]: +def default_database() -> Iterator[Path]: with reference_dir() as blast_db: - yield str(blast_db / "refs.fasta") + yield blast_db / "refs.fasta" def read_assembled_contigs(group_refs: Dict[str, str], @@ -134,7 +134,7 @@ def write_contigs(writer: DictWriter, contig=contig.seq)) -def genotype(fasta: str, db: Optional[str] = None, +def genotype(fasta: str, db: Optional[Path] = None, blast_csv: Optional[TextIO] = None, group_refs: Optional[Dict[str, str]] = None) -> Dict[str, typing.Tuple[str, float]]: """Use Blastn to search for the genotype of a set of reference sequences. @@ -166,7 +166,7 @@ def genotype(fasta: str, db: Optional[str] = None, 'sstart', 'send'] - def invoke_blast(db: str) -> str: + def invoke_blast(db: Path) -> str: return Blastn().genotype( contigs_fasta=Path(fasta), database=Path(db),