Order Sequences By Number Of Times Found
2
8
Entering edit mode
11.7 years ago
Pauln ▴ 80

I have a large (~1 million) list of sequences 15 bp long and would like to be able to:
1) Find the unique sequences
2) Find how many times each of these are in the list
3) Order the unique sequences by the number of times they occur

Any help greatly appreciated

sequence • 2.1k views
0
Entering edit mode

please, accept the answer that you think is the most correct. It is a fair way to thank the people who answered you.

22
Entering edit mode
11.7 years ago
Andrew Su 4.9k

Assuming your sequences are in a plain text file (called input.txt) with one sequence per line, then it's a unix one-liner...

sort input.txt | uniq -c | sort -k1nr > output.txt


the first column in output.txt will show the number of occurrences of the sequence in the second column, and the whole file will be sorted decreasing by column 2.

0
Entering edit mode

0
Entering edit mode

i wish i could double up up

0
Entering edit mode

I think it will be a very long long job in unix !

0
Entering edit mode

Just prototyped it on my not-particularly-beefy computer. For the specs above (1 million sequences, 15 bp long), the job took three seconds.

9
Entering edit mode
11.6 years ago
lexnederbragt ★ 1.3k

Faster than using unix sort, still a one-liner:

awk '{cnt[\$0]++}END{for (x in cnt){print cnt[x]"\t"x}}' input.txt|sort -k1nr > output.txt