Skip to content

Instantly share code, notes, and snippets.

@ngopal
ngopal / data3.tsv
Created March 29, 2014 22:32
Visualization of a specialized "look and say" sequence
Xco Yco
0 1
3 1
1 1
1 0
1 1
4 1
2 1
2 0
2 3
margin = {top: 20, right: 20, bottom: 30, left: 50}
width = 960 - margin.left - margin.right
height = 500 - margin.top - margin.bottom
parseDate = d3.time.format("%Y-%m-%d").parse
x = d3.time.scale().range([0, width])
@ngopal
ngopal / hypergeometric_probability.js
Created June 30, 2014 05:19
A set of functions to calculate the probability of intersection between sets being a chance event in a hypergeometric distribution
function GetBinCoeff(N, K) {
// http://stackoverflow.com/questions/14556266/how-to-calculate-combination-of-large-numbers
if ( K > N) {
return 0;
}
else {
var r = 1;
var d;
for (d = 1; d <= K; d++)
{
@ngopal
ngopal / ConfusionMatrix.js
Last active August 29, 2015 14:03
A small javascript library to create a confusion matrix and calculate values of true positives, true negatives, false positives, false negatives, sensitivity, specificity, positive predictive value, negative predictive value, positive likelihood, negative likelihood, prevalence, false positive rate, false discovery rate, false negative rate, Mat…
// Written by Nikhil Gopal
// http://www.nikhilgopal.com
function TwoCellCalculation(k,j) {
return(k/(k+j));
}
function ConfusionMatrix(a,b,c,d) {
this.n = a+b+c+d;
this.true_positives = a;
@ngopal
ngopal / parsejson.js
Last active August 29, 2015 14:04
A list of different ways to parse json in javascript. Currently unfinished
// To parse CSV, TSV, etc
// https://code.google.com/p/jquery-csv/ --> Library to parse CSV
// otherwise use ajax call with dataType set to text
// If the JSON file is in string form
// http://stackoverflow.com/questions/4935632/how-to-parse-json-in-javascript
var json = '{"result":true,"count":1}';
var obj = JSON.parse(json);
console.log(obj.count);
@ngopal
ngopal / alzheimerR.json
Created July 30, 2014 16:55
Visualizing Alzheimer's Disease Using Reactome Data in D3
{
"sbml": {
"-xmlns": "http://www.sbml.org/sbml/level2/version4",
"-level": "2",
"-version": "4",
"model": {
"-id": "pathway_977225",
"-name": "Amyloids",
"-metaid": "metaid_0",
"notes": {
@ngopal
ngopal / graph.js
Last active August 29, 2015 14:04
Extremely simple implementation of a network graph library
function node(inid,inname) {
return {
id : inid,
name : inname
};
}
function edge(node1,node2) {
return {
source : node1,
@ngopal
ngopal / networkGenerators.js
Created September 9, 2014 00:47
A JS implementation of creating a Erdos-Renyi (random) network. Planning to add others.
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function erdosRenyi(nodesNum,directedness,prob) {
// create nodes list
var nodes = []
for (var i = 0; i < nodesNum; i++) {
nodes.push(i);
@ngopal
ngopal / heatmapthingy.R
Last active August 29, 2015 14:09
Applying A Divergent Color Scale to A Gene Expression Heat Map
# Blog Post is here: http://www.nikhilgopal.com/applying-a-divergent-color-scale-to-a-gene-expression-heat-map/
source("http://bioconductor.org/biocLite.R")
biocLite("ALL")
biocLite("limma")
library("ALL")
library("limma")
data("ALL")
eset <- ALL[, ALL$mol.biol %in% c("BCR/ABL", "ALL1/AF4")]
@ngopal
ngopal / index.html
Created December 1, 2014 05:41
Degree Centrality based force-layout // source http://jsbin.com/fijefe
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="Degree Centrality based force-layout" />
<script src="http://code.jquery.com/jquery-2.1.0.min.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://jsbin.com/xiyehe/1.js"></script>