You mention needing/wanting to use bash, but if you tried something, you should show it along with any error messages.
Linearize your sequences:
awk '/^>/ {printf("\n%s\n",$0);next; } { printf("%s",$0);} END {printf("\n");}' < infile.fa > infile_single.fasta
Python:
#!/usr/bin/env python
import sys, itertools
def comp_seqs(a, b, i):
mismatch = []
mismatch.append(i)
one = list(a)
two = list(b)
for n in range(len(one)):
if one[n] != 'X' and two[n] != 'X':
if one[n] != '*' and two[n] != '*':
if one[n] != '-' and two[n] != '-':
if one[n] != two[n]:
mismatch.append(two[n] + str(n+1) + one[n])
return mismatch
with open(sys.argv[1], 'r') as f:
myseqs = []
for line in f:
if line.startswith(">"):
myseqs.append((line.strip().split('>')[1].split(' ')[0], next(f).strip()))
target = myseqs[-1]
myseqs.remove(target)
with open(sys.argv[1].split('.fasta')[0] + '_mm.txt', 'w') as out:
results = []
for i in myseqs:
vs = comp_seqs(i[1], target[1], i[0])
results.append(vs)
for x in itertools.izip_longest(*sorted(results), fillvalue=''):
print >> out, '\t'.join(str(i) for i in x)
Save as comp_seqs.py, run as python comp_seqs.py in_file.fasta. If you have lots of FASTA to compare, use a for loop in your terminal:
for file in *.fasta; do python comp_seqs.py $file; done