Skip to content

Commit

Permalink
chords
Browse files Browse the repository at this point in the history
  • Loading branch information
ihh committed Jun 26, 2016
1 parent b6e10bf commit 4911d92
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 69 deletions.
135 changes: 75 additions & 60 deletions init.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,68 @@ var rotunda
require(
["dojo/request/xhr",
"Rotunda/Rotunda",
"Rotunda/util",
"dojo/domReady!"],

function(xhr,
Rotunda) {
Rotunda,
util) {

var refSeqNameLen = [
["chr1", 249250621],
["chr2", 243199373],
["chr3", 198022430],
["chr4", 191154276],
["chr5", 180915260],
["chr6", 171115067],
["chr7", 159138663],
["chr8", 146364022],
["chr9", 141213431],
["chr10", 135534747],
["chr11", 135006516],
["chr12", 133851895],
["chr13", 115169878],
["chr14", 107349540],
["chr15", 102531392],
["chr16", 90354753],
["chr17", 81195210],
["chr18", 78077248],
["chr20", 63025520],
["chr19", 59128983],
["chr22", 51304566],
["chr21", 48129895],
["chrX", 155270560],
["chrY", 59373566]
]

var refSeqName = refSeqNameLen.map (function (nl) { return nl[0] })
var refSeqLen = refSeqNameLen.map (function (nl) { return nl[1] })
var isRefSeqName = util.listToCounts (refSeqName)

var refSeqFeatures = refSeqNameLen.map (function (nl) {
return { seq: nl[0],
start: 0,
end: nl[1],
id: nl[0],
type: nl[0] }
})

var refSeqTrack = { id: "ref_seqs",
label: "Chromosomes",
type: "feature",
features: refSeqFeatures }

var refSeqNameFeatures = refSeqNameLen.map (function (nl) {
return { seq: nl[0],
pos: Math.floor(nl[1]/2),
label: nl[0].replace("chr","") }
})
var refSeqNameTrack = { id: "ref_seq_names",
label: "Chromosome names",
type: "text",
radius: 30,
features: refSeqNameFeatures }

xhr("cytoBand.txt", {
handleAs: "text"
}).then (function (cytoBandTxt) {
Expand All @@ -28,13 +85,14 @@ require(

var cytoTrack = { id: "cyto_bands",
label: "Cytogenetic bands",
type: "arc",
type: "feature",
features: cyto }

xhr("GRCh37GenomicSuperDup.links", {
handleAs: "text"
}).then (function (segDupTxt) {


var minSegDupSize = 100000
var segDup = segDupTxt
.split("\n")
.filter (function (line) { return line.match (nonempty_regex) })
Expand All @@ -43,70 +101,27 @@ require(
return { seq: fields[0],
start: fields[1],
end: fields[2],
otherseq: fields[4],
otherstart: fields[5],
otherend: fields[6] }
otherSeq: fields[3],
otherStart: fields[4],
otherEnd: fields[5] }
})
.filter (function (link) {
return isRefSeqName[link.seq] && isRefSeqName[link.otherSeq] && link.end - link.start >= minSegDupSize
})

var refSeqNameLen = [
["chr1", 249250621],
["chr2", 243199373],
["chr3", 198022430],
["chr4", 191154276],
["chr5", 180915260],
["chr6", 171115067],
["chr7", 159138663],
["chr8", 146364022],
["chr9", 141213431],
["chr10", 135534747],
["chr11", 135006516],
["chr12", 133851895],
["chr13", 115169878],
["chr14", 107349540],
["chr15", 102531392],
["chr16", 90354753],
["chr17", 81195210],
["chr18", 78077248],
["chr20", 63025520],
["chr19", 59128983],
["chr22", 51304566],
["chr21", 48129895],
["chrX", 155270560],
["chrY", 59373566]
]

var refSeqName = refSeqNameLen.map (function (nl) { return nl[0] })
var refSeqLen = refSeqNameLen.map (function (nl) { return nl[1] })

var refSeqFeatures = refSeqNameLen.map (function (nl) {
return { seq: nl[0],
start: 0,
end: nl[1],
id: nl[0],
type: nl[0] }
})

var refSeqTrack = { id: "ref_seqs",
label: "Chromosomes",
type: "arc",
features: refSeqFeatures }

var refSeqNameFeatures = refSeqNameLen.map (function (nl) {
return { seq: nl[0],
pos: Math.floor(nl[1]/2),
label: nl[0].replace("chr","") }
})
var refSeqNameTrack = { id: "ref_seq_names",
label: "Chromosome names",
type: "text",
radius: 30,
features: refSeqNameFeatures }
console.log (segDup.length + " segmental duplications of size >= " + minSegDupSize + "bp")

var segDupTrack = { id: "segdup",
label: "Segmental duplications",
type: "link",
features: segDup }

rotunda = new Rotunda( { refSeqName: refSeqName,
refSeqLen: refSeqLen,
tracks: [ refSeqNameTrack,
refSeqTrack,
cytoTrack ] })
cytoTrack,
segDupTrack ] })
})

})
Expand Down
45 changes: 37 additions & 8 deletions src/Rotunda/Rotunda.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ return declare( null, {
return track.radius || config.defaultTrackRadius || 10
})

