muscle_node
Version:
node.js wrapper for MUSCLE alignment
47 lines (44 loc) • 1.67 kB
JavaScript
//export functions below
var exports = module.exports = {};
//module for spawning new shell
var exec = require('child_process').exec;
//other flags will be pushed into otherlfags arr
var otherflags = [];
exports.muscle_align = function (myfilePath, outFile, flagArr, callback) {
//check that enough arguments are supplied
if (process.argv.length >= 3) {
//generate commandline
var mkDirCommand = 'mkdir Output';
console.log('\n' + ' made Output folder...');
//spawn child process for new shell command
var child = exec(mkDirCommand, function (error, stdout, stderr) {
if (error != null) {
console.log(stderr);
}
});
//invoke callback and push in arguments
callback(myfilePath, outFile, flagArr);
} else {
console.log('insufficient number of arguments');
}
}
exports.align = function (myfilePath, outFile, flagArr) {
//merge other flags from commandline into a single string
for (var i = 3; i < flagArr.length; i++) {
otherflags.push(flagArr[i]);
}
//stringify
var stringify = otherflags.toString();
//replace commas with spaces
var flags = stringify.replace(/,/g, " ");
//generate the commandline
var alignCommand = 'muscle -in ' + myfilePath + ' -out ' + outFile + ' ' + flags;
console.log('\n' + ' running...');
//spawn child to run exec shell
var child = exec(alignCommand, function (error, stdout, stderr) {
if (error != null) {
console.log(stderr);
}
console.log('\n' + ' finished!');
});
}