def _write_node_body(self, node, out):
     out.write(self._render_node_tag(node))
     if node.edge and node.edge.length != None and not self.suppress_edge_lengths:
         out.write(":{}".format(self.edge_label_compose_fn(node.edge)))
     if not self.suppress_annotations:
         node_annotation_comments = nexusprocessing.format_item_annotations_as_comments(node,
                 nhx=self.annotations_as_nhx,
                 real_value_format_specifier=self.real_value_format_specifier)
         out.write(node_annotation_comments)
         edge_annotation_comments = nexusprocessing.format_item_annotations_as_comments(node.edge,
                 nhx=self.annotations_as_nhx,
                 real_value_format_specifier=self.real_value_format_specifier)
         out.write(edge_annotation_comments)
     out.write(self._compose_comment_string(node))
     out.write(self._compose_comment_string(node.edge))
 def _write_node_body(self, node, out):
     out.write(self._render_node_tag(node))
     if node.edge and node.edge.length != None and not self.suppress_edge_lengths:
         out.write(":{}".format(self.edge_label_compose_fn(node.edge)))
     if not self.suppress_annotations:
         node_annotation_comments = nexusprocessing.format_item_annotations_as_comments(node,
                 nhx=self.annotations_as_nhx,
                 real_value_format_specifier=self.real_value_format_specifier)
         out.write(node_annotation_comments)
         edge_annotation_comments = nexusprocessing.format_item_annotations_as_comments(node.edge,
                 nhx=self.annotations_as_nhx,
                 real_value_format_specifier=self.real_value_format_specifier)
         out.write(edge_annotation_comments)
     out.write(self._compose_comment_string(node))
     out.write(self._compose_comment_string(node.edge))
Exemple #3
0
 def _write_item_annotations(self, stream, item):
     if not self.suppress_annotations and item.annotations:
         a = nexusprocessing.format_item_annotations_as_comments(
             item,
             nhx=self.annotations_as_nhx,
             real_value_format_specifier=self.real_value_format_specifier)
         stream.write("{}\n".format(a))
Exemple #4
0
 def _write_tree_list(self, stream, tree_list):
     """
     Writes a |TreeList| in Newick schema to ``stream``.
     """
     for tree in tree_list:
         self._write_tree(stream, tree)
         stream.write("\n")
     # In Newick format, no clear way to distinguish between
     # annotations/comments associated with tree collection and
     # annotations/comments associated with first tree. So we place them at
     # *end* of document.
     if (not self.suppress_annotations) and (hasattr(
             tree_list, "_annotations")):
         annotation_comments = nexusprocessing.format_item_annotations_as_comments(
             tree_list,
             nhx=self.annotations_as_nhx,
             real_value_format_specifier=self.real_value_format_specifier,
         )
     else:
         annotation_comments = ""
     treelist_comments = self._compose_comment_string(tree_list)
     stream.write("{}{}".format(annotation_comments, treelist_comments))
 def _write_tree_list(self, stream, tree_list):
     """
     Writes a |TreeList| in Newick schema to ``stream``.
     """
     for tree in tree_list:
         self._write_tree(stream, tree)
         stream.write("\n")
     # In Newick format, no clear way to distinguish between
     # annotations/comments associated with tree collection and
     # annotations/comments associated with first tree. So we place them at
     # *end* of document.
     if (not self.suppress_annotations) and (hasattr(tree_list, "_annotations")):
         annotation_comments = nexusprocessing.format_item_annotations_as_comments(tree_list,
                 nhx=self.annotations_as_nhx,
                 real_value_format_specifier=self.real_value_format_specifier,
                 )
     else:
         annotation_comments = ""
     treelist_comments = self._compose_comment_string(tree_list)
     stream.write("{}{}".format(
             annotation_comments,
             treelist_comments))
Exemple #6
0
 def _write_tree(self, stream, tree):
     """
     Composes and writes ``tree`` to ``stream``.
     """
     if tree.rooting_state_is_undefined or self.suppress_rooting:
         rooting = ""
     elif tree.is_rooted:
         rooting = "[&R] "
     elif not tree.is_rooted:
         rooting = "[&U] "
     else:
         rooting = ""
     if self.store_tree_weights and tree.weight is not None:
         weight = "[&W {}] ".format(tree.weight)
     else:
         weight = ""
     if not self.suppress_annotations:
         annotation_comments = nexusprocessing.format_item_annotations_as_comments(
             tree,
             nhx=self.annotations_as_nhx,
             real_value_format_specifier=self.real_value_format_specifier,
         )
     else:
         annotation_comments = ""
     tree_comments = self._compose_comment_string(tree)
     stream.write("{}{}{}{}".format(
         rooting,
         weight,
         annotation_comments,
         tree_comments,
     ))
     tree.apply(
         before_fn=lambda x: self._write_node_open(x, stream),
         after_fn=lambda x: self._write_node_close(x, stream),
         leaf_fn=lambda x: self._write_leaf(x, stream),
     )
     stream.write(";")
 def _write_tree(self, stream, tree):
     """
     Composes and writes ``tree`` to ``stream``.
     """
     if tree.rooting_state_is_undefined or self.suppress_rooting:
         rooting = ""
     elif tree.is_rooted:
         rooting = "[&R] "
     elif not tree.is_rooted:
         rooting = "[&U] "
     else:
         rooting = ""
     if self.store_tree_weights and tree.weight is not None:
         weight = "[&W {}] ".format(tree.weight)
     else:
         weight = ""
     if not self.suppress_annotations:
         annotation_comments = nexusprocessing.format_item_annotations_as_comments(tree,
                 nhx=self.annotations_as_nhx,
                 real_value_format_specifier=self.real_value_format_specifier,
                 )
     else:
         annotation_comments = ""
     tree_comments = self._compose_comment_string(tree)
     stream.write("{}{}{}{}".format(
             rooting,
             weight,
             annotation_comments,
             tree_comments,
             ))
     tree.apply(
             before_fn=lambda x: self._write_node_open(x, stream),
             after_fn=lambda x: self._write_node_close(x, stream),
             leaf_fn=lambda x: self._write_leaf(x, stream),
             )
     stream.write(";")
Exemple #8
0
 def _write_item_annotations(self, stream, item):
     if not self.suppress_annotations and item.annotations:
         a = nexusprocessing.format_item_annotations_as_comments(item,
                 nhx=self.annotations_as_nhx,
                 real_value_format_specifier=self.real_value_format_specifier)
         stream.write("{}\n".format(a))