Connecting General-Purpose LLMs to Scientific Research Platforms: AI for Science in Practice

    Large language models are moving from code editors into the laboratory, with biology and chemistry emerging as key application areas for AI-driven science. This article explains how general-purpose LLMs can be integrated into existing research computing platforms as agents, walks through a complete single-cell RNA analysis example from a single natural-language instruction to candidate genes, and outlines the common pitfalls and biological limitations teams should understand before adopting such workflows.

    Large language models are moving from code editors into the laboratory. Complex research domains such as biology and chemistry are becoming new ground for LLM applications, and drug discovery and materials research are generating fresh demand as a result. This article explains how general-purpose LLMs can be integrated into scientific research platforms, which parts of the workflow they can handle, and the limitations to keep in mind when putting them into practice.

    What Research Scenarios Demand from Models

    The core of scientific research is formulating hypotheses, designing experiments, collecting data, and validating conclusions. LLMs have two natural advantages here: first, they can digest large volumes of unstructured content such as papers, lab notebooks, and experimental protocols; second, they can write analysis code from natural-language descriptions.

    Compared with ordinary business scenarios, research places much higher demands on models. A model needs reliable logical reasoning, the ability to handle long literature contexts, and a solid grasp of domain terminology. For example, “pseudotime” means something different in developmental biology than in general data analysis. If the model misunderstands the term, the downstream code may produce conclusions that look plausible but do not hold up.

    The Four-Layer Structure of a Research Agent

    The most common approach today is to connect an LLM to an existing research computing platform, where it acts as an agent responsible for part of the analysis pipeline. This avoids rebuilding tool libraries from scratch and lets the model work directly within an environment that is already configured.

    A research agent typically consists of four layers:

    1. Intent understanding layer: Breaks down a researcher’s natural-language question into concrete computational steps, such as quality control, dimensionality reduction, clustering, and differential analysis.
    2. Code generation layer: Generates scripts for each step—usually Python code—calling bioinformatics or computational chemistry libraries.
    3. Tool invocation layer: The model decides which external APIs or built-in tools to call, such as cell type annotation tools or gene expression databases. Tools should be managed through a whitelist so the model can only invoke authorized ones.
    4. Execution environment layer: Code runs in an isolated sandbox. Results such as charts, data tables, and logs are returned to the model for the next round of reasoning, or presented directly to the user.

    These four layers form a closed loop. The model chains together questions, code, and tools into an automated or semi-automated analysis workflow. Execution results still require human review—model output must never be treated as a scientific conclusion on its own.

    A Single-Cell Example: From One Instruction to Candidate Genes

    Consider single-cell transcriptome analysis as a concrete example. Suppose a team has a dataset of 3,696 mouse pancreatic cells, all sampled from a single developmental time point. The researchers want to infer possible state transitions among these cells and identify candidate genes.

    The instruction the researcher enters is: “Based on the existing dataset, infer the state transition paths between cells and output the top 100 candidate genes for each cell cluster.”

    The agent generates illustrative code like the following. This version corrects two common issues: a missing diffusion map step before pseudotime analysis, and a candidate gene extraction method that does not match the requirement to select genes per cell cluster.

    1. import numpy as np
    2. import scanpy as sc
    3. # 1. Read and perform quality control
    4. adata = sc.read_h5ad('mouse_pancreas.h5ad')
    5. sc.pp.filter_cells(adata, min_genes=200)
    6. sc.pp.filter_genes(adata, min_cells=3)
    7. sc.pp.normalize_total(adata, target_sum=1e4)
    8. sc.pp.log1p(adata)
    9. # 2. Highly variable genes, dimensionality reduction, and clustering
    10. sc.pp.highly_variable_genes(adata, n_top_genes=2000)
    11. sc.pp.pca(adata, n_comps=50)
    12. sc.pp.neighbors(adata, n_neighbors=10, n_pcs=30)
    13. sc.tl.leiden(adata, resolution=0.5) # requires leidenalg and igraph
    14. sc.tl.umap(adata)
    15. # 3. Pseudotime: diffusion map + root cell + DPT
    16. sc.tl.diffmap(adata, n_comps=10)
    17. root_cluster = '0' # the root cluster must be determined by biological markers
    18. adata.uns['iroot'] = int(np.flatnonzero(adata.obs['leiden'] == root_cluster)[0])
    19. sc.tl.dpt(adata)
    20. # 4. Select candidate genes per cell cluster
    21. sc.tl.rank_genes_groups(adata, 'leiden', method='wilcoxon')
    22. candidate_genes = {}
    23. for group in adata.obs['leiden'].cat.categories:
    24. df = sc.get.rank_genes_groups_df(adata, group=group)
    25. candidate_genes[group] = df.head(100)['names'].tolist()
    26. print(candidate_genes)

    Three points about this code deserve explanation. First, sc.tl.dpt depends on the diffusion map, so sc.tl.diffmap must run beforehand. Second, the root cell determines the starting point of pseudotime. The code uses cluster '0' as an example; in a real analysis, you should choose the cluster containing known progenitor cells or marker genes of the starting state. Third, adata.uns['rank_genes_groups'] is a structured array. Slicing it directly to take the top 100 mixes results from all cell clusters together, making it impossible to tell which cluster each gene belongs to. Reading results per cluster is much clearer.

    There is also a biological limitation to this analysis. Pseudotime reflects similarity relationships between cells in expression space, not real developmental time. When the data comes from a single time point, what the model infers is the plausibility of a state ordering—it cannot be treated as a chronological developmental history. Validating the inferred paths requires multi-time-point data, lineage tracing experiments, or cross-checking against known marker genes.

    Runtime depends on hardware configuration and data size. This article deliberately avoids giving time-comparison figures between manual and automated workflows; teams should measure actual runtimes on their own data before deciding whether to scale up the approach.

    Common Errors and Troubleshooting

    The fact that agent-generated code runs does not mean the results are correct. The following problems come up frequently in practice:

    • Missing dependencies: Leiden clustering requires leidenalg and igraph; version mismatches will raise errors directly. Pin the versions and record dependencies in an environment configuration file.
    • Missing pseudotime prerequisites: Without running the diffusion map or setting a root cell, DPT results are uninterpretable or will fail outright.
    • Batch effects: If samples come from multiple batches, clustering directly may mistake batch differences for cell type differences. Check the distribution of each batch on the UMAP first.
    • Irreproducible results: Clustering resolution, random seeds, and the number of highly variable genes all change the outcome. Record these parameters during analysis and fix the random seed.