util module

class mavis.util.Log(indent_str=' ', indent_level=0, level=20)[source]

Bases: object

wrapper aroung the builtin logging to make it more readable

dedent()[source]
indent()[source]
class mavis.util.NullableType(callback_func)[source]

Bases: object

class mavis.util.WeakMavisNamespace(*pos, **kwargs)[source]

Bases: mavis.constants.MavisNamespace

is_env_overwritable(attr)[source]

Returns: bool: True if the variable is overrided by specifying the environment variable equivalent

mavis.util.bash_expands(*expressions)[source]

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

Returns

a list of files

Return type

list

Example

>>> bash_expands('./{test,doc}/*py')
[...]
mavis.util.cast(value, cast_func)[source]

cast a value to a given type

Example

>>> cast('1', int)
1
mavis.util.filepath(path)[source]
mavis.util.filter_on_overlap(bpps, regions_by_reference_name)[source]

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

Parameters
mavis.util.filter_uninformative(annotations_by_chr, breakpoint_pairs, max_proximity=5000)[source]
mavis.util.generate_complete_stamp(output_dir, log=<mavis.util.Log object>, prefix='MAVIS.', start_time=None)[source]

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

Parameters
  • output_dir (str) – path to the output dir the stamp should be written in

  • log (function) – function to print logging messages to

  • prefix (str) – prefix for the stamp name

  • start_time (int) – the start time

Returns

path to the complete stamp

Return type

str

Example

>>> generate_complete_stamp('some_output_dir')
'some_output_dir/MAVIS.COMPLETE'
mavis.util.get_connected_components(adj_matrix)[source]

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

mavis.util.get_env_variable(arg, default, cast_type=None)[source]
Parameters

arg (str) – the argument/variable name

Returns

the setting from the environment variable if given, otherwise the default value

mavis.util.log_arguments(args)[source]

output the arguments to the console

Parameters

args (Namespace) – the namespace to print arguments for

mavis.util.mkdirp(dirname)[source]

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

mavis.util.output_tabbed_file(bpps, filename, header=None)[source]
mavis.util.read_bpp_from_input_file(filename, expand_orient=False, expand_strand=False, expand_svtype=False, **kwargs)[source]

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

Parameters
  • filename (str) – path to the input file

  • expand_ns (bool) – expand not specified orient/strand settings to all specific version (for strand this is only applied if the bam itself is stranded)

  • explicit_strand (bool) – used to stop unstranded breakpoint pairs from losing input strand information

Returns

a list of pairs

Return type

list of BreakpointPair

Example

>>> 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(), ...]
mavis.util.read_inputs(inputs, **kwargs)[source]
mavis.util.soft_cast(value, cast_type)[source]

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

Example

>>> cast(None, int)
None
>>> cast('', int)
None
mavis.util.unique_exists(pattern, allow_none=False, get_newest=False)[source]
mavis.util.write_bed_file(filename, bed_rows)[source]