My Python function starts with an empty string and uses random.choice on G, C, A and T once per character. Six sequences in a row started with A. Is something wrong with the function?
Why do my random DNA sequences keep starting with A?
Answers
Nothing in that function makes A more likely at the start. Each choice has a 1 in 4 chance of being A, so six specified sequences all starting with A has a probability of 1 in 4,096, or about 0.024%. Unlikely, sure, but still possible.
Generate a larger batch and count the first letters. You should expect some variation in the counts, not exactly 25 of each in every batch of 100.
Reply to this answer
Check whether anything else in the program is calling random.seed repeatedly. The function itself doesn't reseed, and calling it quickly won't reset Python's random generator each time.
If a much larger batch still starts only with A, check the actual symbols and choice objects being used, and make sure the code being run matches the function you posted.
Reply to this answer
Small DNA modeling note: your function makes one random strand, which is fine for what you're testing. If you want a matching second strand, use complementary bases: A pairs with T, and G pairs with C.
Reply to this answer
Add your answer
Answers are reviewed before publication.
Related Discussions