| 1 | =head1 NAME | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | Bio::DB::GFF::Util::Rearrange - rearrange utility | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | use Bio::DB::GFF::Util::Rearrange 'rearrange'; | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | my ($arg1,$arg2,$arg3,$others) = rearrange(['ARG1','ARG2','ARG3'],@args); | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | This is a different version of the _rearrange() method from | ||||||||||||||||||||||||||||
| 14 | Bio::Root::Root. It runs as a function call, rather than as a method | ||||||||||||||||||||||||||||
| 15 | call, and it handles unidentified parameters slightly differently. | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | It exports a single function call: | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | =over 4 | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | =item @rearranged_args = rearrange(\@parameter_names,@parameters); | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | The first argument is an array reference containing list of parameter | ||||||||||||||||||||||||||||
| 24 | names in the desired order. The second and subsequent arguments are a | ||||||||||||||||||||||||||||
| 25 | list of parameters in the format: | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | (-arg1=>$arg1,-arg2=>$arg2,-arg3=>$arg3...) | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | The function calls returns the parameter values in the order in which | ||||||||||||||||||||||||||||
| 30 | they were specified in @parameter_names. Any parameters that were not | ||||||||||||||||||||||||||||
| 31 | found in @parameter_names are returned in the form of a hash reference | ||||||||||||||||||||||||||||
| 32 | in which the keys are the uppercased forms of the parameter names, and | ||||||||||||||||||||||||||||
| 33 | the values are the parameter values. | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | =back | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | =head1 BUGS | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | None known yet. | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | L<Bio::DB::GFF>, | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | Lincoln Stein E<lt>lstein@cshl.orgE<gt>. | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | Copyright (c) 2001 Cold Spring Harbor Laboratory. | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | This library is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||
| 52 | it under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | =cut | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | package Bio::DB::GFF::Util::Rearrange; | ||||||||||||||||||||||||||||
| 57 | 1 | $Bio::DB::GFF::Util::Rearrange::VERSION = '1.7.8'; | |||||||||||||||||||||||||||
| 58 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 59 | 1 | require Exporter; | |||||||||||||||||||||||||||
| 60 | 1 | ▶ | use vars qw(@EXPORT @EXPORT_OK); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 61 | 1 | ▶ | use base qw(Exporter); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 62 | 1 | @EXPORT_OK = qw(rearrange); | |||||||||||||||||||||||||||
| 63 | 1 | @EXPORT = qw(rearrange); | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | # default export | ||||||||||||||||||||||||||||
| 66 | 0 | ▶ | sub rearrange { | ||||||||||||||||||||||||||
|
Subroutine
rearrange: not called CC=11 SCAR=48.8
Pod
documented
| |||||||||||||||||||||||||||||
| 67 | 0 | my($order,@param) = @_; | |||||||||||||||||||||||||||
| 68 | 0 | ▶ | return unless @param; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | 0 | my %param; | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 0 | ▶ | if (ref $param[0] eq 'HASH') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | 0 | %param = %{$param[0]}; | |||||||||||||||||||||||||||
| 73 | } else { | ||||||||||||||||||||||||||||
| 74 | 0 | ▶ | return @param unless (defined($param[0]) && substr($param[0],0,1) eq '-'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $param[0] and substr($param[0], 0, 1) eq "-"
MC/DC0%0/2
defined $param[0] and substr($param[0], 0, 1) eq "-"
defined $param[0]
substr($param[0], 0, 1) eq "-"
Truth table0%0/3
A and B
A= defined $param[0]B= substr($param[0], 0, 1) eq "-"
| |||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 0 | my $i; | |||||||||||||||||||||||||||
| 77 | 0 | ▶ | for ($i=0;$i<@param;$i+=2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | 0 | $param[$i]=~s/^\-//; # get rid of initial - if present | |||||||||||||||||||||||||||
| 79 | 0 | $param[$i]=~tr/a-z/A-Z/; # parameters are upper case | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 0 | %param = @param; # convert into associative array | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 0 | my(@return_array); | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 0 | local($^W) = 0; | |||||||||||||||||||||||||||
| 88 | 0 | my($key)=''; | |||||||||||||||||||||||||||
| 89 | 0 | foreach $key (@$order) { | |||||||||||||||||||||||||||
| 90 | 0 | my($value); | |||||||||||||||||||||||||||
| 91 | 0 | ▶ | if (ref($key) eq 'ARRAY') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | 0 | foreach (@$key) { | |||||||||||||||||||||||||||
| 93 | 0 | ▶ | last if defined($value); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | 0 | $value = $param{$_}; | |||||||||||||||||||||||||||
| 95 | 0 | delete $param{$_}; | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | } else { | ||||||||||||||||||||||||||||
| 98 | 0 | $value = $param{$key}; | |||||||||||||||||||||||||||
| 99 | 0 | delete $param{$key}; | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | 0 | push(@return_array,$value); | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | 0 | ▶ | push (@return_array,\%param) if %param; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | 0 | return @return_array; | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 1 | 1; | |||||||||||||||||||||||||||