Differential Testing

We test which features differ between two groups of samples, using one method on both tables, and then look closely at how much a significant result is worth.

Slides

Make slides full screen

Exercise 1: Test the gene table with a grouping from the species table

Pi can run DESeq2 in a minute. Most of the decisions that shape the answer come before the test (which samples, which genes, which way round the contrast goes) or after it (which cutoff, which plot). Those decisions are yours, and this exercise has you look at several versions of each.

Open notebooks/04-differential.qmd and run the setup chunk. It reads back the community column you saved on Tuesday and joins it to the metadata. Start Pi with a fresh conversation.

Part 1: Predict

  1. We will test 13,738 genes. If no gene were truly different between the two community types, how many would come out with a raw p-value below 0.05?
  2. You will test at week 18 only, which is 157 samples, 37 against 120. Would you rather have 157 samples at one visit or 471 samples across three visits? Say why before you look at anything.
  3. Of the genes that do come out significant, do you expect more to be higher in anaerobe-dominant samples or in Lactobacillus-dominant samples?

Part 2: Ask, look, decide

  1. Set up and run the test:

    Using d and metadata from the setup chunk, keep only the week 18 samples. Keep genes with a count of at least 10 in at least a quarter of those samples. Run DESeq2 on the raw counts with ~ community and the contrast anaerobe against lactobacillus. Add gene symbols and names from d$gene_info. Save the results table to data/genes_by_community.csv with the columns feature (the Ensembl ID), baseMean, log2FoldChange, lfcSE, stat, pvalue, padj, symbol and gene_name.

    Tomorrow’s notebook reads that file. Before you go on, ask Pi to tell you how many samples are in each group (37 and 120), how many genes went into the test (13,738), and to print the first five count-table column names next to the first five sample_id values of the sample table. If those two lists are not in the same order, DESeq2 gives you nonsense without a warning.

  2. A short report:

    Write a summary of the results: how many genes have pvalue below 0.05, how many have padj below 0.05, how many of those change more than two-fold, and how many go each way. Then list the top 20 genes by padj with symbol, name and fold change.

    Check it against the slides: 1,815 genes at padj below 0.05, and 303 of them more than two-fold. Read the top 20 names out loud to your group. What do they have in common?

  3. One result, four plots. From here on, write your own requests. Ask for a volcano plot, an MA plot (fold change against mean count), a histogram of the raw p-values with a line where they would sit if no gene differed, and boxplots of normalised counts for the top six genes by community.

    Check the direction: each boxplot must be higher on the side that the sign of its log2FoldChange says. Ask Pi to explain the sign convention of your contrast first, then compare its explanation with the boxplots. Getting the direction backwards is the most common error in this analysis.

  4. Cutoffs are choices. Ask for a table of how many genes pass at padj of 0.01, 0.05 and 0.1, crossed with an absolute fold change of 0, 1.5, 2 and 4 (log2FoldChange of 0, 0.58, 1 and 2). Then ask Pi to rerun the test with a looser gene filter (at least 10 counts in 10% of samples) and a stricter one (in 50%), and to show genes tested, genes significant and how much of the top 20 stays the same. Which of these choices changes what you would report?

  5. Argue with it. Ask Pi to rerun the test on counts per million instead of raw counts. It may do it, or it may round the numbers to make DESeq2 accept them. Look at what happens to the results and work out why it is wrong. Then ask whether you should have used all 471 samples, and push on the answer until it mentions that each person would appear three times.

  6. Polish the volcano plot for a talk. Label the ten strongest genes by symbol without the labels overlapping. Colour up and down in two colours you choose, and put the direction in words under the x axis, “higher in Lactobacillus-dominant” on one side and “higher in anaerobe-dominant” on the other. Draw dashed lines at your cutoffs and save it as a PNG.

Discussion

  • Did the direction of the effect surprise you?
  • What do the top genes have in common? You do not need to know the genes; read the names in gene_name and describe the pattern in plain words.
  • Which cutoff did you settle on, and would a reviewer accept your reason?
  • Someone will have used all 471 samples instead of 157. What is wrong with that, and how wrong is it?

Exercise 2: The same test, on the species table

The same three lines of DESeq2 on the species table give a list of familiar bacterial vaginosis organisms, and that list comes from the wrong normalisation. Nothing in the output warns you. This exercise has you look behind a result that looks right.

Same notebook. Type /new in Pi first. Steps 3 and 5 each save a file that tomorrow’s notebook reads, so make sure you reach both.

