Code Monkey home page Code Monkey logo

pymean's Introduction

pyMEAN: Metabolomic Enrichment ANalysis in Python

The pyMEAN package is designed to facilitate semi-automated enrichment analysis for metabolomic experiments.

Installation

pyMEAN requires Python 3+ and is unfortunately not compatible with Python 2. If you are still using Python 2, a clever workaround is to install Python 3 and use that instead.

The easiest way of installing pyMEAN is using pip:

pip install pymean

Alternatively, you can use git and pip in unison to get the development branch:

pip install https://github.com/KeironO/pyMEAN

Usage

Here's a starting template to get you started:

# Import pyMEAN module into Python.
from pymean import EnrichmentAnalysis

# A compound list of inchikeys.
compound_list = [
    "WDJHALXBUFZDSR-UHFFFAOYSA-N", # acetoacetic acid
    "UCMIRNVEIXFBKS-UHFFFAOYSA-N", # beta-alanine
    "CVSVTCORWBXHQV-UHFFFAOYSA-N", # creatine
    "FFDGPVCHZBVARC-UHFFFAOYSA-N", # dimethylglycine
    "VZCYOOQTPOCHFL-OWOJBTEDSA-N", # fumaric acid
    "DHMQDGOQFOQNFH-UHFFFAOYSA-N", # glycine
    "FFFHZYDWPBMWHY-UHFFFAOYSA-N", # l-homocysteine
    "XUJNEKJLAYXESH-REOHCLBHSA-N", # l-cysteine
    "COLNVLDHVKWLRT-QMMMGPOBSA-N", # l-phenylalanine
    "BTNMPGBKDVTSJY-UHFFFAOYSA-N" # phenylpyruvic acid
]


# Create an EnrichmentAnalysis object for the analysis of hsa
ea = EnrichmentAnalysis(compound_list, organism="hsa")

# Run the analysis
ea.run_analysis(pvalue_cutoff=0.05)

# Obtain results (in the format of a pandas dataframe)
resuklts = ea.results

If you'd like to plot out your results, take inspiration from the following method:

def plot_enrichment_analysis_results(results: pd.DataFrame, adj_method:str):
    fold_enrichment = np.abs(np.log(results["%s adj. p-value" % (adj_method)]))
    plt.figure()
    plt.title("Metabolite Sets Enrichment Overview")
    plt.barh(results["Pathway Name"], fold_enrichment, height=0.5)
    plt.xlabel("Fold Enrichment")

    plt.yticks(fontsize=6)
    plt.tight_layout()

    plt.show()

plot_enrichment_analysis_results(results, "fdr_bh")

Which will return the following chart:

Plot of results

License

Code released under the GPLv3.

pymean's People

Contributors

keirono avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

wudangbio hcji

pymean's Issues

Hypergeometric test from scipy does not have the right parameters fed

p_value = 1-hypergeom.cdf(
  num_hits-1,
  population-num_dbids,
  num_cpds,
  num_dbids)

According to scipy doc: cdf or sf take for argument : (k, M, n, N, loc=0) where M is the total number of objects (and not n=N-m like in R phyper, so here it should be the population.
Also the fisher_exact test could take an alternative param 'greater' so that both p-value would be the same, as Fischer is based on hypergeometric distribution.
I hope this package is still maintain :)

I have problem plot out my result?

Hello,
I run the commands with my data like your template. However, I have faced with this errors. Could you please help me to solve my problem?
KeyError Traceback (most recent call last)
File ~\anaconda3\envs\torch\lib\site-packages\pandas\core\indexes\base.py:3803, in Index.get_loc(self, key, method, tolerance)
3802 try:
-> 3803 return self._engine.get_loc(casted_key)
3804 except KeyError as err:

File ~\anaconda3\envs\torch\lib\site-packages\pandas_libs\index.pyx:138, in pandas._libs.index.IndexEngine.get_loc()

File ~\anaconda3\envs\torch\lib\site-packages\pandas_libs\index.pyx:165, in pandas._libs.index.IndexEngine.get_loc()

File pandas_libs\hashtable_class_helper.pxi:5745, in pandas._libs.hashtable.PyObjectHashTable.get_item()

File pandas_libs\hashtable_class_helper.pxi:5753, in pandas._libs.hashtable.PyObjectHashTable.get_item()

KeyError: 'fdr_bh adj. p-value'

The above exception was the direct cause of the following exception:

KeyError Traceback (most recent call last)
Cell In [28], line 1
----> 1 plot_enrichment_analysis_results(results, "fdr_bh")

Cell In [27], line 2, in plot_enrichment_analysis_results(results, adj_method)
1 def plot_enrichment_analysis_results(results: pd.DataFrame, adj_method:str):
----> 2 fold_enrichment = np.abs(np.log(results["%s adj. p-value" % (adj_method)]))
3 plt.figure()
4 plt.title("Metabolite Sets Enrichment Overview")

File ~\anaconda3\envs\torch\lib\site-packages\pandas\core\frame.py:3804, in DataFrame.getitem(self, key)
3802 if self.columns.nlevels > 1:
3803 return self._getitem_multilevel(key)
-> 3804 indexer = self.columns.get_loc(key)
3805 if is_integer(indexer):
3806 indexer = [indexer]

File ~\anaconda3\envs\torch\lib\site-packages\pandas\core\indexes\base.py:3805, in Index.get_loc(self, key, method, tolerance)
3803 return self._engine.get_loc(casted_key)
3804 except KeyError as err:
-> 3805 raise KeyError(key) from err
3806 except TypeError:
3807 # If we have a listlike key, _check_indexing_error will raise
3808 # InvalidIndexError. Otherwise we fall through and re-raise
3809 # the TypeError.
3810 self._check_indexing_error(key)

KeyError: 'fdr_bh adj. p-value'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.