Skip to content

Examples Gallery

Interactive Jupyter notebooks demonstrating LZGraphs in action.

Available Notebooks

AAPLZGraph Example

AAPLZGraph Example

Complete amino acid graph tutorial

Build graphs, calculate probabilities, generate sequences, and visualize results.

View Notebook

NDPLZGraph Example

NDPLZGraph Example

Nucleotide sequence analysis

Work with nucleotide CDR3 sequences using double positional encoding.

View Notebook

Metrics Example

Metrics Example

Diversity and entropy analysis

Calculate K1000, LZCentrality, entropy metrics, and compare repertoires.

View Notebook

NaiveLZGraph Example

NaiveLZGraph Example

Feature extraction for ML

Use NaiveLZGraph for consistent feature vectors and cross-repertoire analysis.

View Notebook

Running Notebooks Locally

1. Clone the Repository

git clone https://github.com/MuteJester/LZGraphs.git
cd LZGraphs

2. Install Dependencies

pip install -e .
pip install jupyter

3. Launch Jupyter

cd Examples
jupyter notebook

Sample Data

The examples use these datasets included in the repository:

File Description Sequences
ExampleData1.csv TCR repertoire sample 1 ~20,000
ExampleData2.csv TCR repertoire sample 2 ~15,000
ExampleData3.csv TCR repertoire sample 3 ~10,000

Data Format

import pandas as pd

data = pd.read_csv("Examples/ExampleData1.csv")
print(data.columns.tolist())
# ['cdr3_amino_acid', 'cdr3_rearrangement', 'V', 'J']

print(data.head())

Quick Examples

Build Your First Graph

import pandas as pd
from LZGraphs import AAPLZGraph

# Load example data
data = pd.read_csv("Examples/ExampleData1.csv")

# Build graph
graph = AAPLZGraph(data, verbose=True)

# Check stats
print(f"Nodes: {graph.graph.number_of_nodes()}")
print(f"Edges: {graph.graph.number_of_edges()}")

Calculate Diversity

from LZGraphs import K1000_Diversity, AAPLZGraph

sequences = data['cdr3_amino_acid'].tolist()
k1000 = K1000_Diversity(sequences, AAPLZGraph.encode_sequence, draws=30)
print(f"K1000: {k1000:.1f}")

Generate Sequences

# Generate with gene constraints
walk, v_gene, j_gene = graph.genomic_random_walk()
sequence = ''.join([AAPLZGraph.clean_node(n) for n in walk])
print(f"Generated: {sequence}")
print(f"V: {v_gene}, J: {j_gene}")

What's Covered

Notebook Topics
AAPLZGraph Graph construction, probabilities, random walks, visualization
NDPLZGraph Nucleotide encoding, double positions, gene analysis
Metrics K-diversity, entropy, perplexity, JS divergence
NaiveLZGraph Fixed dictionaries, eigenvector centrality, ML features

Next Steps