S6-3

Genotype, phenotype, and variation between individuals

14 min

You have met the genome as a molecule and, in S6.2, as a layout. Now we ask the question that turns biology into a data science: what makes your genome different from mine? Every human carries nearly the same set of roughly 20,000 protein-coding genes, in nearly the same order on the same chromosomes. And yet no two people (outside identical twins) read the same at every position. Those differences are the raw material of everything from eye color to disease risk, and they are the input to almost every tool you will build in the bioinformatics track.

Genotype and phenotype: the two words you must not mix up

Start with a clean distinction.

Your genotype is the specific sequence you carry. Down at a single spot on chromosome 15, you might have an A where I have a G. That A-versus-G fact, for you, at that position, is a piece of your genotype.

Your phenotype is anything observable that results: your height, your blood type, the color of your eyes, whether a drug clears from your body fast or slow. Phenotype is the output. Genotype is one of the inputs.

The word "one" in that last sentence is the whole lesson. Genotype does not compile straight into phenotype the way source compiles into a binary. The environment, your history, and pure chance all get a vote. Two people with the exact same variant at a height-related position can differ by fifteen centimeters because one was undernourished as a child. The DNA set a tendency. The world finished the sentence.

Key terms

Genotype
The specific set of DNA variants an individual carries, for example an A rather than a G at a particular position.
Phenotype
An observable trait, such as height or blood type, that results from genotype together with environment and chance.
Allele
One of the alternative versions of a sequence at a given position, for example the A allele versus the G allele.
Polygenic trait
A trait influenced by many genes at once, each contributing a small nudge, rather than by a single gene.
SNP
A single nucleotide polymorphism, a one-base difference between individuals at a specific position in the genome.
Indel
A small insertion or deletion of one or a few bases relative to the reference sequence.
Copy-number variant
A difference in how many copies of a chunk of DNA an individual carries, from a large deletion up to several duplicated copies.
Reference genome
An agreed-upon consensus sequence used as a shared coordinate system, not the genome of any single real person.

Most traits are polygenic, and why that had to be true

Here is the beat that undoes the pop-science version of genetics. For most traits you care about, there is no single gene. Height is shaped by thousands of positions across the genome, each one shifting your expected height by a fraction of a millimeter. Risk for type 2 diabetes, for depression, for heart disease: same story. Many genes, each a small contributor, plus a large environmental term. This is what polygenic means.

You can almost derive that this had to be the case. Recall from S5 how much machinery stands between a base and a body: transcription, splicing, translation, folding, regulation, feedback. A trait like height is the summed output of bone growth, hormone signaling, cartilage timing, and nutrition, and each of those is itself run by dozens of proteins. A system with that many moving parts cannot hang on one base. The single-gene traits we do know (like cystic fibrosis or sickle cell) are the exceptions precisely because they hit one irreplaceable protein hard enough that nothing downstream can compensate.

The three shapes of variation

When your genome differs from someone else's, the difference comes in a few recognizable shapes. You will meet all three constantly once you start parsing genomic files.

A SNP (single nucleotide polymorphism, say it "snip") is a one-base swap. Where the reference has a C, you have a T. SNPs are the most common variant. Any two people differ at millions of SNP positions across their three billion bases. Most SNPs sit in regions that do nothing obvious. A few land inside a codon or a regulatory site and change something real, exactly the kind of single-base change you traced in S5.5.

An indel is a small insertion or deletion, from one base up to a few dozen. Insert two bases inside a coding region and you have caused the frameshift you met in S5.5, which scrambles every codon downstream. Indels are less common than SNPs but often more disruptive, because length changes ripple.

A copy-number variant (CNV) is a difference in how many copies of a whole chunk of DNA you carry. Instead of changing a letter, the genome duplicates or deletes a block that might span thousands or millions of bases. You might carry three copies of a stretch where I carry two, or one where I carry two. Copy number matters because more copies of a gene often means more of its protein, and dose can change a phenotype.

The reference genome is a coordinate system, not a person

Here is the mental model that makes the whole field click, and it is one you already own as an engineer.

The reference genome is a single agreed-upon sequence for our species. It is what lets a researcher in Tokyo and a researcher in Toronto both say "chromosome 7, position 117,559,590" and mean the exact same spot. But, and this is the part people get wrong, the reference is not the genome of any real individual. It is a consensus assembled from several donors, a shared ruler. Nobody's actual DNA matches it everywhere. Yours differs from it at roughly four to five million positions. That is normal. That is not you being broken. That is just you being a person and not a ruler.

