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 can read sequence data and distance matrices from NEXUS files.
  • Export converts sequence data to the NEXUS format.

Import and ExportImport 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 as specifying the corresponding .
  • 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.

ElementsElements

  • 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 element by default.
  • Additional data elements:
  • "Data" and elements combined in a list
    "LabeledData"list of rules for each taxon and sequence stored in the file
  • Mathematica uses the standard IUB/IUPAC abbreviations for nucleic acids and amino acids. See the reference page for "FASTA" for detailed information.

ExamplesExamplesopen allclose all

Basic Examples (6)Basic Examples (6)

Import sequence data from a NEXUS file:

In[1]:=
Click for copyable input
Out[1]=

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

In[1]:=
Click for copyable input
Out[1]=

Export DNA sequences to the NEXUS format:

In[1]:=
Click for copyable input
Out[1]=

Export a pair of DNA sequences with explicit taxon names:

In[1]:=
Click for copyable input
Out[1]=

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

In[1]:=
Click for copyable input
Out[1]=

Import taxon names and sequence data as pairs:

In[1]:=
Click for copyable input
Out[1]=
New in 8
New to Mathematica? Find your learning path »
Have a question? Ask support »