get_longseq.pl 506 B

1234567891011121314151617181920212223242526272829
  1. #!/usr/bin/perl -w
  2. use strict;
  3. use List::Util qw(min max);
  4. die "Usage:\n\tperl $0 cds.fa/pep.fa > uniq_id.cdsfa\n" if(@ARGV!=1);
  5. my %gene;
  6. open IN ,$ARGV[0]||die $!;
  7. local $/=">";
  8. <IN>;
  9. while(<IN>){
  10. chomp;
  11. my @a = split/\n/,$_;
  12. my $id = shift @a;
  13. my $seq = join("\n",@a);
  14. my $len = length(join("",@a));
  15. $gene{$id}{$len}{$seq}=1;
  16. }
  17. local $/="\n";
  18. close IN;
  19. foreach(sort keys %gene){
  20. my $max = max keys %{$gene{$_}};
  21. my @a = keys %{$gene{$_}{$max}};
  22. my $seq = shift @a;
  23. print ">$_\n$seq\n";
  24. }