Archive Ensembl HomeArchive Ensembl Home
StoreSequence.pm
Go to the documentation of this file.
00001 #
00002 # You may distribute this module under the same terms as perl itself
00003 #
00004 # POD documentation - main docs before the code
00005 
00006 =pod 
00007 
00008 =head1 NAME
00009 
00010 Bio::EnsEMBL::Compara::Production::GenomicAlignBlock::StoreSequence
00011 
00012 =cut
00013 
00014 =head1 SYNOPSIS
00015 
00016 my $db       = Bio::EnsEMBL::Compara::DBAdaptor->new($locator);
00017 my $runnable = Bio::EnsEMBL::Compara::Production::GenomicAlignBlock::StoreSequence>new (
00018                                                     -db      => $db,
00019                                                     -input_id   => $input_id
00020                                                     -analysis   => $analysis );
00021 $runnable->fetch_input(); #reads from DB
00022 $runnable->run();
00023 $runnable->write_output(); #writes to DB
00024 
00025 =cut
00026 
00027 =head1 DESCRIPTION
00028 
00029 This object gets the DnaFrag objects from a DnaFragChunkSet and stores the sequence (if short enough) in the Compara sequence table
00030 
00031 =cut
00032 
00033 =head1 CONTACT
00034 
00035 Describe contact details here
00036 
00037 =cut
00038 
00039 =head1 APPENDIX
00040 
00041 The rest of the documentation details each of the object methods.
00042 Internal methods are usually preceded with a _
00043 
00044 =cut
00045 
00046 package Bio::EnsEMBL::Compara::Production::GenomicAlignBlock::StoreSequence;
00047 
00048 use strict;
00049 use Time::HiRes qw(time gettimeofday tv_interval);
00050 use Bio::EnsEMBL::Utils::Exception qw( throw warning verbose );
00051 
00052 use Bio::EnsEMBL::DBSQL::DBAdaptor;
00053 use Bio::EnsEMBL::DBLoader;
00054 
00055 use Bio::EnsEMBL::Compara::Production::DBSQL::DBAdaptor;
00056 
00057 use Bio::EnsEMBL::Compara::Production::DnaFragChunk;
00058 use Bio::EnsEMBL::Compara::Production::DnaFragChunkSet;
00059 use Bio::EnsEMBL::Compara::Production::DnaCollection;
00060 
00061 use Bio::EnsEMBL::Hive::DBSQL::AnalysisJobAdaptor;
00062 
00063 use Bio::EnsEMBL::Analysis::RunnableDB;
00064 use Bio::EnsEMBL::Hive::Process;
00065 
00066 our @ISA = qw(Bio::EnsEMBL::Hive::Process Bio::EnsEMBL::Analysis::RunnableDB);
00067 
00068 
00069 =head2 fetch_input
00070 
00071     Title   :   fetch_input
00072     Usage   :   $self->fetch_input
00073     Function:   prepares global variables and DB connections
00074     Returns :   none
00075     Args    :   none
00076 
00077 =cut
00078 
00079 sub fetch_input {
00080     my( $self) = @_;
00081     
00082     #create a Compara::DBAdaptor which shares the same DBI handle
00083     #with the DBAdaptor that is based into this runnable
00084     $self->{'comparaDBA'} = Bio::EnsEMBL::Compara::Production::DBSQL::DBAdaptor->new(-DBCONN => $self->db->dbc);
00085     
00086     $self->get_params($self->parameters);
00087     $self->get_params($self->input_id);
00088     
00089     return 1;
00090 }
00091 
00092 
00093 sub run
00094 {
00095   my $self = shift;
00096 
00097   return 1;
00098 }
00099 
00100 
00101 sub write_output 
00102 {  
00103   my $self = shift;
00104 
00105   #
00106   #Get all the chunks in this dnaFragChunkSet
00107   #
00108   if (defined $self->{'dnaFragChunkSet'}) {
00109       my $chunkSet = $self->{'dnaFragChunkSet'};
00110       my $chunk_array = $chunkSet->get_all_DnaFragChunks;
00111       
00112       #Store sequence in Sequence table
00113       foreach my $chunk (@$chunk_array) {
00114       my $bioseq = $chunk->bioseq;
00115       if($chunk->sequence_id==0) {
00116           $self->{'comparaDBA'}->get_DnaFragChunkAdaptor->update_sequence($chunk);
00117       }
00118       }
00119   }
00120 
00121   if (defined $self->{'dnaFragChunk'}) {
00122       my $chunk = $self->{'dnaFragChunk'};
00123 
00124       #Store sequence in Sequence table
00125       my $bioseq = $chunk->bioseq;
00126       if($chunk->sequence_id==0) {
00127       $self->{'comparaDBA'}->get_DnaFragChunkAdaptor->update_sequence($chunk);
00128       }
00129   }
00130   return 1;
00131 }
00132 
00133 
00134 
00135 ######################################
00136 #
00137 # subroutines
00138 #
00139 #####################################
00140 
00141 sub get_params {
00142   my $self         = shift;
00143   my $param_string = shift;
00144 
00145   return unless($param_string);
00146   print("parsing parameter string : ",$param_string,"\n");
00147   
00148   my $params = eval($param_string);
00149   return unless($params);
00150 
00151   foreach my $key (keys %$params) {
00152     print("  $key : ", $params->{$key}, "\n");
00153   }
00154 
00155   #Convert chunkSetID into DnaFragChunkSet object
00156   if(defined($params->{'chunkSetID'})) {
00157      my $chunkset = $self->{'comparaDBA'}->get_DnaFragChunkSetAdaptor->fetch_by_dbID($params->{'chunkSetID'});
00158      $self->{'dnaFragChunkSet'} = $chunkset;
00159   }
00160 
00161   #Convert chunkID into DnaFragChunk object
00162   if(defined($params->{'chunkID'})) {
00163      my $chunk = $self->{'comparaDBA'}->get_DnaFragChunkAdaptor->fetch_by_dbID($params->{'chunkID'});
00164      $self->{'dnaFragChunk'} = $chunk;
00165   }
00166 
00167 }
00168