Free audit for one project, up to 30 samples. No payment today. Request yours

CodeISB / Blog

How to find a sample swap in your RNA-seq data

2026-11-05 · 5 min read

A swapped sample does not announce itself. The pipeline runs, the p-values come out, and the mistake sits inside the result until someone looks at the right plot. Here are three checks that catch most swaps using only your count matrix and your sample sheet.

How swaps happen

Almost always by hand. Two tubes get switched at the bench, a plate layout is read in the wrong direction, a file is renamed during upload, or a sample sheet is typed from memory weeks after the run. None of these leave a trace in the sequencing data itself, which is why they survive so long.

Published work shows the problem is not rare. A 2016 analysis in F1000Research found that 46% of 70 public gene expression datasets had samples whose recorded sex disagreed with what their own expression showed, and an earlier study of 45 datasets found 40%. Both used microarrays and cannot tell a tube swap from a typo in the metadata, but both show how often labels go wrong unnoticed.

Check 1: does the sex in your sample sheet match the expression?

If your samples come from both sexes, this is the fastest identity check there is. In human data, the X-inactivation gene XIST is high in female-derived samples and close to zero in male ones, while Y-chromosome genes such as RPS4Y1, DDX3Y and KDM5D show the reverse. Mouse has equivalents (Xist, Ddx3y, Kdm5d).

Plot XIST against a Y-gene for every sample and color by the sex in your sheet. Each sample should fall clearly into one of two groups. A point in the wrong group is a mislabeled or swapped sample until proven otherwise.

Limit: it only works when the experiment includes both sexes, and it cannot see a swap between two samples of the same sex.

Check 2: does each sample resemble its own replicates?

Compute the correlation between all pairs of samples (Spearman on log-transformed, normalized counts works well). Replicates of the same condition should correlate more strongly with each other than with samples from other conditions. A common rule of thumb is that biological replicates of the same condition should have a correlation of about 0.9 or higher, though the right number depends on the tissue and the design.

The useful question is relative: for each sample, is it closer to its own group or to a different one? A sample labeled as treated that correlates better with the controls is a swap candidate. Use the median correlation to each group, not the mean, so that one noisy sample does not drag the result.

Check 3: does the PCA put every sample where you expect?

Run a PCA on the normalized, log-transformed counts and color the points by condition, then again by batch. Samples should cluster by the biology you designed the experiment around. One sample sitting inside the wrong cluster is the picture a swap leaves behind. PCA also shows outlier libraries that are not swaps at all, which you want to know about anyway.

What these checks cannot prove

Expression-based checks give you evidence, not a verdict. A flagged sample might be a swap, a mislabel in the sheet, a real biological outlier or a failed library. They also miss swaps between samples that look alike. The definitive test compares genotypes: variants called from the reads should match between the RNA sample and an independent DNA or genotype record from the same individual. That needs read-level data and a matching reference, which a count matrix alone does not contain.

What to do when something is flagged

  • Go back to the bench records and the plate map before touching the data.
  • Do not silently drop or relabel the sample. Write down what you found and what you decided.
  • If you cannot resolve it, rerun the analysis with and without the sample and report both.
  • Run the same checks on the next dataset before you analyze it, not after.

Do not find out after it costs you

CodeISB checks your count matrix and sample sheet for swapped samples, weak libraries and batch confounding, and returns a one-page report. No raw reads or patient identifiers needed.

The first audit is free. Current prices hold for 12 months from your first project; later customers pay list.

Get your free audit