#!/bin/bash

#Script to determine the insert length of a paired-end or mate-paired run using BWA alignment to reference

REF=$1
R1=$2
R2=$3
module load bwa
bwa index $REF

#This uses the first 100,000 reads
head -n 400000 $R1 > $R1.sample
head -n 400000 $R2 > $R2.sample
bwa aln -f $R1.sai $REF $R1.sample
bwa aln -f $R2.sai $REF $R2.sample
bwa sampe -f $R1.R2.sam $REF $R1.sai $R2.sai $R1.sample $R2.sample