| 1 | package Microarray::Config; | ||
| 2 | |||
| 3 | # License information (the MIT license) | ||
| 4 | |||
| 5 | # Copyright (c) 2003 Christian Rees, Janos Demeter, John Matese, Gavin | ||
| 6 | # Sherlock; Stanford University | ||
| 7 | |||
| 8 | # Permission is hereby granted, free of charge, to any person | ||
| 9 | # obtaining a copy of this software and associated documentation files | ||
| 10 | # (the "Software"), to deal in the Software without restriction, | ||
| 11 | # including without limitation the rights to use, copy, modify, merge, | ||
| 12 | # publish, distribute, sublicense, and/or sell copies of the Software, | ||
| 13 | # and to permit persons to whom the Software is furnished to do so, | ||
| 14 | # subject to the following conditions: | ||
| 15 | |||
| 16 | # The above copyright notice and this permission notice shall be | ||
| 17 | # included in all copies or substantial portions of the Software. | ||
| 18 | |||
| 19 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
| 20 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
| 21 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
| 22 | # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
| 23 | # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
| 24 | # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
| 25 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| 26 | # SOFTWARE. | ||
| 27 | |||
| 28 | |||
| 29 | # This package is to be used by microarray softare for the GMOD | ||
| 30 | # project, to get file paths and other configurations, so that | ||
| 31 | # programs can be easily be moved about | ||
| 32 | |||
| 33 | |||
| 34 | use strict; | ||
| 35 | |||
| 36 | my $VERSION = "0.1"; | ||
| 37 | |||
| 38 | my $PACKAGE = 'Microarray::Config'; | ||
| 39 | |||
| 40 | my $kRootPath = $PACKAGE.'::__serverPath'; | ||
| 41 | my $kBinPath = $PACKAGE.'::__binPath'; | ||
| 42 | my $kRootURL = $PACKAGE.'::__serverUrl'; | ||
| 43 | my $kTmpPath = $PACKAGE.'::__tmpPath'; | ||
| 44 | my $kTmpURL = $PACKAGE.'::__tmpURL'; | ||
| 45 | my $kGxHtmlPath = $PACKAGE.'::__gxHtmlPath'; | ||
| 46 | my $kGxImagesPath = $PACKAGE.'::__gxImagesPath'; | ||
| 47 | my $kGxDataPath = $PACKAGE.'::__gxDataPath'; | ||
| 48 | my $kGxURL = $PACKAGE.'::__gxURL'; | ||
| 49 | my $kGxImagesURL = $PACKAGE.'::__gxImagesURL'; | ||
| 50 | my $kDataPath = $PACKAGE.'::__dataPath'; | ||
| 51 | my $kHtmlPath = $PACKAGE.'::__htmlPath'; | ||
| 52 | my $kGxRootWord = $PACKAGE.'::__gxRootword'; # just to store a key directory name | ||
| 53 | |||
| 54 | |||
| 55 | ######################################################################### | ||
| 56 | sub new{ | ||
| 57 | ######################################################################### | ||
| 58 | # This simple constructor initializes a few variables, and returns a | ||
| 59 | # object reference, which can then be used to call the various methods | ||
| 60 | # | ||
| 61 | # Microarray::Config makes some very strict assumptions about the layout of the | ||
| 62 | # file system. It assumes you will provide it a rootpath, and a rooturl, and that below | ||
| 63 | # the rootpath will be the following directories: | ||
| 64 | # | ||
| 65 | # html, html/tmp, html/explorer, html/images, data, data/explorer, bin | ||
| 66 | # | ||
| 67 | # it assumes that the rooturl points to the rootpath/html/ | ||
| 68 | # | ||
| 69 | # | ||
| 70 | # Usage my $config = Microarray::Config->new(rootpath => $rootpath, | ||
| 71 | # rooturl => $rooturl); | ||
| 72 | # my $path = $config->gxHtmlPath; | ||
| 73 | |||
| 74 | |||
| 75 | my $self = {}; | ||
| 76 | |||
| 77 | bless $self, shift; | ||
| 78 | |||
| 79 | $self->__init(@_); | ||
| 80 | |||
| 81 | return $self; | ||
| 82 | |||
| 83 | } | ||
| 84 | |||
| 85 | |||
| 86 | ######################################################################### | ||
| 87 | sub __init { | ||
| 88 | ######################################################################### | ||
| 89 | |||
| 90 | my ($self, %args) = @_; | ||
| 91 | |||
| 92 | # ROOTWORDS below | ||
| 93 | $self->{$kGxRootWord} = 'explorer'; # key directory for explorer | ||
| 94 | |||
| 95 | # FILEPATHS BELOW | ||
| 96 | $self->{$kRootPath} = $args{'rootpath'} || die "You must provide a rootpath"; | ||
| 97 | |||
| 98 | $self->{$kBinPath} = $self->{$kRootPath}.'bin/'; | ||
| 99 | |||
| 100 | $self->{$kDataPath} = $self->{$kRootPath}.'data/'; | ||
| 101 | $self->{$kGxDataPath} = $self->{$kDataPath}.$self->{$kGxRootWord}.'/'; | ||
| 102 | |||
| 103 | $self->{$kHtmlPath} = $self->{$kRootPath}.'html/'; | ||
| 104 | $self->{$kTmpPath} = $self->{$kHtmlPath}.'tmp/'; | ||
| 105 | $self->{$kGxHtmlPath} = $self->{$kHtmlPath}.$self->{$kGxRootWord}.'/'; | ||
| 106 | $self->{$kGxImagesPath} = $self->{$kGxHtmlPath}.'images/'; | ||
| 107 | |||
| 108 | |||
| 109 | # URLS BELOW | ||
| 110 | $self->{$kRootURL} = $args{'rooturl'} || die "You must supply a rooturl"; | ||
| 111 | $self->{$kTmpURL} = $self->{$kRootURL}.'/tmp/'; | ||
| 112 | $self->{$kGxURL} = $self->{$kRootURL}.'/'.$self->{$kGxRootWord}.'/'; | ||
| 113 | $self->{$kGxImagesURL} = $self->{$kGxURL}.'images/'; | ||
| 114 | |||
| 115 | return $self; | ||
| 116 | } | ||
| 117 | |||
| 118 | ######################################################################### | ||
| 119 | # | ||
| 120 | # ACCESSOR METHODS | ||
| 121 | # | ||
| 122 | ######################################################################### | ||
| 123 | ######################################################################### | ||
| 124 | sub serverRootPath { | ||
| 125 | ######################################################################### | ||
| 126 | |||
| 127 | return $_[0]->{$kRootPath}; | ||
| 128 | } | ||
| 129 | |||
| 130 | ######################################################################### | ||
| 131 | sub tmpPath{ | ||
| 132 | ######################################################################### | ||
| 133 | # This method returns the filepath of the tmp directory to be used by | ||
| 134 | # microarray cgi's | ||
| 135 | |||
| 136 | return $_[0]->{$kTmpPath}; | ||
| 137 | } | ||
| 138 | |||
| 139 | ######################################################################### | ||
| 140 | sub gxHtmlPath { | ||
| 141 | ######################################################################### | ||
| 142 | # returns the filesystem path to the explorer html directory stem, | ||
| 143 | # suitable for appending the project name and dataset name | ||
| 144 | # (directories) | ||
| 145 | |||
| 146 | return $_[0]->{$kGxHtmlPath}; | ||
| 147 | } | ||
| 148 | |||
| 149 | |||
| 150 | ######################################################################### | ||
| 151 | sub gxImagesPath { | ||
| 152 | ######################################################################### | ||
| 153 | # returns the filesystem path to the explorer images directory stem, | ||
| 154 | # home of those images accompanying the distribution | ||
| 155 | |||
| 156 | return $_[0]->{$kGxImagesPath}; | ||
| 157 | } | ||
| 158 | |||
| 159 | |||
| 160 | ######################################################################### | ||
| 161 | sub gxDataPath { | ||
| 162 | ######################################################################### | ||
| 163 | # returns the filesystem path to the explorer data directory stem, | ||
| 164 | # suitable for appending the project name and dataset name | ||
| 165 | # (directories) | ||
| 166 | |||
| 167 | return $_[0]->{$kGxDataPath}; | ||
| 168 | } | ||
| 169 | |||
| 170 | |||
| 171 | ######################################################################### | ||
| 172 | sub binPath{ | ||
| 173 | ######################################################################### | ||
| 174 | # This method returns the path of the directory contianing the binary | ||
| 175 | # scripts | ||
| 176 | |||
| 177 | |||
| 178 | return $_[0]->{$kBinPath}; | ||
| 179 | } | ||
| 180 | |||
| 181 | |||
| 182 | ######################################################################### | ||
| 183 | sub tmpUrl{ | ||
| 184 | ######################################################################### | ||
| 185 | # This method returns the URL of the tmp directory to be used by | ||
| 186 | # microarray cgi's | ||
| 187 | |||
| 188 | return $_[0]->{$kTmpURL}; | ||
| 189 | } | ||
| 190 | |||
| 191 | |||
| 192 | ######################################################################### | ||
| 193 | sub gxRootWord { | ||
| 194 | ######################################################################### | ||
| 195 | |||
| 196 | return $_[0]->{$kGxRootWord}; | ||
| 197 | } | ||
| 198 | |||
| 199 | |||
| 200 | |||
| 201 | ######################################################################### | ||
| 202 | sub gxURL { | ||
| 203 | ######################################################################### | ||
| 204 | # returns the stem URL for the explorer documents, suitable for appending | ||
| 205 | # the project name and dataset name (directories) | ||
| 206 | |||
| 207 | return $_[0]->{$kGxURL}; | ||
| 208 | } | ||
| 209 | |||
| 210 | |||
| 211 | ######################################################################### | ||
| 212 | sub gxImagesURL { | ||
| 213 | ######################################################################### | ||
| 214 | # returns the stem URL for the explorer images, including scalebars, | ||
| 215 | # background images, and other images included within the distribution | ||
| 216 | |||
| 217 | return $_[0]->{$kGxImagesURL}; | ||
| 218 | } | ||
| 219 | |||
| 220 | ######################################################################### | ||
| 221 | sub ColorSchemeTranslationHash { | ||
| 222 | ######################################################################### | ||
| 223 | # This public class method returns a colorscheme lookup hash, so that | ||
| 224 | # the myriad of user imput, client software, and class expectations | ||
| 225 | # can be tranlated to a simple, standardized two letter code for the | ||
| 226 | # colorscheme. This could be added to in the future, if required. | ||
| 227 | |||
| 228 | return ('red/green' =>'rg', | ||
| 229 | 'green/red' =>'rg', | ||
| 230 | 'rg' =>'rg', | ||
| 231 | 'gr' =>'rg', | ||
| 232 | 'blue/yellow' =>'yb', | ||
| 233 | 'yellow/blue' =>'yb', | ||
| 234 | 'yb' =>'yb', | ||
| 235 | 'by' =>'yb'); | ||
| 236 | |||
| 237 | } | ||
| 238 | |||
| 239 | |||
| 240 | ######################################################################### | ||
| 241 | sub ImageType { | ||
| 242 | ######################################################################### | ||
| 243 | # this public class simply return the type of image that is likely | ||
| 244 | # being written by GD, based on the GD version | ||
| 245 | |||
| 246 | my $kImgType = ($GD::VERSION > 1.19) ? "png" : "gif"; | ||
| 247 | |||
| 248 | return $kImgType; | ||
| 249 | |||
| 250 | } | ||
| 251 | |||
| 252 | 1; |