use Bio::Seq;
use Bio::SeqIO;
while(my $fname = shift) {
open(INSEQ, "<$fname") or die $!;
my $seq;
## Grab all the sequence in a single string
while(<INSEQ>) {
chomp;
$seq .= $_;
}
close INSEQ;
my $fname =~ s{\.txt}{}; # strip .txt
## Create a new Bio::Seq object with your sequence
my $seqobj = Bio::Seq->new(-display_id => $fname,
-seq => $seq
);
## Write it out to filename.fa
my $outfile = $fname . ".fa";
my $seqout = Bio::SeqIO->new(-format => 'fasta',
-file => "> $outfile",
);
$seqout->write_seq($seqobj);
}
It'll do exactly what you asked. Plus, just change 'fasta' to some other format, and it will convert that too. |