diff --git a/app/models/fel.js b/app/models/fel.js index c4933642..9ec1e38a 100644 --- a/app/models/fel.js +++ b/app/models/fel.js @@ -15,6 +15,16 @@ var FEL = mongoose.Schema({ resample: Number, ci: Boolean, bootstrap: Boolean, + multiple_hits: { + type: String, + enum: ["None", "Double", "Double+Triple"], + default: "None", + }, + site_multihit: { + type: String, + enum: ["Estimate", "Global"], + default: "Estimate", + }, }); FEL.add(AnalysisSchema); @@ -47,7 +57,7 @@ FEL.virtual("original_fn").get(function () { "/../../uploads/msa/" + this._id + "-original." + - this.original_extension + this.original_extension, ); }); @@ -123,7 +133,7 @@ FEL.statics.spawn = function (fn, options, callback) { } else { var move = Msa.removeTreeFromFile( fel_result.filepath, - fel_result.filepath + fel_result.filepath, ); move.then( (val) => { @@ -137,7 +147,7 @@ FEL.statics.spawn = function (fn, options, callback) { }, (reason) => { callback(err, "issue removing tree from file"); - } + }, ); } } diff --git a/app/models/meme.js b/app/models/meme.js index bad9ffcc..c66974d5 100644 --- a/app/models/meme.js +++ b/app/models/meme.js @@ -12,6 +12,10 @@ var MEME = mongoose.Schema({ results: Object, resample: Number, bootstrap: Boolean, + multiple_hits: String, + site_multihit: String, + rates: Number, + impute_states: String, }); MEME.add(AnalysisSchema); @@ -49,50 +53,41 @@ MEME.virtual("url").get(function () { return "http://" + setup.host + "/meme/" + this._id; }); -/** - * Shared API / Web request job spawn - */ + MEME.statics.spawn = function (fn, options, callback) { const Msa = mongoose.model("Msa"); - var meme = new this(); + const meme = new this(); - let gencodeid = options.gencodeid, - datatype = options.datatype; - - meme.mail = options.mail; + // Dynamically add all options to the meme object + Object.keys(options).forEach((key) => { + meme[key] = options[key]; + }); // Check advanced options - if (!_.isNaN(options.resample)) { - meme.resample = options.resample; - meme.bootstrap = true; - } else { - meme.bootstrap = false; - } + meme.bootstrap = !_.isNaN(options.resample); const connect_callback = function (data) { - if (data == "connected") { + if (data === "connected") { logger.log("connected"); } }; - Msa.parseFile(fn, datatype, gencodeid, (err, msa) => { + Msa.parseFile(fn, options.datatype, options.gencodeid, (err, msa) => { if (err) { callback(err); return; } + // Check if msa exceeds limitations if (msa.sites > meme.max_sites) { - const error = - "Site limit exceeded! Sites must be less than " + meme.max_sites; + const error = `Site limit exceeded! Sites must be less than ${meme.max_sites}`; logger.error(error); callback(error); return; } if (msa.sequences > meme.max_sequences) { - var error = - "Sequence limit exceeded! Sequences must be less than " + - meme.max_sequences; + const error = `Sequence limit exceeded! Sequences must be less than ${meme.max_sequences}`; logger.error(error); callback(error); return; @@ -108,32 +103,24 @@ MEME.statics.spawn = function (fn, options, callback) { return; } - function move_cb(err, result) { + function move_cb(err) { if (err) { logger.error( - "meme rename failed" + - " Errored on line 113~ within models/meme.js :: move_cb " + - err + `meme rename failed. Error on line 113~ within models/meme.js :: move_cb ${err}`, ); callback(err, null); } else { - var move = Msa.removeTreeFromFile( - meme_result.filepath, - meme_result.filepath - ); - move.then( - (val) => { - let to_send = meme; - to_send.upload_redirect_path = meme.upload_redirect_path; + Msa.removeTreeFromFile(meme_result.filepath, meme_result.filepath) + .then(() => { this.submitJob(meme_result, connect_callback); callback(null, meme); - }, - (reason) => { - res.json(500, { error: "issue removing tree from file" }); - } - ); + }) + .catch(() => { + callback(new Error("issue removing tree from file")); + }); } } + helpers.moveSafely(fn, meme_result.filepath, move_cb.bind(this)); }); }); diff --git a/app/models/msa.js b/app/models/msa.js index c3dfb6eb..a9cb7d86 100644 --- a/app/models/msa.js +++ b/app/models/msa.js @@ -65,12 +65,12 @@ Msa.virtual("genetic_code").get(function () { }); Msa.virtual("day_created_on").get(function () { - var time = moment(this.timestamp); + var time = moment.unix(this.timestamp); return time.format("YYYY-MMM-DD"); }); Msa.virtual("time_created_on").get(function () { - var time = moment(this.timestamp); + var time = moment.unix(this.timestamp); return time.format("HH:mm"); }); diff --git a/app/routes/fel.js b/app/routes/fel.js index cdd89c3f..1b8e2163 100644 --- a/app/routes/fel.js +++ b/app/routes/fel.js @@ -25,6 +25,7 @@ exports.uploadFile = function (req, res) { } }; + var fn = req.files.files.file, fel = new FEL(), postdata = req.body, @@ -33,9 +34,12 @@ exports.uploadFile = function (req, res) { ds_variation = postdata.ds_variation, resample = parseInt(postdata.resample); + fel.original_extension = path.basename(fn).split(".")[1]; fel.mail = postdata.mail; fel.ci = postdata.confidence_interval == "true"; + fel.multiple_hits = postdata.multiple_hits; + fel.site_multihit = postdata.site_multihit; // Check advanced options if (!_.isNaN(resample)) { @@ -87,7 +91,7 @@ exports.uploadFile = function (req, res) { } else { var move = Msa.removeTreeFromFile( fel_result.filepath, - fel_result.filepath + fel_result.filepath, ); move.then( (val) => { @@ -98,7 +102,7 @@ exports.uploadFile = function (req, res) { }, (reason) => { res.json(500, { error: "issue removing tree from file" }); - } + }, ); } } @@ -116,7 +120,7 @@ exports.uploadFile = function (req, res) { helpers.moveSafely( req.files.files.file, fel_result.filepath, - move_cb + move_cb, ); }); }); diff --git a/app/routes/meme.js b/app/routes/meme.js index a5958010..2ea13707 100644 --- a/app/routes/meme.js +++ b/app/routes/meme.js @@ -18,12 +18,16 @@ exports.form = function (req, res) { exports.invoke = function (req, res) { var fn = req.files.files.file; let postdata = req.body; - //let resample = parseInt(postdata.resample); let options = { datatype: 0, gencodeid: postdata.gencodeid, mail: postdata.mail, + multiple_hits: postdata.multiple_hits, + site_multihit: postdata.site_multihit, + rates: parseInt(postdata.rates), + resample: parseInt(postdata.resample || 0), + impute_states: postdata.impute_states, }; //// Check advanced options diff --git a/app/templates/fel/msa_form.ejs b/app/templates/fel/msa_form.ejs index 550d3e37..8d5eacac 100644 --- a/app/templates/fel/msa_form.ejs +++ b/app/templates/fel/msa_form.ejs @@ -88,6 +88,22 @@ +