From Reads to Count Tables

Workshop 2, Module 1

This afternoon

We won’t run any software today.

By the end of the afternoon you should be able to explain, in your own words, where each number in a count table came from.

Millions of reads per sample

Lindsay showed you one FASTQ read this morning. Each sample produces millions of them, and the quality drops toward the end of every read.

Before counting, the low-quality ends are usually trimmed off.

All the processing after this tries to answer what was in the tube, and how much of it?

Decisions that may already be made

Between the sequencer and the count table, someone may have chosen:

  • where to trim each read
  • which samples were too poor to keep
  • which reference to compare against
  • what to do with reads that matched more than one thing
  • what to do with reads that matched nothing

Sometimes that someone is you, starting from raw reads. Sometimes it is a facility or a collaborator, and the choices don’t travel with the table. Each choice changes the numbers, so find out who made them. Lindsay’s ten questions from this morning are a good list to send.

Both pipelines end in a count table

The lab work and the software differ at every step. Both end with features in rows, samples in columns, and read counts in the cells.

16S: one gene, every bacterium

The 16S ribosomal RNA gene is in every bacterium, and parts of it differ between species.

  • copy one variable region by PCR and sequence it, as Lindsay showed this morning
  • group identical sequences together
  • look each one up in a reference database

PCR distorts the proportions

Primers bind some templates better than others, and 16S copy number varies between species, so the most common species in the reads may not be the most common in the tube.

Grouping reads: ASVs and OTUs

If two reads differ by one base, did they come from one organism or two?

  • OTUs cluster anything within some cutoff of each other, say 3%. Errors get absorbed, and so do close relatives.
  • ASVs model the sequencing error process and keep exact sequences. They can separate close relatives, if the error model is right.

Classification often stops short of species

The sequenced region is short, and some species are identical across it.

what the classifier can say how our table names it
Lactobacillus crispatus lactobacillus_crispatus
Gardnerella, but which species is ambiguous gardnerella_swidsinskii_leopoldii
family only prevotella_sp_1
bacteria dropped

Two of our 220 row names admit this uncertainty in the name itself, so read the row names before you interpret them.

A 16S count is a number of reads

A cell in the species table is the number of amplicon reads in this sample that matched this species.

It is not the number of bacteria. The count also depends on

  • how many copies of the 16S gene that species carries
  • how well the primers bind to it
  • how completely the cells lysed
  • how deeply the sample was sequenced

Quick check

RNA-seq: every gene, one organism*

  • select messenger RNA, fragment it and sequence it
  • find where each fragment belongs in the genome
  • count fragments overlapping each gene

*Metatranscriptomics is RNA-seq on multiple organisms in a sample, usually microbes.

An RNA-seq count is a number of fragments

A cell in the gene table is the number of fragments in this sample assigned to this gene.

It is not the number of mRNA molecules either. The count also depends on

  • how long the gene is
  • how well the capture chemistry worked
  • whether the read could be placed uniquely
  • how deeply the sample was sequenced

One sample can generate multiple ’omics datasets

A cervicovaginal swab contains human cells and bacteria together.

  • The 16S run amplifies a bacterial gene, so human material is mostly ignored.
  • The RNA-seq run captures polyadenylated RNA, which is mostly human.
  • Neither table is pure, but both come from the same swab.

Because they share a swab, we can pair the two tables sample by sample.

The two tables share their columns

table row P001_week_18 P001_week_24 P002_week_18
16S lactobacillus_jensenii 18,362 9 0
gardnerella_swidsinskii_leopoldii 193 17,977 42
fannyhessea_vaginae 0 7,050 0
lactobacillus_iners 2,956 2,301 460
… 216 more species
RNA-seq HBB 1,692,453 945,462 1,905,792
MUC5B 114,446 1,116,191 966,436
HBA2 707,226 429,587 873,145
HBA1 341,042 201,850 629,533
… 14,222 more genes

The rows with the most reads, in the first three columns of each table. Every sample ID is a column in both tables, so any sample can be looked up in both.

Some reads fit more than one gene

Gene families and repeated sequences produce reads that match several genes equally well. Counting such a read once, twice, or not at all gives a different table each time.

Counts, not TPM, for testing

You will see expression reported as TPM, FPKM or RPKM. Those divide by gene length so you can compare genes within a sample.

  • Good for: “is gene A higher than gene B in this sample?”
  • Wrong for: the statistical tests we run on Wednesday

Those tests need raw counts, because they model counting noise. Hand them normalised values and they will believe the noise is smaller than it is.