The analogy, and where it breaks

Think of the reference genome as a base commit in version control. Your personal genome is a diff against that commit. A SNP is a changed line. An indel is an inserted or deleted line. A copy-number variant is a whole block copied or removed. Storing you as a diff instead of the full source is not just a metaphor, it is literally how the VCF format saves space: it records only what differs from a shared baseline instead of a fresh copy of the genome for every person.

Use the analogy, but know its failure edge, because an analogy without its limit is a bug.

See the diff yourself

The single most common operation on genomic data is lining two sequences up so you can see where they agree, where a base was swapped (a SNP), and where a base was inserted or deleted (an indel shows up as a gap). Do it by hand once and the file formats stop being abstract.

Below, treat the top sequence as the reference and the bottom as an individual. Run the alignment and read off the diff: every mismatch is a SNP, every gap is an indel. Predict where the gaps will land before you run it, then check yourself.

align.ts
The recurrence
matrix[i][j] = max(
  matrix[i-1][j-1] + s(a[i-1], b[j-1]),   // diagonal: align the two residues
  matrix[i-1][j]   + gap,                 // up: a gap in sequence b
  matrix[i][j-1]   + gap                  // left: a gap in sequence a
)
s(x, y) = match when x == y, else mismatch

Global alignment (Needleman-Wunsch) seeds row 0 and column 0 with k * gap and reads the score from the bottom-right corner.

-GATTACA
-0-2-4-6-8-10-12-14
G-21-1-3-5-7-9-11
C-4-10-2-4-6-6-8
A-6-30-1-3-3-5-5
T-8-5-210-2-4-6
G-10-7-4-10-1-3-5
C-12-9-6-3-2-10-2
U-14-11-8-5-4-3-2-1
GCATGCU
GATTACA
Score-1
Identity43%
Columns7
Gap penalty-2
Write it yourself: the DP fill

The grid above is not magic. It is one nested loop. Given the two sequences and the scores, fill every cell from the three neighbors you already computed, then trace back from the best cell to recover the alignment. Try writing the fill from the recurrence before you read it.

align.ts
// A thin sketch of needlemanWunsch (global). Local alignment is the same
// loop with a 0 floor and a traceback that starts at the largest cell.
function fill(a: string, b: string, match: number, mismatch: number, gap: number) {
  const m = a.length;
  const n = b.length;
  const matrix: number[][] = [];
  for (let i = 0; i <= m; i++) matrix.push(new Array(n + 1).fill(0));

  // Seed the borders: a run of k gaps costs k * gap. (Local leaves these at 0.)
  for (let i = 1; i <= m; i++) matrix[i][0] = i * gap;
  for (let j = 1; j <= n; j++) matrix[0][j] = j * gap;

  // Fill. Row i indexes a, column j indexes b.
  for (let i = 1; i <= m; i++) {
    for (let j = 1; j <= n; j++) {
      const s = a[i - 1] === b[j - 1] ? match : mismatch;
      const diag = matrix[i - 1][j - 1] + s;   // align a[i-1] with b[j-1]
      const up = matrix[i - 1][j] + gap;        // a gap in b
      const left = matrix[i][j - 1] + gap;      // a gap in a
      matrix[i][j] = Math.max(diag, up, left);
      // Smith-Waterman (local) instead: Math.max(0, diag, up, left)
    }
  }

  // The global score is the bottom-right corner.
  return matrix[m][n];
}
Why alignment is harder than a string compare

You might reach for a position-by-position equality check, the way you would diff two strings of equal length. But an indel shifts every base after it, so a naive compare would report a mismatch at every position past the first insertion even though the sequences are nearly identical. Alignment algorithms solve this by allowing gaps, paying a penalty to insert one, so that the rest of the sequence can slide back into agreement. That is the whole idea behind the Needleman-Wunsch and Smith-Waterman methods you will build in the BIO track. The gap penalty is you telling the algorithm how much you believe an indel happened versus a run of coincidental swaps.

Check yourself

1. You carry a T where the reference has a C at one position. That fact, for you, is an example of your:

2. A headline reads 'scientists discover the gene for height.' What is the most accurate way to read it?

3. In an alignment of your DNA against the reference, a gap in one sequence most directly indicates:

4. Your genome differs from the reference genome at millions of positions. What does that tell you?

4 unanswered