forked from j-4/fornac-cmd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generator.js
56 lines (44 loc) · 1.54 KB
/
generator.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
var system = require('system');
var sequence = "";
var structure = "";
if(system.args.length !== 3){
console.log('Error: this script requires two arguments (sequence and structure)!');
} else {
sequence = system.args[1];
structure = system.args[2];
}
var options = {'structure': structure,'sequence': sequence};
var fs = require('fs');
var page = require('webpage').create();
var url = 'file://' + fs.absolute('./index.html');
var createForna = function(options) {
var container = new fornac.FornaContainer("#rna_ss",
{'applyForce': true, 'allowPanningAndZooming': true, 'initialSize':[500,500],
'friction': 0.35,
'middleCharge': -30,
'otherCharge': -30,
'linkDistanceMultiplier': 15,
'chargeDistance': 110
}
);
container.addRNA(options.structure, options);
return container;
};
var writeSVG = function() {
var svg = document.getElementById('plotting-area');
var svg_string = new XMLSerializer().serializeToString(svg);
return svg_string;
};
function evaluate(page, func) {
var args = [].slice.call(arguments, 2);
var fn = "function() { return (" + func.toString() + ").apply(this, " + JSON.stringify(args) + ");}";
return page.evaluate(fn);
}
page.open(url, function (status) {
var container = evaluate(page, createForna, options);
setTimeout(function() {
//page.evaluate(function(){ container.clearNodes(); });
console.log(page.evaluate(writeSVG));
phantom.exit();
}, 2500);
});