#!/usr/bin/perl -w use strict; use List::Util qw(min max); die "Usage:\n\tperl $0 cds.fa/pep.fa > uniq_id.cdsfa\n" if(@ARGV!=1); my %gene; open IN ,$ARGV[0]||die $!; local $/=">"; ; while(){ chomp; my @a = split/\n/,$_; my $id = shift @a; my $seq = join("\n",@a); my $len = length(join("",@a)); $gene{$id}{$len}{$seq}=1; } local $/="\n"; close IN; foreach(sort keys %gene){ my $max = max keys %{$gene{$_}}; my @a = keys %{$gene{$_}{$max}}; my $seq = shift @a; print ">$_\n$seq\n"; }