commonnexus 1.5.0__tar.gz → 1.6.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {commonnexus-1.5.0/src/commonnexus.egg-info → commonnexus-1.6.0}/PKG-INFO +1 -1
- {commonnexus-1.5.0 → commonnexus-1.6.0}/setup.cfg +1 -1
- {commonnexus-1.5.0 → commonnexus-1.6.0}/src/commonnexus/__init__.py +1 -1
- {commonnexus-1.5.0 → commonnexus-1.6.0}/src/commonnexus/tools/normalise.py +17 -2
- {commonnexus-1.5.0 → commonnexus-1.6.0/src/commonnexus.egg-info}/PKG-INFO +1 -1
- {commonnexus-1.5.0 → commonnexus-1.6.0}/LICENSE +0 -0
- {commonnexus-1.5.0 → commonnexus-1.6.0}/README.md +0 -0
- {commonnexus-1.5.0 → commonnexus-1.6.0}/setup.py +0 -0
- {commonnexus-1.5.0 → commonnexus-1.6.0}/src/commonnexus/__main__.py +0 -0
- {commonnexus-1.5.0 → commonnexus-1.6.0}/src/commonnexus/blocks/__init__.py +0 -0
- {commonnexus-1.5.0 → commonnexus-1.6.0}/src/commonnexus/blocks/assumptions.py +0 -0
- {commonnexus-1.5.0 → commonnexus-1.6.0}/src/commonnexus/blocks/base.py +0 -0
- {commonnexus-1.5.0 → commonnexus-1.6.0}/src/commonnexus/blocks/characters.py +0 -0
- {commonnexus-1.5.0 → commonnexus-1.6.0}/src/commonnexus/blocks/codons.py +0 -0
- {commonnexus-1.5.0 → commonnexus-1.6.0}/src/commonnexus/blocks/distances.py +0 -0
- {commonnexus-1.5.0 → commonnexus-1.6.0}/src/commonnexus/blocks/notes.py +0 -0
- {commonnexus-1.5.0 → commonnexus-1.6.0}/src/commonnexus/blocks/sets.py +0 -0
- {commonnexus-1.5.0 → commonnexus-1.6.0}/src/commonnexus/blocks/taxa.py +0 -0
- {commonnexus-1.5.0 → commonnexus-1.6.0}/src/commonnexus/blocks/trees.py +0 -0
- {commonnexus-1.5.0 → commonnexus-1.6.0}/src/commonnexus/blocks/unaligned.py +0 -0
- {commonnexus-1.5.0 → commonnexus-1.6.0}/src/commonnexus/cli_util.py +0 -0
- {commonnexus-1.5.0 → commonnexus-1.6.0}/src/commonnexus/command.py +0 -0
- {commonnexus-1.5.0 → commonnexus-1.6.0}/src/commonnexus/commands/__init__.py +0 -0
- {commonnexus-1.5.0 → commonnexus-1.6.0}/src/commonnexus/commands/characters.py +0 -0
- {commonnexus-1.5.0 → commonnexus-1.6.0}/src/commonnexus/commands/combine.py +0 -0
- {commonnexus-1.5.0 → commonnexus-1.6.0}/src/commonnexus/commands/help.py +0 -0
- {commonnexus-1.5.0 → commonnexus-1.6.0}/src/commonnexus/commands/normalise.py +0 -0
- {commonnexus-1.5.0 → commonnexus-1.6.0}/src/commonnexus/commands/split.py +0 -0
- {commonnexus-1.5.0 → commonnexus-1.6.0}/src/commonnexus/commands/taxa.py +0 -0
- {commonnexus-1.5.0 → commonnexus-1.6.0}/src/commonnexus/commands/trees.py +0 -0
- {commonnexus-1.5.0 → commonnexus-1.6.0}/src/commonnexus/nexus.py +0 -0
- {commonnexus-1.5.0 → commonnexus-1.6.0}/src/commonnexus/tokenizer.py +0 -0
- {commonnexus-1.5.0 → commonnexus-1.6.0}/src/commonnexus/tools/__init__.py +0 -0
- {commonnexus-1.5.0 → commonnexus-1.6.0}/src/commonnexus/tools/combine.py +0 -0
- {commonnexus-1.5.0 → commonnexus-1.6.0}/src/commonnexus/tools/matrix.py +0 -0
- {commonnexus-1.5.0 → commonnexus-1.6.0}/src/commonnexus/util.py +0 -0
- {commonnexus-1.5.0 → commonnexus-1.6.0}/src/commonnexus.egg-info/SOURCES.txt +0 -0
- {commonnexus-1.5.0 → commonnexus-1.6.0}/src/commonnexus.egg-info/dependency_links.txt +0 -0
- {commonnexus-1.5.0 → commonnexus-1.6.0}/src/commonnexus.egg-info/entry_points.txt +0 -0
- {commonnexus-1.5.0 → commonnexus-1.6.0}/src/commonnexus.egg-info/not-zip-safe +0 -0
- {commonnexus-1.5.0 → commonnexus-1.6.0}/src/commonnexus.egg-info/requires.txt +0 -0
- {commonnexus-1.5.0 → commonnexus-1.6.0}/src/commonnexus.egg-info/top_level.txt +0 -0
|
@@ -17,6 +17,9 @@ In addition, after normalisation, the following assumptions hold:
|
|
|
17
17
|
- The ";" terminating MATRIX commands is on a separate line, allowing more simplistic parsing
|
|
18
18
|
of matrix rows.
|
|
19
19
|
"""
|
|
20
|
+
import typing
|
|
21
|
+
import collections
|
|
22
|
+
|
|
20
23
|
from commonnexus import Nexus
|
|
21
24
|
from commonnexus.blocks.characters import Data
|
|
22
25
|
from commonnexus.blocks import Taxa, Distances, Characters, Trees
|
|
@@ -24,12 +27,14 @@ from commonnexus.blocks import Taxa, Distances, Characters, Trees
|
|
|
24
27
|
|
|
25
28
|
def normalise(nexus: Nexus,
|
|
26
29
|
data_to_characters: bool = False,
|
|
27
|
-
strip_comments: bool = False
|
|
30
|
+
strip_comments: bool = False,
|
|
31
|
+
remove_taxa: typing.Optional[typing.Container[str]] = None) -> Nexus:
|
|
28
32
|
"""
|
|
29
33
|
:param nexus: A `Nexus` object to be normalised in-place.
|
|
30
34
|
:param data_to_characters: Flag signaling whether DATA blocks should be converted to CHARACTER \
|
|
31
35
|
blocks.
|
|
32
36
|
:param strip_comments: Flag signaling whether to remove all non-command comments.
|
|
37
|
+
:param remove_taxa: Container of taxon labels specifying taxa to remove from relevant blocks.
|
|
33
38
|
:return: The modified `Nexus` object.
|
|
34
39
|
|
|
35
40
|
.. code-block:: python
|
|
@@ -87,6 +92,8 @@ def normalise(nexus: Nexus,
|
|
|
87
92
|
TREE 1 = (t1,t2,t3);
|
|
88
93
|
END;
|
|
89
94
|
"""
|
|
95
|
+
remove_taxa = remove_taxa or []
|
|
96
|
+
|
|
90
97
|
if strip_comments:
|
|
91
98
|
nexus = Nexus([cmd.without_comments() for cmd in nexus], config=nexus.cfg)
|
|
92
99
|
nexus = Nexus([cmd.with_normalised_whitespace() for cmd in nexus], config=nexus.cfg)
|
|
@@ -95,6 +102,7 @@ def normalise(nexus: Nexus,
|
|
|
95
102
|
if nexus.characters:
|
|
96
103
|
matrix = nexus.characters.get_matrix()
|
|
97
104
|
taxlabels = list(matrix.keys())
|
|
105
|
+
matrix = collections.OrderedDict((k, v) for k, v in matrix.items() if k not in remove_taxa)
|
|
98
106
|
characters = nexus.DATA or nexus.CHARACTERS
|
|
99
107
|
cls = Data if characters.name == 'DATA' and not data_to_characters else Characters
|
|
100
108
|
nexus.replace_block(
|
|
@@ -107,19 +115,26 @@ def normalise(nexus: Nexus,
|
|
|
107
115
|
assert set(matrix.keys()).issubset(taxlabels)
|
|
108
116
|
else:
|
|
109
117
|
taxlabels = list(matrix.keys())
|
|
118
|
+
matrix = collections.OrderedDict(
|
|
119
|
+
(k, collections.OrderedDict((kk, vv) for kk, vv in v.items() if kk not in remove_taxa))
|
|
120
|
+
for k, v in matrix.items() if k not in remove_taxa)
|
|
110
121
|
nexus.replace_block(nexus.DISTANCES, Distances.from_data(matrix))
|
|
111
122
|
|
|
112
123
|
if nexus.TREES:
|
|
113
124
|
trees = []
|
|
114
125
|
for tree in nexus.TREES.trees:
|
|
115
126
|
nwk = nexus.TREES.translate(tree) if nexus.TREES.TRANSLATE else tree.newick
|
|
127
|
+
if remove_taxa:
|
|
128
|
+
nwk.prune_by_names(remove_taxa)
|
|
116
129
|
trees.append((tree.name, nwk, tree.rooted))
|
|
117
130
|
nexus.replace_block(nexus.TREES, Trees.from_data(*trees))
|
|
118
131
|
|
|
119
132
|
if taxlabels:
|
|
133
|
+
taxa = Taxa.from_data([t for t in taxlabels if t not in remove_taxa])
|
|
120
134
|
if nexus.TAXA:
|
|
121
135
|
assert nexus.TAXA.DIMENSIONS.ntax == len(taxlabels)
|
|
122
136
|
assert set(nexus.TAXA.TAXLABELS.labels.values()) == set(taxlabels)
|
|
137
|
+
nexus.replace_block(nexus.TAXA, taxa)
|
|
123
138
|
else:
|
|
124
|
-
nexus.prepend_block(
|
|
139
|
+
nexus.prepend_block(taxa)
|
|
125
140
|
return nexus
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|