Skip to content

Python implementation of PANDA and LIONESS

Notifications You must be signed in to change notification settings

aless80/pypanda

 
 

Repository files navigation

Description

Forked from https://github.com/QuackenbushLab/pypanda, which was based on https://github.com/davidvi/pypanda.
Compared to QuackenbushLab/pypanda this repository adds the Python implementation of PUMA (run_puma.py and pypanda/puma.py). NaN values in normalized matrices are replaced with values normalized by the overall z-score. This allows running the Toy Data provided in this repository.

Table of Contents

Links to literature

  • PUMA (PANDA Using MicroRNA Associations)
    Manuscript in preparation, used in PUMA.
    C and MATLAB code: https://github.com/mararie/PUMA

  • PANDA Passing Attributes between Networks for Data Assimilation
    Glass K, Huttenhower C, Quackenbush J, Yuan GC. Passing Messages Between Biological Networks to Refine Predicted Interactions, PLoS One, 2013 May 31;8(5):e64832
    Original PANDA C++ code: http://sourceforge.net/projects/panda-net/.

  • LIONESS (Linear Interpolation to Obtain Network Estimates for Single Samples)
    Marieke Lydia Kuijjer, Matthew Tung,GuoCheng Yuan,John Quackenbush, Kimberly Glass. Estimating sample-specific regulatory networks

