Last active
December 10, 2015 18:38
-
-
Save klmr/4475683 to your computer and use it in GitHub Desktop.
Count nucleotides in a sequence (from file or standard input).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -e | |
set -u | |
input="${1-/dev/stdin}" | |
declare -A counts=( | |
[A]=0 | |
[C]=0 | |
[G]=0 | |
[T]=0) | |
while read line < "$input"; do | |
for nuc in A C G T; do | |
counts[$nuc]=$((${counts[$nuc]} + | |
$(sed "s/[^$nuc]//g" <<< "$line" | xargs echo -n | wc -c))) | |
done | |
done | |
for nuc in ${!counts[@]}; do | |
echo "$nuc ${counts[$nuc]}" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment