Skip to content

Instantly share code, notes, and snippets.

@keithshep
keithshep / tidyAll.R
Created June 11, 2010 02:12
reformat R source
#!/usr/bin/Rscript
library("animation")
# reformat a directory full of R source files
tidy.all <- function(inDir = NULL, outDir = NULL, ...) {
if (is.null(inDir) || is.na(outDir))
stop("inDir can't be null or NA")
if (!file.info(inDir)$isdir)
stop("inDir must be a directory")
@keithshep
keithshep / liftover-csv.rb
Created June 14, 2010 13:32
liftover and sort a CSV file
#!/usr/bin/ruby -w
################################################################################
# Created By: Keith Sheppard ([email protected])
# Modification History:
# July 7, 2008: Initial revision created to run the liftover utility on
# the CGD (cgd.jax.org) imputed SNP data in comma-separated format
#
# This is a ruby script for running liftover to map SNPs in a source
# comma-separated file to a destination file using a different NCBI genome
@keithshep
keithshep / svn-tkdiff-modified.pl
Created June 14, 2010 13:47
Scans svn dir for modified files and tkdiffs them
#!/usr/bin/perl
use strict;
use warnings;
my $status_output = `svn status @ARGV`;
my @split_status_lines = split(/\n/, $status_output);
foreach(@split_status_lines)
{
if($_ =~ /^M.{5}\s+(.*)$/)
@keithshep
keithshep / strip-N-H-calls.bash
Created June 14, 2010 13:49
strip rows with N or H calls from a dir full of genotype CSV files
#!/bin/bash
echo "input directory: $1"
echo "output directory: $2"
for i in `ls $1` ; do echo "striping N and H calls from: $i" && egrep -v '(,N,)|(,N$)|(,H,)|(,H$)|(,n,)|(,n$)|(,h,)|(,h$)' $1/$i > $2/$i; done
@keithshep
keithshep / liftover-links.txt
Created June 14, 2010 19:46
links for using liftover
@keithshep
keithshep / r-cheats.txt
Created June 14, 2010 19:54
Cheat-sheet for R
# attach and detach a package:
library("MouseDivGeno")
detach(package:MouseDivGeno)
# start in 64 bit mode:
R --arch x86_64
# Stack-trace in R:
traceback()
@keithshep
keithshep / rhmm-example.R
Created June 14, 2010 19:57
Example use of R HMM package
library("RHmm")
sunProb <- c(0.6, 0.2, 0.15, 0.05)
cloudProb <- c(0.25, 0.25, 0.25, 0.25)
rainProb <- c(0.05, 0.10, 0.35, 0.50)
weatherDist <- distributionSet(dis="DISCRETE", proba=list(sunProb, cloudProb, rainProb), labels =c("DRY", "DRYISH", "DAMP", "SOGGY"))
weatherTransitions <- rbind(c(0.5, 0.375, 0.125), c(0.25, 0.125, 0.625), c(0.25, 0.375, 0.375))
weatherHmm <- HMMSet(initProb=c(0.63, 0.17, 0.20), transMat=weatherTransitions, distribution=weatherDist)
weatherPath <- viterbi(HMM=weatherHmm, obs=c("DRY", "DAMP", "SOGGY", "SOGGY", "DRYISH"))
@keithshep
keithshep / osx-specific.txt
Last active September 5, 2015 04:54
OS X Specific Commands
To get rid of shadows in screen captures:
defaults write com.apple.screencapture disable-shadow -bool true
To manipulate file attributes use xattr:
usage: xattr [-l] file [file ...]
xattr -p [-l] attr_name file [file ...]
xattr -w attr_name attr_value file [file ...]
xattr -d attr_name file [file ...]
The first form lists the names of all xattrs on the given file(s).
@keithshep
keithshep / bash-cheats.sh
Last active February 13, 2022 02:39
bash shell cheats
#!/bin/bash
# exit on error and don't allow the use of unset variables
set -o errexit
set -o nounset
#NOTE: you can find a list of special variables at http://tldp.org/LDP/abs/html/internalvariables.html
# quietly execute GUI applications
function quietly() {
@keithshep
keithshep / git-cheats.sh
Last active September 29, 2020 15:26
git cheats
# grep through git history
for i in {1..20}
do
echo "### check master~$((i - 1)) vs master~${i} diff ###"
git diff "master~$((i - 1))" "master~${i}" | grep -i 'sample-index'
done
# merge logs across several projects
(echo "commit time,author,project,message"; \
(for i in `"ls" -d */`; do (cd $i; git log "--pretty=tformat:%ai,%an,$i,%s") 2>/dev/null; done \