This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Order Sequences By Number Of Times Found

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

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

2 answers

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.

Yup, that about covers it.

i wish i could double up up

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

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

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

Log in to answer this question.