Skip to content

Instantly share code, notes, and snippets.

View CnrLwlss's full-sized avatar

Conor Lawless CnrLwlss

View GitHub Profile
@CnrLwlss
CnrLwlss / AnalyzeTimecourse.py
Last active December 14, 2015 23:29
A quick demo, analyzing a batch of files with Colonyzer2. See this page for more info: http://research.ncl.ac.uk/colonyzer/
from colonyzer2 import *
import time, sys
def main(fmt="384"):
# Lydall lab file naming convention
# First 15 characters in filename identify unique plates
# Remaining charaters can be used to store date, time etc.
barcRange=(0,15)
if len(sys.argv)>1:
fmt=sys.argv[1]
@CnrLwlss
CnrLwlss / CellCounter.py
Created April 7, 2013 11:45
Electronic clicker for manual counting of three cell types (G1, G2/M and S). While looking down the eyepiece of a microscope at cells on a glass slide, the user can press "g" to increment the number of cells in G1, "h" to increment the number of cells in G2/M and "j" to increment the number of cells in S. Press space bar to move from one slide t…
import winsound, time, Tkinter
slides=[]
cells=[0,0,0]
labels=["G1","S","G2/M"]
print "Slide: %02d"%(len(slides)+1)
def key(event):
if event.char=="g":
cells[0]+=1
@CnrLwlss
CnrLwlss / Resize.py
Last active December 15, 2015 22:00
Find all images in the current directory and generate resized versions, together with a single preview file displaying all patched versions pasted together.
import PIL, os, math
from PIL import Image
resizeWidth=500
allfiles=os.listdir(os.getcwd())
filelist=[f for f in allfiles if f[-4:] in ['.jpg','.JPG','.jpeg','.JPEG','.png','.PNG']]
Nimages=len(filelist)
im0=Image.open(filelist[0])
w,h=im0.size
@CnrLwlss
CnrLwlss / align.sh
Last active December 19, 2015 02:39
Aligning yeast sequences to a reference genome.
#!/bin/bash
echo Making indices...
# Set up path to include bowtie2 and samtools
export PATH=$PATH:/home/username/bowtie2-2.1.0:/home/username/samtools:/home/username/samtools/bcftools:/home/username/samtools/misc
# Generate an index file from the reference genome
bowtie2-build reference_SGD/S288C_reference_genome_R64-1-1_20110203/S288C_reference_sequence_R64-1-1_20110203.fsa indices/SGD_S288C
roots=(
@echo off
:: Make indices
bowtie2-build reference_SGD/S288C_reference_genome_R64-1-1_20110203/S288C_reference_sequence_R64-1-1_20110203.fsa indices/SGD_S288C
for /f "tokens=*" %%x in (roots.txt) do (
echo %%x
:: Align reads
bowtie2-align -x indices/SGD_S288C -1 data/%%x_1_sequence.fq -2 data/%%x_2_sequence.fq -S alignments/%%x.sam -p 12 --end-to-end
)
@CnrLwlss
CnrLwlss / Coverage.R
Last active December 19, 2015 04:09
library(ShortRead)
# Root of .bam filename
sname="HG00100.unmapped.ILLUMINA.bwa.GBR.low_coverage.20130415"
# Construct path to file
fname=file.path("alignments",paste(sname,".bam",sep=""))
# Read alignments
bm=readGappedAlignments(fname)
#!/bin/bash
echo Generating consensus sequences
export PATH=$PATH:/home/username/bowtie2-2.1.0:/home/username/samtools:/home/username/samtools/bcftools:/home/username/samtools/misc
roots=(
SN7640178_10172_8183
SN7640178_10173_8265
SN7640178_10174_8266
@CnrLwlss
CnrLwlss / mtDNA.R
Last active December 19, 2015 06:19
Generating a circular plot of sequencing coverage along the mitochondrial genome, annotating gene locations.
#source("http://bioconductor.org/biocLite.R")
#biocLite("ecolitk")
#biocLite("ShortRead")
library(ecolitk)
library(plotrix)
library(ShortRead)
# Read in some alignments
getReads=function(fname,rad=1.5,readmax=29000,logb=10){
bm=readGappedAlignments(fname)
@CnrLwlss
CnrLwlss / CheckGenes.py
Last active December 19, 2015 09:39
Example script demonstrating the use of BioPython to compare genomic sequences at a given gene location. See http://cnr.lwlss.net/seqConsensus
# http://cnr.lwlss.net/seqConsensus
import os
from Bio import SeqIO
def checkMutations(ref_dict, roots, genedict,showSeq=False):
'''Comparing a reference sequence (ref_dict) with a series of sample sequences.'''
# Sample sequences are read in from .fastq files in a "pileups" directory.
# Filenames are constructed from a list of roots (e.g. filenames without extensions).
# A Python dictionary specifying genes to analyze connects gene labels (e.g. "HIS3") with a tuple of chromosome number, start position and stop position (e.g. (15,721946,722608)).
@CnrLwlss
CnrLwlss / ChemReactionNet.R
Created November 30, 2013 16:00
Describing and simulating the ODEs representing a chemical network, and plotting the simulated output.
# Install and load ODE solver package
install.packages("deSolve")
library(deSolve)
# Named vector of parameter values
parameters=c(k1=0.15,k2=0.075,V=1.0)
# Named vector of initial conditions
state=c(A=4,B=2,AB=0)