Bamboost
bamboost/core/utilities

bamboost.core.utilities

Utility functions used by bamboost.

Attributes

  • __all__=['flatten_dict', 'unflatten_dict', 'tree', 'h5_tree', 'show_differences', 'to_camel_case']
  • space=' '
  • branch=''
  • tee='├── '
  • last='└── '
  • JobArguments=NamedTuple('JobArguments', [('db_path', Path), ('name', str), ('submit', bool), ('note', str)])
  • ScriptArguments=NamedTuple('ScriptArguments', [('simulation', str)])

Functions

flatten_dict(dictionary, parent_key='', seperator='.') -> dict
Arguments:
  • dictionary:typing.Mapping
  • parent_key=''
  • seperator='.'
unflatten_dict(dictionary, seperator='.') -> dict
Arguments:
  • dictionary:dict
  • seperator:str='.'
tree(dir_path, level=-1, limit_to_directories=False, length_limit=1000) -> str

Given a directory Path object print a visual tree structure

Arguments:
  • dir_path:pathlib.Path
  • level:int=-1
  • limit_to_directories:bool=False
  • length_limit:int=1000
h5_tree(val, pre='')
Arguments:
  • val
  • pre=''
show_differences(df) -> DataFrame

This function takes a pandas DataFrame as input and returns a modified DataFrame that shows only the columns which have differences.

The function first creates a copy of the input DataFrame to work with. It then iterates over each column in the DataFrame and tries to calculate the number of unique values in that column. If successful, it adds the column name and number of unique values to a list of good results. If there is an error, it attempts to apply json.dumps to the column and then calculate the number of unique values again. If this is successful, it also adds the column name and number of unique values to the list of good results. If there is still an error, it adds the column name and the error to a list of errors.

After processing all columns, the function removes any columns that had errors from the DataFrame. It then sets the index of the DataFrame to 'id' and filters out any columns that have only one unique value. The modified DataFrame is then returned.

Arguments:
  • df:pd.pd.DataFrame

    The input DataFrame to analyze

Returns
pandas.DataFramepd.DataFrame
to_camel_case(s) -> str
Arguments:
  • s:str
parse_job_arguments() -> JobArguments

Parse command-line arguments for submitting a job to a bamboost database.

Returns
JobArgumentsA named tuple containing the parsed arguments.
parse_script_arguments() -> ScriptArguments

Parse command-line arguments for a script using the bamboost system.

Returns
ScriptArgumentsA named tuple containing the parsed arguments.

Classes

FilePicker

FilePicker(self, path)
Arguments:
  • path:pathlib.Path
Attributes:
  • path=bamboost.core.utilities.FilePicker(path)
  • _dict=self._build_file_dict(path)
FilePicker.__str__(self, *_args)
Arguments:
  • _args=()
FilePicker.__getitem__(self, key) -> Path
Arguments:
  • key
FilePicker._build_file_dict(self, path) -> dict
Arguments:
  • path:pathlib.Path