Commit 87f0b96b authored by Graham McVicker's avatar Graham McVicker
Browse files

Changed methods relating to fetching and storing of features. Most notably:

    fetch_by_contig_id(int) -> fetch_by_Contig(RawContig)
  store(int, list of Features) -> store(list of Features with attached contigs)
parent e67dc5f0
......@@ -54,15 +54,15 @@ use Bio::EnsEMBL::DBSQL::BaseFeatureAdaptor;
=head2 fetch_by_contig_id_and_pid
=head2 fetch_by_Contig_and_pid
Arg [1] : int $cid
the unique identifier (dbID) for contig to obtain feats from
Arg [1] : Bio::EnsEMBL::RawContig
the contig to obtain align features from
Arg [2] : float $pid
a lower bound for the percentage identifier of feats to obtain
Arg [3] : (optional) string $logic_name
the logic name of the type of features to obtain
Example : @feats = $adaptor->fetch_by_contig_id_and_pid(1234, 50.0);
Example : @feats = $adaptor->fetch_by_Contig_and_pid($contig, 50.0);
Description: Returns a list of features created from the database which are
are on the contig defined by $cid and with a percentage id
greater than $pid. If logic name is defined, only features
......@@ -73,8 +73,8 @@ use Bio::EnsEMBL::DBSQL::BaseFeatureAdaptor;
=cut
sub fetch_by_contig_id_and_pid {
my($self, $cid, $pid, $logic_name) = @_;
sub fetch_by_Contig_and_pid {
my($self, $contig, $pid, $logic_name) = @_;
my $constraint;
......@@ -85,7 +85,7 @@ sub fetch_by_contig_id_and_pid {
}
my @features =
$self->fetch_by_contig_id_constraint($cid, $constraint, $logic_name);
$self->fetch_by_Contig_constraint($contig, $constraint, $logic_name);
return @features;
}
......
......@@ -142,15 +142,15 @@ sub fetch_by_dbID{
}
=head2 fetch_by_contig_id_constraint
=head2 fetch_by_Contig_constraint
Arg [1] : int $cid
the unique identifier (dbID) for contig to obtain feats from
Arg [1] : Bio::EnsEMBL::RawContig $contig
The contig object from which features are to be obtained
Arg [2] : (optional) string $constraint
An SQL query constraint (i.e. part of the WHERE clause)
Arg [3] : (optional) string $logic_name
the logic name of the type of features to obtain
Example : @fts = $a->fetch_by_contig_id_constraint(1, 'perc_ident > 5.0');
Example : @fts = $a->fetch_by_Contig_constraint($contig, 'perc_ident>5.0');
Description: Returns a list of features created from the database which are
are on the contig defined by $cid and fulfill the SQL constraint
defined by $constraint. If logic name is defined, only features
......@@ -161,13 +161,19 @@ sub fetch_by_dbID{
=cut
sub fetch_by_contig_id_constraint {
my ($self, $cid, $constraint, $logic_name) = @_;
sub fetch_by_Contig_constraint {
my ($self, $contig, $constraint, $logic_name) = @_;
if( !defined $cid ) {
$self->throw("fetch_by_contig_id_constraint must have an contig id");
unless( defined $contig ) {
$self->throw("fetch_by_Contig_constraint must have an contig");
}
unless( ref $contig && $contig->isa('Bio::EnsEMBL::RawContig')) {
$self->throw("contig argument is not a Bio::EnsEMBL::RawContig object\n");
}
my $cid = $contig->dbID();
if($constraint) {
$constraint .= " AND contig_id = $cid";
} else {
......@@ -178,13 +184,13 @@ sub fetch_by_contig_id_constraint {
}
=head2 fetch_by_contig_id
=head2 fetch_by_Contig
Arg [1] : int $cid
the unique identifier (dbID) for contig to obtain feats from
Arg [1] : Bio::EnsEMBL::RawContig $contig
the contig from which features should be obtained
Arg [2] : (optional) string $logic_name
the logic name of the type of features to obtain
Example : @fts = $a->fetch_by_contig_id(1, 'swall');
Example : @fts = $a->fetch_by_Contig($contig, 'swall');
Description: Returns a list of features created from the database which are
are on the contig defined by $cid If logic name is defined,
only features with an analysis of type $logic_name will be
......@@ -195,23 +201,23 @@ sub fetch_by_contig_id_constraint {
=cut
sub fetch_by_contig_id{
my ($self, $cid, $logic_name) = @_;
sub fetch_by_Contig{
my ($self, $contig, $logic_name) = @_;
#fetch by contig id constraint with empty constraint
return $self->fetch_by_contig_id_constraint($cid, '',$logic_name);
return $self->fetch_by_Contig_constraint($contig, '',$logic_name);
}
=head2 fetch_by_contig_id_and_score
=head2 fetch_by_Contig_and_score
Arg [1] : int $cid
the unique identifier (dbID) for contig to obtain feats from
Arg [1] : Bio::EnsEMBL::RawContig $contig
the contig from which features should be obtained
Arg [2] : float $score
the lower bound of the score of the features to obtain
Arg [3] : (optional) string $logic_name
the logic name of the type of features to obtain
Example : @fts = $a->fetch_by_contig_id_and_score(1, 50.0, 'swall');
Example : @fts = $a->fetch_by_Contig_and_score(1, 50.0, 'swall');
Description: Returns a list of features created from the database which are
are on the contig defined by $cid and which have score greater
than score. If logic name is defined, only features with an
......@@ -222,8 +228,8 @@ sub fetch_by_contig_id{
=cut
sub fetch_by_contig_id_and_score{
my($self, $cid, $score, $logic_name) = @_;
sub fetch_by_Contig_and_score{
my($self, $contig, $score, $logic_name) = @_;
my $constraint;
......@@ -234,7 +240,7 @@ sub fetch_by_contig_id_and_score{
}
my @features =
$self->fetch_by_contig_id_constraint($cid, $constraint, $logic_name);
$self->fetch_by_Contig_constraint($contig, $constraint, $logic_name);
return @features;
}
......@@ -518,7 +524,11 @@ sub fetch_by_assembly_location_constraint {
$f->start($coord->start());
$f->end($coord->end());
$f->strand($coord->strand());
$f->seqname($coord->id());
#$f->seqname($coord->id());
#
# Should we attach a slice of the entire chromosome here? (mcvicker)
#
push(@out,$f);
}
......
......@@ -17,9 +17,9 @@ Bio::EnsEMBL::DBSQL::DnaAlignFeatureAdaptor - Adaptor for DnaAlignFeatures
$dafa = $dbadaptor->get_DnaAlignFeatureAdaptor();
@feature_array = $dafa->fetch_by_contig_id($contig_id);
@feature_array = $dafa->fetch_by_Contig($contig);
$dafa->store($contig_id,@feature_array);
$dafa->store(@feature_array);
=head1 DESCRIPTION
......@@ -115,17 +115,13 @@ sub _columns {
=cut
sub store {
my ($self,$contig_id,@sf) = @_;
my ($self, @sf) = @_;
my $tablename = $self->_tablename();
if( scalar(@sf) == 0 ) {
$self->throw("Must call store with contig_id then sequence features");
}
if( $contig_id !~ /^\d+$/ ) {
$self->throw("Contig_id must be a number, not [$contig_id]");
}
my $sth = $self->prepare("
INSERT INTO $tablename (contig_id, contig_start, contig_end,
contig_strand, hit_start, hit_end,
......@@ -135,18 +131,29 @@ sub store {
foreach my $sf ( @sf ) {
if( !ref $sf || !$sf->isa("Bio::EnsEMBL::DnaDnaAlignFeature") ) {
$self->throw("feature must be an Ensembl DnaDnaAlignFeature, not a [$sf]");
$self->throw("feature must be a Bio::EnsEMBL::DnaDnaAlignFeature,"
. " not a [$sf]");
}
my $contig = $sf->entire_seq();
unless(defined $contig && ref $contig &&
$contig->isa("Bio::EnsEMBL::RawContig")) {
$self->throw("A contig must be attached to the features to be " .
"stored via the attach seq method\n");
}
if( !defined $sf->analysis ) {
$self->throw("Cannot store sequence features without analysis");
}
if( !defined $sf->analysis ) {
$self->throw("Cannot store sequence features without analysis");
}
if( !defined $sf->analysis->dbID ) {
# maybe we should throw here. Shouldn't we always have an analysis from the database?
$self->throw("I think we should always have an analysis object which has originated from the database. No dbID, not putting in!");
# maybe we should throw here.
# Shouldn't we always have an analysis from the database?
$self->throw("I think we should always have an analysis object which " .
"has originated from the database. No dbID, not putting in!");
}
#print STDERR "storing ".$sf->gffstring."\n";
$sth->execute( $contig_id, $sf->start, $sf->end, $sf->strand,
$sth->execute( $contig->dbID(), $sf->start, $sf->end, $sf->strand,
$sf->hstart, $sf->hend, $sf->hstrand, $sf->hseqname,
$sf->cigar_string, $sf->analysis->dbID, $sf->score,
$sf->p_value, $sf->percent_id);
......
......@@ -312,7 +312,8 @@ sub _new_Exon_from_hashRef {
$exon->sticky_rank($hashRef->{'sticky_rank'});
$exon->adaptor($self);
my $rc = $self->db->get_RawContigAdaptor->fetch_by_dbID($hashRef->{'contig_id'});
my $rc =
$self->db->get_RawContigAdaptor->fetch_by_dbID($hashRef->{'contig_id'});
$exon->contig( $rc );
$exon->seqname($hashRef->{'cid'});
......@@ -430,13 +431,15 @@ sub store {
my @componentExons = $exon->each_component_Exon();
for my $componentExon ( @componentExons ) {
my $contig = $componentExon->contig();
if( !defined $componentExon->contig_id ) {
$self->throw("Component Exon does not have a contig_id set. " .
unless(defined $contig && ref $contig && $contig->dbID()) {
$self->throw("Component Exon does not have an attached contig " .
"with a valid set database id. " .
"Needs to have one set");
}
$exonst->execute( $exonId, $componentExon->contig_id,
$exonst->execute( $exonId, $contig->dbID,
$componentExon->start(),
$componentExon->end(),
$componentExon->strand(),
......@@ -452,12 +455,14 @@ sub store {
} else {
# normal storing
if( !defined $exon->contig_id ) {
$self->throw("Exon does not have a contig_id set." .
"Needs to have one set");
my $contig = $exon->contig();
unless( defined $contig && ref $contig && $contig->dbID() ) {
$self->throw("Exon does not have an attached contig with a valid " .
"database id. Needs to have one set");
}
$exonst->execute( undef,$exon->contig_id,
$exonst->execute( undef,$contig->dbID,
$exon->start(),
$exon->end(),
$exon->strand(),
......
......@@ -151,10 +151,11 @@ sub write {
=head2 store
Title : store
Usage : $fa->store($contig,@features)
Function: Writes a feature on the genomic sequence of a contig into the database.
Checks that we have contig_obj, gets its internal_id. Checks that each
feature_obj has analysis_obj attached, gets analysis_id from it.
Usage : $fa->store(@features)
Function: Writes a feature on the genomic sequence of a contig into the
database. Checks that we have contig_obj, gets its internal_id.
Checks that each feature_obj has analysis_obj attached,
gets analysis_id from it.
Checks what kind of feature(s) is/are passed in and passes it/them
further to appropriate _store_blabla function together with contig_internal_id
and analysis_id.
......@@ -166,7 +167,7 @@ sub write {
sub store {
my ($self,$contig,@features) = @_;
my ($self,@features) = @_;
my ($p,$f,$l) = caller;
......@@ -181,9 +182,9 @@ sub store {
# Check for contig
$self->throw("$contig is not a Bio::EnsEMBL::DB::ContigI")
unless (defined($contig) && $contig->isa("Bio::EnsEMBL::DB::ContigI"));
my $contig_internal_id = $contig->dbID();
#$self->throw("$contig is not a Bio::EnsEMBL::DB::ContigI")
# unless (defined($contig) && $contig->isa("Bio::EnsEMBL::DB::ContigI"));
#my $contig_internal_id = $contig->dbID();
#
......@@ -224,13 +225,13 @@ sub store {
#
print STDERR "storing ".$feature."\n";
if( $feature->isa('Bio::EnsEMBL::DnaPepAlignFeature') ) {
$protein_align_adaptor->store($contig_internal_id,$feature);
$protein_align_adaptor->store($feature);
} elsif ( $feature->isa('Bio::EnsEMBL::DnaDnaAlignFeature') ) {
$dna_align_adaptor->store($contig_internal_id,$feature);
$dna_align_adaptor->store($feature);
} elsif ( $feature->isa('Bio::EnsEMBL::RepeatFeature') ) {
$repeat_adaptor->store($contig_internal_id,$feature);
$repeat_adaptor->store($feature);
} elsif ( $feature->isa('Bio::EnsEMBL::SimpleFeature') ) {
$simple_adaptor->store($contig_internal_id,$feature);
$simple_adaptor->store($feature);
# } elsif ( $feature->isa('Bio::EnsEMBL::PredictionFeature') ) {
# $prediction_adaptor->store($contig_internal_id,$feature);
} else {
......
......@@ -98,46 +98,21 @@ sub fetch_by_dbID {
=head2 fetch_by_Contig
Arg [1] : Bio::EnsEMBL::RawContig $contig
the contig to retrieve prediction transcripts on
The contig to retrieve prediction transcripts from
Arg [2] : (optional) string $logic_name
the type of analysis performed on objects which should be
retrieved
Example : @pts = $pt_adaptor->fetch_by_Contig($contig,'Genscan')
Description: Retrieves prediction transcripts from a contig
Returntype : list of Bio::EnsEMBL::PredictionTranscript in contig coords
Returntype : list of Bio::EnsEMBL::PredictionTranscripts in contig coords
Exceptions : none
Caller : general
=cut
sub fetch_by_Contig{
sub fetch_by_Contig {
my ($self, $contig, $logic_name) = @_;
my @results = $self->fetch_by_contig_id($contig->dbID, $logic_name);
return @results;
}
=head2 fetch_by_contig_id
Arg [1] : int $contig_id
the database id of the contig to retrieve prediction
transcripts on
Arg [2] : (optional) string $logic_name
the type of analysis performed on objects which should be
retrieved
Example : @pts = $pt_adaptor->fetch_by_Contig($contig,'Genscan')
Description: Retrieves prediction transcripts from a contig
Returntype : list of Bio::EnsEMBL::PredictionTranscripts in contig coords
Exceptions : none
Caller : general
=cut
sub fetch_by_contig_id {
my ($self, $contig_id, $logic_name) = @_;
my $constraint = undef;
if($logic_name){
......@@ -152,21 +127,20 @@ sub fetch_by_contig_id {
$constraint = " analysis_id = ".$analysis->dbID;
}
my @results = $self->fetch_by_contig_id_constraint($contig_id, $constraint);
my @results = $self->fetch_by_Contig_constraint($contig, $constraint);
return @results;
}
=head2 fetch_by_contig_id_constraint
=head2 fetch_by_Contig_constraint
Arg [1] : int $contig_id
the unique database identifier of the contig to retrieve
prediction transcripts from
Arg [1] : Bio::EnsEMBL::RawContig $contig
The contig to obtain prediction transcripts from
Arg [2] : (optional) string $constraint
the limiting SQL to form the where clause of the the database
query
Example : @pts = $pta->fetch_by_contig_id_constraint(1,'analysis_id = 2');
Example : @pts = $pta->fetch_by_Contig_constraint($contig, 'analysis_id = 2');
Description: returns all PredicitonTranscipts on given contig
Returntype : list of Bio::EnsEMBL::PredictionTranscript in contig coords
Exceptions : none, if there are none, the list is empty.
......@@ -174,11 +148,17 @@ sub fetch_by_contig_id {
=cut
sub fetch_by_contig_id_constraint {
sub fetch_by_Contig_constraint {
my $self = shift;
my $contig_id = shift;
my $contig = shift;
my $constraint = shift;
unless(defined $contig && ref $contig &&
$contig->isa('Bio::EnsEMBL::Contig')){
$self->throw("contig arg must be a Bio::EnsEMBL::RawContig");
return undef;
}
my $query = qq {
SELECT p.prediction_transcript_id
, p.contig_id
......@@ -203,7 +183,7 @@ sub fetch_by_contig_id_constraint {
$query .= " order by p.prediction_transcript_id, p.exon_rank";
#print $query."\n";
my $sth = $self->prepare( $query );
$sth->execute( $contig_id );
$sth->execute( $contig->dbID() );
my @res = $self->_ptrans_from_sth( $sth );
return @res;
......
......@@ -18,11 +18,11 @@ Adaptor for ProteinAlignFeatures
$pfadp = $dbadaptor->get_ProteinAlignFeatureAdaptor();
my @features = $pfadp->fetch_by_contig_id($contig_numeric_id);
my @features = $pfadp->fetch_by_Contig($contig);
my @features = $pfadp->fetch_by_assembly_location($start,$end,$chr,'UCSC');
$pfadp->store($contig_numeric_id, @features);
$pfadp->store(@features);
=head1 DESCRIPTION
......@@ -64,48 +64,63 @@ use Bio::EnsEMBL::SeqFeature;
=head2 store
Title : store
Usage :
Function:
Example :
Returns :
Args :
Arg [1] : list of Bio::EnsEMBL::DnaPepAlignFeature @sf
Example : $protein_align_feature_adaptor->store(@sf);
Description: stores a list of features in the database
Returntype : none
Exceptions : thrown if there is no attached sequence on any of the features,
if the features are not defined
Caller :
=cut
sub store{
my ($self,$contig_id,@sf) = @_;
my ($self ,@sf) = @_;
if( scalar(@sf) == 0 ) {
$self->throw("Must call store with contig_id then sequence features");
}
if( $contig_id !~ /^\d+$/ ) {
$self->throw("Contig_id must be a number, not [$contig_id]");
$self->throw("Must call store with list of sequence features");
}
my $sth = $self->prepare("insert into protein_align_feature (contig_id,contig_start,contig_end,contig_strand,hit_start,hit_end,hit_name,cigar_line,analysis_id,score, evalue, perc_ident) values (?,?,?,?,?,?,?,?,?,?, ?, ?)");
my $sth = $self->prepare(
"INSERT INTO protein_align_feature(contig_id, contig_start, contig_end,
contig_strand, hit_start, hit_end,
hit_name, cigar_line, analysis_id,
score, evalue, perc_ident)
VALUES (?,?,?,?,?,?,?,?,?,?, ?, ?)");
foreach my $sf ( @sf ) {
if( !ref $sf || !$sf->isa("Bio::EnsEMBL::DnaPepAlignFeature") ) {
$self->throw("Simple feature must be an Ensembl ProteinAlignFeature, not a [$sf]");
}
if( !defined $sf->analysis ) {
$self->throw("Cannot store sequence features without analysis");
}
if( !defined $sf->analysis->dbID ) {
# maybe we should throw here. Shouldn't we always have an analysis from the database?
$self->throw("I think we should always have an analysis object which has originated from the database. No dbID, not putting in!");
}
#print STDERR "storing ".$sf->gffstring."\n";
$sth->execute($contig_id,$sf->start,$sf->end,$sf->strand,$sf->hstart,$sf->hend,$sf->hseqname,$sf->cigar_string,$sf->analysis->dbID,$sf->score, $sf->p_value, $sf->percent_id);
$sf->dbID($sth->{'mysql_insertid'});
if( !ref $sf || !$sf->isa("Bio::EnsEMBL::DnaPepAlignFeature") ) {
$self->throw("Feature must be a Bio::EnsEMBL::ProteinAlignFeature, " .
"not a [$sf]");
}
if( !defined $sf->analysis ) {
$self->throw("Cannot store sequence features without analysis");
}
if( !defined $sf->analysis->dbID ) {
# maybe we should throw here. Shouldn't we always have an
# analysis from the database?
$self->throw("I think we should always have an analysis object " .
"which has originated from the database. No dbID, " .
"not putting in!");
}
my $contig = $sf->entire_seq();
unless(defined $contig && ref $contig &&
$contig->isa("Bio::EnsEMBL::RawContig")) {
$self->throw("Cannot store feature without Contig attached via " .
"attach_seq\n");
}
$sth->execute($contig->dbID(), $sf->start, $sf->end,
$sf->strand, $sf->hstart, $sf->hend,
$sf->hseqname, $sf->cigar_string, $sf->analysis->dbID,
$sf->score, $sf->p_value, $sf->percent_id);
$sf->dbID($sth->{'mysql_insertid'});
}
}
}
#
......@@ -149,7 +164,6 @@ sub _obj_from_hashref {
-cigar_string => $cigar);
$dnapep->analysis($analysis);
$dnapep->seqname($contig->name());
$dnapep->attach_seq($contig);
#set the 'id' of the feature to the hit name
$dnapep->id($hashref->{'hit_name'});
......
......@@ -304,7 +304,7 @@ sub fetch_filled_by_dbIDs {
}
=head2 fetch_by_clone
=head2 fetch_by_Clone
Arg [1] : Bio::EnsEMBL::Clone $clone
The clone object that the contigs are desired from
......@@ -317,7 +317,7 @@ sub fetch_filled_by_dbIDs {
=cut
sub fetch_by_clone {
sub fetch_by_Clone {
my $self = shift;
my $clone = shift;
......
......@@ -178,33 +178,32 @@ sub fetch_seq_string_for_dbID {
=cut
sub store {
my( $self, @consensi ) = @_;
my $sth = $self->prepare(q{
INSERT into repeat_consensus( repeat_consensus_id
my( $self, @consensi ) = @_;
my $sth = $self->prepare(q{
INSERT into repeat_consensus( repeat_consensus_id
, repeat_name
, repeat_class
, repeat_consensus )
VALUES (NULL, ?,?,?)
});
VALUES (NULL, ?,?,?)
});
foreach my $rc (@consensi) {
my $name = $rc->name