repare 0.1.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
repare/__init__.py ADDED
@@ -0,0 +1,4 @@
1
+ from .pedigree import Pedigree
2
+ from .pedigree_reconstructor import PedigreeReconstructor
3
+
4
+ __all__ = ["Pedigree", "PedigreeReconstructor"]
repare/main.py ADDED
@@ -0,0 +1,89 @@
1
+ import argparse
2
+ import logging
3
+ from datetime import datetime
4
+ from pathlib import Path
5
+
6
+ from tqdm.contrib.logging import logging_redirect_tqdm
7
+
8
+ from repare.pedigree_reconstructor import PedigreeReconstructor
9
+
10
+
11
+ def parse_arguments():
12
+ base_parser = argparse.ArgumentParser(add_help=False)
13
+ base_parser.add_argument(
14
+ "--print-allowed-constraints",
15
+ action="store_true",
16
+ help="Print the list of allowed constraint strings and exit.",
17
+ )
18
+
19
+ # Handle the informational flag before enforcing required arguments
20
+ base_args, remaining_args = base_parser.parse_known_args()
21
+ if base_args.print_allowed_constraints:
22
+ for constraint in sorted(PedigreeReconstructor.get_allowed_constraints()):
23
+ print(constraint)
24
+ base_parser.exit()
25
+
26
+ parser = argparse.ArgumentParser(
27
+ parents=[base_parser],
28
+ description="Reconstruct (ancient) pedigrees from pairwise kinship relations.",
29
+ )
30
+ parser.add_argument("-n", "--nodes", type=str, required=True, help="Path to the nodes CSV file.")
31
+ parser.add_argument("-r", "--relations", type=str, required=True, help="Path to the relations CSV file.")
32
+ parser.add_argument(
33
+ "-o",
34
+ "--output",
35
+ type=str,
36
+ default=datetime.now().strftime("repare_output_%Y%m%d_%H%M%S"),
37
+ help=(
38
+ "Directory to save the output files. Defaults to repare_output_<YYYYMMDD_HHMMSS> in the current directory."
39
+ ),
40
+ )
41
+ parser.add_argument(
42
+ "-m",
43
+ "--max_candidate_pedigrees",
44
+ type=int,
45
+ default=1000,
46
+ help="Number of pedigrees to keep after each iteration. Defaults to 1000.",
47
+ )
48
+ parser.add_argument(
49
+ "-e",
50
+ "--epsilon",
51
+ type=float,
52
+ default=0.2,
53
+ help="Parameter for adapted epsilon-greedy sampling at the end of each algorithm iteration. Defaults to 0.2.",
54
+ )
55
+ parser.add_argument("-s", "--seed", type=int, default=42, help="Random seed for reproducibility. Defaults to 42.")
56
+ parser.add_argument("-d", "--do_not_plot", action="store_false", help="Do not plot reconstructed pedigree(s).")
57
+ parser.add_argument(
58
+ "-w", "--write_alternates", action="store_true", help="Write outputs of alternate pedigrees to disk."
59
+ )
60
+ parser.add_argument("-v", "--verbose", action="store_true", help="Enable verbose output (INFO-level logging).")
61
+ return parser.parse_args(remaining_args)
62
+
63
+
64
+ def main():
65
+ args = parse_arguments()
66
+ logging_level = logging.INFO if args.verbose else logging.WARNING
67
+ logging.basicConfig(level=logging_level, format="%(levelname)s - %(message)s")
68
+
69
+ output_dir = Path(args.output)
70
+ output_dir.mkdir(parents=True, exist_ok=True)
71
+
72
+ with logging_redirect_tqdm():
73
+ print("Beginning pedigree reconstruction...")
74
+ pedigree_reconstructor = PedigreeReconstructor(
75
+ relations_path=args.relations,
76
+ nodes_path=args.nodes,
77
+ outputs_dir=output_dir,
78
+ max_candidate_pedigrees=args.max_candidate_pedigrees,
79
+ epsilon=args.epsilon,
80
+ plot=args.do_not_plot,
81
+ write_alternate_pedigrees=args.write_alternates,
82
+ random_seed=args.seed,
83
+ )
84
+ pedigree_reconstructor.find_best_pedigree()
85
+ print(f"Finished pedigree reconstruction. Outputs written to {output_dir.resolve()}.")
86
+
87
+
88
+ if __name__ == "__main__":
89
+ main()