Track A: Bulk RNA-seq

Track: Bulk RNA-seq

Introduction to agentic AI

About this lecture

A sequencing facility sends you a table of read counts and asks nothing more. Turning it into a list of changed genes, and that list into biology, is a standard analysis with well-known pitfalls. In this track you do the whole analysis by prompting: the agent installs R and DESeq2, writes and runs the scripts, and you judge every step.

  • The sample sheet decides everything. A wrong label or a wrong match gives a confident, wrong answer.
  • Look before you test. Library sizes, PCA and sample correlations show swaps, outliers and batches.
  • The design formula is a sentence. “Compare treated with control within each day” is ~ batch + treatment.
  • Check with what you know. A known answer, known genes, padj instead of p, a rerun from scratch.
  • The agent reports; you decide. It must never drop or relabel a sample on its own.

This is a track: the agent skills from Parts 1 to 4 on RNA-seq data. Statistics only as deep as needed to judge the result. It builds on the table from Literature review.

A count table arrives with one question: which genes changed?

You decide and check; the agent types and runs

  • You never write R. You do read the sample sheet, the design formula and the plots.
  • Every decision about samples and cut-offs is yours, written down in decisions.md.

The analysis is a pipeline with a check at every step

We use two datasets: one with a known answer, one real

Synthetic pilot airway (real, public)
What made-up drug experiment, 10 000 genes human airway smooth-muscle cells, dexamethasone vs untreated
Samples 12: 6 control, 6 treated, two extraction days 8: four cell lines, each untreated and treated
Source synthetic-rnaseq.zip on the exercise page the Bioconductor package airway (Himes et al. 2014, GEO GSE52778)
Known answer 400 planted genes, a planted problem in the sample sheet known glucocorticoid-response genes (FKBP5, TSC22D3, PER1 …)
Used for QC, the sample sheet, the design, multiple testing volcano, MA, enrichment, the literature link

Start with the synthetic data. Only there can you check the agent against the truth.

A count table holds whole numbers: reads per gene per sample

The sample sheet must be matched by name, never by position

First prompt: make the agent describe the data back to you

This folder holds an RNA-seq experiment: data/raw/counts.csv (raw counts,
genes x samples), data/raw/samples.csv (the sample sheet) and
data/raw/lab-notes.txt. Do not analyse anything yet.

Read the three files and tell me:
- how many genes and samples there are, and whether all values are
  whole numbers
- each sample with its group and batch, matched BY NAME between the
  count table and the sample sheet, as a table
- any sample that is in one file but not the other
- anything in the lab notes that could affect the analysis
Do not change any file in data/raw.

What you check: 12 samples in both files, 6 per group, the matched table agrees with the sheet, and the agent mentions the note about S08 and S11.

The project folder keeps raw data, scripts and results apart

  • The agent installs R (if needed) and the Bioconductor package DESeq2. It asks before it installs; this can take a while.

QC 1: library sizes show how deeply each sample was sequenced

  • S03 has about 5 times fewer reads. Low depth alone is not a reason to remove a sample: DESeq2 corrects for depth.
  • Ask what else is odd about it. Here, nothing: it groups with its controls (next slides).

QC 2: in the PCA, two samples sit with the wrong group

QC 3: sample correlations tell the same story

The agent must report odd samples, never fix them on its own

The prompt for the QC step says so explicitly:

Write scripts/01-qc.R that makes, in results/qc/: a bar chart of library
sizes, a PCA plot coloured by treatment and shaped by batch, and a
heatmap of sample correlations. Run it and show me the plots.

Then tell me which samples, if any, look unusual and why. Do NOT remove,
relabel or reweight any sample. I will decide. List what you would
recommend and what I could check in the lab to settle it.
  • Agents tend to “solve” problems: drop the outlier, swap the labels, mention it in passing.
  • A silently dropped or relabelled sample is a changed experiment that nobody reviewed.

You decide about the swap, and write the decision down

The design formula says what is compared, in one line

Ask the agent to explain the design in words before it runs

Before running DESeq2, tell me in plain words:
- the design formula you will use, and what each term means for
  this experiment
- which group is the reference, so that a positive log2 fold change
  means "higher in treated"
- how many samples are in each group after any changes I approved
- whether anything about the design worries you (batch, pairing,
  too few replicates)
Then write scripts/02-deseq2.R, run it, and save the full results table.
Check Synthetic pilot airway
Design ~ batch + treatment ~ cell + dex
Reference control untreated (untrt); R sorts trt first unless told otherwise
n per group 6 and 6 4 and 4, paired by cell line

Replicates are the samples you count, and you need several

  • n per group is the number of independent biological replicates: separate animals, patients, cultures.
  • Two wells from one culture, or one library sequenced twice, are one replicate.
  • With 1 sample per group there is no way to estimate noise. DESeq2 results are then not meaningful.
  • 3 per group is a common minimum; more gives more power. airway: 4 pairs. Synthetic: 6 per group.
  • The agent cannot know how your samples were made. Tell it, in the README or the prompt.

