suzannejin's picture
add functions for nf-core module yaml i/o extraction
2e4a27d
import gradio as gr
import requests
import re
import yaml
def fetch_module(url: str) -> str:
"""
Fetch the raw content of a file from a GitHub URL.
Args:
url (str): The URL of the GitHub file. Can be a standard GitHub URL or a raw URL.
Returns:
str: The raw text content of the file.
Raises:
requests.HTTPError: If the HTTP request fails.
"""
if "github.com" in url and "raw.githubusercontent.com" not in url:
url = url.replace("github.com", "raw.githubusercontent.com").replace("/blob/", "/")
response = requests.get(url)
response.raise_for_status()
return response.text
def extract_nfcore_meta_io(url: str) -> dict:
"""
Extract input and output metadata from a nf-core module YAML file.
Args:
url (str): The URL to the nf-core module's meta.yml file.
Returns:
dict: A dictionary with 'inputs' and 'outputs' keys, each containing lists of files or terms.
Example:
{
"inputs": [...],
"outputs": [...]
}
"""
content = fetch_module(url)
meta = yaml.safe_load(content)
inputs = meta.get("input", [])
outputs = meta.get("output", [])
return {"inputs": inputs, "outputs": outputs}
with gr.Blocks() as demo:
gr.Markdown("# Multi-Tool App")
with gr.Tab("nf-core Module Meta i/o Extractor"):
gr.Interface(
fn=extract_nfcore_meta_io,
inputs=gr.Textbox(
placeholder="Paste nf-core module URL...",
label="nf-core module meta.yml URL",
info="Paste the URL to the meta.yml file of a nf-core module. Example: https://github.com/nf-core/modules/blob/master/modules/nf-core/fastqc/meta.yml"
),
outputs=gr.JSON(label="Meta inputs and outputs"),
title="nf-core Module Meta i/o Extractor",
description="Extracts input/output files from a nf-core module's meta.yml file. Provide the URL to the meta.yml file in a nf-core module repository."
)
# Launch the interface and MCP server
if __name__ == "__main__":
demo.launch(mcp_server=True)