From 304738dbd8db655b284bfe037ed562bc42751281 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Kusalananda=20K=C3=A4h=C3=A4ri?= <ak4@sanger.ac.uk> Date: Tue, 27 Oct 2009 11:56:29 +0000 Subject: [PATCH] Subroutine store() formatted for readability. --- .../EnsEMBL/DBSQL/DnaAlignFeatureAdaptor.pm | 107 ++++++++++-------- 1 file changed, 59 insertions(+), 48 deletions(-) diff --git a/modules/Bio/EnsEMBL/DBSQL/DnaAlignFeatureAdaptor.pm b/modules/Bio/EnsEMBL/DBSQL/DnaAlignFeatureAdaptor.pm index f8b08d7459..ac81eb3a45 100644 --- a/modules/Bio/EnsEMBL/DBSQL/DnaAlignFeatureAdaptor.pm +++ b/modules/Bio/EnsEMBL/DBSQL/DnaAlignFeatureAdaptor.pm @@ -138,89 +138,100 @@ sub _columns { =cut sub store { - my ($self, @feats) = @_; + my ( $self, @feats ) = @_; - throw("Must call store with features") if( scalar(@feats) == 0 ); + throw("Must call store with features") if ( scalar(@feats) == 0 ); my @tabs = $self->_tables; - my ($tablename) = @{$tabs[0]}; + my ($tablename) = @{ $tabs[0] }; - my $db = $self->db(); + my $db = $self->db(); my $analysis_adaptor = $db->get_AnalysisAdaptor(); my $sth = $self->prepare( - "INSERT INTO $tablename (seq_region_id, seq_region_start, seq_region_end, - seq_region_strand, hit_start, hit_end, - hit_strand, hit_name, cigar_line, - analysis_id, score, evalue, perc_ident, external_db_id, - hcoverage, pair_dna_align_feature_id) - VALUES (?,?,?,?,?,?,?,?,?,?,?, ?, ?, ?, ?, ?)"); - - FEATURE: foreach my $feat ( @feats ) { - if( !ref $feat || !$feat->isa("Bio::EnsEMBL::DnaDnaAlignFeature") ) { + "INSERT INTO $tablename (seq_region_id, seq_region_start, + seq_region_end, seq_region_strand, + hit_start, hit_end, hit_strand, hit_name, + cigar_line, analysis_id, score, evalue, + perc_ident, external_db_id, hcoverage, + pair_dna_align_feature_id) + VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)" # 16 arguments + ); + +FEATURE: + foreach my $feat (@feats) { + if ( !ref $feat || !$feat->isa("Bio::EnsEMBL::DnaDnaAlignFeature") ) + { throw("feature must be a Bio::EnsEMBL::DnaDnaAlignFeature," - . " not a [".ref($feat)."]."); + . " not a [" + . ref($feat) + . "]." ); } - if($feat->is_stored($db)) { - warning("DnaDnaAlignFeature [".$feat->dbID."] is already stored" . - " in this database."); + if ( $feat->is_stored($db) ) { + warning( "DnaDnaAlignFeature [" + . $feat->dbID() + . "] is already stored in this database." ); next FEATURE; } - my $hstart = $feat->hstart(); - my $hend = $feat->hend(); + my $hstart = $feat->hstart(); + my $hend = $feat->hend(); my $hstrand = $feat->hstrand(); - $self->_check_start_end_strand($hstart,$hend, $hstrand); + $self->_check_start_end_strand( $hstart, $hend, $hstrand ); my $cigar_string = $feat->cigar_string(); - if(!$cigar_string) { + if ( !$cigar_string ) { $cigar_string = $feat->length() . 'M'; - warning("DnaDnaAlignFeature does not define a cigar_string.\n" . - "Assuming ungapped block with cigar_line=$cigar_string ."); + warning( "DnaDnaAlignFeature does not define a cigar_string.\n" + . "Assuming ungapped block with cigar_line=$cigar_string ." ); } my $hseqname = $feat->hseqname(); - if(!$hseqname) { + if ( !$hseqname ) { throw("DnaDnaAlignFeature must define an hseqname."); } - if(!defined($feat->analysis)) { - throw("An analysis must be attached to the features to be stored."); + 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()); + if ( !$feat->analysis->is_stored($db) ) { + $analysis_adaptor->store( $feat->analysis() ); } my $original = $feat; my $seq_region_id; - ($feat, $seq_region_id) = $self->_pre_store($feat); - $sth->bind_param(1,$seq_region_id,SQL_INTEGER); - $sth->bind_param(2,$feat->start,SQL_INTEGER); - $sth->bind_param(3,$feat->end,SQL_INTEGER); - $sth->bind_param(4,$feat->strand,SQL_TINYINT); - $sth->bind_param(5,$hstart,SQL_INTEGER); - $sth->bind_param(6,$hend,SQL_INTEGER); - $sth->bind_param(7,$hstrand,SQL_TINYINT); - $sth->bind_param(8,$hseqname,SQL_VARCHAR); - $sth->bind_param(9,$cigar_string,SQL_LONGVARCHAR); - $sth->bind_param(10,$feat->analysis->dbID,SQL_INTEGER); - $sth->bind_param(11,$feat->score,SQL_DOUBLE); - $sth->bind_param(12,$feat->p_value,SQL_DOUBLE); - $sth->bind_param(13,$feat->percent_id,SQL_FLOAT); - $sth->bind_param(14,$feat->external_db_id,SQL_INTEGER); - $sth->bind_param(15,$feat->hcoverage,SQL_DOUBLE); - $sth->bind_param(16,$feat->pair_dna_align_feature_id, SQL_INTEGER); + ( $feat, $seq_region_id ) = $self->_pre_store($feat); + + $sth->bind_param( 1, $seq_region_id, SQL_INTEGER ); + $sth->bind_param( 2, $feat->start, SQL_INTEGER ); + $sth->bind_param( 3, $feat->end, SQL_INTEGER ); + $sth->bind_param( 4, $feat->strand, SQL_TINYINT ); + $sth->bind_param( 5, $hstart, SQL_INTEGER ); + $sth->bind_param( 6, $hend, SQL_INTEGER ); + $sth->bind_param( 7, $hstrand, SQL_TINYINT ); + $sth->bind_param( 8, $hseqname, SQL_VARCHAR ); + $sth->bind_param( 9, $cigar_string, SQL_LONGVARCHAR ); + $sth->bind_param( 10, $feat->analysis->dbID, SQL_INTEGER ); + $sth->bind_param( 11, $feat->score, SQL_DOUBLE ); + $sth->bind_param( 12, $feat->p_value, SQL_DOUBLE ); + $sth->bind_param( 13, $feat->percent_id, SQL_FLOAT ); + $sth->bind_param( 14, $feat->external_db_id, SQL_INTEGER ); + $sth->bind_param( 15, $feat->hcoverage, SQL_DOUBLE ); + $sth->bind_param( 16, $feat->pair_dna_align_feature_id, + SQL_INTEGER ); $sth->execute(); - $original->dbID($sth->{'mysql_insertid'}); + + $original->dbID( $sth->{'mysql_insertid'} ); $original->adaptor($self); - } + } ## end foreach my $feat (@feats) $sth->finish(); -} +} ## end sub store sub save { -- GitLab