| 1 | #!/usr/local/bin/perl | ||
| 2 | |||
| 3 | =head1 NAME | ||
| 4 | |||
| 5 | umls-association-runDataSet.pl This program calculates the assocation a | ||
| 6 | dataset of term pairs | ||
| 7 | |||
| 8 | =head1 SYNOPSIS | ||
| 9 | |||
| 10 | This utility takes a file of line seperated term pairs as input. The file is | ||
| 11 | of the form: "cui1<>cui2\n" with each line containing a new cui pair. It | ||
| 12 | outputs a line seperated list of association score and term pair of the | ||
| 13 | form: "score<>cui1<>cui2". Each line contains a different cui pair and their | ||
| 14 | score | ||
| 15 | |||
| 16 | =head1 USAGE | ||
| 17 | |||
| 18 | Usage: umls-assocation-runDataSet.pl [OPTIONS] CUI_LIST_FILE OUTPUT_FILE | ||
| 19 | |||
| 20 | =head1 INPUT | ||
| 21 | |||
| 22 | =head2 CUI_LIST_FILE | ||
| 23 | |||
| 24 | the input file containing line seperated cui pairs of the form: "cui1<>cui2" | ||
| 25 | |||
| 26 | =head2 OUTPUT_FILE | ||
| 27 | |||
| 28 | the output file, where each score and cui pair are output of the form: | ||
| 29 | score<>cui1<>cui2 | ||
| 30 | |||
| 31 | =head1 OPTIONS | ||
| 32 | |||
| 33 | Optional command line arguements. These options are identical to | ||
| 34 | umls-association.pl. Please see umls-associaton.pl for descriptions. | ||
| 35 | |||
| 36 | =head1 OUTPUT | ||
| 37 | |||
| 38 | The association between the each concept pair of the input file written to | ||
| 39 | a new line of the output file. | ||
| 40 | |||
| 41 | =head1 SYSTEM REQUIREMENTS | ||
| 42 | |||
| 43 | =over | ||
| 44 | |||
| 45 | =item * Perl (version 5.8.5 or better) - http://www.perl.org | ||
| 46 | |||
| 47 | =item * UMLS::Interface - http://search.cpan.org/dist/UMLS-Interface | ||
| 48 | |||
| 49 | =item * Text::NSP - http://search.cpan.org/dist/Text-NSP | ||
| 50 | |||
| 51 | =back | ||
| 52 | |||
| 53 | =head1 CONTACT US | ||
| 54 | |||
| 55 | If you have any trouble installing and using UMLS-Assocation, | ||
| 56 | please contact us via the users mailing list : | ||
| 57 | |||
| 58 | umls-association@yahoogroups.com | ||
| 59 | |||
| 60 | You can join this group by going to: | ||
| 61 | |||
| 62 | http://tech.groups.yahoo.com/group/umls-assocation/ | ||
| 63 | |||
| 64 | You may also contact us directly if you prefer : | ||
| 65 | |||
| 66 | Sam Henry: henryst at vcu.edu | ||
| 67 | |||
| 68 | =head1 AUTHOR | ||
| 69 | |||
| 70 | Sam Henry, Virginia Commonwealth University | ||
| 71 | Bridget T. McInnes, Virginia Commonwealth University | ||
| 72 | Alexander D. McQuilkin, Virginia Commonwealth University | ||
| 73 | |||
| 74 | =head1 COPYRIGHT | ||
| 75 | |||
| 76 | Copyright (c) 2015 | ||
| 77 | |||
| 78 | Bridget T. McInnes, Virginia Commonwealth University | ||
| 79 | btmcinnes at vcu.edu | ||
| 80 | |||
| 81 | This program is free software; you can redistribute it and/or modify it under | ||
| 82 | the terms of the GNU General Public License as published by the Free Software | ||
| 83 | Foundation; either version 2 of the License, or (at your option) any later | ||
| 84 | version. | ||
| 85 | |||
| 86 | This program is distributed in the hope that it will be useful, but WITHOUT | ||
| 87 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
| 88 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
| 89 | |||
| 90 | You should have received a copy of the GNU General Public License along with | ||
| 91 | this program; if not, write to: | ||
| 92 | |||
| 93 | The Free Software Foundation, Inc., | ||
| 94 | 59 Temple Place - Suite 330, | ||
| 95 | Boston, MA 02111-1307, USA. | ||
| 96 | |||
| 97 | =cut | ||
| 98 | |||
| 99 | use UMLS::Interface; | ||
| 100 | use UMLS::Association; | ||
| 101 | use Getopt::Long; | ||
| 102 | |||
| 103 | my $DEFAULT_MEASURE = "tscore"; | ||
| 104 | |||
| 105 | ############################################# | ||
| 106 | # Get Options and params | ||
| 107 | ############################################# | ||
| 108 | eval(GetOptions( "version", "help", "debug", "username=s", "password=s", "hostname=s", "umlsdatabase=s", "assocdatabase=s", "socket=s", "measure=s", "conceptexpansion", "noorder", "lta", "mwa", "vsa", "matrix=s", "config=s","precision=s")) or die ("Please check the above mentioned option(s).\n"); | ||
| 109 | |||
| 110 | #get required input | ||
| 111 | my $cuisFileName = shift; | ||
| 112 | my $outputFileName = shift; | ||
| 113 | |||
| 114 | ############################################# | ||
| 115 | # Check help, version, minimal usage notes | ||
| 116 | ############################################# | ||
| 117 | # if help is defined, print out help | ||
| 118 | if( defined $opt_help ) { | ||
| 119 | $opt_help = 1; | ||
| 120 | &showHelp(); | ||
| 121 | exit; | ||
| 122 | } | ||
| 123 | |||
| 124 | # if version is requested, show version | ||
| 125 | if( defined $opt_version ) { | ||
| 126 | $opt_version = 1; | ||
| 127 | &showVersion(); | ||
| 128 | exit; | ||
| 129 | } | ||
| 130 | |||
| 131 | # a single input file and output file must be passed in | ||
| 132 | if(!(defined $cuisFileName)) { | ||
| 133 | print STDERR "No CUI Pair Input File provided\n"; | ||
| 134 | &minimalUsageNotes(); | ||
| 135 | exit; | ||
| 136 | } | ||
| 137 | if(!(defined $outputFileName)) { | ||
| 138 | print STDERR "No Output File provided\n"; | ||
| 139 | &minimalUsageNotes(); | ||
| 140 | exit; | ||
| 141 | } | ||
| 142 | |||
| 143 | |||
| 144 | ############################################# | ||
| 145 | # Set Up UMLS::Interface | ||
| 146 | ############################################# | ||
| 147 | # set UMLS-Interface options | ||
| 148 | my %umls_option_hash = (); | ||
| 149 | |||
| 150 | $umls_option_hash{"t"} = 1; | ||
| 151 | |||
| 152 | if(defined $opt_debug) { | ||
| 153 | $umls_option_hash{"debug"} = $opt_debug; | ||
| 154 | } | ||
| 155 | if(defined $opt_verbose) { | ||
| 156 | $umls_option_hash{"verbose"} = $opt_verbose; | ||
| 157 | } | ||
| 158 | if(defined $opt_username) { | ||
| 159 | $umls_option_hash{"username"} = $opt_username; | ||
| 160 | } | ||
| 161 | if(defined $opt_driver) { | ||
| 162 | $umls_option_hash{"driver"} = $opt_driver; | ||
| 163 | } | ||
| 164 | if(defined $opt_umlsdatabase) { | ||
| 165 | $umls_option_hash{"database"} = $opt_umlsdatabase; | ||
| 166 | } | ||
| 167 | if(defined $opt_password) { | ||
| 168 | $umls_option_hash{"password"} = $opt_password; | ||
| 169 | } | ||
| 170 | if(defined $opt_hostname) { | ||
| 171 | $umls_option_hash{"hostname"} = $opt_hostname; | ||
| 172 | } | ||
| 173 | if(defined $opt_socket) { | ||
| 174 | $umls_option_hash{"socket"} = $opt_socket; | ||
| 175 | } | ||
| 176 | if(defined $opt_config){ | ||
| 177 | $umls_option_hash{"config"} = $opt_config; | ||
| 178 | } | ||
| 179 | |||
| 180 | # instantiate instance of UMLS-Interface | ||
| 181 | my $umls = UMLS::Interface->new(\%umls_option_hash); | ||
| 182 | die "Unable to create UMLS::Interface object.\n" if(!$umls); | ||
| 183 | |||
| 184 | ############################################# | ||
| 185 | # Set Up UMLS::Association | ||
| 186 | ############################################# | ||
| 187 | # set UMLS-Association option hash | ||
| 188 | my %assoc_option_hash = (); | ||
| 189 | $assoc_option_hash{'umls'} = $umls; | ||
| 190 | |||
| 191 | if(defined $opt_measure) { | ||
| 192 | $assoc_option_hash{"measure"} = $opt_measure; | ||
| 193 | } else { | ||
| 194 | $assoc_option_hash{"measure"} = $DEFAULT_MEASURE; | ||
| 195 | } | ||
| 196 | if(defined $opt_debug) { | ||
| 197 | $assoc_option_hash{"debug"} = $opt_debug; | ||
| 198 | } | ||
| 199 | if(defined $opt_verbose) { | ||
| 200 | $assoc_option_hash{"verbose"} = $opt_verbose; | ||
| 201 | } | ||
| 202 | if(defined $opt_username) { | ||
| 203 | $assoc_option_hash{"username"} = $opt_username; | ||
| 204 | } | ||
| 205 | if(defined $opt_driver) { | ||
| 206 | $assoc_option_hash{"driver"} = $opt_driver; | ||
| 207 | } | ||
| 208 | if(defined $opt_assocdatabase) { | ||
| 209 | $assoc_option_hash{"database"} = $opt_assocdatabase; | ||
| 210 | } | ||
| 211 | if(defined $opt_password) { | ||
| 212 | $assoc_option_hash{"password"} = $opt_password; | ||
| 213 | } | ||
| 214 | if(defined $opt_hostname) { | ||
| 215 | $assoc_option_hash{"hostname"} = $opt_hostname; | ||
| 216 | } | ||
| 217 | if(defined $opt_socket) { | ||
| 218 | $assoc_option_hash{"socket"} = $opt_socket; | ||
| 219 | } | ||
| 220 | if(defined $opt_conceptexpansion) { | ||
| 221 | $assoc_option_hash{"conceptexpansion"} = $opt_conceptexpansion; | ||
| 222 | } | ||
| 223 | if(defined $opt_precision){ | ||
| 224 | $assoc_option_hash{"precision"} = $opt_precision; | ||
| 225 | } | ||
| 226 | if(defined $opt_lta){ | ||
| 227 | $assoc_option_hash{"lta"} = $opt_lta; | ||
| 228 | } | ||
| 229 | if(defined $opt_mwa){ | ||
| 230 | $assoc_option_hash{"mwa"} = $opt_mwa; | ||
| 231 | } | ||
| 232 | if(defined $opt_vsa){ | ||
| 233 | $assoc_option_hash{"vsa"} = $opt_vsa; | ||
| 234 | } | ||
| 235 | if(defined $opt_noorder){ | ||
| 236 | $assoc_option_hash{"noorder"} = $opt_noorder; | ||
| 237 | } | ||
| 238 | if(defined $opt_matrix){ | ||
| 239 | $assoc_option_hash{"matrix"} = $opt_matrix; | ||
| 240 | } | ||
| 241 | |||
| 242 | # instantiate instance of UMLS-Assocation | ||
| 243 | my $association = UMLS::Association->new(\%assoc_option_hash); | ||
| 244 | die "Unable to create UMLS::Association object.\n" if(!$association); | ||
| 245 | |||
| 246 | ############################################# | ||
| 247 | # Calculate Association | ||
| 248 | ############################################# | ||
| 249 | |||
| 250 | #read in all the first and second cuis | ||
| 251 | open IN, $cuisFileName | ||
| 252 | or die ("Error: unable to open cui list file: $cuisFileName"); | ||
| 253 | my @cuiPairs = (); | ||
| 254 | foreach my $line (<IN>) { | ||
| 255 | chomp $line; | ||
| 256 | (my $cui1, my $cui2) = split('<>',$line); | ||
| 257 | push @cuiPairs, "$cui1,$cui2"; | ||
| 258 | } | ||
| 259 | close IN; | ||
| 260 | |||
| 261 | #calculate association scores for each term pair | ||
| 262 | my $scoresRef = $association->calculateAssociation_termPairList(\@cuiPairs, $assoc_option_hash{"measure"}); | ||
| 263 | |||
| 264 | #output the results | ||
| 265 | open OUT, ">$outputFileName" | ||
| 266 | or die ("Error: Unable to open output file: $outputFileName"); | ||
| 267 | for (my $i = 0; $i < scalar @cuiPairs; $i++) { | ||
| 268 | (my $cui1, my $cui2) = split(',',$cuiPairs[$i]); | ||
| 269 | print OUT "${$scoresRef}[$i]<>$cui1<>$cui2\n"; | ||
| 270 | } | ||
| 271 | close OUT; | ||
| 272 | |||
| 273 | |||
| 274 | |||
| 275 | ########################### | ||
| 276 | # Help Functions | ||
| 277 | ########################### | ||
| 278 | #shows the minimal usage notes | ||
| 279 | sub minimalUsageNotes { | ||
| 280 | print "Usage: umls-association-runDataSet.pl [OPTIONS] CUI_LIST_FILE OUTPUT_FILE\n"; | ||
| 281 | print "Type umls-association-runDataSet.pl --help for help.\n"; | ||
| 282 | exit; | ||
| 283 | } | ||
| 284 | |||
| 285 | #shows help to the user | ||
| 286 | sub showHelp { | ||
| 287 | print "This utility takes a file of line seperated term pairs as input.\n"; | ||
| 288 | print " The file is of the form: \"cui1<>cui2\n\" with each line containing\n"; | ||
| 289 | print " a new cui pair. It outputs a line seperated list of association\n"; | ||
| 290 | print "score and term pair of the form: \"score<>cui1<>cui2\". Each line \n"; | ||
| 291 | print "contains a different cui pair and their score\n"; | ||
| 292 | print "\n"; | ||
| 293 | print "Usage: umls-association-runDataSet.pl [OPTIONS] CUI_LIST_FILE OUTPUT_FILE\n"; | ||
| 294 | print "\n"; | ||
| 295 | print "Please note, the optional parameters are identical to umls-association.pl.\n"; | ||
| 296 | print "to avoid inconsitencies when adding new features or updating, please see:\n"; | ||
| 297 | print "umls-association --help\n"; | ||
| 298 | print "for a complete list of optional arguments" | ||
| 299 | } | ||
| 300 | |||
| 301 | #shows the current version | ||
| 302 | sub showVersion { | ||
| 303 | print "current version is ".(Association->version())."\n"; | ||
| 304 | exit; | ||
| 305 | } |