Skip to content

Instantly share code, notes, and snippets.

View molpopgen's full-sized avatar

Kevin R. Thornton molpopgen

View GitHub Profile
@molpopgen
molpopgen / edges.rs
Last active November 16, 2022 23:54
edges.rs
pub struct EdgeTableRow {
pub id: EdgeId,
pub left: Position,
pub right: Position,
pub parent: NodeId,
pub child: NodeId,
pub metadata: Option<Vec<u8>>,
}
@molpopgen
molpopgen / many_indepdendent_loci.py
Created November 24, 2021 23:17
Lots of indepdent loci w/exactly 1 mutation using msprime.
import demes
import demesdraw
import matplotlib.pyplot as plt
import msprime
import numpy as np
import tskit
dmodel = """
time_units: generations
demes:
@molpopgen
molpopgen / pickle2sqlite3.py
Created July 24, 2018 22:13
Store pickled data from Python into sqlite3 database and retrieve.
import sqlite3
import pickle
import codecs
x = {'a':1,2:'b'}
xp = pickle.dumps(x, -1)
xps = codecs.encode(xp, "base64").decode()
print(xps,type(xps),len(xps))
with sqlite3.connect("test.db") as conn:
@molpopgen
molpopgen / order.cc
Last active January 25, 2018 21:10
Example of an <algorithm>-like version of R's order.
// Usage:
// c++ -std=c++11 -o order order.cc
// ./order
//
// A "standard library*"-like implementation of R's order.
// To back-port this to C++98, one would need to
// replace the lambda closures with functors. But there's no need
// to do such silliness anymore.
//
// The implementation is in terms of sorting iterators and then
@molpopgen
molpopgen / fwdpy11_pytables.py
Last active October 5, 2017 19:42
WIP for fwdpy11 <-> PyTables interaction
# Test code writing fwdpy11
# pop data to hdf5 via PyTables.
# GOAL IS COMPRESSION!!!!
# Instead of using ragged arrays
# (not compressable), we use carrays,
# and simply concacenate gamete data.
# In longer-term, this would be
# abstracted into some sort of GameteTable
# class that interacts with an hdf5 object.
@molpopgen
molpopgen / RemoteJupyter.md
Last active February 19, 2022 22:05
SSH port forwarding and Jupyter

Problem

You want to use Jupyter remotely. X11 forwarding is too slow for this.

Solution

SSH port forwarding!

The recipe

@molpopgen
molpopgen / collate.sh
Last active August 29, 2015 14:25
Benchmarking scripts.
#!sh
##collect the simulation results. This may have to be run as 'bash collate.sh' on some systems
echo "Simulation L time mem" > results.txt
paste <(find . -name "*.time" -type f ! -size 0 | sed 's/\.\///' | cut -d"." -f 1,2 | sed 's/\./ /') <(find . -name "*.time" -type f ! -size 0 | xargs cat) | sort -n -k 2,3 >> results.txt
@molpopgen
molpopgen / doit.R
Last active August 29, 2015 14:21
Issue with Rcpp -- gcc vs clang++
library(Rcpp)
Sys.setenv("PKG_CXXFLAGS" = "-std=c++11")
sourceCpp("tuple.cc",verbose=TRUE)
@molpopgen
molpopgen / block1.cc
Last active December 19, 2022 10:03
File locking via boost::interprocess
#include <boost/interprocess/sync/file_lock.hpp>
#include <boost/interprocess/sync/scoped_lock.hpp>
#include <fstream>
int main( int argc, char ** argv )
{
std::ofstream o("monkey.txt",std::ios_base::app);
boost::interprocess::file_lock ol("monkey.txt");
@molpopgen
molpopgen / perm.cpp
Last active August 29, 2015 14:01
Making PLINK's permutation code "cluster-friendly". For v1.07. Replace the files in that version with these, then recompile.
//////////////////////////////////////////////////////////////////
// //
// PLINK (c) 2005-2008 Shaun Purcell //
// //
// This file is distributed under the GNU General Public //
// License, Version 2. Please see the file COPYING for more //
// details //
// //
//////////////////////////////////////////////////////////////////