Skip to main content

A workflow for LDA analysis of microbiome data using MALLET

Project description

Microbiome LDA Topic Modeling Workflow

Overview

This workflow implements Latent Dirichlet Allocation (LDA) topic modeling for microbiome data analysis using MALLET through the my_little_warp Python interface.

Workflow Illustration

Please refer to the workflow diagram in Workflow Diagram for a visual representation of the process.

Workflow Steps

The workflow consists of three steps, corresponding to three .py files. The first step may take significant time to run (depends on the size of your data, potentially hours). Once all models are calculated, you can select an optimal model based on evaluation metrics and domain interpretation. Three types of data are required: an ASV table (rows represent samples, columns represent features), a taxonomy mapping file, and sample metadata. You can find examples of these data files in the example folder.

Step 0: Data Transforming (step0_DataPreprocessing(MALLET).py)

Inputs

  • Input ASV abundance table and taxonomy file paths
  • ASV abundance table requires a CSV file where the index contains samples and columns contain features (ASV IDs), with values as raw counts instead of relative abundance values
  • Taxonomy table requires a CSV file where the index contains ASV IDs and columns include taxonomy levels (Domain, Kingdom, Phylum, Class, Order, Family, Genus, and Species)

Process

  • Annotating ASVs based on genus level, falling back through taxonomic hierarchy (Family → Order → Class → Phylum) when genus is missing/uncultured. Assign unique IDs to ASVs that share the same annotation, allowing ASV-level interpretation
  • Creating random IDs for each ASV to avoid LDA package's built-in data processing
  • Transforming data format - Converting ASV abundance tables into document format where each sample becomes a "document" with taxa repeated based on their abundance counts
  • Preparing Mallet input - Creating training files for the Mallet LDA toolkit

Outputs

Get a dictionary including:

  • asvtable: Transposed ASV abundance matrix
  • taxa_split: Enhanced taxonomy table with genus-based names, sequential IDs, and random IDs
  • sampletable_randomID: ASV table with columns renamed to random IDs for anonymization
  • paths: Dictionary of all created directory and file paths for the analysis pipeline

Step 1: Model Building (step1_loop_.py)

  • Inputs include ASV table and taxonomy mapping file.
  • Explore topic models across a predefined range of topics (K)
  • Default K range: 2 to 21 microbe components (MC), but adjust this range based on your research question
  • Fewer models will take less time to run
  • Utilize MALLET for robust LDA topic modeling
  • Implement through my_little_warp Python interface

Step 2: Model Evaluation (step2_selection(new).py)

  • Calculate and analyze key evaluation metrics
  • Metrics include:
    • Coherence scores
    • Perplexity
    • Number of microbe component clusters in all models (Ideally, K should not exceed this number)
  • Compare performance across different numbers of topics

Step 3: Model Selection and Visualization (step3_visualization.py)

  • Inputs include which K you selected.
  • Make an informed decision on the optimal number of topics
  • Generate visualizations to support topic interpretation
  • Create:
    • MC-sample heatmap, annotated by selected metadata
    • MC-ASV heatmap
    • Interpretative visualizations of microbiome topics

Key Considerations

  • Careful selection of K (number of topics)
  • Interpretation of topics in the biological context
  • Validation of results

Output

Comprehensive analysis of microbiome data through probabilistic topic modeling

Installation

Clone the repository

git clone https://github.com/username/microbiome-lda-workflow.git cd microbiome-lda-workflow

Create and activate conda environment

conda env create -f environment.yml conda activate microbiome-lda

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lda4microbiome-0.1.3.tar.gz (32.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lda4microbiome-0.1.3-py3-none-any.whl (32.7 kB view details)

Uploaded Python 3

File details

Details for the file lda4microbiome-0.1.3.tar.gz.

File metadata

  • Download URL: lda4microbiome-0.1.3.tar.gz
  • Upload date:
  • Size: 32.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.18

File hashes

Hashes for lda4microbiome-0.1.3.tar.gz
Algorithm Hash digest
SHA256 4f0cb98fc7744b997499efad9c79d20280f8ed45bede1202f75a40075c8c443b
MD5 a8ae0dd70e4b48c17134977b247feddc
BLAKE2b-256 ffb41980ba2637018d0f359412b4ea34dbecf83c06b7dd47f98f5b559de67112

See more details on using hashes here.

File details

Details for the file lda4microbiome-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: lda4microbiome-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 32.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.18

File hashes

Hashes for lda4microbiome-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 7a007d9b39da5427cada8bcfc2f5b03fa64e008b07856029e1aed84d50a02b22
MD5 4f4e1208dc93b42b3a6896fe41b14c70
BLAKE2b-256 ca26397fc0bb717cc8e20b0a22aac69478f12840ab7a1d607a763cf4b4a5139c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page