Skip to content

Instantly share code, notes, and snippets.

@kdaily
kdaily / knitr.mk
Created May 16, 2012 12:48 — forked from halpo/knitr.mk
knitr makefile
################################################################################
# Copyright 2011
# Andrew Redd
# 11/23/2011
#
# Description of File:
# Makefile for knitr compiling
#
################################################################################
all:pdf # default rule DO NOT EDIT
@kdaily
kdaily / plyr_colwise_gsub.R
Created November 13, 2012 03:03
Example for using plyr to replace strings in multiple columns
## Need plyr
require(plyr)
## Some fake data
foo <- data.frame(a=rep("foo", 3), b=rep("foofoo", 3), c=rep("foobarfoo", 3))
## Replace function, works on vectors
fn <- function(x) gsub("foo", "bar", x)
## Turn it into a column-wise function; only apply to cols "a" and "b"
@kdaily
kdaily / example-r-markdown.rmd
Created December 5, 2012 18:44 — forked from jeromyanglim/example-r-markdown.rmd
Example of using R Markdown
This post examines the features of [R Markdown](http://www.rstudio.org/docs/authoring/using_markdown)
using [knitr](http://yihui.name/knitr/) in Rstudio 0.96.
This combination of tools provides an exciting improvement in usability for
[reproducible analysis](http://stats.stackexchange.com/a/15006/183).
Specifically, this post
(1) discusses getting started with R Markdown and `knitr` in Rstudio 0.96;
(2) provides a basic example of producing console output and plots using R Markdown;
(3) highlights several code chunk options such as caching and controlling how input and output is displayed;
(4) demonstrates use of standard Markdown notation as well as the extended features of formulas and tables; and
(5) discusses the implications of R Markdown.
@kdaily
kdaily / bamsplit.py
Created February 14, 2013 20:12 — forked from seandavi/bamsplit.py
#!/usr/bin/env python
# split a bam file by read group ID
# Sean Davis <seandavi@gmail.com>
# March 10, 2012
#
import pysam
import argparse
import logging
logging.basicConfig(level=logging.INFO)
@kdaily
kdaily / add_rgid_to_qname.py
Last active December 17, 2015 20:49
Add the read group ID to each read name in a BAM or SAM file.
"""Add the read group ID to each read name in a BAM or SAM file.
Must output to SAM format to get the header.
To directly convert to BAM, pipe to samtools view:
python add_rgid_to_qname.py INPUT.sam /dev/stdout | samtools view -Sb /dev/stdin > OUTPUT.bam
"""
def safe_qsub_run(cmd, jobname, script_header=_script_header, nodes=1, params="", stdout=None, stderr=None, shell=False):
"""Run a command via qsub in blocking mode so that the command waits to exit.
Requires a header string and a job name.
"""
scriptfile = tempfile.NamedTemporaryFile()
scriptfile.write("%(header)s\n%(command)s\n" % dict(header=script_header, command=cmd))
scriptfile.file.flush()
qsub_cmd = "qsub -N %(jobname)s -l nodes=%(nodes)s -W block=true %(params)s" % dict(jobname=jobname,
@kdaily
kdaily / arrangeMusic.R
Last active December 19, 2015 16:29 — forked from Vessy/arrangeMusic.R
Read .mp3 files from a given directory, compare songs, and play them in order of similarity
# Read .mp3 files from a given directory, compare songs, and play them in order of similarity
# To run, source this file, then:
# arrangeMusicC(inDirectory = getwd())
library("plyr")
library("tuneR")
library("seewave")
library("compiler")
@kdaily
kdaily / JQ479319
Created August 20, 2013 16:01
Merkel cell polyomavirus sequence (accession JQ479319) https://www.ncbi.nlm.nih.gov/nuccore/JQ479319
GGGGCTCCTAGCCTCCGAGGCCTCTGGAAAAAAAAGAGAGAGGCCTCTGAGGCTTAAGAGGCTTAATTAGCAAAAAAGGCAGTATCTAAGGGCAGATCCCAAGGGCGGGAAACTGCAGTATAAAAACCACTCCTTAGTGAGGTAGCTCATTTGCTCCTCTGCTCTTTCTGCAAACTCCTTCTGCATATAGACAAGATGGATTTAGTCCTAAATAGGAAAGAAAGAGAGGCTCTCTGCAAGCTTTTAGAGATTGCTCCTAATTGTTATGGCAACATCCCTCTGATGAAAGCTGCTTTCAAAAGAAGCTGCTTAAAGCATCACCCTGATAAAGGGGGAAATCCTGTTATAATGATGGAATTGAACACCCTTTGGAGCAAATTCCAGCAAAATATCCACAAGCTCAGAAGTGACTTCTCTATGTTTGATGAGGTCAGTACAAAATTTCCTTGGGAAGAATATGGAACTTTAAAGGATTATATGCAAAGTGGATATAATGCTAGATTTTGCAGAGGTCCTGGGTGCATGCTTAAGCAACTTAGAGATTCTAAGTGCGCTTGTATTAGCTGTAAGTTGTCTCGCCAGCATTGTAGTCTAAAAACTTTAAAGCAAAAAAACTGTCTGACGTGGGGAGAGTGTTTTTGCTATCAGTGCTTTATTCTTTGGTTTGGATTTCCTCCTACTTGGGAAAGTTTTGACTGGTGGCAAAAAACTTTAGAAGAAACTGACTACTGCTTACTGCATCTGCACCTTTTCTAGACTCCTACTTCCTTCCTCTGTAAGTATTAGATATGGAAAAGTCTATAAGGCAAAATATCAAAGAAAGGTTATTTATGACAGATTTTCTGTACTTTCCCATCTAGGTTGACGAGGCCCCTATATATGGGACCACTAAATTCAAAGAATGGTGGAGATCAGGAGGATTCAGCTTCGGGAAGGCATACGAATATGGGCCCAATCCACACGGGACCAACTCAAGATCCAGAAAGCCTTCCTCCAATGCATCCAGGGGAGCCCCCAGTGGAAG
@kdaily
kdaily / NIHResearchFestival2013.Rmd
Last active December 27, 2015 14:09
NIH Research Festival 2013, posters
NIH research festival
========================================================
http://researchfestival.nih.gov/2013/posters.cgi
chrom-4
Cancer-4
Cancer-5
Molbio-6
#!/usr/bin/perl -w
# From http://genomics-pubs.princeton.edu/prv/resources/scripts/fastq-filter_extract_reads.pl
=head1 NAME
fastq-filter_extract_reads.pl - Splits fastq file based on read ids in a list
=head1 SYNOPSIS