The problem:
I have multiple text files (.fas), which look like this:
file1.fas:
>species1
AICGICVIAGIAIYIAAICG
>species2
AICGIVVYICAGAYICAGCG
file2.fas:
>species1
AIG
>species2
GCI
I'm interested in counting the number of characters in the second line (it's the same across all the species in one file as they are aligned.
My current one liner:
for i in *.fas; do echo -n "$i," && grep -m 1 -A 1 '>' $i | tail -n 1 | wc -c; done;
This works to an extent but is counting one number higher than the actual number of characters, as it is counting the newline character. How do I fix this so it only counts the number of characters excluding newline characters?
Current output:
file1.fas,21
file2.fas,4
Desired output:
file1.fas,20
file2.fas,3
species2
regardless of where in the file it occurs?samtools
to create an index of the file and then simply read the length from the index file? Alternatively,infoseq
from EMBOSS or one of the many other existing tools for working with Fasta files?