Skip to content

Instantly share code, notes, and snippets.

@s-boardman
s-boardman / django-ModelMultipleChoiceField-crispy.py
Created August 18, 2017 12:30
Django 1.11 Using ModelMultipleChoiceField outside Admin interface with Crispy-Forms
# How to use the ModelMultipleChoiceField widget outside the Django admin interface
# when processing forms with Crispy-forms
## Prerequisites
django-crispy-forms installed and included in settings (as per crispy docs)
## Edited files:
### urls.py (root, not app/urls.py)
@s-boardman
s-boardman / dunn.py
Created February 19, 2016 14:44 — forked from alimuldal/dunn.py
Implementation of Dunn's multiple comparison test, following a Kruskal-Wallis 1-way ANOVA
import numpy as np
from scipy import stats
from itertools import combinations
from statsmodels.stats.multitest import multipletests
from statsmodels.stats.libqsturng import psturng
import warnings
def kw_dunn(groups, to_compare=None, alpha=0.05, method='bonf'):
"""
@s-boardman
s-boardman / cnvnator_wrapper.py
Created January 6, 2016 10:13
Python wrapper for CNVnator
import os
import subprocess
import numpy as np
import pandas as pd
from sample_class import Sample
from custom_parser import Parser
from pipeline_tools import file_checker
@s-boardman
s-boardman / Cufflinks easy installation
Last active October 27, 2016 21:51
Cufflinks installation for Unix systems
# argparse section
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("-l","--list", help="pass a list", nargs="*")
parser.add_argument("-b","--boolean", action="store_true", default=False, help="use this flag to turn on an option")
# grab the options here from the command line, console overrides email
args = parser.parse_args()
@s-boardman
s-boardman / pandas heatmaps
Last active August 22, 2017 18:55
Heatmap functions for Pandas dataframes.
"""Plots a Pandas dataframe as a heatmap"""
import matplotlib as mpl
import matplotlib.pyplot as plt
def heatmap(df,
edgecolors='w',
cmap=mpl.cm.RdBu,
log=False,vmin=0,vmax=500):
width = len(df.columns)/4
height = len(df.index)/4