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

Read 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'])

Write 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

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.1.0.tar.gz (67.7 kB view details)

Uploaded Source

Built Distribution

commonnexus-1.1.0-py2.py3-none-any.whl (78.8 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

  • Download URL: commonnexus-1.1.0.tar.gz
  • Upload date:
  • Size: 67.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for commonnexus-1.1.0.tar.gz
Algorithm Hash digest
SHA256 d937db0c8e3f8dced8119c2cfb5d7fba51fca96971b51dde3a799670b7fc372d
MD5 ccf8207ac50838cc616e6842d49c0d09
BLAKE2b-256 4271d7e685949b037d4f1d95d4717f6245e6d2b77fa50c4a61e365f309a4f047

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for commonnexus-1.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 28d2638c141eb75a7f3a0f72f62ed7e6b1cfe2edb68ac50a29dab11348ecf1f9
MD5 9b59cf8cd51f1e73bb6b9f71ef26419f
BLAKE2b-256 5887518ddd146b3bd4f24bf0ffd7a21e5fba4e744d2fc1cbdfb97196092aa943

See more details on using hashes here.

Supported by

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