Skip to content

Instantly share code, notes, and snippets.

Conor Lawless CnrLwlss

Block or report user

Report or block CnrLwlss

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@CnrLwlss
CnrLwlss / SteveRuns.R
Created Jul 11, 2017
Adventures in plotting running data with R.
View SteveRuns.R
distance=seq(0.2,4,0.2)
pace=rep(9,length(distance))
op=par(mfrow=c(2,2))
plot(distance,pace,type="b",main="Sensible")
plot(distance,pace/distance,type="b",main="A bit odd")
plot(distance,pace/(distance^2),type="b",main="WTF?!")
par(op)
@CnrLwlss
CnrLwlss / Focus.py
Created Apr 14, 2017
Image analysis script for finding and visualising the areas of an image that are in focus.
View Focus.py
from PIL import Image
from scipy import ndimage
import numpy as np
def getVar(im, sigma = 4.0):
'''Identifies & highlights areas of image fname with high pixel intensity variance (focus)'''
imbw = im.convert("F") # Convert im to greyscale array
arrbw = np.array(imbw)
sub_mean = ndimage.gaussian_filter(arrbw, sigma) # Calculate variance in area around each pixel
@CnrLwlss
CnrLwlss / RectangularArray.R
Created Nov 30, 2016
Get best size for graphics array (array dimension that is most perfectly filled by correlation plots) when plotting possible pairwise combinations of variables against each other.
View RectangularArray.R
fdefpairs=t(combn(fdefs,2))
npairs=dim(fdefpairs)[1]
a=round(sqrt(npairs))
if((a+1)*(a+1)>=npairs) mfrow=c(a+1,a+1)
if((a+1)*a>=npairs) mfrow=c(a,a+1)
if(a*a>=npairs) mfrow=c(a,a)
@CnrLwlss
CnrLwlss / CustomErrorBars.py
Last active Nov 12, 2018
Script for plotting stripplot or swarmplot with barplot overlay, including custom error bars, with matplotlib/Seaborn.
View CustomErrorBars.py
import seaborn as sns
tips = sns.load_dataset("tips")
print(sns.__version__)
print(tips.head())
ax=sns.swarmplot(x="day", y="total_bill", hue="sex", data=tips,split=True)
sns.barplot(x="day", y="total_bill", hue="sex", data=tips,capsize=0.1,errwidth=1.25,alpha=0.25,ci=None)
xcentres=[0,1,2,3]
delt=0.2
xneg=[x-delt for x in xcentres]
@CnrLwlss
CnrLwlss / Limited_logistic_mixture.R
Created Oct 22, 2016
Simulating growth of a nutrient-limited population consisting of a mixture of two lineages with different growth rates (but sharing resources, i.e. co-localised).
View Limited_logistic_mixture.R
# Install and load ODE solver package
#install.packages("deSolve")
library(deSolve)
# Named vector of parameter values
parameters=c(r_1=1.0,r_2=1.1,K=1)
# Named vector of initial conditions
state=c(x_1=0.01,x_2=0.01)
@CnrLwlss
CnrLwlss / miniQFA.JAGS
Created Oct 13, 2016
Bayesian hierarchical model, written in JAGS, representing relationship between spots on a QFA plate. Constrained, uniform priors all the way through hierarchy.
View miniQFA.JAGS
model {
tau_min <- 10000
tau_max <- 1000000
x0_min <- 0.0
x0_max <- 0.05
r_min <- 0.0
r_max <- 10.0
K_min <- 0.0
K_max <- 0.5
View ColourContrast.R
# Visual comparison of the contrast between colours and different solid backgrounds
colourGrid=function(dimval=20,background="gray",colourfun=rainbow,ptsize=1){
cols=colourfun(dimval^2)
yvals=rep(seq(0,1,length.out=dimval),each=dimval)
xvals=rep(seq(0,1,length.out=dimval),dimval)
plot(xvals,yvals,type="n",xaxt="n",yaxt="n",ann=FALSE, bty="n")
rect(par("usr")[1],par("usr")[3],par("usr")[2],par("usr")[4],col = background,border=NA)
points(xvals,yvals,col=cols,pch=16,cex=ptsize)
}
@CnrLwlss
CnrLwlss / RankPlots.py
Created Jul 7, 2016
Visualising changes in rank order. For example, can think of changes in rank order of phenotypes in genetic screen with experiment or with type of analysis.
View RankPlots.py
# Plot comparing ranks
import string
import random
import matplotlib.pyplot as plt
from matplotlib import cm
import numpy as np
def experiment(genes,vmin=0.0,vmax=1.0):
'''Simulate an experiment with (average) measurement for a set of genotypes'''
@CnrLwlss
CnrLwlss / plotDemo.py
Created Mar 4, 2016
Preparing differently sized plot panels, labelled with proper genetics nomenclature, using matplotlib.
View plotDemo.py
import matplotlib as mp
import matplotlib.pyplot as plt
import numpy as np
import string
# Set font for figure according to journal specs
mp.rcParams['font.family'] = "Arial"
# Gene deletion names read from file might not necessarily be in lower case
gnames=["EXO1","RAD9","TMA20"]
@CnrLwlss
CnrLwlss / Colormap.py
Last active Feb 18, 2016
Continuous colour map in python with matplotlib. Requires matplotlib 1.5?
View Colormap.py
#http://matplotlib.org/examples/color/colormaps_reference.html
#http://matplotlib.org/users/colormaps.html
import matplotlib.pyplot as plt
from matplotlib import cm
import numpy as np
N = 200
x = np.random.randn(N)
y = np.random.randn(N)
You can’t perform that action at this time.