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.
- 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:
- 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:
- 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:
- 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:
- 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]