Skip to content

Instantly share code, notes, and snippets.

@ngopal
ngopal / cypher_query
Created February 22, 2014 23:23
a simple cypher query to find all of the shortest paths in the neo4j shell
START source=node(10), destination=node(144)
MATCH p = allShortestPaths(source-[r:interacts*..3]->destination)
RETURN NODES(p);
@ngopal
ngopal / consensuspathdb_to_neo4j.py
Last active August 29, 2015 13:56
a quick python script to take consensuspathdb data and throw it into a running neo4j instance
# This program takes the PPI data from ConsensusDB and populates the NEO4J database with it
# By Nikhil Gopal
#
# To run: python populate_running_db.py ConsensusDB_Human_PPI nodes_list.txt
# The code to generate the nodes_list.txt file exists here: https://gist.github.com/ngopal/9164294
import os, sys
from neo4jrestclient.client import GraphDatabase
from itertools import chain, combinations
brew install neo4j
@ngopal
ngopal / neo4j_start_stop
Created February 22, 2014 23:39
how to start and stop neo4j
# To start server
neo4j start
# To stop server
neo4j stop
@ngopal
ngopal / make_node_list.py
Created February 22, 2014 23:52
make a list of nodes from human PPI data
import os, sys
from itertools import chain, combinations
genes_set = set([])
for i in open(sys.argv[1], 'r').readlines():
if '#' in i:
continue
else:
line = i.strip('\r\n').split('\t')
genes = line[2].replace('_HUMAN','').split(',')
@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);