Skip to content

Commit

Permalink
Merge branch 'master' of github.com:veg/datamonkey-js
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenweaver committed Dec 4, 2024
2 parents 4a47fe8 + dfe170d commit cb336f6
Show file tree
Hide file tree
Showing 10 changed files with 324 additions and 172 deletions.
16 changes: 13 additions & 3 deletions app/models/fel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -47,7 +57,7 @@ FEL.virtual("original_fn").get(function () {
"/../../uploads/msa/" +
this._id +
"-original." +
this.original_extension
this.original_extension,
);
});

Expand Down Expand Up @@ -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) => {
Expand All @@ -137,7 +147,7 @@ FEL.statics.spawn = function (fn, options, callback) {
},
(reason) => {
callback(err, "issue removing tree from file");
}
},
);
}
}
Expand Down
63 changes: 25 additions & 38 deletions app/models/meme.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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));
});
});
Expand Down
4 changes: 2 additions & 2 deletions app/models/msa.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});

Expand Down
10 changes: 7 additions & 3 deletions app/routes/fel.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ exports.uploadFile = function (req, res) {
}
};


var fn = req.files.files.file,
fel = new FEL(),
postdata = req.body,
Expand All @@ -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)) {
Expand Down Expand Up @@ -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) => {
Expand All @@ -98,7 +102,7 @@ exports.uploadFile = function (req, res) {
},
(reason) => {
res.json(500, { error: "issue removing tree from file" });
}
},
);
}
}
Expand All @@ -116,7 +120,7 @@ exports.uploadFile = function (req, res) {
helpers.moveSafely(
req.files.files.file,
fel_result.filepath,
move_cb
move_cb,
);
});
});
Expand Down
6 changes: 5 additions & 1 deletion app/routes/meme.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions app/templates/fel/msa_form.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,22 @@
</select>
</div>

<div class="form-group">
<label for="multiple-hits">Multiple Hits</label>
<select name="multiple_hits" id="multiple-hits">
<option value="None">None (Single mutations only)</option>
<option value="Double">Double (Branch-specific rates for double substitutions)</option>
<option value="Double+Triple">Double+Triple (Branch-specific rates for double and triple substitutions)</option>
</select>
</div>

<div class="form-group">
<label for="estimated-rates">Site Multihit</label>
<select name="site_multihit" id="site-multihit">
<option value="Estimate">Estimate (Branch-specific rates for substitutions based on model fit)</option>
<option value="Global">Global (Rates derived from global model fit)</option>
</select>
</div>

<div class="form-group <%if (typeof errors != "undefined" && typeof errors.mail != "undefined") { %>has-error<% } %>">
<label id="datatype-content" class="control-label">Notify When Completed?</label>
Expand Down
2 changes: 1 addition & 1 deletion app/templates/meme/form.ejs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<%- include("../includes/header.ejs") %>
<div id="container" class="container">
<%- include("header.ejs") %>
<%- include("../partials/msa/form.ejs") %>
<%- include("./msa_form.ejs") %>
<%- include("../includes/modal.ejs") %>
</div>
<%- include("../includes/footer.ejs") %>
Loading

0 comments on commit cb336f6

Please sign in to comment.