3 See the NOTICE file distributed with
this work
for additional information
4 regarding copyright ownership.
6 Licensed under the Apache License, Version 2.0 (the
"License");
7 you may not use
this file except in compliance with the License.
8 You may obtain a copy of the License at
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an
"AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License
for the specific language governing permissions and
16 limitations under the License.
23 Please email comments or questions to the
public Ensembl
24 developers list at <http:
26 Questions may also be sent to the Ensembl help desk at
43 my ( $start, $end, $strand ) =
44 rearrange( [
'START',
'END',
'STRAND' ], @_ );
47 bless( {
'start' => $start,
'end' => $end,
'strand' => $strand },
53 This is derived from the Bio::Root module in BioPerl. The _rearrange
54 object method taken from BioPerl has been renamed rearrange and is now
55 a
static class method. This method was originally written by Lincoln
56 Stein, and has since been refactored several times by various people (as
59 It is recommended that this package be used instead of inheriting
60 unnecessarily from the
Bio::EnsEMBL::Root or Bio::Root object.
72 # Interface with some of the module function XS reimplementation
74 # If Bio::EnsEMBL::XS is installed, assign the function glob to
75 # the XS counterpart, otherwise assign to the original function
79 if (eval { require Bio::EnsEMBL::XS; 1 }) {
80 *rearrange = \&Bio::EnsEMBL::XS::Utils::Argument::rearrange;
82 *rearrange = \&rearrange_pp;
89 use vars qw(@ISA @EXPORT);
92 @EXPORT = qw(rearrange);
98 Usage : rearrange( array_ref, list_of_arguments)
99 Purpose : Rearranges named parameters to requested order.
101 : rearrange([qw(SEQUENCE ID DESC)],@param);
102 : Where @param = (-sequence => $s,
105 Returns : @params - an array of parameters in the requested order.
106 : The above example would
return ($s, $i, $d)
107 Argument : $order : a reference to an array which describes the desired
108 : order of the named parameters.
109 : @param : an array of parameters, either as a list (in
110 : which
case the
function simply returns the list),
111 : or as an associative array with hyphenated tags
112 : (in which
case the
function sorts the values
113 : according to @{$order} and returns that
new array.)
114 : The tags can be upper, lower, or mixed case
115 : but they must start with a hyphen (at least the
116 : first one should be hyphenated.)
117 Source : This
function was taken from CGI.pm, written by Dr. Lincoln
118 : Stein, and adapted
for use in Bio::Seq by Richard Resnick and
119 : then adapted
for use in Bio::Root::Object.pm by Steve A. Chervitz.
120 : This has since been adapted as an exported
static method in
this
123 : This method may not be appropriate for method calls that are
124 : within in an inner loop if efficiency is a concern.
126 : Parameters can be specified using any of these formats:
127 : @param = (-name=>'me', -color=>'blue');
128 : @param = (-NAME=>'me', -COLOR=>'blue');
129 : @param = (-Name=>'me', -Color=>'blue');
130 : A leading hyphenated argument is used by this function to
131 : indicate that named parameters are being used.
132 : Therefore, a ('me', 'blue') list will be returned as-is.
134 : Note that Perl will confuse unquoted, hyphenated tags as
135 : function calls if there is a function of the same name
136 : in the current namespace:
137 : -name => 'foo' is interpreted as -&name => 'foo'
139 : For ultimate safety, put single quotes around the tag:
140 : ('-name'=>'me', '-color' =>'blue');
141 : This can be a bit cumbersome and I find not as readable
142 : as using all uppercase, which is also fairly safe:
143 : (-NAME=>'me', -COLOR =>'blue');
145 : Personal note (SAC): I have found all uppercase tags to
146 : be more managable: it involves less single-quoting,
147 : the code is more readable, and there are no method naming
149 : Regardless of the style, it greatly helps to line
150 : the parameters up vertically for long/complex lists.
158 if ( $order eq
"Bio::EnsEMBL::Utils::Argument" ) {
159 # skip object if one provided
163 # If we've got parameters, we need to check to see whether
164 # they are named or simply listed. If they are listed, we
165 # can just return them.
166 unless ( @_ && $_[0] && substr( $_[0], 0, 1 ) eq
'-' ) {
170 # Push undef onto the end if % 2 != 0 to stop warnings
171 push @_,undef unless $#_ %2;
174 #deletes all dashes & uppercases at the same time
175 (my $key = shift) =~ tr/a-z\055/A-Z/d;
176 $param{$key} = shift;
179 # What we intend to do is loop through the @{$order} variable,
180 # and for each value, we use that as a key into our associative
181 # array, pushing the value at that key onto our return array.
182 return map { $param{uc($_)} } @$order;