I have been trying to write a code using BioPerl that will query Genbank for a specific protein and then print the results to a fasta file. So far the code I have works and I can print the results to the screen, but not to a file. I have done lots of researching on the BioPerl website and other sources (CPAN, PerlMonks, etc.) but I have not found anything that can solve my problem. I understand how to read something from a file and then print the output to a new file (using SeqIO), but the problem I am having seems to be that what I want the program to read is not stored in a text or FASTA file, but is the result of a database query. Help? I am very much a beginner, new to Perl/BioPerl and programming in general.
Here is the code I have so far:
#!usr/bin/perl
use Bio::DB::GenBank;
use Bio::DB::Query::GenBank;
use Bio::Seq;
$query = "Homo sapiens[ORGN] AND TFII-I[TITL]";
$query_obj = Bio::DB::Query::GenBank->new(-db => 'protein', -query => $query);
$gb_obj = Bio::DB::GenBank->new;
$stream_obj = $gb_obj->get_Stream_by_query($query_obj);
while ($seq_obj = $stream_obj->next_seq)
{print $seq_obj->desc, "\t", $seq_obj->seq, "\n";
}
So, what I want to do in the last line is instead of printing to the screen, print to a file in fasta format.
Thanks, ~Jay