Skip to content

Instantly share code, notes, and snippets.

@nkrumm
nkrumm / gist:c6b15a7295037ccb0e67
Created March 10, 2015 23:08
Convert RefFlat genes to exon list
curl -s "http://hgdownload.cse.ucsc.edu/goldenPath/hg19/database/refFlat.txt.gz" \
| gunzip -c \
| awk '{n=int($9); split($10,S,/,/);split($11,E,/,/); for(i=1;i<=n;++i) {printf("%s\t%s\t%s\t%s\n",$3,S[i],E[i],$1);} }' \
> refFlat.exons.hg19.bed
bedtools sort -i refFlat.exons.hg19.bed > refFlat.exons.hg19.sorted.bed
@nkrumm
nkrumm / average_image.py
Created March 3, 2015 19:02
Use k-means clustering to identify primary colors of an input image. Can specify --n-colors=INT. Also, --out-pallete=FILE will create a pallete of colors identified.
import argparse
import numpy as np
from scipy import ndimage
from scipy.cluster.vq import kmeans
from scipy.misc import imsave
def rgb2hex(r, g, b):
return '#{:02x}{:02x}{:02x}'.format(r, g, b)
@nkrumm
nkrumm / progress_magic.py
Created December 15, 2014 19:01
simple %progress magic for displaying progress updates in ipython notebook
from IPython.core.magic import (Magics, magics_class, line_magic,
cell_magic, line_cell_magic, needs_local_scope)
# The class MUST call this class decorator at creation time
@magics_class
class ProgressMagic(Magics):
@line_magic
@needs_local_scope
def progress(self, line, *args, **kwargs):
@nkrumm
nkrumm / ls_ftp.sh
Created August 28, 2014 17:13
Listing files in an FTP directory
#!/bin/bash
#As an example, get all ".fa.gz" files from a directory
wget -r -np --spider ftp://ftp.ncbi.nlm.nih.gov/genomes/Sus_scrofa/CHR* 2>&1 | grep -Eo "ftp\:.*\.fa\.gz" | uniq
@nkrumm
nkrumm / bash_aliases.sh
Last active August 29, 2015 14:03
More good bash aliases
# requires `tree` package
alias lst='tree -CAL 2 $1'
@nkrumm
nkrumm / bash_aliases.sh
Created July 4, 2014 12:58
More good bash aliases
alias lst='tree -L 2 $1'
@nkrumm
nkrumm / gist:5a879e6a58717f048855
Created July 4, 2014 12:35
Pretty Printing CSV and TSV functions
function csv() { cat "$@" | column -t -s, | less -S; }
function tsv() { cat "$@" | column -t -s"\t" | less -S; }
@nkrumm
nkrumm / gist:9289dbad6f4258a2ee53
Created July 4, 2014 12:32
Mac OS X history fixes
shopt -s histappend
export HISTSIZE=100000
export HISTFILESIZE=100000
export HISTCONTROL=ignoredups:erasedups
export PROMPT_COMMAND="history -a;history -c;history -r;$PROMPT_COMMAND"
@nkrumm
nkrumm / ps1.sh
Created June 26, 2014 00:10
PS1 git prompt
# Put in ~/.bash_profile or similar.
# PS1 (prompt)
# Reset
Color_Off="\[\033[0m\]" # Text Reset
# Regular Colors
Black="\[\033[0;30m\]" # Black
Red="\[\033[0;31m\]" # Red
Green="\[\033[0;32m\]" # Green
@nkrumm
nkrumm / [Helix] SRA downloading.ipynb
Created May 22, 2014 07:19
SRA+Entrez downloading
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.