Skip to content

Instantly share code, notes, and snippets.

View stephenturner's full-sized avatar

Stephen Turner stephenturner

View GitHub Profile
#!/usr/bin/python
import sys
header=True
for line in sys.stdin:
if line.startswith('##'):
if header:
print line.strip()
continue
@stephenturner
stephenturner / keybindings.json
Created May 31, 2017 21:04
VSCode keybindings to replicate my most commonly used RStudio shortcuts (Mac)
// Place your key bindings in this file to overwrite the defaults
[
// RStudio: Copy lines up/down with alt+cmd+up/down
{
"key": "alt+cmd+down",
"command": "editor.action.copyLinesDownAction",
"when": "editorTextFocus && !editorReadonly"
},
{
"key": "shift+alt+down",
@stephenturner
stephenturner / sublime-keybindings.txt
Last active February 14, 2017 15:07
keybindings for sublime text 3
[
// Auto-pair backticks
{ "keys": ["`"], "command": "insert_snippet", "args": {"contents": "`$0`"}, "context":
[
{ "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
{ "key": "following_text", "operator": "regex_contains", "operand": "^(?:\t| |\\)|]|\\}|>|$)", "match_all": true },
{ "key": "preceding_text", "operator": "not_regex_contains", "operand": "[`a-zA-Z0-9_]$", "match_all": true },
{ "key": "eol_selector", "operator": "not_equal", "operand": "string.quoted.single", "match_all": true }
]
@stephenturner
stephenturner / clickable-imgs.js
Created September 29, 2016 15:06 — forked from bearloga/clickable-imgs.js
Make the figures click-able in your RMarkdown=>HTML reports.
<script language="JavaScript">
$(function() {
/* Lets the user click on the images to view them in full resolution. */
$("div.figure img").wrap(function() {
var link = $('<a/>');
link.attr('href', $(this).attr('src'));
link.attr('title', $(this).attr('alt'));
link.attr('target', '_blank');
return link;
});
## devtools::install_github("stephenturner/msigdf")
library(msigdf)
library(dplyr)
library(clusterProfiler)
c2 <- msigdf.human %>%
filter(collection == "c2") %>% select(geneset, entrez) %>% as.data.frame
data(geneList)
de <- names(geneList)[1:100]
# Performs principal components analysis on an ExpressionSet
eset_pca <- function (eset) {
mypca <- prcomp(t(na.omit(exprs(eset))))
pca <- as.data.frame(mypca$x)
pc1var <- round(summary(mypca)$importance[2,1]*100, digits<-1)
pc2var <- round(summary(mypca)$importance[2,2]*100, digits<-1)
pc1lab <- paste0("PC1 (",as.character(pc1var),"%)")
pc2lab <- paste0("PC1 (",as.character(pc2var),"%)")
out <- merge(pData(eset), pca, by<-"row.names") %>%
dplyr::rename(id<-Row.names)
@stephenturner
stephenturner / nullarbor-install-ubuntu1404.sh
Last active December 14, 2020 18:09
Nullarbor+dependencies installation script for a fresh Ubuntu 14.04 instance.
#!/bin/bash
# Nullarbor+dependencies installation script for a fresh Ubuntu 14.04 instance.
################################################################################
## Conveniences
################################################################################
# Some essential aliases
@stephenturner
stephenturner / deploy.sh
Created June 9, 2016 17:51 — forked from klmr/deploy.sh
Deploy a generated GitHub page (`_site` subfolder)
#!/usr/bin/env bash
# Configuration
remote_target=master
destination=_site
get-working-branch() {
git status | head -n 1 | awk '{ print $NF }'
}
@stephenturner
stephenturner / gh-pages-deploy.md
Created June 9, 2016 17:44 — forked from cobyism/gh-pages-deploy.md
Deploy to `gh-pages` from a `dist` folder on the master branch. Useful for use with [yeoman](http://yeoman.io).

Deploying a subfolder to GitHub Pages

Sometimes you want to have a subdirectory on the master branch be the root directory of a repository’s gh-pages branch. This is useful for things like sites developed with Yeoman, or if you have a Jekyll site contained in the master branch alongside the rest of your code.

For the sake of this example, let’s pretend the subfolder containing your site is named dist.

Step 1

Remove the dist directory from the project’s .gitignore file (it’s ignored by default by Yeoman).

# The hook
```{r}
library(knitr)
knitr::knit_hooks$set(source = function(x, options){
if (!is.null(options$verbatim) && options$verbatim){
opts = gsub(",\\s*verbatim\\s*=\\s*TRUE\\s*", "", options$params.src)
bef = sprintf('\n\n ```{r %s}\n', opts, "\n")
stringr::str_c(
bef,