#!/bin/sh
set -eu

if [ $# == 0 ]; then
	set `</dev/stdin`
fi

for i; do
	echo $i
	samtools view `grep -w ^$i sample-bam |cut -f2` `<regions` \
		|gzip >$i.sam.gz
done
