Skip to content

Instantly share code, notes, and snippets.

View clintval's full-sized avatar

Clint Valentine clintval

View GitHub Profile
$ffmpeg -i in.mov -pix_fmt rgb8 -r 10 output.gif && gifsicle -O3 output.gif -o output.gif
from typing import Any, Callable, Optional
class wait_callable_true(object):
"""Wait until a callable evaluates to a truthy statement, then continue.
This object can be used as a function or as a context manager.
Args:
callable: A function which should eventually return a truthy value.
call_rate: The rate at which to test the callable, optional.
import numpy as np
import scipy.stats as stats
__all__ = [
'gaussian_1d_mixture',
'gaussian_2d_mixture']
def gaussian_1d_mixture(arr, cov_factor=0.2):
"""A Gaussian kernel density estimation with a tuneable covariance factor.
from itertools import combinations, product
def hamming_circle(word, n, alphabet):
"""Create all words of hamming distance `n` in a given alphabet from a
target word.
Examples
---
>>> sorted(hamming_circle('abc', 0, 'abc'))
['abc']
from cyvcf2 import VCFReader
from snv_spectrum import Snv
reader = VCFReader(str(root / 'all.ann.vcf'))
samples = reader.samples
for variant in reader:
for sample, depth, alt_depth, gt_base in zip(
samples,
#!/bin/bash
#
# drawHelix.sh <input.fa>
#
# Reads a fasta input file and stream a B-Form DNA
# helix with the sequence to STDOUT
#
## __ __ __ ___
### |__) | / \ /__` \ / |\ | | /\ \_/
#### |__) | \__/ .__/ | | \| | /~~\ / \
@clintval
clintval / spinner.py
Created March 20, 2018 23:09
A non-blocking terminal spinner for Python
import sys
import threading
import time
# Really though just use a library for this:
# https://github.com/ManrajGrover/halo
#
class Spinner:
"""https://stackoverflow.com/a/39504463/3727678"""
busy = False
@clintval
clintval / get-karyotype-fasta-demo.sh
Created March 19, 2018 17:39
Grab karyotype assembly from a reference genome
# Pipe in the karyotype chromosomes
# Prefix each chromosome name with `chr` if necessary
# Slice the contigs from the source indexed FASTA with samtools
# Output to file
build="${build}"
echo {1..20} X Y M \
| xargs printf -- 'chr%s ' \
| xargs samtools faidx "${build}".fa \
@clintval
clintval / mutpos-model.py
Last active March 7, 2018 23:18
Mutpos utilities, a faux-object-oriented model but please use VCF
from Bio.Seq import Seq
from Bio.Seq import reverse_complement
dna_bases = ('A', 'C', 'G', 'T')
purines = ('A', 'G')
pyrimidines = ('C', 'T')
transitions = ('A>T', 'C>G', 'G>C', 'T>A')
transversions = ('A>C', 'A>G', 'C>A', 'C>T', 'G>A', 'G>T', 'T>C', 'T>G')
@clintval
clintval / pileup.py
Created March 7, 2018 23:13
An untested Python pileup parser - do not use
import re
import csv
import textwrap
import matplotlib.pyplot as plt
from collections import Counter
class ReadError(LookupError):
"""Raise this when a property of a read is called for and no data exists"""
pass