[Biojava-l] Problem with serialisation of Markov Models
Schreiber, Mark
mark.schreiber@agresearch.co.nz
Thu, 11 Jul 2002 09:41:19 +1200
Hi -
The problem here is that Markov Models have there own custom state
alphabets that inherit from AbstractAlphabet. AbstractAlphabet has a
readResolve method for reconstructing alphabets when they are
deserialized:
/**
* To prevent duplication of a what should be a
* single instance of an existing alphabet. This method
* was written as protected so that subclasses even from
* other packages will inherit it. It should only be overridden
* with care.
*/
protected Object readResolve() throws ObjectStreamException{
try{
return AlphabetManager.alphabetForName(this.getName());
}catch(NoSuchElementException nse){
//a custom alphabet has been sent to your VM, register it.
AlphabetManager.registerAlphabet(this.getName(), this);
return this;
}
}
As the method states it attempts to prevent duplication of what should
be a singleton alphabet on a VM. Normally the AlphabetManager can sort
this out except that the MarkovModel state alphabets have no name hence
the null pointer exception.
Three possible solutions exist:
1. Give the SimpleMarkovModel (from which everything inherits)
state alphabet a name and modify the
AlphabetManager.alphabetForName() method to deal with it.
2. Mark the SimpleMarkovModel state alphabet as transient and make
custom serialization methods to rebuild it.
3. Serialize to XML via the XmlMarkovModel class (in which case
SimpleMarkovModel should not be tagged as Serializable).
Currently number 3 works quite well but doesn't allow for RMI etc. It
can also require the writing of wrapper classes if you particular model
has special features.
Solution 2 is probably the way to go. Does anyone have any cunning ideas
on how such a state alphabet may be serialized (without duplicating the
alphabet in the VM). Or does it really matter if the Alphabet gets
duplicated? The equals method will fail after serialization which could
be a problem.
- Mark
> -----Original Message-----
> From: Lachlan Coin [mailto:lc1@sanger.ac.uk]
> Sent: Thursday, 11 July 2002 2:44 a.m.
> To: biojava-l@biojava.org
> Subject: [Biojava-l] Problem with serialisation of Markov Models
>
>
> Hi,
>
> I am trying to use serialisation to write a ProfileHMM to
> disk and then to read it from disk. However, I get the
> following error in reading the object from the disk when I write:
>
> ProfileHMM model = (ProfileHMM) p.readObject();
>
>
> java.lang.NullPointerException
> at org.biojava.bio.symbol.AlphabetManager.alphabetForName
> (AlphabetManager.java:148) (pc 20)
> at org.biojava.bio.symbol.AbstractAlphabet.readResolve
> (AbstractAlphabet.java:76) (pc 4)
> at java.lang.reflect.Method.invoke (Method.java)
> at java.io.ObjectStreamClass.invokeMethod
> (ObjectStreamClass.java:1615) (pc 5)
> at
> java.io.ObjectInputStream.readObject(boolean)
> (ObjectInputStream.java:393) (pc ...
>
>
>
> This suggests that alphabet embedded in my ProfileHMM object
> hasn't been correctly written to disk somehow, even though
> the in-memory version
> works fine? Any ideas?
>
> Thanks very much,
>
> Lachlan
>
>
> _______________________________________________
> Biojava-l mailing list - Biojava-l@biojava.org
> http://biojava.org/mailman/listinfo/biojava-l
>
=======================================================================
Attention: The information contained in this message and/or attachments
from AgResearch Limited is intended only for the persons or entities
to which it is addressed and may contain confidential and/or privileged
material. Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by persons or
entities other than the intended recipients is prohibited by AgResearch
Limited. If you have received this message in error, please notify the
sender immediately.
=======================================================================