Skip to main content

A nexus (phylogenetics) file reader and writer (.nex, .trees)

Project description

commonnexus

Build Status Documentation Status PyPI

This package provides functionality to read and write the NEXUS file format as specified in

Maddison, Swofford, and Maddison (1997). "NEXUS: An extensible file format for systematic information". Systematic Biology. 46 (4): 590–621. doi:10.1093/sysbio/46.4.590

Rather than trying to rip out relevant portions of a NEXUS file as quickly as possible, the implementation in commonnexus tries to do "the right thing" according to the specification, i.e. parse a file token by token. Thus, we sacrifice speed for correctness and the ability to support weird edge cases like

Comments do not break tokens. Thus, AssuMP[comment]TiONS is processed as ASSUMPTIONS.

Install

Install commonnexus from PyPI:

pip install commonnexus

Overview

commonnexus provides a Python API as well as a shell command to manipulate (the data in) NEXUS files.

In particular, it allows reading NEXUS

>>> from commonnexus import Nexus
>>> nex = Nexus.from_file('docs/characters.nex')
>>> nex.CHARACTERS.get_matrix()['t1'].values()
odict_values(['1', '0', '0', '1', '0', '1', '0', '0', '0', '0'])

and writing NEXUS

>>> from commonnexus import Nexus
>>> from commonnexus.blocks import Data
>>> nex = Nexus.from_file('docs/characters.nex')
>>> print(Nexus.from_blocks(Data.from_data(nex.CHARACTERS.get_matrix())))
#NEXUS
BEGIN DATA;
DIMENSIONS NCHAR=10;
FORMAT DATATYPE=STANDARD MISSING=? GAP=- SYMBOLS="01";
MATRIX 
t1 1001010000
t2 0101000100
t3 0011101010
t4 0001100001
t5 0001100001
;
END;

Command line usage

Installing the commonnexus package will also install a command line interface commonnexus, which provides several sub-commands to manipulate NEXUS files.

Run commonnexus -h to get an overview of available sub-commands or find detailed documentation with examples on ReadTheDocs.

Python API

The Python API tries to convert NEXUS constructs to appropriate Python objects, e.g.

  • NEXUS content is a list of Command objects,
  • missing states in a CHARACTERS MATRIX are conveyed as None values, etc.

This allows for dealing with NEXUS data in a way that is abstracted from the NEXUS formatting conventions

For a detailed documentation of the Python API, refer to the docs on ReadTheDocs.

See also

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

commonnexus-1.9.3.tar.gz (86.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

commonnexus-1.9.3-py2.py3-none-any.whl (81.7 kB view details)

Uploaded Python 2Python 3

File details

Details for the file commonnexus-1.9.3.tar.gz.

File metadata

  • Download URL: commonnexus-1.9.3.tar.gz
  • Upload date:
  • Size: 86.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for commonnexus-1.9.3.tar.gz
Algorithm Hash digest
SHA256 7742353b72a4c7b87583bd17c8409261ff13ad50b981d1a1f7052c598402aa2b
MD5 c8a98aa4451569925a81e3478a5173a8
BLAKE2b-256 ae8a78f56f195dfffee84da54889978c47b7c83231d007180ab3e045adf0dff5

See more details on using hashes here.

File details

Details for the file commonnexus-1.9.3-py2.py3-none-any.whl.

File metadata

  • Download URL: commonnexus-1.9.3-py2.py3-none-any.whl
  • Upload date:
  • Size: 81.7 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for commonnexus-1.9.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 9d59b5b78b5154fe52cadabdb01d11d4ce7179450d68631877b49d2beb667e17
MD5 c69964a62c18c8c6deac55bd2d0e2c25
BLAKE2b-256 7814e21914cc47d87d78b860647ff1fe1bbf6eda4b8c9814dbc0dea1f73f21b4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page