NexusSets
¶
-
class
NexusSets
[source]¶ A container for Nexus CharSet, CharPartition, and TaxSet objects.
When the first Nexus sets block is read, a NexusSets object is made and saved as
var.nexusSets
.CharSet
,TaxSet
, andCharPartition
objects are placed in it, as they are read/created. TaxPartition commands are not implemented. Here is a simple nexus sets block that only has charsets:#nexus begin sets; charset pos1 = 1-.\3; charset pos2 = 2-.\3; charset pos3 = 3-.\3; end;
To get the third positions only, you could say:
read('myAlignment.phy') a = var.alignments[0] read('mySets.nex') # the sets block above b = a.subsetUsingCharSet('pos3')
What happens above when the mySets.nex file is read is that a NexusSets object is created as
var.nexusSets
and populated with the three charsets as CharSet objects. Then when you asked for a subset, a copy of that NexusSets object was made and applied to the alignment.Notice that the length of the alignment is not part of the information in the sets block, and so things remain undefined in
var.nexusSets
until the nexus sets are applied to a particular alignment. One consequence of this somewhat awkward system is that the same charsets could then be applied to another alignment of a different size:read('myAlignment.phy') aA = var.alignments[0] read('anotherAlignment.nex') aB = var.alignments[1] read('mySets.nex') # the sets block above bA = aA.subsetUsingCharSet('pos3') bB = aB.subsetUsingCharSet('pos3')
In the above example,
bA.nexusSets
andbB.nexusSets
are both derived fromvar.nexusSets
but are independent of it, and different from each other.So when an Alignment (or Tree object) wants to use
var.nexusSets
, it makes a copy of it, and attaches the copy as theAlignment.nexusSets or theTree.nexusSetsHere is another example, including a
charPartition
definition:begin sets; charset gene1 = 1-213; charset gene2 = 214-497; charPartition cpName = gene1:gene1, gene2:gene2; end;
For an alignment, you can then set a character partition by
a.setCharPartition(cpName)
Do this before you make a Data object, to partition the alignment.
You can also use charsets to extract subsets, eg via:
b = a.subsetUsingCharSet(csName)
Setting a charPartition or asking for a subset will trigger applying
var.nexusSets
to the alignment, but you can also do it explicitly, by:myTree.setNexusSets()
NexusSets knows about predefined ‘constant’, ‘gapped’, and ‘remainder’ charsets. It does not know about ‘missambig’ or ‘uninf’ charsets.
NexusSets can either be in the default standard format or in vector format – you can change them to vector format with the
mySet.vectorize()
method, and you can change them to standard format with the
mySet.standardize()
method. For taxSets, you can use actual tax names (rather than numbers or ranges) by setting:
myTaxSet.useTaxNames = True # default None
Each taxSet has a:
taxSet.taxNames
list, which might be handy.
You can see the current state of a NexusSets object using
myNexusSets.dump()
It can also be written out as a nexus sets block. If an Alignment object has a
nexusSets
attribute then if you ask the alignment to write itself to a nexus file then the Alignment.nexusSets is also written. If you would rather it not be written, delete it first. If you would rather it be written to a separate file, do that first and then delete it.One nice thing about taxsets is that
Tree.Tree.tv()
andTree.Tree.btv()
know about them and can display them.