PyWGCNA: Python Weighted Gene Co-expression Network Analysis

repository·main·Indexed 43 days ago

https://github.com/mortazavilab/pywgcna

A Python library for Weighted Gene Co-expression Network Analysis (WGCNA) used to identify gene modules, relate them to traits, and compare networks across datasets. It provides tools for module discovery, functional enrichment analysis (GO, KEGG, REACTOME), and Protein-Protein Interaction (PPI) recovery via the STRING database. The API is organized into modules for gene expression processing (geneExp), core WGCNA algorithms (wgcna), network comparison (comparison), and utilities (utils).

Tokens
6.1K
Snippets
20
Records
37
Agent score
55%

What's inside PyWGCNA

  1. Overview of PyWGCNA capabilities

    main

    PyWGCNA is a Python library for weighted correlation network analysis (WGCNA). It is used for:

    • Module Discovery: Finding clusters (modules) of highly correlated genes.
    • Summarization: Using module eigengenes to summarize clusters.
    • Network Analysis: Relating modules to one another and to external sample traits using eigengene network methodology.
    • Membership: Calculating module membership measures.
    • Comparison: Comparing WGCNA networks across different datasets or against external gene lists to assess conservation or functional enrichment.
    • Functional Analysis: Performing enrichment analysis (GO, KEGG, REACTOME) and Protein-Protein Interaction (PPI) recovery using the STRING database.
  2. Explore the PyWGCNA API modules

    main

    The PyWGCNA API is organized into four primary modules, each handling a specific stage of the Weighted Gene Co-expression Network Analysis (WGCNA) workflow:

    • PyWGCNA.geneExp: Handles gene expression data processing and preparation.
    • PyWGCNA.wgcna: Contains the core WGCNA algorithms, including network construction and module identification.
    • PyWGCNA.comparison: Provides tools for comparing networks (e.g., between different conditions or tissues).
    • PyWGCNA.utils: Contains utility functions for data manipulation and general helper tasks.
  3. Interact with PyWGCNA objects

    main
    The PyWGCNA object is the central data structure. You can interact with it to access various parameters, results, and internal states. Use the PyWGCNA object tutorial to learn how to access specific attributes and manage object parameters.
  4. Understand the WGCNA methodology via suggested reading

    main

    If you are transitioning from R to pywgcna or are unfamiliar with the underlying Weighted Gene Co-expression Network Analysis (WGCNA) methodology, it is recommended to review the original R package documentation and publications to understand the mathematical and biological principles being implemented.

    Key resources include:

  5. Clean and preprocess data in PyWGCNA

    main

    PyWGCNA provides automated data cleaning and preprocessing steps to ensure data quality for network analysis:

    1. Expression Filtering: Removes genes that do not have expression values above the specified TPMcutoff (default is 1) across all samples.
    2. Missing Value Detection: Uses the goodSamplesGenes() function to identify and handle genes and samples with excessive missing values.
    3. Outlier Detection: Performs hierarchical clustering (using scipy.cluster.hierarchy) on samples to identify obvious outliers.
      • You can control the sensitivity of outlier removal by specifying a cut value for the clustering height.
      • By default, no samples are removed via hierarchical clustering.
  6. Input data using AnnData format

    main

    If your expression data is already in AnnData format, you can define your PyWGCNA object by passing the AnnData object to the geneExpr variable.

    Ensure your AnnData object follows these requirements:

    • AnnData.X: The expression matrix.
    • AnnData.var: Information about each gene.
    • AnnData.obs: Information about each sample.
    # Example conceptual usage
    # geneExpr = your_anndata_object
  7. Format, clean and preprocess data for PyWGCNA

    main
    Before running PyWGCNA analyses, you must ensure your input data is correctly formatted, cleaned, and preprocessed. Detailed instructions on the required data structures and cleaning steps can be found in the Data Format tutorial.
  8. Input data using separate matrices

    main

    You can provide gene expression, gene metadata, and sample metadata as separate files/matrices.

    Gene Expression Matrix

    • Rows: Samples.
    • Columns: Genes.
    • First Column: Must contain unique sample IDs or sample names.
    • Subsequent Columns: Must contain unique gene IDs or gene names.

    Gene Metadata

    • Rows: Each row represents a gene.
    • Columns: Metadata features (e.g., biotype, length).
    • First Column: Must contain the same gene identifiers used in the expression matrix.
    • Ordering: Rows should match the column order of the expression matrix, or you can set order=False.

    Sample Metadata

    • Rows: Each row represents a sample.
    • Columns: Metadata features (e.g., age, genotype).
    • First Column: Must contain the same sample identifiers used in the expression matrix.
    • Ordering: Rows should match the row order of the expression matrix, or you can set order=False.