I built a file where I have headers with generic IDs that identify multiple alignments and on the next rows the genome IDs that correspond to that alignment ID. Along with the genome IDs I have numbers that I would like to convert in percentages, adding the value of the percentage as a third column, according to the example below:
ORIGINAL FILE:
>Alignment_1
GCA_910584205.1 13
GCA_003584705.1 7
>Alignment_2
GCA_002361735.1 168
GCA_002492725.1 2880
GCA_002492725.1 2880
>Alignment_3
GCA_900540295.1 165
GCA_002490525.1 125
FINAL FILE:
>Alignment_1
GCA_910584205.1 13 65%
GCA_003584705.1 7 35%
>Alignment_2
GCA_002361735.1 168 3%
GCA_002492725.1 2880 49%
GCA_002492725.1 2880 49%
>Alignment_3
GCA_900540295.1 165 57%
GCA_002490525.1 125 43%
I know awk can be used to calculate the percentages of values in a column in comparison with the total value of the column but how can I get these percentages by groups of alignments delimited by the headers?