coalispr.resources.utilities

Attributes

Functions

bins_sum(df[, level])

Sum bin-values to get bin totals.

chrom_region(chrnam, region)

Create label for chromosome region.

chrxtra()

Check for presence extra DNA and annotations.

clean_dict(adict)

Remove empty items from a dictionary.

doneon()

Return date of function called (for saving files).

get_skip()

Provide a value of fragment size skipped during counting,

get_string_info(df)

Return a string for logging info, bypassing standard out.

get_tsvpath()

Return location of folder with TSV files

get_ylabel(label[, strand, spaces])

Return formatted label for y-axis of count plots.

is_all_zero(df)

Is this a dataframe with only 0 values?

joinall(labels[, conn])

Return string of words from list or dict of labels.

joiner([symb])

Quote list-items when joined to string. Add start and end ' to calling

merg(df1, df2)

Merge bedgraphs for each chr on intervals with hits.

percentaged(df)

Turn dataframe values into percentages of column totals.

remove_odds(termodds)

Prevent spaces or odd symbols in filename string.

replace_dot(termdot)

Remove dots from file name.

replacelist(linestring, names_old_new)

Replace sections in a string, pathname, print line etc.

replacelist_list(listofitems, names_old_new)

Replace items in a list.

thisfunc([n])

Return name of current or calling function for logging.

timer(func)

Print the time needed to run the decorated function.

Module Contents

coalispr.resources.utilities.logger
coalispr.resources.utilities.bins_sum(df, level=BINN)

Sum bin-values to get bin totals.

Parameters:
  • df (pandas.DataFrame) – Dataframe with bins that constitute a level to be converted.

  • level (str) – Column header with indices to be grouped (default=**BINN**).

Return type:

pandas.DataFrame

coalispr.resources.utilities.chrom_region(chrnam, region)

Create label for chromosome region.

Parameters:
  • chrnam (str) – Chromosome name.

  • region (tuple) – Tuple of coordinates.

coalispr.resources.utilities.chrxtra()

Check for presence extra DNA and annotations.

coalispr.resources.utilities.clean_dict(adict)

Remove empty items from a dictionary.

Parameters:

adict (dict) – Dictionary

coalispr.resources.utilities.doneon()

Return date of function called (for saving files).

coalispr.resources.utilities.get_skip()

Provide a value of fragment size skipped during counting, which depends on BINSTEP and MIRNAPKBUF.

Returns:

A value representing an extra margin to expand read segment with a single peak beyond 0.

Return type:

int

coalispr.resources.utilities.get_string_info(df)

Return a string for logging info, bypassing standard out.

Parameters:

df (pandas.DataFrame) – Dataframe to get info for.

coalispr.resources.utilities.get_tsvpath()

Return location of folder with TSV files

coalispr.resources.utilities.get_ylabel(label, strand=COMBI, spaces=0)

Return formatted label for y-axis of count plots.

Parameters:
  • label (str) – Read kind name to retrieve a label for configured in CNTLABELS.

  • strand (str) – One of COMBI, MUNR or CORB to indicate strand counted reads map to.

  • spaces (int) – Number of spaces to start second line with.

coalispr.resources.utilities.is_all_zero(df)

Is this a dataframe with only 0 values?

Parameters:

df (pandas.DataFrame) – Dataframe to get info for.

Returns:

Flag to indicate whether all values are 0.

Return type:

bool

coalispr.resources.utilities.joinall(labels, conn="', '")

Return string of words from list or dict of labels.

Parameters:
  • labels (list or dict) – List/Dictionary of lists of words to be joined.

  • conn (str) – Connector linking the words from labels.

coalispr.resources.utilities.joiner(symb=None)

Quote list-items when joined to string. Add start and end ‘ to calling format function {no control of ‘/” when using ‘repr’ by including !r}.

coalispr.resources.utilities.merg(df1, df2)

Merge bedgraphs for each chr on intervals with hits.

All rows/columns need to be combined; this creates duplicate columns with adapted names when non-unique columns are merged.

Parameters:
  • df1 (pandas.DataFrame) – Dataframes to merge

  • df2 (pandas.DataFrame) – Dataframes to merge

Returns:

Merged dataframe.

Return type:

pandas.DataFrame

coalispr.resources.utilities.percentaged(df)

Turn dataframe values into percentages of column totals.

Parameters:

df (pandas.DataFrame) – Dataframe with raw counts

Return type:

pandas.DataFrame

coalispr.resources.utilities.remove_odds(termodds)

Prevent spaces or odd symbols in filename string.

Parameters:

termodds (str) – String with possibly symbols or spaces in filename.

Returns:

Lower case name without odds; not to be confused with extension.

Return type:

str

coalispr.resources.utilities.replace_dot(termdot)

Remove dots from file name.

Parameters:

termdot (str) – String with possibly dots (‘.’) in filename (excluding extension).

Returns:

Name without dot(s); not to be confused with extension.

Return type:

str

coalispr.resources.utilities.replacelist(linestring, names_old_new)

Replace sections in a string, pathname, print line etc.

Parameters:
  • linestring (str) – String with particular sections to be replaced.

  • names_old_new (list of tuples) – Contents of listed tuples: (search-string, replacement).

Returns:

String after replacement.

Return type:

str

coalispr.resources.utilities.replacelist_list(listofitems, names_old_new)

Replace items in a list.

Parameters:
  • listofitems (list) – List with particular items to be changed.

  • names_old_new (list of tuples) – Contents of listed tuples: (search-string, replacement).

Returns:

List with items including those that have been replaced.

Return type:

list

coalispr.resources.utilities.thisfunc(n=0)

Return name of current or calling function for logging.

from: https://stackoverflow.com/questions/5067604/determine-function-name-from-within-that-function-without-using-traceback

https://docs.quantifiedcode.com/python-anti-patterns/correctness/assigning_a_lambda_to_a_variable.html

https://docs.quantifiedcode.com/python-anti-patterns/correctness/accessing_a_protected_member_from_outside_the_class.html

Parameters:

n (int) – For current func name, specify 0 or no argument. For name of caller of current func, specify 1. For name of caller of caller of current func, specify 2. etc.

Returns:

Name of function containing call.

Return type:

str

coalispr.resources.utilities.timer(func)

Print the time needed to run the decorated function. from: https://realpython.com/primer-on-python-decorators/