Mercurial > repos > cpt > cpt_psm_plotter
comparison lib/CPT/Parameter/File/Output.pm @ 1:8691c1c61a8e draft default tip
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
| author | cpt |
|---|---|
| date | Mon, 05 Jun 2023 02:48:47 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 0:54c7a3ea81e2 | 1:8691c1c61a8e |
|---|---|
| 1 package CPT::Parameter::File::Output; | |
| 2 use Moose; | |
| 3 with 'CPT::Parameter'; | |
| 4 use CPT::OutputFiles; | |
| 5 | |
| 6 # Has the user requested that the format is ALWAYS of a specific type. This is | |
| 7 # useful when (e.g,.) CSV output is required because it's part of a pipeline. | |
| 8 # Of course, in a perfect world that wouldn't be necessary as we'd be able to | |
| 9 # read in data and the only constraint would be that it was "text/tabular" and | |
| 10 # magically we'd have a hash just like we would with CSV. Sigh.... | |
| 11 has 'hardcoded' => ( is => 'rw', isa => 'Bool' ); | |
| 12 # The format of the internal data structure that we're pushing to output | |
| 13 # See CPT.pm for a list of these (under %acceptable) | |
| 14 has 'data_format' => ( is => 'rw', isa => 'Str' ); | |
| 15 has 'default_format' => ( is => 'rw', isa => 'Str' ); | |
| 16 | |
| 17 # registered => ['text/tabular~CSV', 'text/plain=TXT'], | |
| 18 has 'registered_types' => ( is => 'rw', isa => 'ArrayRef' ); | |
| 19 has 'cpt_outputfile_data_access' => ( is => 'ro', isa => 'Any', default => sub { CPT::OutputFiles->new() } ); | |
| 20 | |
| 21 | |
| 22 | |
| 23 sub galaxy_input { | |
| 24 | |
| 25 # Required by our parent. For an output file, this is non-functional | |
| 26 my ( $self, $xml_writer ) = @_; | |
| 27 $self->handle_possible_galaxy_input_repeat_start($xml_writer); | |
| 28 my %params = $self->get_default_input_parameters('select'); | |
| 29 $params{label} = 'Format of ' . $self->get_galaxy_cli_identifier(), | |
| 30 $params{name} = sprintf( "%s_%s", $self->get_galaxy_cli_identifier, 'format' ), | |
| 31 # Remove any default values for galaxy | |
| 32 delete $params{value}; | |
| 33 $xml_writer->startTag( | |
| 34 'param', | |
| 35 %params, | |
| 36 ); | |
| 37 | |
| 38 if(defined $self->data_format()){ | |
| 39 | |
| 40 foreach ( sort @{ $self->cpt_outputfile_data_access()->valid_formats($self->data_format()) } ) { | |
| 41 my %p = (value => $_); | |
| 42 if($_ eq $self->default_format()){ | |
| 43 $p{selected} = 'True'; | |
| 44 } | |
| 45 $xml_writer->startTag( 'option', %p ); | |
| 46 $xml_writer->characters( $_ ); | |
| 47 $xml_writer->endTag('option'); | |
| 48 } | |
| 49 }else{ | |
| 50 $xml_writer->startTag( 'option', value => 'data', selected => 'True' ); | |
| 51 $xml_writer->characters( 'data' ); | |
| 52 $xml_writer->endTag('option'); | |
| 53 } | |
| 54 $xml_writer->endTag('param'); | |
| 55 $self->handle_possible_galaxy_input_repeat_end($xml_writer); | |
| 56 } | |
| 57 | |
| 58 | |
| 59 sub galaxy_output { | |
| 60 my ( $self, $xml_writer ) = @_; | |
| 61 my $format; | |
| 62 if(defined $self->default_format()){ | |
| 63 $format = $self->default_format(); | |
| 64 }else{ | |
| 65 $format = 'data'; | |
| 66 } | |
| 67 | |
| 68 $xml_writer->startTag( | |
| 69 'data', | |
| 70 name => $self->get_galaxy_cli_identifier(), | |
| 71 format => $format, | |
| 72 ); | |
| 73 | |
| 74 if ( !$self->hardcoded() ) { | |
| 75 $xml_writer->startTag('change_format'); | |
| 76 # Otherwise it's still going to be set as the default_format so we're not toooo worried. | |
| 77 if(defined($self->data_format())){ | |
| 78 my @galaxy_formats = @{ $self->cpt_outputfile_data_access()->valid_formats($self->data_format()) }; | |
| 79 foreach (sort @galaxy_formats) { | |
| 80 $xml_writer->startTag( | |
| 81 'when', | |
| 82 input => sprintf( "%s_%s", $self->get_galaxy_cli_identifier, 'format' ), | |
| 83 value => $_, | |
| 84 format => $self->cpt_outputfile_data_access()->get_format_mapping($_), | |
| 85 ); | |
| 86 $xml_writer->endTag('when'); | |
| 87 } | |
| 88 } | |
| 89 $xml_writer->endTag('change_format'); | |
| 90 } | |
| 91 $xml_writer->endTag('data'); | |
| 92 } | |
| 93 | |
| 94 sub validate_individual { | |
| 95 my ($self, $val) = @_; | |
| 96 #if(! -e $self->value()){ | |
| 97 # return 1; | |
| 98 #} | |
| 99 #return 0; | |
| 100 return 1; | |
| 101 } | |
| 102 | |
| 103 | |
| 104 sub getopt_format { | |
| 105 return '=s'; | |
| 106 } | |
| 107 | |
| 108 no Moose; | |
| 109 1; | |
| 110 | |
| 111 __END__ | |
| 112 | |
| 113 =pod | |
| 114 | |
| 115 =encoding UTF-8 | |
| 116 | |
| 117 =head1 NAME | |
| 118 | |
| 119 CPT::Parameter::File::Output | |
| 120 | |
| 121 =head1 VERSION | |
| 122 | |
| 123 version 1.99.4 | |
| 124 | |
| 125 =head2 galaxy_input | |
| 126 | |
| 127 $file_param->galaxy_input($xml_writer); # where $file_param is a CPT::Parameter::* | |
| 128 | |
| 129 Utilises the $xml_writer to add a <data> block in the <output> section | |
| 130 | |
| 131 =head2 galaxy_output | |
| 132 | |
| 133 $file_param->galaxy_output($xml_writer); # where $file_param is a CPT::Parameter::* | |
| 134 | |
| 135 Utilises the $xml_writer to add a <data> block in the <output> section | |
| 136 | |
| 137 =head2 getopt_format | |
| 138 | |
| 139 Returns the format character for a given CPT::Parameter::* type | |
| 140 | |
| 141 =head1 AUTHOR | |
| 142 | |
| 143 Eric Rasche <rasche.eric@yandex.ru> | |
| 144 | |
| 145 =head1 COPYRIGHT AND LICENSE | |
| 146 | |
| 147 This software is Copyright (c) 2014 by Eric Rasche. | |
| 148 | |
| 149 This is free software, licensed under: | |
| 150 | |
| 151 The GNU General Public License, Version 3, June 2007 | |
| 152 | |
| 153 =cut |
