Skip to content

Instantly share code, notes, and snippets.

@cmdcolin
cmdcolin / tumblrAPI
Last active January 31, 2016 21:11
Tumblr community analysis
#!/usr/bin/env Rscript
require(jsonlite)
require(reshape2)
api_key='your_api_key'
get_reblogs<-function(blogname,apikey,total=100) {
<script src="require.js"></script>
// uses https://github.com/alexkalderimis/imjs
<script>
require(['js/im'], function(im) {
console.log(im);
var flymine = new im.Service({root: 'www.flymine.org/query'});
var query = {
from: 'Gene',
select: [
'exons.symbol',
@cmdcolin
cmdcolin / intermineAPI
Last active June 17, 2016 23:33
intermine API with R
# intermine gives you code for downloading search results in many languages including Perl,Python,Java,and even Javascript
# by default, no R code is given, but it does provide a XML query string which can be easily be downloaded with RCurl or httr
library(httr)
library(jsonlite)
query='<query model="genomic" view="Gene.chromosome.primaryIdentifier Gene.exons.chromosomeLocation.start Gene.exons.chromosomeLocation.end" ><constraint path="Gene.symbol" op="=" value="eve" /><constraint path="Gene.organism" op="LOOKUP" value="D. melanogaster" /></query>'
ret=POST('http://www.flymine.org/flymine/service/query/results',
body=list(query=query, format='json'),
@cmdcolin
cmdcolin / jbrowse-render
Last active November 7, 2017 00:04
JBrowse feature rendering outside browser
<html>
<head>
<title>JBrowse feature rendering outside of browser</title>
<link rel="stylesheet" type="text/css" href="css/genome.css">
<script type="text/javascript" src="src/dojo/dojo.js" data-dojo-config="async: 1, baseUrl: './src'"></script>
<script type="text/javascript" src="src/JBrowse/init.js"></script>
<script>

Code style guidelines

  • Use unix line endings. If you are on windows, use a text editor writes/reads unix line endings
  • Use 4 spaces for indentation. Don't use tabs, and especially not a mix of tabs and spaces. Configure your editor to handle this
  • Avoid leaving commented out code in the codebase.
  • Use consistent comma style. Prefer not using comma-first style
  • Use consistent spacing surrounding if statements (e.g. choose if( condition ) or if (condition))
  • Use curly brackets on all blocks, don't rely on the fact that you can avoid it in the single line case

Git guidelines

  • Review your commits before pushing to server with git log -p.
@cmdcolin
cmdcolin / rasterize.js
Last active September 8, 2015 15:40
phantomjs rasterize.js with viewport modification
var page = require('webpage').create(),
system = require('system'),
address, output, size;
if (system.args.length < 3 || system.args.length > 5) {
console.log('Usage: rasterize.js URL filename [paperwidth*paperheight|paperformat] [zoom]');
console.log(' paper (pdf output) examples: "5in*7.5in", "10cm*20cm", "A4", "Letter"');
console.log(' image (png/jpg output) examples: "1920px" entire page, window width 1920px');
console.log(' "800px*600px" window, clipped to 800x600');
phantom.exit(1);
@cmdcolin
cmdcolin / convert_bam_to_bigwig.sh
Last active September 25, 2015 22:20
Convert BAM to bigwig (parallel)
#!/bin/bash
samtools faidx reference_genome.fa
cut -f1,2 reference_genome.fa.fai > chrom.sizes
parallel "bedtools genomecov -ibam {} -g chrom.sizes -bg -split > {.}.bg" ::: *.bam;
parallel "bedGraphToBigWig {} chrom.sizes {.}.bw" ::: *.bg

Procedure for compiling HTSLIB under emscripten

  • Get emscripten, e.g. brew install emscripten
  • Get zlib source distribution from zlib.org
  • zlib - “emconfigure ./configure” in zlib
  • zlib - comment out AR and ARFLAGS in Makefile (default libtool breaks things, at least on Mac)
  • zlib - Run “emmake make”
  • Get htslib source distribution from htslib.org
  • htslib - Don’t run emconfigure ./configure as it gets confused by lack of zlib (not sure how to point to it?)
  • htslib - Delete the AR = ar line from Makefile
<html>
<head>
<title>JBrowse feature rendering outside of browser</title>
<link rel="stylesheet" type="text/css" href="css/genome.css">
<script type="text/javascript" src="src/dojo/dojo.js" data-dojo-config="async: 1, baseUrl: './src'"></script>
<script type="text/javascript" src="src/JBrowse/init.js"></script>
<script>
@cmdcolin
cmdcolin / tlengraph.R
Created January 28, 2016 16:03
template length graph
#!/usr/bin/env Rscript
# usage:
# samtools view your_file.bam | cut -f3,4,9 > pre_bedgraph.txt
# tlengraph pre_bedgraph.txt output.bg
# bedGraphToBigWig output.bg chrom.sizes output.bw
library("ggplot2")