Skip to content

Instantly share code, notes, and snippets.

@sahilseth
sahilseth / split_tcga_barcode.R
Created March 23, 2017 17:47
a function to split TCGA barcodes
split_tcga_barcode <- function(x, split.char="-"){
tmp = strsplit(x, split.char)[[1]]
# default values
s.tss = "NA";
s.participant = "NA";
s.programcode = "NA";
s.nucleic = "NA";
s.portion = "NA";
s.sampletype = "00";
# install this cool tools from Heng Li (https://github.com/lh3/bioawk)
brew install bioawk
# information regarding exit_code:
# - NA: not started yet
# show lines where job started and had errors
bioawk -tc hdr '{if($exit_code!=0 && $started=="TRUE") print $jobname, $cmd, $exit_code}' flow_details.txt
# show lines which did not start
@sahilseth
sahilseth / du_type.sh
Created April 19, 2016 19:03
du by file type
find . -type f -printf "%f %s\n" |
awk '{
PARTSCOUNT=split( $1, FILEPARTS, "." );
EXTENSION=PARTSCOUNT == 1 ? "NULL" : FILEPARTS[PARTSCOUNT];
FILETYPE_MAP[EXTENSION]+=$2
}
END {
for( FILETYPE in FILETYPE_MAP ) {
print FILETYPE_MAP[FILETYPE], FILETYPE_MAP[FILETYPE]/10^6, FILETYPE;
}
@sahilseth
sahilseth / send_mail.R
Last active April 9, 2016 02:18
sending mail from R with attachments
library(sendmailR)
send_mail <- function(msg="", subject, tos = c("[email protected]"), attachment}
from <- sprintf("<abc@%s.inst.edu>", Sys.info()[4])
if(missing(subject))
subject <- paste("morning!")
salute <- paste("Hello there\n I just ran the tracker on ")
body <- c(salute, "\n", msg, "\n", mime_part(attachment))
@sahilseth
sahilseth / git_submodules.sh
Created December 1, 2015 06:41
git submodules
# here is scratchpad on various steps which are helpful in using git submodules
# holy grail of details: https://git-scm.com/book/en/v2/Git-Tools-Submodules
# adding a submodule
git submodule add <URL>
# clone a repo with submodules
git clone --recursive <URL>
@sahilseth
sahilseth / highlight
Created November 30, 2015 19:46
highlight code for keynote etc
Do you want to display some code in a Keynote presentation?
It's easy. All you need is Homebrew installed.
First you need to install the program highlight.
brew install highlight
So you have a piece of code. For example some Python code. The take that snippet of code and save it to a file like code.py. Now all you need to do is run this:
highlight -O rtf code.py | pbcopy
@sahilseth
sahilseth / bioawk.sh
Last active May 5, 2018 21:21
bioawk/flowr tutorial
# install this cool tools from Heng Li (https://github.com/lh3/bioawk)
brew install bioawk
# information regarding exit_code:
# - NA: not started yet
# show lines where job started and had errors
bioawk -tc hdr '{if($exit_code!=0 && $started=="TRUE") print $jobname, $cmd, $exit_code}' flow_details.txt
# show lines which did not start
@sahilseth
sahilseth / gist:c0d305e8981274228c6b
Created November 22, 2015 21:56
solving issues with GCC/ruby on apple
# issue: http://stackoverflow.com/questions/10575679/bundle-update-fails-on-ffi
# install apple commandline tools:
xcode-select --install
@sahilseth
sahilseth / gzip_files.sh
Created November 18, 2015 18:01
gunzip files
fqs=$(find . -name '*.fastq')
for fq in $fqs; do
echo "zipping $fq ...."
gzip $fq
done
@sahilseth
sahilseth / keynote theme
Created November 16, 2015 14:32
keynote themes folder
cd ~/Library/Containers/com.apple.iWork.Keynote/Data/Library/Application\ Support/User\ Templates/