File size: 1,524 Bytes
469e58f
82ea511
 
 
 
 
469e58f
 
 
 
82ea511
 
 
 
469e58f
82ea511
 
469e58f
82ea511
469e58f
 
 
82ea511
 
469e58f
82ea511
469e58f
82ea511
 
 
469e58f
82ea511
 
 
 
 
 
 
 
469e58f
82ea511
469e58f
82ea511
 
 
 
 
 
 
 
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
# genesis/literature.py
"""
Literature intelligence for GENESIS-AI
Fetches biomedical, biotech, and synthetic biology publications.
"""

import os
import requests

NCBI_EMAIL = os.getenv("NCBI_EMAIL")
PUBMED_SEARCH_URL = "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi"
PUBMED_FETCH_URL = "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi"

CHEMBL_API = "https://www.ebi.ac.uk/chembl/api/data/molecule"

def search_pubmed(query, max_results=10):
    """Search PubMed and return article IDs."""
    try:
        params = {
            "db": "pubmed",
            "term": query,
            "retmax": max_results,
            "retmode": "json",
            "email": NCBI_EMAIL
        }
        r = requests.get(PUBMED_SEARCH_URL, params=params)
        r.raise_for_status()
        return r.json()
    except Exception as e:
        return {"error": str(e)}

def fetch_pubmed_details(id_list):
    """Fetch details for a list of PubMed IDs."""
    try:
        ids = ",".join(id_list)
        params = {"db": "pubmed", "id": ids, "retmode": "xml"}
        r = requests.get(PUBMED_FETCH_URL, params=params)
        r.raise_for_status()
        return r.text  # XML response
    except Exception as e:
        return {"error": str(e)}

def search_chembl(query):
    """Search ChEMBL molecules by name."""
    try:
        r = requests.get(f"{CHEMBL_API}?molecule_synonyms__icontains={query}")
        r.raise_for_status()
        return r.json()
    except Exception as e:
        return {"error": str(e)}