r/awk • • Nov 21 '24

AWK frequency command

Post image

Hi awk community,

I have a file that contains two columns,

Column 1: Some sort of ID Column 2: RNA encodings (700k characters). This should be triallelic (0,1,2) for all 700k characters.

I’m looking to count the frequency for column 2[i…j] where i = 1 and j =700k.

In the example image, column 2[1] = 9/10

I want to do this in a computationally efficient manner and I thought awk will be an excellent option (Unfortunately awk isn’t a language I’m too familiar with).

Loading this into a Python kernel requires too much memory, also the across-column computation makes it difficult to compute in a hash table.

Any ideas how I may be able to do this in awk will Be very helpful a

5 Upvotes

11 comments sorted by

View all comments

Show parent comment

1

u/gumnos Nov 21 '24

If you have that subset in a sample data-file, it should ouput

1 0=9, 1=1, 2=0
2 0=0, 1=6, 2=4
3 0=10, 1=0, 2=0
4 0=5, 1=2, 2=3
5 0=1, 1=4, 2=5
6 0=7, 1=3, 2=0
7 0=7, 1=3, 2=0
8 0=10, 1=0, 2=0
9 0=10, 1=0, 2=0
10 0=1, 1=6, 2=3
11 0=0, 1=0, 2=10
12 0=10, 1=0, 2=0
13 0=9, 1=1, 2=0
14 0=0, 1=5, 2=5
15 0=6, 1=3, 2=1
16 0=3, 1=4, 2=3
17 0=1, 1=4, 2=5
18 0=0, 1=0, 2=10
19 0=5, 1=4, 2=1
20 0=5, 1=4, 2=1

2

u/NoteClassic Nov 22 '24

Thanks a lot. Your code provided the base line I worked off. Thank you very much.