Skip to content

Instantly share code, notes, and snippets.

@cmdcolin
cmdcolin / x11sudo.sh
Created January 28, 2016 20:44
X11 as sudo
#!/bin/bash
# usage: x11sudo.sh username
su - $1 -c 'xauth list' | grep `echo $DISPLAY | cut -d ':' -f 2| cut -d '.' -f 1 | sed -e 's/^/:/'`|xargs -n 3 xauth add
@cmdcolin
cmdcolin / genrand.cpp
Last active February 5, 2016 14:15
Programming challenge v1 - find max contiguous product of integers in an array
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char **argv) {
if(argc < 3) {
cout << "Usage: " << argv[0] << " <n> <m> <s>" << endl;
cout << "Generates <n> random numbers to stdout max value <m> using seed <s>" << endl;
return -1;
}
@cmdcolin
cmdcolin / aprs.js
Created February 9, 2016 02:47
aprs.fi query
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-2.1.4.js"></script>
<script>
// call the api and update
for(var i=0; i<5; i++) {
setTimeout(function() {
@cmdcolin
cmdcolin / access_screen.md
Created February 16, 2016 23:07
access screen in another person's account
#!/bin/sh

$ screen -r 
Cannot open your terminal '/dev/pts/15' - please check.

$ script /dev/null
$ screen -r

works
@cmdcolin
cmdcolin / change-vcf-names.sh
Last active February 19, 2016 17:24
Modify the names on a VCF file in a streaming fashion, in this case, prepend the string "chr" to them
#!/bin/sh
bgzip -dc $1 | sed -e 's/^\([^#].*\)/chr\1/' | bgzip -c > `basename $1 .vcf.gz`.mod.vcf.gz
@cmdcolin
cmdcolin / gwas_data.sh
Last active March 8, 2016 07:23
Process a bunch of GWAS data with rsIDs to a BED file
#for i in GIANT*.txt; do LC_ALL=c sort -k1,1 $i > `basename $i .txt`.sort.bed; done;
export LC_ALL=c
parallel "join -1 4 -2 1 -t $'\t' snp144.sort.bed {} > {.}.joined.bed" ::: GIANT*sort.bed
parallel "cat {} | awk '{print \$2,\"\t\",\$3,\"\t\",\$4,\"\t\",\$1,\"\t\",\$8}' > {.}.final.bed" ::: *joined.bed
parallel "sort -k1,1 -k2,2n {} > {.}.final.sorted.bed" ::: *.final.bed
parallel "bgzip {}; tabix {}.gz" ::: *.final.sorted.bed
#for i in {1..22};do tabix GIANT_BMI_Speliotes2010_publicrelease_HapMapCeuFreq.sort.bed.gz chr$i > GIANT_BMI_Speliotes2010_publicrelease_HapMapCeuFreq.chr$i.bed; bgzip GIANT_BMI_Speliotes2010_publicrelease_HapMapCeuFreq.chr$i.bed; tabix GIANT_BMI_Speliotes2010_publicrelease_HapMapCeuFreq.chr$i.bed.gz; done;
@cmdcolin
cmdcolin / jbrowse-gwas.html
Last active February 21, 2018 16:33
render a GWAS dataset with jbrowse
<html>
<head>
<title>JBrowse render GWAS</title>
<link rel="stylesheet" type="text/css" href="css/genome.css">
<script type="text/javascript" src="src/dojo/dojo.js" data-dojo-config="async: 1, baseUrl: './src'"></script>
<script type="text/javascript" src="src/JBrowse/init.js"></script>
<script>
require({
@cmdcolin
cmdcolin / get_gc_content.R
Created March 29, 2016 14:09
calculcate GC content with sliding window in R
library("seqinr")
refseq=read.fasta('../Code/Amel_variants/Amel_4.5_scaffolds.fa')
wiggle_output <- file("output5.wig", "a")
printf("track type=print wiggle_0 name=fileName description=fileName\n",file=wiggle_output)
window_size=2000
refseq_names=names(refseq)
for(i in 1:length(refseq)) {
fasta=refseq[[i]]
@cmdcolin
cmdcolin / ea_utils.patch
Created March 29, 2016 14:10
Potential patches to ea_utils to work with C++0x
9d8
< #include <functional>
32c31
< bool operator()(FILE* fp, const std::pair<std::tr1::reference_wrapper<const string>, std::tr1::reference_wrapper<const vector<annot> > > value) const {
---
> bool operator()(FILE* fp, const std::pair<const string&, const vector<annot> >& value) const {
35c34,35
< const unsigned char size = value.first.get().length();
---
> assert(value.first.length() <= UCHAR_MAX);
@cmdcolin
cmdcolin / knapsack.R
Created March 29, 2016 14:15
Given a list of song durations, split them into two parts of equal length using knapsack
# given a list of song durations, split them into two parts of equal length using knapsack
songs=list("drugs"=6*60+40,"error"=5*60+36,"stepvhen"=5*60+17,"infinity"=6*60+13,
"pete"=2*60+38,"Zalh"=7*60+3,"morpheus"=5*60+4,"cleartone"=6*60+5,
"dedmeth"=6*60+32,"orthodox"=2*60+18,"xeph"=4*60+12,"amelia where are"=6*60+58)
half.cassette <- local (
function (target) {