Skip to content

Instantly share code, notes, and snippets.

View mfoll's full-sized avatar

Matthieu Foll mfoll

View GitHub Profile
@mfoll
mfoll / LSF_bjobs_monitor.r
Created May 11, 2016 07:57
Summary of jobs launched by all users for LSF cluster
#! /usr/bin/env Rscript
data=read.table(pipe("bjobs -u all -w | grep RUN | awk '{print $2\" \"$6}'"),stringsAsFactors = F,col.names = c("username","cpus"))
data[,2]=gsub("^cn.+$",1,data[,2])
data[,2]=as.numeric(gsub("^(.+)\\*cn.+$","\\1",data[,2]))
res=aggregate(cpus ~ username, data, sum)
print(res[order(res$cpus,decreasing = T),],row.names = FALSE)
@mfoll
mfoll / LSF_cluster_usage.r
Last active May 11, 2016 08:55
Summary of CPU usage for LSF cluster (graph and text file)
#! /usr/bin/env Rscript
# With no argument provided, produce a graph since the begining of the year
# Argument can be "2016/03/01,2016/12/31" or "2016/03/01,"
if (!is.na(commandArgs(TRUE)[1])) {
time_string=commandArgs(TRUE)[1]
} else {
time_string=paste(format(Sys.time(), "%Y"),"/01/01,",sep="")
}
@mfoll
mfoll / seqlen.awk
Last active September 25, 2015 15:02 — forked from danielecook/fasta_sequence_lengths.sh
Generate Fasta sequence lengths
BEGIN {
OFS = "\t"; # tab-delimited output
}
# Use substr instead of regex to match a starting ">"
substr($0, 1, 1) == ">" {
if (seqlen) {
# Only print info for this sequence if no target was given
# or its id matches the target.
if (! target || id == target) {
print id, seqlen;
@mfoll
mfoll / get_vcf_data.r
Created September 23, 2015 08:42
Two functions to extract INFO and GENOTYPE data from a VCF file
get_info=function(info,field,num=T) {
get_single_info=function(single_info,field) {
grep_res=grep(paste("^",field,"=",sep=""),unlist(strsplit(single_info,";")),value=T)
if (length(grep_res)>0) strsplit(grep_res,"=")[[1]][2] else NA
}
res=unlist(lapply(info,get_single_info,field))
if (num) as.numeric(res) else res
}
get_genotype=function(genotype,format,field,num=T) {
@mfoll
mfoll / qqplot_pvalue.r
Created September 9, 2015 13:11
QQ plot for a vector of pvalues
qq = function(pvector, title="Quantile-quantile plot of p-values",red=NULL) {
# adapted from http://www.gettinggeneticsdone.com/2009/11/qq-plots-of-p-values-in-r-using-ggplot2.html
pvector[pvector==0]=min(pvector[pvector>0])
obs <- -log10(pvector)
N <- length(obs) ## number of p-values
null <- -log(1:N/N,10)
MAX <- max(c(obs,null))
c95 <- rep(0,N)
c05 <- rep(0,N)
for(i in 1:N){