param_substitution_test.pl 2.75 KB
Newer Older
1 2
#!/usr/bin/env perl

3 4 5 6 7 8 9 10
=pod

=head1 DESCRIPTION

    A script for testing parameter substitution in Bio::EnsEMBL::Hive::Params class.

=head1 LICENSE

11
    Copyright [1999-2014] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
12 13 14 15 16 17 18 19 20 21 22 23

    Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

         http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software distributed under the License
    is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and limitations under the License.

=head1 CONTACT

24
    Please subscribe to the Hive mailing list:  http://listserver.ebi.ac.uk/mailman/listinfo/ehive-users  to discuss Hive-related questions or to be notified of our updates
25 26 27 28

=cut


29 30 31 32
use strict;
use warnings;

use Bio::EnsEMBL::Hive::Params;
33
use Bio::EnsEMBL::Hive::Utils ('stringify');
34 35 36

my $params = Bio::EnsEMBL::Hive::Params->new();

37 38 39 40 41 42 43 44 45 46
$params->param_init(1, {
    'alpha' => 2,
    'beta' => 5,
    'delta' => '#expr( #alpha#*#beta# )expr#',

    'gamma' => [10,20,33,15],
    'gamma_prime' => '#expr( [ @{#gamma#} ] )expr#',

    'age' => { 'Alice' => 17, 'Bob' => 20, 'Chloe' => 21},
    'age_prime' => '#expr( { %{#age#} } )expr#',
47 48 49

    'csv' => '123,456,789',
    'listref' => '#expr([eval #csv#])expr#',
50
});
51 52 53 54 55

print $params->param_substitute( "Substituting one scalar: #alpha# and another: #beta# and again one: #alpha# and the other: #beta# . Their product: #delta#\n" );

print $params->param_substitute( 'Old syntax needs single quotes or escaping the dollar. #expr( "One scalar: $alpha and another: $beta and again one: $alpha and another: $beta" )expr#' )."\n";

56
print $params->param_substitute( "This is csvq:gamma -> #csvq:gamma# and this is an expr()expr -> #expr( join(', ', sort \@{#gamma#}))expr#\n" );
57
print $params->param_substitute( 'adding indexed values: #expr( #age#->{Alice}+(max @{#gamma#}) )expr#' )."\n";
58 59 60 61 62 63

print $params->param_substitute( 'joined gamma: #expr( join(", ", @{ #gamma# } ) )expr#'."\n" );
print $params->param_substitute( 'joined gamma_prime: #expr( join(", ", @{#gamma_prime#}) )expr#'."\n" );

print $params->param_substitute( 'complex fold of age: #expr( join("\t", map { $ _.":".#age#->{$ _}} keys %{#age#}) )expr#' )."\n";
print $params->param_substitute( 'complex fold of age_prime: #expr( join("\t", map { $ _.":".#age_prime#->{$ _}} keys %{#age_prime#}) )expr#' )."\n";
64

65 66 67 68
print "\ncsv = '".$params->param('csv')."'\n";
my $listref = $params->param_substitute( '#listref#' );
print "list reference produced by evaluating csv: ".stringify($listref)."\n";