#!/bin/bash
ALL=$(du -s | awk '{print $1}');
NODEMODULES=$(find . -type d -depth 1 -name node_modules | xargs du -s | awk '{print $1}' | awk '{sum+=$1} END {print sum}');
DECIMAL=$(awk "BEGIN {printf \"%.2f\", $NODEMODULES/$ALL}")
PERCENT=$(echo "$DECIMAL*100" | bc)
echo "node_modules are using $PERCENT% of space in the current directory."
var s = 10;
var f = new File();
var b = new Bytes();
var last_chr = null, start = 0, end = 0;
while (f.readline(b) >= 0) {
var t = b.toString().split("\t");
t[1] = parseInt(t[1]);
t[2] = parseInt(t[2]);
if (t[0] != last_chr) {
if (last_chr) print(last_chr, start, end);
last_chr = t[0], start = t[1], end = t[2];
} else if (t[1] - end > s) {
print(last_chr, start, end);
start = t[1], end = t[2];
} else {
end = end > t[2]? end : t[2];
}
}
if (last_chr) print(last_chr, start, end);
b.destroy();
f.close();
21_clustreg.js
var getopt = function(args, ostr) {
var oli; // option letter list index
if (typeof(getopt.place) == 'undefined')
getopt.ind = 0, getopt.arg = null, getopt.place = -1;
if (getopt.place == -1) { // update scanning pointer
if (getopt.ind >= args.length || args[getopt.ind].charAt(getopt.place = 0) != '-') {
getopt.place = -1;
return null;
}
if (getopt.place + 1 < args[getopt.ind].length && args[getopt.ind].charAt(++getopt.place) == '-') { // found "--"
++getopt.ind;
getopt.place = -1;
return null;
}
}
var optopt = args[getopt.ind].charAt(getopt.place++); // character checked for validity
if (optopt == ':' || (oli = ostr.indexOf(optopt)) < 0) {
if (optopt == '-') return null; // if the user didn't specify '-' as an option, assume it means null.
if (getopt.place < 0) ++getopt.ind;
return '?';
}
if (oli+1 >= ostr.length || ostr.charAt(++oli) != ':') { // don't need argument
getopt.arg = null;
if (getopt.place < 0 || getopt.place >= args[getopt.ind].length) ++getopt.ind, getopt.place = -1;
} else { // need an argument
if (getopt.place >= 0 && getopt.place < args[getopt.ind].length)
getopt.arg = args[getopt.ind].substr(getopt.place);
else if (args.length <= ++getopt.ind) { // no arg
getopt.place = -1;
if (ostr.length > 0 && ostr.charAt(0) == ':') return ':';
return '?';
} else getopt.arg = args[getopt.ind]; // white space
getopt.place = -1;
++getopt.ind;
}
return optopt;
}
// parse command-line options
var c, w1 = 1000, w2 = 10000, min_n = 2;
while ((c = getopt(arguments, "w:W:n:")) != null) {
if (c == 'w') w1 = parseInt(getopt.arg);
else if (c == 'W') w2 = parseInt(getopt.arg);
else if (c == 'n') min_n = parseInt(getopt.arg);
}
// read data
var file = getopt.ind < arguments.length? new File(arguments[getopt.ind]) : new File();
var buf = new Bytes();
var seqs = {};
while (file.readline(buf) >= 0) {
var t = buf.toString().split("\t");
if (seqs[t[0]] == null) seqs[t[0]] = [];
seqs[t[0]].push(parseInt(t[1]));
}
buf.destroy();
file.close();
// cluster
function cluster(a, w1, w2)
{
a.sort(function(b,c){return b-c});
var x = [], y = [];
for (var i = 0; i < a.length; ++i)
x.push([i, a[i] - 1, a[i], 1]);
for (var i = 0; i < a.length - 1; ++i)
y.push([a[i+1] - a[i], i]);
y.sort(function(b,c){return b[0]!=c[0]?b[0]-c[0]:b[1]-c[1]});
for (var j = 0; j < y.length && y[j][0] <= w2; ++j) {
var l = y[j][1] + 1;
if (x[l][0] != l)
throw Error("Bug!!!");
// find the parent of y[j][1]
var k = y[j][1], tmp = [];
while (x[k][0] != k)
tmp.push((k = x[k][0]));
for (var i = 0; i < tmp.length; ++i) x[tmp[i]][0] = k;
// test merge
if ((x[l][2] - x[k][1]) / (x[l][3] + x[k][3]) > w1) continue;
// merge l into k
x[k][2] = x[l][2]; x[k][3] += x[l][3];
x[l][0] = k;
}
y.length = 0;
return x;
}
for (var seq in seqs) {
var x = cluster(seqs[seq], w1, w2);
for (var i = 0; i < x.length; ++i)
if (x[i][0] == i && x[i][3] >= min_n)
print(seq, x[i][1], x[i][2], x[i][3]);
}
11_filter.pl
#!/usr/bin/env perl
use strict;
use warnings;
while (<>) {
next if /^#/;
next if /INDEL/;
my @t = split("\t");
my ($hwe, $f) = (1, 0);
my @g3;
my $af = ($t[7] =~ /AF1=([^;]+)/)? $1 : 0;
if ($t[7] =~ /G3=([^;,]+),([^;,]+),([^;,]+).*HWE=([^;,]+)/) {
$hwe = $4 == 0? 1e-300 : $4;
my $p = $1 + .5 * $2;
$f = ($p > 0 && $p < 1)? 1 - $2 / (2 * $p * (1-$p)) : 0;
$hwe = -4.343 * log($hwe);
@g3 = ($1, $2, $3);
} else {
$hwe = 0;
}
$t[7] =~ /DP=(\d+)/;
my $dp = $1;
print join("\t", $t[0], $t[1], $t[5], $dp, sprintf("%.4g\t%.4g\t%.4f", $af, $f, $hwe), @g3), "\n";
}
su -
yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel
yum install gcc perl-ExtUtils-MakeMaker
yum remove git
# Download source
# check latest version in http://git-scm.com/downloads
cd /usr/src
wget https://www.kernel.org/pub/software/scm/git/git-<latest-version>.tar.gz
tar xzf git-<latest-version>.tar.gz
# create git from source code
cd git-<latest-version>
make prefix=/opt/git all
make prefix=/opt/git install
# Apppend this to your ~/.bashrc
function title () {
echo -ne "\033]0;$1\007"
}
function ssh () {
title "$*"
$(which ssh) "$@"
}
PROMPT_COMMAND='printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/\~}"'
PS1='[\[\033[32m\]\u@\h\[\033[00m\] \[\033[36m\]\W\[\033[31m\]\[\033[00m\]] \$ '