| 1 | package WebService::UMLSKS::Similarity; | ||
| 2 | |||
| 3 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 0 | ▶ | use Log::Message::Simple qw[msg error debug]; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 6 | |||
| 7 | no warnings qw/redefine/; | ||
| 8 | |||
| 9 | =head1 NAME | ||
| 10 | |||
| 11 | WebService::UMLSKS::Similarity - access the Unified Medical Language System (UMLS) via Webservices | ||
| 12 | |||
| 13 | =head1 VERSION | ||
| 14 | |||
| 15 | Version 0.23 | ||
| 16 | |||
| 17 | =cut | ||
| 18 | |||
| 19 | our $VERSION = '0.23'; | ||
| 20 | |||
| 21 | =head1 SYNOPSIS | ||
| 22 | |||
| 23 | =head2 Basic Usage | ||
| 24 | |||
| 25 | use WebService::UMLS::Similarity; | ||
| 26 | # Creating object of similarity with default constructor. | ||
| 27 | my $similarity1 = WebService::UMLS::Similarity->new(); | ||
| 28 | |||
| 29 | # Creating object of Similarity by providing Configuration parameters. | ||
| 30 | my @source_list = ("SNOMEDCT", "MSH"); | ||
| 31 | my @relation_list = ("PAR", "CHD","RB", "RN") ; | ||
| 32 | my $similarity2 = WebService::UMLS::Similarity->new({"sources" => \@source_list,"rels" => \@relation_list } ); | ||
| 33 | |||
| 34 | # Creating object of Similarity by providing Cinfiguration file path and name. | ||
| 35 | my $similarity3 = WebService::UMLS::Similarity-> | ||
| 36 | new({"config" => "/home/../config"}); | ||
| 37 | |||
| 38 | Format of configuaration file | ||
| 39 | |||
| 40 | The configuaration fie accepted by the module should be in the fillowing format | ||
| 41 | |||
| 42 | SAB :: include SNOMEDCT,MSH | ||
| 43 | REL :: include PAR,RB | ||
| 44 | DIR :: include U,H | ||
| 45 | RELA :: include RB-has_part | ||
| 46 | |||
| 47 | Here, SAB is the sources and REL is relations you want to include in | ||
| 48 | searching the UMLS. The list of sources and relations can be provided | ||
| 49 | seperated by comma. Some UMLS sources are :SNOMEDCT,MSH,UWDA,CSP,FMA,NCI | ||
| 50 | |||
| 51 | =head1 DESCRIPTION | ||
| 52 | |||
| 53 | This module creates a new instance of Similarity module and while creating the | ||
| 54 | instance sets all the configuration parameters which are used in rest of the module. | ||
| 55 | User can provide the configuration parameters by directly passing them to the | ||
| 56 | constructor using a hash of parameters with 'sources' and 'rels' options | ||
| 57 | or user can provide directly the configuration file path in the constructor using | ||
| 58 | 'config' option. If the user does not specify any configuartion parameters, | ||
| 59 | defualt parameters are used. 'SNOMEDCT' is the deafult source used and 'PAR|CHD' | ||
| 60 | are the default relations used. | ||
| 61 | |||
| 62 | =head1 SUBROUTINES | ||
| 63 | |||
| 64 | =head2 new | ||
| 65 | |||
| 66 | This sub creates a new object of Display by taking in optional configuaration | ||
| 67 | parameters. | ||
| 68 | |||
| 69 | =cut | ||
| 70 | |||
| 71 | sub new { | ||
| 72 | |||
| 73 | my $class = shift; | ||
| 74 | my $params = shift; | ||
| 75 | |||
| 76 | my @s_array = ("SNOMEDCT"); | ||
| 77 | my @r_array = ("PAR"); | ||
| 78 | my @d_array = ("U"); | ||
| 79 | my @a_array = (); | ||
| 80 | |||
| 81 | my %ConfigurationParameters = ( | ||
| 82 | "SAB", \@s_array, "REL", \@r_array, | ||
| 83 | "DIR", \@d_array, "RELA", \@a_array | ||
| 84 | ); | ||
| 85 | my $self = \%ConfigurationParameters; | ||
| 86 | |||
| 87 | bless( $self, $class ); | ||
| 88 | |||
| 89 | # call initialiseParameters only if parameters are passed else use default values | ||
| 90 | if ( defined $params && $params ne "" ) { | ||
| 91 | $self->initialiseParameters($params); | ||
| 92 | |||
| 93 | #printhashvaluearray(\%ConfigurationParameters); | ||
| 94 | |||
| 95 | } | ||
| 96 | |||
| 97 | return $self; | ||
| 98 | } | ||
| 99 | |||
| 100 | =head2 initialiseParameters | ||
| 101 | |||
| 102 | This subroutine sets the configuaration parameters hash | ||
| 103 | which are then used in rest of the module. | ||
| 104 | |||
| 105 | =cut | ||
| 106 | |||
| 107 | sub initialiseParameters { | ||
| 108 | |||
| 109 | my $self = shift; | ||
| 110 | my $params = shift; | ||
| 111 | |||
| 112 | # set the hash to default values | ||
| 113 | |||
| 114 | if ( !defined $params || !ref $params ) { | ||
| 115 | |||
| 116 | #return; | ||
| 117 | print "\nUndefined parameter reference"; | ||
| 118 | } | ||
| 119 | |||
| 120 | my $file_path_name = $params->{'config'}; | ||
| 121 | |||
| 122 | my @source_list; | ||
| 123 | my @relation_list; | ||
| 124 | my @direction_list; | ||
| 125 | if ( defined $params->{'sources'} ) { | ||
| 126 | @source_list = @{ $params->{'sources'} }; | ||
| 127 | } | ||
| 128 | if ( defined $params->{'rels'} ) { | ||
| 129 | @relation_list = @{ $params->{'rels'} }; | ||
| 130 | } | ||
| 131 | if ( defined $params->{'dirs'} ) { | ||
| 132 | @direction_list = @{ $params->{'dirs'} }; | ||
| 133 | } | ||
| 134 | |||
| 135 | my $r = 0; | ||
| 136 | my $d = 0; | ||
| 137 | #print "\n *****file path name: $file_path_name"; | ||
| 138 | |||
| 139 | if ( defined $file_path_name && $file_path_name ne "" ) { | ||
| 140 | |||
| 141 | my $pflag = 0; | ||
| 142 | my $dflag = 1; | ||
| 143 | |||
| 144 | # If user has provided a configuration file | ||
| 145 | open( CONFIG, $file_path_name ) | ||
| 146 | or die("Error: cannot open configuration file '$file_path_name'\n"); | ||
| 147 | |||
| 148 | my @parameters = <CONFIG>; | ||
| 149 | |||
| 150 | for my $p ( 0 .. $#parameters ) { | ||
| 151 | |||
| 152 | # print "\n $param"; | ||
| 153 | |||
| 154 | $parameters[$p] =~ /\s*(.*)\s*::\s*(.*?) (.*?)$/; | ||
| 155 | msg("\n $1 \t $2 \t $3"); | ||
| 156 | my $parameter_name = $1; | ||
| 157 | my $flag = $2; | ||
| 158 | my $parameter_value = $3; | ||
| 159 | my @parameter_array = (); | ||
| 160 | |||
| 161 | $parameter_name =~ s/\s*//g; | ||
| 162 | $parameter_value =~ s/\s*//g; | ||
| 163 | $flag =~ s/\s*//g; | ||
| 164 | |||
| 165 | #my @parameter_array | ||
| 166 | |||
| 167 | if ( $parameter_name && $flag && $parameter_value ) { | ||
| 168 | |||
| 169 | # If more than one sources/relations specified, then seperate by comma | ||
| 170 | if ( $parameter_value =~ /\,/ ) { | ||
| 171 | |||
| 172 | @parameter_array = split( ",", $parameter_value ); | ||
| 173 | } | ||
| 174 | else { | ||
| 175 | |||
| 176 | $parameter_array[0] = $parameter_value; | ||
| 177 | |||
| 178 | } | ||
| 179 | |||
| 180 | $parameter_name =~ s/\s*//g; | ||
| 181 | |||
| 182 | #chop($parameter_name); | ||
| 183 | |||
| 184 | if ( $parameter_name =~ /\bREL\b/ ) { | ||
| 185 | $pflag = 1; | ||
| 186 | $dflag = 0; | ||
| 187 | $r = $#parameter_array; | ||
| 188 | } | ||
| 189 | if ( $pflag == 1 ) { | ||
| 190 | if ( $parameter_name =~ /DIR/ ) { | ||
| 191 | $dflag = 1; | ||
| 192 | $d = $#parameter_array; | ||
| 193 | } | ||
| 194 | } | ||
| 195 | if ( $flag =~ /\binclude\b/ ) { | ||
| 196 | |||
| 197 | |||
| 198 | #print "\n including @parameter_array"; | ||
| 199 | $self->{$parameter_name} = \@parameter_array; | ||
| 200 | msg( | ||
| 201 | "\n in hash $parameter_name: @{$self->{$parameter_name}}" | ||
| 202 | ); | ||
| 203 | } | ||
| 204 | elsif ( $flag =~ /\bexclude\b/ ) { | ||
| 205 | |||
| 206 | # Dont do anything for now | ||
| 207 | |||
| 208 | "\n Invalid configurations: does not handle exclude yet\n"; | ||
| 209 | |||
| 210 | "\nPlease specify valid configuaration file by refering to the documentation\n"; | ||
| 211 | exit; | ||
| 212 | |||
| 213 | } | ||
| 214 | else { | ||
| 215 | |||
| 216 | "\n Invalid configurations, may be forgot to have 'include' keyword\n"; | ||
| 217 | |||
| 218 | "\nPlease specify valid configuaration file by refering to the documentation\n"; | ||
| 219 | exit; | ||
| 220 | } | ||
| 221 | } | ||
| 222 | else | ||
| 223 | |||
| 224 | { | ||
| 225 | print "\n Invalid configurations\n"; | ||
| 226 | |||
| 227 | "\nPlease specify valid configuaration file by refering to the documentation\n"; | ||
| 228 | exit; | ||
| 229 | } | ||
| 230 | |||
| 231 | } | ||
| 232 | |||
| 233 | |||
| 234 | if ( $dflag == 0 ) { | ||
| 235 | |||
| 236 | "\nIf relations are specified, it is necessay to specify directions for them"; | ||
| 237 | |||
| 238 | "\nPlease specify valid configuaration file by refering to the documentation\n"; | ||
| 239 | exit; | ||
| 240 | } | ||
| 241 | |||
| 242 | |||
| 243 | if($r != $d) | ||
| 244 | { | ||
| 245 | |||
| 246 | "\nEach relation must have a corresponding direction in the configuaration"; | ||
| 247 | |||
| 248 | "\nPlease specify valid configuaration file by refering to the documentation\n"; | ||
| 249 | exit; | ||
| 250 | |||
| 251 | } | ||
| 252 | |||
| 253 | |||
| 254 | |||
| 255 | } | ||
| 256 | else { | ||
| 257 | |||
| 258 | # If user has not provided a configuration file but has directly | ||
| 259 | # provided the configuration option in params hash | ||
| 260 | |||
| 261 | # if no configuration file is specified | ||
| 262 | # if configuration parameters are set using hash as parameter | ||
| 263 | |||
| 264 | if ( !defined $file_path_name | ||
| 265 | && @source_list | ||
| 266 | && @relation_list | ||
| 267 | && @direction_list ) | ||
| 268 | { | ||
| 269 | |||
| 270 | $self->{"SAB"} = \@source_list; | ||
| 271 | $self->{"REL"} = \@relation_list; | ||
| 272 | $self->{"DIR"} = \@direction_list; | ||
| 273 | } | ||
| 274 | |||
| 275 | else { | ||
| 276 | |||
| 277 | if (@source_list) { | ||
| 278 | $self->{"SAB"} = \@source_list; | ||
| 279 | } | ||
| 280 | if (@relation_list) { | ||
| 281 | $self->{"REL"} = \@relation_list; | ||
| 282 | } | ||
| 283 | if (@direction_list) { | ||
| 284 | $self->{"DIR"} = \@direction_list; | ||
| 285 | } | ||
| 286 | |||
| 287 | } | ||
| 288 | |||
| 289 | #if(!defined $file_path_name && !@source_list && !@relation_list) | ||
| 290 | #{ | ||
| 291 | # # nothing is specified , then use default values | ||
| 292 | |||
| 293 | #} | ||
| 294 | } | ||
| 295 | |||
| 296 | } | ||
| 297 | |||
| 298 | #-------------------------------PERLDOC STARTS HERE------------------------------------------------------------- | ||
| 299 | |||
| 300 | =head1 SEE ALSO | ||
| 301 | |||
| 302 | ValidateTerm.pm GetUserData.pm ConnectUMLS.pm ws-getUMLSInfo.pl ws-getAllowablePath.pl | ||
| 303 | |||
| 304 | =cut | ||
| 305 | |||
| 306 | =head1 AUTHORS | ||
| 307 | |||
| 308 | Mugdha Choudhari, University of Minnesota Duluth | ||
| 309 | E<lt>chou0130 at d.umn.eduE<gt> | ||
| 310 | |||
| 311 | Ted Pedersen, University of Minnesota Duluth | ||
| 312 | E<lt>tpederse at d.umn.eduE<gt> | ||
| 313 | |||
| 314 | |||
| 315 | |||
| 316 | |||
| 317 | =head1 COPYRIGHT | ||
| 318 | |||
| 319 | Copyright (C) 2011, Mugdha Choudhari, Ted Pedersen | ||
| 320 | |||
| 321 | This program is free software; you can redistribute it and/or modify | ||
| 322 | it under the terms of the GNU General Public License as published by | ||
| 323 | the Free Software Foundation; either version 2 of the License, or (at | ||
| 324 | your option) any later version. | ||
| 325 | |||
| 326 | This program is distributed in the hope that it will be useful, but | ||
| 327 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 328 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 329 | General Public License for more details. | ||
| 330 | |||
| 331 | You should have received a copy of the GNU General Public License | ||
| 332 | along with this program; if not, write to | ||
| 333 | The Free Software Foundation, Inc., | ||
| 334 | 59 Temple Place - Suite 330, | ||
| 335 | Boston, MA 02111-1307, USA. | ||
| 336 | |||
| 337 | =cut | ||
| 338 | |||
| 339 | #---------------------------------PERLDOC ENDS HERE--------------------------------------------------------------- | ||
| 340 | |||
| 341 | 1; # End of WebService::UMLS::Similarity | ||