A nexus (phylogenetics) file reader and writer (.nex, .trees)
Project description
commonnexus
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 asASSUMPTIONS
.
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file commonnexus-1.0.0.tar.gz
.
File metadata
- Download URL: commonnexus-1.0.0.tar.gz
- Upload date:
- Size: 65.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 59d1e8ed23749fdd13cbf05960f1f9e1d70e3cf60b1fa8713f48386a8245a9bf |
|
MD5 | afcf6c7d5d1d62b1e5ceec3af2a1aa1c |
|
BLAKE2b-256 | 9a507733580336e4d3a01a03be36e105881a12b73c1a06cadfd35d2ff566fb6e |
File details
Details for the file commonnexus-1.0.0-py2.py3-none-any.whl
.
File metadata
- Download URL: commonnexus-1.0.0-py2.py3-none-any.whl
- Upload date:
- Size: 75.7 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ff62ead5f4eade931bc013174c0d1337d8951427f014fac69e10116f1bedf04c |
|
MD5 | 0fac7a25ec135a95c559cfd36ddf993d |
|
BLAKE2b-256 | b5f8e2407b5701f90cec830a3dd34004985a4a5e5d27c0197b9c72ece27c00e5 |