Esempio n. 1
0
def expression_cluster_json(cluster_id, family_method_id=None):
    """
    Generates JSON output compatible with cytoscape.js (see planet/static/planet_graph.js for details how to render)

    :param cluster_id: id of the cluster to plot
    :param family_method_id: gene family method used for color coding the graph
    """
    network = CoexpressionCluster.get_cluster(cluster_id)

    if family_method_id is None:
        family_method = GeneFamilyMethod.query.first()
        if family_method is not None:
            family_method_id = family_method.id
        else:
            family_method_id = None

    network_cytoscape = CytoscapeHelper.parse_network(network)
    network_cytoscape = CytoscapeHelper.add_family_data_nodes(
        network_cytoscape, family_method_id)
    network_cytoscape = CytoscapeHelper.add_lc_data_nodes(network_cytoscape)
    network_cytoscape = CytoscapeHelper.add_connection_data_nodes(
        network_cytoscape)
    network_cytoscape = CytoscapeHelper.add_descriptions_nodes(
        network_cytoscape)

    return Response(json.dumps(network_cytoscape), mimetype='application/json')
Esempio n. 2
0
def expression_network_json(node_id, family_method_id=None):
    """
    Generates JSON output compatible with cytoscape.js (see planet/static/planet_graph.js for details how to render)

    :param node_id: id of the network's probe (the query) to visualize
    :param family_method_id: Which gene families to use
    """

    node = ExpressionNetwork.query.get(node_id)
    enable_second_level = node.method.enable_second_level
    depth = 1 if enable_second_level else 0

    network = ExpressionNetwork.get_neighborhood(node_id, depth=depth)

    if family_method_id is None:
        family_method = GeneFamilyMethod.query.first()
        if family_method is not None:
            family_method_id = family_method.id
        else:
            family_method_id = None

    network_cytoscape = CytoscapeHelper.parse_network(network)
    network_cytoscape = CytoscapeHelper.add_family_data_nodes(
        network_cytoscape, family_method_id)
    network_cytoscape = CytoscapeHelper.add_lc_data_nodes(network_cytoscape)
    network_cytoscape = CytoscapeHelper.add_descriptions_nodes(
        network_cytoscape)

    return Response(json.dumps(network_cytoscape), mimetype='application/json')
Esempio n. 3
0
def graph_comparison_cluster_json(one, two, family_method_id=None):
    """
    Controller that fetches network data from two clusters from the database, adds all essential information and merges
    the two networks. The function returns a JSON object compatible with cytoscape.js

    :param one: internal id of the first cluster
    :param two: internal id of the second cluster
    :param family_method_id: internal id of the gene family method (used down stream for coloring and connecting)
    :return: json object compatible with cytoscape.js and our UI elements
    """
    if family_method_id is None:
        family_method = GeneFamilyMethod.query.first()
        family_method_id = family_method.id

    network_one = CytoscapeHelper.parse_network(
        CoexpressionCluster.get_cluster(one))
    network_one = CytoscapeHelper.add_family_data_nodes(
        network_one, family_method_id)
    network_one = CytoscapeHelper.add_connection_data_nodes(network_one)

    network_two = CytoscapeHelper.parse_network(
        CoexpressionCluster.get_cluster(two))
    network_two = CytoscapeHelper.add_family_data_nodes(
        network_two, family_method_id)
    network_two = CytoscapeHelper.add_connection_data_nodes(network_two)

    output = CytoscapeHelper.merge_networks(network_one, network_two)
    output = CytoscapeHelper.add_lc_data_nodes(output)
    output = CytoscapeHelper.add_descriptions_nodes(output)

    return Response(json.dumps(output), mimetype='application/json')
Esempio n. 4
0
def ecc_graph_json(sequence, network, family):
    """
    Returns a JSON object compatible with cytoscape.js that contains the ECC graph for a specific sequence

    :param sequence: Internal ID of a sequence
    :param network: Internal ID of the network method
    :param family: Internal ID of the family method
    :return: JSON object compatible with cytoscape.js
    """

    network = SequenceSequenceECCAssociation.get_ecc_network(
        sequence, network, family)

    network_cytoscape = CytoscapeHelper.parse_network(network)
    network_cytoscape = CytoscapeHelper.add_descriptions_nodes(
        network_cytoscape)
    network_cytoscape = CytoscapeHelper.add_family_data_nodes(
        network_cytoscape, family)
    network_cytoscape = CytoscapeHelper.add_lc_data_nodes(network_cytoscape)
    network_cytoscape = CytoscapeHelper.add_species_data_nodes(
        network_cytoscape)

    return json.dumps(network_cytoscape)
Esempio n. 5
0
def ecc_graph_pair_json(ecc_id):
    """
    Returns a JSON object compatible with cytoscape.js that contains the ECC graph for a specific pair of sequences

    :param ecc_id: internal ID of the sequence to sequence ECC relationship
    :return: JSON object compatible with cytoscape.js
    """
    network, family = SequenceSequenceECCAssociation.get_ecc_pair_network(
        ecc_id)

    network_cytoscape = CytoscapeHelper.parse_network(network)
    network_cytoscape = CytoscapeHelper.add_descriptions_nodes(
        network_cytoscape)
    network_cytoscape = CytoscapeHelper.add_family_data_nodes(
        network_cytoscape, family)
    network_cytoscape = CytoscapeHelper.add_lc_data_nodes(network_cytoscape)
    network_cytoscape = CytoscapeHelper.add_species_data_nodes(
        network_cytoscape)
    network_cytoscape = CytoscapeHelper.connect_homologs(network_cytoscape)
    network_cytoscape = CytoscapeHelper.tag_ecc_singles(network_cytoscape)

    return json.dumps(network_cytoscape)
Esempio n. 6
0
def custom_network_json():
    """
    Profile comparison tool, accepts a species and a list of probes and plots the profiles for the selected
    """
    terms = request.form.get('probes').split()
    method_id = request.form.get('method_id')

    family_method_id = request.form.get('family_method')
    cluster_method_id = request.form.get('cluster_method')
    specificity_method_id = request.form.get('specificity_method')

    probes = terms

    # also do search by gene ID
    sequences = Sequence.query.filter(Sequence.name.in_(terms)).all()

    for s in sequences:
        for ep in s.expression_profiles:
            probes.append(ep.probe)

    # make probe list unique
    probes = list(set(probes))

    network = ExpressionNetwork.get_custom_network(method_id, probes)

    network_cytoscape = CytoscapeHelper.parse_network(network)
    network_cytoscape = CytoscapeHelper.add_family_data_nodes(
        network_cytoscape, family_method_id)
    network_cytoscape = CytoscapeHelper.add_lc_data_nodes(network_cytoscape)
    network_cytoscape = CytoscapeHelper.add_descriptions_nodes(
        network_cytoscape)
    network_cytoscape = CytoscapeHelper.add_cluster_data_nodes(
        network_cytoscape, cluster_method_id)
    network_cytoscape = CytoscapeHelper.add_specificity_data_nodes(
        network_cytoscape, specificity_method_id)

    return Response(json.dumps(network_cytoscape), mimetype='application/json')
Esempio n. 7
0
def custom_network_main():
    """
    Profile comparison tool, accepts a species and a list of probes and plots the profiles for the selected
    """
    form = CustomNetworkForm(request.form)
    form.populate_method()

    if request.method == 'POST':
        terms = request.form.get('probes').split()
        method_id = request.form.get('method_id')

        family_method_id = request.form.get('family_method')
        cluster_method_id = request.form.get('cluster_method')
        specificity_method_id = request.form.get('specificity_method')

        probes = terms

        # also do search by gene ID
        sequences = Sequence.query.filter(Sequence.name.in_(terms)).all()

        for s in sequences:
            for ep in s.expression_profiles:
                probes.append(ep.probe)

        # make probe list unique
        probes = list(set(probes))

        network_method = ExpressionNetworkMethod.query.get_or_404(method_id)
        network = ExpressionNetwork.get_custom_network(method_id, probes)

        network_cytoscape = CytoscapeHelper.parse_network(network)
        network_cytoscape = CytoscapeHelper.add_family_data_nodes(
            network_cytoscape, family_method_id)
        network_cytoscape = CytoscapeHelper.add_lc_data_nodes(
            network_cytoscape)
        network_cytoscape = CytoscapeHelper.add_descriptions_nodes(
            network_cytoscape)
        network_cytoscape = CytoscapeHelper.add_cluster_data_nodes(
            network_cytoscape, cluster_method_id)
        network_cytoscape = CytoscapeHelper.add_specificity_data_nodes(
            network_cytoscape, specificity_method_id)

        return render_template("expression_graph.html",
                               graph_data=Markup(
                                   json.dumps(network_cytoscape)),
                               cutoff=network_method.hrr_cutoff)
    else:

        example = {'method_id': None, 'probes': None}

        data = ExpressionNetwork.query.order_by(
            ExpressionNetwork.method_id).limit(20).all()

        probes = []

        for d in data:
            example['method_id'] = d.method_id

            if d.probe not in probes:
                probes.append(d.probe)

            network = json.loads(d.network)
            for n in network:
                if "gene_name" in n and "gene_name" not in probes and len(
                        probes) < 35:
                    probes.append(n["gene_name"])

            if len(probes) >= 35:
                break
        example['probes'] = ' '.join(probes)

        return render_template("custom_network.html",
                               form=form,
                               example=example)