Skip to content

Instantly share code, notes, and snippets.

View molpopgen's full-sized avatar

Kevin R. Thornton molpopgen

View GitHub Profile
@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 / 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 / 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 / cppbinary.cc
Last active February 2, 2026 07:27
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 / 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
*/