Skip to content

Instantly share code, notes, and snippets.

View molpopgen's full-sized avatar

Kevin R. Thornton molpopgen

View GitHub Profile
@molpopgen
molpopgen / isgz.cpp
Created February 20, 2014 20:45
A C++ function to check that a file both exists and is in .gz format.
/*
A function to check that a file both exists and is in .gz format.
It is done the easy way, using only C++ constructs instead of any lower-level calls
Requires the boost iostreams library
Programs compiled using this function need -lboost_iostreams
*/
@molpopgen
molpopgen / cppbinary.cc
Last active February 20, 2024 06:33
Basics of binary I/O in C++
/*
Example of how to write binary stuff in C++
Illustrates some of the various quirks/annoyances
*/
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
@molpopgen
molpopgen / bwapetrick1.sh
Last active August 29, 2015 13:56
Skip intermediate "sai" files via use of implicit pipes when doing paired-end alignment (Linux/bash)
#!sh
#Must be executed with bash shell.
#If sh bwapetrick1.sh fails, then say bash bwapetrick1.sh
#bwa 0.7.5a-r405
#samtools 0.1.19
LEFTREADS=NY42_06_21_2010_54_1.fastq.gz
RIGHTREADS=NY42_06_21_2010_54_2.fastq.gz
@molpopgen
molpopgen / behavior.cc
Last active August 29, 2015 13:56
Iterators != pointers, but the former are data types behaving like the latter. If iterators were pointers, they would be assignable and convertible from one another, which is not true.
/*
sizeof(iterator) and sizeof(pointer) are the same.
They also act the same vis-a-vis dereferencing.
But, they do not act the same with respect to traversal of a range
Note that this example forces iterator and pointer invalidation to occur.
Thus, the specifics of the output may vary with the optimization level
used to compile. On OS X Mavericks, -O2 provides cleaner output
@molpopgen
molpopgen / readbgz.cc
Created May 21, 2014 21:03
Writes binary data to a gzipped file
//g++ -o readbgz readbgz.cc -lboost_iostreams -lz
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/iostreams/device/file.hpp>
#include <boost/iostreams/filter/gzip.hpp>
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <vector>
@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 //
// //
//////////////////////////////////////////////////////////////////
@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 / 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 / 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 / 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