{{ message }}

Instantly share code, notes, and snippets.

# Kevin Gorikgori

Last active Jul 12, 2019
bcftools make consensus with insertion
View Makefile
 # Replace these with the full path to the executables, if necessary BWA=bwa SAMTOOLS=samtools BCFTOOLS=bcftools # Makefile targets all: ref.fa reads.fq aln.bam aln.bam.bai pileup.vcf filtered_calls.bcf consensus.fa .PHONY: all simulation: ref.fa reads.fq
Created Nov 27, 2018
Convert regression line coefficient and intercept of standardised variables back to the original scale
View standardised_variables.R
 # Standardisation formula z <- function(x) (x - mean(x)) / sd(x) #' Convert regression parameters obtained from standardised variables #' back to the scale of the original data. #' #' For a regression y ~ x*, where x* denotes the standardised form of x: #' Result: y = m(x*) + c #' Transformed: y = (m / sd(x))(x) + (c - (m*mean(x)/sd(x)) #'
Created Apr 6, 2018
DNA reverse complement
View revcomp.py
 def revcomp(s): complements = dict( A='T', C='G', G='C', T='A', M='K', R='Y', W='W', S='S', Y='R', K='M', V='B', H='D', D='H', B='V', N='N' ) return ''.join(complements[char] for char in s.upper()[::-1])
Created Nov 17, 2017
Simple progress bar
View progress.py
 import sys class Progress(): def __init__(self, capacity, label = '', width=80, fill='#', blank=' '): self.capacity = capacity self.label = label self.width = width self.fill = fill self.blank = blank self.completed = 0
Last active Mar 23, 2018
Estimate insert size distribution of proper pairs in bam file
View insert_size.py
Last active Jan 23, 2017
PYMC3 model code to do signature fitting using NUTS
View sigfit_pymc3.py
 """ PYMC3 model code to do signature fitting using NUTS """ import pymc3 from theano import tensor mytest = pymc3.Model() counts = data with mytest: mixing_proportions = pymc3.Dirichlet('mixing_proportions', a = np.ones(30), shape = 30)
Last active Oct 11, 2020
How to discretize a gamma or lognormal distribution, for modelling rates over sites in a phylogenetic model
View discretize.py
 import scipy import scipy.stats as ss import numpy as np def discretize(alpha, ncat, dist=ss.gamma): if dist == ss.gamma: dist = dist(alpha, scale=1 / alpha) elif dist == ss.lognorm: dist = dist(s=alpha, scale=np.exp(0.5 * alpha**2)) quantiles = dist.ppf(np.arange(0, ncat) / ncat)
Last active Sep 24, 2015