#/******************************************************************************* # * Author : HaoTan # * Email : tanhao2013@foxmail.com # * Last modified : 2013-03-05 13:01 # * Filename : efa2fa.pl # * *****************************************************************************/ #!/usr/bin/perl use Bio::SeqIO; use Data::Dumper; die("perl $0 in.efasta >out.fasta\n")unless(@ARGV == 1); open(FH,"<$ARGV[0]"); my $e_seq = Bio::SeqIO->new( -format => 'Fasta', -fh => \*FH|| \*STDIN ); while((my $seq_obj = $e_seq->next_seq())){ my $id = $seq_obj->id; my $seq = $seq_obj->seq; my @block = split(/\{|\}/,$seq,); my $tseq = ""; foreach my $t (@block){ if($t =~ /,/){ my %hash = map{ $_ => length($_)} (split(/\,/,$t)); $tseq .= (sort{$hash{$b} <=> $hash{$a}}(keys %hash))[0]; }else{ $tseq .= $t; } } my $hn = (scalar(@block)-1)/2; my $len = length($tseq); $tseq =~ s/(.{100})/$1\n/ig; print ">$id\t$hn\t$len\n$tseq\n"; }