sample library size reads for gene X reads per million range if sequenced again
sample 1 2,000,000 10 5 2.0 to 8.5
sample 2 20,000,000 100 5 4.0 to 6.0

The normalised values match. Only the raw counts show that sample 1 rests on ten reads.

Quick check

Both of our tables are compositional

As Lindsay put it this morning, the sequencer tells you the slices of the pie, not the size of the pie.

  • 16S is hit hardest, because one species routinely holds 90% of the reads.
  • RNA-seq is affected less, since no single gene dominates, but the effect is still there.

“Relative abundance went down” and “there was less of it” are different claims. Without a spike-in or an absolute measurement, you cannot tell them apart.

The sentence to remember

A count measures how much of something was in the tube relative to everything else in that tube, multiplied by how hard we looked.

Every analysis starts the same way

  1. How deeply was each sample sequenced?
  2. Which features are we even able to see?
  3. How alike are whole samples, and what makes them alike?
  4. Only then: which features differ between groups?

Tomorrow morning covers the first two, on both tables at once, and tomorrow afternoon the third. The fourth waits until Wednesday.

Our gene table has a batch label

The gene table was produced in two sequencing batches, and we kept that label in the metadata.

Lindsay showed you this morning what a batch effect looks like in a PCA.

Tomorrow afternoon you will measure how much of the table the batch explains, and the answer is uncomfortable.

Keep every technical label your sequencing facility gives you. A batch effect you never recorded is one you cannot test for.

On your feet

Put the laptops away.

For the next ninety minutes we build count tables by hand.

Pick a bag, then draw balls

  1. Pick a bag. Each bag is one community.
  2. Draw balls. Each ball is one read, and the number of balls you draw is the depth.
study the bag a ball
16S a vaginal community a 16S read
RNA-seq the cells on a cytobrush a cDNA fragment
bird survey a patch of forest a bird you saw

Four bags, eight volunteers

Two people per bag, without looking:

  • the first person draws 5 balls, the second draws 20
  • tally your colours on the back of a blank card, then colour the bar on the front
  • copy the bag’s tag, high or low inflammation, onto your card

Did the two people at the same bag make the same card?

Your card

The front shows proportions, so every bar is the same length. The small n says how many balls were drawn. The back has the counts and one piece of sample information.

Round 1: find your closest partner

Find the one card most like yours and stand together. Judge by the bars and ignore the card numbers.

Now each pair finds its closest pair.

Now each group of four finds its closest group. Watch the board.

Round 2: the floor is a plot

Stand where your card belongs. Left to right: how much of your bar is blue. Back to front: orange share minus green share.

Spoilers ahead

The next slides show which bag every card came from.

If you are reading these slides before Monday afternoon, stop here.

The bag behind each card

bag cards
orange S04 S10 S13 S16 S24 S29 S32 S37 S41 S50 S55 S59 S63 S65 S73 S79
green S03 S07 S11 S19 S22 S30 S33 S40 S42 S45 S51 S58 S64 S69 S74 S76
blue S01 S08 S15 S18 S23 S28 S35 S38 S44 S49 S53 S57 S61 S67 S72 S77
diverse S05 S06 S12 S17 S21 S27 S34 S36 S43 S47 S54 S60 S62 S70 S71 S78
green~blue S09 S20 S26 S31 S46 S56 S68 S80
orange~green S02 S25 S52 S66
blue~diverse S14 S39 S48 S75

A ~ is a blend: a community caught partway between two bags.

The floor, computed

The computer draws the same map

Bray-Curtis PCoA of all 80 cards. Big points are the cards with 5 to 10 balls.

A third axis

On the floor, blue and pink cards crowded together. A third axis pulls them apart.

The computer’s version of Round 1

Average-linkage clustering: join the two closest, then the two closest groups.

Debrief

  • Who struggled to find a partner? Check the n on their card.
  • Did any group of four come from more than one bag?
  • Where did the blends end up, in a group or between groups?
  • When two groups both wanted the same pair, how did you decide?

Build the table

Sit down with the people near you. One worksheet each.

Copy your table’s cards into the columns, one card per column.

Report to the room

Copy your two-by-two table onto the flip chart, with your n.

table n mostly lactic acid, high mostly lactic acid, low not, high not, low
1
2
…
room

Does your table agree with the room? Who is right?

Tomorrow

The same table, with 220 rows of bacteria or 14,226 rows of human genes, and 471 columns.

The column totals and proportions from your worksheet are the first things you compute in R.