forked from mdbassoon/fly-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nightmareTools.js
573 lines (554 loc) · 24.8 KB
/
nightmareTools.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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
const Nightmare = require('nightmare');
var Xvfb = require('xvfb');
async function searchForGene(gene) {
try{
var xvfb = new Xvfb();
xvfb.startSync();
// code that uses the virtual frame buffer here
const nightmare = Nightmare({ show: false });
let res = await nightmare
.goto('https://flybase.org')
.wait('#GeneSearch')
.insert('#GeneSearch', gene)
.click('#GeneSearch_submit')
.wait(4000, '#general_information','#genomic_location')
.end()
.evaluate(() => {
const geneName = document.getElementById('general_information').nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling.children[0].children[1].innerText;
const fastaButton = document.getElementById('genomic_location').nextElementSibling.nextElementSibling.nextElementSibling.children[0].children[1].children[0].children[1].children[0];
const jbrowseButton = document.getElementById('genomic_location').nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling.children[0].children[0].children[0].children[1];
const fastaUrl = fastaButton.href;
const jbrowseUrl = jbrowseButton.href;
const obj = {
'fastaUrl':fastaUrl,
'jbrowseUrl':jbrowseUrl,
'geneName':geneName
}
return obj;
}).catch(err=>console.log(err));
//console.log('response',res);
const fastaUrl = !res['fastaUrl']?'':res['fastaUrl'];
const jbrowseUrl = !res['jbrowseUrl']?'':res['jbrowseUrl'];
const geneName = !res['jbrowseUrl']?'':res['geneName'];
xvfb.stopSync();
return {fastaUrl:fastaUrl,jbrowseUrl:jbrowseUrl,geneTitle:geneName};
}catch(error) {
//console.log(error);
return error;
}
}
async function getMoreBases(url) {
try {
var xvfb = new Xvfb();
xvfb.startSync();
let nightmare = Nightmare({show: false});
let geneInfo = await nightmare.goto(url).end().evaluate(()=>{
const genes = document.getElementsByClassName('col-xs-12')[2].children[0].children;
let geneArr = [];
let geneColorArr = [];
for(let i = 0;i<genes.length;i++){
geneArr.push(genes[i].innerText.replace(/\s/g, ''));
if(window.getComputedStyle(genes[i]).color) {
geneColorArr.push(window.getComputedStyle(genes[i]).color);
} else {
geneColorArr.push(genes[i].style.color);
}
}
return {'fullGene':document.getElementsByClassName('col-xs-12')[2].children[0].innerText.replace(/\s/g, ''),'geneSections':geneArr,'colorCode':geneColorArr};
});
const sections = geneInfo['geneSections'];
let sectionStarts = [];
let sectionStops = [];
let geneSections = [];
let geneColors = [];
let sectionNames = [];
let fullGene = geneInfo['fullGene'];
for(let i=0;i<sections.length;i++){
const start = geneInfo['fullGene'].search(sections[i]);
const stop = start+sections[i].length;
sectionStarts.push(start);
sectionStops.push(stop);
}
const pre = fullGene.slice(0,sectionStarts[0]);
for(let i=0;i<sectionStarts.length;i++){
const start = sectionStarts[i];
const stop = sectionStops[i];
const nextStart = !sectionStarts[i+1]?fullGene.length:sectionStarts[i+1];
const section = fullGene.slice(start,stop);
const isPink = geneInfo['colorCode'][i].search(/rgb\(25/)>-1;
const isBlue = geneInfo['colorCode'][i].search(/rgb\(0, 0, 2/)>-1;
if(isPink){
//Coding Region
geneColors.push('rgb(55,114,255)')
sectionNames.push('coding region');
geneSections.push(section);
} else if(isBlue) {
if(fullGene[start] === fullGene[start].toUpperCase()){//If it's blue and first letters uppercase, it's a UTR
// console.log('UTR: ');
// console.log('multiple sections?: ',section.match(/[a-z]/g, "")?true:false);
if(section.match(/[a-z]/g, "")){//if there is a lowercase section within this section, separate it out as a genespan. Multiple alternating sections possible.
let lowerStarts = [0];
let upperStarts = [section.search(/[a-z]/g, "")];
for(let y=0;y<section.length;y++) {
if(y>upperStarts[upperStarts.length-1]&&upperStarts[upperStarts.length-1]>lowerStarts[lowerStarts.length-1]&§ion[y].match(/[A-Z]/g, "")){
lowerStarts.push(y);
} else if(y>lowerStarts[lowerStarts.length-1]&&lowerStarts[lowerStarts.length-1]>upperStarts[upperStarts.length-1]&§ion[y].match(/[a-z]/g, "")) {
upperStarts.push(y);
}
}
// console.log(lowerStarts);
// console.log(upperStarts);
// console.log('total sections: ',lowerStarts.length>upperStarts.length?(lowerStarts.length*2)-1:lowerStarts.length*2);
for(let y=0;y<lowerStarts.length;y++){
if(!upperStarts[y]) {
geneColors.push('rgb(19,111,99)');
sectionNames.push('UTR');
geneSections.push(section.split('').slice(lowerStarts[y],section.length).join(''));
// console.log(y+': ', section.split('').slice(lowerStarts[y],section.length).join(''));
} else {
// console.log('lowerStart y: ', lowerStarts[y]);
// console.log('upperStarts y: ', upperStarts[y]);
geneColors.push('rgb(19,111,99)');
sectionNames.push('UTR');
geneSections.push(section.split('').slice( lowerStarts[y], upperStarts[y]).join(''));
// console.log(y, section.split('').slice(lowerStarts[y], upperStarts[y]).join(''));
// console.log('upperStarts y: ', upperStarts[y]);
// console.log('lowerStarts y+1: ', lowerStarts[y+1]);
geneColors.push('rgb(8,7,8)');
sectionNames.push('geneSpan');
geneSections.push(section.split('').slice(upperStarts[y], !lowerStarts[y+1]?section.length:lowerStarts[y+1]).join(''));
// console.log(y+': ',section.split('').slice(upperStarts[y], !lowerStarts[y+1]?section.length:lowerStarts[y+1]).join(''))
}
}
} else {
geneColors.push('rgb(19,111,99)');
sectionNames.push('UTR');
geneSections.push(section);
}
/*geneColors.push('rgb(19,111,99)')
sectionNames.push('UTR');
geneSections.push(section);*/
} else { //genespan
// console.log('gene span: ');
// console.log('multiple sections?: ',section.match(/[A-Z]/g, "")?true:false);
if(section.match(/[A-Z]/g, "")){//if there is an uppercase section within this section, separate it out as a UTR. Multiple alternating sections possible.
let lowerStarts = [0];
let upperStarts = [section.search(/[A-Z]/g, "")];
for(let y=0;y<section.length;y++) {
if(y>upperStarts[upperStarts.length-1]&&upperStarts[upperStarts.length-1]>lowerStarts[lowerStarts.length-1]&§ion[y].match(/[a-z]/g, "")){
lowerStarts.push(y);
} else if(y>lowerStarts[lowerStarts.length-1]&&lowerStarts[lowerStarts.length-1]>upperStarts[upperStarts.length-1]&§ion[y].match(/[A-Z]/g, "")) {
upperStarts.push(y);
}
}
// console.log(lowerStarts);
// console.log(upperStarts);
// console.log('total sections: ',lowerStarts.length>upperStarts.length?(lowerStarts.length*2)-1:lowerStarts.length*2);
for(let y=0;y<lowerStarts.length;y++){
if(!upperStarts[y]) {
geneColors.push('rgb(8,7,8)');
sectionNames.push('geneSpan');
geneSections.push(section.split('').slice(lowerStarts[y],section.length).join(''));
// console.log(y+': ', section.split('').slice(lowerStarts[y],section.length).join(''));
} else {
// console.log('lowerStart y: ', lowerStarts[y]);
// console.log('upperStarts y: ', upperStarts[y]);
geneColors.push('rgb(8,7,8)');
sectionNames.push('geneSpan');
geneSections.push(section.split('').slice( lowerStarts[y], upperStarts[y]).join(''));
// console.log(y, section.split('').slice(lowerStarts[y], upperStarts[y]).join(''));
// console.log('upperStarts y: ', upperStarts[y]);
// console.log('lowerStarts y+1: ', lowerStarts[y+1]);
geneColors.push('rgb(19,111,99)');
sectionNames.push('UTR');
geneSections.push(section.split('').slice(upperStarts[y], !lowerStarts[y+1]?section.length:lowerStarts[y+1]).join(''));
// console.log(y+': ',section.split('').slice(upperStarts[y], !lowerStarts[y+1]?section.length:lowerStarts[y+1]).join(''))
}
}
} else {
geneColors.push('rgba(8,7,8)');
sectionNames.push('geneSpan');
geneSections.push(section);
}
}
} else {
geneColors.push('rgba(8,7,8,0.2)');
sectionNames.push('unknown');
}
if(nextStart-1>stop&&i<sectionStarts.length-1){//If there is unwrapped space between the genetic information, it is the intergenic region
geneSections.push(fullGene.slice(stop, nextStart));
geneColors.push('rgba(8,7,8,0.4)');
sectionNames.push('intergenic');
}
}
xvfb.stopSync();
return {
geneSections:geneSections,
fullGene:geneInfo['fullGene'].slice(pre.length,geneInfo['fullGene'].length),
colorCode:geneColors,
sectionNames:sectionNames,
pre:pre,
};
} catch(error) {
// console.log(error);
return error;
}
}
async function getGeneInfo(url) {
try {
var xvfb = new Xvfb();
xvfb.startSync();
let nightmare = Nightmare({show: false});
let geneInfo = await nightmare.goto(url).end().evaluate(()=>{
const genes = document.getElementsByClassName('col-xs-12')[2].children[0].children;
let geneArr = [];
let geneColorArr = [];
for(let i = 0;i<genes.length;i++){
geneArr.push(genes[i].innerText.replace(/\s/g, ''));
if(window.getComputedStyle(genes[i]).color) {
geneColorArr.push(window.getComputedStyle(genes[i]).color);
} else {
geneColorArr.push(genes[i].style.color);
}
}
return {'fullGene':document.getElementsByClassName('col-xs-12')[2].children[0].innerText.replace(/\s/g, ''),'geneSections':geneArr,'colorCode':geneColorArr};
});
const sections = geneInfo['geneSections'];
let sectionStarts = [];
let sectionStops = [];
let geneSections = [];
let geneColors = [];
let sectionNames = [];
let fullGene = geneInfo['fullGene'];
for(let i=0;i<sections.length;i++){
const start = geneInfo['fullGene'].search(sections[i]);
const stop = start+sections[i].length;
sectionStarts.push(start);
sectionStops.push(stop);
}
const pre = fullGene.slice(0,sectionStarts[0]);
for(let i=0;i<sectionStarts.length;i++){
const start = sectionStarts[i];
const stop = sectionStops[i];
const nextStart = !sectionStarts[i+1]?fullGene.length:sectionStarts[i+1];
const section = fullGene.slice(start,stop);
const isPink = geneInfo['colorCode'][i].search(/rgb\(25/)>-1;
const isBlue = geneInfo['colorCode'][i].search(/rgb\(0, 0, 2/)>-1;
if(isPink){
//Coding Region
geneColors.push('rgb(55,114,255)')
sectionNames.push('coding region');
geneSections.push(section);
} else if(isBlue) {
if(fullGene[start] === fullGene[start].toUpperCase()){//If it's blue and first letters uppercase, it's a UTR
// console.log('UTR: ');
// console.log('multiple sections?: ',section.match(/[a-z]/g, "")?true:false);
if(section.match(/[a-z]/g, "")){//if there is a lowercase section within this section, separate it out as a genespan. Multiple alternating sections possible.
let lowerStarts = [0];
let upperStarts = [section.search(/[a-z]/g, "")];
for(let y=0;y<section.length;y++) {
if(y>upperStarts[upperStarts.length-1]&&upperStarts[upperStarts.length-1]>lowerStarts[lowerStarts.length-1]&§ion[y].match(/[A-Z]/g, "")){
lowerStarts.push(y);
} else if(y>lowerStarts[lowerStarts.length-1]&&lowerStarts[lowerStarts.length-1]>upperStarts[upperStarts.length-1]&§ion[y].match(/[a-z]/g, "")) {
upperStarts.push(y);
}
}
// console.log(lowerStarts);
// console.log(upperStarts);
// console.log('total sections: ',lowerStarts.length>upperStarts.length?(lowerStarts.length*2)-1:lowerStarts.length*2);
for(let y=0;y<lowerStarts.length;y++){
if(!upperStarts[y]) {
geneColors.push('rgb(19,111,99)');
sectionNames.push('UTR');
geneSections.push(section.split('').slice(lowerStarts[y],section.length).join(''));
// console.log(y+': ', section.split('').slice(lowerStarts[y],section.length).join(''));
} else {
// console.log('lowerStart y: ', lowerStarts[y]);
// console.log('upperStarts y: ', upperStarts[y]);
geneColors.push('rgb(19,111,99)');
sectionNames.push('UTR');
geneSections.push(section.split('').slice( lowerStarts[y], upperStarts[y]).join(''));
// console.log(y, section.split('').slice(lowerStarts[y], upperStarts[y]).join(''));
// console.log('upperStarts y: ', upperStarts[y]);
// console.log('lowerStarts y+1: ', lowerStarts[y+1]);
geneColors.push('rgb(8,7,8)');
sectionNames.push('geneSpan');
geneSections.push(section.split('').slice(upperStarts[y], !lowerStarts[y+1]?section.length:lowerStarts[y+1]).join(''));
// console.log(y+': ',section.split('').slice(upperStarts[y], !lowerStarts[y+1]?section.length:lowerStarts[y+1]).join(''))
}
}
} else {
geneColors.push('rgb(19,111,99)');
sectionNames.push('UTR');
geneSections.push(section);
}
/*geneColors.push('rgb(19,111,99)')
sectionNames.push('UTR');
geneSections.push(section);*/
} else { //genespan
// console.log('gene span: ');
// console.log('multiple sections?: ',section.match(/[A-Z]/g, "")?true:false);
if(section.match(/[A-Z]/g, "")){//if there is an uppercase section within this section, separate it out as a UTR. Multiple alternating sections possible.
let lowerStarts = [0];
let upperStarts = [section.search(/[A-Z]/g, "")];
for(let y=0;y<section.length;y++) {
if(y>upperStarts[upperStarts.length-1]&&upperStarts[upperStarts.length-1]>lowerStarts[lowerStarts.length-1]&§ion[y].match(/[a-z]/g, "")){
lowerStarts.push(y);
} else if(y>lowerStarts[lowerStarts.length-1]&&lowerStarts[lowerStarts.length-1]>upperStarts[upperStarts.length-1]&§ion[y].match(/[A-Z]/g, "")) {
upperStarts.push(y);
}
}
// console.log(lowerStarts);
// console.log(upperStarts);
// console.log('total sections: ',lowerStarts.length>upperStarts.length?(lowerStarts.length*2)-1:lowerStarts.length*2);
for(let y=0;y<lowerStarts.length;y++){
if(!upperStarts[y]) {
geneColors.push('rgb(8,7,8)');
sectionNames.push('geneSpan');
geneSections.push(section.split('').slice(lowerStarts[y],section.length).join(''));
// console.log(y+': ', section.split('').slice(lowerStarts[y],section.length).join(''));
} else {
// console.log('lowerStart y: ', lowerStarts[y]);
// console.log('upperStarts y: ', upperStarts[y]);
geneColors.push('rgb(8,7,8)');
sectionNames.push('geneSpan');
geneSections.push(section.split('').slice( lowerStarts[y], upperStarts[y]).join(''));
// console.log(y, section.split('').slice(lowerStarts[y], upperStarts[y]).join(''));
// console.log('upperStarts y: ', upperStarts[y]);
// console.log('lowerStarts y+1: ', lowerStarts[y+1]);
geneColors.push('rgb(19,111,99)');
sectionNames.push('UTR');
geneSections.push(section.split('').slice(upperStarts[y], !lowerStarts[y+1]?section.length:lowerStarts[y+1]).join(''));
// console.log(y+': ',section.split('').slice(upperStarts[y], !lowerStarts[y+1]?section.length:lowerStarts[y+1]).join(''))
}
}
} else {
geneColors.push('rgba(8,7,8)');
sectionNames.push('geneSpan');
geneSections.push(section);
}
}
} else {
geneColors.push('rgba(8,7,8,0.2)');
sectionNames.push('unknown');
}
if(nextStart-1>stop&&i<sectionStarts.length-1){//If there is unwrapped space between the genetic information, it is the intergenic region
geneSections.push(fullGene.slice(stop, nextStart));
geneColors.push('rgba(8,7,8,0.4)');
sectionNames.push('intergenic');
}
}
xvfb.stopSync();
return {
geneSections:geneSections,
fullGene:geneInfo['fullGene'].slice(pre.length,geneInfo['fullGene'].length),
colorCode:geneColors,
sectionNames:sectionNames,
pre:pre,
};
} catch(error) {
// console.log(error);
return error;
}
}
async function searchForTargets(targetArea) {
// console.log('target area: ',targetArea)
try {
var xvfb = new Xvfb();
xvfb.startSync();
const url = 'http://targetfinder.flycrispr.neuro.brown.edu/';
let nightmare = Nightmare({show: false});
let error = false;
let res = await nightmare.goto(url)
.wait('select[name="genomeSelect"]')
.select('select[name="genomeSelect"]', 'Dmelvc9')
.insert('#gDNA-form', targetArea)
.click('button[name="routingVar"]')
.wait('#CRISPRinput')
.evaluate(()=>{
const input = document.getElementById('CRISPRinput');
const targets = input.innerHTML.toString().split('\n');
if(targets.length>99) {
input.innerHTML = targets.slice(0,99).join('\n');
}
})
.click('button[name="routingVar"]')
.wait('.result')
.end()
.evaluate(()=>{
const results = document.getElementsByClassName('result');
let resultsArr = [];
for(let i=0;i<results.length;i++){
let resultObj = {};
if(results[i].getElementsByClassName('label-important-custom').length===0){
resultObj['offTarget'] = results[i].getElementsByClassName('label')[0].innerText[0];
resultObj['distal'] = results[i].getElementsByClassName('distal')[0].innerText;
resultObj['proximal'] = results[i].getElementsByClassName('proximal')[0].innerText;
resultObj['pam'] = results[i].getElementsByClassName('pam')[0].innerText;
resultObj['strand'] = results[i].getElementsByTagName('td')[1].innerText;
resultObj['label'] = results[i].getElementsByClassName('target-label')[0].innerText;
resultsArr.push(resultObj);
} else {error = true;}
}
return resultsArr;
});
// console.log('res: ',res);
xvfb.stopSync();
if(!Array.isArray(res) || !res.length || error) {
return {'error':'No Targets Found'};
} else {
if(res.length>0) {
return res;
} else {
return {'error':'No Targets Found'};
}
}
} catch(error){
return error;
}
}
async function checkTargetEfficiency(targets) {
const url = 'http://www.flyrnai.org/evaluateCrispr/'
try {
var xvfb = new Xvfb();
xvfb.startSync();
let nightmare = Nightmare({show:false});
const fullSearchString = targets.map((target)=>{
const proximal = target.proximal;
const distal = target.distal;
const pam = target.pam;
return proximal+distal;
}).join('\n');
let scores = await nightmare.goto(url)
.insert('#textAreaInput', fullSearchString)
.click('input[value="Display Results"]')
.wait('#dataTable')
.end()
.evaluate(()=>{
const rows = document.getElementById('dataTable').children[1].children;
let scores = [];
for(let i=0;i<rows.length;i++){
const score = rows[i].children[8].innerText;
scores.push(score)
}
return scores;
});
xvfb.stopSync();
if(!Array.isArray(scores) || !scores.length){
return {'error':'scores not found'}
} else {
for(let i=0;i<targets.length;i++){
targets[i]['score'] = scores[i];
}
return targets;
}
} catch(error) {
return error;
}
}
async function getOligos(target) {
try {
var xvfb = new Xvfb();
xvfb.startSync();
const thisTarget = target.toString();
let nightmare = Nightmare({show: false});
const url = 'http://targetfinder.flycrispr.neuro.brown.edu/';
let res = await nightmare.goto(url)
.wait('select[name="genomeSelect"]')
.select('select[name="genomeSelect"]', 'Dmelvc9')
.wait('#gDNA-form')
.insert('#gDNA-form', thisTarget)
.click('button[name="routingVar"]')
.wait('#CRISPRinput')
.evaluate((thisTarget)=>{
document.getElementById('CRISPRinput').innerHTML = thisTarget;
}, thisTarget)
.click('button[name="routingVar"]')
.wait('.target-checkbox')
.click('.target-checkbox')
.wait('button[name="routingVar"]')
.click('button[name="routingVar"]')
.wait('.oligo-order')
.end()
.evaluate(()=>{
const oligos = document.getElementsByClassName('oligo-order')[0].children;
let oligoText = [];
for(let i=0;i<oligos.length;i++) {
oligoText.push(oligos[i].innerText);
}
return oligoText;
});
xvfb.stopSync();
if(!Array.isArray(res) || !res.length) {
return {error:'error'}
} else {
return res;
}
} catch(error) {
return error;
}
}
async function getPrimers(primerSections) {
let primers = {};
const url = 'http://bioinfo.ut.ee/primer3-0.4.0/';
for(let i=0;i<4;i++){
var xvfb = new Xvfb();
xvfb.startSync();
let currentPrimer = !primers['hom5']?"5' Homology":!primers['seq5']?"5' Sequence":!primers['seq3']?"3' Sequence":"3' Homology";
let primerSection = primerSections[currentPrimer];
let primerSide = currentPrimer==="3' Homology"?'input[name="MUST_XLATE_PICK_LEFT"]':currentPrimer==="3' Sequence"?'input[name="MUST_XLATE_PICK_LEFT"]':'input[name="MUST_XLATE_PICK_RIGHT"]';
try {
let nightmare = Nightmare({show: false});
let res = await nightmare.goto(url)
.wait('textarea[name="SEQUENCE"]')
.insert('textarea[name="SEQUENCE"]', primerSection)
.click(primerSide)
.click('input[name="Pick Primers"]')
.wait('a[href="/primer3-0.4.0/primer3_www_results_help.html#PRIMER_OLIGO_SEQ"]')
.end()
.evaluate(()=>{
const primers = document.querySelector('a[href="/primer3-0.4.0/primer3_www_results_help.html#PRIMER_OLIGO_SEQ"]').parentElement.innerText;
return primers;
});
xvfb.stopSync();
let primerStart = [];
let stop = 0;
let finalStop = 0;
for(let i=0;i<res.length;i++) {
if(res.slice(i,i+6)==='PRIMER'){
primerStart.push(i);
} else if(res.slice(i,i+13)==='SEQUENCE SIZE') {
stop = i;
} else if(res.slice(i,i+10)==='Statistics') {
finalStop = i;
}
}
const firstPrimer = res.slice(primerStart[0],stop).replace(/[\n\r]/g,'').split(' ').filter((el)=>{return el != ''});
let allPrimers = [firstPrimer];
for(let i=1;i<primerStart.length;i++){
const primer = res.slice(primerStart[i],!primerStart[i+1]?finalStop:primerStart[i+1]).replace(/[\n\r]/g,'').split(' ').filter((el)=>{return el != ''});
allPrimers.push(primer);
}
if(currentPrimer==="5' Homology"){
primers['hom5'] = allPrimers;
} else if(currentPrimer==="5' Sequence") {
primers['seq5'] = allPrimers;
} else if(currentPrimer==="3' Sequence") {
primers['seq3'] = allPrimers;
} else {
primers['hom3'] = allPrimers;
}
} catch(error) {
// console.log(error);
return error;
}
}
return primers;
}
module.exports.searchForGene = searchForGene;
module.exports.getMoreBases = getMoreBases;
module.exports.getGeneInfo = getGeneInfo;
module.exports.searchForTargets = searchForTargets;
module.exports.checkTargetEfficiency = checkTargetEfficiency;
module.exports.getOligos = getOligos;
module.exports.getPrimers = getPrimers;