-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 8bd5291
Showing
15 changed files
with
559 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# vim: set filetype=r: | ||
|
||
# Default CRAN mirror | ||
options(repos=structure(c(CRAN="https://cloud.r-project.org/"))) | ||
|
||
# Print data.table's columns classes and key | ||
options(datatable.print.class = TRUE, datatable.print.keys = TRUE) | ||
|
||
# Monitor memory usage ( https://stackoverflow.com/questions/1358003 ) | ||
.ls.objects <- function (pos = 1, | ||
pattern, | ||
order.by, | ||
decreasing=FALSE, | ||
head=FALSE, | ||
n=5) { | ||
napply <- function(names, fn) sapply(names, function(x) fn(get(x, pos = pos))) | ||
names <- ls(pos = pos, pattern = pattern) | ||
obj.class <- napply(names, function(x) as.character(class(x))[1]) | ||
obj.mode <- napply(names, mode) | ||
obj.type <- ifelse(is.na(obj.class), obj.mode, obj.class) | ||
obj.prettysize <- napply(names, | ||
function(x) { | ||
format(utils::object.size(x), units = "auto") | ||
}) | ||
obj.size <- napply(names, object.size) | ||
obj.dim <- t(napply(names, function(x) as.numeric(dim(x))[1:2])) | ||
vec <- is.na(obj.dim)[, 1] & (obj.type != "function") | ||
obj.dim[vec, 1] <- napply(names, length)[vec] | ||
out <- data.frame(obj.type, obj.size, obj.prettysize, obj.dim) | ||
names(out) <- c("Type", "Size", "PrettySize", "Length/Rows", "Columns") | ||
if (!missing(order.by)) { | ||
out <- out[order(out[[order.by]], decreasing=decreasing), ] | ||
} | ||
if (head) { | ||
out <- head(out, n) | ||
} | ||
return(out) | ||
} | ||
.lsos <- function(..., n=10) { | ||
.ls.objects(..., order.by="Size", decreasing=TRUE, head=TRUE, n=n) | ||
} | ||
|
||
# Built-in color names ( http://www.sthda.com/english/wiki/colors-in-r ) | ||
.showCols <- function(cl=colors(), | ||
bg = "grey", | ||
cex = 0.75, | ||
rot = 30) { | ||
m <- ceiling(sqrt(n <-length(cl))) | ||
length(cl) <- m*m; cm <- matrix(cl, m) | ||
require("grid") | ||
grid.newpage(); vp <- viewport(w = .92, h = .92) | ||
grid.rect(gp=gpar(fill=bg)) | ||
grid.text(cm, x = col(cm)/m, y = rev(row(cm))/m, rot = rot, vp=vp, | ||
gp=gpar(cex = cex, col = cm)) | ||
} | ||
|
||
# Set IRkernel default plot size ( https://irkernel.github.io/ ) | ||
.d <- function(width = 8, height = 5, scale = 2) { | ||
options(repr.plot.width = width, repr.plot.height = height, | ||
jupyter.plot_scale = scale) | ||
} | ||
|
||
# Initialize environment and print summary, useful for notebooks | ||
.envInit <- function(packages = NULL) { | ||
if (!is.null(packages)) { | ||
invisible(lapply(packages, library, character.only = TRUE)) | ||
} | ||
print(R.version.string) | ||
print(sapply(packages, function(x) paste0(packageVersion(x)))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
channels: | ||
- conda-forge | ||
- bioconda | ||
- nodefaults | ||
channel_priority: strict | ||
auto_activate_base: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
prefix_path: "~/.local/share/condax" | ||
link_destination: "~/.local/bin" | ||
channels: | ||
- conda-forge | ||
- bioconda | ||
- nodefaults |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Alias to manage dotfiles in a bare repo | ||
alias config='git --git-dir=$HOME/.config/dotfiles --work-tree=$HOME' | ||
|
||
# Colored outputs | ||
alias ls='ls --color=auto' | ||
alias grep='grep --color=auto' | ||
alias fgrep='fgrep --color=auto' | ||
alias egrep='egrep --color=auto' | ||
|
||
# Safety aliases | ||
alias rm='rm -i' | ||
alias cp='cp -i' | ||
alias mv='mv -i' | ||
|
||
# Quality-of-life aliases | ||
[ -x "$(command -v batcat)" ] && alias bat='batcat' | ||
alias la='ls -A' | ||
alias l='ls -CF' | ||
alias ll='ls -alF' | ||
if [ ! -x "$(command -v realpath)" ] && [ -x "$(command -v readlink)" ]; then | ||
alias realpath='readlink -f' | ||
fi | ||
alias fsort='LC_ALL=C sort' | ||
[ -x "$(command -v stow)" ] && alias stow='stow --no-folding' | ||
if [ -x "$(command -v tmux)" ]; then | ||
tm() { | ||
if [ -n "$1" ]; then | ||
tmux attach-session -d -t "$1" | ||
else | ||
tmux attach-session -d | ||
fi | ||
|
||
} | ||
alias tmc='tmux load-buffer' | ||
alias tmv='tmux save-buffer' | ||
fi | ||
if command -v micromamba &>/dev/null; then | ||
alias c='micromamba' | ||
! command -v mamba &>/dev/null && alias mamba='micromamba' | ||
! command -v conda &>/dev/null && alias conda='micromamba' | ||
elif command -v mamba &>/dev/null; then | ||
alias c='mamba' | ||
elif command -v conda &>/dev/null; then | ||
alias c='conda' | ||
fi | ||
alias ca='c activate' cda='c deactivate' | ||
[ -x "$(command -v zoxide)" ] && alias z='zi' | ||
|
||
# Slurm shortcuts | ||
if [ -x "$(command -v sbatch)" ]; then | ||
__jobcols() { printf '%s' "$((COLUMNS / 4))"; } | ||
alias squeue='squeue -o "%.18i %.9P %.$(__jobcols)j %.8u %.2t %.10M %.6D %R"' | ||
alias squeueu='squeue -u $USER' | ||
alias sacct='sacct -o "jobid,jobname%$(__jobcols),alloccpus,MaxRSS,state,exitcode,Start,End"' | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
# Print the header (the first line of input) | ||
# and then run the specified command on the body (the rest of the input) | ||
# use it in a pipeline, e.g. ps | body grep somepattern | ||
# (ref:https://unix.stackexchange.com/a/11859) | ||
body() { | ||
IFS= read -r header | ||
printf '%s\n' "$header" | ||
"$@" | ||
} | ||
|
||
# Reverse complement a DNA sequence | ||
revc() { | ||
if [ -n "$1" ]; then | ||
echo "$1" | rev | tr 'ACGTRYKMBDHV' 'TGCAYRMKVHDB' | ||
else | ||
rev | tr 'ACGTRYKMBDHV' 'TGCAYRMKVHDB' | ||
fi | ||
} | ||
|
||
# count unique lines; sortcut for `sort -u | wc -l` | ||
wcu() { | ||
sort -u "$1" | wc -l | ||
} | ||
|
||
# Add the executed command line to output's header | ||
cmdump() { | ||
echo -E "# $*" | ||
"$@" | ||
} | ||
|
||
# Create directory and enter it | ||
cmkdir() { | ||
mkdir -p "$1" && cd "$1" || return | ||
} | ||
|
||
# Check resource usage by user | ||
userusage() { | ||
ps aux | awk '{print $1,$3,$6,$8}' | sort -u | awk ' | ||
BEGIN {print "USER\t%CPU\tRSS(GB)"} | ||
{ rss[$1]+=$3; cpu[$1]+=$2 } | ||
END { for(i in rss){OFS="\t"; print i,cpu[i],rss[i]/1000000} }' | ||
} | ||
|
||
# Wrapper for `zcat <file.gz> | head` | ||
# usage: zhead <file.gz> [10] | ||
zhead() { | ||
if [ -z "$2" ]; then | ||
local n=10 | ||
else | ||
local n="$2" | ||
fi | ||
zcat "$1" | head -n "$n" | ||
} | ||
|
||
# Quickly remove large directories with rsync | ||
rsyncrm() { | ||
mkdir rsrm_empty | ||
rsync -a --delete rsrm_empty/ "$1" | ||
rmdir rsrm_empty "$1" | ||
} | ||
|
||
# Scrape biocontainers | ||
biocontainers() { | ||
local url="https://quay.io/api/v1/repository/biocontainers" | ||
local sprefix="https://depot.galaxyproject.org/singularity" | ||
local dprefix="quay.io/biocontainers" | ||
curl -s -X GET "$url"/"$1"/tag/ | | ||
python3 -c "import json,sys;from datetime import datetime;\ | ||
obj=json.load(sys.stdin);\ | ||
print('docker_image\tsingularity_image\tlast_modified');\ | ||
[print('$dprefix/$1:{}\t$sprefix/$1:{}\t{}'.format(\ | ||
x['name'], x['name'], datetime.strptime(x['last_modified'], '%a, %d %b %Y %H:%M:%S -0000')\ | ||
)) for x in obj['tags']]" | ||
} | ||
biocontainers_galaxy() { | ||
local url="https://depot.galaxyproject.org/singularity/" | ||
curl -s $url | sed 's/\r$//' | grep -v "\-$" | grep "^<a href" | | ||
sed 's/<[^<>]*>//g' | | ||
awk -vurl=$url '{print url""$1"\t"$2"-"$3}' | ||
} | ||
|
||
# SSH to current directory | ||
sshpwd() { | ||
local shell=${SHELL:-bash} | ||
case "$shell" in | ||
*/sh) | ||
local args="" | ||
;; | ||
*) | ||
local args=${2:-"--login"} | ||
;; | ||
esac | ||
ssh -t "$1" "cd $PWD; $shell $args" | ||
} | ||
|
||
# Get numbered header COLUMNS | ||
nheader() { | ||
head -n 1 "$1" | tr '\t' '\n' | nl | ||
} | ||
|
||
# Generate duckduckgo email alias | ||
duck() { | ||
curl -s -H "Content-Type: application/json" \ | ||
-H "Authorization: Bearer ${DUCK_TOKEN:-$1}" \ | ||
-X POST \ | ||
https://quack.duckduckgo.com/api/email/addresses | | ||
sed 's/.*"\([^"]\+\)"}/\[email protected]\n/' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# plugins management, edited from https://github.com/mattmc3/zsh_unplugged | ||
plugin-load() { | ||
local repo plugdir initfiles zpd=() | ||
local ZPLUGDIRS=( | ||
"${XDG_DATA_HOME:-$HOME/.local/share}/zsh/plugins" | ||
'/usr/local/share/zsh/plugins' | ||
'/usr/share/zsh/plugins' | ||
) | ||
for repo in $@; do | ||
for zpd in $ZPLUGDIRS; do | ||
plugdir="$zpd/${repo:t}" | ||
if [[ -d "$plugdir" ]]; then | ||
break | ||
fi | ||
done | ||
if [[ ! -d "$plugdir" ]]; then | ||
printf "Clone $repo ? [yN]" | ||
if read -q; then | ||
git clone -q --depth 1 --recursive --shallow-submodules \ | ||
https://github.com/"$repo" "$plugdir" | ||
else | ||
continue | ||
fi | ||
fi | ||
initfiles=($plugdir/*.{plugin.zsh,zsh-theme,zsh,sh}(N)) | ||
(( $#initfiles )) || {echo >&2 "No init file found '$repo'." && continue} | ||
source $initfiles[1] | ||
done | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Run only if fzf has been initialized | ||
if ! declare -F _fzf_complete &>/dev/null; then | ||
return 0 | ||
fi | ||
|
||
# Slurm process IDs | ||
_fzf_complete_scancel() { | ||
_fzf_complete --multi --header-lines=1 -- "$@" < <(squeue -u "$USER") | ||
} | ||
_fzf_complete_scancel_post() { | ||
awk '{print $1}' | ||
} | ||
|
||
_fzf_complete_scontrol() { | ||
_fzf_complete --header-lines=1 -- "$@" < <(squeue) | ||
} | ||
_fzf_complete_scontrol_post() { | ||
awk '{print $1}' | ||
} | ||
|
||
if [ -n "$BASH" ]; then | ||
complete -F _fzf_complete_scancel -o default -o bashdefault scancel | ||
complete -F _fzf_complete_scontrol -o default -o bashdefault scontrol | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/sh | ||
|
||
command sacct -n -o 'jobid,state' -S 'now-24hours' \ | ||
| grep -vw RUNNING | grep -vw PENDING \ | ||
| cut -f1 -d' ' > ~/.config/tmux/blacklist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/bin/bash | ||
|
||
if [ ! -f ~/.config/tmux/blacklist ]; then | ||
touch ~/.config/tmux/blacklist | ||
fi | ||
|
||
if [ -x "$(command -v sacct)" ]; then | ||
cat <(command sacct -n -o 'jobid,state' -S 'now-24hours') \ | ||
| sed 's/ \+/ /' | sed -r 's/^([0-9]+)\.[^ ]+ /\1 /' | sort -u \ | ||
| grep -vwf ~/.config/tmux/blacklist \ | ||
| awk '$1!~/[0-9]+\.b/ && $2!~/CANCELLED/ { | ||
a[substr($2,1,1)]+=1;next | ||
} END { | ||
outline=""; | ||
for(i in a) outline=outline""i":"a[i]" "; | ||
sub(/ $/,"",outline); | ||
if(outline) print " | "outline | ||
}' | ||
fi | ||
|
Oops, something went wrong.