Commit 107f04ed authored by Anze Vavpetic's avatar Anze Vavpetic

Merge branch 'bioinformatics' into dev

parents 9ec20e5b 593ec48a
......@@ -36,4 +36,18 @@ def select_subgroups(request, input_dict, output_dict, widget):
'widget' : widget,
'model_name' : sd_rules.algorithmName,
'subgroups' : subgroups
})
def table_from_sets(request, input_dict, output_dict, widget):
'''
Makes a table with the given sets of examples as the classes.
@author: Anze Vavpetic, 2012
'''
tables = input_dict['data']
return render(request, 'interactions/table_from_sets.html', {
'widget' : widget,
'class_name' : 'class name',
'class_values' : ['class%d' % i for i in range(len(tables))],
'replace' : True
})
\ No newline at end of file
......@@ -78,10 +78,48 @@ def select_subgroups_finished(postdata, input_dict, output_dict):
def query_with_subgroups(input_dict):
data = input_dict['data']
sd_rules = input_dict['rules']
full_set = set([ex for ex in data])
subset = set()
for rule in sd_rules.rules:
subset = subset.union(rule.filter(data))
subset_table = Orange.data.Table(data.domain)
remaining_table = Orange.data.Table(data.domain)
for ex in subset:
subset_table.append(ex)
return {'data' : subset_table}
for ex in full_set.difference(subset):
remaining_table.append(ex)
return {'data' : subset_table, 'remaining_data' : remaining_table}
def table_from_sets(input_dict):
return {'merged_data' : None}
def table_from_sets_finished(postdata, input_dict, output_dict):
tables = input_dict['data']
widget_id = postdata['widget_id'][0]
class_name = str(postdata['class_name'+widget_id][0])
class_values = [str(postdata['class'+str(i)+widget_id][0]) for i in range(len(tables))]
replace = postdata.get('replace'+widget_id, [False])[0]
class_var = Orange.feature.Discrete(class_name, values = class_values)
class_table = Orange.data.Table(Orange.data.Domain([class_var]))
# Check if the domains are the same
domain = tables[0].domain
for table in tables:
if table.domain.variables != domain.variables:
print table.domain, domain
raise Exception('The domains of tables do not match!')
for i, table in enumerate(tables):
for ex in table:
class_table.append(Orange.data.Instance(class_table.domain, [class_values[i]]))
# All examples
examples = Orange.data.Table(tables[0])
for table in tables[1:]:
examples.extend(table)
old_table = examples
if replace:
if not examples.domain.classVar:
raise Exception('No class variable present.')
else:
old_domain = list(examples.domain)
old_domain.remove(examples.domain.classVar)
old_table = Orange.data.Table(Orange.data.Domain(old_domain, examples.domain), examples)
return {'merged_data' : Orange.data.Table([old_table, class_table])}
......@@ -9,13 +9,13 @@
{% for param, info in parameters_info.items %}
<label for="{{param}}{{widget.pk}}">{{info.1}}</label><input type="number" id="{{param}}{{widget.pk}}" name="{{param}}{{widget.pk}}" value="{{info.0}}"/>
{% endfor %}
<input type="hidden" name="widget_id" value="{{widget.pk}}">
<label for="class{{widget.pk}}">Class</label>
<select id="class{{widget.pk}}" name="class{{widget.pk}}">
{% for class in classValues %}
<option value="{{class}}">{{class}}</option>
{% endfor %}
</select>
<input type="hidden" name="widget_id" value="{{widget.pk}}">
</form>
<script type="text/javascript">
var all_parameters = {{all_parameters|safe}};
......
<div id="widgetinteract-{{widget.pk}}" rel="{{widget.pk}}" class="widgetinteractdialog" title="{{widget.name}} interaction" width="400" height="300">
<form>
<label for="class_name{{widget.pk}}">New class attribute name</label>
<input type="text" name="class_name{{widget.pk}}" value="{{class_name}}"/>
{% for class_val in class_values %}
<label for="{{class_val}}{{widget.pk}}">Class label for set on signal #{{forloop.counter}}</label>
<input type="text" name="{{class_val}}{{widget.pk}}" value="{{class_val}}"/>
{% endfor %}
<input type="checkbox" name="replace{{widget.pk}}" value="{{replace}}"/>
<label for="replace{{widget.pk}}">Replace existing class</label>
<input type="hidden" name="widget_id" value="{{widget.pk}}">
</form>
<script type="text/javascript">
</script>
</div>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment