Commit 4d10a1ff authored by Magali Ruffier's avatar Magali Ruffier
Browse files

ENSCORESW-371: annotation extensions commited back from branch into head

parent 99a68e97
......@@ -776,6 +776,49 @@ sub _store_object_xref_mapping {
$sth->bind_param( 3, $linkage_type, SQL_VARCHAR );
$sth->execute();
} #end foreach
$sth = $self->prepare( "
INSERT ignore INTO associated_xref
SET object_xref_id = ?,
xref_id = ?,
source_xref_id = ?,
condition_type = ?,
associated_group_id = ?,
rank = ? " );
my $annotext = $dbEntry->get_all_associated_xrefs();
foreach my $ax_group (sort keys %{ $annotext }) {
my $group = $annotext->{$ax_group};
my $gsth = $self->prepare( "
INSERT INTO associated_group
SET description = ?;" );
$sth->bind_param( 1, $ax_group, SQL_INTEGER );
$gsth->execute();
my $associatedGid = $self->last_insert_id();
foreach my $ax_rank (sort keys %{ $group }) {
my @ax = @{ $group->{$ax_rank} };
my $associatedXid = undef;
my $sourceXid = undef;
$ax[0]->is_stored( $self->dbc ) || $self->store($ax[0]);
$associatedXid = $ax[0]->dbID;
$ax[1]->is_stored( $self->dbc ) || $self->store($ax[1]);
$sourceXid = $ax[1]->dbID;
if (!defined $associatedXid || !defined $sourceXid) {
next;
}
$sth->bind_param( 1, $object_xref_id, SQL_INTEGER );
$sth->bind_param( 2, $associatedXid, SQL_INTEGER );
$sth->bind_param( 3, $sourceXid, SQL_INTEGER );
$sth->bind_param( 4, $ax[2], SQL_VARCHAR );
$sth->bind_param( 5, $associatedGid, SQL_VARCHAR );
$sth->bind_param( 6, $ax_rank, SQL_INTEGER );
$sth->execute();
}
} #end foreach
} #end elsif
} # end if ($object_xref_id)
return $object_xref_id;
......@@ -1178,6 +1221,11 @@ sub remove_from_object {
$sth->bind_param(1,$ox_id,SQL_INTEGER);
$sth->execute();
$sth->finish();
$sth = $self->prepare("DELETE FROM associated_xref WHERE object_xref_id = ?");
$sth->bind_param(1,$ox_id,SQL_INTEGER);
$sth->execute();
$sth->finish();
$sth = $self->prepare("DELETE FROM identity_xref WHERE object_xref_id = ?");
$sth->bind_param(1,$ox_id,SQL_INTEGER);
......@@ -1247,11 +1295,15 @@ sub _fetch_by_object_type {
idt.cigar_line, idt.score, idt.evalue, oxr.analysis_id,
gx.linkage_type,
xref.info_type, xref.info_text, exDB.type, gx.source_xref_id,
oxr.linkage_annotation, xref.description
oxr.linkage_annotation, xref.description,
ax.xref_id, ax.source_xref_id, ax.condition_type,
ax.associated_group_id, ax.rank
FROM (xref xref, external_db exDB, object_xref oxr)
LEFT JOIN external_synonym es on es.xref_id = xref.xref_id
LEFT JOIN identity_xref idt on idt.object_xref_id = oxr.object_xref_id
LEFT JOIN ontology_xref gx on gx.object_xref_id = oxr.object_xref_id
LEFT JOIN associated_xref ax ON ax.object_xref_id = oxr.object_xref_id
LEFT JOIN associated_group ag ON ax.associated_group_id = ag.associated_group_id
WHERE xref.xref_id = oxr.xref_id
AND xref.external_db_id = exDB.external_db_id
AND oxr.ensembl_id = ?
......@@ -1284,32 +1336,39 @@ SSQL
$sth->bind_param( 2, $ensType, SQL_VARCHAR );
$sth->execute();
my ( %seen, %linkage_types, %synonyms );
my ( %seen, %linkage_types, %synonyms, %associated_xrefs );
my $max_rows = 1000;
while ( my $rowcache = $sth->fetchall_arrayref( undef, $max_rows ) ) {
while ( my $arrRef = shift( @{$rowcache} ) ) {
my ( $refID, $dbprimaryId,
$displayid, $version,
my ( $refID, $dbprimaryId,
$displayid, $version,
$priority,
$dbname, $release,
$exDB_status, $exDB_db_display_name,
$exDB_secondary_db_name, $exDB_secondary_db_table,
$objid, $synonym,
$xrefid, $ensemblid,
$xref_start, $xref_end,
$ensembl_start, $ensembl_end,
$cigar_line, $score,
$evalue, $analysis_id,
$linkage_type, $info_type,
$info_text, $type,
$source_xref_id, $link_annotation,
$description
$dbname, $release,
$exDB_status, $exDB_db_display_name,
$exDB_secondary_db_name, $exDB_secondary_db_table,
$objid, $synonym,
$xrefid, $ensemblid,
$xref_start, $xref_end,
$ensembl_start, $ensembl_end,
$cigar_line, $score,
$evalue, $analysis_id,
$linkage_type, $info_type,
$info_text, $type,
$source_xref_id, $link_annotation,
$description, $associated_xref_id,
$source_associated_xref_id, $condition_type,
$associate_group_id, $associate_group_rank
) = @$arrRef;
my $linkage_key =
( $linkage_type || '' ) . ( $source_xref_id || '' );
my $associated_key =
( $condition_type || '' )
. ( $source_associated_xref_id || '' )
. ( $associated_xref_id || '' );
my $analysis = undef;
......@@ -1341,6 +1400,8 @@ SSQL
# original). Since there is at most one identity_xref row per
# xref, this is easy enough; all the 'extra' bits are synonyms.
my $source_xref;
my $associated_xref;
my $source_associated_xref;
if ( !$seen{$refID} ) {
my $exDB;
......@@ -1364,6 +1425,20 @@ SSQL
: undef );
$exDB->add_linkage_type( $linkage_type, $source_xref || () );
$linkage_types{$refID}->{$linkage_key} = 1;
# Add associated Xref annotations to the OntologyXref entry.
if ( defined $associated_xref_id && $associated_xref_id ne "" ) {
$exDB = Bio::EnsEMBL::OntologyXref->new_fast( \%obj_hash );
$associated_xref = ( defined($associated_xref_id)
? $self->fetch_by_dbID($associated_xref_id)
: undef );
$source_associated_xref = ( defined($source_associated_xref_id)
? $self->fetch_by_dbID($source_associated_xref_id)
: undef );
if ( defined($associated_xref) ) {
$exDB->add_linked_associated_xref( $associated_xref, $source_associated_xref, $condition_type || '', $associate_group_id, $associate_group_rank );
}
}
} else {
$exDB = Bio::EnsEMBL::DBEntry->new_fast( \%obj_hash );
......@@ -1400,6 +1475,24 @@ SSQL
->add_linkage_type( $linkage_type, $source_xref || () );
$linkage_types{$refID}->{$linkage_key} = 1;
}
if ( defined($associated_xref_id)
&& $associated_xref_id ne ""
&& !$associated_xrefs{$refID}->{$associated_key} )
{
$associated_xref = ( defined($associated_xref_id)
? $self->fetch_by_dbID($associated_xref_id)
: undef );
$source_associated_xref = ( defined($source_associated_xref_id)
? $self->fetch_by_dbID($source_associated_xref_id)
: undef );
if ( defined($associated_xref) ) {
$seen{$refID}->add_linked_associated_xref( $associated_xref, $source_associated_xref, $condition_type || '', $associate_group_id, $associate_group_rank );
}
$linkage_types{$refID}->{$linkage_key} = 1;
}
} ## end while ( my $arrRef = shift...
} ## end while ( my $rowcache = $sth...
......
......@@ -176,4 +176,335 @@ sub flush_linkage_types {
$self->{'linkage_types'} = [];
}
=head2 add_associated_xref
Arg [1] : Bio::EnsEMBL::DBEntry $associated_xref
or an Array of Bio::EnsEMBL::DBEntry for compound annotations
Arg [2] : Bio::EnsEMBL::DBEntry $source_dbentry
Arg [3] : string $condition_type or an Array of string $condition_types
matching the order of Arg[1] for compound queries.
Arg [4] : (optional) Integer $group id for compound annotations.
Arg [5] : (optional) Integer $rank order for a term within a compound annotation.
Example : $ontology_xref->add_associated_xref(
$associated_xref,
$source_dbentry,
'with',
42,
5);
Description: Associates a linkage type and source DBEntry with
this ontology_xref
Returntype : none
Exceptions : thrown if $linkage_type argument not supplied or
the optional DBEntry is not a DBEntry object.
Caller : DBEntryAdaptor
Status : Experimantal
=cut
sub add_associated_xref {
my ( $self, $associated_xref, $source_dbentry, $condition_type, $group, $rank ) = @_;
if ( ref($associated_xref) eq 'ARRAY' )
{
foreach my $e ( @{ $associated_xref } ) {
if ( !$e->isa('Bio::EnsEMBL::DBEntry') ) {
$self->throw("associated_xref must be a Bio::EnsEMBL::DBEntry or an
Array of Bio::EnsEMBL::DBEntry objects.");
}
}
} elsif ( defined($associated_xref)
&& !$associated_xref->isa('Bio::EnsEMBL::DBEntry') )
{
$self->throw("associated_xref must be a Bio::EnsEMBL::DBEntry or an Array
of Bio::EnsEMBL::DBEntry objects.");
}
if ( defined($source_dbentry)
&& !$source_dbentry->isa('Bio::EnsEMBL::DBEntry') )
{
$self->throw("source_dbentry must be a Bio::EnsEMBL::DBEntry");
}
if ( !defined $condition_type ) {
$self->throw("condition must be a string");
}
if (!defined $group) {
$group = 1 + scalar keys %{ $self->{'associated_xref'} };
}
if (!defined $rank) {
#$rank = 0;
$rank = 1 + scalar keys %{ $self->{'associated_xref'}->{ $group } };
}
$self->{'associated_xref'} ||= {};
$self->{'associated_xref'}->{ $group }->{$rank} =
[ $associated_xref, $source_dbentry, $condition_type ];
}
=head2 add_linked_associated_xref
Arg [1] : Bio::EnsEMBL::DBEntry $associated_xref
or an Array of Bio::EnsEMBL::DBEntry for compound annotations
Arg [2] : Bio::EnsEMBL::DBEntry $source_dbentry
Arg [3] : string $condition_type or an Array of string $condition_types
matching the order of Arg[1] for compound queries.
Arg [4] : Integer $group id.
Arg [5] : Integer $rank id.
Example : $ontology_xref->add_associated_xref(
$associated_xref,
$source_dbentry,
'with',
42,
5);
Description: Associates a linkage type and source DBEntry with this
ontology_xref that have come from the same annotation source
Returntype : none
Exceptions : thrown if $linkage_type argument not supplied or
the optional DBEntry is not a DBEntry object.
Caller : DBEntryAdaptor
Status : Experimantal
=cut
sub add_linked_associated_xref {
my ( $self, $associated_xref, $source_dbentry, $condition_type, $associate_group_id, $associate_group_rank ) = @_;
if ( !defined($associated_xref) )
{
$self->throw("associated_xref must be a Bio::EnsEMBL::DBEntry or an Array
of Bio::EnsEMBL::DBEntry objects.");
}
if ( defined($associated_xref)
&& !$associated_xref->isa('Bio::EnsEMBL::DBEntry') )
{
$self->throw("associated_xref must be a Bio::EnsEMBL::DBEntry or an Array
of Bio::EnsEMBL::DBEntry objects.");
}
if ( defined($source_dbentry)
&& !$source_dbentry->isa('Bio::EnsEMBL::DBEntry') )
{
$self->throw("source_dbentry must be a Bio::EnsEMBL::DBEntry");
}
if ( !defined $condition_type ) {
$self->throw("condition must be a string");
}
if ( !defined $associate_group_id )
{
$self->throw("$associate_group_id must be an integer");
}
if ( !defined $associate_group_rank )
{
$self->throw("$associate_group_rank must be an integer");
}
# print "\t" . $associate_group_id;
# print "\t" . $associate_group_rank;
# print "\t|" . defined($associated_xref) . '|';
# #print "\t" . defined($associated_xref->primary_id);
# print "\t" . $associated_xref->primary_id;# . ' (' . $associated_xref->display_id . ')';
# print "\t" . $source_dbentry->primary_id;
# print "\t" . $condition_type . "\n";
my $associated_xref_array = {};
my $matching_link = 0;
my $load_postion = 0;
if ( !defined $self->{'associated_xref'} ) {
$associated_xref_array->{$associate_group_id}->{$associate_group_rank} = [
$associated_xref,
$source_dbentry,
$condition_type
];
$load_postion = 1;
} else {
$associated_xref_array = $self->{'associated_xref'};
if (!defined $associated_xref_array->{$associate_group_id} ) {
$associated_xref_array->{$associate_group_id}->{$associate_group_rank} = [
$associated_xref,
$source_dbentry,
$condition_type
];
$load_postion = 2;
} else {
my $already_loaded = 0;
foreach my $rank ( keys %{$associated_xref_array->{$associate_group_id}} ) {
my @ax_gr_set = @{ $associated_xref_array->{$associate_group_id}->{$rank} };
if (
$ax_gr_set[0]->primary_id eq $associated_xref->primary_id &&
$ax_gr_set[1]->primary_id eq $source_dbentry->primary_id &&
$ax_gr_set[2] eq $condition_type
) {
$already_loaded = 1;
$load_postion = 4;
#last;
}
}
if ( !$already_loaded ) {
if (!defined $associated_xref_array->{$associate_group_id}->{$associate_group_rank} ) {
$associated_xref_array->{$associate_group_id}->{$associate_group_rank} = [
$associated_xref,
$source_dbentry,
$condition_type
];
$load_postion = 5;
} else {
$associated_xref_array->{$associate_group_id}->{scalar keys %{ $associated_xref_array->{$associate_group_id} }} = [
$associated_xref,
$source_dbentry,
$condition_type
];
$load_postion = 3;
}
}
}
}
$self->{'associated_xref'} = $associated_xref_array;
# print "\t\tLoaded at " . $load_postion . "\n";
# if ($associate_group_id == 28792 || $associate_group_id == 28793) {
# print Data::Dumper->Dumper([$self->{'associated_xref'}]);
# }
}
=head2 get_all_associated_xrefs
Arg [1] : none
Example :
foreach ( @{ $ontology_xref->get_all_associated_xref() } ) {
print "evidence: $_->[0] via $_->[1]->display_id";
}
Description: Retrieves a list of associated-DBEntry/source-DBEntry/condition
sets associated with this ontology_xref
Returntype : listref of listrefs
Exceptions : none
Caller : geneview? general.
Status : Experimental
=cut
sub get_all_associated_xrefs {
my ($self) = @_;
return $self->{'associated_xref'} || {};
}
=head2 get_extensions
Arg [1] : none
Example :
use Data::Dumper;
print Dumper @{ $ontology_xref->get_extensions_for_web() }
Returns :
$VAR1 = {
'source' => '<a href="<Link to CiteXplore>">11937031</a>',
'evidence' => 'IDA',
'description' => '<strong>has_direct_input</strong>
<a href="http://www.pombase.org/spombe/result/SPBC32F12.09">
SPBC32F12.09
</a>'
};
Description: Retrieves a list of associated-DBEntry/source-DBEntry/condition
sets associated with this ontology_xref and formats them ready
for web display in a group per row fashion.
The accessions for ontologies are linkable. Extra links need to
be added for each distinct database that is reference.
Returntype : listref of hashrefs
Exceptions : none
Caller :
Status : Experimental
=cut
sub get_extensions {
my ($self) = @_;
if ( !defined $self->{'associated_xref'} ) {
return [];
}
my @annotExtRows = ();
my %external_urls = (
'GO' => 'http://www.ebi.ac.uk/ego/GTerm?id=',
'GO_REF' => 'http://www.geneontology.org/cgi-bin/references.cgi#',
'SO' => 'http://www.sequenceontology.org/miso/current_cvs/term/',
#'MOD' => 'href=mod',
'PomBase' => 'http://www.pombase.org/spombe/result/',
'PomBase_Systematic_ID' => 'http://www.pombase.org/spombe/result/',
'PUBMED' => 'http://europepmc.org/abstract/MED/'
);
foreach my $groupId (keys %{ $self->{'associated_xref'} } ) {
my $description = '';
my $evidence = '';
my $source = '';
foreach my $rank ( keys %{ $self->{'associated_xref'}->{$groupId} } ) {
if ( $self->{'associated_xref'}->{$groupId}->{$rank}->[2]
eq 'evidence' ) {
if ( exists $external_urls{$self->{'associated_xref'}->{$groupId}->{$rank}->[0]->dbname} ) {
$evidence = '<a href="' . $external_urls{$self->{'associated_xref'}->{$groupId}->{$rank}->[0]->dbname}
. $self->{'associated_xref'}->{$groupId}->{$rank}->[0]->primary_id . '">'
. $self->{'associated_xref'}->{$groupId}->{$rank}->[0]->display_id
. '</a>';
} else {
$evidence = $self->{'associated_xref'}->{$groupId}->{$rank}->[0]->display_id;
}
} else {
if (length $description > 0) {
$description .= ', ';
}
$description .= '<strong>' . $self->{'associated_xref'}->{$groupId}->{$rank}->[2] . '</strong> ';
if (exists $external_urls{$self->{'associated_xref'}->{$groupId}->{$rank}->[0]->dbname} ) {
$description .= '<a href="' . $external_urls{$self->{'associated_xref'}->{$groupId}->{$rank}->[0]->dbname}
. $self->{'associated_xref'}->{$groupId}->{$rank}->[0]->primary_id . '">'
. $self->{'associated_xref'}->{$groupId}->{$rank}->[0]->display_id
. '</a>';
} else {
$description .= $self->{'associated_xref'}->{$groupId}->{$rank}->[0]->display_id;
}
}
if ( !undef $external_urls{$self->{'associated_xref'}->{$groupId}->{$rank}->[1]} ) {
if ( exists $external_urls{$self->{'associated_xref'}->{$groupId}->{$rank}->[1]->dbname} ) {
$source = '<a href="' . $external_urls{$self->{'associated_xref'}->{$groupId}->{$rank}->[1]->dbname}
. $self->{'associated_xref'}->{$groupId}->{$rank}->[1]->primary_id . '">';
if ( $self->{'associated_xref'}->{$groupId}->{$rank}->[1]->dbname ne 'GO_REF' ) {
$source .= 'PMC:';
}
$source .= $self->{'associated_xref'}->{$groupId}->{$rank}->[1]->display_id . '</a>';
} elsif ($self->{'associated_xref'}->{$groupId}->{$rank}->[1]->display_id eq 'PMPB:0') {
$source = '';
} else {
$source = $self->{'associated_xref'}->{$groupId}->{$rank}->[1]->display_id;
}
}
}
if ($evidence ne '' and $description ne '') {
my %row = ('description' => $description,
'evidence' => $evidence,
'source' => $source);
push @annotExtRows, (\%row);
}
}
return \@annotExtRows;
}
1;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment