Skip to content

Commit

Permalink
perf: move more importing into respective entrypoint functions
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlougheed committed Sep 8, 2022
1 parent e11b0d0 commit 7767d4b
Showing 1 changed file with 22 additions and 23 deletions.
45 changes: 22 additions & 23 deletions strkit/entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@
import strkit.constants as c
from strkit import __version__

from strkit.mi.base import BaseCalculator
from strkit.mi.expansionhunter import ExpansionHunterCalculator
from strkit.mi.gangstr import GangSTRCalculator
from strkit.mi.repeathmm import RepeatHMMCalculator, RepeatHMMReCallCalculator
from strkit.mi.straglr import StraglrCalculator, StraglrReCallCalculator
from strkit.mi.strkit import StrKitCalculator, StrKitJSONCalculator
from strkit.mi.tandem_genotypes import TandemGenotypesCalculator, TandemGenotypesReCallCalculator


def add_call_parser_args(call_parser):
call_parser.add_argument(
Expand Down Expand Up @@ -187,20 +179,6 @@ def add_re_call_parser_args(re_call_parser):
help="Random seed to pass to random number generators for result replicability.")


CALC_CLASSES: dict[str, Type[BaseCalculator]] = {
c.CALLER_EXPANSIONHUNTER: ExpansionHunterCalculator,
c.CALLER_GANGSTR: GangSTRCalculator,
c.CALLER_REPEATHMM: RepeatHMMCalculator,
c.CALLER_REPEATHMM_RECALL: RepeatHMMReCallCalculator,
c.CALLER_STRAGLR: StraglrCalculator,
c.CALLER_STRAGLR_RECALL: StraglrReCallCalculator,
c.CALLER_STRKIT: StrKitCalculator,
c.CALLER_STRKIT_JSON: StrKitJSONCalculator,
c.CALLER_TANDEM_GENOTYPES: TandemGenotypesCalculator,
c.CALLER_TANDEM_GENOTYPES_RECALL: TandemGenotypesReCallCalculator,
}


def add_mi_parser_args(mi_parser):
mi_parser.add_argument(
"--debug",
Expand Down Expand Up @@ -414,14 +392,35 @@ def _exec_re_call(p_args) -> int:


def _exec_mi(p_args) -> int:
from strkit.mi.base import BaseCalculator
from strkit.mi.expansionhunter import ExpansionHunterCalculator
from strkit.mi.gangstr import GangSTRCalculator
from strkit.mi.repeathmm import RepeatHMMCalculator, RepeatHMMReCallCalculator
from strkit.mi.straglr import StraglrCalculator, StraglrReCallCalculator
from strkit.mi.strkit import StrKitCalculator, StrKitJSONCalculator
from strkit.mi.tandem_genotypes import TandemGenotypesCalculator, TandemGenotypesReCallCalculator

calc_classes: dict[str, Type[BaseCalculator]] = {
c.CALLER_EXPANSIONHUNTER: ExpansionHunterCalculator,
c.CALLER_GANGSTR: GangSTRCalculator,
c.CALLER_REPEATHMM: RepeatHMMCalculator,
c.CALLER_REPEATHMM_RECALL: RepeatHMMReCallCalculator,
c.CALLER_STRAGLR: StraglrCalculator,
c.CALLER_STRAGLR_RECALL: StraglrReCallCalculator,
c.CALLER_STRKIT: StrKitCalculator,
c.CALLER_STRKIT_JSON: StrKitJSONCalculator,
c.CALLER_TANDEM_GENOTYPES: TandemGenotypesCalculator,
c.CALLER_TANDEM_GENOTYPES_RECALL: TandemGenotypesReCallCalculator,
}

caller = p_args.caller.lower()

trf_bed_file = getattr(p_args, "trf_bed") or None
if trf_bed_file is None and caller in (c.CALLER_STRAGLR, c.CALLER_STRAGLR_RECALL):
sys.stderr.write(f"Error: Using mistr with Straglr requires that the --trf-bed flag is used.\n")
exit(1)

calc_class: Optional[Type[BaseCalculator]] = CALC_CLASSES.get(caller)
calc_class: Optional[Type[BaseCalculator]] = calc_classes.get(caller)
if not calc_class:
sys.stderr.write(f"Error: Unknown or unimplemented caller '{caller}'\n")
exit(1)
Expand Down

0 comments on commit 7767d4b

Please sign in to comment.