[Bioperl-l] sequence upgrading

Jamie Hatfield jamie at genome.arizona.edu
Thu Jun 26 17:20:50 EDT 2003


Could the Storable.pm object be used to do deep cloning of objects?  I
use it for storing data to files sometimes, and noticed it had a dclone
option...

I think it comes standard with perl 5.8...  :-(  But it uses C and is
quite faster than Data::Dumper.

On Thu, 2003-06-26 at 05:11, Marc Logghe wrote:
> Thanks,
> and yes I was thinking of a module for deep copying of objects. Currently I
> was trying with Data::Dumper cos this comes standard with Perl.
> Regards,
> ML
> 
> > -----Original Message-----
> > From: Heikki Lehvaslaiho [mailto:heikki at ebi.ac.uk]
> > Sent: Thursday, June 26, 2003 12:51 PM
> > To: Marc Logghe
> > Cc: 'Hilmar Lapp'; Bioperl-L (E-mail)
> > Subject: RE: [Bioperl-l] sequence upgrading
> > 
> > 
> > Marc,
> > 
> > I think Hilmar suggests adding something like this into 
> > Bio::Seq::RichSeq:
> > 
> > 
> > sub copy {
> >     my ($self, $seq) = @_;
> >     unless (defined $seq) {
> >         # return a deep copy of $self
> >         my $newseq = new $self;
> >         # ... copy attributes
> > 
> >         return $newseq;
> >     }
> >     if ($seq->isa('Bio::PrimarySeqI') ) {
> >         my $newseq = new $self;
> >         @primaryseqmethods = qw( seq display_id ...);
> >         map {$newseq->$_($seq->$_) } @primaryseqmethods;
> >         return $newseq if $seq->isa('Bio::PrimarySeq');
> > 
> >         # either deal with all other methods by class
> >         @seqmethods = qw( species ...);
> > 
> >         # or test them all one by one
> >         $newseq->species($seq->species) if $seq->can('spacies');
> >         # ...
> >         returnt $newseq;
> >     } else {
> >      $self->throw("Can copy only sequence objects, not ". ref $seq.
> > "\n");
> >     }
> > 
> > }
> > 
> > Actually, the whole problem of dealing with attributes is solved in a
> > CPAN module Clone which does deep copying of structures.
> > 
> > With it you can simply say:
> > 
> > use Clone qw(clone);
> > # $seq can be e.g. Bio::Seq with features
> > my $seq2 = clone $seq;
> > 
> > However, simply 'use'ing Clone in sequence classes would add 
> > an external
> > dependency into bioperl core classes, which is not acceptable.  I am
> > sure there are many clever solutions to this problem, though.
> > 
> > 	-Heikki
> > 
> > On Thu, 2003-06-26 at 10:43, Marc Logghe wrote:
> > > > 
> > > > This depends entirely on your implementation. E.g., if 
> > you put a copy 
> > > > constructor on Bio::Seq::RichSeq that accepts 
> > Bio::PrimarySeqs (or 
> > > > whatever) then you would 'upgrade'.
> > > > 
> > > > 	-hilmar
> > > OK, I see.
> > > Something like:
> > > 1) deep copying 
> > > use Bio::SeqIO;
> > > my $gbio = Bio::SeqIO->new(-format => 'genbank');
> > > 
> > > while (my $seq1 = $gbio->next_seq)
> > > {
> > >   my $seq2 = $seq1->copy # $seq2 is deep copy of 
> > Bio::Seq::RichSeq object
> > > $seq1
> > > 
> > >   # do some stuff with $seq2
> > > }
> > > 
> > > or:
> > > 2) 'upgrading'
> > > use Bio::SeqIO;
> > > use Bio::Seq::RichSeq;
> > > my $fasta_io = Bio::SeqIO->new;
> > > 
> > > while (my $seq1 = $fasta_io->next_seq)
> > > {
> > >    my $seq2 = Bio::Seq::RichSeq->copy($seq1) # $seq2 is 
> > enriched fasta seq
> > > object
> > > 
> > >    # do some stuff with $seq2
> > > }
> > > 
> > > Correct ?
> > > Marc
> > > _______________________________________________
> > > Bioperl-l mailing list
> > > Bioperl-l at portal.open-bio.org
> > > http://portal.open-bio.org/mailman/listinfo/bioperl-l
> > -- 
> > ______ _/      _/_____________________________________________________
> >       _/      _/                      http://www.ebi.ac.uk/mutations/
> >      _/  _/  _/  Heikki Lehvaslaiho    heikki_at_ebi ac uk
> >     _/_/_/_/_/  EMBL Outstation, European Bioinformatics Institute
> >    _/  _/  _/  Wellcome Trust Genome Campus, Hinxton
> >   _/  _/  _/  Cambs. CB10 1SD, United Kingdom
> >      _/      Phone: +44 (0)1223 494 644   FAX: +44 (0)1223 494 468
> > ___ _/_/_/_/_/________________________________________________________
> > 
> _______________________________________________
> Bioperl-l mailing list
> Bioperl-l at portal.open-bio.org
> http://portal.open-bio.org/mailman/listinfo/bioperl-l




More information about the Bioperl-l mailing list