'Select all heatmap rows which belong to the dendrogram.'

def select_from_dendrogram(self, dendrogram, key):

    dendrogram_widget = dendrogram.parentWidget()
    anchors = list(dendrogram_widget.leaf_anchors())
    cluster = dendrogram.cluster
    (start, end) = (anchors[cluster.first], anchors[(cluster.last - 1)])
    (start, end) = (dendrogram_widget.mapToScene(start), dendrogram_widget.mapToScene(end))
    heatmap = None
    for hm in self.heatmap_widgets():
        b_rect = hm.sceneBoundingRect()
        if b_rect.contains(QPointF(b_rect.center().x(), start.y())):
            heatmap = hm
            break
    if dendrogram:
        b_rect = heatmap.boundingRect()
        (start, end) = (heatmap.mapFromScene(start), heatmap.mapFromScene(end))
        (start, _) = heatmap.cell_at(QPointF(b_rect.center().x(), start.y()))
        (end, _) = heatmap.cell_at(QPointF(b_rect.center().x(), end.y()))
        clear = (not (key & ((Qt.ControlModifier | Qt.ShiftModifier) | Qt.AltModifier)))
        remove = (key & (Qt.ControlModifier | Qt.AltModifier))
        append = (key & Qt.ControlModifier)
        self.selection_manager.selection_add(start, end, heatmap, clear=clear, remove=remove, append=append)
    return
