[Bioperl-l] Newbie question: fasta output to string

Marc Logghe MarcL@DEVGEN.com
Mon, 28 May 2001 15:43:17 +0200


Thanks Ewan, for your fast response, but I am afraid that was not exactly
what I meant.
For the moment I am reformatting sequences in the exact way you suggest, but
the thing is you always have to deal with these file handles. I had
something else in mind, like the 'layout'-method of the PreSeq.pm module.
The thing is I need the formatted sequence (fasta, genbank,... ) in a string
so that I can ad some highlighting by inserting some HTML tags before the
output is sent to the browser. What I have done up to now, is something like
this:
# reformat sequence
open (OUT, ">$outfile");
$out = Bio::SeqIO->new(-fh => \*OUT, '-format' => 'Genbank');
$out->write_seq($seq); # $seq is a Bio::Seq or Bio::RichSeq object
close OUT;
# read in Genbank sequence again
local $/ = undef;
open (FILE, "<$outfile") or die("Cannot open $outfile: $!\n");
my $genbank = (<FILE>);
close (FILE);
# add some tags
$genbank = colour($genbank, $pre, $post, $type, $label);


You see what I mean, you first have to write a file and than open it again
to be able to catch your string
instead of something like:
my $genbank = $seq->layout('fasta');
As far as I know, the PreSeq.pm module was the 'beta' version of the Seq.pm
module, where the layout method apparently has been removed.
Marc






-----Original Message-----
From: Ewan Birney [mailto:birney@ebi.ac.uk]
Sent: Monday, May 28, 2001 2:30 PM
To: Marc Logghe
Cc: 'bioperl-l@bioperl.org'
Subject: Re: [Bioperl-l] Newbie question: fasta output to string


On Mon, 28 May 2001, Marc Logghe wrote:

> Hi,
> I am currently trying to find my way in BioPerl an playing around a
little.
> I struck into the following 'problem' (at least for me): you can easily
> convert a sequence from, let's say  raw to fasta using SeqIO via a file
> handle but I did not find how to get the output into a string variable
> directly without using a file handle. On the other hand I could find this
> line in Blast.pm: $hsp->seq('query')->layout('fasta'). The seq method
should
> return a Bio::Seq object but this object does not 'can' this method.
> Can somebody please help me out ?

here we go:

$seqio = Bio::SeqIO->new( -format => 'fasta', -file => 'myfile');
$seq = $seqio->next_seq; # first sequence from teh file

# $seq is a Bio::Seq object

print "sequence as string is ",$seq->seq,"\n";
print "first 10 residues are ",$seq->subseq(1,10),"\n";
print "name (id) is ",$seq->id,"\n";


For more info, look at the Bio::Seq documentation, ie

perldoc Bio::Seq 



(assumming you have installed Bioperl, not just made PERL5LIB point at it)



> Thanks a lot and keep up the good work
> Marc
> _______________________________________________
> Bioperl-l mailing list
> Bioperl-l@bioperl.org
> http://bioperl.org/mailman/listinfo/bioperl-l
> 

-----------------------------------------------------------------
Ewan Birney. Mobile: +44 (0)7970 151230, Work: +44 1223 494420
<birney@ebi.ac.uk>. 
-----------------------------------------------------------------