Commit f2791670 authored by Sean Solari's avatar Sean Solari
Browse files

Type hinting fixes

parent 4f005cc6
...@@ -5,7 +5,7 @@ from setuptools.extension import Extension ...@@ -5,7 +5,7 @@ from setuptools.extension import Extension
from Cython.Build import cythonize from Cython.Build import cythonize
import numpy as np import numpy as np
EXPAM_VERSION = (1, 0, 1) EXPAM_VERSION = (1, 0, 3)
SOURCE = os.path.dirname(os.path.abspath(__file__)) SOURCE = os.path.dirname(os.path.abspath(__file__))
......
...@@ -3,7 +3,7 @@ from multiprocessing import shared_memory ...@@ -3,7 +3,7 @@ from multiprocessing import shared_memory
import os import os
import re import re
import shutil import shutil
from typing import Union from typing import List, Mapping, Tuple, Union
import numpy as np import numpy as np
import pandas as pd import pandas as pd
...@@ -29,13 +29,13 @@ def run_classifier( ...@@ -29,13 +29,13 @@ def run_classifier(
k: int, k: int,
n: int, n: int,
phylogeny_path: str, phylogeny_path: str,
keys_shape: tuple[int], keys_shape: Tuple[int],
values_shape: tuple[int], values_shape: Tuple[int],
logging_dir: str, logging_dir: str,
taxonomy: bool = False, cutoff: float = 0.0, groups: Union[None, list[tuple]] = None, taxonomy: bool = False, cutoff: float = 0.0, groups: Union[None, List[tuple]] = None,
keep_zeros: bool = False, cpm: float = 0.0, use_node_names: bool = True, keep_zeros: bool = False, cpm: float = 0.0, use_node_names: bool = True,
phyla: bool = False, name_taxa: Union[dict[str, str], None] = None, phyla: bool = False, name_taxa: Union[Mapping[str, str], None] = None,
colour_list: list[str] = None, paired_end: bool = False, alpha: float = 1.0, colour_list: List[str] = None, paired_end: bool = False, alpha: float = 1.0,
log_scores: bool = False, itol_mode: bool = False log_scores: bool = False, itol_mode: bool = False
): ):
output_config: ResultsPathConfig = load_results_config(out_dir, create=True) output_config: ResultsPathConfig = load_results_config(out_dir, create=True)
......
import os import os
from typing import List, Set
from expam.cli.main import CommandGroup, ExpamOptions, clear_logs from expam.cli.main import CommandGroup, ExpamOptions, clear_logs
from expam.database import FileLocationConfig from expam.database import FileLocationConfig
from expam.database.build import main as expam from expam.database.build import main as expam
...@@ -8,7 +9,7 @@ from expam.utils import die, ls, make_path_absolute ...@@ -8,7 +9,7 @@ from expam.utils import die, ls, make_path_absolute
class BuildCommand(CommandGroup): class BuildCommand(CommandGroup):
commands: set[str] = { commands: Set[str] = {
'quickrun', 'default_db', 'create', 'quickrun', 'default_db', 'create',
'build', 'print', 'add', 'remove', 'set' 'build', 'print', 'add', 'remove', 'set'
} }
...@@ -16,7 +17,7 @@ class BuildCommand(CommandGroup): ...@@ -16,7 +17,7 @@ class BuildCommand(CommandGroup):
def __init__( def __init__(
self, config: FileLocationConfig, self, config: FileLocationConfig,
k: int, n: int, s: int, phylogeny_path: str, pile_size: int, k: int, n: int, s: int, phylogeny_path: str, pile_size: int,
files: list[str], group: str, first_n: int files: List[str], group: str, first_n: int
) -> None: ) -> None:
super().__init__() super().__init__()
self.config: FileLocationConfig = config self.config: FileLocationConfig = config
......
import os import os
from typing import List, Set, Tuple
from expam.classify import ResultsPathConfig from expam.classify import ResultsPathConfig
from expam.classify.classify import ClassificationResults, name_to_id, run_classifier from expam.classify.classify import ClassificationResults, name_to_id, run_classifier
from expam.classify.config import make_results_config, validate_results_configuration from expam.classify.config import make_results_config, validate_results_configuration
...@@ -10,16 +11,16 @@ from expam.utils import die, is_hex, make_path_absolute ...@@ -10,16 +11,16 @@ from expam.utils import die, is_hex, make_path_absolute
class ClassifyCommand(CommandGroup): class ClassifyCommand(CommandGroup):
commands: set[str] = { commands: Set[str] = {
'classify', 'to_taxonomy' 'classify', 'to_taxonomy'
} }
def __init__( def __init__(
self, config: FileLocationConfig, self, config: FileLocationConfig,
files: list[str], out_dir: str, files: List[str], out_dir: str,
convert_to_taxonomy: bool, cutoff: int, cpm: float, groups: list[tuple[str]], convert_to_taxonomy: bool, cutoff: int, cpm: float, groups: List[Tuple[str]],
use_node_names: bool, keep_zeros: bool, plot_phyla: bool, use_node_names: bool, keep_zeros: bool, plot_phyla: bool,
colour_list: list[str], paired_end: bool, alpha: float, colour_list: List[str], paired_end: bool, alpha: float,
log_scores: bool, itol_mode: bool log_scores: bool, itol_mode: bool
) -> None: ) -> None:
super().__init__() super().__init__()
......
...@@ -3,6 +3,7 @@ from collections import namedtuple ...@@ -3,6 +3,7 @@ from collections import namedtuple
import datetime import datetime
import os import os
import shutil import shutil
from typing import Set
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import numpy as np import numpy as np
...@@ -154,7 +155,7 @@ def clear_logs(log_path) -> None: ...@@ -154,7 +155,7 @@ def clear_logs(log_path) -> None:
class CommandGroup: class CommandGroup:
commands: set[str] = {} commands: Set[str] = {}
@classmethod @classmethod
def take_args(cls, args: ExpamOptions) -> dict: def take_args(cls, args: ExpamOptions) -> dict:
......
from functools import partial
import os import os
import re import re
import shutil import shutil
import subprocess import subprocess
from typing import Union from typing import List, Set, Tuple, Union
from expam.classify import ResultsPathConfig from expam.classify import ResultsPathConfig
from expam.classify.classify import ClassificationResults, name_to_id from expam.classify.classify import ClassificationResults, name_to_id
from expam.classify.config import make_results_config, validate_results_configuration from expam.classify.config import make_results_config, validate_results_configuration
...@@ -17,16 +16,16 @@ from expam.utils import die, is_hex, ls, make_path_absolute ...@@ -17,16 +16,16 @@ from expam.utils import die, is_hex, ls, make_path_absolute
class TreeCommand(CommandGroup): class TreeCommand(CommandGroup):
commands: set[str] = { commands: Set[str] = {
'phylotree', 'draw_tree', 'tree', 'phylotree', 'draw_tree', 'tree',
'mashtree', 'sketch', 'distance', 'nj' 'mashtree', 'sketch', 'distance', 'nj'
} }
def __init__( def __init__(
self, config: FileLocationConfig, self, config: FileLocationConfig,
out_dir: str, cutoff: int, cpm: float, groups: list[tuple[str]], out_dir: str, cutoff: int, cpm: float, groups: List[Tuple[str]],
use_node_names: bool, keep_zeros: bool, plot_phyla: bool, use_node_names: bool, keep_zeros: bool, plot_phyla: bool,
colour_list: list[str], log_scores: bool, itol_mode: bool, colour_list: List[str], log_scores: bool, itol_mode: bool,
at_rank: str, use_sourmash: bool, use_quicktree: bool at_rank: str, use_sourmash: bool, use_quicktree: bool
) -> None: ) -> None:
super().__init__() super().__init__()
...@@ -493,7 +492,7 @@ class TreeCommand(CommandGroup): ...@@ -493,7 +492,7 @@ class TreeCommand(CommandGroup):
file_path = os.path.join(sketch_dir, file_name % "msh") file_path = os.path.join(sketch_dir, file_name % "msh")
self.mash_sketch(k=k, s=s, p=n, sequences=sequences, out_dir=file_path) self.mash_sketch(k=k, s=s, p=n, sequences=sequences, out_dir=file_path)
def sour_sketch(self, k: int, s: int, sequences: list[str], sig_dir: str): def sour_sketch(self, k: int, s: int, sequences: List[str], sig_dir: str):
from expam.tree.sourmash import make_signatures from expam.tree.sourmash import make_signatures
make_signatures(self.get_n_processes(), sequences, sig_dir, k, s) make_signatures(self.get_n_processes(), sequences, sig_dir, k, s)
......
import os import os
from typing import Set
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
from expam.classify import ResultsPathConfig from expam.classify import ResultsPathConfig
from expam.classify.config import make_results_config, validate_classification_results, validate_results_configuration from expam.classify.config import make_results_config, validate_classification_results, validate_results_configuration
...@@ -12,7 +13,7 @@ from expam.utils import die, ls ...@@ -12,7 +13,7 @@ from expam.utils import die, ls
class UtilsCommand(CommandGroup): class UtilsCommand(CommandGroup):
commands: set[str] = { commands: Set[str] = {
'download_taxonomy', 'cutoff', 'fake_phylogeny', 'plot_memory' 'download_taxonomy', 'cutoff', 'fake_phylogeny', 'plot_memory'
} }
......
...@@ -3,6 +3,7 @@ import math ...@@ -3,6 +3,7 @@ import math
from multiprocessing import Pipe, Value, shared_memory from multiprocessing import Pipe, Value, shared_memory
import os import os
import subprocess import subprocess
from typing import List, Mapping
import numpy as np import numpy as np
from expam.database import CHUNK_SIZE, TIMEOUT, UNION_RATIO, FileLocationConfig, expam_dtypes from expam.database import CHUNK_SIZE, TIMEOUT, UNION_RATIO, FileLocationConfig, expam_dtypes
from expam.database.config import load_database_config from expam.database.config import load_database_config
...@@ -15,7 +16,7 @@ from expam.utils import ls ...@@ -15,7 +16,7 @@ from expam.utils import ls
def main( def main(
db_path: str, genome_paths: list[str], phylogeny_path: str, k: int, db_path: str, genome_paths: List[str], phylogeny_path: str, k: int,
n=None, n_extract=None, n_union=None, pile_size=None, n=None, n_extract=None, n_union=None, pile_size=None,
): ):
# Configure number of processes. # Configure number of processes.
...@@ -211,7 +212,7 @@ def yield_coordinates(index: Index): ...@@ -211,7 +212,7 @@ def yield_coordinates(index: Index):
def compute_lca(i, j, coord_one, coord_two): def compute_lca(i, j, coord_one, coord_two):
return i, j, propose_lca(coord_one, coord_two) return i, j, propose_lca(coord_one, coord_two)
def make_lca_matrix(index: Index, node_to_index: dict[str, str]): def make_lca_matrix(index: Index, node_to_index: Mapping[str, str]):
print("Creating LCA matrix...") print("Creating LCA matrix...")
def get_children(fixed_node, flexible_index_list): def get_children(fixed_node, flexible_index_list):
......
import multiprocessing import multiprocessing
import platform import platform
from typing import Tuple
from expam.cli.build import BuildCommand from expam.cli.build import BuildCommand
from expam.cli.classify import ClassifyCommand from expam.cli.classify import ClassifyCommand
...@@ -16,7 +17,7 @@ def main(): ...@@ -16,7 +17,7 @@ def main():
args: ExpamOptions = retrieve_arguments() args: ExpamOptions = retrieve_arguments()
handlers: tuple[CommandGroup] = (BuildCommand, ClassifyCommand, TreeCommand, UtilsCommand) handlers: Tuple[CommandGroup] = (BuildCommand, ClassifyCommand, TreeCommand, UtilsCommand)
for handler in handlers: for handler in handlers:
if args.command in handler.commands: if args.command in handler.commands:
handler(**handler.take_args(args)).run(args.command) handler(**handler.take_args(args)).run(args.command)
......
...@@ -101,7 +101,7 @@ class Index: ...@@ -101,7 +101,7 @@ class Index:
:type path: str :type path: str
:raises OSError: file does not exist :raises OSError: file does not exist
:return: name of leaves and phylogeny Index object :return: name of leaves and phylogeny Index object
:rtype: list[str], expam.tree.Index :rtype: List[str], expam.tree.Index
""" """
newick_str = "" newick_str = ""
...@@ -121,7 +121,7 @@ class Index: ...@@ -121,7 +121,7 @@ class Index:
:param newick_string: Newick string encoding tree. :param newick_string: Newick string encoding tree.
:type newick_string: str :type newick_string: str
:return: name of leaves and phylogeny Index object :return: name of leaves and phylogeny Index object
:rtype: list[str], expam.tree.Index :rtype: List[str], expam.tree.Index
""" """
stream = sys.stdout if verbose else open(os.devnull, 'w') stream = sys.stdout if verbose else open(os.devnull, 'w')
...@@ -570,7 +570,7 @@ class Index: ...@@ -570,7 +570,7 @@ class Index:
:param node_name: name of node :param node_name: name of node
:type node_name: str :type node_name: str
:return: list of node names :return: list of node names
:rtype: list[str] :rtype: List[str]
""" """
return list(self.yield_child_nodes(node_name)) return list(self.yield_child_nodes(node_name))
...@@ -580,7 +580,7 @@ class Index: ...@@ -580,7 +580,7 @@ class Index:
:param node_name: name of node :param node_name: name of node
:type node_name: str :type node_name: str
:return: list of leaf names :return: list of leaf names
:rtype: list[str] :rtype: List[str]
""" """
return list(self.yield_leaves(node_name)) return list(self.yield_leaves(node_name))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment