Commit 8c13b969 authored by vpodpecan's avatar vpodpecan
Browse files

new SegMine widgets

parent 08b75646
IGNORE_MISSING = 'ignore'
IMPUTE_MISSING = 'impute row'
ENTREZ_GENE_PREFIX = 'Entrez_Gene'
ENTREZ_GENE_PREFIX = 'EntrezGene'
GO_PREFIX = 'GO'
KEGG_PREFIX = 'KEGG'
DEFAULT_CONTROL_GROUP_ID = '1'
CONTROL_GROUP_KEY = 'control group'
......
......@@ -988,6 +988,220 @@
"description": ""
}
},
{
"pk": 425,
"model": "workflows.abstractwidget",
"fields": {
"category": 44,
"treeview_image": "",
"windows_queue": false,
"name": "Hierarchical clustering",
"is_streaming": false,
"uid": "03d64d6e-843e-4dac-941c-ab4f0a29c5e0",
"interaction_view": "",
"image": "",
"package": "segmine",
"static_image": "",
"post_interact_action": "",
"user": null,
"visualization_view": "",
"streaming_visualization_view": "",
"action": "segmine_do_hclustering",
"wsdl_method": "",
"wsdl": "",
"interactive": false,
"has_progress_bar": false,
"order": 1,
"description": "Performs hierarchical clustering using the selected linkage."
}
},
{
"pk": 1064,
"model": "workflows.abstractinput",
"fields": {
"widget": 425,
"name": "Data table",
"short_name": "odt",
"uid": "f3424ab8-e105-4887-885d-68144fc59e13",
"default": "",
"required": true,
"multi": false,
"parameter_type": null,
"variable": "table",
"parameter": false,
"order": 1,
"description": "Orange data table with examples"
}
},
{
"pk": 1066,
"model": "workflows.abstractinput",
"fields": {
"widget": 425,
"name": "Distance metric",
"short_name": "dm",
"uid": "e04bd4bb-a2d2-4e56-b986-5d4e605c8786",
"default": "1",
"required": true,
"multi": false,
"parameter_type": "select",
"variable": "metric",
"parameter": true,
"order": 1,
"description": "Distance metric"
}
},
{
"pk": 297,
"model": "workflows.abstractoption",
"fields": {
"uid": "771c3395-8fba-41f1-abbf-03f316b78de2",
"abstract_input": 1066,
"value": "1",
"name": "Euclidean"
}
},
{
"pk": 298,
"model": "workflows.abstractoption",
"fields": {
"uid": "28c5cd5f-6a30-4463-a34a-be2b1cb2cb8c",
"abstract_input": 1066,
"value": "2",
"name": "Hamming"
}
},
{
"pk": 304,
"model": "workflows.abstractoption",
"fields": {
"uid": "9e892884-14be-4426-b11c-0c078d6b5ef4",
"abstract_input": 1066,
"value": "8",
"name": "Mahalanobis"
}
},
{
"pk": 300,
"model": "workflows.abstractoption",
"fields": {
"uid": "efa9d187-ce62-4cff-818c-d659786eeeaf",
"abstract_input": 1066,
"value": "4",
"name": "Manhattan"
}
},
{
"pk": 299,
"model": "workflows.abstractoption",
"fields": {
"uid": "e167209d-d284-49e4-983b-ccfc09afd5b3",
"abstract_input": 1066,
"value": "3",
"name": "Maximal"
}
},
{
"pk": 302,
"model": "workflows.abstractoption",
"fields": {
"uid": "e6ec8edd-0bc1-498b-8004-eac5a5679b10",
"abstract_input": 1066,
"value": "6",
"name": "Pearson"
}
},
{
"pk": 301,
"model": "workflows.abstractoption",
"fields": {
"uid": "d479c184-c543-43cb-8b56-413142c1f2d0",
"abstract_input": 1066,
"value": "5",
"name": "Relief"
}
},
{
"pk": 303,
"model": "workflows.abstractoption",
"fields": {
"uid": "31cde594-d060-4e92-a715-2d667e9ed059",
"abstract_input": 1066,
"value": "7",
"name": "Spearman"
}
},
{
"pk": 1065,
"model": "workflows.abstractinput",
"fields": {
"widget": 425,
"name": "Linkage",
"short_name": "lin",
"uid": "a08686eb-acef-47c1-8fca-6693ac142754",
"default": "4",
"required": true,
"multi": false,
"parameter_type": "select",
"variable": "linkage",
"parameter": true,
"order": 2,
"description": "Type of linkage"
}
},
{
"pk": 294,
"model": "workflows.abstractoption",
"fields": {
"uid": "eecdc5f2-5653-4792-99d9-cecf8dec5eb8",
"abstract_input": 1065,
"value": "2",
"name": "average"
}
},
{
"pk": 295,
"model": "workflows.abstractoption",
"fields": {
"uid": "0ac1a67c-e7ab-4605-a34a-97d57e69c76c",
"abstract_input": 1065,
"value": "3",
"name": "complete"
}
},
{
"pk": 293,
"model": "workflows.abstractoption",
"fields": {
"uid": "151310a4-6f9c-4940-b461-9ab4b43f872e",
"abstract_input": 1065,
"value": "1",
"name": "single"
}
},
{
"pk": 296,
"model": "workflows.abstractoption",
"fields": {
"uid": "e1ee195d-707c-4d89-8f3f-eda86e6f047a",
"abstract_input": 1065,
"value": "4",
"name": "ward"
}
},
{
"pk": 457,
"model": "workflows.abstractoutput",
"fields": {
"widget": 425,
"name": "Hierarchical clustering",
"short_name": "hcl",
"variable": "hcluster",
"uid": "892c1e63-65d3-4ea2-89bd-123f967b6357",
"order": 1,
"description": "Orange hierarchical clustering data structure"
}
},
{
"pk": 198,
"model": "workflows.abstractwidget",
......@@ -2696,6 +2910,64 @@
"description": "Rules as rows, their terms as columns."
}
},
{
"pk": 424,
"model": "workflows.abstractwidget",
"fields": {
"category": 44,
"treeview_image": "",
"windows_queue": false,
"name": "Select hierarchical cluster",
"is_streaming": false,
"uid": "0462eba5-248e-43be-a40d-0ec96530d09b",
"interaction_view": "segmine_hclustering",
"image": "",
"package": "segmine",
"static_image": "",
"post_interact_action": "segmine_hclustering_finished",
"user": null,
"visualization_view": "",
"streaming_visualization_view": "",
"action": "segmine_hclustering",
"wsdl_method": "",
"wsdl": "",
"interactive": true,
"has_progress_bar": false,
"order": 1,
"description": "A non-interactive variant of Hierarchical clustering for SegMine."
}
},
{
"pk": 1063,
"model": "workflows.abstractinput",
"fields": {
"widget": 424,
"name": "Hierarchical clustering",
"short_name": "hcl",
"uid": "0ae6fa4f-9032-42f0-a65c-067b221036c6",
"default": "",
"required": true,
"multi": false,
"parameter_type": null,
"variable": "hclustering",
"parameter": false,
"order": 1,
"description": "Orange hierarchical clustering object"
}
},
{
"pk": 456,
"model": "workflows.abstractoutput",
"fields": {
"widget": 424,
"name": "Selected examples",
"short_name": "sel",
"variable": "selected_examples",
"uid": "5bd9d37d-f9da-4d38-a70f-fe6e8a19778e",
"order": 1,
"description": "Examples from the selected cluster"
}
},
{
"pk": 208,
"model": "workflows.abstractwidget",
......@@ -2753,5 +3025,76 @@
"order": 1,
"description": "Orange dataset with filtered genes"
}
},
{
"pk": 426,
"model": "workflows.abstractwidget",
"fields": {
"category": 44,
"treeview_image": "",
"windows_queue": false,
"name": "Union and intersection of attributes for SegMine rule table",
"is_streaming": false,
"uid": "2e3c0b5c-5bcb-4c8c-950f-a4c92a5d6c7d",
"interaction_view": "",
"image": "",
"package": "segmine",
"static_image": "",
"post_interact_action": "",
"user": null,
"visualization_view": "",
"streaming_visualization_view": "",
"action": "segmine_ruletable2attribute_union_intersection",
"wsdl_method": "",
"wsdl": "",
"interactive": false,
"has_progress_bar": false,
"order": 1,
"description": "Returns a set of strings computed as a union and intersection of all attributes of a SegMine rule table (genes or terms)."
}
},
{
"pk": 1067,
"model": "workflows.abstractinput",
"fields": {
"widget": 426,
"name": "Data table",
"short_name": "odt",
"uid": "2e913773-e48c-4401-b058-e75869eed9b6",
"default": "",
"required": true,
"multi": false,
"parameter_type": null,
"variable": "ruletable",
"parameter": false,
"order": 1,
"description": "Orange data table"
}
},
{
"pk": 458,
"model": "workflows.abstractoutput",
"fields": {
"widget": 426,
"name": "Attribute union",
"short_name": "atu",
"variable": "atrUnion",
"uid": "64b2edae-31f7-4b97-93f5-144a03097852",
"order": 1,
"description": "Union of attributes of rules"
}
},
{
"pk": 459,
"model": "workflows.abstractoutput",
"fields": {
"widget": 426,
"name": "Attribute intersection",
"short_name": "ati",
"variable": "atrInter",
"uid": "06e8a9b6-901b-4e16-8d02-fded307a12c1",
"order": 2,
"description": "Intersection of atributes of rules"
}
}
]
\ No newline at end of file
......@@ -5,23 +5,57 @@ Segmine interaction viewes.
'''
from django.shortcuts import render
def segmine_ttest_gene_filter(request, input_dict, output_dict, widget):
dataset = input_dict['dataset']
targets = dataset.domain.classVar.values
return render(request, 'interactions/segmine_ttest_gene_filter.html',
{'widget':widget, 'targets' : targets,
'default_threshold' : 0.05})
{'widget': widget, 'targets': targets,
'default_threshold': 0.05})
def segmine_fc_gene_filter(request, input_dict, output_dict, widget):
dataset = input_dict['dataset']
targets = dataset.domain.classVar.values
return render(request, 'interactions/segmine_fc_gene_filter.html',
{'widget':widget, 'targets' : targets,
'default_threshold' : 1.0})
'default_threshold': 1.0})
def segmine_rule_browser(request, input_dict, output_dict, widget):
rules = input_dict['rules']
aggregate = rules[0].has_key('aggregate_pval') if rules else False
return render(request, 'interactions/segmine_rule_browser.html',
{'widget':widget, 'rules' : rules, 'aggregate' : aggregate})
{'widget': widget, 'rules': rules, 'aggregate': aggregate})
def segmine_hclustering(request, input_dict, output_dict, widget):
import json
import Orange
import constants
def assign_numbers(root):
nodes = Orange.clustering.hierarchical.preorder(root)
for (i, node) in enumerate(nodes):
node.setattr('idx', i)
def to_dict(cluster):
if cluster.branches:
return {"name": cluster.idx, "children": [to_dict(x) for x in cluster.branches]}
else:
# stupid segmine hardcoded meta attribute
if cluster[0].has_meta(constants.NAME_ATTR):
return {"name": str(cluster[0][constants.NAME_ATTR])}
else:
return {"name": str(cluster[0])}
def hclustering2json(cluster):
return json.dumps(to_dict(cluster))
hcluster = input_dict['hclustering']
assign_numbers(hcluster)
djson = hclustering2json(hcluster)
return render(request, 'interactions/segmine_hierarchical_clustering.html', {'widget': widget,
'dendrogram_json': djson,
'nexamples': len(hcluster)})
\ No newline at end of file
......@@ -784,3 +784,97 @@ def resolve_gene_names_STU(input_dict):
result = list(set(result))
result = [(x[1], x[0]) for x in sorted([(x[1], x[0]) for x in result], reverse=True)]
return {'mapped_ranks': result}
def segmine_do_hclustering(input_dict):
import Orange
table = input_dict['table']
linkage = int(input_dict['linkage'])
metric = int(input_dict['metric'])
linkages = {1: Orange.clustering.hierarchical.SINGLE,
2: Orange.clustering.hierarchical.AVERAGE,
3: Orange.clustering.hierarchical.COMPLETE,
4: Orange.clustering.hierarchical.WARD}
dmetrices = {1: Orange.distance.Euclidean,
2: Orange.distance.Hamming,
3: Orange.distance.Maximal,
4: Orange.distance.Manhattan,
5: Orange.distance.Relief,
6: Orange.distance.PearsonR,
7: Orange.distance.SpearmanR,
8: Orange.distance.Mahalanobis}
dmatrix = Orange.distance.distance_matrix(table, dmetrices[metric])
clustering = Orange.clustering.hierarchical.HierarchicalClustering()
clustering.linkage = linkages[linkage]
hcl = clustering(dmatrix)
hcl.mapping.objects = table
return {'hcluster': hcl}
def segmine_hclustering(input_dict):
return {'selected_examples': None}
def segmine_hclustering_finished(postdata, input_dict, output_dict):
import Orange
def assign_numbers(root):
nodes = Orange.clustering.hierarchical.preorder(root)
for (i, node) in enumerate(nodes):
node.setattr('idx', i)
try:
cid = int(postdata['selected_cluster'][0])
except ValueError:
raise SyntaxError("Invalid cluster number! Please enter a valid number.")
widget_pk = postdata['widget_id'][0]
cluster = input_dict['hclustering']
assign_numbers(cluster)
clusters = Orange.clustering.hierarchical.cluster_to_list(cluster)
selected = [x for x in clusters if x.idx == cid][0]
table = Orange.data.Table(selected[0].domain)
table.extend([x for x in selected])
return {'selected_examples': table}
def segmine_ruletable2attribute_union_intersection(input_dict):
import Orange
import constants
table = input_dict['ruletable']
def allGenes(names):
for name in names:
try:
gid = int(name)
except ValueError:
return False
return True
#end
def allGOKEGG(names):
for name in names:
if not name.startswith(constants.GO_PREFIX) and not name.startswith(constants.KEGG_PREFIX):
return False
return True
#end
names = [x.name for x in table.domain.attributes]
allgenes = allGenes(names)
allgokegg = allGOKEGG(names)
if not allgenes and not allgokegg:
raise ValueError('This widget only accepts SegMine rule table.')
union = names
intersection = []
for name in names:
if all([bool(int(example[name])) for example in table]):
intersection.append(name)
if allgenes:
union = [constants.ENTREZ_GENE_PREFIX + ':' + x for x in union]
intersection = [constants.ENTREZ_GENE_PREFIX + ':' + x for x in intersection]
return {'atrUnion': union, 'atrInter': intersection}
<div id="widgetinteract-{{ widget.pk }}"
rel="{{ widget.pk }}"
class="widgetinteractdialog"
title="{{ widget.name }} wants your input!"
width=1024 height=768>
<div id="dendrogram">
</div>
<form id="interactionform-{{ widget.pk }}" name="interactionform-{{ widget.pk }}">
<input type="input" id="input_cluster_id" name="cluster_number" value="" style="display:inline;width:auto;">selected
cluster<br>
<input type="hidden" name="widget_id" value="{{ widget.pk }}">
<input type="hidden" id="output_cluster_id" name="selected_cluster" value="">
</form>
</div>
<style type="text/css">
.node circle {
/*fill: #fff;*/
stroke: steelblue;
/*stroke-width: 1.5px;*/
}
.node {
font: 12px sans-serif;
/*background-color: yellow;*/
}
.link {
fill: none;
stroke: #ccc;
stroke-width: 1px;
}
.overlay {
fill: none;
pointer-events: all;
}
</style>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script>
$("#input_cluster_id").change(function () {
$("#output_cluster_id").val($("#input_cluster_id").val());
});
var dataset = {{ dendrogram_json|safe }};
var n = {{ nexamples }};
var width = Math.max(800, Math.min(n*5, 1500));
var height = Math.max(500, n*20);
{# var width = n * 30,#}
{# height = n * 20;#}
{# var width = 1000,#}
{# height = 500;#}