Add comparator based on Needleman-Wunsch score
[autophylo.git] / cmp_diff / cmp.sh
bloba14c7f37cdf6dc703f46359c1979595916bc7014
1 #!/bin/sh
2 # The diff-based DNA file comparator.
4 filea="$1"
5 numa="$2"
6 fileb="$3"
7 numb="$4"
8 scratch="$5/cmp_diff"
10 echo "$filea - $fileb" >&2
12 mkdir -p "$scratch"
13 [ -e "$scratch/$numa.dna" ] || cp "$filea" "$scratch/$numa.dna"
14 [ -e "$scratch/$numb.dna" ] || cp "$fileb" "$scratch/$numb.dna"
15 srcdir="$(pwd)"
16 cd "$scratch"
18 sed -e 's/./&\n/g' <"$numa.dna" >"$numa.dnal"
19 sed -e 's/./&\n/g' <"$numb.dna" >"$numb.dnal"
20 all_lines="$(cat "$numa.dnal" "$numb.dnal" | wc -l)"
21 diff -c "$numa.dnal" "$numb.dnal" | grep -i '^[+-\!] [actg]' >diff
22 diff_lines=$(($(grep -c "^[+-]" diff) + $(grep -c "^!" diff)/2))
24 echo "$diff_lines / $all_lines" | bc -l