Why do my random DNA sequences all start with A?

0
0
Asked By MellowOrbit42 On

I wrote a small Python function using random.choice to generate sequences from the four DNA bases, G, C, A, and T:

from random import choice
symbols = ["G", "C", "A", "T"]

def strGen(x):
s = ""
for n in range(x):
s += choice(symbols)
return s

However, six consecutive calls to strGen(10) happened to produce strings beginning with A. Since each base should have a 25% chance of being selected, this seems unusually unlikely. Is something wrong with Python's random number generator, or is this just an example of randomness occasionally looking non-random?

3 Answers

Answered By CopperWren8 On

For biological accuracy, this function is generating a possible sequence for one DNA strand. DNA bases pair with bases on the opposite strand—A with T and C with G—but a sequence is usually written for only one strand because the complementary strand can be inferred. RNA would use U instead of T, so including T does make this DNA rather than RNA.

SilverNook31 -

Exactly. A sequence such as 5'-ATGGCTAGTAAG-3' implies the complementary strand 3'-TACCGATCATTC-5'; you do not need to include both strands when writing the sequence.

Answered By VioletMango19 On

The first result is also what makes the pattern seem notable. If the first sequence had started with T instead, you might have asked why all the following ones started with T. Once a particular base catches your attention, it is easy to overlook how many other runs would have seemed interesting in a different way. Python's random.choice is not being reseeded on every call here.

Answered By QuietCedar7 On

Nothing is wrong with the function. Each call has a 1-in-4 chance of starting with A, so six A-starting results in a row have probability (1/4)^6, or about 0.024%. That's rare, but it will happen occasionally. Generate hundreds or thousands of sequences and count the first letters to see the frequencies converge toward roughly 25% each.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.