Skip to content

Commit

Permalink
Basic layout
Browse files Browse the repository at this point in the history
  • Loading branch information
ihh committed Apr 5, 2016
1 parent 072c301 commit 726505f
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 56 deletions.
16 changes: 2 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,8 @@ README.md: bin/wtfgenes.js
bin/wtfgenes.js -h | perl -pe 's/</&lt;/g;s/>/&gt;/g;' | perl -e 'open FILE,"<README.md";while(<FILE>){last if/<pre>/;print}close FILE;print"<pre><code>\n";while(<>){print};print"</code></pre>\n"' >temp.md
mv temp.md $@

webclient: jquery plotly web/wtfgenes.js

jquery: web/jquery-1.12.2.min.js

plotly: web/plotly-latest.min.js

web/plotly-latest.min.js:
cd web; curl -O https://cdn.plot.ly/plotly-latest.min.js

web/jquery-1.12.2.min.js:
cd web; curl -O https://code.jquery.com/jquery-1.12.2.min.js

web/wtfgenes.js: web/client.js
browserify $< -o $@
webclient:
cd web; make

cpp-js-comparison:
cd test/data/yeast; make go-basic.obo gene_association.sgd
Expand Down
2 changes: 1 addition & 1 deletion test/mcmc.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ describe('MCMC', function() {
}

function testRelevantTerms(mcmc,move) {
assert.deepEqual (move.model.relevantTerms, [0,1,3,4,5,6,7,8])
assert.deepEqual (move.model.relevantTerms, [0,3,4,5,6,7,8])
}

describe('#randomize', function() {
Expand Down
28 changes: 13 additions & 15 deletions test/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ describe('Model', function() {

describe('#constructor', function() {
it('should identify relevant terms', function() {
assert.deepEqual (mutantModel.relevantTerms, [0,1,3,4,5,6,7,8])
assert.deepEqual (normalModel.relevantTerms, [0,1,2,3,4,7])
assert (normalModel.isRelevant[1])
assert.deepEqual (mutantModel.relevantTerms, [0,3,4,5,6,7,8])
assert.deepEqual (normalModel.relevantTerms, [0,2,3,4,7])
assert (normalModel.isRelevant[3])
assert (!normalModel.isRelevant[5])
})
it('should identify neighbors of relevant terms', function() {
assert.deepEqual (mutantModel.relevantNeighbors, [[5,7],[3,7],[0],[1,4,6],[3,5],[0,4,8],[3],[0,1],[5]])
assert.deepEqual (mutantModel.relevantNeighbors, [[5,7],[3,7],[0],[4,6],[3,5],[0,4,8],[3],[0],[5]])
})
it('should create default params', function() {
assert.deepEqual (mutantModel.paramSet.paramNames(), ['fn','fp','t'])
Expand All @@ -74,7 +74,7 @@ describe('Model', function() {
describe('#setTermState', function() {
it('should update termState & isActiveTerm', function() {
for (var t = 0; t < 9; ++t)
if (t != 2) {
if (t != 1 && t != 2) {
mutantModel.setTermState(t,1);
for (var s = 0; s < 9; ++s)
assert.equal (mutantModel.getTermState(s), s == t ? 1 : 0)
Expand All @@ -87,13 +87,11 @@ describe('Model', function() {
assert.deepEqual (mutantModel._termState, [0,0,0,0,0,0,0,0,0])
})
it('should update nActiveTermsByGene', function() {
mutantModel.setTermState(1,1);
mutantModel.setTermState(3,1);
mutantModel.setTermState(8,1);
assert.equal (mutantModel._nActiveTermsByGene[2], 2)
assert.equal (mutantModel._nActiveTermsByGene[2], 1)
assert.equal (mutantModel._nActiveTermsByGene[3], 0)
assert.equal (mutantModel._nActiveTermsByGene[4], 3)
mutantModel.setTermState(1,0);
assert.equal (mutantModel._nActiveTermsByGene[4], 2)
mutantModel.setTermState(3,0);
mutantModel.setTermState(8,0);
})
Expand All @@ -111,7 +109,7 @@ describe('Model', function() {
describe('#toJSON', function() {
it('should convert term state to JSON', function() {
for (var t = 0; t < 9; ++t)
if (t != 2) {
if (t != 1 && t != 2) {
mutantModel.setTermState(t,1);
assert.deepEqual (mutantModel.toJSON(), [onto.termName[t]])
mutantModel.setTermState(t,0);
Expand Down Expand Up @@ -156,12 +154,12 @@ describe('Model', function() {

describe('#getCounts', function() {
it('should return Bernoulli parameter counts', function() {
assert.deepEqual (mutCount.toJSON(), {succ:{fp:3},fail:{t:8,fp:2}})
assert.deepEqual (normCount.toJSON(), {succ:{fp:2},fail:{t:6,fp:3}})
assert.deepEqual (mutCount.toJSON(), {succ:{fp:3},fail:{t:7,fp:2}})
assert.deepEqual (normCount.toJSON(), {succ:{fp:2},fail:{t:5,fp:3}})

normalModel.setTermState (7, 1)
var newNormCount = normalModel.getCounts()
assert.deepEqual (newNormCount.toJSON(), {succ:{t:1,fn:3},fail:{t:5,fn:2}})
assert.deepEqual (newNormCount.toJSON(), {succ:{t:1,fn:3},fail:{t:4,fn:2}})
normalModel.setTermState (7, 0)
})
})
Expand All @@ -186,11 +184,11 @@ describe('Model', function() {
it('should correctly identify new false negatives', function() {
var m2 = new Model ({ assocs: assocs, geneSet: mutants, terms: ['arachnid','primate','gorilla'] })
var c2 = m2.getCounts()
assert.deepEqual (c2.toJSON(), {succ:{t:3,fn:2},fail:{t:5,fn:3}})
assert.deepEqual (c2.toJSON(), {succ:{t:3,fn:2},fail:{t:4,fn:3}})
var d2 = m2.getCountDelta({0:0})
assert.deepEqual (d2.toJSON(), {succ:{t:-1,fn:-1},fail:{t:1,fp:1}})
m2.setTermStates({0:0})
assert.deepEqual (m2.getCounts().toJSON(), {succ:{t:2,fn:1},fail:{t:6,fn:3,fp:1}})
assert.deepEqual (m2.getCounts().toJSON(), {succ:{t:2,fn:1},fail:{t:5,fn:3,fp:1}})
assert.deepEqual (c2.add(d2).toJSON(), m2.getCounts().toJSON())
})
})
Expand Down
11 changes: 11 additions & 0 deletions web/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

all: jquery-1.12.2.min.js plotly-latest.min.js wtfgenes.js

plotly-latest.min.js:
cd web; curl -O https://cdn.plot.ly/plotly-latest.min.js

jquery-1.12.2.min.js:
cd web; curl -O https://code.jquery.com/jquery-1.12.2.min.js

wtfgenes.js: client.js $(wildcard ../lib/*.js)
browserify client.js -o $@
68 changes: 42 additions & 26 deletions web/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,13 @@
var wtf = this
Plotly.plot( wtf.ui.logLikePlot[0], [{
y: wtf.mcmc.logLikelihoodTrace }],
{ title: "Convergence",
xaxis: { title: "Number of samples" },
yaxis: { title: "Log-likelihood" } } )
{ title: "MCMC convergence",
xaxis: { title: "Number of samples" },
yaxis: { title: "Log-likelihood" },
margin: 0,
width: 400,
height: 400 } )

setTimeout (redrawLogLikelihood.bind(wtf), 100)
}

Expand Down Expand Up @@ -167,7 +171,7 @@
resumeAnalysis.call(wtf)
wtf.ui.startButton.prop('disabled',false)

wtf.ui.interButton = $('<button>Track co-occurence</button>')
wtf.ui.interButton.show()
wtf.ui.interButton.click (function() {
wtf.ui.interButton.prop('disabled',true)
wtf.mcmc.logTermPairs()
Expand All @@ -180,9 +184,10 @@
wtf.ui.samplesPerTerm = $('<span>0</span>')
wtf.ui.samplesPerSec = $('<span>0</span>')
wtf.ui.mcmcStats = $('<span/>')
wtf.ui.mcmcStats.append (" ", wtf.ui.totalSamples, " samples (", wtf.ui.samplesPerTerm, " samples/term, ", wtf.ui.samplesPerSec, " samples/sec)")
wtf.ui.mcmcStats.append (wtf.ui.totalSamples, " samples<br/>", wtf.ui.samplesPerTerm, " samples/term<br/>", wtf.ui.samplesPerSec, " samples/sec")

wtf.ui.inputDiv.append (wtf.ui.interButton, wtf.ui.mcmcStats)
wtf.ui.statusDiv.append (wtf.ui.mcmcStats)
wtf.ui.statusDiv.show()

runMCMC.call(wtf)
plotLogLikelihood.call(wtf)
Expand Down Expand Up @@ -219,7 +224,7 @@
}

function log() {
this.ui.parentDiv.append ('<br/><i>' + Array.prototype.slice.call(arguments).join('') + '</i>')
this.ui.logDiv.append ('<br/><i>' + Array.prototype.slice.call(arguments).join('') + '</i>')
}

function WTFgenes (conf) {
Expand All @@ -235,10 +240,13 @@

// initialize UI
if (!wtf.ui.parentDiv) {
wtf.ui.parentDiv = $('<div id="wtf"/>')
wtf.ui.parentDiv = $('<div id="wtf" class="wtfparent"/>')
$("body").append (wtf.ui.parentDiv)
}

wtf.ui.logDiv = $('<div class="wtflog"/>')
wtf.ui.parentDiv.append (wtf.ui.logDiv)

// load data files, initialize ontology & associations
var ontologyReady = $.Deferred(),
assocsReady = $.Deferred()
Expand All @@ -254,7 +262,6 @@

// load associations
ontologyReady.done (function() {
wtf.log()
wtf.log ("Loading gene-term associations...")
$.get(wtf.assocsURL)
.done (function (assocsJson) {
Expand All @@ -274,26 +281,35 @@
enableExampleLink (wtf)
}

wtf.ui.geneSetTextArea = $('<textarea id="wtfgenes" rows="10" cols="80"/>')
wtf.ui.startButton = $('<button type="button">Start analysis</button>')
wtf.ui.geneSetTextArea = $('<textarea class="wtfgenesettextarea" rows="10"/>')
wtf.ui.startButton = $('<button type="button" class="wtfstartbutton">Start analysis</button>')
.on('click', startAnalysis.bind(wtf))

wtf.ui.inputDiv = $('<div/>')
wtf.ui.inputDiv.append ('<br/><br/>',
wtf.ui.helpText,
'<br/>',
wtf.ui.geneSetTextArea,
'<br/>',
wtf.ui.startButton)

wtf.ui.resultsDiv = $('<div/>')
wtf.ui.logLikePlot = $('<div/>')
wtf.ui.tableParent = $('<div/>')
wtf.ui.resultsDiv.append (wtf.ui.logLikePlot, wtf.ui.tableParent)
wtf.ui.interButton = $('<button>Track co-occurence</button>')
wtf.ui.interButton.hide()

wtf.ui.controlDiv = $('<div class="wtfcontrol"/>')
wtf.ui.statusDiv = $('<div class="wtfstatus"/>')
wtf.ui.statusDiv.hide()

wtf.ui.controlDiv.append (wtf.ui.helpText,
wtf.ui.geneSetTextArea,
wtf.ui.startButton,
wtf.ui.interButton)

wtf.ui.logLikePlot = $('<div class="wtfloglike"/>')
wtf.ui.tableParent = $('<div class="wtftermtable"/>')

wtf.ui.controlAndStatus = $('<div class="wtfcontrolstatus"/>')
wtf.ui.controlAndStatus.append (wtf.ui.controlDiv,
wtf.ui.statusDiv)

wtf.ui.controlAndPlot = $('<div class="wtfcontrolplot"/>')
wtf.ui.controlAndPlot.append (wtf.ui.controlAndStatus,
wtf.ui.logLikePlot)

wtf.ui.parentDiv.append (wtf.ui.inputDiv,
'<br/>',
wtf.ui.resultsDiv)
wtf.ui.parentDiv.append (wtf.ui.controlAndPlot,
wtf.ui.tableParent)

setInterval (setRedraw.bind(wtf), 500)
})
Expand Down
3 changes: 3 additions & 0 deletions web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

<!-- WTFgenes -->
<script type="text/javascript" src="wtfgenes.js"></script>
<link rel="stylesheet" type="text/css" href="wtfgenes.css"></script>
<script type="text/javascript">
$(function(){
var conf = { ontology: "../test/data/yeast/go-basic.json",
Expand All @@ -21,7 +22,9 @@

</head>
<body>
<div>
<h1>WTF genes?</h1>
<b>W</b>hat is <b>T</b>he <b>F</b>unction of these <b>genes</b>?
</div>
</body>
</html>
72 changes: 72 additions & 0 deletions web/wtfgenes.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
.wtfparent {
width: 800px;
float: left;
clear: both;
}

.wtflog {
clear: both;
background-color: #e0e0e0;
border-width: 1px;
border-style: solid;
border-radius: 3px;
padding: 10px;
}

.wtfstartbutton {
clear: left;
}

.wtfgenesettextarea {
clear: left;
width: 100%;
rows: 10;
}

.wtfcontrolstatus {
width: 40%;
float: left;
clear: left;
}

.wtfcontrol {
width: 100%;
height: 200px;
float: left;
clear: left;
background-color: #e0e0e0;
margin: 10px 10px 10px 0px;
padding: 10px;
border-width: 1px;
border-style: solid;
border-radius: 3px;
}

.wtfstatus {
width: 100%;
clear: both;
background-color: #e0e0e0;
margin: 10px 10px 10px 0px;
padding: 10px;
border-width: 1px;
border-style: solid;
border-radius: 3px;
}

.wtfloglike {
float: right;
clear: right;
margin: 10px 0px 10px 10px;
border-width: 1px;
border-style: solid;
border-radius: 3px;
}

.wtftermtable {
float: left;
clear: both;
}

.wtfcontrolplot {
clear: both;
}

0 comments on commit 726505f

Please sign in to comment.