NEXUS (.nex, .nxs)


    NEXUS phylogenetic file format.
    Commonly used for storage and exchange of phylogenetic data.
    Can store DNA and protein sequences, taxa distances, alignment scores, and phylogenetic trees.
    ASCII format.
    Allows user extensions.
    Developed in the 1990s.

Import and Export

  • Import["file.nex"] imports DNA or protein sequences from a NEXUS file.
  • Export["file.nex",expr] exports a sequence or list of sequences to the NEXUS file.
  • Import["file.nex"] returns a list of strings representing the sequences stored in the file.
  • Export["file.nex",str] exports a character string representing a DNA or protein sequence to NEXUS.
  • Export["file.nex",{str1,str2,}] exports multiple sequences.
  • Import["file.nex",elem] imports the specified element from a NEXUS file.
  • Import["file.nex",{"elem","sub",}] imports a subelement.
  • Import["file.nex",{{elem1,elem2,}}] imports multiple elements.
  • The import format can be specified with Import["file","NEXUS"] or Import["file",{"NEXUS",elem,}].
  • Export["file.nex",expr,elem] creates a NEXUS file by treating expr as specifying element elem.
  • Export["file.nex",{expr1,expr2,},{{elem1,elem2,}}] treats each expri as specifying the corresponding elemi.
  • Export["file.nex",expr,opt1->val1,] exports expr with the specified option elements taken to have the specified values.
  • Export["file.nex",{elem1->expr1,elem2->expr2,},"Rules"] uses rules to specify the elements to be exported.
  • See the reference pages for full general information on Import and Export.
  • ImportString and ExportString support the NEXUS format.


  • General Import elements:
  • "Elements"list of elements and options available in this file
    "Rules"full list of rules for each element and option
    "Options"list of rules for options, properties, and settings
  • Data representation elements:
  • "DistanceMatrix"distances between taxa given as a numerical matrix
    "Sequence"sequences given as a list of strings
    "Taxa"taxon names
  • Import uses the "Sequence" element by default.
  • Additional data elements:
  • "Data""Taxa" and "Sequence" elements combined in a list
    "LabeledData"list of rules for each taxon and sequence stored in the file
  • The Wolfram Language uses the standard IUB/IUPAC abbreviations for nucleic acids and amino acids. See the reference page for "FASTA" for detailed information.


Basic Examples  (6)

Import sequence data from a NEXUS file:

Click for copyable input

Import the taxon names and sequence data as a list of rules:

Click for copyable input

Export DNA sequences to the NEXUS format:

Click for copyable input

Export a pair of DNA sequences with explicit taxon names:

Click for copyable input

This returns the taxon names stored in the file along with a distance matrix:

Click for copyable input

Import taxon names and sequence data as pairs:

Click for copyable input

See Also

"FASTA"  "GenBank"

Introduced in 2010