# $1=input file name
cat $1 | awk '{split($0,a,"_"); printf a[7] "_" a[8] "_" a[9] "_" a[10] "\t" a[3] "_" a[4] "_" a[5] "\t"; getline; print toupper($0)}' | sort -k3,3 -k2,2  -S10G | uniq -f1 > $1.unique1

# further remove identical sequences. This only removes 5000 reads. Most multimappers likely map to other non-genomic loci.
uniq -f2 $1.unique1 > $1.unique2

# convert to FASTA
awk '{print ">" NR ":" $2 ":" $1 ; print $3}' $1.unique2 > $1.unique2.fa

