Learning LibraryBiotech LibraryTeens

Orthologs: the same gene across species

The same gene shows up in a human, a mouse, a fish — slightly different in each. These matched-up genes are orthologs, and comparing them in code reveals how related two species are.

The big idea

Orthologs are versions of the same gene in different species; comparing them base by base measures how similar they are.

See it in code

1The basics

Comparing two orthologs comes down to comparing bases. == tells you whether a whole strand is identical — or whether the bases at one position match:

python
human = "ATGGCG"
mouse = "ATGGCA"
print("Identical strands?", human == mouse)
print("Position 0:", human[0], "vs", mouse[0], "->", human[0] == mouse[0])
print("Position 5:", human[5], "vs", mouse[5], "->", human[5] == mouse[5])
Run it — a whole-strand check, then two single positions:
Identical strands? False
Position 0: A vs A -> True
Position 5: G vs A -> False

The strands aren't identical, but most positions match — position 0 does, position 5 doesn't. To measure how similar, we need to count the matches.

2A step further

Loop over every position, compare the two bases there, and add one to a running tally each time they match:

python
human = "ATGGCG"
mouse = "ATGGCA"
matches = 0
for i in range(len(human)):
    if human[i] == mouse[i]:
        matches += 1
print("Matching bases:", matches, "out of", len(human))
Run it — the matches counted across the whole strand:
Matching bases: 5 out of 6

Five of six positions match. Turn that count into a fraction of the length and you have a similarity score.

3In our world

Now on real gene versions: line up a human and mouse strand, walk them position by position counting matches, and turn that count into a similarity score:

python
human = "ATGGCGTTA"
mouse = "ATGGCATTA"

matches = 0
for i in range(len(human)):
    if human[i] == mouse[i]:
        matches += 1

similarity = matches / len(human) * 100
print("Human:", human)
print("Mouse:", mouse)
print(f"Matching bases: {matches}/{len(human)} ({similarity:.0f}% similar)")
Run it — a base-by-base similarity score between two species:
Human: ATGGCGTTA
Mouse: ATGGCATTA
Matching bases: 8/9 (89% similar)

Eight of nine bases match — the one difference is a mutation that accumulated since these species shared an ancestor. Counting matches like this, scaled up, is how scientists build family trees of life from raw sequence.

The same idea, everywhere

Comparing two sequences position by position is a core algorithm far beyond biology: diffing two files, checking a password against a hash character by character, measuring how similar two strings are. Real tools add gap handling (alignment), but the counting idea is the seed.

Try it yourself

Add a third species and compare it to both. Then handle sequences of different lengths by looping only up to the shorter one with min(len(a), len(b)).

The common mistake

Comparing sequences of different lengths without care. Indexing past the end of the shorter strand raises an IndexError. Real comparisons also align first — inserting gaps so similar regions line up — before counting matches.

What it unlocks

Comparison builds on list indexing, conditionals, and sequence analysis, and hints at how evolution is read from DNA.