Exemplo n.º 1
0
def get_dot(G_orig):
    """Change labels and colors to be presented with graphviz"""
    G = G_orig.copy()
    cluster_networks.relabel_graph(G)
    tr = {}
    for node in G.nodes_iter():
        tr[node] = '"{}"'.format(node)
    nx.relabel_nodes(G, tr, copy=False)
    for node in G.nodes_iter():
        label = str(node)
        if len(label) > MAX_LABEL:
            label = u'{}..."'.format(label[:MAX_LABEL])
        G.node[node]['label'] = label
    for node in cluster_networks.get_leaf_nodes(G):
        G.node[node]['color'] = "blue"
    for node in cluster_networks.hybrid_nodes(G):
        G.node[node]['color'] = "#7BFF74"  # light green
        G.node[node]['style'] = 'filled'
    for node in cluster_networks.get_root_nodes(G):
        G.node[node]['color'] = "orange"
    for node in cluster_networks.problematic_treechild_nodes(G):
        G.node[node]['color'] = "#FF77EB"  # light pink
        G.node[node]['style'] = 'filled'
    for u, v in cluster_networks.removable_edges(G):
        G.edge[u][v]['color'] = "red"
    for root in cluster_networks.get_root_nodes(G):
        G.node[root]['label'] = '"R"'
    dot = nx.to_pydot(G).to_string()
    return dot.strip()
Exemplo n.º 2
0
    G = network
    return {
        'cluster': cluster,
        'network_dot': get_dot(G),
        'network_ascii': network.nodes(),
        'network_hard': hard,
        'subtrees': subtrees,
        'queue_key': q.key,
        'soft_job_id': soft_job_id,
        'soft_too_expensive': 1 if soft_too_expensive else 0,
        'families_job_id': families_job_id,
        'is_treechild': cluster_networks.is_treechild(G),
        'number_nodes': len(G.nodes()),
        'number_edges': len(G.edges()),
        'number_hybrids': len(cluster_networks.hybrid_nodes(G)),
        'number_leafs': len(cluster_networks.get_leaf_nodes(G)),
        'number_conflictive_nodes': len(cluster_networks.problematic_treechild_nodes(G)),
        'number_removable_edges': len(cluster_networks.removable_edges(G)),
        'hybridization_degree': cluster_networks.hybridization_degree(G),
    }

###
# Inputs
@post("/input/upload/")
def process_from_upload():
    file_content = request.forms.optionsRadios
    data = request.files.data
    if file_content and data and data.file:
        raw = data.file.read() # This is dangerous for big files
        if file_content == 'cluster':
            return process_clusters(raw)