muscle_node
Version:
node.js wrapper for MUSCLE alignment
61 lines (53 loc) • 2.12 kB
JavaScript
/*
****Usage
node getMuscle.js
node will check your OS (Win or Mac) and download the correct binary; in the case of MacOS, node will unzip. Finally, node will rename the executable 'muscle' for simplicity
***************************************************************
*/
//require the following modules
var fs = require('fs');
var download = require('download');
var exec = require('child_process').exec;
//check if user is using Windows
var isWin = /^win/.test(process.platform);
//build a commandline for unzipping the MacOS download
var unzipCommand = 'tar -zxvf muscle3.8.31_i86darwin64.tar.gz';
//function for Windows download that takes callback
function musclePC(Windows) {
download('http://www.drive5.com/muscle/downloads3.8.31/muscle3.8.31_i86win32.exe', './').then(() => {
console.log('\n' + ' downloaded executable');
Windows();
});
}
//function for MacOS download that takes
//two functions to unzip and rename
function muscleMac(Mac, callback) {
download('http://www.drive5.com/muscle/downloads3.8.31/muscle3.8.31_i86darwin64.tar.gz', './').then(() => {
console.log('\n' + ' downloaded zipped executable');
Mac(callback);
});
}
if (isWin == true) {
musclePC(function () {
fs.rename('muscle3.8.31_i86win32.exe', 'muscle.exe', function (err) {
if (err) throw err;
fs.stat('muscle.exe', function (err, stats) {
if (err) throw err;
console.log('\n' + ' truncated executable filename to muscle');
});
});
});
} else {
muscleMac(function (callback) {
exec(unzipCommand, function (error, stdout, stderr) {
if (error != null) {
console.log(stderr);
}
callback();
});
console.log('\n' + ' unzipped file...TODO add it to your PATH');
}, function () {
fs.renameSync('muscle3.8.31_i86darwin64', 'muscle');
console.log('\n' + ' truncated executable filename to muscle' + '\n');
});
}