acore.utils module#

convertToEdgeList(data, cols)[source]#

This function converts a pandas dataframe to an edge list where index becomes the source nodes and columns the target nodes.

Parameters:
  • data – pandas dataframe.

  • cols (list) – names for dataframe columns.

Returns:

Pandas dataframe with columns cols.

check_is_paired(df, subject, group)[source]#

Check if samples are paired.

Parameters:
  • df – pandas dataframe with samples as rows and protein identifiers as columns (with additional columns ‘group’, ‘sample’ and ‘subject’).

  • subject (str) – column with subject identifiers

  • group (str) – column with group identifiers

Returns:

True if paired samples.

Return type:

bool

transform_into_wide_format(data, index, columns, values, extra=[])[source]#

This function converts a Pandas DataFrame from long to wide format using pandas pivot_table() function.

Parameters:
  • data – long-format Pandas DataFrame

  • index (list) – columns that will be converted into the index

  • columns (str) – column name whose unique values will become the new column names

  • values (str) – column to aggregate

  • extra (list) – additional columns to be kept as columns

Returns:

Wide-format pandas DataFrame

Example:

result = transform_into_wide_format(df, index='index', columns='x', values='y', extra='group')
transform_into_long_format(data, drop_columns, group, columns=['name', 'y'])[source]#

Converts a Pandas DataDrame from wide to long format using pd.melt() function.

Parameters:
  • data – wide-format Pandas DataFrame

  • drop_columns (list) – columns to be deleted

  • group (str or list) – column(s) to use as identifier variables

  • columns (list) – names to use for the 1)variable column, and for the 2)value column

Returns:

Long-format Pandas DataFrame.

Example:

result = transform_into_long_format(df, drop_columns=['sample', 'subject'], group='group', columns=['name','y'])
remove_group(data)[source]#

Removes column with label ‘group’.

Parameters:

data – pandas dataframe with one column labelled ‘group’

Returns:

Pandas dataframe

Example:

result = remove_group(data)
calculate_fold_change(df, condition1, condition2)[source]#

Calculates fold-changes between two groups for all proteins in a dataframe.

Parameters:
  • df – pandas dataframe with samples as rows and protein identifiers as columns.

  • condition1 (str) – identifier of first group.

  • condition2 (str) – identifier of second group.

Returns:

Numpy array.

Example:

result = calculate_fold_change(data, 'group1', 'group2')
pooled_standard_deviation(sample1, sample2, ddof)[source]#

Calculates the pooled standard deviation. For more information visit https://www.hackdeploy.com/learn-what-is-statistical-power-with-python/.

Parameters:
  • sample1 (array) – numpy array with values for first group

  • sample2 (array) – numpy array with values for second group

  • ddof (int) – degrees of freedom

cohens_d(sample1, sample2, ddof)[source]#

Calculates Cohen’s d effect size based on the distance between two means, measured in standard deviations. For more information visit https://www.hackdeploy.com/learn-what-is-statistical-power-with-python/.

Parameters:
  • sample1 (array) – numpy array with values for first group

  • sample2 (array) – numpy array with values for second group

  • ddof (int) – degrees of freedom

hedges_g(df, condition1, condition2, ddof=0)[source]#

Calculates Hedges’ g effect size (more accurate for sample sizes below 20 than Cohen’s d). For more information visit https://docs.scipy.org/doc/numpy/reference/generated/numpy.nanstd.html.

Parameters:
  • df – pandas dataframe with samples as rows and protein identifiers as columns.

  • condition1 (str) – identifier of first group.

  • condition2 (str) – identifier of second group.

  • ddof (int) – means Delta Degrees of Freedom.

Returns:

Numpy array.

Example:

result = hedges_g(data, 'group1', 'group2', ddof=0)
unit_vector(vector)[source]#

Returns the unit vector of the vector. :param tuple vector: vector :return tuple unit_vector: unit vector

flatten(t, my_list=[])[source]#

Code from: https://gist.github.com/shaxbee/0ada767debf9eefbdb6e Acknowledgements: Zbigniew Mandziejewicz (shaxbee) Generator flattening the structure

>>> list(flatten([2, [2, (4, 5, [7], [2, [6, 2, 6, [6], 4]], 6)]]))
[2, 2, 4, 5, 7, 2, 6, 2, 6, 6, 4, 6]
angle_between(v1, v2)[source]#

Returns the angle in radians between vectors ‘v1’ and ‘v2’

Parameters:
Return float angle:

angle between two vectors in radians

Example::

angle = angle_between((1, 0, 0), (0, 1, 0))

append_to_list(mylist, myappend)[source]#
generator_to_dict(genvar)[source]#