Skip to content

Instantly share code, notes, and snippets.

🔬
hacking genomic data compression

Konrad Rudolph klmr

🔬
hacking genomic data compression
Block or report user

Report or block klmr

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@klmr
klmr / relatedness.r
Created Nov 12, 2019
Average number of shared alleles between two siblings
View relatedness.r
n_genes = 20000
n = 100
relatedness = replicate(n, {
child1 = sample(c('mother', 'father'), n_genes, replace = TRUE)
child2 = sample(c('mother', 'father'), n_genes, replace = TRUE)
mean(child1 == child2)
})
mean(relatedness)
@klmr
klmr / freq_table.cpp
Created Oct 23, 2019
Frequency table and mode calculation
View freq_table.cpp
#include <algorithm>
#include <initializer_list>
#include <iostream>
#include <iterator>
#include <string_view>
#include <type_traits>
#include <unordered_map>
namespace stats {
@klmr
klmr / errors.r
Last active Aug 30, 2019
Simple error handling with subclasses in R. Code is a direct port of Python code from https://codereview.stackexchange.com/q/225419/308
View errors.r
os_error = function (message, call = NULL) {
class = c('os_error', 'error', 'condition')
structure(list(message = message, call = call), class = class)
}
value_error = function (message, call = NULL) {
class = c('value_error', 'error', 'condition')
structure(list(message = message, call = call), class = class)
}
@klmr
klmr / Calculator.cs
Created Mar 6, 2019
Workaround for missing numeric type constraints in C# — https://stackoverflow.com/q/32664/1968
View Calculator.cs
using System;
using System.Collections.Generic;
namespace OperatorTest {
public interface ICalculator { }
public interface ICalculator<T> : ICalculator {
T Add(T a, T b);
T Divide(T a, T b);
T Multiply(T a, T b);
@klmr
klmr / inspector-stylesheet.css
Created Feb 27, 2018
Open the inspector and add the following as a new CSS rule (once you’ve added any rule, you can subsequently edit the inspector stylesheet found under “Sources” on Chrome)
View inspector-stylesheet.css
.blob-code span:before {
background: #fdfd9c;
color: #a2a2a2;
content: attr(class);
font-family: sans-serif;
font-size: 0.7em;
padding: 0 0.2em;
vertical-align: middle;
}
@klmr
klmr / look-ma-no-downcasts.cs
Last active May 28, 2019
Using generic interfaces in class hierarchies without downcasts (discussed on https://softwareengineering.stackexchange.com/a/366666/2366)
View look-ma-no-downcasts.cs
using System;
using Color = System.Drawing.Color;
namespace CsTest {
// Generic interfaces. // (1)
interface IEquatable<in T> {
bool Equals(T other);
}
interface ICloneable<out T> {
View problems.md
  • Invalid signature void main() (… I mean, seriously?!)
  • Missing namespace qualifiers throughout
  • Missing include for accumulate
  • Missing ) in accumulate call
  • Invalid arguments to accumulate call:
    • init missing
    • op has wrong function type (expected (T, T) -> T; got (T) -> void)
    • — in fact, it seems they actually meant std::for_each.
  • … but using std::accumulate correctly would have been way easier, without a gratuitous lambda.
@klmr
klmr / summary-tibble.r
Last active Feb 12, 2018
Summarise a column in a (grouped) tibble
View summary-tibble.r
summary.tbl_df = function (object, ...) {
dots = rlang::quos(...)
stopifnot(length(dots) == 1)
name = rlang::quo_name(dots[[1]])
do(object, as_data_frame(as.list(summary(.[[name]]))))
}
@klmr
klmr / tmup
Last active Feb 6, 2018 — forked from simonjbeaumont/tmup
Update bash to latest tmux environment on reattaching.
View tmup
#!/bin/bash
tmup() {
local IFS=$'\n'
for line in $(tmux showenv -t $(tmux display -p '#S')); do
case $line in
-*) unset ${line:1} ;;
*) export $line ;;
esac
done
View group-table-cols.r
#' Apply a function over groups of columns.
grouped_columns_apply = function (data, width, fun) {
# Generate the group indices for the columns (see below).
group_indices = group_indices(ncol(data), width)
# For each group, apply `fun` to the columns of its indices.
results = lapply(group_indices, function (indices) fun(data[, indices, drop = FALSE]))
bind_cols(results)
}
# If the number of columns is always evenly divisible by the width, the following
You can’t perform that action at this time.