liveBook · Manning

FASTA

As explained in Regular Expression Puzzles and AI Coding Assistants

A biological nucleotide or protein sequence represented as a FASTA header and sequence-data record.

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

How Regular Expression Puzzles and AI Coding Assistants covers it

How deep it goes
Explains a simplified nucleotide alphabet, ignored line breaks, terminal-repeat rules, and rejection cases rather than the full format.
Examples
Demonstrates wrapped valid DNA, malformed telomere tails, and an unknown-nucleotide failure.
What it assumes
Teaches A, C, G, T, N, and - meanings while relying on regular-expression matching for the extraction task.
What you can do after
Apply it via Python regular expressions to extract regions preceding three or more terminal TTAGGG repeats.
How it connects
Connects FASTA sequences with regular expressions, telomeres, nucleotide bases, and Python string searching.

This explainer was generated by Manning's knowledge graph from the text of Regular Expression Puzzles and AI Coding Assistants. The section links point to the parts of the book it draws on.