#!/usr/bin/perl
eval
(GetOptions(
"version"
,
"help"
,
"debug"
,
"username=s"
,
"password=s"
,
"hostname=s"
,
"database=s"
,
"socket=s"
,
"config=s"
,
"forcerun"
,
"verbose"
,
"debugpath=s"
,
"cuilist=s"
,
"realtime"
,
"infile=s"
,
"depth"
,
"propagation=s"
)) or
die
(
"Please check the above mentioned option(s).\n"
);
if
(
defined
$opt_help
) {
$opt_help
= 1;
&showHelp
();
exit
;
}
if
(
defined
$opt_version
) {
$opt_version
= 1;
&showVersion
();
exit
;
}
my
@fileArray
= ();
if
(
defined
$opt_infile
) {
open
(FILE,
$opt_infile
) ||
die
"Could not open infile: $opt_infile\n"
;
while
(<FILE>) {
chomp
;
if
(
$_
=~/^\s*$/) {
next
; }
push
@fileArray
,
$_
;
}
close
FILE;
}
else
{
if
(
scalar
(
@ARGV
) < 2 ) {
print
STDERR
"Two terms and/or CUIs are required\n"
;
&minimalUsageNotes
();
exit
;
}
my
$i1
=
shift
;
my
$i2
=
shift
;
my
$string
=
"$i1<>$i2"
;
push
@fileArray
,
$string
;
}
my
$database
=
"umls"
;
if
(
defined
$opt_database
) {
$database
=
$opt_database
; }
my
$hostname
=
"localhost"
;
if
(
defined
$opt_hostname
) {
$hostname
=
$opt_hostname
; }
my
$socket
=
"/tmp/mysql.sock"
;
if
(
defined
$opt_socket
) {
$socket
=
$opt_socket
; }
my
$umls
=
""
;
my
$precision
= 4;
my
$floatformat
=
join
''
,
'%'
,
'.'
,
$precision
,
'f'
;
my
%option_hash
= ();
if
(
defined
$opt_propagation
) {
$option_hash
{
"propagation"
} =
$opt_propagation
;
}
if
(
defined
$opt_debug
) {
$option_hash
{
"debug"
} =
$opt_debug
;
}
if
(
defined
$opt_realtime
) {
$option_hash
{
"realtime"
} =
$opt_realtime
;
}
if
(
defined
$opt_config
) {
$option_hash
{
"config"
} =
$opt_config
;
}
if
(
defined
$opt_forcerun
) {
$option_hash
{
"forcerun"
} =
$opt_forcerun
;
}
if
(
defined
$opt_verbose
) {
$option_hash
{
"verbose"
} =
$opt_verbose
;
}
if
(
defined
$opt_debugpath
) {
$option_hash
{
"debugpath"
} =
$opt_debugpath
;
}
if
(
defined
$opt_cuilist
) {
$option_hash
{
"cuilist"
} =
$opt_cuilist
;
}
if
(
defined
$opt_username
) {
$option_hash
{
"username"
} =
$opt_username
;
}
if
(
defined
$opt_driver
) {
$option_hash
{
"driver"
} =
"mysql"
;
}
if
(
defined
$opt_database
) {
$option_hash
{
"database"
} =
$database
;
}
if
(
defined
$opt_password
) {
$option_hash
{
"password"
} =
$opt_password
;
}
if
(
defined
$opt_hostname
) {
$option_hash
{
"hostname"
} =
$hostname
;
}
if
(
defined
$opt_socket
) {
$option_hash
{
"socket"
} =
$socket
;
}
$umls
= UMLS::Interface->new(\
%option_hash
);
die
"Unable to create UMLS::Interface object.\n"
if
(!
$umls
);
foreach
my
$element
(
@fileArray
) {
my
(
$input1
,
$input2
) =
split
/<>/,
$element
;
my
@c1
= ();
my
@c2
= ();
if
( (
$input1
=~/C[0-9]+/)) {
push
@c1
,
$input1
;
}
else
{
@c1
=
$umls
->getConceptList(
$input1
);
}
if
( (
$input2
=~/C[0-9]+/)) {
push
@c2
,
$input2
;
}
else
{
@c2
=
$umls
->getConceptList(
$input2
);
}
my
$printFlag
= 0;
foreach
$cui1
(
@c1
) {
foreach
$cui2
(
@c2
) {
my
$t1
=
$input1
;
my
$t2
=
$input2
;
if
(
$t1
=~/C[0-9]+/) {
(
$t1
) =
$umls
->getTermList(
$cui1
);
}
if
(
$t2
=~/C[0-9]+/) {
(
$t2
) =
$umls
->getTermList(
$cui2
);
}
if
((
$umls
->
exists
(
$cui1
) == 0) or
(
$umls
->
exists
(
$cui2
) == 0) ) {
next
; }
if
(
$cui1
eq
$cui2
) {
print
"\nThe least common subsumer between $t1 ($cui1) and $t2 ($cui2) is $t1 ($cui1) "
;
if
(
defined
$opt_depth
) {
my
$min
=
$umls
->findMinimumDepth(
$cui1
);
my
$max
=
$umls
->findMaximumDepth(
$cui1
);
print
"with a min and max depth of $min and $max "
;
}
if
(
defined
$opt_propagation
) {
my
$ic
=
sprintf
$floatformat
,
$umls
->getIC(
$cui1
);
print
"with an IC of $ic "
;
}
print
"\n"
;
$printFlag
= 1;
next
;
}
my
@lcses
=
$umls
->findLeastCommonSubsumer(
$cui1
,
$cui2
);
foreach
my
$lcs
(
@lcses
) {
my
(
$t
) =
$umls
->getTermList(
$lcs
);
print
"\nThe least common subsumer between $t1 ($cui1) and $t2 ($cui2) is $t ($lcs) "
;
if
(
defined
$opt_depth
) {
my
$min
=
$umls
->findMinimumDepth(
$lcs
);
my
$max
=
$umls
->findMaximumDepth(
$lcs
);
print
"with a min and max depth of $min and $max "
;
}
if
(
defined
$opt_propagation
) {
my
$ic
=
sprintf
$floatformat
,
$umls
->getIC(
$lcs
);
print
"with an IC of $ic "
;
}
print
"\n"
;
$printFlag
= 1;
}
}
}
if
( !(
$printFlag
) ) {
print
"\n"
;
print
"There is not a least common subsumer between $input1 and $input2 given the current view of the UMLS.\n\n"
;
}
}
sub
minimalUsageNotes {
print
"Usage: findLeastCommonSubsumer.pl [OPTIONS] [CUI1|TERM1] [CUI2|TERM2]\n"
;
&askHelp
();
exit
;
}
sub
showHelp() {
print
"This is a utility that takes as input two Terms or CUIs\n"
;
print
"and returns the Least Common Subsumer between the two.\n\n"
;
print
"Usage: findLeastCommonSubsumer.pl [OPTIONS] [CUI1|TERM1] [CUI2|TERM2]\n\n"
;
print
"Options:\n\n"
;
print
"--infile FILE File containing TERM or CUI pairs\n\n"
;
print
"--depth Outputs the depth of the lcs\n\n"
;
print
"--propagation FILE Outputs the IC of the lcs\n\n"
;
print
"--debug Sets the debug flag for testing.\n\n"
;
print
"--username STRING Username required to access mysql\n\n"
;
print
"--password STRING Password required to access mysql\n\n"
;
print
"--hostname STRING Hostname for mysql (DEFAULT: localhost)\n\n"
;
print
"--database STRING Database contain UMLS (DEFAULT: umls)\n\n"
;
print
"--socket STRING Socket used by mysql (DEFAULT: /tmp.mysql.sock)\n\n"
;
print
"--config FILE Configuration file\n\n"
;
print
"--realtime This option will not create a database of the\n"
;
print
" path information for all of concepts but just\n"
;
print
" obtain the information for the input concept\n\n"
;
print
"--forcerun This option will bypass any command \n"
;
print
" prompts such as asking if you would \n"
;
print
" like to continue with the index \n"
;
print
" creation. \n\n"
;
print
"--debugpath FILE This option prints out the path\n"
;
print
" information for debugging purposes\n\n"
;
print
"--verbose This option prints out table information\n"
;
print
" to a directory in your config directory.\n\n"
;
print
"--cuilist FILE This option takes in a file containing a \n"
;
print
" list of CUIs (one CUI per line) and stores\n"
;
print
" only the path information for those CUIs\n"
;
print
" rather than for all of the CUIs\n\n"
;
print
"--version Prints the version number\n\n"
;
print
"--help Prints this help message.\n\n"
;
}
sub
showVersion {
print
'$Id: findLeastCommonSubsumer.pl,v 1.18 2010/05/24 17:57:16 btmcinnes Exp $'
;
print
"\nCopyright (c) 2008, Ted Pedersen & Bridget McInnes\n"
;
}
sub
askHelp {
print
STDERR
"Type findLeastCommonSubsumer.pl --help for help.\n"
;
}