[Bioperl-l] Printing strings without return
Chris Dwan (CCGB)
cdwan at mail.ahc.umn.edu
Wed Mar 24 14:25:06 EST 2004
> I would like to ask how do I make one string from a Fasta file.
> In other words, from:
>
> >name
> actgtg
> tgctat
> accggg
I think the most "BioPerl" way to do what you describe is:
---------------
use Bio::SeqIO;
my $filename = shift;
my $in = Bio::SeqIO->new('-file' => "<$filename",
'-format' => 'fasta');
while (my $seq = $in->next_seq()) {
print join(" ", ( ">", $seq->id(), $seq->desc(), $seq->seq(), "\n"));
}
---------------
If you want the result to be a fasta file, but with a different width for
the sequence lines, you can get up to 32,766 characters per line as
fasta.pm is currently written:
---------------
use Bio::SeqIO;
my $filename = shift;
my $in = Bio::SeqIO->new('-file' => "<$filename",
'-format' => 'fasta');
my $out = Bio::SeqIO->new('-fh' => \*STDOUT,
'-format' => 'fasta',
'-width' => 32766);
while (my $seq = $in->next_seq()) {
$out->write_seq($seq);
}
---------------
A perl purist might use the following (from the command line) to create an
output free of "\n" characters.
perl -e "while (<STDIN>) { s/\n//g; print; }" < test.fsa
Note that in the case of your example, this gives:
> nameactgtgtgctataccggg
-Chris Dwan
More information about the Bioperl-l
mailing list