Skip to content

Commit

Permalink
Add drawrna, with existing code until npm dependency works
Browse files Browse the repository at this point in the history
  • Loading branch information
guerler committed Feb 11, 2018
1 parent 97cab84 commit 820d0b4
Show file tree
Hide file tree
Showing 30 changed files with 5,438 additions and 0 deletions.
16 changes: 16 additions & 0 deletions config/plugins/visualizations/drawrna/config/drawrna.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE visualization SYSTEM "../../visualization.dtd">
<visualization name="RNA Structure Viewer">
<description>Renders RNA structures hosted at https://github.com/bene200/drawrnajs.</description>
<data_sources>
<data_source>
<model_class>HistoryDatasetAssociation</model_class>
<test test_attr="ext" result_type="datatype">dbn</test>
<to_param param_attr="id">dataset_id</to_param>
</data_source>
</data_sources>
<params>
<param type="dataset" var_name_in_template="hda" required="true">dataset_id</param>
</params>
<entry_point entry_point_type="chart" src="static/script.js" func="func"/>
</visualization>
20 changes: 20 additions & 0 deletions config/plugins/visualizations/drawrna/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "visualization",
"version": "0.1.0",
"keywords": [
"galaxy",
"visualization"
],
"license": "AFL-3.0",
"dependencies": {
"babel-preset-env": "^1.6.1",
"backbone": "^1.3.3",
"bootstrap": "^3.3.7",
"drawrnajs": "^1.2.6",
"jquery": "^3.1.1",
"parcel-bundler": "^1.4.1"
},
"scripts": {
"build": "parcel build src/script.js -d static"
}
}
15 changes: 15 additions & 0 deletions config/plugins/visualizations/drawrna/src/drawrnajs/drawrna.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
var Backbone = require("backbone");
var Structure = require("./models/structure");
var Vispanel = require("./views/vispanel");

var Drawrnajs = Backbone.View.extend({
initialize: function(opts){
this.struct = new Structure(opts.seq, opts.dotbr, 'naview');
this.vis = new Vispanel({ el: opts.el, struct: this.struct, resindex: opts.resindex });
},
render: function(){
this.vis.render();
}
});

module.exports = Drawrnajs;
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
var radiate = require("./radiate/getradiate");
var naview = require("./naview/getnaview");

var Layout = function(layout, nodes, links){
this.layout = layout;
this.nodes = nodes;
this.links = links;
}

Layout.prototype.getCoords = function(){
var coords = null;
if(this.layout === "radiate"){
coords = radiate(this.nodes, this.links);
}
else if(this.layout === "naview"){
coords = naview(this.nodes, this.links);
}
else {
throw new Error("Invalid layout");
}
return coords;
}

module.exports = Layout;
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
var Region = require("./region");

var Base = module.exports = function(){
this.mate = null;
this.x = null;
this.y = null;
this.extracted = null;
this.region = new Region();
}

Base.prototype.getMate = function(){
return this.mate;
}

Base.prototype.setMate = function(mate){
this.mate = mate;
}

Base.prototype.getX = function(){
return this.x;
}

Base.prototype.setX = function(x){
this.x = x;
}

Base.prototype.getY = function(){
return this.y;
}

Base.prototype.setY = function(y){
this.y = y;
}

Base.prototype.isExtracted = function(){
return this.extracted;
}

Base.prototype.setExtracted = function(extracted){
this.extracted = extracted;
}

Base.prototype.getRegion = function(){
return this.region;
}

