Skip to content

Instantly share code, notes, and snippets.

View endrebak's full-sized avatar
🧬
Trying to write a genomic library in Rust

endrebak.ada endrebak

🧬
Trying to write a genomic library in Rust
View GitHub Profile
@sanfx
sanfx / mockNamespace.py
Last active May 10, 2016 09:59
mock argparse's Namespace behaviour.
class Namespace(object):
"""Mock for argparse's NameSpace
"""
def __init__(self, lst=None, flter=None):
super(Namespace, self).__init__()
self.filter = flter
self.lst = lst
def __repr__(self):
return 'Namespace(filter=self.filter, lst = self.lst)'
# Example for https://www.biostars.org/p/193145
import pybedtools
import pysam
# Use an example BAM file included with pybedtools
fn = pybedtools.example_filename('x.bam')
bam = pysam.Samfile(fn, 'r')
# Filter reads using pysam. Since all aspects of the SAM-format read
@endrebak
endrebak / simes.py
Last active April 24, 2018 07:42
Simes' method Python
import pandas as pd
# A combined P-value was computed for each peak cluster using Simes’ method
# (19). For a cluster containing n windows, the combined P-value is defined as
# p{s}=min{np{r}/r;r=1,2…,n} where the p{r} are the individual window P-values sorted
# in increasing order. This provides weak control of the family-wise error rate
# across the set of null hypotheses for all windows in the cluster. In other
# words, p{s} represents evidence against the global null hypothesis, i.e. that
# no windows in the cluster are DB.
@charlietsai
charlietsai / pretty_print_df.py
Created November 9, 2016 00:26
Pretty print Pandas DataFrame
from tabulate import tabulate
def pretty_print_df(df):
print tabulate(df, headers='keys', tablefmt='psql')
@ericnormand
ericnormand / 00 Langton's Ant.md
Last active May 8, 2019 06:42
324 - PurelyFunctional.tv Newsletter - Puzzle solutions

Langton's ant (from Rosetta Code)

Langton's ant is a cellular automaton that models an ant sitting on a plane of cells, all of which are white initially, the ant facing in one of four directions.

Each cell can either be black or white.

The ant moves according to the color of the cell it is currently sitting in, with the following rules:

  1. If the cell is black, it changes to white and the ant turns left; If the cell is white, it changes to black and the ant turns right;
# Author: denis.engemann@gmail.com
# License: simplified BSD (3 clause)
# Note: code is based on scipy.stats.pearsonr
def ss(a, axis):
return np.sum(a * a, axis=axis)
def compute_corr(x, y):
x = np.asarray(x)
y = np.asarray(y)
@verma
verma / Datascript101-Chapter2.clj
Created May 6, 2016 17:07
Datascript101 - Chapter 2
(ns dt.core
(:require [datascript.core :as d]))
;; schema so nice
(def schema {:maker/email {:db/unique :db.unique/identity}
:car/model {:db/unique :db.unique/identity}
:car/maker {:db/type :db.type/ref}
:car/colors {:db/cardinality :db.cardinality/many}})

Minor update: Genetic correlations and Genomic Control(GC) in GenomicSEM

This document describes a minor update to genomic SEM that provides the user with the option to control how the LD score intercept is used to apply genomic control to GenomicSEM GWAS and code to get quick initial genetic correlations and the standard errors of the genetic correlation from the ldsc() function.

Better documentation and options for Genomic Control.

Behind the scenes, and poorly documented (there were some comments in the code, that’s it), GenomicSEM was applying Genomic Control. The LD score regression intercept produces an expectation for the mean chi-square statistic under the null. As a chi2 distribution with 1 df has a mean of 1.0, an LDSC intercept greater than 1.0 can be used as an index of inflation of the test statistic attributable to uncontrolled confounding (Bulik Sullivan et al. 2015). Specifically, we estimate the univariate LD score intercept and inflate the SE of the estimated SNP-trait covarianc

%%file _chi2.c
#include <Python.h>
#include <numpy/arrayobject.h>
#include "chi2.h"
static char module_docstring[] =
"This module provides an interface for calculating chi-squared using C.";
static char chi2_docstring[] =
"Calculate the chi-squared of some data given a model.";
@vsoch
vsoch / Singularity
Last active June 28, 2021 19:11
A quick tutorial on how to generate a Singularity image with loadcaffee
Bootstrap: docker
From: ubuntu:16.04
%runscript
. /torch/install/bin/torch-activate
exec /bin/bash
%labels
MAINTAINER vsochat@stanford.edu