DESeq2 does three things in one command

The results table has one row per gene

Column Plain meaning What to check
baseMean average normalised count over all samples very low: little information
log2FoldChange change between groups: 1 = 2-fold up, -1 = 2-fold down, 3 = 8-fold up sign matches the reference you chose
lfcSE how uncertain that fold change is large for genes with few reads
pvalue evidence against “no change”, for this gene alone do not use it to pick genes
padj p-value adjusted for testing all genes use this; NA = not tested (too few reads)

Ask the agent to save the full table (every gene), not only the significant ones. A gene missing from a list can be “not changed” or “not tested”.

Testing 10 000 genes at p < 0.05 gives hundreds of false hits

  • At p < 0.05, about 1 in 20 unchanged genes passes by chance: here 551 of them.
  • padj < 0.05 keeps the share of false hits small: here 38 of 421. Small, not zero.

The known answer shows what the swap would have cost

The volcano plot shows size and certainty of every change

Genes you already know are the quickest sanity check

Gene Expected with a glucocorticoid airway result (our run)
FKBP5 up, classic marker log2FC 4.0 (16-fold up), padj 7e-26
TSC22D3 (GILZ) up log2FC 3.2, padj 3e-19
PER1 up log2FC 3.2, padj 2e-81
DUSP1 up log2FC 2.9, padj 1e-124
KLF15 up log2FC 4.5, padj 8e-78
GAPDH no change (housekeeping) log2FC -0.2, padj 0.38

If FKBP5 came out down, the reference level is wrong. If nothing you know shows up, check the sample sheet before the biology.

Enrichment asks whether a pathway is over-represented in your list

Enrichment tools differ in what you give them

Tool How What to give it Watch out for
g:Profiler (web, or the R package gprofiler2) paste a list, or the agent calls it significant genes, and the tested genes as a custom background default background is all known genes
clusterProfiler (R) over-representation or ranked tests gene list + background, or all genes ranked gene IDs converted correctly (Ensembl ↔︎ symbol); genes lost in conversion
fgsea (R) ranked: no cut-off needed every tested gene with a score (e.g. the test statistic) which gene sets, which version

Ask how many genes went in and how many were lost in ID conversion. Many “enriched” terms are the same few themes; enriched does not mean causal.

A rerun from scratch proves the result lives in the scripts

The checklist before you believe a gene list

Your own RNA-seq data: check what you may send

  • Counts from cell lines, animals, plants, microbes: usually fine as internal research data. Check unpublished-data rules with your group.
  • Counts from human participants: personal data under GDPR, even with codes instead of names. Expression can reveal sex, ancestry and disease.
  • Raw reads (FASTQ, BAM) from humans: genetic data, a special category. Never into a cloud agent without explicit approval.
  • The sample sheet often holds the most sensitive part: age, sex, diagnosis, dates. Send only the columns the analysis needs.
  • When in doubt: a synthetic stand-in with the same structure, as in Privacy, ethics and safety.

Where this goes wrong

  • Matching by position. Sample sheet and count columns in different orders: a wrong answer with no error.
  • Silent sample changes. An outlier dropped, a swap “fixed”, a low-depth sample excluded, mentioned in passing or not at all.
  • Wrong reference level. Every fold change has the wrong sign; known genes go “down”.
  • Normalised data into DESeq2. It needs raw counts. CPM, TPM or log values give wrong tests.
  • p instead of padj. Hundreds of false hits that look like real ones.
  • Technical repeats counted as replicates. Too many significant genes and false confidence.
  • Whole-genome background in enrichment: tissue-typical pathways look “enriched”.
  • Invented biology. A fluent paragraph about what the genes “do”, with references nobody checked.
  • Different numbers on rerun. A step lived only in the chat.

Summary

Concept Key fact
Division of labour you decide and check; the agent installs, writes and runs R
Count table raw whole numbers, genes x samples; column totals = depth
Sample sheet match by name; print the matched table; never trust position
QC library sizes, PCA, correlations: swaps, outliers, batches
Odd samples the agent reports and recommends; you decide; decisions.md
Design formula ~ batch + treatment = compare within each batch; say it in words

Summary (continued)

Concept Key fact
Reference level decides the sign; check with a known gene
Replicates independent biological samples; 3 per group is a common minimum
padj use it, not p; expect a few false hits even so
Enrichment against the tested genes; check ID conversion; enriched is not causal
Literature link join with your verified table; new genes, new references checked
Rerun fresh session, scripts only, same numbers

Next (From gene lists to mechanisms): the second deck of this track: a literature review of your top genes, the regulators behind them, and a mechanism with testable predictions.