Skip to content

Instantly share code, notes, and snippets.

View kcha's full-sized avatar

Kevin Ha kcha

View GitHub Profile
#!/usr/bin/perl
# KH: This is modified from the original lastjoboutput script.
#
# Shows the output of the last N jobs that finished running on the cluster
# with an exit status OTHER THAN ZERO.
# Convenience function to avoid having to find the most recent job output file
use strict;
use warnings;
@kcha
kcha / multiprocessing_template.py
Last active August 29, 2015 14:02 — forked from ngcrawford/multiprocessing_template.py
Modified with options. Compatible with python 2.6.
#!/usr/bin/env python
# encoding: utf-8
import sys
import fileinput
from optparse import OptionParser, OptionGroup
import multiprocessing
import time
from itertools import izip_longest, izip, repeat
@kcha
kcha / hclust_example.R
Created July 30, 2014 19:53
Hierarchical clustering example
# Sample code for performing hierarchical clustering
# install.packages("gplots")
library(gplots)
library(RColorBrewer)
##### Use iris dataset ####
# See ?iris for more info
data <- as.matrix(iris[,1:4])
@kcha
kcha / stats.py
Last active August 29, 2015 14:04
Python math and stats functions
# $Date: 2010-10-29 16:09:50 -0400 (Fri, 29 Oct 2010) $
# Filename: stats.py
#
# A bunch of math/stats functions
import math
'''calculate average'''
def calcAvg(ls):
n, mean = len(ls), 0.0
@kcha
kcha / .Rprofile
Last active August 29, 2015 14:05
# Rprofile.site file
.First <- function() {
#.libPaths(c("~/lib/R/3.0", .libPaths()))
if (Sys.getenv("TERM") == "xterm-256color") {
library("colorout")
}
}
.Last <- function() {
@kcha
kcha / seqLogo.R
Last active August 29, 2015 14:07
#install if necessary
source("http://bioconductor.org/biocLite.R")
biocLite("seqLogo")
biocLite("Biostrings")
library(seqLogo)
library(Biostrings)
strings <- c("GATTACA", "GATAACA", "GATAAAA", "GATTAGA")
# these examples rely on the R/qtl package, www.rqtl.org
# install R/qtl package, within R, by typing install.packages("qtl")
all: knitr_example.html knitr_example_asciidoc.html knitr_example.pdf markdown_example.html
R_OPTS=--no-save --no-restore --no-init-file --no-site-file # vanilla, but with --environ
knitr_example.html: knitr_example.Rmd
R ${R_OPTS} -e 'library(knitr);knit2html("knitr_example.Rmd")'
@kcha
kcha / check_exit_status.sh
Last active August 29, 2015 14:11
Check exit status after running a command in bash
#!/bin/bash
check_exit_status() {
# Checks the latest exit status and exits if status is non-zero
# usage: check_exit_status $? "my_function"
EXITSTAT=$1
FUNC=$2
if [ "$EXITSTAT" -ne "0" ]; then
echo "=> ["`date`"] $FUNC failed"
exit $EXITSTAT
@kcha
kcha / chunk_jobs.sh
Last active August 29, 2015 14:18
Chunk jobs so that they don't all execute at the same time
N=4 # Chunk size
C=0 # Counter
for i in {1..12};
do
# submitjob here...
echo $i
((C=C+1))
if [[ `expr $C % $N` == 0 ]]; then
library(readr)
library(dplyr)
library(tm)
library(wordcloud)
library(SnowballC)
library(RColorBrewer)
m <- read_csv("node_table.csv.gz") %>%
filter(EM1_fwer_qvalue_dataset1 < 0.5, EM1_gs_size_dataset1 > 95)