Source code for tooluniverse.l1000fwd_tool

"""
L1000FWD Tool

Provides access to the L1000FWD (L1000 Fireworks) API for Connectivity Map signature search.
L1000FWD enables querying LINCS L1000 chemical and genetic perturbation signatures
using a user-defined gene expression signature (up- and down-regulated genes).

API: https://maayanlab.cloud/L1000FWD/
No authentication required.
"""

import requests
from typing import Dict, Any, List
from .base_tool import BaseTool
from .tool_registry import register_tool

L1000FWD_BASE_URL = "https://maayanlab.cloud/L1000FWD"


[docs] @register_tool("L1000FWDTool") class L1000FWDTool(BaseTool): """ Tool for querying the L1000FWD Connectivity Map API. Provides access to: - Signature search: find L1000 signatures similar or opposite to a user gene set """
[docs] def __init__(self, tool_config: Dict[str, Any]): super().__init__(tool_config) self.parameter = tool_config.get("parameter", {}) self.required = self.parameter.get("required", [])
[docs] def run(self, arguments: Dict[str, Any]) -> Dict[str, Any]: """Execute the L1000FWD tool with given arguments.""" operation = arguments.get("operation") if not operation: return {"status": "error", "error": "Missing required parameter: operation"} operation_handlers = { "sig_search": self._sig_search, } handler = operation_handlers.get(operation) if not handler: return { "status": "error", "error": f"Unknown operation: {operation}", "available_operations": list(operation_handlers.keys()), } try: return handler(arguments) except requests.exceptions.Timeout: return {"status": "error", "error": "L1000FWD API request timed out"} except requests.exceptions.ConnectionError: return {"status": "error", "error": "Failed to connect to L1000FWD API"} except Exception as e: return {"status": "error", "error": f"Operation failed: {str(e)}"}