Skip to content

Instantly share code, notes, and snippets.

@sxv
sxv / README.md
Last active July 3, 2018 07:20
Interactive SVG + Canvas Plot

A D3 demonstration of SVG and Canvas intermingling. Blue circles are plotted in SVG, black circles in canvas. One force to rule them all. The plot is zoomable and pannable.

Inspired by M. Bostock's Canvas / SVG zoom comparison series and collision detection examples [1] [2] .

@sxv
sxv / README.md
Last active December 10, 2015 20:58
Can't we all get along?

Another take on the SVG + Canvas Plot, but this time includes a third group of nodes: divs. Black nodes are drawn with HTML5 Canvas, blue nodes in SVG, and red nodes as divs. Zoomable and pannable.

@sxv
sxv / README.md
Last active December 11, 2015 14:48
Chroma + Phi (ϕ)

An exploration of color generation based on the golden ratio (phi). Generating colors according to this ratio allows any arbitrary number of new values to be added, while maximizing the separation between nearest values.

This example uses D3's HCL color space, designed for maximum (perceived) hue separation. Because HCL is based upon three distinct variables, this algorithm optimizes variation of the hue (H) variable first, then chroma (C) and luminance (L). In other words, hue values are generated strictly according to the golden ratio, while chroma and luminance are "staggered" to avoid multiple variables moving together along the Fibonacci spiral "period". I suspect there are more elegant solutions to this problem but have not found any yet.

Both chroma and luminance are restricted to values between 15 and 100.

Inspired by Vi Hart.

@sxv
sxv / vcfgenie.sh
Last active August 10, 2016 20:01
#!/usr/bin/env bash
for f in *.vcf; do \
gawk 'BEGIN{FS="\t"; OFS="\t"; } # separator=tab
/CHROM/{
## for(i=0; i<NF; i++){ if($i=="FORMAT"){ samples=(NF-i) } } # todo
if($(NF-2)~/FORMAT/){
samples=2; # two samples?
if($(NF)~/[nN]$/ || $(NF)~/normal$/){ swap=1 } # is order t/n?
}
@sxv
sxv / genesort.py
Last active August 10, 2016 20:01
import sys
from glob import glob
if (len(sys.argv)<=1): match = '*n0*'
else: match = sys.argv[1]
file = glob(match)[0]
counts = {}
with open(file) as f:
print f.readline()
@sxv
sxv / index.html
Created June 12, 2016 04:34
dots1
<canvas id="canvas"></canvas>
<script src="https://d3js.org/d3.v3.min.js"></script>
<script>
var num = 2000;
var canvas = document.getElementById("canvas");
var width = canvas.width = window.innerWidth;
var height = canvas.height = window.innerHeight;
var ctx = canvas.getContext("2d");
var particles = d3.range(num).map(function(i) {
return [Math.round(width*Math.random()), Math.round(height*Math.random()), 2];
# define input cases via master_key.txt
# for each run, align fastq -> bam
# if GATK specified, run GATK, variant calling, and annovar
# run matricizer2 on tab output
# todo: add R clustering scripts
## usage
# python rnarunner.py --input-dir /path/to/fastqs
## NOTES: input-dir must contain master_key.txt, input fastq.gz files, matricizer2.py, UCSC_GENE_NAME3.txt
@sxv
sxv / rna_runner.py
Last active October 11, 2016 20:53
# define input cases via master_key.txt
# for each run, align fastq -> bam
# if GATK specified, run GATK, variant calling, and annovar
# run matricizer2 on tab output
# todo: add R clustering scripts
## usage
# python rnarunner.py --input-dir /path/to/fastqs
## NOTES: input-dir must contain master_key.txt, input fastq.gz files, matricizer2.py, UCSC_GENE_NAME3.txt
import sys
opts = {
'window': 100000,
'intrachrom': False
}
args = sys.argv[1:]
for a, arg in enumerate(args):
if arg.startswith('-'):
if arg.startswith('-w') or arg.startswith('--window'):
gawk '//{x=tolower($0); gsub(/[aeiou]/,"",x); a[x]++; b[x]=$0;}END{for(i in a){ if(a[i]==1){print i, b[i]} }}' /usr/share/dict/words