Question: Order Sequences By Number Of Times Found
8
gravatar for Pauln
9.3 years ago by
Pauln80
Pauln80 wrote:

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 • 1.6k views
ADD COMMENTlink modified 5.9 years ago by Biostar ♦♦ 20 • written 9.3 years ago by Pauln80

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

ADD REPLYlink written 9.3 years ago by Giovanni M Dall'Olio26k
22
gravatar for Andrew Su
9.3 years ago by
Andrew Su4.8k
San Diego, CA
Andrew Su4.8k wrote:

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 COMMENTlink modified 12 months ago by RamRS24k • written 9.3 years ago by Andrew Su4.8k

Yup, that about covers it.

ADD REPLYlink written 9.3 years ago by Chris Miller21k

i wish i could double up up

ADD REPLYlink written 9.3 years ago by hadasa1.0k

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

ADD REPLYlink written 9.3 years ago by Bilouweb1.1k

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 REPLYlink written 9.3 years ago by Andrew Su4.8k
9
gravatar for lexnederbragt
9.3 years ago by
lexnederbragt1.2k
Oslo, Norway
lexnederbragt1.2k wrote:

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 COMMENTlink modified 12 months ago by RamRS24k • written 9.3 years ago by lexnederbragt1.2k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 782 users visited in the last hour