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]TiONSis processed asASSUMPTIONS.
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
listofCommandobjects, - missing states in a CHARACTERS MATRIX are conveyed as
Nonevalues, 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
Release files for commonnexus 2.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| commonnexus-2.0.0.tar.gz | 93.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| commonnexus-2.0.0-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details |
Total release size: 183.2 kB
Release files / commonnexus-2.0.0.tar.gz
| Download URL | commonnexus-2.0.0.tar.gz |
|---|---|
| Size | 93.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8790d6b50ef0767356efb6295c07695d8ec9e094d1d0cea9d53e673bd897db2c
|
|
BLAKE2b-256 checksum How to use checksums |
ed717232173c09dad5720bf6c5f759b4ffa25e9690bd85cad883cab4b6a016a2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.3
|
Release files / commonnexus-2.0.0-py2.py3-none-any.whl
| Download URL | commonnexus-2.0.0-py2.py3-none-any.whl |
|---|---|
| Size | 89.6 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
9804ee6686f846938bd09d74f0056f18ea23baa83da4c351b542a604b3a7f094
|
|
BLAKE2b-256 checksum How to use checksums |
7af4f8ca5a209995685de6b3b519e0d03eb304c2d69518ee2ece44bb386869d6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.3
|