Base.prototype.setRegion = function(region){
this.region = region;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
var Loop = require("./loop");
var Region = require("./region");

var Connection = module.exports = function(){
this.loop = new Loop();
this.region = new Region();
// Start and end form the 1st base pair of the region.
this.start = null;
this.end = null;
this.xrad = null;
this.yrad = null;
this.angle = null;
// True if segment between this connection and the
// next must be extruded out of the circle
this.extruded = null;
// True if the extruded segment must be drawn long.
this.broken = null;

this._isNull = false;
}

Connection.prototype.isNull = function(){
return this._isNull;
}

Connection.prototype.setNull = function(isNull){
this._isNull = isNull;
}

Connection.prototype.getLoop = function(){
return this.loop;
}

Connection.prototype.setLoop = function(loop) {
this.loop = loop;
}

Connection.prototype.getRegion = function(){
return this.region;
}

Connection.prototype.setRegion = function(region){
this.region = region;
}

Connection.prototype.getStart = function(){
return this.start;
}

Connection.prototype.setStart = function(start) {
this.start = start;
}

Connection.prototype.getEnd = function(){
return this.end;
}

Connection.prototype.setEnd = function(end){
this.end = end;
}

Connection.prototype.getXrad = function(){
return this.xrad;
}

Connection.prototype.setXrad = function(xrad){
this.xrad = xrad;
}

Connection.prototype.getYrad = function(){
return this.yrad;
}

Connection.prototype.setYrad = function(yrad) {
this.yrad = yrad;
}

Connection.prototype.getAngle = function(){
return this.angle;
}

Connection.prototype.setAngle = function(angle){
this.angle = angle;
}

Connection.prototype.isExtruded = function(){
return this.extruded;
}

Connection.prototype.setExtruded = function(extruded){
this.extruded = extruded;
}

Connection.prototype.isBroken = function(){
return this.broken;
}

Connection.prototype.setBroken = function(broken){
this.broken = broken;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
var NAView = require("./naview");

getCoordsNAVIEW = module.exports = function(nodes, links){
//Calculates coordinates according to the NAView layout
var pairTable = [];

for(var i=0; i<nodes.length; i++){
pairTable.push(getPartner(i, links));
}
var naView = new NAView();
var xy = naView.naview_xy_coordinates(pairTable);

// Updating individual base positions
var coords = []
for (var i = 0; i < nodes.length; i++) {
coords.push({
x: Math.round(xy.x[i] * 2.5),
y: Math.round(xy.y[i] * 2.5)
});
}
return coords;
}

function getPartner(srcIndex, links){
//Returns the partner of a nucleotide:
//-1 means there is no partner
var partner = -1;
for(var i = 0; i < links.length; i++){
if(links[i].type !== "phosphodiester" && links[i].type !== "index"){
if(links[i].source === srcIndex){
partner = links[i].target;
break;
}
else if(links[i].target === srcIndex){
partner = links[i].source;
break;
}
else {
continue;
}
}
}
return partner;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
var Loop = module.exports = function(){
this.nconnection = null;
this.connections = [];
this._connections = [];
this.number = null;
this.depth = null;
this.mark = null;
this.x = null;
this.y = null;
this.radius = null;
}

Loop.prototype.getNconnection = function() {
return this.nconnection;
}

Loop.prototype.setNconnection = function(nconnection) {
this.nconnection = nconnection;
}

Loop.prototype.setConnection = function(i, c){
var Connection = require("./connection");
if (c != null){
this._connections[i] = c;
}
else {
if (!this._connections[i]){
this._connections[i] = new Connection();
}
this._connections[i].setNull(true);
}
}

Loop.prototype.getConnection = function(i){
var Connection = require("./connection");
if (!this._connections[i]){
this._connections[i] = new Connection();
}
var c = this._connections[i];
if (c.isNull()){
return null;
}
else {
return c;
}
}

Loop.prototype.addConnection = function(i, c){
this._connections.push(c);
}

Loop.prototype.getNumber = function(){
return this.number;
}

Loop.prototype.setNumber = function(number){
this.number = number;
}

Loop.prototype.getDepth = function(){
return this.depth;
}

Loop.prototype.setDepth = function(depth){
this.depth = depth;
}

Loop.prototype.isMark = function(){
return this.mark;
}

Loop.prototype.setMark = function(mark){
this.mark = mark;
}

Loop.prototype.getX = function(){
return this.x;
}

Loop.prototype.setX = function(x){
this.x = x;
}

Loop.prototype.getY = function(){
return this.y;
}

Loop.prototype.setY = function(y){
this.y = y;
}

Loop.prototype.getRadius = function(){
return this.radius;
}

Loop.prototype.setRadius = function(radius){
this.radius = radius;
}

0 comments on commit 820d0b4

Please sign in to comment.