fq1="$(realpath $R1)"
fq2="$(realpath $R2)"
dir="$(dirname $R1)"
fpath="$(basename $R1)"
#get the sample name and the prefix for the output R1 and R2 reads
samplename="$(cut -d'_' -f1 <<< $fpath)"
#get the length of the 11th read (in case the first few are a bit short). Method will vary depending if the reads are gzipped or not
if [ $extension == "gz" ]; then
fastq_length="$(zcat $fq1 | head -n 42 | sed -n '42p' | wc -c)"
else
fastq_length="$(sed -n '42p' $fq1 | wc -c)"
fi
REF=NC_020638.1_mitochondrial.fasta
srun mitoz all --fastq1 $fq1 --fastq2 $fq2 --fastq_read_length $fastq_length --outprefix $samplename --thread_number 16 --clade Chordata --genetic_code 2 --filter_taxa_method 1
#re-order assembly so all are anchored to a common reference.
srun python /ei/software/testing/mitoz/2.3/src/release_MitoZ_v2.3/useful_scripts/Mitogenome_reorder.py -f $samplename.result/work71.mitogenome.fa -r $REF