Skip to content

Instantly share code, notes, and snippets.

View jimhester's full-sized avatar

Jim Hester jimhester

View GitHub Profile
@jimhester
jimhester / append.pl
Last active January 8, 2018 14:50
Parsing fasta files in perl ruby python and go
#!/usr/bin/env perl
use warnings;use strict;
my ($header,$sequence);
$header = <>;
chomp $header;
while(my $line = <>){
chomp $line;
if($line =~ /^>/){
@jimhester
jimhester / parseREBASE.pl
Created July 31, 2012 15:29
Restriction enzyme regular expression performance
my %sites;
while(<>){
next if( 1 .. /Rich Roberts/);
next unless /\S/;
my(@names) = split /[\s\)\(]+/;
my $site = IUB_to_regexp(uc($names[-1]));
if(not exists $sites{$site} and not exists $sites{$site}){
@jimhester
jimhester / webkit_svg.rmd
Created October 2, 2012 18:51
Webkit error in svg files
```{r error,dev='svg'}
library(ggplot2)
ggplot(movies,aes(x=rating)) + geom_histogram(aes(fill=..count..))
```
@jimhester
jimhester / read_fasta.cpp
Created November 27, 2012 20:17
[C++]Parsing fasta files in R using Rcpp
#include <fstream>
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
CharacterVector read_fasta(std::string file) {
CharacterVector records;
std::ifstream in(file.c_str());
in.get(); // remove first '>'
@jimhester
jimhester / read_gff.R
Created January 23, 2013 20:55
Reading gff/gtf files with Rcpp
require(Rcpp)
require(GenomicRanges)
sourceCpp('read_gff.cpp')
read_gff = function(file, grouping='feature_id', attribute_sep='=') {
data = data.frame(lapply(gff2df(file, attribute_sep), all_numeric, what="vector"))
if(!grouping %in% colnames(data)){
stop(paste(grouping, "does not exist in", file, ", valid columns are", paste(colnames(data), collapse=" ")))
}
stopifnot(grouping %in% colnames(data))
lapply(split(data, factor(data$seqid)), function(df) {
@jimhester
jimhester / knitr_report.css
Created March 8, 2013 21:09
knitr Rmd reports - custom css and javascript header
#toc {
top: 0px;
left: 0px;
height: 100%;
position: fixed;
width: 150px;
padding-top: 20px;
color: white;
}
@jimhester
jimhester / java.hprof.2.1.24.txt
Last active December 19, 2015 23:59
IGV over X11 hprof results for version 2.1.24 and 2.3.12
JAVA PROFILE 1.0.1, created Fri Jul 19 08:47:09 2013
Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
@jimhester
jimhester / team_colors.r
Created August 19, 2013 18:13
Get Hex team colors for NBA, NFL, NHL, and MLB from http://teamcolors.arc90.com/ for use in R.
url = 'http://teamcolors.arc90.com/'
library(httr)
get_colors = function(league=c('NBA', 'NFL', 'NHL', 'MLB')){
league = match.arg(league)
color_data = parse_html(GET('http://teamcolors.arc90.com/'))
rbind.fill(xpathApply(color_data,
paste('//*[@id="', league, '"]/li[@class="team"]', sep=''),
parse_team))
@jimhester
jimhester / .gitignore
Last active December 21, 2015 19:39 — forked from hadley/.gitignore
.Rproj.user
.Rhistory
.RData
*.Rproj
*.html
@jimhester
jimhester / less.R
Last active August 29, 2015 14:03
less function for R
withOptions <- function(optlist, expr)
{
oldopt <- options(optlist)
on.exit(options(oldopt))
expr <- substitute(expr)
eval.parent(expr)
}
less = function(x) {
withOptions(list(pager='less', dplyr.print_min=.Machine$integer.max, width=10000L), page(x, method='print'))