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 / usingSpeedTest.R
Created Nov 13, 2019
Generate broadband speed test reports
View usingSpeedTest.R
#https://github.com/hrbrmstr/speedtest
library(speedtest)
fname = "speedtest_results2.txt"
makeplots = FALSE
if(!makeplots){
config = spd_config()
servers = spd_servers(config = config)
servers = spd_closest_servers(servers, config)
best = spd_best_servers(servers, config, max = 3)
@CnrLwlss
CnrLwlss / estimate_mu.R
Last active Nov 13, 2019
How many replicate samples do we need to estimate the mean of a distribution? 2-panel plot, random output.
View estimate_mu.R
mu = 5
stdev = 2
N = 10000
data = rnorm(N,mu,stdev)
pdf = function(x) dnorm(x,mu,stdev)
bestmu = function(N,x) sum(x[1:N])/N
op=par(mfrow=c(1,2))
@CnrLwlss
CnrLwlss / ColourContrast.R
Last active Nov 12, 2019
Checking colour contrasts
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 / StripchartOpacity.R
Last active Jun 14, 2019
R script demonstrating a few things: 1) drawing boxplots with notches roughly indicating significance of differences 2) stripcharts using transparency to highlight values of high density 3) overlaying boxplot on stripcharts and 4) writing plots as multi-page .pdf reports
View StripchartOpacity.R
# Info about boxplot notches https://sites.google.com/site/davidsstatistics/home/notched-box-plots
# Article about why not to use barplots https://doi.org/10.1371/journal.pbio.1002128
# Article about being wary of summary statistics and why raw data plots are better than boxplots https://www.autodeskresearch.com/publications/samestats
# Generate some fake data
concs = seq(0,10,1)
concobs = rep(concs,each=500)
mdel = function(x) -x^2+10*x+20
vals = mdel(concobs) + rnorm(length(concobs),0,12)
dat = data.frame(conc=concobs,val=vals)
@CnrLwlss
CnrLwlss / mtDNASpecies.R
Created Mar 14, 2019
Testing whether small deletions are under-represented within fibres containing multiple deletion species
View mtDNASpecies.R
# Testing whether small deletions are under-represented within fibres containing multiple deletion species
# Assume 200 mtDNA molecules per fibre section
Nassume = 200
# P7, P15 and P16 are the proportions of smaller mtDNA species in fibres with two or more mtDNA species
P7 = c(0.6,0.2,0.49,0.33,0.57,0.75,0.47,0.29,0.27,0.23,0.51,0.54)
N7 = rep(Nassume,length(P7))
Ndel7 = c(2,2,3,2,2,2,2,3,2,2,2,2)
P15 = c(0.39,0.73,0.37,0.17,0.43,0.53,0.54,0.57)
View EM_mito.R
#install.packages(c("mixOmics","RVAideMemoire"))
library(mixOmics)
library(RVAideMemoire)
# Calculate whether measure is greater in control group after scaling
# Used to colour points in VIP plots
direction=function(dt,measure){
dts = as.data.frame(scale(dt[,-1]))
dts$Group = dt$Group
res = median(dts[[measure]][dts$Group=="Control"],na.rm=TRUE) > median(dts[[measure]][dts$Group!="Control"],na.rm=TRUE)
@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 / mutationLoadMeasures.R
Last active Sep 19, 2018
Comparing measures of mtDNA mutation load in single cells.
View mutationLoadMeasures.R
library(grDevices)
library(gtools)
dat = read.delim("data/RTdata.txt",sep="\t",stringsAsFactors=FALSE)
dat$PNUM = as.numeric(gsub("P","",dat$Patient))
dat$ID = sprintf("P%02d_%04d",dat$PNUM,dat$Cell.number)
dat$PAT = sprintf("P%02d",dat$PNUM)
colfunc = colorRamp(c("blue","yellow","red"),space="Lab")
colfun = function(x, alpha=1.0) {
@CnrLwlss
CnrLwlss / explore_mitocyto.R
Created May 25, 2018
Generating some exploratory plots of mitocyto data.
View explore_mitocyto.R
# Read data and rename columns
dat = read.delim("mitocyto_merged_results.csv",sep=",",stringsAsFactors=FALSE)
colnames(dat) = c("value","id","channel","patient_id","patient_type")
# Specify which ids correspond to patients, and which to control
dat$patient_type = ifelse(dat$patient_id=="M1105","patient","control")
dat$patient_id = paste(toupper(substr(dat$patient_type,1,1)),dat$patient_id,sep="_")
# Specify some colours for plotting
dat$colour = "black"
@CnrLwlss
CnrLwlss / circleObjective.py
Created Jan 19, 2013
Functions for packing N circles into a rectangle of width W and height H, together with a function for plotting solution and some example code fitting 13 circles into a square. http://cnr.lwlss.net/CircleObjectivesPython/ #python #opimisation #circle #packing #svg #function #closure
View circleObjective.py
import random, numpy
def genGuess(N,W,H):
'''Generate sensible initial guess vector (random circle coordinates and radii)'''
z=numpy.zeros(3*N)
for i in xrange(0,N):
z[i*3]=random.random()*W
z[i*3+1]=random.random()*H
z[i*3+2]=0.001*min(W,H)+random.random()*(0.009*min(W,H))
return(z)
You can’t perform that action at this time.