I searched but couldn't find a solution to my problem. I have a file containing strings of the letters A
, T
, C
, and G
(representing DNA sequences) as follows:
$ cat species_gene
>genus_1_species_1
TTGGATATTGAGTTACATACATATGATTTGGGAATGGAGAACCGAGATAAGACTGAAGATCAAGTCACAATTGATTGTGC
TAATGCTGTCAAGAAATACAATGTCGGCATCAAATGTGCAACTATTACTCCTGATGAAAATCGAGTTGAGGAGTTCAAGC
>tribe_1_species_1
CTGGATATAGAGTTGCACACATACGATCTGGGAATGGAAAACCGCGACAAGACTGATGACCAAGTCACAATCGATTGCGC
CAACGCGATTAAAAAATACAACGTTGGAATTAAGTGCGCGACCATCACTCCCGACGAGAAGAGAGTCGAGGAATTCAAGC
>species_2
CTTGATATTGAACTACACACCTATGATTTGGGAATGGAATACCGCGATAAAACTGATGACCAAGTCACAATTGACTGCGC
KAATGCTATTAAGAAATACAATGTTGGTATTAAGTGCGCTACCATAACTCCAGATGAAAAAAGAGTTGAAGAATTCAAAC
I would like to count the number of letters in the strings following the header >genus_1_species_1
until the next header. In this case, the length of the following strings, equal to 160:
TTGGATATTGAGTTACATACATATGATTTGGGAATGGAGAACCGAGATAAGACTGAAGATCAAGTCACAATTGATTGTGC
TAATGCTGTCAAGAAATACAATGTCGGCATCAAATGTGCAACTATTACTCCTGATGAAAATCGAGTTGAGGAGTTCAAGC
I would like to use awk and use >
as the Record Separator and line-breaks as the Field Separators, and subsequently count the number of fields (i. e. lines), starting from the second line of the record.
I used the following command:
$ awk 'BEGIN {RS=">"} NR==2 {print length}' species_gene
I obtained 180 (the number of characters of the first record). The output I'd like to get is 160 (the length of the first record, starting from the second line). I tried the following one to discard the header:
$ awk 'BEGIN {RS=">"; FS="\n"} NR==2 {if (NF!=1) {length}}' species_gene
I would be glad if someone could help me.
>
line and the second one? … … … … … … … … … P.S. Using>
as your shell prompt when you have>
s in your data is really confusing.