SeqBench

How to Clean Up a Pasted DNA Sequence

5 min read · Updated October 30, 2026

A sequence copied out of a paper, a database page or an alignment arrives carrying things that are not bases: line numbers down the left margin, spaces every ten characters, lowercase stretches, dashes where an alignment had gaps. None of it is visible as a problem, because every one of those characters looks like formatting to a reader and like data to a parser.

This is what each of them does, and what a cleaning step should and should not remove.

What a paste from a paper actually contains

Take two lines of a GFP coding sequence in the layout journals and database pages use, with a position number at the start of each line and a space every ten bases. As characters, that is 76 of them. As DNA it is 60 bases, and the other 16 are three digits, eleven spaces and two line breaks.

Stripping everything that is not a letter gives the 60 bases, which is the sequence you meant to paste: ATGGTGAGCAAGGGCGAGGAGCTGTTCACCGGGGTGGTGCCCATCCTGGTCGAGCTGGAC. Nothing else about the paste changes, and that is the whole job — but the failure mode when it is skipped is not an error message.

Digits are the dangerous part

Spaces and line breaks are removed by almost everything that reads a sequence. Digits are not, and they do not sit harmlessly at the start of a line once the line breaks are gone. In that same two-line paste, removing only the whitespace joins the end of the first block to the position number of the second: the string runs ...CTGTTCACC31 GGGGTGGTGC..., 69 characters of which 63 are letters and digits, where there should be 60 bases.

A parser that drops the digits late, or that treats them as unknown residues, has already shifted every downstream coordinate by the number of digits it swallowed. A reading frame moves, a restriction map moves, a primer binding site moves — and each of those still produces a confident answer.

The rule that keeps this from happening is to strip to letters before anything measures the sequence, not after.

Lowercase means something, and it is not what you think

Nothing in the chemistry distinguishes a from A. In files, lowercase is a convention: genome assemblies use it for soft-masked repeats, some annotation tools use it for the region outside a feature, and plenty of software emits lowercase for no reason at all. A tool that is case-sensitive where it should not be will report a motif as absent because the sequence arrived soft-masked.

Convert case deliberately — upper for analysis, as almost every reference file is written — and keep the original if the masking was meaningful to you, because that information is destroyed by the conversion.

Gap characters are data in an alignment and noise everywhere else

A dash in an aligned row means a gap relative to the other rows. Paste one row of an alignment into a Tm calculator or a translation and the dashes are not bases either, so they have to go — but they must go before the sequence is used, not be quietly read as a residue.

The same applies to the dot some older formats use for a gap, and to the asterisk a protein alignment uses for a stop.

Line width is cosmetic, and it is also a compatibility constraint

FASTA's 60- or 70-character line is a convention from terminals, not a requirement of the format, and most modern parsers read a record written as one long line. Some do not, and a few refuse a line longer than a fixed buffer.

Wrapping to 60 costs nothing and removes a class of problem you cannot see from your own screen. A single-line sequence is the right choice when you are pasting into a form that expects raw bases.

DNA to RNA is one substitution and nothing else

Converting DNA to RNA replaces every T with U, and the reverse replaces every U with T. It does not reverse the sequence, complement it, or change anything about the strand it represents — the transcript of a gene on the minus strand is the reverse complement of what the plus strand shows, and that is a separate operation.

If a sequence arrives with both T and U in it, something upstream has already gone wrong: that is a sign of a concatenation of two sources rather than a mixed-chemistry molecule.

Frequently asked questions

Why does my sequence have numbers in it?

Because the page you copied from printed position numbers in the left margin, and copying takes the text, not the layout. They are usually at the start of every line of 60 or 70 bases. Removing the line breaks without removing the digits fuses each number onto the end of the previous block, which lengthens the sequence instead of leaving an obvious error.

Do I need to remove spaces from a DNA sequence?

Yes, although most tools do it for you. Spaces every ten bases are a readability convention from printed sequences. They carry no information, and the one thing they can do is make a character count disagree with a base count.

Does uppercase or lowercase matter in a FASTA file?

Not to the biology. In files, lowercase conventionally marks soft-masked repeats in genome assemblies and is sometimes used to mark a region outside a feature. Convert to uppercase for analysis unless the masking is information you intend to keep, because converting destroys it.

What is the difference between reversing a sequence and reverse-complementing it?

Reversing writes the same letters back to front and is almost never what you want on its own. The reverse complement also swaps each base for its partner, and is the other strand read 5' to 3'. A reverse PCR primer is a reverse complement; a reversed sequence is not a molecule that exists.

Related references

Related tools

Related guides