Skip to content

mavis.util

ENV_VAR_PREFIX

ENV_VAR_PREFIX = 'MAVIS_'

LOG

LOG = Log()

DEVNULL

DEVNULL = Log(level=None)

class mavis.util.Log

wrapper aroung the builtin logging to make it more readable

mavis.util.Log.__init__()

def __init__(self, indent_str='  ', indent_level=0, level=logging.INFO):

Args

  • indent_str
  • indent_level
  • level

class mavis.util.NullableType

class mavis.util.WeakMavisNamespace

inherits MavisNamespace

mavis.util.cast()

cast a value to a given type

def cast(value, cast_func):

Args

  • value
  • cast_func

Examples

>>> cast('1', int)
1

mavis.util.soft_cast()

cast a value to a given type, if the cast fails, cast to null

def soft_cast(value, cast_type):

Args

  • value
  • cast_type

Examples

>>> cast(None, int)
None
>>> cast('', int)
None

mavis.util.bash_expands()

expand a file glob expression, allowing bash-style brackets.

def bash_expands(*expressions):

Returns

  • list: a list of files

Examples

>>> bash_expands('./{test,doc}/*py')
[...]

mavis.util.log_arguments()

output the arguments to the console

def log_arguments(args):

Args

  • args (Namespace): the namespace to print arguments for

mavis.util.mkdirp()

Make a directory or path of directories. Suppresses the error that is normally raised when the directory already exists

def mkdirp(dirname):

Args

  • dirname

mavis.util.filter_on_overlap()

filter a set of breakpoint pairs based on overlap with a set of genomic regions

def filter_on_overlap(bpps, regions_by_reference_name):

Args

mavis.util.get_connected_components()

for a dictionary representing an adjacency matrix of undirected edges returns the connected components

def get_connected_components(adj_matrix):

Args

  • adj_matrix

mavis.util.generate_complete_stamp()

writes a complete stamp, optionally including the run time if start_time is given

def generate_complete_stamp(output_dir, log=DEVNULL, prefix='MAVIS.', start_time=None):

Args

  • output_dir (str): path to the output dir the stamp should be written in
  • log (Callable): function to print logging messages to
  • prefix (str): prefix for the stamp name
  • start_time (int): the start time

Examples

>>> generate_complete_stamp('some_output_dir')
'some_output_dir/MAVIS.COMPLETE'

mavis.util.read_bpp_from_input_file()

reads a file using the tab module. Each row is converted to a breakpoint pair and other column data is stored in the data attribute

def read_bpp_from_input_file(
    filename, expand_orient=False, expand_strand=False, expand_svtype=False, **kwargs
):

Args

  • filename (str): path to the input file
  • expand_orient
  • expand_strand
  • expand_svtype

Returns

  • List[BreakpointPair]: a list of pairs

Examples

>>> read_bpp_from_input_file('filename')
[BreakpointPair(), BreakpointPair(), ...]
One can also validate other expected columns that will go in the data attribute using the usual arguments
to the tab.read_file function
>>> read_bpp_from_input_file('filename', cast={'index': int})
[BreakpointPair(), BreakpointPair(), ...]