FASTA represents genetic sequences with nucleotide symbols, but a valid record is not automatically a valid answer to a biological-pattern puzzle. A simplified fragment may contain A, C, G, T, N for an unknown nucleotide, and - for a gap; exact matching can deliberately reject N and - even though FASTA permits them. section 2.13
A practical wrinkle: sequence data may be visually wrapped across fixed-width lines, yet newlines can be ignored when matching. Broader FASTA handling can also split multiple sequences using initial >description lines before examining each sequence body. section 2.13 section 2.15
For a simplified DNA fragment ending in telomeres, distinguish three separate requirements:
- Accept only explicit A, C, G, and T in the encoding region; an unknown N or a gap blocks the match. section 2.13
- Require the terminal telomere TTAGGG to repeat at least three times. section 2.13
- Return everything before those terminal repeats, rather than quietly treating a partial or interrupted repeat run as valid. section 2.13
A tempting near-match
A long A/C/G/T sequence followed by three or more uninterrupted TTAGGG repeats qualifies, and the coding region ends just before the repeats. A sequence with too few repeats fails; so does one containing N, even though both remain valid FASTA encodings. That distinction is the whole trap. section 2.13
>>> coding = re.search(pat, valid).group()
>>> print('\n'.join(wrap(coding, 60)))
CCCTGAATAATCAAGGTCACAGACCAGTTAGAATGGTTTAGTGTGGAAAGCGGGAAACGA
AAAGCCTCTCTGAATCCTGCGCACCGAGATTCTCCCAAGGCAAGGCGAGGGGCTGTATTG
CAGGGTTCAACTGCAGCGTCGCAACTCAAATGCAGCATTCCTAATGCACACATGACACCC
AAAACTATAACAGACATATTACTCATGGAGGGTGAGGGTGGGGGTGAGGG
Inspect the extracted region beside its wrapped input: the result stops before the terminal TTAGGG run, while line wrapping does not alter the sequence being matched. section 2.13
Python can search for a terminal repeat pattern and process multiple >-delimited records, but generated code deserves inspection. A plausible implementation may recognize broader FASTA structure while still needing careful checking of its repeat count and extracted boundary. section 2.15
