Skip to content

Instantly share code, notes, and snippets.

@rknx
Created October 13, 2022 05:19
Show Gist options
  • Save rknx/3d3ad3b93ad963be84d7f2840486e07f to your computer and use it in GitHub Desktop.
Save rknx/3d3ad3b93ad963be84d7f2840486e07f to your computer and use it in GitHub Desktop.
Pairwise mismatch count from multifasta alignment
#!/bin/bash
#########################################
# Anuj Sharma #
# rknx@outlook.com #
# 2022-10-13 #
#########################################
# Usage: FastaToSNPCount.sh <input.fasta>
awk -vRS=">" -vFS="\n" -vOFS="\t" '
{ a[$1] = $2; next}
END{
for (i in a) {printf "\t%s", i}
for (i in a){
printf "\n%s", i;
for (j in a) {
mis=0
for (k=1; k<length($2); k++){
if (substr(a[i], k, 1) != substr(a[j], k, 1)){ mis++ }
}
printf "\t%s", mis;
}
}
print "";
}
' $1
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment