Exemple #1
0
def _spacingx(current_node, max_dims, offsets, spacing):
    '''Determine the spacing of the current node depending on the number
       of the leaves of the tree
    '''
    x_spacing = n_terminations(current_node) * spacing[0]

    if x_spacing > max_dims[0]:
        max_dims[0] = x_spacing

    return offsets[0] - x_spacing / 2.
Exemple #2
0
def _spacingx(current_node, max_dims, offsets, spacing):
    '''Determine the spacing of the current node depending on the number
       of the leaves of the tree
    '''
    x_spacing = n_terminations(current_node) * spacing[0]

    if x_spacing > max_dims[0]:
        max_dims[0] = x_spacing

    return offsets[0] - x_spacing / 2.
Exemple #3
0
def _spacingx(node, max_dims, xoffset, xspace):
    '''Determine the spacing of the current node depending on the number
       of the leaves of the tree
    '''
    x_spacing = n_terminations(node) * xspace

    if x_spacing > max_dims[0]:
        max_dims[0] = x_spacing

    return xoffset - x_spacing / 2.
Exemple #4
0
def _generate_dendro(current_node, lines, colors, n, max_dims,
                     spacing, offsets, show_diameters=True):
    '''Recursive function for dendrogram line computations
    '''

    start_x = _spacingx(current_node, max_dims, offsets, spacing)

    radii = [0., 0.]
    # store the parent radius in order to construct polygonal segments
    # isntead of simple line segments
    radii[0] = current_node.value[3] if show_diameters else 0.

    for child in current_node.children:

        # segment length
        length = segment_length(list(val_iter((current_node, child))))

        # extract the radius of the child node. Need both radius for
        # realistic segment representation
        radii[1] = child.value[3] if show_diameters else 0.

        # number of leaves in child
        terminations = n_terminations(child)

        # horizontal spacing with respect to the number of
        # terminations
        new_offsets = (start_x + spacing[0] * terminations / 2.,
                       offsets[1] + spacing[1] * 2. + length)

        # vertical segment
        lines[n[0]] = _vertical_segment(offsets, new_offsets, spacing, radii)

        # assign segment id to color array
        colors[n[0]] = child.value[4]
        n[0] += 1

        if offsets[1] + spacing[1] * 2 + length > max_dims[1]:
            max_dims[1] = offsets[1] + spacing[1] * 2. + length

        # recursive call to self.
        _generate_dendro(child, lines, colors, n, max_dims,
                         spacing, new_offsets, show_diameters=show_diameters)

        # update the starting position for the next child
        start_x += terminations * spacing[0]

        # write the horizontal lines only for bifurcations, where the are actual horizontal lines
        # and not zero ones
        if offsets[0] != new_offsets[0]:

            # horizontal segment
            lines[n[0]] = _horizontal_segment(offsets, new_offsets, spacing, 0.)
            colors[n[0]] = current_node.value[4]
            n[0] += 1
Exemple #5
0
    def _generate_dendro(self, current_node, spacing, offsets):
        '''Recursive function for dendrogram line computations
        '''
        max_dims = self._max_dims
        start_x = _spacingx(current_node, max_dims, offsets[0], spacing[0])

        radii = [0., 0.]
        # store the parent radius in order to construct polygonal segments
        # isntead of simple line segments
        radii[0] = current_node.value[COLS.R] if self._show_diameters else 0.

        for child in current_node.children:

            # segment length
            ln = segment_length((current_node.value, child.value))

            # extract the radius of the child node. Need both radius for
            # realistic segment representation
            radii[1] = child.value[COLS.R] if self._show_diameters else 0.

            # number of leaves in child
            terminations = n_terminations(child)

            # horizontal spacing with respect to the number of
            # terminations
            new_offsets = _update_offsets(start_x, spacing, terminations, offsets, ln)

            # create and store vertical segment
            self._rectangles[self._n] = _vertical_segment(offsets, new_offsets, spacing, radii)

            # assign segment id to color array
            # colors[n[0]] = child.value[4]
            self._n += 1

            if offsets[1] + spacing[1] * 2 + ln > max_dims[1]:
                max_dims[1] = offsets[1] + spacing[1] * 2. + ln

            self._max_dims = max_dims
            # recursive call to self.
            self._generate_dendro(child, spacing, new_offsets)

            # update the starting position for the next child
            start_x += terminations * spacing[0]

            # write the horizontal lines only for bifurcations, where the are actual horizontal
            # lines and not zero ones
            if offsets[0] != new_offsets[0]:

                # horizontal segment. Thickness is either 0 if show_diameters is false
                # or 1. if show_diameters is true
                self._rectangles[self._n] = _horizontal_segment(offsets, new_offsets, spacing, 0.)
                self._n += 1
Exemple #6
0
def test_n_terminations():
    nt.ok_(n_terminations(tree0) == 11)
Exemple #7
0
def _generate_dendro(current_node,
                     lines,
                     colors,
                     n,
                     max_dims,
                     spacing,
                     offsets,
                     show_diameters=True):
    '''Recursive function for dendrogram line computations
    '''

    start_x = _spacingx(current_node, max_dims, offsets, spacing)

    radii = [0., 0.]
    # store the parent radius in order to construct polygonal segments
    # isntead of simple line segments
    radii[0] = current_node.value[3] if show_diameters else 0.

    for child in current_node.children:

        # segment length
        length = segment_length(list(val_iter((current_node, child))))

        # extract the radius of the child node. Need both radius for
        # realistic segment representation
        radii[1] = child.value[3] if show_diameters else 0.

        # number of leaves in child
        terminations = n_terminations(child)

        # horizontal spacing with respect to the number of
        # terminations
        new_offsets = (start_x + spacing[0] * terminations / 2.,
                       offsets[1] + spacing[1] * 2. + length)

        # vertical segment
        lines[n[0]] = _vertical_segment(offsets, new_offsets, spacing, radii)

        # assign segment id to color array
        colors[n[0]] = child.value[4]
        n[0] += 1

        if offsets[1] + spacing[1] * 2 + length > max_dims[1]:
            max_dims[1] = offsets[1] + spacing[1] * 2. + length

        # recursive call to self.
        _generate_dendro(child,
                         lines,
                         colors,
                         n,
                         max_dims,
                         spacing,
                         new_offsets,
                         show_diameters=show_diameters)

        # update the starting position for the next child
        start_x += terminations * spacing[0]

        # write the horizontal lines only for bifurcations, where the are actual horizontal lines
        # and not zero ones
        if offsets[0] != new_offsets[0]:

            # horizontal segment
            lines[n[0]] = _horizontal_segment(offsets, new_offsets, spacing,
                                              0.)
            colors[n[0]] = current_node.value[4]
            n[0] += 1