phylojunction.constant_function package

Submodules

phylojunction.constant_function.ct_function_read_tree module

class phylojunction.constant_function.ct_function_read_tree.CtFnTreeReader(n_samples: int, n_repl: int, tr_fp_or_str: str, node_name_attr: str, in_file: bool, list_time_slice_age_ends: List[float] | None = None, is_complete: bool = False, keep_unsampled_alive: bool = False, n_provided: bool = False, nr_provided: bool = False)

Bases: ConstantFn

Build one or more AnnotatedTree(s) from Newick string(s).

‘n’/’nr’ (“number of samples”/”number of replicates”) behave in one of exactly two ways, depending on whether the user wrote either of them in the script at all:

  1. neither ‘n’ nor ‘nr’ is given: every tree string found (a ‘string’ argument is always exactly one tree; a ‘file_path’ argument may hold any number of them, one per line) goes straight into ‘n_samples’ – never into ‘n_repl’ – so, e.g., a 5-line file becomes 5 samples, 1 replicate each, with no further input needed from the user; or

  2. ‘n’ and/or ‘nr’ is given explicitly (even if the value written happens to be ‘1’): that value is taken completely literally, and checked – via ‘init_check_vectorize_sample_size’ – against how many tree strings were actually found (‘n_samples * n_repl’ must equal that count exactly). Mismatches raise ‘exception_classes.ObjInitIncorrectDimensionError’ rather than being silently reconciled one way or another.

There is deliberately no third, in-between behavior (e.g., “read only the first tree of a multi-tree file”) – the whole file is always consumed, and ‘n’/’nr’ only ever either describe its exact shape (case ii) or get inferred from it outright (case i).

CT_FN_NAME = 'read_tree'
generate() → List[AnnotatedTree]
get_rev_inference_spec_info() → List[str]
in_file: bool
init_check_vectorize_sample_size() → None

Check provided tree strings and count members match.

Always enforced – when neither ‘n’ nor ‘nr’ was provided (see ‘__init__’ above), ‘n_samples’ was already set to match ‘total_tr_count’ exactly, so this can never raise in that case; it only ever does when the user gave an explicit ‘n’ and/or ‘nr’ that does not actually match how many tree strings were found.

is_complete: bool
keep_unsampled_alive: bool
n_provided: bool
node_name_attr: str
nr_provided: bool
slice_age_ends: List[float]
slice_t_ends: List[float]
total_tr_count: int
tr_str_list: List[str]

Module contents