Part 1: Predict

  1. Why can you not test the species table using the community column you built on Tuesday? Answer in one sentence.
  2. You will test species against birth outcome. The species table has 220 rows, but most are nearly always absent. How many do you expect to survive a filter of “present in at least 10% of samples”? Of those, how many are present in every one of the 157 samples?
  3. If any species come out significant, do you expect them to be higher in the preterm group or the term group?

Part 2: Ask, look, decide

  1. The default run:

    Using d and metadata from the setup chunk, keep the week 18 samples and the species present in at least 10% of them. Run DESeq2 on the raw counts with ~ outcome and the contrast preterm against term, with the default settings. Add Genus and Family from d$taxonomy, and list the significant species with their fold changes.

    Ask Pi how many species it kept and how many are significant. You should see 53 species tested and 19 significant. Read the names. Do they look like what you would expect for preterm birth?

  2. Look behind it. Ask Pi how many of the 53 species have no zero in any sample, and which ones. Then ask for two plots: each sample’s size factor against its L. iners share, and each sample’s size factor against its library size, both on log scales. What are the size factors measuring? Ask Pi to explain why, and check its explanation against the “median of ratios” slide.

  3. Alternatives side by side. Ask Pi to run the same test with estimateSizeFactors(dds, type = "poscounts"), which is built for tables full of zeros, and to put the two runs in one table: species significant, and how many are higher in preterm. The poscounts run should find none.

    Keep the poscounts version. Save it to data/species_by_outcome.csv with the columns feature (the species name), baseMean, log2FoldChange, lfcSE, stat, pvalue, padj, Genus and Family. Write one sentence in your notebook on why the first list, which looked right, was not.

  4. Many views of a null result. Ask for the top ten species by padj from the poscounts run, with fold changes, whether or not any pass. How many lean toward preterm? Check two of the names against d$taxonomy yourself, because agents invent plausible species names. Then ask for the relative abundance of the top three by outcome, three ways: boxplots on a log scale, the share of samples where each one is present in each group, and the same species across all three visits. Which view is most honest about how weak the signal is?

  5. The gene table against outcome. Ask for the same ~ outcome test on the gene table, set up exactly as in Exercise 1. Save it to data/genes_by_outcome.csv with the same columns as data/genes_by_community.csv.

    Then ask for one table comparing your three tests (genes by community, genes by outcome, species by outcome): features tested, significant, and significant with more than a two-fold change. Check it against the slides: 1,698 genes significant by outcome and only 50 of them more than two-fold. Ask for the two gene volcano plots side by side on the same axes. Write down what the comparison tells you about where the outcome signal lives.

  6. Argue with it. Ask Pi whether DESeq2 is an appropriate method for microbiome counts. Researchers disagree about this, so a confident one-sided answer is a warning sign. Then ask it to argue the opposite position, and decide which argument is stronger.

    Then ask it to repeat the gene test with Nugent score of 7 or more as the grouping. Fewer samples have a Nugent score. Did Pi tell you it dropped samples, and how many it kept?

Part 3: Reach (optional)

Ask Pi to run the species-by-outcome test on all 471 samples, with each participant appearing three times, and compare the number of significant species with your 157-sample result. More samples gave you more hits. Are they real? What assumption did you break?

If you have time after that, ask for a short Quarto report of today’s tests that ends in ## Choices made: samples, filters, size factors, cutoffs, and one alternative for each.

Discussion

  • The default size factors gave a list of species that anyone who works on bacterial vaginosis would recognise. Why is a familiar-looking list not evidence that the method was right?
  • One group found many more hits in the gene table than the species table, and another found the reverse depending on their filter. What does that say about how much of a differential analysis is decided before the test runs?
  • At week 18 the gene table shows an outcome signal and the species table, one species at a time, does not. Does that mean the bacteria do not matter for preterm birth? What other way of looking at the species table could still find a signal?

Further reading

On normalisation, with thanks to Afrah Khairallah, whose slides the size-factor example comes from:

  • Anders and Huber 2010, Genome Biology: DESeq and the median-of-ratios size factor
  • Love, Huber and Anders 2014, Genome Biology: DESeq2
  • Robinson and Oshlack 2010, Genome Biology: TMM, edgeR’s equivalent
  • Law et al. 2014, Genome Biology: limma-voom
  • Li et al. 2010, Bioinformatics: TPM, for comparing genes within a sample

For microbiome counts:

  • Gloor et al. 2017, Frontiers in Microbiology: “Microbiome datasets are compositional: and this is not optional”
  • McMurdie and Holmes 2014, PLoS Computational Biology: the case against rarefying
  • Nearing et al. 2022, Nature Communications: fourteen differential abundance methods run on 38 datasets, and how much they disagree