Skip to content

Instantly share code, notes, and snippets.

View pontikos's full-sized avatar
😀

Nikolas Pontikos pontikos

😀
View GitHub Profile
@pontikos
pontikos / drawchull.R
Last active January 4, 2016 07:19
Draw convex hull around points
testpts <- structure(list(x = c(4.9, 4.2, 4, 4.1, 4.4, 5.8, 5.8, 5.8, 5.8,
5.5, 4.9, 3.2, 3.2, 3.3, 5.4, 5.4, 5.7, 6.4, 6.7, 6.7, 6, 4.8,
3.6, 2.8, 3.5, 4.4, 5.1, 4, 3.7, 4.5, 4.9, 5.7), y = c(6.9, 6.2,
5.3, 4.1, 3.1, 2.9, 2.9, 3.5, 4.2, 4.9, 5.1, 4.9, 4.9, 5.2, 6.9,
6.9, 5.3, 3.8, 4.2, 5.6, 6.9, 5.8, 1.2, 2.5, 5.3, 6.4, 6.8, 7.6,
6.9, 5.4, 4.8, 4.4)), .Names = c("x", "y"))
x <- do.call('cbind',testpts)
ch<-chull(x)
plot(x,pch=20)
points(x[ch,],pch=20,col='red')
@pontikos
pontikos / replaceline.awk
Last active August 29, 2015 14:12
Prepends the string Levine_ to fields which do not start with the prefix Levine_
#! /bin/awk -f
BEGIN {
OFS = FS
}
{
# only one line starting with #CHROM needs to be modified in file
# all others just print out unmoodified
if ( $1 !~ /^#CHROM/ ) {
@pontikos
pontikos / count.awk
Last active August 29, 2015 14:12
Counts occurences of a field in output.
#! /usr/bin/awk -f
{
count[$1]++
}
END {
sort = "sort -n"
for(j in count)
print j, count[j] | sort
close(sort)
@pontikos
pontikos / format_time.py
Last active August 29, 2015 14:12
Format time given on stdin in format specified by first argument to stdout in format given by second argument.
import time
import sys
print time.strftime(sys.argv[2], time.strptime(sys.stdin.read().strip(), sys.argv[1]))
@pontikos
pontikos / errorfunctions.sh
Created January 6, 2015 19:19
Error functions for bash.
# prints to stderr in red
function error() { >&2 echo -e "\033[31m$*\033[0m"; }
function stop() { error "$*"; exit 1; }
try() { "$@" || stop "cannot $*"; }
@pontikos
pontikos / shellcommands.sh
Created January 7, 2015 14:35
Some random shell commands.
#Which shell?
ps | grep $$
#Which distro?
cat /etc/issue
#Which connections?
lsof -i
netstat -lptu
cat /proc/xxxx/net/tcp
@pontikos
pontikos / bgziptabix.sh
Created January 7, 2015 14:52
Takes vcf file and writes to vcf.gz OR takes gz filename as arguments and reads from stdin.
#!/bin/bash
f=$1
extension=${f##*.}
if [[ "$extension" == 'vcf' ]]
then
in=$f
out=${in}.gz
bgzip $in > $out
@pontikos
pontikos / jobarray.sh
Last active August 29, 2015 14:13
script to output SGE job array, which can then be submitted with qsub
#! /bin/bash
set -e
set -u
##
until [ -z "$1" ]
do
# use a case statement to test vars. we always test $1 and shift at the end of the for block.
case $1 in
# parameters to qsub
@pontikos
pontikos / xargs.sh
Created January 9, 2015 17:19
xargs examples for those that can never remember the syntax
seq 1 10 | xargs -I x echo number x
@pontikos
pontikos / createsymlinks.sh
Created January 13, 2015 15:58
Create symlinks to chr directory.