Commit e24aac1d authored by Floreal Cabanettes's avatar Floreal Cabanettes
Browse files

Paired columns function get generic

parent 465ccad3
...@@ -471,11 +471,11 @@ class MultiParameter(dict, AbstractParameter): ...@@ -471,11 +471,11 @@ class MultiParameter(dict, AbstractParameter):
class MultiParameterList(list, AbstractParameter): class MultiParameterList(list, AbstractParameter):
def __init__(self, name, help, required=False, flag=None, group="default", display_name=None, cmd_format="", def __init__(self, name, help, required=False, flag=None, group="default", display_name=None, cmd_format="",
argpos=-1, rules=None, fill_files=False): argpos=-1, rules=None, paired_columns=None):
AbstractParameter.__init__(self, name, help, required=required, type="multiple", flag=flag, AbstractParameter.__init__(self, name, help, required=required, type="multiple", flag=flag,
action="append", group=group, display_name=display_name, action="append", group=group, display_name=display_name,
cmd_format=cmd_format, argpos=argpos, rules=rules) cmd_format=cmd_format, argpos=argpos, rules=rules)
self.fill_files = fill_files self.paired_columns = paired_columns
return list.__init__(self, []) return list.__init__(self, [])
def add_sub_parameter(self, param): def add_sub_parameter(self, param):
......
...@@ -283,8 +283,8 @@ class JFlowServer (object): ...@@ -283,8 +283,8 @@ class JFlowServer (object):
"name": param.name + JFlowServer.MULTIPLE_TYPE_SPLITER + sub_param.flag, "name": param.name + JFlowServer.MULTIPLE_TYPE_SPLITER + sub_param.flag,
"display_name": sub_param.display_name, "display_name": sub_param.display_name,
"group": sub_param.group}) "group": sub_param.group})
if hasattr(param, "fill_files"): if hasattr(param, "paired_columns"):
hash_param["fill_files"] = param.fill_files hash_param["paired_columns"] = param.paired_columns
if hash_param["sub_parameters"][-1]["type"] == "date": if hash_param["sub_parameters"][-1]["type"] == "date":
hash_param["sub_parameters"][-1]["format"] = self.jflow_config_reader.get_date_format() hash_param["sub_parameters"][-1]["format"] = self.jflow_config_reader.get_date_format()
if hash_param["sub_parameters"][-1]["format"] == '%d/%m/%Y': if hash_param["sub_parameters"][-1]["format"] == '%d/%m/%Y':
......
...@@ -246,10 +246,10 @@ class Workflow(threading.Thread): ...@@ -246,10 +246,10 @@ class Workflow(threading.Thread):
self.__setattr__(name, new_param) self.__setattr__(name, new_param)
def add_multiple_parameter_list(self, name, help, required=False, flag=None, group="default", display_name=None, def add_multiple_parameter_list(self, name, help, required=False, flag=None, group="default", display_name=None,
rules=None, fill_files=False): rules=None, paired_columns=None):
self.params_order.append(name) self.params_order.append(name)
new_param = MultiParameterList(name, help, flag=flag, required=required, group=group, display_name=display_name, new_param = MultiParameterList(name, help, flag=flag, required=required, group=group, display_name=display_name,
rules=rules, fill_files=fill_files) rules=rules, paired_columns=paired_columns)
self.__setattr__(name, new_param) self.__setattr__(name, new_param)
def add_parameter(self, name, help, default=None, type=str, choices=None, def add_parameter(self, name, help, default=None, type=str, choices=None,
......
...@@ -859,8 +859,58 @@ Handsontable.cellTypes["bootdate"] = Handsontable.BootstrapDateCell; ...@@ -859,8 +859,58 @@ Handsontable.cellTypes["bootdate"] = Handsontable.BootstrapDateCell;
setClickServerBrowser(params); setClickServerBrowser(params);
$(".selectMultipleFiles").click(function() { $(".selectMultipleFiles").click(function() {
var func = $(this).attr("fill-function"); var paired = $(this).attr("paired_columns").split(",");
var fill_files = function(files) { eval(func)}; var input = $(this).attr("for");
for (var np=0; np < paired.length; np++) {
paired[np] = input + "___" + paired[np].replace("_","-");
}
var fill_files = function(files) {
var paired_files = {};
var single_files = [];
var paired_regex = /(.+)(1|2).fastq(.gz)?/;
for (var f=0; f<files.length; f++) {
var file = files[f];
var match;
if (match = file.match(paired_regex)) {
var base_name = match[1];
var nb = parseInt(match[2]);
if (!(base_name in paired_files)) {
paired_files[base_name] = [];
};
paired_files[base_name][nb-1] = file;
}
else {
single_files.push(file);
};
};
var data = [];
for (var group in paired_files) {
var line = {};
var line_files = paired_files[group];
for (var i=0; i<2; i++) {
if (i < line_files.length) {
var file = line_files[i];
line[paired[i]] = file !== undefined ? file :"";
}
else {
line[paired[i]] ="";
};
};
data.push(line);
};
for (var j=0; j<single_files.length; j++) {
var data_line = {};
data_line[paired[0]] = single_files[j];
for (var k=1; k<paired.length; k++) {
data_line[paired[k]] = "";
}
data.push(data_line);
};
var handsontable_obj = $("#handsontable_" + input);
var original_data=handsontable_obj.handsontable("getData");
handsontable_obj.handsontable("loadData", original_data.slice(0, original_data.length-1)
.concat(data));
};
JflowBrowser.exec(fill_files, true); JflowBrowser.exec(fill_files, true);
return false; return false;
}) })
...@@ -1255,8 +1305,8 @@ Handsontable.cellTypes["bootdate"] = Handsontable.BootstrapDateCell; ...@@ -1255,8 +1305,8 @@ Handsontable.cellTypes["bootdate"] = Handsontable.BootstrapDateCell;
// if it's a multiple type // if it's a multiple type
' {{if param.type == "MultipleParameters"}}', ' {{if param.type == "MultipleParameters"}}',
' <blockquote style="font-size:14px;">', ' <blockquote style="font-size:14px;">',
' {{if param.fill_files}}', ' {{if param.paired_columns}}',
' <button class="selectMultipleFiles" for="${param.name}" fill-function="${param.fill_files}"></button>', ' <button class="selectMultipleFiles" for="${param.name}" paired_columns="${param.paired_columns}"></button>',
' {{/if}}', ' {{/if}}',
' {{if param.action == "MiltipleAppendAction"}}', // if it's an append and multiple type ' {{if param.action == "MiltipleAppendAction"}}', // if it's an append and multiple type
' <div id="handsontable_${param.name}" > </div>', ' <div id="handsontable_${param.name}" > </div>',
......
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