Commit 9d4669ba authored by Graham McVicker's avatar Graham McVicker
Browse files

Added store method to RawContigAdaptor and Sequence Adaptors.

Modified Clone store method so that it functions correctly.
Changed RawContig and Clone so that they can be instantiated w/o db connection.
parent 76fc29d4
......@@ -50,33 +50,42 @@ use Bio::EnsEMBL::Root;
@ISA = qw( Bio::EnsEMBL::Root );
sub new {
my ($class,$adaptor,@args) = @_;
my $self = {};
bless $self,$class;
=head2 new
Arg [1] : Bio::EnsEMBL::DBSQL::BaseAdaptor $adaptor (optional)
The database adaptor for this clone object
Arg [2] : int $internal_id (optional)
The database identifier for this clone
Arg [3] : string $id (optional)
The name of this clone
Arg [4] : string $embl_id (optional)
The EMBL accession number of this clone
Arg [5] : int $version (optional)
The version of this clone
Arg [6] : int $embl_version (optional)
The EMBL version of this clone
Arg [7] : int htg_phase (optional)
the htg phase of this clone
Arg [8] : date $created
The date this clone was first entered into the database.
Arg [9] : date $modified
The date this clone was last modified in the database
Example : $clone = new Bio::EnsEMBL::Clone();
Description: Creates a new Clone object from a set of optional parameters.
Returntype : Bio::EnsEMBL::Clone
Exceptions : none
Caller : general
=cut
my ($internal_id,$id,$embl_id,$version,$embl_version,$htg_phase,$created,$modified)=@args;
sub new {
my ($class,$adaptor,$internal_id, $id, $embl_id, $version, $embl_version,
$htg_phase, $created, $modified) = @_;
$self->throw("Don't have a id [$id] for new clone") unless $id;
$self->throw("Don't have a adaptor [$adaptor] for new clone $id") unless $adaptor;
$self->throw("Don't have a internal id [$internal_id] for new clone $id") unless $internal_id;
$self->throw("Don't have a embl id [$embl_id] for new clone $id") unless $embl_id;
$self->throw("Don't have a version [$version] for new clone $id") unless defined $version;
$self->throw("Don't have a embl verson [$embl_version] for new clone $id") unless defined $embl_version;
my $self = {};
bless $self,$class;
if( $version == 0 ) {
$self->warn("seq version $version and embl version $embl_version are 0 - this will not play nicely with external feature factories!");
}
# HACK htg_phase is NOT set correctly for many clones (th, 7/01)
$self->warn("Don't have a htg phase [$htg_phase] for new clone $id") unless $htg_phase;
#$self->throw("Don't have a created [$created] for new clone") unless $created;
#$self->throw("Don't have a modified [$modified] for new clone") unless $modified;
$self->adaptor($adaptor);
$self->dbID($internal_id);
$self->id($id);
......@@ -92,8 +101,6 @@ sub new {
=head2 get_all_Genes
Args : none
......@@ -107,9 +114,7 @@ sub new {
=cut
sub get_all_Genes
{
sub get_all_Genes {
my $self=shift;
return $self->adaptor->get_all_Genes( $self->dbID );
......@@ -117,41 +122,12 @@ sub get_all_Genes
=head2 get_Contig
Args : none
Example : none
Description: deprecated, use ContigAdaptor to get Contig
Returntype : none
Exceptions : none
Caller : none
=cut
sub get_Contig {
my ($self,$contigid) = @_;
$self->throw("Clone::get_Contig is deprecated, " .
"use \$contig_adaptor->fetch_by_dbID(\$contig_id) instead\n");
return undef;
# my $contig = $self->adaptor->get_Contig($contigid);
# return $contig->fetch();
}
=head2 get_all_Contigs
Args : none
Example : none
Description: get RawContig objects from this Clone
Description: get RawContig objects from this Clone (either manually added
or from the database).
Returntype : list of Bio::EnsEMBL::RawContig
Exceptions : none
Caller : general
......@@ -160,41 +136,52 @@ sub get_Contig {
sub get_all_Contigs {
my( $self ) = @_;
my( $c_list );
unless ($c_list = $self->{'_contig_list'}) {
my $ra = $self->adaptor->db->get_RawContigAdaptor;
$c_list = $ra->fetch_by_clone($self);
$self->{'_contig_list'} = $c_list;
}
return @$c_list;
my( $self ) = @_;
my( $c_list );
#If the contig list is not defined then an attempt is made to retrieve it
#from the database
unless ($c_list = $self->{'_contig_list'}) {
my $ra = $self->adaptor->db->get_RawContigAdaptor;
$c_list = $ra->fetch_by_clone($self);
$self->{'_contig_list'} = $c_list;
}
return @$c_list;
}
=head2 delete
Args : none
Example : none
Description: deprecated, use object adaptor for deletion
=head2 add_Contig
Arg [1] : Bio::EnsEMBL::RawContig $contig
Example : $clone->add_Contig($contig);
Description: Manually adds a contig to this clone object. This is generally
for database loading purposes only. I.e. contigs are added
to clones and then the clones, attached contigs and dna
sequences are loaded into the database. If contigs are added
in this fashion then get_all_Contigs will only return contigs
manually added, not contigs which may be residing in the
database.
Returntype : none
Exceptions : none
Caller : none
Caller : database loading scripts
=cut
sub add_Contig {
my ($self, $contig) = @_;
unless(defined $self->{'_contig_list'}) {
$self->{'_contig_list'} = ();
}
sub delete
{
my ($self)=shift;
$self->warn("delete is now deprecated, use delete_by_dbID instead");
$self->delete_by_dbID;
push @{$self->{'_contig_list'}}, $contig;
}
=head2 delete_by_dbID
Args : none
......@@ -207,8 +194,6 @@ sub delete
=cut
sub delete_by_dbID {
my ($self)=shift;
return $self->adaptor->delete_by_dbID($self->dbID);
......@@ -216,7 +201,6 @@ sub delete_by_dbID {
=head2 get_all_rawcontigs_by_position
Arg 1 : int $base_pair
......@@ -228,8 +212,6 @@ sub delete_by_dbID {
=cut
sub get_rawcontig_by_position {
my ($self, $pos) = @_;
......@@ -253,77 +235,6 @@ sub get_rawcontig_by_position {
=head2 is_golden
Args : none
Example : none
Description: deprecated, use assembly_mapper->in_assembly( $clone )
Returntype : none
Exceptions : none
Caller : none
=cut
sub is_golden{
my ($self,@args) = @_;
$self->warn("Clone::is_golden is deprecated. " .
"Use \$assembly_mapper->in_assembly(\$clone)");
my $asma = $self->adaptor()->db()->get_AssemblyMapperAdaptor();
my $am = $asma->fetch_by_type($self->db()->assembly_type());
return $am->in_assembly($self);
# foreach my $contig ($self->get_all_Contigs) {
# if ($contig->is_golden) {
# return 1;
# }
# }
# return 0;
}
=head2 seq_date
Args : none
Example : none
Description: loops over all $contig->seq_date, throws a warning
if they are different and returns the first unix
time value of the dna created datetime field, which indicates
the original time of the dna sequence data
Returntype : a unix time ??
Exceptions : none
Caller : general
=cut
sub seq_date {
my ($self) = @_;
my $id = $self->id();
my ($seq_date,$old_seq_date);
foreach my $contig ($self->get_all_Contigs) {
$seq_date = $contig->seq_date;
if ($old_seq_date) {
if ($seq_date != $old_seq_date) {
$self->warn ("The created date of the DNA sequence from contig
$contig is different from that of the sequence
from other contigs on the same clone!");
}
}
$old_seq_date = $seq_date;
}
return $seq_date;
}
=head2 htg_phase
Arg [1] : string $htg_phase
......@@ -337,7 +248,6 @@ sub seq_date {
=cut
sub htg_phase {
my $obj = shift;
if( @_ ) {
......@@ -363,7 +273,6 @@ sub htg_phase {
=cut
sub created {
my $obj = shift;
if( @_ ) {
......@@ -389,8 +298,6 @@ sub created {
=cut
sub modified {
my $obj = shift;
if( @_ ) {
......@@ -416,8 +323,6 @@ sub modified {
=cut
sub version{
my $obj = shift;
if( @_ ) {
......@@ -429,6 +334,7 @@ sub version{
}
=head2 embl_version
Arg [1] : string $embl_version
......@@ -440,7 +346,6 @@ sub version{
=cut
sub embl_version {
my $obj = shift;
if( @_ ) {
......@@ -452,7 +357,6 @@ sub embl_version {
=head2 embl_id
Arg [1] : string $embl_id
......@@ -464,9 +368,6 @@ sub embl_version {
=cut
sub embl_id {
my ($obj,$value) = @_;
if( defined $value) {
......@@ -480,18 +381,16 @@ sub embl_id {
=head2 id
Args : none
Example : none
Description: should be deprecated, gives an optional ensembl name
for the clone. Was used for non submitted clones and is
probably useless now.
Returntype : none
Args : string $value (optional)
The new name of this clone
Example : $name = $clone->id();
Description: The name of hte clone.
Returntype : string
Exceptions : none
Caller : none
Caller : general
=cut
sub id {
my ($obj,$value) = @_;
if( defined $value) {
......@@ -501,6 +400,8 @@ sub id {
}
=head2 dbID
Arg [1] : int $dbID
......@@ -512,7 +413,6 @@ sub id {
=cut
sub dbID{
my $obj = shift;
if( @_ ) {
......@@ -524,6 +424,7 @@ sub dbID{
}
=head2 adaptor
Arg [1] : Bio::EnsEMBL::DBSQL::CloneAdaptor $adaptor
......@@ -535,7 +436,6 @@ sub dbID{
=cut
sub adaptor {
my ($obj,$value) = @_;
if( defined $value) {
......@@ -546,6 +446,124 @@ sub adaptor {
}
=head2 delete
Args : none
Example : none
Description: deprecated, use object adaptor for deletion
Returntype : none
Exceptions : none
Caller : none
=cut
sub delete {
my ($self)=shift;
$self->warn("delete is now deprecated, use delete_by_dbID instead");
$self->delete_by_dbID;
}
=head2 seq_date
Arg [1] : none
Example : none
Description: DEPRECATED use created instead
All contig sequences should have been created at the
same time as this clone anyway, and seq_date is no longer
accessable from RawContig.
Returntype : none
Exceptions : none
Caller : none
=cut
sub seq_date {
my ($self) = @_;
$self->warn("Call to deprecated method Bio::EnsEMBL::Clone::seq_date" .
"Calling created method instead");
return $self->created();
# my $id = $self->id();
# my ($seq_date,$old_seq_date);
# foreach my $contig ($self->get_all_Contigs) {
# $seq_date = $contig->seq_date;
# if ($old_seq_date) {
# if ($seq_date != $old_seq_date) {
# $self->warn ("The created date of the DNA sequence from contig
# $contig is different from that of the sequence
# from other contigs on the same clone!");
# }
# }
# $old_seq_date = $seq_date;
# }
# return $seq_date;
}
=head2 is_golden
Args : none
Example : none
Description: deprecated, use assembly_mapper->in_assembly( $clone )
Returntype : none
Exceptions : none
Caller : none
=cut
sub is_golden{
my ($self,@args) = @_;
$self->warn("Clone::is_golden is deprecated. " .
"Use \$assembly_mapper->in_assembly(\$clone)");
my $asma = $self->adaptor()->db()->get_AssemblyMapperAdaptor();
my $am = $asma->fetch_by_type($self->db()->assembly_type());
return $am->in_assembly($self);
# foreach my $contig ($self->get_all_Contigs) {
# if ($contig->is_golden) {
# return 1;
# }
# }
# return 0;
}
=head2 get_Contig
Args : none
Example : none
Description: deprecated, use ContigAdaptor to get Contig
Returntype : none
Exceptions : none
Caller : none
=cut
sub get_Contig {
my ($self,$contigid) = @_;
$self->throw("Clone::get_Contig is deprecated, " .
"use \$contig_adaptor->fetch_by_dbID(\$contig_id) instead\n");
return undef;
# my $contig = $self->adaptor->get_Contig($contigid);
# return $contig->fetch();
}
1;
......
......@@ -370,10 +370,11 @@ sub get_all_Genes {
Arg [1] : Bio::EnsEMBL::Clone $clone
the Clone to store in the database
Example : $clone_adaptor->store($clone);
Description: Stores a clone object in the database
Returntype : none
Description: Stores a clone object and its associated contigs
in the database and returns the dbID of the new db record
Returntype : int
Exceptions : thrown if $clone is not defined or if $clone is not a
Bio::EnsEMBL::Clone
Bio::EnsEMBL::Clone or if the database insertion fails
Caller : general
=cut
......@@ -404,21 +405,28 @@ sub store{
FROM_UNIXTIME(".$clone->created."),
FROM_UNIXTIME(".$clone->modified."))";
my $sth = $self->prepare($sql);
my $rv = $sth->execute();
$self->throw("Failed to insert clone $clone->id") unless $rv;
$self->throw("Failed to insert clone $clone->id") unless $rv;
$sth->finish();
$sth = $self->prepare("select last_insert_id()");
my $res = $sth->execute;
my $row = $sth->fetchrow_hashref;
$sth->finish;
my $id = $row->{'last_insert_id()'};
$sth->execute;
my ($id) = $sth->fetchrow();
$sth->finish();
#update this clones database identifier
$clone->dbID($id);
#store the contigs which were on this clone
my $rca = $self->db->get_RawContigAdaptor();
foreach my $contig($clone->get_all_Contigs()){
my $rca = $self->db->get_RawContigAdaptor();
$rca->store($contig, $id);
$rca->store($contig, $clone);
}
return $id;
}
......
......@@ -365,6 +365,66 @@ sub fetch_attributes {
}
=head2 store
Arg [1] : Bio::EnsEMBL::RawContig $contig
The contig to store in the database.
Arg [2] : Bio::EnsEMBL::Clone $clone
The clone the contig is on
Example : my $contig_id = $raw_contig_adaptor->store($contig, $clone);
Description: Stores a contig and its associated DNA sequence in the database,
returns the database id of the new database record.
Returntype : int
Exceptions : thrown if $contig arg is not defined, $clone arg is not a clone
or if the database insertion fails.
Caller : Bio::EnsEMBL::Clone::store
=cut
sub store {
my ($self, $contig, $clone) = @_;
unless($contig && $contig->isa('Bio::EnsEMBL::RawContig')) {
$self->throw('contig arg is not a Bio::EnsEMBL::RawContig');
}
unless($clone && $clone->isa('Bio::EnsEMBL::Clone')) {
$self->throw('clone arg is not a Bio::EnsEMBL::Clone');
}
my $date = $clone->created();
my $dna = $contig->seq();
my $dna_id = $self->db->get_SequenceAdaptor->store($dna, $date);
my $sth = $self->prepare("INSERT INTO contig (name,
clone_id,
length,
embl_offset,
dna_id)