Skip to content

Instantly share code, notes, and snippets.

View alexpreynolds's full-sized avatar
👋
Hello

Alex Reynolds alexpreynolds

👋
Hello
  • Altius Institute for Biomedical Sciences
  • Seattle, WA USA
  • 05:22 (UTC -07:00)
View GitHub Profile
@alexpreynolds
alexpreynolds / bed2faidxsta.pl
Last active February 3, 2022 21:07
Convert (possibly stranded) BED to sequence via samtools faidx-indexed compressed or uncompressed FASTA files
#!/usr/bin/env perl
use strict;
use warnings;
use Getopt::Long;
#
# bed2faidxsta.pl
# --
# Reads BED data from standard input, writes FASTA to standard output.
@alexpreynolds
alexpreynolds / melt.pl
Last active December 1, 2015 18:37
Split BED intervals into per-base elements
#!/usr/bin/env perl
use strict;
use warnings;
my $cnt = 0;
while (<STDIN>) {
chomp;
my ($chr, $start, $stop, $id, $score, $strand) = split("\t", $_);
for (my $meltIdx = $start; $meltIdx < $stop; $meltIdx += 1) {
@alexpreynolds
alexpreynolds / rc.c
Last active March 28, 2021 03:08
Take reverse-complement of DNA string passed in via standard input
#include <stdlib.h>
#include <stdio.h>
/*
basemap[] works by storing a very small array that maps a base to
its complement, by dereferencing the array with the ASCII char's
decimal value as the index
(int) 'A' = 65;
(int) 'C' = 67;
@alexpreynolds
alexpreynolds / random-mtx.py
Created March 22, 2016 17:59
Generate 10k-row, 1k-column matrix of random integers between 1 and 100
#!/usr/bin/env python
from random import randint
for r in xrange(0, 10000):
print '\t'.join([str(x) for x in [randint(0, 100) for p in range(0, 1000)]])
@alexpreynolds
alexpreynolds / transpose.awk
Created March 22, 2016 18:01
Transpose matrix in awk
{
for (i = 1; i <= NF; i++) {
a[NR,i] = $i
}
}
NF > p { p = NF }
END {
for (j = 1; j <= p; j++) {
str = a[1,j]
for (i = 2; i <= NR; i++) {
@alexpreynolds
alexpreynolds / antisense.cc.sorted-by-netseq.top20.mtx
Created March 31, 2016 05:42
Antisense DNaseI ZNF524_C2H2_2 hits, sorted by NETseq density
window 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
chr6:28908856:28908857:ZNF524_C2H2_2:4.42341e-06:- 2 10 6 5 5 1 0 2 0 2 10 9 5 8 4 14 17 0 7 4 2 8 7 7 19 20 2 36 5 8 5 4 13 0 11 1 16 5 9 7 9 9 0 4 5 4 0 0 1 3 0 0 10 0 3 12 0 2 0 5 0 1 1 0 0 0 1 8 4 21 5 3 16 0 24 5 5 1 2 3 3 3 8 11 27 2 35 0 17 9 0 10 13 3 3 7 1 12 4 2 0 19 3 20 4 6 0 8 5 0
chr6:28863963:28863964:ZNF524_C2H2_2:4.42341e-06:+ 3 0 10 3 6 2 3 8 5 1 3 3 3 10 6 2 14 2 2 20 3 3 5 2 13 2 3 9 4 5 0 6 0 3 1 2 2 0 1 0 11 2 3 2 1 0 8 0 1 0 2 0 4 0 0 25 6 4 31 0 21 4 12 1 2 2 8 3 7 4 2 0 4 6 0 1 3 10 1 3 14 2 3 1 25 10 16 0 7 49 3 24 2 1 9 15 12
chr1:161582501:161582502:ZNF524_C2H2_2:8.44771e-06:- 17 10 18 2 7 0 1 0 0 0 0 0 4 16 6 16 15 12 0 18 8 3 8 5 10
@alexpreynolds
alexpreynolds / antisense.netseq.sorted-by-netseq.top20.mtx
Created March 31, 2016 05:45
Antisense NETseq ZNF524_C2H2_2 hits, sorted by NETseq density
window 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
chr6:28908856:28908857:ZNF524_C2H2_2:4.42341e-06:- 1 0 0 0 1 1 0 0 0 0 1 0 0 0 2 16 335 899 205 74 37 18 20 47 1637 1114 485 945 483 176 349 57 29 26 11 0 0 0 0 1 0 0 1 2 2 0 3 1 5 7 1 4 1 4 0 11 7 33 5 8 9 67 9 63 2 15 8 13 20 9 8 1 5 10 18 24 59 30 5 6 21 36 0 47 55 50 24 78 58 117 29 106 16 62 18 40 31 168 54 132 19 1 10 3 0 0 0 3 7 6 8 8 5 2
chr6:28863963:28863964:ZNF524_C2H2_2:4.42341e-06:+ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 13 65 128 30 31 46 1584 2970 214 80 32 126 0 0 0 0 0 0 0 0 0 2 2 0 3 2 4 1 0 5 1 1 1 6 22 19 1 4 10 67 7 55 3 13 9 3 13 15 8 2 6 15 15 19 76 20 26 7 22 39 0 44 85 102 58 53 41 16 34 112 11 50 56 25 35 35 209 30 49 24 17 7 4 0 0 3 2
@alexpreynolds
alexpreynolds / ucsc_pdf_bbox_parser.py
Created December 1, 2016 23:27
Extract the bounding box of the first, leftmost rectangle dividing labels and annotations in a PDF-formatted UCSC genome browser shot
#!/usr/bin/env python
import sys
from pdfminer.pdfparser import PDFParser
from pdfminer.pdfdocument import PDFDocument
from pdfminer.pdfpage import PDFPage
from pdfminer.pdfpage import PDFTextExtractionNotAllowed
from pdfminer.pdfinterp import PDFResourceManager
from pdfminer.pdfinterp import PDFPageInterpreter
from pdfminer.pdfdevice import PDFDevice
@alexpreynolds
alexpreynolds / json2tdv.py
Created January 6, 2017 22:14
Convert JSON string to tab-delimited output
#!/usr/bin/env python
import sys
import json
test_json_str = '''
[
{"name":"FOO", "chr":"chrN", "start":100, "stop":200},
{"name":"BAR", "chr":"chrN", "start":300, "
@alexpreynolds
alexpreynolds / mtx2json.py
Last active February 15, 2018 05:21
Convert a symmetric matrix to JSON for use with the Checkerboard web application
#!/usr/bin/env python
import sys
import json
ct = {}
ct_a = []
ctr = 0
for line in sys.stdin:
if ctr == 0: