Skip to content

Instantly share code, notes, and snippets.

View clintval's full-sized avatar

Clint Valentine clintval

View GitHub Profile
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,
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']
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 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.
$ffmpeg -i in.mov -pix_fmt rgb8 -r 10 output.gif && gifsicle -O3 output.gif -o output.gif
@clintval
clintval / flt3-itd-tcga.md
Created April 24, 2019 17:50
FLT3 ITDs in TCGA Data

Note: Build 37 coordinates.

TCGA-AB-2812   13 28608256 28608257 -  TCATATTCATATTCTCTGAAATCAACGTAGAAGTACTCATTATCTGAGGAG
TCGA-AB-2825   13 28608217 28608218 -  CCAAACTCTAAATTTTCTCTTGGAAACTCCCATTTGAGATCATATTCATATTCTCTGAAATCAACGTAGAAGTACTCATTATCTGAGGAGCCGGTATTCGTG
TCGA-AB-2830   13 28608242 28608243 -  ACTCCCATTTGAGATCATATTCATATTCTCTGAAATCAACGTAGAAGTACTCATTACCCCCTCGGGGGG
TCGA-AB-2836   13 28608267 28608268 -  TTCTCTGAAATCAACGTAGAAGTACTCATTATC
TCGA-AB-2840   13 28608248 28608249 -  ATTTGAGATCATATTCAT
TCGA-AB-2844   13 28608214 28608215 -  TTACCAAACTCTAAATTTTCTCTTGGAAACTCCCATTTGAGATCATATTCATATTCTCTGAAATCAACGTAGAAGTACTCATTATCT
TCGA-AB-2853   13 28608268 28608269 -  TCTCTGAAATCAACGTAG
@clintval
clintval / type-safe-metric.py
Created May 9, 2019 21:18
Type Safe Metric (Don't look at this... sandbox)
from types import MethodType
class TypeSafeAttribute(object):
def _type_of(self, attr):
if not self._has_attr(attr):
raise ValueError(f'No attribute defined as annotation: {attr}')
return self.__annotations__[attr]
def _has_attr(self, attr):
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
/** Implicit methods for [[Template]] objects. */
implicit class TemplateUtil(val t: Template) {
private def tagValue[A](records: Iterator[SamRecord], tag: String): Iterator[Option[A]] = records.map(_.get[A](tag))
def bestEditDistanceToReference(t: Template): Option[Int] = tagValue[Int](t.allReads, SAMTag.NM.name).min
def worstEditDistanceToReference(t: Template): Option[Int] = tagValue[Int](t.allReads, SAMTag.NM.name).max
def bestAlignmentScore(t: Template): Option[Int] = tagValue[Int](t.allReads, SAMTag.AS.name).max
def worstAlignmentScore(t: Template): Option[Int] = tagValue[Int](t.allReads, SAMTag.AS.name).min
}
@clintval
clintval / CommandLineTool.scala
Last active June 13, 2019 02:09
A small demo for prototyping shell utility helpers and trait abstraction
package com.clintval.misc
trait CommandLineTool {
val Executable: String
def exec(args: String*): ProcessBuilder = { new ProcessBuilder(Executable +: args: _*) }
}
trait Testable {
self: CommandLineTool =>
val TestCommand: Seq[String]