Skip to content

Instantly share code, notes, and snippets.

View brentp's full-sized avatar

Brent Pedersen brentp

View GitHub Profile
{
"metadata": {
"name": "pandas"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
@brentp
brentp / assotest.py
Last active January 12, 2017 12:16
c-alpha test in python. copied from AssotesteR. and rpy2 wrapper for all functions in AssotesteR
"""
C-alpha test for rare variants. Copied from AssotesteR
Only reports the permutation p-value, not the asymptotic
This also wraps all of the functions in R's AssotesteR using
rpy2. Any function available in AssotesteR, e.g. CALPHA is
availailable here has r_calpha().
The args are always
casecon: a list of 0's, 1's indicating case/control status
library(survey)
args = commandArgs(TRUE)
fclin = args[1]
fmeth = args[2]
clin = read.table(fclin, header=T, sep="\t")
clin$Barcode = as.character(clin$Unique.ID)
clin$strata = as.factor(clin$strata)
from bein import *
from bein.util import *
import os
M = MiniLIMS("data.db")
"""
GATK=/home/brentp/src/gatk/GenomeAnalysisTK-2.0-38-g45f7b0d/
@brentp
brentp / qlog.py
Created August 8, 2012 20:31
view log of running job on qsub like: ./qlog.py 314566
#!/mnt/storage4/bin/python-2.6.6/bin/python
from toolshed import nopen
import sys
fh = nopen("|showq -r")
header = fh.next().strip().split()
job_name = len(sys.argv) > 1 and sys.argv[1] or None
d = {}
@brentp
brentp / euler_52.py
Created July 18, 2012 21:19
euler_52
import itertools
from collections import Counter
def euler_52():
for i in itertools.count(1):
nums = [str(i * j) for j in range(1, 7)]
s = frozenset(nums[0])
sall = set()
sall.update(*nums)
if sall == s:
@brentp
brentp / tss.sh
Created July 17, 2012 20:44
bed file of transcription start-sites (TSS)
UPSTREAM=400
INSTREAM=100
ORG=hg18
mysql --user genome --host genome-mysql.cse.ucsc.edu -NAD $ORG -e \
"select chrom, txStart, txEnd, X.geneSymbol, strand from knownGene as K, kgXref as X WHERE txStart != txEnd AND X.kgID = K.name" \
| awk -v ups=$UPSTREAM -v ins=$INSTREAM 'BEGIN{OFS=FS="\t"}
$5 == "-" { print $1,$3-ins,$3+ups,$4 }
$5 == "+" { print $1,$2-ins,$2+ups,$4 }' \
| sort -k1,1 -k2,2n \
from docopt import docopt
import sys
class command(object):
registry = {}
short_docs = []
def __init__(self, doc = None):
self.short_docs.append(doc)
def __call__(self, fn):
"""
qvality must be on the $PATH.
run on a file with pvalues in column 4:
$ python qvality.py --column 4 input.bed > output.bed
output file will have extra columns for PEP (posterior error prob)
and q-value.
if input.bed has a header, it is retained.
@brentp
brentp / compare.R
Created May 1, 2012 03:10
implement f.pvalue from bioconductor's sva to compare 2 models with f-test
xs = read.table('mod4.txt', sep="\t", header=T)
y = read.table('y4.txt', sep="\t", header=T)
colnames(y) = "Survival"
df = cbind(y, xs)
print(colnames(df))
print(drop1(lm(Survival ~ SexMale + AgeChild + class_crewTRUE, data=df), test="F"))