this.innerRadius = config.innerRadius || 100
var minInnerRadius = config.innerRadius || 100
var r = 0
this.trackOutsideRadius = []
for (var n = 0; n < this.tracks.length; ++n) {
this.trackOutsideRadius.push (r)
r += this.trackRadius[n]
}
this.radius = Math.max (config.radius || 300,
r + this.innerRadius)
r + minInnerRadius)

this.width = this.radius * 2
this.height = this.radius * 2
Expand Down Expand Up @@ -99,7 +99,6 @@ return declare( null, {
this.svg.call(drag)

this.draw()
this.redraw()
},

xyAngle: function(x,y) {
Expand Down Expand Up @@ -306,6 +305,10 @@ return declare( null, {
return this.radius * this.scale - this.trackOutsideRadius[trackNum] * this.trackRadiusScale
},

innerRadius: function() {
return this.minRadius (this.tracks.length-1) - 1
},

coordToAngle: function (seqName, pos) {
return this.refSeqStartAngleByName[seqName] + pos * this.radsPerBase + this.rotate
},
Expand All @@ -316,19 +319,22 @@ return declare( null, {
var minRadius = this.minRadius (trackNum)

var featureColor = track.color || function (feature) {
var rgb = rot.colors[feature.type]
if (rgb.length == 3) {
return util.rgbToHex.apply (rot, rgb)
var rgb = rot.colors[feature.color || feature.type || 'black']
if( Object.prototype.toString.call(rgb) === '[object Array]' ) {
if (rgb.length == 3) {
return util.rgbToHex.apply (rot, rgb)
}
return 'black'
}
return "black"
return rgb
}

var data = this.g.selectAll("#track_"+track.id)
.data(track.features)
.enter()

switch (track.type) {
case "arc":
case "feature":

var featureArc = d3.svg.arc()
.innerRadius(minRadius)
Expand Down Expand Up @@ -367,6 +373,29 @@ return declare( null, {
.text(featureText)
break;

case "link":
var innerRadius = rot.innerRadius()
var featureChord = d3.svg.chord()
.source (function (link) {
var s = { startAngle: rot.coordToAngle (link.seq, link.start),
endAngle: rot.coordToAngle (link.seq, link.end),
radius: innerRadius }
return s
})
.target (function (link) {
var t = { startAngle: rot.coordToAngle (link.otherSeq, link.otherStart),
endAngle: rot.coordToAngle (link.otherSeq, link.otherEnd),
radius: innerRadius }
return t
})

data.append("path")
.attr("d", featureChord)
.attr("fill", featureColor)
.attr("stroke", featureColor)

break;

default:
break;
}
Expand Down
10 changes: 9 additions & 1 deletion src/Rotunda/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@ define([

var Util
Util = {


listToCounts: function (list) {
var c = {}
list.forEach (function(x) {
c[x] = (c[x] || 0) + 1
})
return c
},

keyValListToObj: function (keyValList) {
var obj = {}
keyValList.forEach (function (keyVal) {
Expand Down

0 comments on commit 4911d92

Please sign in to comment.