#!/usr/bin/env python3
"""
Demo script to show the battle test results and functionality.
This demonstrates the gget-mcp server working with real APIs.
"""
import asyncio
import tempfile
import sys
from pathlib import Path
# Add the src directory to Python path for imports
sys.path.append(str(Path(__file__).resolve().parent.parent / "src"))
from gget_mcp.server import GgetMCP
async def demo_regular_mode():
"""Demonstrate regular mode functionality."""
print("𧬠DEMO: Regular Mode Functionality")
print("=" * 50)
server = GgetMCP()
# Search for TP53
print("1. Searching for TP53...")
search_result = await server.search_genes(["TP53"], "homo_sapiens", limit=2)
print(f" ā
Found {len(search_result)} results")
# Get gene info
print("2. Getting gene information...")
ensembl_id = "ENSG00000141510" # Known TP53 ID
info_result = await server.get_gene_info([ensembl_id])
print(f" ā
Retrieved information for {ensembl_id}")
# Get sequence (brief)
print("3. Getting DNA sequence...")
seq_result = await server.get_sequences([ensembl_id], translate=False)
if isinstance(seq_result, list) and len(seq_result) > 1:
sequence = seq_result[1].replace('\n', '').replace('\r', '')
print(f" ā
Retrieved {len(sequence)} bases")
else:
print(" ā
Retrieved sequence data")
print()
async def demo_local_mode():
"""Demonstrate local mode functionality with file outputs."""
print("š DEMO: Local Mode Functionality")
print("=" * 50)
with tempfile.TemporaryDirectory() as temp_dir:
server = GgetMCP(transport_mode="stdio-local", output_dir=temp_dir)
# Get sequences in local mode
print("1. Getting cancer gene sequences (DNA)...")
cancer_genes = ["ENSG00000141510", "ENSG00000012048"] # TP53, BRCA1
dna_result = await server.get_sequences_local(
ensembl_ids=cancer_genes,
translate=False,
format="fasta"
)
print(f" ā
DNA sequences saved to: {Path(dna_result['path']).name}")
print(f" š File size: {Path(dna_result['path']).stat().st_size} bytes")
# Get protein sequences
print("2. Getting protein sequences...")
protein_result = await server.get_sequences_local(
ensembl_ids=cancer_genes,
translate=True,
format="fasta"
)
print(f" ā
Protein sequences saved to: {Path(protein_result['path']).name}")
print(f" š File size: {Path(protein_result['path']).stat().st_size} bytes")
# Test PDB structure
print("3. Getting PDB structure...")
pdb_result = await server.get_pdb_structure_local(
pdb_id="1TUP",
format="pdb"
)
print(f" ā
PDB structure saved to: {Path(pdb_result['path']).name}")
print(f" š File size: {Path(pdb_result['path']).stat().st_size} bytes")
# Show file contents preview
print("\n4. File contents preview:")
with open(dna_result['path'], 'r') as f:
lines = f.readlines()[:3]
for line in lines:
print(f" {line.strip()}")
print(" ...")
print(f"\nš All files created in: {temp_dir}")
print()
async def demo_functional_analysis():
"""Demonstrate functional analysis capabilities."""
print("šÆ DEMO: Functional Analysis")
print("=" * 50)
server = GgetMCP()
# Enrichr analysis
print("1. Pathway enrichment analysis...")
try:
enrichr_result = await server.enrichr_analysis(
genes=["TP53", "BRCA1", "MYC"],
database="KEGG_2021_Human"
)
print(f" ā
Found {len(enrichr_result)} pathway results")
except Exception as e:
print(f" ā ļø Enrichr analysis skipped: {str(e)[:50]}...")
# OpenTargets analysis
print("2. Disease association analysis...")
try:
ot_result = await server.opentargets_analysis(
ensembl_id="ENSG00000141510", # TP53
resource="diseases",
limit=5
)
print(f" ā
Found {len(ot_result)} disease associations")
except Exception as e:
print(f" ā ļø OpenTargets analysis skipped: {str(e)[:50]}...")
print()
async def main():
"""Run the complete demo."""
print("š GGET-MCP BATTLE TEST DEMO")
print("=" * 60)
print("This demo shows the gget-mcp server working with real APIs")
print("Testing both regular and local (file-based) modes")
print("=" * 60)
print()
try:
await demo_regular_mode()
await demo_local_mode()
await demo_functional_analysis()
print("š DEMO COMPLETED SUCCESSFULLY!")
print("All systems operational with real bioinformatics data!")
print()
print("Key features demonstrated:")
print("ā
Gene search and information retrieval")
print("ā
DNA and protein sequence retrieval")
print("ā
File-based output in local mode")
print("ā
PDB structure retrieval")
print("ā
Functional analysis capabilities")
print("ā
Real API integration (no mocking)")
except Exception as e:
print(f"ā Demo failed: {e}")
raise
if __name__ == "__main__":
asyncio.run(main())