Order contig by size
1
0
Entering edit mode
5.5 years ago
Rox ★ 1.4k

Hi there !

Does anyone has a easy solution to order contig from an assembly by size ? For example, I want that contig1 is the largest, contig 2 is the second largest etc...

I can't find a convenient solution (maybe I'm not looking good enough..)

Thanks for your help !

Cheers,

Roxane

assembly script • 4.5k views
ADD COMMENT
0
Entering edit mode
ADD REPLY
0
Entering edit mode

Sorry didn't found it... Should I delete my post or marked it as answered ?

ADD REPLY
0
Entering edit mode

please,don't delete. just close it.

ADD REPLY
0
Entering edit mode

oh right! didn't realize this. But it seems that OP wants rename contigs too.

ADD REPLY
4
Entering edit mode
5.5 years ago

Since you ask an easy solution and you seem not a beginner. I introduce a fast and easy solution using seqkit, a handy FASTA/Q toolkits, link.

seqkit provides executable binaries for Linux/OS X/Windows, you just need download, decompress and immediately run.

Sample data:

$ cat contigs.fasta 
>contig1
aaaa
cccc
>contig2
cccccc
tttttt
>contigs
ggggg
ccc

Sorting using seqkit sort, contig sequences can be multi-line.

$ seqkit sort --by-length --reverse contigs.fasta
>contig2
cccccctttttt
>contig1
aaaacccc
>contigs
gggggccc

If you want to rename the FASTA header, then use seqkit replace:

$ seqkit sort --by-length --reverse contigs.fasta | seqkit replace --pattern '.+' --replacement 'Contig_{nr}'
>Contig_1
cccccctttttt
>Contig_2
aaaacccc
>Contig_3
gggggccc

Where {nr} is the number of record.

ADD COMMENT
0
Entering edit mode

I actually like your solution ! awk solution was working but in ascending order, I wanted decreasing order. And adding just a --reverse on the sort command didn't solved it so I was running out of solution.. I'm going to try seqkit thanks !

ADD REPLY
2
Entering edit mode

sort can be in reversed order: sort -k1,1nr

ADD REPLY
0
Entering edit mode

Thanks ! I was trying -rk1,1n

ADD REPLY
0
Entering edit mode

man sort is your friend.

ADD REPLY
0
Entering edit mode

Actually, I have checked the man.. Thanks for the acid comment

ADD REPLY
0
Entering edit mode

That was not an acid comment. It was a genuine suggestion (in case you did not know about man inline help for unix commands). It was in light of your comment above which indicated that you were making a minor formatting error for the sort command option.

ADD REPLY
0
Entering edit mode

Sorry, perceived that as ironic, my bad!

ADD REPLY
0
Entering edit mode

It worked perfectly fine using your tool, thanks !

ADD REPLY

Login before adding your answer.

Traffic: 1809 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