app.components.tools package
Submodules
app.components.tools.R_tools module
- app.components.tools.R_tools.impute_qrilc(dataframe, random_seed, errorfile)[source]
Impute missing values using QRILC (via imputeLCMD).
- Parameters:
dataframe (
DataFrame) – Input DataFrame with missing values.random_seed (
int) – Seed for reproducibility.errorfile (
str) – Base path for error log on failure.
- Return type:
DataFrame- Returns:
DataFrame with imputed values.
- app.components.tools.R_tools.impute_random_forest(dataframe, random_seed, rev_sample_groups, errorfile)[source]
Impute missing values using randomForest::rfImpute grouped by sample groups.
- Parameters:
dataframe (
DataFrame) – Input DataFrame with missing values (rows=ids; cols=samples).random_seed (
int) – Seed for reproducibility.rev_sample_groups (
dict) – Mapping sample -> group for supervised imputation.errorfile (
str) – Base path for error log on failure.
- Return type:
DataFrame- Returns:
DataFrame with imputed values.
- app.components.tools.R_tools.run_rscript(r_script_contents, r_script_data, replace_name, errorfile, replace_dir=None, input_df_has_index=True)[source]
Execute an R script with a temp data file and return parsed output.
- Parameters:
r_script_contents (
list) – Lines of the R script; occurrences ofreplace_nameare replaced with temp paths.r_script_data (
DataFrame) – DataFrame to write to temp file for R to read.replace_name (
str) – Placeholder token to be replaced with temp filename.errorfile (
str|list) – Base path (e.g. ‘logs/errors.log’) or list of a file path (e.g. [‘logs’,’errors.log’]) for error log on failure.replace_dir (
str|None) – Optional directory placeholder to replace with temp dir.input_df_has_index (
bool) – Whether to include index when writing CSV/TSV.
- Returns:
DataFrame parsed from R output file.
- Raises:
Exception – Re-raises Rscript execution errors after logging.
- app.components.tools.R_tools.vsn(dataframe, random_seed, errorfile)[source]
Apply VSN normalization via R’s vsn::justvsn.
- Parameters:
dataframe (
DataFrame) – Input DataFrame (rows=ids in index; columns=samples).random_seed (
int) – Seed for reproducibility in R.errorfile (
str) – Base path to append Rscript stderr on failure.
- Return type:
DataFrame- Returns:
DataFrame of VSN-transformed values, aligned to input.
app.components.tools.utils module
- app.components.tools.utils.deep_merge(base, override)[source]
Deep-merge
overrideintobase.Rules: - Dicts merge recursively. - Scalars/lists replace the base value.
- Parameters:
base (
MutableMapping[str,Any]) – Destination mapping to mutate.override (
Mapping[str,Any]) – Source mapping providing updates.
- Return type:
MutableMapping[str,Any]- Returns:
Mutated
basemapping.
- app.components.tools.utils.dig_dict(in_dict, key_path)[source]
Traverse nested dict by list of keys.
- Parameters:
in_dict – Input mapping.
key_path – Sequence of keys to descend.
- Returns:
Value at the nested path.
- app.components.tools.utils.expand_path(path, param_dict)[source]
Expand a ‘params:’ reference into a concrete path from a dict.
- Parameters:
path – String possibly starting with
'params:'.param_dict – Parameter dictionary.
- Returns:
Expanded path string or original value.
- app.components.tools.utils.expand_paths(in_dict, param_dict)[source]
Recursively expand ‘params:’ paths in a nested dict structure.
- Parameters:
in_dict – Input dict to mutate.
param_dict – Parameter dictionary supplying values.
- Returns:
Mutated input dict with paths expanded.
- app.components.tools.utils.load_toml(path)[source]
Load a TOML file into a Python dict using tomlkit.
- Parameters:
path (
Path) – Path to TOML file.- Return type:
dict[str,Any]- Returns:
Parsed dict.
- app.components.tools.utils.normalize_key(s)[source]
Normalize a string for consistent matching.
Steps: - Lowercase and strip directory/extension. - Replace non-alphanumerics with underscore; collapse repeats. - Trim leading/trailing underscores.
- Parameters:
s (
str) – Input string (e.g., filename).- Return type:
str- Returns:
Normalized key string.
- app.components.tools.utils.prefix_relative_paths(data, basepath=None, check_exists=True)[source]
Recursively prefix relative paths in a nested dict.
Values can be strings, lists, or dicts.
- Parameters:
data (
Dict[str,Any]) – Input dictionary.basepath (
Union[str,PathLike,None]) – Base path to prepend; if None, uses globalBASEPATH.check_exists (
bool) – IfTrue, only replace when resulting path exists.
- Return type:
Dict[str,Any]- Returns:
New dict with adjusted paths.
- app.components.tools.utils.read_toml(toml_file, baseify=['Data paths'], check_exists=False, expand_paths_in_full_dict=True)[source]
Read a TOML file and optionally prefix/expand embedded paths.
- Parameters:
toml_file (
Union[str,Path]) – TOML file path.baseify – Top-level keys whose values should get path prefixing.
check_exists – If
True, only replace with existing paths.expand_paths_in_full_dict – If
True, expandparams:references.
- Returns:
Parsed and transformed dictionary.
- app.components.tools.utils.save_toml(data, path)[source]
Write a TOML document to disk using tomlkit.
- Parameters:
data (
dict[str,Any]) – Dict to serialize.path (
Path) – Output path.
- Return type:
None- Returns:
None
- app.components.tools.utils.zipdir(src_dir, tmpfs_base=None)[source]
Zip a directory and return the created archive path.
The zip contains paths prefixed by the source directory’s basename.
- Parameters:
src_dir (
str|Path) – Directory to zip.tmpfs_base (
str|Path|None) – Base directory for temporary working folder (unused placeholder).
- Return type:
Path- Returns:
Path to the created ZIP file.
- Raises:
FileNotFoundError – If
src_dirdoesn’t exist.NotADirectoryError – If
src_diris not a directory.
Module contents
Tools subpackage for helper utilities.