Skip to content

Instantly share code, notes, and snippets.

@ConradStack
ConradStack / scrape.r
Created June 8, 2015 22:22
Use R to download links from a simple HTML page
require(RCurl)
require(XML)
require(stringr)
pull.to = "~/tmp"
misc.dir = sprintf("%s/lectures",pull.to)
base.url = "http://www.stat.cmu.edu/~cshalizi/uADA/15/"
lns = readLines(base.url)
top = grep("<h2>schedule",lns,ignore.case=T)
use = lns[top:length(lns)]
@ConradStack
ConradStack / Install.BSgenome.Tcacao.R
Last active June 22, 2016 15:35
How to install the cacao genome data packages in R
# Steps:
# 1. Install prerequisite R packages (devtools, BSgenome)
# 2. Install BSgenome.Tcacao packages from github
### install devtools (if needed)
install.packages("devtools")
### install BSgenome from bioconductor
source("https://bioconductor.org/biocLite.R")
biocLite("BSgenome")
@ConradStack
ConradStack / metadata.R
Created June 11, 2016 16:30
Adding metadata to R files
##
## From http://www.r-bloggers.com/adding-metadata-to-variables/
##
# add a comment to a variable (NB -> comment(...) function is base R)
# example
xx <- 1:10
comment(xx) <- "one through ten"
attributes(xx)
comment(xx) <- "another one" # NB -> adding another comment overwrites the last one
# Template for ~/.Rprofile script
# environmental variables:
Sys.setenv(
AUTHOR="Conrad Stack",
EMAIL="[email protected]"
)
# options():
options("stringsAsFactors"=FALSE)
#!/bin/bash
## Tested and worked on Mac OSX 10.11
# Download bedtools2 from github:
wget https://github.com/arq5x/bedtools2/releases/download/v2.25.0/bedtools-2.25.0.tar.gz
# unzip, navigate, and build
tar -zxvf bedtools-2.25.0.tar.gz
cd bedtools2/
@ConradStack
ConradStack / 0_reuse_code.js
Created June 22, 2016 16:04
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
#!/usr/bin/env python3
import argparse
import os
import sys
# Deinterlace an interlaced fastq file
# (modified from iamdelf/deinterlace)
# usage:
@ConradStack
ConradStack / gff3export.R
Last active July 12, 2016 20:45
Export Granges(List) to gff3 with rtracklayer
import(rtracklayer)
# Where syn is a list of GRanges objects:
test = GenomicRangesList(syn)
export.gff(test,"~/tmp/tmp.gff3", version="3")
# ... or a single GRanges element:
export.gff(syn[[1]],"~/tmp/tmp.gff3", version="3")
@ConradStack
ConradStack / ana.py
Last active July 21, 2016 18:29
Managing python versions with Anaconda
## If python 3.5, say, has been installed but you want to use v2.7 for
## a particular project
# Create environment for different (or specific) version of python:
conda create -n py27 python=2.7 anaconda
# Check available environments (optional)
# conda info --envs
@ConradStack
ConradStack / tar_exclude.sh
Last active July 25, 2016 18:01
Excluding files from tarball creation
#!/bin/bash
# From: http://www.cyberciti.biz/faq/exclude-certain-files-when-creating-a-tarball-using-tar-command/
tar --exclude-vcs --exclude='nohup.out' -cjf ~/tmp/whatever.tar.bz2 ./*