Skip to content
Snippets Groups Projects
Commit 0e2e6383 authored by Dan Staines's avatar Dan Staines
Browse files

reformatted to use new perltidy options

parent de129fbc
No related branches found
No related tags found
No related merge requests found
=head1 LICENSE
Copyright (c) 1999-2012 The European Bioinformatics Institute and
......@@ -42,7 +43,6 @@ Bio::EnsEMBL::DBSQL::ProteinFeatureAdaptor
=cut
package Bio::EnsEMBL::DBSQL::ProteinFeatureAdaptor;
use strict;
......@@ -54,7 +54,6 @@ use Bio::EnsEMBL::Utils::Exception qw(throw deprecate warning);
use vars qw(@ISA);
@ISA = qw(Bio::EnsEMBL::DBSQL::BaseAdaptor);
=head2 fetch_all_by_translation_id
Arg [1] : int $transl
......@@ -75,62 +74,51 @@ use vars qw(@ISA);
=cut
sub fetch_all_by_translation_id {
my($self,$translation_id) = @_;
my ($self, $translation_id) = @_;
if(!$translation_id) {
throw("translation_id argument is required\n");
if (!$translation_id) {
throw("translation_id argument is required\n");
}
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 = ?");
$sth->bind_param(1,$translation_id,SQL_INTEGER);
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 = ?");
$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 $analysis = $analysis_adaptor->fetch_by_dbID($analysisid);
if(!$analysis) {
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);
push(@features,$feat);
}
while (my $row = $sth->fetchrow_arrayref) {
my ($dbID, $start, $end, $analysisid, $score, $perc_id, $evalue, $hstart, $hend, $hid, $desc, $interpro_ac) = @$row;
my $analysis = $analysis_adaptor->fetch_by_dbID($analysisid);
if (!$analysis) {
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);
push(@features, $feat);
} ## end while (my $row = $sth->fetchrow_arrayref)
$sth->finish();
return \@features;
}
return \@features;
} ## end sub fetch_all_by_translation_id
=head2 fetch_by_dbID
......@@ -145,52 +133,40 @@ sub fetch_all_by_translation_id {
=cut
sub fetch_by_dbID{
my ($self,$protfeat_id) = @_;
my $sth = $self->prepare(
"SELECT 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.protein_feature_id = ?");
$sth->bind_param(1,$protfeat_id,SQL_INTEGER);
sub fetch_by_dbID {
my ($self, $protfeat_id) = @_;
my $sth = $self->prepare("SELECT 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.protein_feature_id = ?");
$sth->bind_param(1, $protfeat_id, SQL_INTEGER);
my $res = $sth->execute();
if($sth->rows == 0) {
$sth->finish();
return undef;
if ($sth->rows == 0) {
$sth->finish();
return undef;
}
my ($start, $end, $analysis_id, $score, $perc_ident, $pvalue, $hstart,
$hend, $hseqname, $idesc, $interpro_ac) = $sth->fetchrow_array();
my ($start, $end, $analysis_id, $score, $perc_ident, $pvalue, $hstart, $hend, $hseqname, $idesc, $interpro_ac) = $sth->fetchrow_array();
$sth->finish();
my $analysis = $self->db->get_AnalysisAdaptor->fetch_by_dbID($analysis_id);
return Bio::EnsEMBL::ProteinFeature->new
(-ADAPTOR => $self,
-DBID => $protfeat_id,
-START => $start,
-END => $end,
-HSTART => $hstart,
-HEND => $hend,
-HSEQNAME => $hseqname,
-ANALYSIS => $analysis,
-SCORE => $score,
-P_VALUE => $pvalue,
-PERCENT_ID => $perc_ident,
-IDESC => $idesc,
-INTERPRO_AC => $interpro_ac);
}
return
Bio::EnsEMBL::ProteinFeature->new(-ADAPTOR => $self,
-DBID => $protfeat_id,
-START => $start,
-END => $end,
-HSTART => $hstart,
-HEND => $hend,
-HSEQNAME => $hseqname,
-ANALYSIS => $analysis,
-SCORE => $score,
-P_VALUE => $pvalue,
-PERCENT_ID => $perc_ident,
-IDESC => $idesc,
-INTERPRO_AC => $interpro_ac);
} ## end sub fetch_by_dbID
=head2 store
......@@ -208,73 +184,56 @@ sub fetch_by_dbID{
=cut
sub store {
my ($self,$feature, $translation_id) = @_;
my ($self, $feature, $translation_id) = @_;
if(!ref($feature) || !$feature->isa('Bio::EnsEMBL::ProteinFeature')) {
throw("ProteinFeature argument is required");
if (!ref($feature) || !$feature->isa('Bio::EnsEMBL::ProteinFeature')) {
throw("ProteinFeature argument is required");
}
if(!$translation_id) {
deprecate("Calling ProteinFeatureAdaptor without a translation_id is " .
"deprecated. Pass a translation_id argument rather than " .
"setting the ProteinFeature seqname to be the translation " .
"id");
$translation_id = $feature->seqname();
if (!$translation_id) {
deprecate("Calling ProteinFeatureAdaptor without a translation_id is " . "deprecated. Pass a translation_id argument rather than " . "setting the ProteinFeature seqname to be the translation " . "id");
$translation_id = $feature->seqname();
}
my $db = $self->db();
if($feature->is_stored($db)) {
warning("ProteinFeature " . $feature->dbID() . " is already stored in " .
"this database - not storing again");
if ($feature->is_stored($db)) {
warning("ProteinFeature " . $feature->dbID() . " is already stored in " . "this database - not storing again");
}
my $analysis = $feature->analysis();
if (!defined($analysis)) {
throw("Feature doesn't have analysis. Can't write to database");
throw("Feature doesn't have analysis. Can't write to database");
}
if(!$analysis->is_stored($db)) {
$db->get_AnalysisAdaptor->store($analysis);
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 = ?");
$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);
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 = ?");
$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->execute();
my $dbID = $sth->{'mysql_insertid'};
$feature->adaptor($self);
$feature->dbID($dbID);
$sth->finish();
return $dbID;
}
$sth->finish();
return $dbID;
} ## end sub store
sub fetch_by_translation_id {
deprecate("Use fetch_all_by_translation_id instead.");
......@@ -282,8 +241,8 @@ sub fetch_by_translation_id {
}
sub fetch_all_by_feature_and_dbID {
my $self = shift;
my $feature = shift;
my $self = shift;
my $feature = shift;
my $translation_id = shift;
deprecate("Use fetch_all_by_translation_id instead.");
......@@ -293,79 +252,76 @@ sub fetch_all_by_feature_and_dbID {
my @out;
foreach my $f (@$features) {
my $logic_name = lc($f->analysis->logic_name());
print STDERR "LOGIC_NAME = $logic_name | FEATURE = $feature\n";
push(@out, $f) if($logic_name eq lc($feature));
my $logic_name = lc($f->analysis->logic_name());
print STDERR "LOGIC_NAME = $logic_name | FEATURE = $feature\n";
push(@out, $f) if ($logic_name eq lc($feature));
}
return \@out;
}
sub save {
my ($self, $features) = @_;
my @feats = @$features;
throw("Must call save with features") if( scalar(@feats) == 0 );
throw("Must call save with features") if (scalar(@feats) == 0);
# my @tabs = $self->_tables;
# my ($tablename) = @{$tabs[0]};
# my @tabs = $self->_tables;
# my ($tablename) = @{$tabs[0]};
my $tablename = 'protein_feature';
my $db = $self->db();
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 $sth = $self->prepare($sql);
foreach my $feat ( @feats ) {
if( !ref $feat || !$feat->isa("Bio::EnsEMBL::ProteinFeature") ) {
throw("feature must be a Bio::EnsEMBL::ProteinFeature,". " not a [".ref($feat)."].");
}
if($feat->is_stored($db)) {
warning("ProteinFeature [".$feat->dbID."] is already stored" .
" in this database.");
next;
}
my $hstart = defined $feat->hstart ? $feat->hstart : $feat->start ;
my $hend = defined $feat->hend ? $feat->hend : $feat->end;
if(!defined($feat->analysis)) {
throw("An analysis must be attached to the features to be stored.");
}
#store the analysis if it has not been stored yet
if(!$feat->analysis->is_stored($db)) {
$analysis_adaptor->store($feat->analysis());
}
my $original = $feat;
my $extra_data = $feat->extra_data ? $self->dump_data($feat->extra_data) : '';
$sth->bind_param(1,$feat->translation_id,SQL_INTEGER);
$sth->bind_param(2,$feat->start,SQL_INTEGER);
$sth->bind_param(3,$feat->end,SQL_INTEGER);
$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->execute();
$original->dbID($sth->{'mysql_insertid'});
$original->adaptor($self);
}
$sth->finish();
}
foreach my $feat (@feats) {
if (!ref $feat || !$feat->isa("Bio::EnsEMBL::ProteinFeature")) {
throw("feature must be a Bio::EnsEMBL::ProteinFeature," . " not a [" . ref($feat) . "].");
}
if ($feat->is_stored($db)) {
warning("ProteinFeature [" . $feat->dbID . "] is already stored" . " in this database.");
next;
}
my $hstart = defined $feat->hstart ? $feat->hstart : $feat->start;
my $hend = defined $feat->hend ? $feat->hend : $feat->end;
if (!defined($feat->analysis)) {
throw("An analysis must be attached to the features to be stored.");
}
#store the analysis if it has not been stored yet
if (!$feat->analysis->is_stored($db)) {
$analysis_adaptor->store($feat->analysis());
}
my $original = $feat;
my $extra_data = $feat->extra_data ? $self->dump_data($feat->extra_data) : '';
$sth->bind_param(1, $feat->translation_id, SQL_INTEGER);
$sth->bind_param(2, $feat->start, SQL_INTEGER);
$sth->bind_param(3, $feat->end, SQL_INTEGER);
$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->execute();
$original->dbID($sth->{'mysql_insertid'});
$original->adaptor($self);
} ## end foreach my $feat (@feats)
$sth->finish();
} ## end sub save
1;
This diff is collapsed.
=head1 LICENSE
Copyright (c) 1999-2012 The European Bioinformatics Institute and
......@@ -15,7 +16,6 @@
Questions may also be sent to the Ensembl help desk at
<helpdesk@ensembl.org>.
=cut
=head1 NAME
......@@ -51,8 +51,6 @@ use Bio::EnsEMBL::Utils::Argument qw(rearrange);
use vars qw(@ISA);
@ISA = qw(Bio::EnsEMBL::FeaturePair);
=head2 new
Arg [IDESC] : (optional) string An interpro description
......@@ -79,8 +77,7 @@ sub new {
my $class = ref($proto) || $proto;
my ( $idesc, $interpro_ac, $translation_id ) =
rearrange( [ 'IDESC', 'INTERPRO_AC', 'TRANSLATION_ID' ], @_ );
my ($idesc, $interpro_ac, $translation_id) = rearrange(['IDESC', 'INTERPRO_AC', 'TRANSLATION_ID'], @_);
my $self = $class->SUPER::new(@_);
......@@ -93,7 +90,6 @@ sub new {
return $self;
}
=head2 strand
Arg [1] : Ignored
......@@ -110,8 +106,6 @@ sub strand {
return $self->{'strand'};
}
=head2 idesc
Arg [1] : (optional) string The interpro description
......@@ -125,14 +119,12 @@ sub strand {
=cut
sub idesc{
sub idesc {
my $self = shift;
$self->{'idesc'} = shift if(@_);
$self->{'idesc'} = shift if (@_);
return $self->{'idesc'};
}
=head2 interpro_ac
Arg [1] : (optional) string The interpro accession
......@@ -146,13 +138,12 @@ sub idesc{
=cut
sub interpro_ac{
sub interpro_ac {
my $self = shift;
$self->{'interpro_ac'} = shift if(@_);
$self->{'interpro_ac'} = shift if (@_);
return $self->{'interpro_ac'};
}
=head2 translation_id
Arg [1] : (optional) integer The dbID of the translation
......
use strict;
use warnings;
BEGIN { $| = 1;
use Test;
plan tests => 17;
BEGIN {
$| = 1;
use Test;
plan tests => 17;
}
use Bio::EnsEMBL::Test::TestUtils;
......@@ -12,46 +12,41 @@ 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 $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,
-IDESC => $idesc,
-INTERPRO_AC => $interpro_ac);
ok($f && $f->isa('Bio::EnsEMBL::ProteinFeature'));
......@@ -60,15 +55,15 @@ 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->idesc eq $idesc);
ok($f->idesc eq $idesc);
ok($f->interpro_ac eq $interpro_ac);
# check that the strand is 0
......@@ -77,9 +72,6 @@ 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'));
......@@ -2,9 +2,10 @@ use strict;
use Bio::EnsEMBL::Test::TestUtils;
BEGIN { $| = 1;
use Test;
plan tests => 2;
BEGIN {
$| = 1;
use Test;
plan tests => 2;
}
use Bio::EnsEMBL::Test::MultiTestDB;
......@@ -16,7 +17,6 @@ my $multi = Bio::EnsEMBL::Test::MultiTestDB->new;
# get a core DBAdaptor
my $dba = $multi->get_DBAdaptor("core");
#
# Test get_ProteinFeatureAdaptor works
#
......@@ -24,7 +24,6 @@ my $pfa = $dba->get_ProteinFeatureAdaptor();
ok($pfa && ref($pfa) && $pfa->isa('Bio::EnsEMBL::DBSQL::ProteinFeatureAdaptor'));
my $pfs = $pfa->fetch_all_by_translation_id(21724);
print_features($pfs);
......@@ -34,9 +33,8 @@ ok(@$pfs == 15);
sub print_features {
my $features = shift;
foreach my $f (@$features) {
if(defined($f)) {
debug($f->start.'-'.$f->end. ' -> '.$f->hseqname. ':'.
$f->hstart. '-'.$f->hend);
}
if (defined($f)) {
debug($f->start . '-' . $f->end . ' -> ' . $f->hseqname . ':' . $f->hstart . '-' . $f->hend);
}
}
}
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