| 1 | #!/usr/bin/perl | ||
| 2 | # | ||
| 3 | # @File Interface.pm | ||
| 4 | # @Author andriy | ||
| 5 | # @Created Aug 1, 2016 10:33:50 AM | ||
| 6 | # | ||
| 7 | |||
| 8 | =head1 NAME | ||
| 9 | |||
| 10 | SemMed::Interface - A suite of Perl modules that utilize path information | ||
| 11 | present in the Semantic Medline Database in order to calculate the semantic | ||
| 12 | association between two concepts in the UMLS. | ||
| 13 | |||
| 14 | =head1 INSTALL | ||
| 15 | To install the module, run the following magic commands: | ||
| 16 | |||
| 17 | perl Makefile.PL | ||
| 18 | make | ||
| 19 | make test | ||
| 20 | make install | ||
| 21 | |||
| 22 | This will install the module in the standard location. You will, most | ||
| 23 | probably, require root privileges to install in standard system | ||
| 24 | directories. To install in a non-standard directory, specify a prefix | ||
| 25 | during the 'perl Makefile.PL' stage as: | ||
| 26 | |||
| 27 | perl Makefile.PL PREFIX=/home/sid | ||
| 28 | |||
| 29 | It is possible to modify other parameters during installation. The | ||
| 30 | details of these can be found in the ExtUtils::MakeMaker | ||
| 31 | documentation. However, it is highly recommended not messing around | ||
| 32 | with other parameters, unless you know what you're doing. | ||
| 33 | |||
| 34 | =head1 DESCRIPTION | ||
| 35 | This package provides a Perl interface to the Semantic Medline Database | ||
| 36 | |||
| 37 | =head1 DATABASE SETUP | ||
| 38 | |||
| 39 | The interface assumes you have installed the Semantic Medline Database onto your | ||
| 40 | MySQL server and in addition, followed the steps present in the INSTALL file to | ||
| 41 | create the appropriate auxilary tables in order to speed up program runtime. | ||
| 42 | The name of the database can be passed through during program runtime but will | ||
| 43 | default to 'SemMedDB' if no parameter is given. | ||
| 44 | |||
| 45 | The SemMedDB database must contain the following tables: | ||
| 46 | 1. CONCEPT | ||
| 47 | 2. CONCEPT_SEMTYPE | ||
| 48 | 3. PREDICATION_ARGUMENT | ||
| 49 | 4. PREDICATION | ||
| 50 | 5. SENTENCE_PREDICATION | ||
| 51 | 6. SENTENCE | ||
| 52 | 7. CITATIONS | ||
| 53 | 8. PREDICATION_AGGREGATE | ||
| 54 | 9. DISTINCT_PREDICATION_AGGREGATE * | ||
| 55 | |||
| 56 | *The table 'DISTINCT_PREDICATION_AGGREGATE' does not install alongside the | ||
| 57 | Semantic Medline Database via the .SQL file provided on their website. Steps | ||
| 58 | must be followed in the INSTALL file to set-up this table. Failure to do so | ||
| 59 | will cause fatal errors at runtime. | ||
| 60 | |||
| 61 | A script inside the INSTALL file details the steps needed to generate | ||
| 62 | the required auxilary tables. These steps are to be done following the Semantic | ||
| 63 | Medline Database install and may take up to several days to complete due to the | ||
| 64 | size of the database. | ||
| 65 | |||
| 66 | =head1 INITIALIZING THE MODULE | ||
| 67 | |||
| 68 | To create an instance of the interface module, using default values | ||
| 69 | for all configuration options: | ||
| 70 | |||
| 71 | use SemMed::Interface; | ||
| 72 | my $SemMedLoginParam = { "driver" => "mysql", | ||
| 73 | "database" => "SemMedDB", | ||
| 74 | "username" => "username", | ||
| 75 | "password" => "password", | ||
| 76 | "socket" => "/home/mysql/mysql.sock", | ||
| 77 | "hostname" => "localhost", | ||
| 78 | "port" => "3306"}; | ||
| 79 | |||
| 80 | my $AssociationLoginParam = { "driver" => "mysql", | ||
| 81 | "database" => "CUI_BIGRAMS_27JUL15", | ||
| 82 | "username" => "username", | ||
| 83 | "password" => "password", | ||
| 84 | "socket" => "/home/mysql/mysql.sock", | ||
| 85 | "hostname" => "localhost", | ||
| 86 | "port" => "3306"}; | ||
| 87 | |||
| 88 | |||
| 89 | my $interface = new SemMed::Interface($SemMedLoginParam, $AssociationLoginParam); | ||
| 90 | |||
| 91 | =cut | ||
| 92 | |||
| 93 | package SemMed::Interface; | ||
| 94 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 95 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 96 | 1 | ▶ | use SemMed::Interface::GraphTraversal; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 97 | use SemMed::Interface::DataAccess; | ||
| 98 | |||
| 99 | |||
| 100 | use vars qw($VERSION); | ||
| 101 | |||
| 102 | $VERSION = '0.03'; | ||
| 103 | |||
| 104 | my $connection = ""; | ||
| 105 | my $gt = ""; | ||
| 106 | |||
| 107 | my @includedPredicates; #only this predicates will be used in the traversal | ||
| 108 | my @excludedPredicates; #these predicates will be excluded in the traversal | ||
| 109 | |||
| 110 | # method to create a new SemMed::Interface object | ||
| 111 | # input : $SemMedLoginParams <- reference to hash containing SemMed login parameter | ||
| 112 | # $AssociationLoginParams <- reference to hash containing the UMLS::Association login parameters | ||
| 113 | # output: | ||
| 114 | sub new { | ||
| 115 | |||
| 116 | my $self = {}; | ||
| 117 | my $class = shift; | ||
| 118 | my $SemMedLoginParams = shift; #hash containing the SemMed login parameters | ||
| 119 | my $AssociationLoginParams = shift; #hash containing the UMLS::Association login parameters | ||
| 120 | |||
| 121 | @includedPredicates = (); | ||
| 122 | @excludedPredicates = (); | ||
| 123 | |||
| 124 | bless($self, $class); | ||
| 125 | |||
| 126 | $connection = new DataAccess($SemMedLoginParams, $AssociationLoginParams); | ||
| 127 | $gt = new GraphTraversal($connection); | ||
| 128 | |||
| 129 | return $self; | ||
| 130 | } | ||
| 131 | |||
| 132 | ####################################### | ||
| 133 | |||
| 134 | =head3 findPathLength | ||
| 135 | |||
| 136 | description: | ||
| 137 | |||
| 138 | Utilizes a breadth first search to find the path length from a source_concept to a destination_concept | ||
| 139 | |||
| 140 | input: | ||
| 141 | |||
| 142 | $source_concept <- string containing the concept id of the cui to start seraching from | ||
| 143 | $destination_concept <- string containing the concept id you are searching for | ||
| 144 | |||
| 145 | output: | ||
| 146 | |||
| 147 | length of path <- Non-negative Integer | -1 indicating length of path between the two concepts | ||
| 148 | |||
| 149 | example: | ||
| 150 | |||
| 151 | #finds path length between Heart and Myocardial Infarction | ||
| 152 | use SemMed::Interface; | ||
| 153 | my $interface = new SemMed::Interface(); | ||
| 154 | |||
| 155 | my $pathlength = $interface->findPathLength("C0018787", "C0027061"); | ||
| 156 | |||
| 157 | |||
| 158 | =cut | ||
| 159 | sub findPathLength{ | ||
| 160 | |||
| 161 | my $self = shift; | ||
| 162 | my $source_cui = shift; | ||
| 163 | my $destination_cui = shift; | ||
| 164 | # return $gt->findPath($source_cui, $destination_cui, \@includedPredicates, \@excludedPredicates); | ||
| 165 | return $gt->findPath($source_cui, $destination_cui); | ||
| 166 | } | ||
| 167 | |||
| 168 | ####################################### | ||
| 169 | |||
| 170 | =head3 findPathScore | ||
| 171 | |||
| 172 | description: | ||
| 173 | |||
| 174 | Function utilizing a breadth first search along with UMLS::Association to find the aggregate association score | ||
| 175 | along the path between source_concept and destination_concept | ||
| 176 | |||
| 177 | input: | ||
| 178 | |||
| 179 | $source_concept <- string containing the concept id of the cui to start seraching from | ||
| 180 | $destination_concept <- string containing the concept id you are searching for | ||
| 181 | $measure <- string containing the UMLS::Association statistic measure to aggregate along paths. | ||
| 182 | |||
| 183 | output: | ||
| 184 | |||
| 185 | Aggregate association score <- Non-negative float indicating the aggregate path score | ||
| 186 | |||
| 187 | example: | ||
| 188 | |||
| 189 | #finds aggregate association score between Heart and Myocardial Infarction | ||
| 190 | use SemMed::Interface; | ||
| 191 | my $interface = new SemMed::Interface(); | ||
| 192 | |||
| 193 | my $score = $interface->findPathLength("C0018787", "C0027061", "tscore"); | ||
| 194 | |||
| 195 | |||
| 196 | =cut | ||
| 197 | sub findPathScore{ | ||
| 198 | |||
| 199 | my $self = shift; | ||
| 200 | my $source_cui = shift; | ||
| 201 | my $destination_cui = shift; | ||
| 202 | my $measure = shift; | ||
| 203 | return $gt->findPathScore($source_cui, $destination_cui, $measure, \@includedPredicates, \@excludedPredicates); | ||
| 204 | |||
| 205 | } | ||
| 206 | |||
| 207 | |||
| 208 | =head3 getConceptDegree | ||
| 209 | description: | ||
| 210 | Gets the degree(the number of outgoing relationships) from a particular cui | ||
| 211 | input: | ||
| 212 | $concept <- string containing the concept id of the cui to start seraching from | ||
| 213 | output: | ||
| 214 | Integer >= 0 <- Degree of the concept | ||
| 215 | =cut | ||
| 216 | sub getConceptDegree{ | ||
| 217 | my $self = shift; | ||
| 218 | my $concept = shift; | ||
| 219 | return $connection->getConceptDegree($concept); | ||
| 220 | } | ||
| 221 | |||
| 222 | =head3 getConnections | ||
| 223 | description: | ||
| 224 | Gets all outgoing predicates and concepts from a given concept | ||
| 225 | input: | ||
| 226 | $concept <- string containing the concept id to get outgoing edges from | ||
| 227 | output: | ||
| 228 | $edges <- array reference of outgoing predicates and concepts | ||
| 229 | |||
| 230 | example: | ||
| 231 | use SemMed::Interface; | ||
| 232 | my $interface = new SemMed::Interface(); | ||
| 233 | |||
| 234 | my $edges = $interface->getConnections("C0018787"); | ||
| 235 | |||
| 236 | foreach @edge (@$edges){ | ||
| 237 | $predicate = $edge[0]; | ||
| 238 | $destination_concept = $edge[1]; | ||
| 239 | } | ||
| 240 | |||
| 241 | =cut | ||
| 242 | |||
| 243 | sub getConnections { | ||
| 244 | my $self = shift; | ||
| 245 | my $concept = shift; | ||
| 246 | return $connection->getConnections($concept); | ||
| 247 | } | ||
| 248 | |||
| 249 | |||
| 250 | |||
| 251 | |||
| 252 | |||
| 253 | |||
| 254 | |||
| 255 | |||
| 256 | sub addIncludedPredicates{ | ||
| 257 | my $self = shift; | ||
| 258 | my $predicates = shift; | ||
| 259 | push @includedPredicates, @$predicates; | ||
| 260 | } | ||
| 261 | |||
| 262 | |||
| 263 | |||
| 264 | sub clearIncludedPredicates{ | ||
| 265 | my $self = shift; | ||
| 266 | @includedPredicates = (); | ||
| 267 | } | ||
| 268 | |||
| 269 | |||
| 270 | |||
| 271 | sub addExcludedPredicates{ | ||
| 272 | my $self = shift; | ||
| 273 | my $predicates = shift; | ||
| 274 | push @excludedPredicates, @$predicates; | ||
| 275 | } | ||
| 276 | |||
| 277 | |||
| 278 | |||
| 279 | sub clearExcludedPredicates{ | ||
| 280 | my $self = shift; | ||
| 281 | @excludedPredicates = (); | ||
| 282 | } | ||
| 283 | |||
| 284 | |||
| 285 | |||
| 286 | |||
| 287 | 1; | ||