Run a popular ALDEx2 tool in Python via rpy2.
This tool is aware of the compositionality of sequencing data, and treats them accordingly.
Create a new conda environment and install required dependencies:
conda create --name pyaldex2 -c conda-forge -c bioconda bioconductor-aldex2 rpy2 pandas
Activate the environment:
conda activate pyaldex2
Clone this repository to a convinient location to store the script:
git clone https://github.com/trickovicmatija/ALDEx2-python.git
Import the module and set the path:
import pandas as pd
import sys, os
sys.path.append("<CHANGE_PATH>/ALDEx2-python") # Append the location of cloned repository
import pyaldex2
path = f'{os.path.dirname(pyaldex2.__file__)}/run_aldex2.R' # Set the path of the "run_aldex2.R" R-script. Default: same directory as the Python module.
Import test data:
counts = pd.read_csv("<CHANGE_PATH>/ALDEx2-python/test_data/raw_counts.tsv",sep='\t',index_col=0) # It will automatically orient the dataframe
metadata = pd.read_csv("<CHANGE_PATH>/ALDEx2-python/test_data/metadata.tsv",sep='\t',index_col=0)
Run the script:
result_df = pyaldex2.run_aldex2(counts,metadata,'t',r_script_path=path)
For the description of ALDEx2 output see here.
You can also get CLR-transformed data, which represent a median between all created Monte-Carlo instances:
clr_data = pyaldex2.get_clr(counts,metadata,mc_samples=16,r_script_path=path)
Or, you can get only one instance:
clr_instance = pyaldex2.get_clr_instance(counts,metadata,instance=1,mc_samples=16,r_script_path=path)
Before plotting, make sure neccessary libraries (numpy, seaborn, matplotlib.pyplot) are installed.
If not, install them in order to continue.
You can create a MA-plot using pyaldex2.MA_plot()
:
pyaldex2.MA_plot(result_df,effect_threshold=1)
Check help of the function for details.
Also, you can create a vulcano-plot using pyaldex2.vulcano_plot()
:
pyaldex2.vulcano_plot(result_df)
Check help of the function for details.
This script is only running the original ALDEx2 tool in Python. I don't take any responsibility or credits from it. For any questions about the tool itself, please write to them.