g-language

SubOpt

Summary Included libraries Package variables Synopsis Description General documentation Methods

Summary
SubOpt - Odyssey Subroutine Input API
Package variables top
Globals (from use vars definitions)
@EXPORT
$VERSION
@EXPORT_OK
Privates (from my definitions)
$unknown = shift @_
$ref = \$ unknown
%data;
$new_gb = new G::Skyline('blessed')
Included modulestop
G::IO::Bioperl
G::Messenger
G::Skyline
strict
Inherit top
AutoLoader Exporter
Synopsistop
  use SubOpt;

&odyssey ($gb, -option=>"neat!", -file=>"fancy.txt", "oops");

sub odyssey{
opt_default(option => 'none', file => 'hoge.txt');
# Set default values. This is optional.

my @args = opt_get(@_);
# Parse options.

my $gb = opt_as_gb(shift @args);
# Get the input value as a G instance

my $last = shift @args;

print $gb->{SEQ} , "\n";
print "last: $last\n";
print "option: ", opt_val("option"), "\n";
print "file: ", opt_val("file"), "\n";
# Option values are accessed via opt_val().
}
Descriptiontop
  SubOpt parses the arguments given to a subroutine in a similar 
manner as GetOpt module.

Options are specified in the form: -option=>"hoge"
The above will input the value "hoge" with a key "option".
i.e. option with '-' is stored with the value pointed with '=>'.

supported methods:

opt_default(<option>=><value>)
This mehod sets default values for the options.
i.e. if the option is not specified, the value set with this method
is used. This method is optional.

The option name here should be enclosed in quotations, and do not
have to have a hyphen in the beginning.

eg. opt_default("option"=>"hoge");
#inputs default value of "hoge" for key "option"
#if the subroutine is called with -option, like
#&subroutine($gb, -option=>"boo");
#the option value will be overridden by "boo"

opt_get(@_)
This method parses the option arguments, stores the options in its
class, and returns the array of arguments that are not options.

eg. my @args = opt_get(@_);
#receives all arguments in @args, and all options are stored
#in SubOpt name space; therefore options are not passed to @args

opt_val(<option>)
This method returns the value of the given option. The option name
here should be enclosed in quotations.

eg. my $key = opt_val("key");
#gets the value for the option "key".
#It is recommended to store the option in a local variable
#instead of calling opt_val() everytime the option is used.
#This is for the prevention of the confusion of SubOpt name space
#in case SubOpt is called in cascade.

opt_as_gb(<$gb or $seq>)
This method automatically distinguish the variable from
a scalar sequence, reference of a sequence, and a G instance,
and returns the value as a G instance. If the input variable is a scalar
of reference of sequence, the G instance only contains the $gb->{SEQ} object.

If only the sequence portion of the G instance is required in a subroutine,
&subroutine($gb); and
&subroutine($gb->{SEQ}); and
&subroutine(\$gb->{SEQ}); and
&subroutine("atgc"); and
&subroutine(\$atgc); #$atgc = "atgc";
should all be used by the subroutine. In this case, calling opt_as_gb() as
my @args = opt_get(@_);
my $gb = opt_as_gb(shift @args);
will store the first argument in G instance form regardless of the type of
input argument. Therefore, the sequence information is accessible as
$gb->{SEQ} in the subroutine.
Methodstop
opt_as_gbNo descriptionCode
opt_defaultNo descriptionCode
opt_getNo descriptionCode
opt_valNo descriptionCode

Methods description


Methods code

opt_as_gbdescriptiontopprevnext
sub opt_as_gb {
    if ($##_ >= 1){
&msg_error("Error 1:\n Given value is not a valid sequence at SubOpt::opt_as_gb.\n"); return '';
}
opt_defaultdescriptiontopprevnext
sub opt_default {
    %data = (@_);
}
opt_getdescriptiontopprevnext
sub opt_get {
    my @args = @_;
    my @new_args = ();
    my $i = 0;
    my @bparray = ();

    while(defined $args[$i]){

	if (substr($args[$i], 0, 1) eq '-' && substr($args[$i], 1, 1) !~ /[0-9]/){
	    $data{substr($args[$i],1)} = $args[$i + 1];
	    $i += 2;
        }else{
	    if (ref $args[$i] =~ /Bio::Seq/){
		$bparray[$i] = new G::Skyline('blessed');
	        G::IO::Bioperl::convert($args[$i], $bparray[$i]);
		push(@new_args, $bparray[$i]);
	    }else{
		push(@new_args, $args[$i]);
	    }
	    $i ++;
	}
    }

    return @new_args;
}
opt_valdescriptiontopprevnext
sub opt_val {
    my $key = shift;
    return $data{$key};
}

General documentation

AUTHOR top
  Kazuharu Gaou Arakawa, gaou@g-language.org
SEE ALSO top
perl(1).