File size: 5,609 Bytes
7a92197 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
#!/usr/bin/env python3
"""
Cancer@Home v2 - Main Entry Point
Quick start script for the entire application
"""
import sys
import time
import subprocess
import webbrowser
from pathlib import Path
from rich.console import Console
from rich.panel import Panel
from rich.progress import Progress, SpinnerColumn, TextColumn
import yaml
console = Console()
def load_config():
"""Load configuration"""
with open('config.yml', 'r') as f:
return yaml.safe_load(f)
def check_docker():
"""Check if Docker is running"""
try:
subprocess.run(['docker', 'ps'], capture_output=True, check=True)
return True
except:
return False
def setup_directories():
"""Create necessary directories"""
dirs = [
'data/gdc',
'data/boinc',
'data/processed/fastq',
'data/processed/blast',
'data/processed/variants',
'data/cache',
'logs'
]
for dir_path in dirs:
Path(dir_path).mkdir(parents=True, exist_ok=True)
def start_neo4j():
"""Start Neo4j container"""
console.print("[cyan]Starting Neo4j database...[/cyan]")
subprocess.run(['docker-compose', 'up', '-d'], check=True)
# Wait for Neo4j to be ready
console.print("[yellow]Waiting for Neo4j to be ready...[/yellow]")
time.sleep(10)
def initialize_database():
"""Initialize Neo4j database schema"""
from backend.neo4j.db_manager import DatabaseManager
console.print("[cyan]Initializing database schema...[/cyan]")
db = DatabaseManager()
db.initialize_schema()
console.print("[green]β Database initialized[/green]")
def start_backend():
"""Start FastAPI backend"""
console.print("[cyan]Starting backend server...[/cyan]")
import uvicorn
from backend.api.main import app
config = load_config()
# Run in background
import threading
def run_server():
uvicorn.run(
app,
host=config['app']['host'],
port=config['app']['port'],
log_level="info"
)
thread = threading.Thread(target=run_server, daemon=True)
thread.start()
time.sleep(3)
def open_browser():
"""Open browser to application"""
config = load_config()
url = f"http://{config['app']['host']}:{config['app']['port']}"
console.print(f"[green]β Opening browser at {url}[/green]")
time.sleep(2)
webbrowser.open(url)
def main():
"""Main entry point"""
console.clear()
# Display banner
banner = """
βββββββββββββββββββββββββββββββββββββββββββββ
β Cancer@Home v2.0 β
β Distributed Cancer Genomics Research β
βββββββββββββββββββββββββββββββββββββββββββββ
"""
console.print(Panel(banner, style="bold blue"))
try:
with Progress(
SpinnerColumn(),
TextColumn("[progress.description]{task.description}"),
console=console
) as progress:
# Setup
task = progress.add_task("[cyan]Setting up directories...", total=None)
setup_directories()
progress.update(task, completed=True)
# Check Docker
task = progress.add_task("[cyan]Checking Docker...", total=None)
if not check_docker():
console.print("[red]β Docker is not running. Please start Docker Desktop.[/red]")
sys.exit(1)
progress.update(task, completed=True)
# Start Neo4j
task = progress.add_task("[cyan]Starting Neo4j...", total=None)
start_neo4j()
progress.update(task, completed=True)
# Initialize database
task = progress.add_task("[cyan]Initializing database...", total=None)
initialize_database()
progress.update(task, completed=True)
# Start backend
task = progress.add_task("[cyan]Starting backend server...", total=None)
start_backend()
progress.update(task, completed=True)
console.print("\n[bold green]β Cancer@Home is running![/bold green]\n")
config = load_config()
console.print(f"[cyan]β Application:[/cyan] http://{config['app']['host']}:{config['app']['port']}")
console.print(f"[cyan]β Neo4j Browser:[/cyan] http://localhost:7474")
console.print(f"[cyan]β API Docs:[/cyan] http://{config['app']['host']}:{config['app']['port']}/docs")
console.print(f"[cyan]β GraphQL:[/cyan] http://{config['app']['host']}:{config['app']['port']}/graphql\n")
console.print("[yellow]Press Ctrl+C to stop the server[/yellow]\n")
# Open browser
open_browser()
# Keep running
while True:
time.sleep(1)
except KeyboardInterrupt:
console.print("\n[yellow]Shutting down...[/yellow]")
subprocess.run(['docker-compose', 'down'])
console.print("[green]β Goodbye![/green]")
sys.exit(0)
except Exception as e:
console.print(f"[red]β Error: {e}[/red]")
sys.exit(1)
if __name__ == "__main__":
main()
|