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
ADD COMMENT
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.

ADD REPLY
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.

ADD COMMENT
0
Entering edit mode

Yup, that about covers it.

ADD REPLY
0
Entering edit mode

i wish i could double up up

ADD REPLY
0
Entering edit mode

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

ADD REPLY
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.

ADD REPLY
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
ADD COMMENT

Login before adding your answer.

Traffic: 2476 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6