Skip to content

Instantly share code, notes, and snippets.

View klmr's full-sized avatar
📦
Making your R code easier to reuse

Konrad Rudolph klmr

📦
Making your R code easier to reuse
View GitHub Profile
@klmr
klmr / gist:3752679
Created September 19, 2012 22:14
tRNA gene
TATA.\{6,\}T[AG]G[CT]..A...G.\{33,\}G[AT]TC[AG]A..C.*TTTT
@klmr
klmr / check-md5.sh
Created October 12, 2012 11:10
Test checksum of gzipped FastQ files after download
#!/bin/bash
set -e
set -u
failed=0
for file in *.fq.gz; do
md5=$(gunzip -c "$file" | openssl md5 | cut -f2 -d " ")
gold=$(grep "${file/.gz/}" md5sums.txt | cut -f2)
if [ "$md5" != "$gold" ]; then
@klmr
klmr / string.hpp
Created October 12, 2012 17:21
Ultra-simple string class
#ifndef TEXT_STRING_HPP
#define TEXT_STRING_HPP
#include <algorithm>
#include <cstring>
#include <iterator>
#include <memory>
#include <iosfwd>
namespace text {
@klmr
klmr / trie.cpp
Created November 27, 2012 14:19
Anagram clustering using a trie
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <boost/container/vector.hpp>
struct TrieNode {
boost::container::vector<TrieNode> children;
std::vector<std::vector<std::string>::const_iterator> head;
@klmr
klmr / IsAssignableToGenericTypeTests.cs
Created November 30, 2012 09:23
Comprehensive test cases for the IsAssignableToGenericType test
using System;
using System.Collections.Generic;
namespace klmr {
// Version from http://stackoverflow.com/a/75502/1968
public class Test {
public static bool IsAssignableToGenericType(Type givenType, Type genericType) {
var interfaceTypes = givenType.GetInterfaces();
foreach (var it in interfaceTypes)
@klmr
klmr / gist:4250731
Created December 10, 2012 14:04
C++11 enum classes boilerplate
enum class dna_strand : char {
positive = '+',
negative = '-'
};
std::ostream& operator <<(std::ostream& out, dna_strand strand) {
return out << static_cast<char>(strand);
}
std::istream& operator >>(std::istream& in, dna_strand& strand) {
@klmr
klmr / count-nuc.sh
Last active December 10, 2015 18:38
Count nucleotides in a sequence (from file or standard input).
#!/usr/bin/env bash
set -e
set -u
input="${1-/dev/stdin}"
declare -A counts=(
[A]=0
[C]=0
@klmr
klmr / gist:4960666
Created February 15, 2013 14:23
Read-group extraction without temporary buffer
while (getline(in, line)) {
if (line.compare(0, 4, "@RG\t") != 0) continue;
size_t start = line.find("\tID:");
if (start == string::npos) continue;
start += 4;
size_t end = line.find("\t", start);
if (end == string::npos or end == start) continue;
gids.emplace(string.begin() + start, string.begin() + end);
// Or, in C++03:
//gids.insert(line.substr(start, end - start));
@klmr
klmr / foo.cpp
Created February 19, 2013 11:55
Ternary
result = x == "foo" ? foo() :
x == "bar" ? bar() :
x == "baz" ? baz() :
x == "qux" ? qux();
#!/usr/bin/env bash
source ~/.config/extpaths # For samtools
set -e
set -u
n=0
for bam in $*; do