#!/bin/bash

EXPERIMENT=demo

SAMPLES=`cut -f1 samples.tsv | tail -n +2`

echo ""
echo "Samples are set as:"
echo ""
echo $SAMPLES
echo ""
echo ""
date


cut -f1,2 samples.tsv > bamf12
echo "FILE" > bamf3
i=0
for sample in ${SAMPLES[@]}
do
	sampledir=$(echo "${EXPERIMENT}_s_${sample}")
	samplelabel=${EXPERIMENT}_s_${sample}

	cd ${sampledir}
	echo "Now in directory ${sampledir} ..."
	$rws make cleanup
	$rws make finishup
	echo "`pwd`/${samplelabel}.bam" >> ../bamf3
	cd ..
	echo "... done"
	((++i))
done
paste bamf12 bamf3 > bamfiles.tsv
\rm bamf12 bamf3
echo ""
echo ""
echo "... all done!"
echo ""
echo "The final alignment files are in the sample directories and listed"
echo "in bamfiles.tsv (which can be used as input to TSRchitect; see"
echo "https://github.com/vpbrendel/TSRchitect/wiki/FAQ."
echo ""
date
