python-nexus 1.7
pip install python-nexus==1.7
Released:
A nexus (phylogenetics) file reader (.nex, .trees)
Navigation
Unverified details
These details have not been verified by PyPIProject links
Meta
- License: BSD License (BSD)
- Author: Simon Greenhill
- Tags phylogenetics, nexus, newick, paup, splitstree
Classifiers
- Intended Audience
- License
- Programming Language
- Topic
Project description
Reading a Nexus
>>> import os >>> EXAMPLE_DIR = os.path.join(os.path.dirname(__file__), 'examples') >>> >>> from nexus import NexusReader >>> n = NexusReader() >>> n.read_file(os.path.join(EXAMPLE_DIR, 'example.nex')) ... >>> n = NexusReader(os.path.join(EXAMPLE_DIR, 'example.nex')) ...
# display blocks found in data file >>> n.blocks {‘data’: <NexusDataBlock: 2 characters from 4 taxa>}
data blocks
>>> n.data.nchar 2
>>> n.data.ntaxa 4
>>> n.data.format {'datatype': 'standard', 'symbols': '01', 'gap': '-'}
>>> n.data.matrix.keys() ['Simon', 'Louise', 'Betty', 'Harry']
>>> n.data.matrix['Simon'] ['0', '1']
>>> sorted(n.data.taxa) ['Betty', 'Harry', 'Louise', 'Simon']
>>> sorted(n.data.matrix.keys()) ['Betty', 'Harry', 'Louise', 'Simon']
>>> for taxon, characters in n.data: #doctest: +SKIP
tree blocks
>>> n = NexusReader(os.path.join(EXAMPLE_DIR, 'example.trees')) >>> n.trees.ntrees 3 >>> n.trees.trees[0][0:60] 'tree tree.0.1065.603220 = (((((((Chris:0.0668822155,Bruce:0.'
>>> for tree in n.trees: #doctest: +SKIP
Writing a Nexus File
>>> from nexus import NexusWriter >>> n = NexusWriter()
Add a comment to appear in the header of the file >>> n.add_comment(“I am a comment”)
data are added by using the “add” function - which takes 3 arguments, a taxon, a character name, and a value
>>> n.add('taxon1', 'Character1', 'A') >>> n.data {'Character1': {'taxon1': 'A'}} >>> n.add('taxon2', 'Character1', 'C') >>> n.add('taxon3', 'Character1', 'A')
Characters and values can be strings or integers >>> n.add(‘taxon1’, 2, 1) >>> n.add(‘taxon2’, 2, 2) >>> n.add(‘taxon3’, 2, 3)
NexusWriter will interpolate missing entries (i.e. taxon2 in this case) >>> n.add(‘taxon1’, “Char3”, ‘4’) >>> n.add(‘taxon3’, “Char3”, ‘4’)
… when you’re ready, you can generate the nexus using make_nexus or write_to_file: n.make_nexus(interleave=True, charblock=True) n.write_to_file(filename=”output.nex”, interleave=True, charblock=True)
Project details
Unverified details
These details have not been verified by PyPIProject links
Meta
- License: BSD License (BSD)
- Author: Simon Greenhill
- Tags phylogenetics, nexus, newick, paup, splitstree
Classifiers
- Intended Audience
- License
- Programming Language
- Topic
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 python-nexus-1.7.tar.gz
.
File metadata
- Download URL: python-nexus-1.7.tar.gz
- Upload date:
- Size: 38.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: Python-urllib/3.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 28198a035160adc2de8d2983fcced982da1fbf44e63304a5aa91b8f5b110f0c0 |
|
MD5 | bd09514d313bd5b15a8c4671cbfd9a08 |
|
BLAKE2b-256 | 17552ad24b6e172b19bb78e554e03f05845e72b5eb494f1b96f11c3333e5fa17 |
File details
Details for the file python_nexus-1.7-py2.py3-none-any.whl
.
File metadata
- Download URL: python_nexus-1.7-py2.py3-none-any.whl
- Upload date:
- Size: 75.9 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: Python-urllib/3.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 80ee07ca705e758bb8ee8702a5eb3f35b1d883264f3f0cb87529bcbed24ce82f |
|
MD5 | b16de8319ad7d556cc85d186864c5d6e |
|
BLAKE2b-256 | 72ac761b45c281dab4b73dd6905f7ea5ec6396f9bb883f76a4a00a20ac642063 |