Skip to content

Instantly share code, notes, and snippets.

View kmader's full-sized avatar

Kevin Mader kmader

  • Zurich, Switzerland
View GitHub Profile
@kmader
kmader / A analysis.ijm
Last active August 29, 2015 13:59
Load Stack of Images and Perform Analysis on Each Slice
// Load the data in
imageStackDirectory=getDirectory("Select the folder where the images should loaded from");
run("Image Sequence...", "open="+imageStackDirectory+" sort");
run("Set Measurements...", "area mean min centroid center perimeter bounding fit shape redirect=None decimal=3");
// Apply a threshold
setThreshold(129, 255);
setOption("BlackBackground", false);
run("Convert to Mask", "method=Default background=Dark black");
imgDirectory=getInfo("image.directory");
@kmader
kmader / ellipsoid_analysis.m
Last active August 29, 2015 14:00 — forked from kmader/Matlab Shape Analysis Function
A full shape analysis for 3D images segmented in matlab in the format used by bwlabeln or watershed
% this function (will) performs the ellipsoid based shape analysis on a 3D image
% the input is a labeled image probably from the bwlabel function
% the output is an array formatted like such
% labelId, volume, centerX, centerY, centerZ, extentsX, extentsY, extentsZ, pca1X, pca1Y, pca1Z, score1, score2, score3
function [out_table]=ellipsoid_analysis(in_image,out_file)
% create an array the same size as the image of x,y, and z points. This way we can calculate
% center of volume and other parameters by using multiplication
[xgrid,ygrid,zgrid]=meshgrid(1:size(in_image,1),1:size(in_image,2),1:size(in_image,3));
num_of_obj=max(in_image(:));
@kmader
kmader / mandelbrot.condor
Created May 7, 2014 08:49
Basic Condor Script for Running a Mandelbrot, stolen from https://computing.ee.ethz.ch/Services/Condor
##################################################################
##
## Mandelbrot pictures with MATLAB and Condor
## Filename: mandelbrot.condor
##
##################################################################
#
# For this example, variables not used by Condor are marked my_*
#
@kmader
kmader / batchimage.condor
Last active August 29, 2015 14:01 — forked from kmader/mandelbrot.condor
A condor script for filtering and thresholding a given image using a number of different parameters
##################################################################
##
## Run a parameter sweep with threshold and filter using condor
## Filename: batchimage.condor
##
##################################################################
universe = vanilla
getenv = True # MATLAB needs local environment
@kmader
kmader / A ImageJ Analysis.ijm
Last active August 29, 2015 14:01 — forked from kmader/A analysis.ijm
Code for Birkedal to do slice by slice analysis
// taken from https://gist.github.com/kmader/10871528
// Load the data in
imageStackDirectory=getDirectory("Select the folder where the images should loaded from");
run("Image Sequence...", "open="+imageStackDirectory+" sort use");
// crop the image
makeRectangle(1089, 993, 675, 702);
run("Crop");
// clear the meaningless pixel sizes and set them to 0
run("Properties...", "unit=pixel pixel_width=1 pixel_height=1 voxel_depth=1 global");
// set which metrics to record for each analysis
@kmader
kmader / randnetwork.R
Created June 18, 2014 09:45
Random Network, creates a nice random directed network in R, useful for showing systems are complicated
library(igraph)
library(plyr)
node.names<-c("Gene 104","Gene 105", "Gene 106","Cellular Structure","Cellular Viability","Turnover Rate","Mechanosensitivity","AB Signaling","BC Signaling","Temperature","pH","Mixing Rate","Cooling Rate","Catalysts")
c.mat<-matrix(0,length(node.names),length(node.names))
colnames(c.mat)<-node.names
rownames(c.mat)<-node.names
rr<-function(x=length(node.names),n=1) round(runif(n,min=0,max=x)+.5)
edge.count<-round(3*length(node.names))
for(i in c(1:edge.count)) {
rpos<-rr(n=2)
@kmader
kmader / relationshipplot.R
Last active August 29, 2015 14:02
A plot of a simple relationship between control variables and measurable outputs
library(ggplot2)
library(reshape2)
parm.table<-expand.grid(Temperature=seq(20,80,length.out=20),Gene=c(1,2,3),pH=seq(3,6,length.out=10))
rf<-function(amplitude=0.1) runif(nrow(parm.table),min=1/(1+amplitude),max=1+amplitude)
parm.table$Thickness<-with(parm.table,10^(pH+as.numeric(Gene))-10*Temperature)*rf(.1)
parm.table$Count<-with(parm.table,10^(as.numeric(Gene))+100*Temperature)*rf(0.01)
parm.table$Connections<-with(parm.table,2^(as.numeric(Gene))-5*as.numeric(Gene)+12)*rf(0.2)
parm.table$GrowthRate<-with(parm.table,log(Thickness/Count)*Gene)*rf(0.2)
parm.table$Strength<-with(parm.table,Count/Connections)*rf(0.1)
parm.table$Viability<-with(parm.table,10^(10-Connections))*rf(0.2)
@kmader
kmader / A-touch.py
Last active August 29, 2015 14:04
A script for users who do not reconstruct all their samples correctly (the first touches files so they are not automatically deleted, the second reconstructs them all with the same parameters and automatic centering
"""
Touches all files in the image folder based on a list of sample names to keep (prevent from being autodeleted
"""
start_dir='/sls/X02DA/data/e14570/Data10/'
from subprocess import call,Popen,PIPE
import os
fancyExec=lambda cmd: Popen(cmd.split(' '), stdin=PIPE, stdout=PIPE, stderr=PIPE).communicate()[0].split('\n')
clean_line = lambda lines: dict(filter(lambda cline: len(cline[0])>0,map(lambda cline: (cline.upper().strip(),cline.strip()),lines)))
keeplines = clean_line(open('keepfiles.txt').readlines()).keys()
@kmader
kmader / correctTypeMacro.scala
Last active August 29, 2015 14:04
An easy macro for selecting a type of an object (asInstanceOf) by using an integer parameter (0 -> Boolean, 1->Double, etc)
import scala.language.experimental.macros
import scala.reflect.macros.Context
object correctlyTypeObj {
def apply(objToType: Any, imageType: Int): Any = macro correctlyTypeObjImpl
def correctlyTypeObjImpl(c: Context)(objToType: c.Expr[Any] ,imageType: c.Expr[Int]): c.Expr[Any] = {
import c.universe._
imageType.tree match {
case Literal(Constant(0)) => reify{objToType.splice.asInstanceOf[Boolean]}
case Literal(Constant(1)) => reify{objToType.splice.asInstanceOf[Double]}
case _ => reify{null}
@kmader
kmader / matrixAssembly.scala
Last active August 29, 2015 14:04
Code to break apart and reassemble a matrix in scala using list operations (spark)
import breeze.linalg._
val testMat = DenseMatrix.rand(10,5)
val splitMat = for(r<-0 until testMat.cols) yield (r,testMat(::,r))
// recombine in a single thread
val startMat = DenseMatrix.zeros[Double](10,5)
val fixMat = splitMat.foldLeft(startMat)(
(oldMat,newLine) => {oldMat(::,newLine._1) := newLine._2
oldMat})
// recombine in an rdd