[Bioperl-l] sequence upgrading
Heikki Lehvaslaiho
heikki at ebi.ac.uk
Thu Jun 26 11:50:42 EDT 2003
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
___ _/_/_/_/_/________________________________________________________
More information about the Bioperl-l
mailing list