Пример #1
0
    def __init__(self, **kwargs):
        """
        __init__ recognizes the following keywords (in addition to those of `DataReader.__init__`):

            - `taxon_set`: TaxonSet object to use when reading data
            - `as_rooted=True` (or `as_unrooted=False`): interprets trees as rooted
            - `as_unrooted=True` (or `as_rooted=False`): interprets trees as unrooted
            - `default_as_rooted=True` (or `default_as_unrooted=False`): interprets
               all trees as rooted if rooting not given by `[&R]` or `[&U]` comments
            - `default_as_unrooted=True` (or `default_as_rooted=False`): interprets
               all trees as rooted if rooting not given by `[&R]` or `[&U]` comments
            - `edge_len_type`: specifies the type of the edge lengths (int or float)
            - `encode_splits`: specifies whether or not split bitmasks will be
               calculated and attached to the edges.
            - `finish_node_func`: is a function that will be applied to each node
               after it has been constructed
            - `allow_duplicate_taxon_labels` : if True, allow duplicate labels
               on trees
            - `ignore_missing_node_info` : if True, then no errors will be thrown if
               tree nodes do not have the the required information.
        """
        if 'edge_len_type' not in kwargs:
            kwargs['edge_len_type'] = float
        NexusReader.__init__(self, **kwargs)
        self.is_ignore_missing_node_info = kwargs.get('ignore_missing_node_info', False)
Пример #2
0
 def read(self, stream):
     """
     Instantiates and returns a DataSet object based on the
     NEXUS-formatted contents given in the file-like object `stream`.
     """
     if self.dataset is None:
         new_tree_list_idx = 0
     else:
         new_tree_list_idx = len(self.dataset.tree_lists)
     self.dataset = NexusReader.read(self, stream)
     for tree_list in self.dataset.tree_lists[new_tree_list_idx:]:
         for tree in tree_list:
             BeastSummaryTreeReader.parse_beast_tree_node_info(tree,
                     set_node_attributes=True,
                     value_type=float,
                     create_field_if_missing=True,
                     ignore_missing=self.is_ignore_missing_node_info)
     return self.dataset
Пример #3
0
 def tree_source_iter(self, stream):
     """
     Iterates over a NEXUS-formatted source of trees.
     Only trees will be returned, and any and all character data will
     be skipped. The iterator will span over multiple tree blocks,
     but, because our NEXUS data model implementation currently does
     not recognize multiple taxon collection definnitions, taxa in
     those tree blocks will be aggregated into the same `TaxonSet` (a
     new one created, or the one passed to this method via the
     `taxon_set` argument). This behavior is similar to how multiple
     tree blocks are handled by a full NEXUS data file read.
     """
     for tree in NexusReader.tree_source_iter(self, stream):
         BeastSummaryTreeReader.parse_beast_tree_node_info(tree,
                 set_node_attributes=True,
                 value_type=float,
                 create_field_if_missing=True,
                 ignore_missing=self.is_ignore_missing_node_info)
         yield tree