Skip to content

Instantly share code, notes, and snippets.

View dnbaker's full-sized avatar

Daniel Baker dnbaker

View GitHub Profile
@dnbaker
dnbaker / set_base.c
Last active March 8, 2016 19:02
bam1_t sequence setting
/*
* :abstract: set the base in pSeq at index i in the read to the base in bSeq at index i in the read.
* These 8-bit integers are the points in memory returned by bam_get_seq(p) and bam_get_seq(b), respectively.
* :param: pSeq [uint8_t *]
* :param: bSeq [uint8_t *]
* :param: i [int/integral type]
*/
#define set_base(pSeq, bSeq, i) (pSeq)[(i)>>1] = ((bam_seqi(bSeq, i) << (((~i) & 1) << 2)) | (((pSeq)[(i)>>1]) & (0xf0U >> (((~i) & 1) << 2))))
/*
* :abstract: set the base at index i in the read to "N".
@dnbaker
dnbaker / get_qchars.py
Last active April 23, 2016 03:54
Get list of all quality scores found in quality strings in a bam
import pysam
from itertools import chain
def get_qchars(bampath):
return set(chain.from_iterable(set(c.qual) for
c in pysam.AlignmentFile(bampath)))
@dnbaker
dnbaker / kmer2str.h
Last active January 18, 2016 04:35
Decode kmer from 64-bit integer
#ifndef KMER2STR_H
#define KMER2STR_H
#include "stdint.h"
#ifndef num2nuc
# ifndef NUM2NUC_STR
# define NUM2NUC_STR "ACGTN"
# endif
# define num2nuc(x) NUM2NUC_STR[(uint8_t)x]
@dnbaker
dnbaker / ipow.h
Last active February 1, 2016 00:18 — forked from orlp/ipow.c
#ifndef FALL_THROUGH_IPOW_H
#define FALL_THROUGH_IPOW_H
#include "stdint.h"
static inline int64_t ipow(int32_t base, uint8_t exp) {
static const uint8_t highest_bit_set[] = {
0, 1, 2, 2, 3, 3, 3, 3,
4, 4, 4, 4, 4, 4, 4, 4,
5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5,
@dnbaker
dnbaker / gist:760d2cd79ae0fc0a67e8
Created March 15, 2016 02:05 — forked from debasishg/gist:8172796
A collection of links for streaming algorithms and data structures
  1. General Background and Overview
@dnbaker
dnbaker / hd.c
Created April 23, 2016 03:19
Hamming distance
/* Assumes that both strings are of equal length.
*
*/
int hd(char *a, char *b) {
int ret = 0;
while(*a) ret += (*a++ != *b++);
return ret;
}
@dnbaker
dnbaker / qchar_count.py
Created April 23, 2016 03:56
qchar counts
try:
from cytoolz import frequencies
except ImportError:
from collections import Counter as frequencies
# Works, but it's less than 3x as fast
# A simple pure python counter is twice as fast as Counter anyhow....
from itertools import chain
def get_qchars_counts(bampath):
'''
@dnbaker
dnbaker / tmux_local_install.sh
Last active July 26, 2016 23:50 — forked from ryin/tmux_local_install.sh
bash script for installing tmux without root access
#!/bin/bash
# Script for installing tmux on systems where you don't have root access.
# tmux will be installed in $HOME/local/bin.
# It's assumed that wget and a C/C++ compiler are installed.
# exit on error
set -e
TMUX_VERSION=1.8
@dnbaker
dnbaker / .bash_aliases
Created August 9, 2016 05:59
See diff for last commit
alias gdl="git diff $(git log -n 2 | grep commit | tail -n +2 | awk '{print $NF}')"