LIONESS can be used to estimate single-sample networks using aggregate networks made with any network reconstruction algorithm (http://arxiv.org/pdf/1505.06440.pdf).

Panda algorithm

To find agreement between the three input networks first the responsibility (R) is calculated.

Thereafter availability (A) is calculated.

Availability and responsibility are combined with the following formula.

Protein cooperativity and gene co-regulatory networks are updated.

P and C are updated to satisfy convergence.

Hamming distance is calculated every iteration.

Installation

PyPanda runs on Python 2.7*. You can either run the pypanda script directly (see Usage) or install it on your system. We recommend the following commands to install pypandas on UNIX systems:

Using a virtual environment

Using python virtual environments is the cleanest installation method.

Cloning git and setting up a python virtual environment:

pip install --user pipenv   #Make sure you have pipenv
git clone https://github.com/aless80/pypanda.git
cd pypanda

Creating a virtual environment and installing pypanda:

virtualenv pypandaenv #virtual environment created in a folder inside the git folder 
source pypandaenv/bin/activate
(pypandaenv)$ pip install -r requirements.txt
(pypandaenv)$ python setup.py install --record files.txt

Uninstall pypanda from virtual environment:

cat files.txt | xargs rm -rf

Complete removal of virtual environment and pypanda:

(pypanda)$ deactivate	#Quit virtual environment
rm -rf pypandaenv

Using pip

Never use sudo pip. Instead you can use pip for Python 2.7 in the user's install directory:

git clone https://github.com/aless80/pypanda.git
cd pypanda
python setup.py install --user
#to run from the command line you will need to make pypanda executable and add the bin directory to your PATH:
cd bin
chmod +x pypanda
echo "$(pwd):PATH" >> ~/.bashrc
source ~/.bashrc

Uninstall pypanda:

pip uninstall pypanda

To run pypanda from Windows (tested on Windows 10) install Git (https://git-scm.com/downloads) and Anaconda Python 2.7 (https://www.continuum.io/downloads) and from the Anaconda prompt run:

git clone https://github.com/aless80/pypanda.git
cd pypanda
python setup.py install

Usage

Run from terminal

pypanda (or pypuma) can be run directly from the terminal with the following options:

-h help
-e, --expression: expression values
-m, --motif: pair file of motif edges, or Pearson correlation matrix when not provided 
-p, --ppi: pair file of PPI edges
-o, --output: output file
-i, --mir: mir data miR file (only for pypuma)
-r, --rm_missing
-q, --lioness: output for Lioness single sample networks 

To run pypanda on toy data:

python run_panda.py -e ./ToyData/ToyExpressionData.txt -m ./ToyData/ToyMotifData.txt -p ./ToyData/ToyPPIData.txt -o output_panda.txt

To reconstruct a single sample Lioness Pearson correlation network (this can take some time):

python run_panda.py -e ./ToyData/ToyExpressionData.txt -m ./ToyData/ToyMotifData.txt -p ./ToyData/ToyPPIData.txt -o output_panda.txt -q output_lioness.txt

To run pypuma on toy data:

python run_puma.py -e ./ToyData/ToyExpressionData.txt -m ./ToyData/ToyMotifData.txt -p ./ToyData/ToyPPIData.txt -o output_puma.txt -i ./ToyData/ToyMiRList.txt

To reconstruct a single sample Lioness Pearson correlation network using pypuma (this can take some time):

python run_puma.py -e ./ToyData/ToyExpressionData.txt -m ./ToyData/ToyMotifData.txt -p ./ToyData/ToyPPIData.txt -i ToyData/ToyMiRList.txt -o output_puma.txt -q output_lioness.txt

For pypuma see also PyPuma.

Run from Python

Fire up your Python 2.7 shell or ipython notebook. Use the python installation in the virtual environment if you installed pypanda there.

Import the classes in the pypanda library:

from pypanda.panda import Panda
from pypuma.puma import Puma
from pypanda.lioness import Lioness

Run the Panda algorithm, leave out motif and PPI data to use Pearson correlation network:

panda_obj = Panda('ToyData/ToyExpressionData.txt', 'ToyData/ToyMotifData.txt', 'ToyData/ToyPPIData.txt', remove_missing=False)

Save the results:

panda_obj.save_panda_results('Toy_Panda.pairs.txt')

Return a network plot:

panda_obj.top_network_plot(top=70, file='top_genes.png')

Calculate in- and outdegrees for further analysis:

indegree = panda_obj.return_panda_indegree()
outdegree = panda_obj.return_panda_outdegree()

To run the Lioness algorithm for single sample networks, first run panda (or puma) using the keep_expression_matrix flag, then use Lioness as follows:

panda_obj = Panda('ToyData/ToyExpressionData.txt', 'ToyData/ToyMotifData.txt', 'ToyData/ToyPPIData.txt', remove_missing=False, keep_expression_matrix=True)
lioness_obj = Lioness(panda_obj)

Save Lioness results:

lioness_obj.save_lioness_results('Toy_Lioness.txt')

Return a network plot for one of the Lioness single sample networks:

plot = AnalyzeLioness(lioness_obj)
plot.top_network_plot(column= 0, top=100, file='top_100_genes.png')

Run the Puma algorithm, leave out motif and PPI data to use Pearson correlation network:

puma_obj = Puma('ToyData/ToyExpressionData.txt', 'ToyData/ToyMotifData.txt', 'ToyData/ToyPPIData.txt','ToyData/ToyMiRList.txt')

Toy data

The example gene expression data that we have available here contains gene expression profiles for different samples in the columns. Of note, this is just a small subset of a larger gene expression dataset. We provided these "toy" data so that the user can test the method.

However, if you plan to model gene regulatory networks on your own dataset, you should use your own expression data as input.

Results

Example Panda output:
TF  Gene  Motif Force
---------------------
CEBPA	AACSL	0.0	-0.951416589143
CREB1	AACSL	0.0	-0.904241609324
DDIT3	AACSL	0.0	-0.956471642313
E2F1	AACSL	1.0	3.6853160511
EGR1	AACSL	0.0	-0.695698519643

Example lioness output:
Sample1 Sample2 Sample3 Sample4
-------------------------------
-0.667452814003	-1.70433776179	-0.158129613892	-0.655795512803
-0.843366539284	-0.733709815256	-0.84849895139	-0.915217389738
3.23445386464	2.68888472802	3.35809757371	3.05297381396
2.39500370135	1.84608635425	2.80179804094	2.67540878165
-0.117475863987	0.494923925853	0.0518448588965	-0.0584810456421

TF, Gene and Motif order is identical to the panda output file.

Python 3.4 is not yet supported but most of the code should also work there

About

Python implementation of PANDA and LIONESS

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 99.7%
  • Shell 0.3%