.label-wrap { display: none !important; }
.model-quick-btn button {
font-size: 12px !important; font-weight: 600 !important;
padding: 6px 14px !important; border-radius: 8px !important;
border: 1.5px solid #C8D0E7 !important; background: #FFFFFF !important;
color: #5A6480 !important; transition: all 0.15s ease !important;
}
.model-quick-btn button:hover {
border-color: #5BA8E5 !important; color: #2C5F8A !important; background: #EBF5FF !important;
}
"""
SAMPLE_DATA = """ID,Phenotype,chr1_134521_SNP1,chr1_134810_SNP2,chr1_178766_SNP3,chr1_210328_SNP4
chromosome,1,1,1,1
IRRI-1,25.34,0,0,0,2
IRRI-75,23.34,0,0,0,0
IRRI-84,26.67,2,0,2,0
IRRI-93,23,0,0,0,1
IRRI-9,28.34,0,0,0,0
IRRI-17,18.67,0,0,0,0
IRRI-25,20,2,0,2,0
IRRI-34,37,0,0,0,0
IRRI-42,30.67,0,0,0,0
IRRI-50,22,0,0,0,2"""
ALL_MODELS = ["OLS", "MLM", "GLM", "CMLM", "BLINK", "FarmCPU", "EMMAX", "PLINK", "GAPIT3", "GEMMA"]
MODEL_INFO_HTML = """
OLS/PLINK — baseline, no correction |
GLM — PCs only |
EMMAX/GEMMA — fast REML LMM ✓ |
MLM — exact GLS |
FarmCPU/BLINK/GAPIT3 — iterative QTN |
CMLM — compressed kinship
⚡ All plots are interactive — hover, zoom, click on SNPs!
"""
# ─────────────────────── GRADIO INTERFACE ─────────────────────────────────────
with gr.Blocks(css=PASTEL_CSS, title="🧬 GWAS Pipeline", theme=gr.themes.Base()) as demo:
gr.HTML("""
""")
with gr.Row(equal_height=False):
with gr.Column(scale=1, min_width=340):
gr.HTML('📂 Data Input
')
file_in = gr.File(label="Upload CSV / TSV / TXT",
file_types=[".csv", ".tsv", ".txt"])
text_in = gr.Textbox(label="Or paste CSV data", lines=7,
value=SAMPLE_DATA,
placeholder="Paste your CSV data here…")
gr.HTML('⚙️ Select Models to Run
')
gr.HTML(MODEL_INFO_HTML)
model_sel = gr.CheckboxGroup(
choices=ALL_MODELS,
value=ALL_MODELS,
label="Models",
elem_id="model-selector",
interactive=True,
)
with gr.Row():
gr.Button("✅ All", size="sm", elem_classes=["model-quick-btn"]).click(
fn=lambda: ALL_MODELS, outputs=model_sel)
gr.Button("☐ None", size="sm", elem_classes=["model-quick-btn"]).click(
fn=lambda: [], outputs=model_sel)
gr.Button("⚡ Fast", size="sm", elem_classes=["model-quick-btn"]).click(
fn=lambda: ["OLS", "GLM", "EMMAX", "PLINK", "GEMMA"], outputs=model_sel)
gr.Button("🔬 LMM", size="sm", elem_classes=["model-quick-btn"]).click(
fn=lambda: ["MLM", "EMMAX", "GEMMA", "CMLM"], outputs=model_sel)
gr.HTML('🎛️ Settings
')
maf_thr = gr.Slider(0, 0.5, value=0.05, step=0.01, label="MAF Threshold")
run_btn = gr.Button("🚀 Run GWAS Pipeline", variant="primary")
gr.HTML('📥 Downloads
')
with gr.Column(elem_classes=["download-section"]):
excel_out = gr.File(label="📊 Excel — All Results", interactive=False)
zip_out = gr.File(label="🖼 Static PNGs (ZIP)", interactive=False)
with gr.Column(scale=2):
gr.HTML('📊 Analysis Summary
')
summary_out = gr.Textbox(label="", lines=30,
elem_classes=["summary-box"],
show_label=False)
gr.HTML('🖼 Interactive Visualizations
')
with gr.Tabs():
with gr.Tab("🗺 Manhattan (Primary)"):
gr.HTML('Hover SNPs for details · Zoom with scroll · Click legend to toggle chromosomes
')
plot1 = gr.Plot(label="Manhattan — Primary Model")
with gr.Tab("📈 QQ (Primary)"):
gr.HTML('Hover points for p-values · λ shows genomic inflation
')
plot2 = gr.Plot(label="QQ Plot — Primary Model")
with gr.Tab("📊 QQ Overlay"):
gr.HTML('All models overlaid · Click legend to toggle · Compare λ values
')
plot3 = gr.Plot(label="QQ Overlay — All Models")
with gr.Tab("🔵 Circos (Best Models)"):
gr.HTML('Shows top 4 best-controlled models (λ closest to 1) · ◆ = genome-wide significant
')
plot4 = gr.Plot(label="Circos — Best Models")
with gr.Tab("🔗 LD Decay"):
gr.HTML('Hover for distance/r² values · Binned mean ± SEM shown
')
plot5 = gr.Plot(label="LD Decay")
with gr.Tab("🔬 PCA"):
gr.HTML('Color = phenotype value · Hover for sample ID
')
plot6 = gr.Plot(label="PCA")
with gr.Tab("👨👩👧 Kinship"):
gr.HTML('Hover cells for kinship coefficient · Distribution shows population structure
')
plot7 = gr.Plot(label="Kinship Matrix")
with gr.Tab("⚖ Effect Sizes"):
gr.HTML('Hover for SNP details · Red = GW significant · Green = positive effect
')
plot8 = gr.Plot(label="Effect Sizes & Volcano")
with gr.Tab("🔄 All Models (Stacked)"):
gr.HTML('All models stacked · Hover for SNP identity · λ shown per panel
')
plot9 = gr.Plot(label="Manhattan — All Models")
with gr.Tab("📊 Dashboard"):
gr.HTML('Summary statistics · Model concordance · Inflation control
')
plot10 = gr.Plot(label="Summary Dashboard")
def run_wrapper(file_obj, text_data, selected_models, maf):
if not selected_models:
selected_models = ALL_MODELS
out = run_gwas(file_obj, text_data, selected_models, maf)
while len(out) < 13:
out.append(None)
return out
run_btn.click(
fn=run_wrapper,
inputs=[file_in, text_in, model_sel, maf_thr],
outputs=[
plot1, plot2, plot3, plot4, plot5,
plot6, plot7, plot8, plot9, plot10,
excel_out, zip_out, summary_out
],
)
#
if __name__ == "__main__":
demo.launch(share=True, server_port=7860)