#!/usr/bin/perl
GetOptions(
"version"
,
"help"
,
"username=s"
,
"password=s"
,
"hostname=s"
,
"database=s"
,
"socket=s"
,
"config=s"
);
if
(
defined
$opt_help
) {
$opt_help
= 1;
&showHelp
();
exit
;
}
if
(
defined
$opt_version
) {
$opt_version
= 1;
&showVersion
();
exit
;
}
if
(
scalar
(
@ARGV
) < 1) {
print
STDERR
"No term was specified on the command line\n"
;
&minimalUsageNotes
();
exit
;
}
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
=
""
;
if
(
defined
$opt_username
and
defined
$opt_password
and
defined
$opt_config
) {
$umls
= UMLS::Interface->new({
"driver"
=>
"mysql"
,
"database"
=>
"$database"
,
"username"
=>
"$opt_username"
,
"password"
=>
"$opt_password"
,
"hostname"
=>
"$hostname"
,
"socket"
=>
"$socket"
,
"config"
=>
"$opt_config"
});
die
"Unable to create UMLS::Interface object.\n"
if
(!
$umls
);
(
$errCode
,
$errString
) =
$umls
->getError();
die
"$errString\n"
if
(
$errCode
);
}
elsif
(
defined
$opt_username
and
defined
$opt_password
) {
$umls
= UMLS::Interface->new({
"driver"
=>
"mysql"
,
"database"
=>
"$database"
,
"username"
=>
"$opt_username"
,
"password"
=>
"$opt_password"
,
"hostname"
=>
"$hostname"
,
"socket"
=>
"$socket"
});
die
"Unable to create UMLS::Interface object.\n"
if
(!
$umls
);
(
$errCode
,
$errString
) =
$umls
->getError();
die
"$errString\n"
if
(
$errCode
);
}
elsif
(
defined
$opt_config
) {
$umls
= UMLS::Interface->new({
"config"
=>
"$opt_config"
});
die
"Unable to create UMLS::Interface object.\n"
if
(!
$umls
);
(
$errCode
,
$errString
) =
$umls
->getError();
die
"$errString\n"
if
(
$errCode
);
}
else
{
$umls
= UMLS::Interface->new();
die
"Unable to create UMLS::Interface object.\n"
if
(!
$umls
);
(
$errCode
,
$errString
) =
$umls
->getError();
die
"$errString\n"
if
(
$errCode
);
}
&errorCheck
(
$umls
);
my
$input
=
shift
;
my
$rel
=
shift
;
my
$term
=
$input
;
my
@c
= ();
if
(
$input
=~/C[0-9]+/) {
push
@c
,
$input
;
(
$term
) =
$umls
->getTermList(
$input
);
}
else
{
@c
=
$umls
->getConceptList(
$input
);
}
&errorCheck
(
$umls
);
my
$printFlag
= 0;
foreach
my
$cui
(
@c
) {
if
(
$umls
->validCui(
$cui
)) {
print
STDERR
"ERROR: The concept ($cui) is not valid.\n"
;
exit
;
}
my
@cuis
=
$umls
->getRelated(
$cui
,
$rel
);
&errorCheck
(
$umls
);
if
(
$#cuis
< 0) {
print
"No CUIs are associated with $term ($cui) given the relation ($rel).\n"
;
}
else
{
print
"The related ($rel) CUIs to $term ($cui):\n"
;
foreach
my
$related_cui
(
@cuis
) {
my
(
$t
) =
$umls
->getTermList(
$related_cui
);
print
" $t ($related_cui)\n"
;
}
}
$printFlag
= 1;
}
if
(! (
$printFlag
) ) {
print
"No CUIs are associated with $input given the relation ($rel).\n"
;
}
sub
errorCheck
{
my
$obj
=
shift
;
(
$errCode
,
$errString
) =
$obj
->getError();
print
STDERR
"$errString\n"
if
(
$errCode
);
exit
if
(
$errCode
> 1);
}
sub
minimalUsageNotes {
print
"Usage: getRelated.pl [OPTIONS] [CUI|TERM] REL\n"
;
&askHelp
();
exit
;
}
sub
showHelp() {
print
"This is a utility that takes as input a CUI (or a \n"
;
print
"term) and a relation and returns all the related CUIs \n"
;
print
"a specified set of sources\n\n"
;
print
"Usage: getRelated.pl [OPTIONS] [CUI|TERM] REL\n\n"
;
print
"Options:\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
"--version Prints the version number\n\n"
;
print
"--help Prints this help message.\n\n"
;
}
sub
showVersion {
print
'$Id: getRelated.pl,v 1.10 2009/10/13 18:46:06 btmcinnes Exp $'
;
print
"\nCopyright (c) 2008, Ted Pedersen & Bridget McInnes\n"
;
}
sub
askHelp {
print
STDERR
"Type getRelated.pl --help for help.\n"
;
}