Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1from pathlib import Path 

2from typing import Optional 

3 

4from Bio.AlignIO import _FormatToIterator as supported_alignment_formats 

5from Bio.Phylo._io import supported_formats as supported_tree_formats 

6from Bio.SeqIO import _FormatToIterator as supported_sequence_formats 

7 

8supported_sequence_formats.update(supported_alignment_formats) 

9import typer 

10 

11from .main import main 

12 

13app = typer.Typer() 

14 

15 

16def sequence_format_callback(value: str): 

17 if value not in supported_sequence_formats: 

18 raise typer.BadParameter( 

19 f"'{value}' is not a valid sequence format. Must be one of {', '.join(supported_sequence_formats.keys())}." 

20 ) 

21 return value 

22 

23 

24def tree_format_callback(value: str): 

25 if value not in supported_tree_formats: 

26 raise typer.BadParameter( 

27 f"'{value}' is not a valid tree format. Must be one of {', '.join(supported_tree_formats.keys())}." 

28 ) 

29 return value 

30 

31 

32def data_format_callback(value: str): 

33 if value not in ['csv', 'tsv', 'excel']: 

34 raise typer.BadParameter(f"'{value}' is not a valid data format. Must be one of csv, tsv, excel.") 

35 return value 

36 

37 

38@app.command(context_settings={"help_option_names": ["-h", "--help"]}) 

39def cli( 

40 testfile: Path = typer.Argument(..., help="Path to test file."), 

41 sequence: Optional[Path] = typer.Option( 

42 None, "--sequence", "-s", dir_okay=False, exists=True, help="Path to sequence file." 

43 ), 

44 sequence_format: Optional[str] = typer.Option( 

45 'fasta', 

46 "--sequence-format", 

47 dir_okay=False, 

48 exists=True, 

49 help=f"{', '.join(supported_sequence_formats.keys())}.", 

50 callback=sequence_format_callback, 

51 ), 

52 tree: Optional[Path] = typer.Option(None, "--tree", "-t", dir_okay=False, exists=True, help="Path to tree file."), 

53 tree_format: Optional[str] = typer.Option( 

54 'newick', 

55 "--tree-format", 

56 dir_okay=False, 

57 exists=True, 

58 help=f"{', '.join(supported_tree_formats.keys())}.", 

59 callback=tree_format_callback, 

60 ), 

61 data: Optional[Path] = typer.Option(None, "--data", "-d", dir_okay=False, exists=True, help="Path to data file."), 

62 data_format: Optional[str] = typer.Option( 

63 'csv', "--data-format", dir_okay=False, exists=True, help="csv, tsv, excel.", callback=data_format_callback 

64 ), 

65 report: Optional[Path] = typer.Option( 

66 None, "--report", "-r", dir_okay=False, exists=False, help="Path to HTML report to generate." 

67 ), 

68 verbose: Optional[bool] = typer.Option(False, "--verbose", "-v", help="Verbose output"), 

69 expression: Optional[str] = typer.Option( 

70 None, "-k", help="Only run tests which match the given substring expression." 

71 ), 

72 cores: Optional[str] = typer.Option( 

73 None, 

74 "-n", 

75 help="Number of cores. Use 'auto' to spawn a number of workers processes equal to the number of available CPUs.", 

76 ), 

77): 

78 exit_code = main( 

79 testfile=testfile, 

80 sequence=sequence, 

81 sequence_format=sequence_format, 

82 tree=tree, 

83 tree_format=tree_format, 

84 data=data, 

85 data_format=data_format, 

86 verbose=verbose, 

87 report=report, 

88 expression=expression, 

89 cores=cores, 

90 ) 

91 raise typer.Exit(code=exit_code)