[Biojava-dev] Sequence cloning with annotations & features...

mark.schreiber at novartis.com mark.schreiber at novartis.com
Wed Mar 30 02:42:34 EST 2005


Only if you reassign it to the same reference. Otherwise there is a true 
deep copy/

eg

Sequence seqA = ... //code to initialize SeqA
Sequence seqB = null
ObjectOutputStream oos = ...
ObjectInputStream ois = ...

oos.writeObject(seqA);
seqB = (Sequence)ois.readObject();

seqA == seqB //this is false, there are now two copies in memory in 
different locations. Unless someone has done some major work on overriding 
the readResolve method of the Sequence implementation seqA and seqB do not 
reference the same memory location.

seqA.equals(seqB) //probably true depending on implementation of equals()


This is a true deep copy. Most clone operations are shallow so many of the 
internal objects of a cloned object are cannonical, thier reference points 
to the same memory location, (== returns true).

There are however some tricks in BioJava. Because lots of things are 
singletons (eg instances of Alphabet) there are read resolve methods to 
prevent these been duplicated. If you serialized a Distribution over DNA 
and then read it back in. Both Distributions would still reference the 
same Alphabet object even though everything else has been duplicated. The 
regenerated Distribution is simply reconnected with an existing Alphabet 
instance. This even happens across JVMs!

- Mark





Michael Heuer <heuermh at acm.org>
Sent by: Michael Heuer <heuermh at shell3.shore.net>
03/30/2005 03:05 PM

 
        To:     Mark Schreiber/GP/Novartis at PH
        cc:     David Jung <jungdl at ornl.gov>, <biojava-dev at biojava.org>
        Subject:        Re: [Biojava-dev] Sequence cloning with annotations & features...



On Wed, 30 Mar 2005 mark.schreiber at novartis.com wrote:

> A very crude way to "deep clone" would be to serialize the Sequence 
object
> and deserialize it as another object. We did a lot of work on
> Serialization a few years back to get biojava to work with it. If you
> notice anything odd let us know. The advantage of this is that both 
would
> be exactly the same, even down to the implementing classes.

Presumably if you serialize a Sequence to a stream or file and then
deserialize it back into memory again, shouldn't the before and after
copies be "equal" to each other?  Thinking back to a chapter in Bloch's
Effective Java that I haven't read in a while...

   michael





______________________________________________________________________
The Novartis email address format has changed to 
firstname.lastname at novartis.com.  Please update your address book 
accordingly.
______________________________________________________________________


More information about the biojava-dev mailing list