This class (importable from peyotl.nexson_syntax) provides a simple container for holding the set of variables needed to convert from one format to another (with error checking). The primary motivation for this class is to:
- generate type conversion errors up front when some one requests a particular coercion. For example, this allows the phylesystem api to raise an error before it fetches the data in cases in which the user is requesting a format/content combination is not currently supported (or not possible)
- allow that agreed-upon coercion to be done later with a simple call to convert or serialize. So the class acts like a closure that can transform any nexson to the desired format (if NexSON has the necessary content)
This class is used internally by peyotl. Client code may have to create instances of PhyloSchema objects, but should not need to call methods of the objects.
Initialization
PhyloSchema.__init__(schema, **kwargs) creates an object where the arguments are:
-
schemaNoneone ofnexsonnewick |nexml|nexus` -
contentone offilemetaotuotumapotusstudysubtreetree - content_id = None if
content==studyormeta)
a string ifcontentisfile,otu,otumap,otus,tree, or
a tuple of strings (TREE_ID, NODE_ID) ifcontent==tree type_ext(only used ifschemais None to infer schema using the rule
‘.nexson’ -> ‘nexson’,
‘.nexml’-> ‘nexml’,
‘.nex’-> ‘nexus’,
‘.tre’-> ‘newick’,
‘.nwk’-> ‘newick’,output_nexml2jsonused if the schema is NexSON should be0.0.0,1.0.0,1.2.1specifies the version of NexSONformat_stracts likeschema(but has lower priority than type_ext and output_nexml2json)versionacts likeoutput_nexml2jsonotu_label(see below)
If OTUs are requested, the otu_label specifies what field will be used to represent the otu. This should
be ot:originalLabel, ot:ottId, or ot:ottTaxonName (but the value is not case sensitive).
create_content_spec factory
create_content_spec returns a PhyloSchema object.
As seen above, the PhyloSchema(...) initializer is quite complex and its generic nature leads to some cryptic names (e.g. content_id can hold a tree ID, or an OTU ID depending on the content argument).
The create_content_spec(**kwargs) supports some more specific arguments that lead to clearer
calls on the client side. The arguments for this function support:
formatas an alias forformat_strnexson_versionas an alias ofversiontip_labelas an alias forotu_labeltree_id=TREEID, subtree_id=NODEIDortree_id=TREEID, node_id=NODEIDas aliases forcontent="subtree", content_id=(TREEID, NODEID)tree_id=TREEIDas an alias forcontent="tree", content=TREEIDotus_id=OTUSIDas an alias forcontent="otus", content=OTUSIDotu_id=OTUIDas an alias forcontent="otu", content=OTUID
