Skip to content

Instantly share code, notes, and snippets.

View disa-mhembere's full-sized avatar

Disa Mhembere disa-mhembere

View GitHub Profile
@disa-mhembere
disa-mhembere / __init__.py
Created July 6, 2012 18:02
Example __init__.py
# See http://docs.python.org/tutorial/modules.html#packages
import os
import pyximport;
pyximport.install()
os.sys.path.extend([os.path.abspath('./PyGraphStat/code/'),
os.path.abspath('./MR-connectome/mrcap/')])
def embed_graph(ccfn, roiRootName, fgfn, embedfn, dim=10):
"""
ccfn - connected components file with numpy arrray
roiRootName - roi files root name
fgfn - mat file with the fibergraph
embedfn - full file name of output file to be saved
dim - desired dimension for the embedding
"""
vcc = lcc.ConnectedComponent(fn =ccfn)
@disa-mhembere
disa-mhembere / xyzToZ.py
Created October 30, 2012 20:24
XYZ to Z Morton
# Dependencies cython
# zindex.pyx - https://github.com/openconnectome/MR-connectome/blob/master/mrcap/zindex.pyx
# setup.py - https://github.com/openconnectome/MR-connectome/blob/master/mrcap/setup.py
# Build zindex & install it first - from terminal: sudo python setup.py install
import zindex
def xyzToz(xyz): # xyz is a tuple [x,y,z]
return XYZMorton() # returns z-index as int
@disa-mhembere
disa-mhembere / tri_test.py
Created September 8, 2013 02:50
Test max num of triangles in complete graph.
import networkx as nx
from math import factorial as fact
import sys
def test_tri_count(num_nodes):
g = nx.complete_graph(num_nodes)
tri = nx.triangles(g)
num_tri = sum(tri.values())/3 # Div by 3 because of triple counting
comb = int(fact(num_nodes)/(fact(3)*fact(num_nodes-3)))
@disa-mhembere
disa-mhembere / c3.R
Last active December 27, 2015 09:39
Building out of mem c^3
require(Matrix)
require(igraph)
require(gtools)
args <- commandArgs(trailingOnly = TRUE)
n <- 10^6
m <- 10^2
(KA <- n/m)
rho <- c(0.02,0.5,0.15,0.08,0.25)
require(Matrix)
require(igraph)
createc3 <- function()
{
set.seed(12345)
n <- 10^6
m <- 10^2
(KA <- n/m)
rho <- c(0.02,0.5,0.15,0.08,0.25)
@disa-mhembere
disa-mhembere / create_graph.py
Created November 21, 2013 21:38
create your own ER graph using networkx
import networkx as nx
import numpy as np
p = 0.3 # Alter as necessary
n = 1000 # Alter as necessary
fn = "graph%d"%n # Alter as necessary
g = nx.erdos_renyi_graph(n, p,False)
gsp = nx.to_scipy_sparse_matrix(g)
@disa-mhembere
disa-mhembere / get_eigs.R
Last active December 29, 2015 06:29
Compute top eigs
require(Matrix)
require(igraph)
require(argparse)
parser <- ArgumentParser(description="Process some integers")
parser$add_argument("gfn", help="The graph file name")
parser$add_argument("nev", type="integer", help="Number of eigenvectors to compute")
parser$add_argument("ncv", type="integer",help="Number of Lanczos vectors to compute")
parser$add_argument("maxiter", type="integer",help="Max number of iterations to compute eigenvectors")
@disa-mhembere
disa-mhembere / makefly.R
Created March 8, 2014 22:02
Make fly graph
require(igraph)
dat <- read.table("./fly.csv", header=TRUE, sep=",")
dat <- dat[c("presynaptic", "postsynaptic" , "pre.x", "post.x", "pre.y", "post.y", "pre.z", "post.z","proofreading.details")]
g <- graph.data.frame(dat, directed=TRUE)
g <- set.graph.attribute(g, "source", value="http://www.nature.com/nature/journal/v500/n7461/full/nature12450.html")
g <- set.graph.attribute(g, "info", value="source=presynaptic, targe=postsynaptic")
write.graph(g, "drosophila_retina.graphml", format="graphml")
@disa-mhembere
disa-mhembere / get.clusters.R
Created March 24, 2014 16:22
Get components in a graph
require(igraph)
g <- read.graph("./web-Google.txt") # Change fn
cl <- clusters(g, "strong") # "weak"
unique.clusters <- unique(cl$csize)
for (i in 1: length(unique.clusters) ) {
cat(unique.clusters[i], length(which(cl$csize == unique.clusters[i])),"\n")
}