|
|
|
|
|
"""
|
|
|
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)
|
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
|
|
|
|
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:
|
|
|
|
|
|
|
|
|
task = progress.add_task("[cyan]Setting up directories...", total=None)
|
|
|
setup_directories()
|
|
|
progress.update(task, completed=True)
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
task = progress.add_task("[cyan]Starting Neo4j...", total=None)
|
|
|
start_neo4j()
|
|
|
progress.update(task, completed=True)
|
|
|
|
|
|
|
|
|
task = progress.add_task("[cyan]Initializing database...", total=None)
|
|
|
initialize_database()
|
|
|
progress.update(task, completed=True)
|
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
|
|
|
|
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()
|
|
|
|