-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
245 lines (204 loc) · 7.01 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
const electron = require('electron');
// Module to control application life.
const app = electron.app;
// Module to create native browser window.
const BrowserWindow = electron.BrowserWindow;
// Module to communicate with renderer process.
const ipcMain = require('electron').ipcMain;
// Module to open diaglogs
const dialog = require('electron').dialog;
// Modules to allow access to shell commands
const shell = require('shelljs');
const exec = require('child_process').exec;
// Read JSON files
const fs = require('fs');
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow;
let projectsWindow;
let project = undefined;
function openSelectProject () {
// Create the browser window.
projectsWindow = new BrowserWindow({width: 400, height: 600, resizable:false});
projectsWindow.loadURL(`file://${__dirname}/selectProject.html`);
projectsWindow.webContents.openDevTools();
// Emitted when the window is closed.
projectsWindow.on('closed', function () {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
projectsWindow = null;
});
}
function openGeneysis() {
// Create the browser window.
mainWindow = new BrowserWindow({width: 1400, height: 900});
mainWindow.loadURL(`file://${__dirname}/index.html`);
// Open the DevTools.
mainWindow.webContents.openDevTools();
// Emitted when the window is closed.
mainWindow.on('closed', function () {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
mainWindow = null;
});
if (projectsWindow != null) {
projectsWindow.close();
}
}
function startGeneysis () {
if (project == undefined) {
openSelectProject();
}
else {
openGeneysis();
}
//check for all dependencies
var missing = "";
if (!shell.which("clustalo")) {
missing += "Clustal Omega (clustalo): http://clustal.org/omega/\n";
}
if (!(shell.which("blastp") && shell.which("makeblastdb"))) {
missing += "Blast: http://www.ncbi.nlm.nih.gov/guide/howto/run-blast-local/\n"
}
if (!shell.which("python")) {
missing += "Python 2.7+: https://www.python.org/\n";
}
exec('python --version', (error, stdout, stderr) => { // check python version 2.7+
if (error) {
console.error("FAILED TO CHECK PYTHON VERSION");
app.quit();
}
stderr = stderr.match(/Python (\d\.\d).+/)[1]
if (stderr != '2.7') {
missing += "Python 2.7+: https://www.python.org/\n";
}
exec('python -c "import sqlite3"; echo $?', (error, stdout, stderr) => { // make sure sqlite3 module is installed
if (error) {
dialog.showMessageBox(mainWindow, {type:"error",title:"ERROR",message:'python -c "import sqlite3"; echo $?',buttons:["OK"]}, function() {
mainWindow.close();
});
}
else {
stdout = stdout.replace("\n","")
if (stdout != "0") {
missing += "Missing SQLite3 Module: try \"pip install pysqlite\"\n";
}
}
exec('python -c "from Bio import SeqIO"; echo $?', (error, stdout, stderr) => { // make sure sqlite3 module is installed
if (error) {
dialog.showMessageBox(mainWindow, {type:"error",title:"ERROR",message:'Failed to run python -c "from Bio import SeqO"; echo $?',buttons:["OK"]}, function() {
mainWindow.close();
});
}
else {
stdout = stdout.replace("\n","")
if (stdout != "0") {
missing += "Missing BioPython Module: try \"pip install biopython\"\n";
}
}
if (missing.length > 0) {
let open_window = mainWindow;
if (open_window == null) {
open_window = projectsWindow;
}
dialog.showMessageBox(null, {type:"error",title:"Missing Dependencies",message:"Please install the following dependencies:",detail:missing,buttons:["OK"]}, function() {
open_window.close();
});
}
});
});
});
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', startGeneysis);
// Quit when all windows are closed.
app.on('window-all-closed', function () {
app.quit();
});
// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.
ipcMain.on('electron-msg', (event, msg) => {
//handle incoming message here
console.log(msg);
if (msg.task == "get_genbank") { // open dialog to allow user to select files
let options = {
properties: ['openFile', 'multiSelections'],
filters: [
{name: 'Genbank', extensions: ['.gbk', '.gb', '.genbank']},
{name: 'Others', extensions: ['*']}
],
};
if (process.platform !== 'darwin') {
dialog.showOpenDialog(options, function (selected_files) {
if (selected_files) {
event.sender.send('electron-msg', {
task: "load_genbank",
files: selected_files
})
}
});
}
else { // use sheet dialog
const window = BrowserWindow.fromWebContents(event.sender)
const files = dialog.showOpenDialog(window, options, function (selected_files) {
if (selected_files) {
event.sender.send('electron-msg', {
task: "load_genbank",
files: selected_files
})
}
});
}
}
else if (msg.task == "get_projects") {
shell.cd();
var home = shell.pwd().stdout;
shell.cd('.geneysis');
if (shell.pwd().stdout == home) {
shell.mkdir('-p',[".geneysis/projects",".geneysis/config"]);
shell.cd('.geneysis');
}
var wd = shell.pwd().stdout
var results = shell.ls('projects/*/project.json');
var projects = [];
for (let i = 0; i < results.length; i++) {
console.log(results[i])
try {
let obj = JSON.parse(fs.readFileSync(results[i],{encoding:'utf8'}));
console.log(obj)
projects.push(obj);
}
catch (err) {
console.log(err)
}
}
console.log(projects);
event.sender.send('electron-msg', {
task: "projects",
projects: projects,
wd: wd + "/projects/"
});
}
else if (msg.task == "open_project") {
project = msg.project;
openGeneysis();
}
else if (msg.task == "get_current_project") {
console.log(project);
try {
let obj = JSON.parse(fs.readFileSync(project.path + "project.json",{encoding:'utf8'}));
console.log(obj);
event.sender.send('electron-msg', {
task: "load_project",
project: obj,
});
}
catch (err) {
console.log(err)
}
}
});