Convert already aligned, equal-length FASTA records to a NEXUS alignment.
Packing an aligned FASTA file into a NEXUS alignment
Yes, this page converts FASTA to NEXUS alignment, but only when the records are already aligned: every sequence must have the same length, and the converter does not align them for you. You choose DNA, RNA, or protein once for the whole file, and the output keeps each record's ID with its row of letters.
What carries over into the alignment
| Data in your file | In the output | Details |
|---|---|---|
| Aligned sequence rows | Kept | Written as one alignment, one row per record. |
| Record IDs | Kept | Each ID names its row. |
| Header description text | Lost | Words after the ID on a header line are not kept. |
| Sequence type | Set by you | NEXUS output needs a sequence type, so the converter uses your DNA, RNA, or protein choice. |
What the converter checks before it writes
The file is refused, not repaired, when any of these fails:
- Every sequence must have the same length. A record whose length differs from the first record's is refused; the message names that record and gives both lengths.
- No sequence may be empty.
- Every record needs an ID; add a name to each header line if one is missing.
- Your DNA or RNA choice must match the letters: with DNA chosen, a record containing U is refused; with RNA chosen, a record containing T is refused. The message asks you to choose the type that matches the letters.
The sample on this page converts
The sample file holds three records of 39 letters each, named seq1 to seq3. With DNA chosen, it converts to one alignment of three rows with the IDs and letters unchanged, and the words after each ID on the header lines are gone from the output, as the table says.
Other alignment outputs, and the way back
FASTA to PHYLIP alignment (interleaved) applies the same equal-length rule. It also shortens IDs longer than 10 characters and rejects IDs that become identical. FASTA to Clustal alignment keeps up to 30 characters of each ID. Both drop header descriptions, neither asks the sequence-type question, and both convert the sample as well.
The reverse route, NEXUS alignment to FASTA, is available. Only the aligned rows are converted; alignment annotations such as scores and consensus lines are not kept. Converting back does not bring back header descriptions dropped here.
If the file is refused for another reason
If the upload cannot be read at all, the page says only that it could not be read as FASTA and asks you to check that it is a valid FASTA file; no cause is given. Uploads are limited to 50 MB.
Run it with Biopython
For batch work, you can use Biopython's SeqIO.convert function. This output needs a sequence type, so replace the example molecule type with DNA, RNA, or protein to match your file.
from Bio import SeqIO
count = SeqIO.convert("input.fasta", "fasta",
"output.nexus", "nexus",
molecule_type="DNA")
print("Converted %i records" % count)
Sample input file: FASTA
Copy this example into a file, or download it, to try a FASTA conversion.
Download sample (sample.fasta, 210 bytes)
Samples are small illustrative files. Some come from the Biopython test suite (see the project's sample notes); they are not real study data.