File Coverage

blib/lib/SemMed/Interface.pm
Criterion Covered Total %
statement 7 9 77.7
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 10 12 83.3


line stmt bran cond sub pod time code
1             #!/usr/bin/perl
2             #
3             # @File Interface.pm.pm
4             # @Author andriy
5             # @Created Aug 1, 2016 10:33:50 AM
6             #
7              
8             =head1 NAME
9             SemRep::Interface - A suite of Perl modules that utilize path information
10             present in the Semantic Medline Database in order to calculate the semantic
11             association between two concepts in the UMLS.
12              
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
36              
37             =head1 DATABASE SETUP
38             The interface assumes you have installed the Semantic Medline Database onto your
39             MYSQL server and in addition, followed the steps present in the INSTALL file to
40             create the appropriate auxilary tables in order to speed up program runtime.
41             The name of the database can be passed through during program runtime but will
42             default to 'SemMedDB' if no parameter is given.
43              
44             The SemMedDB database must contain the following tables:
45             1. CONCEPT
46             2. CONCEPT_SEMTYPE
47             3. PREDICATION_ARGUMENT
48             4. PREDICATION
49             5. SENTENCE_PREDICATION
50             6. SENTENCE
51             7. CITATIONS
52             8. PREDICATION_AGGREGATE
53             9. DISTINCT_PREDICATION_AGGREGATE *
54              
55             *The table 'DISTINCT_PREDICATION_AGGREGATE' does not install alongside the
56             Semantic Medline Database via the .SQL file provided on their website. Steps
57             must be followed in the INSTALL file to set-up this table. Failure to do so
58             will cause fatal errors at runtime.
59              
60             A script inside the INSTALL file details the steps needed to generate
61             the required auxilary tables. These steps are to be done following the Semantic
62             Medline Database install and may take up to several days to complete due to the
63             size of the database.
64              
65             =head1 INITIALIZING THE MODULE
66              
67             To create an instance of the interface module, using default values
68             for all configuration options:
69              
70             use SemRep::Interface;
71             my $interface = new SemRep::Interface();
72              
73             =cut
74              
75             package SemMed::Interface;
76 1     1   14482 use strict;
  1         2  
  1         27  
77 1     1   3 use warnings;
  1         2  
  1         25  
78 1     1   356 use SemMed::Interface::GraphTraversal;
  0            
  0            
79             use SemMed::Interface::DataAccess;
80              
81              
82             use vars qw($VERSION);
83              
84             $VERSION = '0.01';
85              
86             my $connection = "";
87             my $gt = "";
88              
89             my @includedPredicates= (); #only this predicates will be used in the traversal
90             my @excludedPredicates = (); #these predicates will be excluded in the traversal
91              
92             # method to create a new SemRep::Interface object
93             # input : $SemMedLoginParams <- reference to hash containing SemMed login parameter
94             # $AssociationLoginParams <- reference to hash containing the UMLS::Association login parameters
95             # output:
96             sub new {
97            
98             my $self = {};
99             my $class = shift;
100             my $SemMedLoginParams = shift; #hash containing the SemMed login parameters
101             my $AssociationLoginParams = shift; #hash containing the UMLS::Association login parameters
102             bless($self, $class);
103            
104             $connection = new DataAccess($SemMedLoginParams, $AssociationLoginParams);
105             $gt = new GraphTraversal($connection);
106            
107             return $self;
108             }
109              
110             #######################################
111              
112             =head3 findPathLength
113              
114             description:
115              
116             Utilizes a breadth first search to find the path length from a source_concept to a destination_concept
117              
118             input:
119              
120             $source_concept <- string containing the concept id of the cui to start seraching from
121             $destination_concept <- string containing the concept id you are searching for
122              
123             output:
124              
125             length of path <- Non-negative Integer indicating length of path between the two concepts
126              
127             example:
128            
129             #finds path length between Heart and Myocardial Infarction
130             use SemRep::Interface;
131             my $interface = new SemRep::Interface();
132            
133             my $pathlength = $interface->findPathLength("C0018787", "C0027061");
134            
135              
136             =cut
137             sub findPathLength{
138            
139             my $self = shift;
140             my $source_cui = shift;
141             my $destination_cui = shift;
142             return $gt->findPath($source_cui, $destination_cui, \@includedPredicates, \@excludedPredicates);
143              
144             }
145              
146             #######################################
147              
148             =head3 findPathSCore
149              
150             description:
151              
152             Function utilizing a breadth first search along with UMLS::Association to find the aggregate association score
153             along the path between source_concept and destination_concept
154              
155             input:
156              
157             $source_concept <- string containing the concept id of the cui to start seraching from
158             $destination_concept <- string containing the concept id you are searching for
159             $measure <- string containing the UMLS::Association statistic measure to aggregate along paths.
160              
161             output:
162              
163             Aggregate association score <- Non-negative float indicating the aggregate path score
164              
165             example:
166            
167             #finds aggregate association score between Heart and Myocardial Infarction
168             use SemRep::Interface;
169             my $interface = new SemRep::Interface();
170            
171             my $score = $interface->findPathLength("C0018787", "C0027061", "tscore");
172            
173              
174             =cut
175             sub findPathScore{
176            
177             my $self = shift;
178             my $source_cui = shift;
179             my $destination_cui = shift;
180             my $measure = shift;
181             return $gt->findPathScore($source_cui, $destination_cui, $measure, \@includedPredicates, \@excludedPredicates);
182              
183             }
184              
185             #############################
186              
187              
188             sub addIncludedPredicates{
189             my $self = shift;
190             my $predicates = shift;
191             push @includedPredicates, @$predicates;
192             }
193              
194             #############################
195              
196             sub clearIncludedPredicates{
197             my $self = shift;
198             @includedPredicates = ();
199             }
200              
201             #############################
202              
203             sub addExcludedPredicates{
204             my $self = shift;
205             my $predicates = shift;
206             push @excludedPredicates, @$predicates;
207             }
208              
209             #############################
210              
211             sub clearExcludedPredicates{
212             my $self = shift;
213             @excludedPredicates = ();
214             }
215              
216              
217              
218              
219             1;
220            
221              
222              
223              
224              
225              
226              
227              
228              
229              
230              
231              
232