NEXUS to FASTA Converter

Paste a NEXUS alignment, extract the DATA or CHARACTERS matrix, and get standard FASTA back. Handles interleaved matrices, comments, matchchar shorthand, and TAXA labels in your browser.

Try:
FASTA output

What this tool does

Convert a NEXUS sequence-alignment matrix into standard FASTA. Paste the file text, including #NEXUS and its begin data; or begin characters; block, and the tool extracts the matrix command into one >name FASTA record per taxon. It runs locally in your browser, so the alignment is not uploaded.

NEXUS is flexible: comments can appear almost anywhere, taxon labels may be quoted, DATA and CHARACTERS blocks are both common, and matrices may be sequential or interleaved. This converter handles those everyday forms and reports dimension mismatches clearly.

Supported NEXUS features

FeatureHandling
DATA and CHARACTERS blocksThe first matching block is used; TAXA/TREES/ASSUMPTIONS are ignored except for taxlabels.
dimensions ntax=… nchar=…Used to validate taxon count and site count.
format interleaveHonoured by Auto-detect; you can also force sequential or interleaved.
format gap=…The declared gap symbol is preserved, or stripped when Strip gaps is on.
format matchchar=.Expanded from the first taxon's residue by default.
format labels=noRows are paired with labels from the TAXA block's taxlabels command.
Bracketed [comments]Removed before parsing, including nested comments.
Quoted taxon labelsSingle-quoted labels with spaces are preserved.

Options

OptionWhat it does
Matrix layoutAuto-detect (default), Sequential, or Interleaved. Auto honours the interleave flag and otherwise chooses the parse that matches nchar.
FASTA line widthWrap each sequence at this many characters. Default 60; 0 writes one long line per sequence.
Residue caseKeep, uppercase, or lowercase sequence residues. Taxon labels are not case-normalised.
Strip gapsRemove the declared gap= symbol plus common - and . gap marks.
Expand matchcharReplace a declared matchchar (usually .) with the first taxon's residue at the same site. On by default.
Unquoted underscores become spacesApply the NEXUS convention where Homo_sapiens in an unquoted label means Homo sapiens. Off by default because many FASTA workflows prefer underscore-stable headers.
TolerantConvert anyway when ntax or nchar checks fail. Off by default.

Worked example

A simple DATA block:

#NEXUS
begin data;
  dimensions ntax=2 nchar=8;
  format datatype=dna gap=-;
  matrix
    Alpha  ACGTACGT
    Beta   ACGTTCGT
  ;
end;

With FASTA line width set to 0, the output is:

>Alpha
ACGTACGT
>Beta
ACGTTCGT

An interleaved CHARACTERS block with matchchar=. expands the dots from the first taxon when Expand matchchar is on:

#NEXUS
begin characters;
  dimensions ntax=2 nchar=8;
  format datatype=dna gap=- matchchar=. interleave;
  matrix
    Alpha  ACGT
    Beta   ....

    Alpha  TGCA
    Beta   ....
  ;
end;
>Alpha
ACGTTGCA
>Beta
ACGTTGCA

Limits and edge cases

FAQ

Does this convert TREE blocks too?

No. It only extracts the sequence matrix from a DATA or CHARACTERS block and writes FASTA. NEXUS tree definitions are a different data shape and are ignored.

Why does the output differ when Expand matchchar is on?

In NEXUS, a declared matchchar such as . means "use the same state as the first taxon at this site." Expanding it writes the actual residue into the FASTA record, which is usually what downstream FASTA tools expect. Turn the option off when you want literal dots preserved.

How are spaces in taxon names handled?

Single-quoted labels such as 'Homo sapiens' keep the space. For unquoted labels, NEXUS treats underscores as spaces; this tool can apply that convention with Unquoted underscores become spaces, but keeps underscores by default for safer FASTA headers.

Can I convert interleaved NEXUS files?

Yes. Auto-detect honours format interleave and also tries the interleaved parse when no flag is present. Force Matrix layout to Interleaved if the file is malformed and you still want that interpretation.

What does a dimension mismatch mean?

The dimensions command declares how many taxa and sites the matrix should have. A mismatch usually means the file is truncated, a wrong layout was forced, or the matrix contains labels/no-labels in a different shape than declared. Use Tolerant only when you want the partial sequences anyway.

Developer & Automation Access

Run it from the terminal

Same engine as this page, headless — via the gizza CLI:

gizza tool nexus-to-fasta "#NEXUS
begin data;
  dimensions ntax=2 nchar=8;
  format datatype=dna gap=-;
  matrix
    Alpha  ACGTACGT
    Beta   ACGTTCGT
  ;
end;"

New to the CLI? Get gizza →

Open it by URL

Pre-fill and auto-run this tool with query parameters — the names match the API/CLI:

https://gizza.ai/tools/nexus-to-fasta/?nexus=%23NEXUS%0Abegin%20data%3B%0A%20%20dimensions%20ntax%3D2%20nchar%3D8%3B%0A%20%20format%20datatype%3Ddna%20gap%3D-%3B%0A%20%20matrix%0A%20%20%20%20Alpha%20%20ACGTACGT%0A%20%20%20%20Beta%20%20%20ACGTTCGT%0A%20%20%3B%0Aend%3B&layout=auto&wrap=60&case=keep&remove_gaps=true&expand_matchchar=true&underscores_to_spaces=true&tolerant=true

Machine-readable descriptor: tool.json — title + parameters JSON Schema for agents.