| Summary | Package variables | Synopsis | General documentation | Methods |
| Summary | Top |
| Clair::Bio::Connection - Connect to the Bio database using SOAP head1 VERSION Version 0.01 |
| Package variables | Top |
| No package variables defined. |
| Included modules | Top |
| Clair::Cluster |
| Clair::Document |
| Clair::Network |
| FindBin |
| SOAP::Lite |
| Synopsis | Top |
This module connects to the biodb using SOAP. #!/usr/bin/perl -w |
| Description | Top |
| Methods | Top |
| _get_citations | No description | Code |
| _hashref_to_network | No description | Code |
| count_citations | Description | Code |
| dbquery | Description | Code |
| get_abstract | Description | Code |
| get_abstract_sentences | Description | Code |
| get_body | Description | Code |
| get_citation_network | Description | Code |
| get_cited_ids | No description | Code |
| get_citing_ids | No description | Code |
| get_citing_sentences | Description | Code |
| get_degree | No description | Code |
| get_degree_in | Description | Code |
| get_degree_out | Description | Code |
| get_full_citation_network | Description | Code |
| get_ids | Description | Code |
| get_pagerank | No description | Code |
| get_sentences | Description | Code |
| get_title | Description | Code |
| list_to_sql_list | No description | Code |
| new | Description | Code |
| count_citations() | code | next | Top |
| Returns the total number of citations in the database. |
| dbquery($statement) | code | prev | next | Top |
| Executes the given statement on the database and returns the results. The result is an array of array references. See the synopsis for an example. |
| get_abstract($id) | code | prev | next | Top |
| Returns all of the sentences from the abstract of the document with PMID $id concatenated together. |
| get_abstract_sentences($id) | code | prev | next | Top |
| Returns a list of sentences from the abstract of the document with PMID $id. |
| get_body($id) | code | prev | next | Top |
| Returns all of the sentences of the document with PMID $id concatenated together. |
| get_citation_network(@ids) | code | prev | next | Top |
| Returns a Clair::Network object of ids with an edge between id1 and id2 if id1 cites id2. Generates the network starting from the ids in @ids. |
| get_citing_sentences($citer, $cited) | code | prev | next | Top |
| Returns a list of sentences from the document with PMID $citer that cite the document with PMID $cited. This list will have the same structure as in get_sentences. |
| get_degree_in($id) | code | prev | next | Top |
| Returns the total number of papers that cite the document with PMID $id. |
| get_degree_out($id) | code | prev | next | Top |
| Returns the total number of papers the document with PMID $id cites. |
| get_full_citation_network() | code | prev | next | Top |
| Returns a Clair::Network object containing the full citation network. |
| get_ids() | code | prev | next | Top |
| Returns a list of the ids of every paper in the database. |
| get_sentences($id) | code | prev | next | Top |
| Returns a list of hash references containing information about each sentence in the document with PMID $id. Each element in the list is in the form { parno => ..., rsnt => ..., sno => ..., text => .. }. |
| get_title($id) | code | prev | next | Top |
| Returns the title of the document with PMID $id. |
| new | code | prev | next | Top |
| Creates a new Connection object. The following parameters can be set: proxy, server, database, user, password. |
| _get_citations | description | prev | next | Top |
sub _get_citations
{ my $self = shift;
if ($self->{_forward_graph} && $self->{_backward_graph}) {
return ($self->{_forward_graph}, $self->{_backward_graph});
}
my $statement = "SELECT citer, cited FROM citations";
my @rows = $self->dbquery($statement);
my %forward_graph;
my %backward_graph;
foreach my $row (@rows) {
my ($from, $to) = ($row->[0], $row->[1]);
unless ($forward_graph{$from}) {
$forward_graph{$from} = {};
}
$forward_graph{$from}->{$to} = 1;
unless ($backward_graph{$to}) {
$backward_graph{$to} = {};
}
$backward_graph{$to}->{$from} = 1;
}
$self->{_forward_graph} =\% forward_graph;
$self->{_backward_graph} =\% backward_graph;
return (\%forward_graph,\% backward_graph);} |
| _hashref_to_network | description | prev | next | Top |
sub _hashref_to_network
{ my $self = shift;
my $hashref = shift;
my $n = new Clair::Network();
foreach my $from (keys %$hashref) {
$n->add_node($from) unless $n->has_node($from);
foreach my $to (keys %{ $hashref->{$from} } ) {
$n->add_node($to) unless $n->has_node($to);
my $edge = $n->add_edge($from, $to);
$n->set_edge_attribute($from, $to, 'pagerank_transition', 1);
}
}
return $n;} |
| count_citations | description | prev | next | Top |
sub count_citations
{ my $self = shift;
my $statement = "SELECT count(*) FROM citations";
my @rows = $self->dbquery($statement);
return $rows[0]->[0];} |
| dbquery | description | prev | next | Top |
sub dbquery
{
my $self = shift;
my $statement = shift;
my $client = SOAP::Lite->new();
$client->proxy($self->{"proxy"});
my $som = $client->dbquery(
$self->{"server"},
$self->{"database"},
$self->{"user"},
$self->{"password"}, $statement) || die "Query failed $!";
my $result_chunk = $som->result();
# A tab and newline separated chunk of text is what we get back. } |
| get_abstract | description | prev | next | Top |
sub get_abstract
{ my $self = shift;
my $id = shift;
my @sents = $self->get_abstract_sentences($id);
my $result = "";
for (@sents) {
$result .= $_->{text};
}
return $result;} |
| get_abstract_sentences | description | prev | next | Top |
sub get_abstract_sentences
{ my $self = shift;
my $id = shift;
my $statement = "SELECT parid, sentid, sentence FROM abstracts WHERE "
. "pmcid=$id ORDER BY parid, sentid";
my @rows = $self->dbquery($statement);
my @result;
for (@rows) {
push @result, {
parno => $_->[0],
sno => $_->[1],
text => $_->[2]
};
}
return @result;} |
| get_body | description | prev | next | Top |
sub get_body
{ my $self = shift;
my $id = shift;
my @sents = $self->get_sentences($id);
my $result = "";
for (@sents) {
$result .= $_->{text};
}
return $result;} |
| get_citation_network | description | prev | next | Top |
sub get_citation_network
{ my $self = shift;
my @ids = @_;
my ($forward_graph, $backward_graph) = $self->_get_citations();
my $subgraph = {};
my $visited = {};
my %to_visit = ();
map { $to_visit{$_} = 1 } @ids;
while (keys %to_visit) {
my ($id, $junk) = each %to_visit;
delete $to_visit{$id};
$visited->{$id} = 1;
unless ($subgraph->{$id}) {
$subgraph->{$id} = {};
}
for (keys %{ $forward_graph->{$id} }) {
$subgraph->{$id}->{$_} = 1;
$to_visit{$_} = 1 unless $visited->{$_};
}
for (keys %{ $backward_graph->{$id} }) {
unless ($subgraph->{$_}) {
$subgraph->{$_} = {};
}
$subgraph->{$_}->{$id} = 1;
$to_visit{$_} = 1 unless $visited->{$_};
}
}
my $n = $self->_hashref_to_network($subgraph);
return $n;} |
| get_cited_ids | description | prev | next | Top |
sub get_cited_ids
{ my $self = shift;
my $citing = shift;
my $statement = "SELECT cited FROM citations WHERE citer=$citing";
my @rows = $self->dbquery($statement);
@rows = map { $_->[0] } @rows;
return @rows;} |
| get_citing_ids | description | prev | next | Top |
sub get_citing_ids
{ my $self = shift;
my $cited = shift;
my $statement = "SELECT citer FROM citations WHERE cited=$cited";
my @rows = $self->dbquery($statement);
@rows = map { $_->[0] } @rows;
return @rows;} |
| get_citing_sentences | description | prev | next | Top |
sub get_citing_sentences
{ my $self = shift;
my $citer = shift;
my $cited = shift;
my $statement_xml = "SELECT sentence.parno, sentence.rsnt, sentence.sno, "
."sentence.sentence, citation FROM references_xml, "
. "sentence, pmid WHERE citation=sentence AND "
. "cited_pmid=pmid AND pmid.pmcid=$cited AND "
. "citer_pmcid=$citer AND sentence.pmcid=$citer";
my $statement_html = "SELECT sentence.parno, sentence.rsnt, sentence.sno, "
. "sentence.sentence, citation FROM references_html, "
. "sentence WHERE citation=sentence AND "
. "cited_pmcid=$cited AND citer_pmcid=$citer AND "
. "sentence.pmcid=$citer";
my @xml_rows = $self->dbquery($statement_xml);
my @html_rows = $self->dbquery($statement_html);
my @rows = (@xml_rows, @html_rows);
my @result;
for (@rows) {
push @result, {
parno => $_->[0],
rsnt => $_->[1],
sno => $_->[2],
text => $_->[3]
};
}
return @result;} |
| get_degree | description | prev | next | Top |
sub get_degree
{ my $self = shift;
my $id = shift;
my $type = shift;
die "Type must be citer or cited"
unless ($type eq "citer" or $type eq "cited");
my $statement = "SELECT count(*) FROM citations WHERE $type=$id";
my @rows = $self->dbquery($statement);
return $rows[0]->[0];} |
| get_degree_in | description | prev | next | Top |
sub get_degree_in
{ my $self = shift;
my $id = shift;
return $self->get_degree($id, "cited");} |
| get_degree_out | description | prev | next | Top |
sub get_degree_out
{ my $self = shift;
my $id = shift;
return $self->get_degree($id, "citer");} |
| get_full_citation_network | description | prev | next | Top |
sub get_full_citation_network
{ my $self = shift;
my ($forward_graph, $backward_graph) = $self->_get_citations();
return $self->_hashref_to_network($forward_graph);} |
| get_ids | description | prev | next | Top |
sub get_ids
{ my $self = shift;
my @list = @_;
my $statement = "SELECT pmcid FROM openaccess_pmcids";
if (@list) {
my $lstr = join ",", map { "'$_'" } @list;
$statement .= " WHERE pmcid in ($lstr)";
}
my @rows = $self->dbquery($statement);
my @result;
for (@rows) {
push @result, $_->[0];
}
return @result;} |
| get_pagerank | description | prev | next | Top |
sub get_pagerank
{ my $self = shift;
my @ids = shift;
return undef unless @ids;
my $str = list_to_sql_list(@ids);
my $statement = "SELECT pmcid, pagerank_score FROM pagerank WHERE pmcid "
. "IN $str";
my @rows = $self->dbquery($statement);
my %scores;
foreach my $row (@rows) {
my ($pmcid, $score) = @$row;
$scores{$pmcid} = $score;
}
return %scores;} |
| get_sentences | description | prev | next | Top |
sub get_sentences
{ my $self = shift;
my $id = shift;
my $statement = "SELECT parno, rsnt, sno, sentence FROM "
. "sentence WHERE pmcid = $id ORDER BY sno";
my @rows = $self->dbquery($statement);
my @result = ();
for (@rows) {
my ($parno, $rsnt, $sno, $text) = @$_;
my %map = ( parno => $parno,
rsnt => $rsnt,
sno => $sno,
text => $text );
push @result,\% map;
}
return @result;} |
| get_title | description | prev | next | Top |
sub get_title
{ my $self = shift;
my $id = shift;
my $statement = "SELECT atitle FROM atitle WHERE pmcid=$id";
my @rows = $self->dbquery($statement);
return $rows[0]->[0];} |
| list_to_sql_list | description | prev | next | Top |
sub list_to_sql_list
{ my @list = @_;
my $joined = join ", ", @list;
return "($joined)";} |
| new | description | prev | next | Top |
sub new
{ my $class = shift;
my %given_parameters = @_;
my %parameters = (
"proxy" => "http://www.bioinformatics.med.umich.edu/app/mbi/dbquery.php",
"server" => "db3",
"database" => "pmcoa",
"user" => "bionlp",
"password" => "bionlp04" );
for (keys %given_parameters) {
$parameters{$_} = $given_parameters{$_};
}
my $self = bless\% parameters, $class;
return $self;} |