diff --git a/modules/Bio/EnsEMBL/DBSQL/ProteinFeatureAdaptor.pm b/modules/Bio/EnsEMBL/DBSQL/ProteinFeatureAdaptor.pm index 87d804881f4f1115ae3f8a7b1881b9abb26918da..ebc4b469e5fbedeee00ce6172cf274237e5657ee 100755 --- a/modules/Bio/EnsEMBL/DBSQL/ProteinFeatureAdaptor.pm +++ b/modules/Bio/EnsEMBL/DBSQL/ProteinFeatureAdaptor.pm @@ -83,13 +83,13 @@ sub fetch_all_by_translation_id { my @features; my $analysis_adaptor = $self->db()->get_AnalysisAdaptor(); - my $sth = $self->prepare("SELECT protein_feature_id, p.seq_start, p.seq_end, p.analysis_id, " . " p.score, p.perc_ident, p.evalue, p.hit_start, p.hit_end, " . " p.hit_name, x.display_label, i.interpro_ac " . "FROM protein_feature p " . "LEFT JOIN interpro AS i ON p.hit_name = i.id " . "LEFT JOIN xref AS x ON x.dbprimary_acc = i.interpro_ac " . "WHERE p.translation_id = ?"); + my $sth = $self->prepare("SELECT protein_feature_id, p.seq_start, p.seq_end, p.analysis_id, " . " p.score, p.perc_ident, p.evalue, p.hit_start, p.hit_end, " . " p.hit_name, p.hit_description, x.display_label, i.interpro_ac " . "FROM protein_feature p " . "LEFT JOIN interpro AS i ON p.hit_name = i.id " . "LEFT JOIN xref AS x ON x.dbprimary_acc = i.interpro_ac " . "WHERE p.translation_id = ?"); $sth->bind_param(1, $translation_id, SQL_INTEGER); $sth->execute(); while (my $row = $sth->fetchrow_arrayref) { - my ($dbID, $start, $end, $analysisid, $score, $perc_id, $evalue, $hstart, $hend, $hid, $desc, $interpro_ac) = @$row; + my ($dbID, $start, $end, $analysisid, $score, $perc_id, $evalue, $hstart, $hend, $hid, $hdesc, $desc, $interpro_ac) = @$row; my $analysis = $analysis_adaptor->fetch_by_dbID($analysisid); @@ -97,20 +97,21 @@ sub fetch_all_by_translation_id { warning("Analysis with dbID=$analysisid does not exist\n" . "but is referenced by ProteinFeature $dbID"); } - my $feat = Bio::EnsEMBL::ProteinFeature->new(-DBID => $dbID, - -ADAPTOR => $self, - -SEQNAME => $translation_id, - -START => $start, - -END => $end, - -ANALYSIS => $analysis, - -PERCENT_ID => $perc_id, - -P_VALUE => $evalue, - -SCORE => $score, - -HSTART => $hstart, - -HEND => $hend, - -HSEQNAME => $hid, - -IDESC => $desc, - -INTERPRO_AC => $interpro_ac); + my $feat = Bio::EnsEMBL::ProteinFeature->new(-DBID => $dbID, + -ADAPTOR => $self, + -SEQNAME => $translation_id, + -START => $start, + -END => $end, + -ANALYSIS => $analysis, + -PERCENT_ID => $perc_id, + -P_VALUE => $evalue, + -SCORE => $score, + -HSTART => $hstart, + -HEND => $hend, + -HSEQNAME => $hid, + -HDESCRIPTION => $hdesc, + -IDESC => $desc, + -INTERPRO_AC => $interpro_ac); push(@features, $feat); } ## end while (my $row = $sth->fetchrow_arrayref) @@ -205,23 +206,23 @@ sub store { if (!defined($analysis)) { throw("Feature doesn't have analysis. Can't write to database"); } - if (!$analysis->is_stored($db)) { $db->get_AnalysisAdaptor->store($analysis); } - my $sth = $self->prepare("INSERT INTO protein_feature " . " SET translation_id = ?, " . " seq_start = ?, " . " seq_end = ?, " . " analysis_id = ?, " . " hit_start = ?, " . " hit_end = ?, " . " hit_name = ?, " . " score = ?, " . " perc_ident = ?, " . " evalue = ?"); + my $sth = $self->prepare("INSERT INTO protein_feature " . " SET translation_id = ?, " . " seq_start = ?, " . " seq_end = ?, " . " analysis_id = ?, " . " hit_start = ?, " . " hit_end = ?, " . " hit_name = ?, " . " hit_description = ?, " . " score = ?, " . " perc_ident = ?, " . " evalue = ?"); - $sth->bind_param(1, $translation_id, SQL_INTEGER); - $sth->bind_param(2, $feature->start, SQL_INTEGER); - $sth->bind_param(3, $feature->end, SQL_INTEGER); - $sth->bind_param(4, $analysis->dbID, SQL_INTEGER); - $sth->bind_param(5, $feature->hstart, SQL_INTEGER); - $sth->bind_param(6, $feature->hend, SQL_INTEGER); - $sth->bind_param(7, $feature->hseqname, SQL_VARCHAR); - $sth->bind_param(8, $feature->score, SQL_DOUBLE); - $sth->bind_param(9, $feature->percent_id, SQL_FLOAT); - $sth->bind_param(10, $feature->p_value, SQL_DOUBLE); + $sth->bind_param(1, $translation_id, SQL_INTEGER); + $sth->bind_param(2, $feature->start, SQL_INTEGER); + $sth->bind_param(3, $feature->end, SQL_INTEGER); + $sth->bind_param(4, $analysis->dbID, SQL_INTEGER); + $sth->bind_param(5, $feature->hstart, SQL_INTEGER); + $sth->bind_param(6, $feature->hend, SQL_INTEGER); + $sth->bind_param(7, $feature->hseqname, SQL_VARCHAR); + $sth->bind_param(8, $feature->hdescription, SQL_LONGVARCHAR); + $sth->bind_param(9, $feature->score, SQL_DOUBLE); + $sth->bind_param(10, $feature->percent_id, SQL_FLOAT); + $sth->bind_param(11, $feature->p_value, SQL_DOUBLE); $sth->execute(); @@ -274,7 +275,7 @@ sub save { my $db = $self->db(); my $analysis_adaptor = $db->get_AnalysisAdaptor(); - my $sql = qq{INSERT INTO $tablename (translation_id, seq_start, seq_end, hit_start, hit_end, hit_name, analysis_id, score, evalue, perc_ident, external_data) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)}; + my $sql = qq{INSERT INTO $tablename (translation_id, seq_start, seq_end, hit_start, hit_end, hit_name, hdescription, analysis_id, score, evalue, perc_ident, external_data) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)}; my $sth = $self->prepare($sql); @@ -309,11 +310,12 @@ sub save { $sth->bind_param(4, $hstart, SQL_INTEGER); $sth->bind_param(5, $hend, SQL_INTEGER); $sth->bind_param(6, $feat->hseqname, SQL_VARCHAR); - $sth->bind_param(7, $feat->analysis->dbID, SQL_INTEGER); - $sth->bind_param(8, $feat->score, SQL_DOUBLE); - $sth->bind_param(9, $feat->p_value, SQL_DOUBLE); - $sth->bind_param(10, $feat->percent_id, SQL_FLOAT); - $sth->bind_param(11, $extra_data, SQL_LONGVARCHAR); + $sth->bind_param(7, $feat->hdescription, SQL_LONGVARCHAR); + $sth->bind_param(8, $feat->analysis->dbID, SQL_INTEGER); + $sth->bind_param(9, $feat->score, SQL_DOUBLE); + $sth->bind_param(10, $feat->p_value, SQL_DOUBLE); + $sth->bind_param(11, $feat->percent_id, SQL_FLOAT); + $sth->bind_param(12, $extra_data, SQL_LONGVARCHAR); $sth->execute(); $original->dbID($sth->{'mysql_insertid'}); diff --git a/modules/Bio/EnsEMBL/FeaturePair.pm b/modules/Bio/EnsEMBL/FeaturePair.pm index 5cbcbf1d5a7bff1340f1021381606a4c14ede648..170d504cd0c48a40ae63275423f765c9a6aaaa5d 100755 --- a/modules/Bio/EnsEMBL/FeaturePair.pm +++ b/modules/Bio/EnsEMBL/FeaturePair.pm @@ -10,6 +10,7 @@ http://www.ensembl.org/info/about/code_licence.html =head1 CONTACT + Please email comments or questions to the public Ensembl developers list at <dev@ensembl.org>. @@ -126,7 +127,7 @@ sub new { my $self = $class->SUPER::new(@_); - my ($hstart, $hend, $hstrand, $percent_id, $score, $species, $hspecies, $p_value, $hseqname, $f1, $f2, $coverage, $hcoverage, $group_id, $level_id, $external_db_id, $extra_data, $external_db_name, $external_display_db_name) = rearrange(['HSTART', 'HEND', 'HSTRAND', 'PERCENT_ID', 'SCORE', 'SPECIES', 'HSPECIES', 'P_VALUE', 'HSEQNAME', 'FEATURE1', 'FEATURE2', 'COVERAGE', 'HCOVERAGE', 'GROUP_ID', 'LEVEL_ID', 'EXTERNAL_DB_ID', 'EXTRA_DATA', 'DBNAME', 'DB_DISPLAY_NAME'], @_); + my ($hstart, $hend, $hstrand, $percent_id, $score, $species, $hspecies, $p_value, $hseqname, $f1, $f2, $coverage, $hcoverage, $group_id, $level_id, $external_db_id, $extra_data, $external_db_name, $external_display_db_name, $hdescription) = rearrange(['HSTART', 'HEND', 'HSTRAND', 'PERCENT_ID', 'SCORE', 'SPECIES', 'HSPECIES', 'P_VALUE', 'HSEQNAME', 'FEATURE1', 'FEATURE2', 'COVERAGE', 'HCOVERAGE', 'GROUP_ID', 'LEVEL_ID', 'EXTERNAL_DB_ID', 'EXTRA_DATA', 'DBNAME', 'DB_DISPLAY_NAME', 'HDESCRIPTION'], @_); if (defined($hstart) && defined($hend) && ($hend < $hstart)) { throw('HSTART must be less than or equal to HEND'); @@ -153,7 +154,7 @@ sub new { $self->{'extra_data'} = $extra_data; $self->{'dbname'} = $external_db_name; $self->{'db_display_name'} = $external_display_db_name; - + $self->{'hdescription'} = $hdescription; # # Feature1 and Feature2 arg handling for backwards compatibility # @@ -583,6 +584,24 @@ sub p_value { return $self->{'p_value'}; } +=head2 hdescription + + Arg [1] : String (optional) + Example : $des = $fp->hdescription() + Description: Getter Setter for optional description of this feature + Returntype : String + Exceptions : none + Caller : general + Status : Stable + +=cut + +sub hdescription { + my $self = shift; + $self->{'hdescription'} = shift if (@_); + return $self->{'hdescription'}; +} + =head2 display_id Arg [1] : none @@ -768,11 +787,12 @@ sub invert { $slice = $self->hslice; } - my $hstart = $self->{'hstart'}; - my $hend = $self->{'hend'}; - my $hstrand = $self->{'hstrand'}; - my $hspecies = $self->{'hspecies'}; - my $hseqname = $self->{'hseqname'}; + my $hstart = $self->{'hstart'}; + my $hend = $self->{'hend'}; + my $hstrand = $self->{'hstrand'}; + my $hspecies = $self->{'hspecies'}; + my $hseqname = $self->{'hseqname'}; + my $hdescription = $self->{'hdescription'}; my $start = $self->{'start'}; my $end = $self->{'end'}; @@ -792,6 +812,8 @@ sub invert { $self->{'hseqname'} = $seqname; $self->{'hspecies'} = $species; + $self->{'hdescription'} = $hdescription; + $self->{'hslice'} = $self->slice; $self->{'slice'} = $slice; } ## end sub invert diff --git a/modules/t/proteinFeature.t b/modules/t/proteinFeature.t index 538533f511279e21fb7c5c072d4a1e46b4c7c457..576cd597bcf35ca17df75d7d617d42ce2491ce02 100644 --- a/modules/t/proteinFeature.t +++ b/modules/t/proteinFeature.t @@ -1,10 +1,10 @@ use strict; use warnings; -BEGIN { - $| = 1; - use Test; - plan tests => 17; + +BEGIN { $| = 1; + use Test; + plan tests => 17; } use Bio::EnsEMBL::Test::TestUtils; @@ -12,41 +12,48 @@ use Bio::EnsEMBL::Test::TestUtils; use Bio::EnsEMBL::ProteinFeature; use Bio::EnsEMBL::Analysis; -our $verbose = 0; #turn on or off debug statements +our $verbose = 0; #turn on or off debug statements + # # Test new and getters # -my $start = 10; -my $end = 100; -my $hstart = 1; -my $hend = 90; -my $hstrand = 1; -my $hseqname = 'RF1231'; +my $start = 10; +my $end = 100; +my $hstart = 1; +my $hend = 90; +my $hstrand = 1; +my $hseqname = 'RF1231'; my $percent_id = 90.8; -my $p_value = '1.52'; -my $score = 50; -my $species = 'Homo_sapiens'; -my $hspecies = 'Mus_musculus'; +my $p_value = '1.52'; +my $score = 50; +my $species = 'Homo_sapiens'; +my $hspecies = 'Mus_musculus'; +my $hdes = "Hit description"; -my $idesc = 'interpro description'; +my $idesc = 'interpro description'; my $interpro_ac = 'interpro accession'; my $analysis = Bio::EnsEMBL::Analysis->new(-LOGIC_NAME => 'test'); -my $f = Bio::EnsEMBL::ProteinFeature->new(-START => $start, - -END => $end, - -ANALYSIS => $analysis, - -HSTART => $hstart, - -HEND => $hend, - -HSEQNAME => $hseqname, - -PERCENT_ID => $percent_id, - -P_VALUE => $p_value, - -SCORE => $score, - -SPECIES => $species, - -HSPECIES => $hspecies, - -IDESC => $idesc, - -INTERPRO_AC => $interpro_ac); + +my $f = Bio::EnsEMBL::ProteinFeature->new + (-START => $start, + -END => $end, + -ANALYSIS => $analysis, + -HSTART => $hstart, + -HEND => $hend, + -HSEQNAME => $hseqname, + -PERCENT_ID => $percent_id, + -P_VALUE => $p_value, + -SCORE => $score, + -SPECIES => $species, + -HSPECIES => $hspecies, + -HDESCRIPTION=> $hdes, + -IDESC => $idesc, + -INTERPRO_AC => $interpro_ac); + + ok($f && $f->isa('Bio::EnsEMBL::ProteinFeature')); @@ -55,15 +62,16 @@ ok($f->end == $end); ok($f->analysis == $analysis); ok($f->hstart == $hstart); -ok($f->hend == $hend); +ok($f->hend == $hend); ok($f->hseqname eq $hseqname); ok($f->percent_id == $percent_id); ok($f->p_value == $p_value); ok($f->score == $score); -ok($f->species eq $species); +ok($f->species eq $species); ok($f->hspecies eq $hspecies); +ok($f->hdescription eq $hdes); -ok($f->idesc eq $idesc); +ok($f->idesc eq $idesc); ok($f->interpro_ac eq $interpro_ac); # check that the strand is 0 @@ -72,6 +80,9 @@ ok($f->strand == 0); # # Test setters # -ok(test_getter_setter($f, 'idesc', 'interpro desc1')); -ok(test_getter_setter($f, 'interpro_ac', 'interpro ac1')); +ok(test_getter_setter($f, 'idesc', 'interpro desc1')); +ok(test_getter_setter($f, 'interpro_ac', 'interpro ac1')); + + + diff --git a/modules/t/proteinFeatureAdaptor.t b/modules/t/proteinFeatureAdaptor.t index ed3b48391ef02600f210a4d9b298083b64d0334d..081e4f2c980cfc2884d66ab4a6c12c37bfa94554 100644 --- a/modules/t/proteinFeatureAdaptor.t +++ b/modules/t/proteinFeatureAdaptor.t @@ -38,3 +38,49 @@ sub print_features { } } } + +# test adding and retrieving a new feature +my $start = 10; +my $end = 100; +my $hstart = 1; +my $hend = 90; +my $hstrand = 1; +my $hseqname = 'RF1231'; +my $percent_id = 90.8; +my $p_value = '1.52'; +my $score = 50; +my $species = 'Homo_sapiens'; +my $hspecies = 'Mus_musculus'; +my $hdes = "Hit description"; + +my $idesc = 'interpro description'; +my $interpro_ac = 'interpro accession'; + +my $analysis = Bio::EnsEMBL::Analysis->new(-LOGIC_NAME => 'test'); + + +my $f = Bio::EnsEMBL::ProteinFeature->new + (-START => $start, + -END => $end, + -ANALYSIS => $analysis, + -HSTART => $hstart, + -HEND => $hend, + -HSEQNAME => $hseqname, + -PERCENT_ID => $percent_id, + -P_VALUE => $p_value, + -SCORE => $score, + -SPECIES => $species, + -HSPECIES => $hspecies, + -HDESCRIPTION=> $hdes, + -IDESC => $idesc, + -INTERPRO_AC => $interpro_ac); + +$pfa->store($f,21724); + +my $pfs = $pfa->fetch_all_by_translation_id(21724); + +ok(@$pfs == 16); + +my @pfs = grep{$_->hdescription() eq $hdes} @$pfs; + +ok(scalar @pfs > 0); diff --git a/sql/patch_69_70_e.sql b/sql/patch_69_70_e.sql new file mode 100644 index 0000000000000000000000000000000000000000..b11061a1587dd67d3bef8b16871a79fea0a95db5 --- /dev/null +++ b/sql/patch_69_70_e.sql @@ -0,0 +1,13 @@ +# patch_69_70_e.sql +# +# Title: Add hit_description to protein_feature +# +# Description: Column allowing an optional description to be added to a protein_feature + +ALTER TABLE protein_feature ADD COLUMN hit_description TEXT; + +# Patch identifier +INSERT INTO meta (species_id, meta_key, meta_value) + VALUES (NULL, 'patch', 'patch_69_70_e.sql|protein_feature_hit_description'); + + diff --git a/sql/table.sql b/sql/table.sql index a865a4744705e0f8ebacd9b64516a3b313ccb5cf..2d7192e94d3a0b57fc0122c937d3e8d36f92a7c4 100755 --- a/sql/table.sql +++ b/sql/table.sql @@ -1594,6 +1594,7 @@ CREATE TABLE protein_align_feature ( @column hit_start Alignment hit start position. @column hit_end Alignment hit end position. @column hit_name Alignment hit name. +@column hit_description Optional description of the hit. @column analysis_id Foreign key references to the @link analysis table. @column score Alignment score. @column evalue Alignment E-value. @@ -1614,6 +1615,7 @@ CREATE TABLE protein_feature ( hit_start INT(10) NOT NULL, hit_end INT(10) NOT NULL, hit_name VARCHAR(40) NOT NULL, + hit_description TEXT, analysis_id SMALLINT UNSIGNED NOT NULL, score DOUBLE, evalue DOUBLE,