[Bioperl-l] [Bioperl -l] Passing argument via Command line

Marc Logghe Marc.Logghe at devgen.com
Mon Jul 18 08:43:25 EDT 2005


Hi Iain,
It is because you run 2 times the new method with Bio::SeqIO
new Bio::SeqIO->new( ... )

This is like writing:
my $input = Bio::SeqIO->new;
$input = $input->new( -file => $seqfile,-format=>'EMBL' );

When you take your script where you hardcoded $seqfile and you run as
'perl test_embl.pl HBB_HUMAN.BC007075.embl' everything works fine.
The first time new() is called, you actually do not pass any arguments.
So by default bioperl will look for the passed filename in @ARGV, which
was given. Using that filename it will try to guess the format. This
succeeds also. The 2nd call to new() also will succeed.
But when one runs it like 'perl test_embl.pl' then it fails, because the
first call to new() fails because it has no filename (@ARGV is empty),
so no chance to guess the format.
Your instantion should obviously look like:
my $input = Bio::SeqIO->new( -file => $seqfile,-format=>'EMBL');
HTH,
Marc


> -----Original Message-----
> From: bioperl-l-bounces at portal.open-bio.org 
> [mailto:bioperl-l-bounces at portal.open-bio.org] On Behalf Of 
> Iain Wallace
> Sent: Monday, July 18, 2005 1:55 PM
> To: bioperl-l at portal.open-bio.org
> Subject: [Bioperl-l] [Bioperl -l] Passing argument via Command line
> 
> Hi all,
> 
> I am wondering if anybody can help me. I am trying to open a 
> sequence file and parse it via Bio::SeqIO.
> 
> My script works fine if I pass the filename in via the 
> commandline e.g. perl test_embl.pl filename.
> but it doesn't work if i hard code the filename into the 
> script, and I cann't figure out why. 
> 
> The only two lines i change are:
> #my $seqfile = $ARGV[0];
> my $seqfile = "HBB_HUMAN.BC007075.embl";
> 
> Thanks for any help you can give me
> 
> Iain 
> 
> --The Script--
> use Bio::AlignIO;
> use Bio::SeqIO;
> use Bio::LocatableSeq;
> 
> #my $seqfile = $ARGV[0];
> my $seqfile = "HBB_HUMAN.BC007075.embl"; print $seqfile,"\n"; 
> my $input = new Bio::SeqIO->new( -file => $seqfile,-format=>'EMBL');
> 
> while ( my $seq = $input->next_seq() ) { print $seq->id,"\n"; 
> @features = $seq->get_SeqFeatures(); # just top level foreach 
> my $feat ( @features ) { if($feat->primary_tag eq "CDS"){ 
> $cds_obj= $feat->spliced_seq; $cds_seq=$cds_obj->seq; my 
> @translated = $feat->each_tag_value('translation');
> $translated_seq= $translated[0];
> print $translated_seq,"\n";
> }
> }
> 
> }



More information about the Bioperl-l mailing list