[Biojava-l] Parsing exising gaps

Richard Holland holland at ebi.ac.uk
Fri Nov 16 04:49:35 EST 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

>   The returned gapped sequences are all properly set up with gaps, name etc.
> But as for other users, I think there may be some problems, since the
> SimpleAlignment object only has a general symbol list iterator, the user
> will have to cast each statement extracting a sequence object, and
> 
>       SimpleSequence aSimple = (SimpleSequence)aSequences.next();
> 
> returns an ClassCastException at run time. So old code might not run with
> the update as far as I can see.

This is true. However, such code would be unsupported by us as the API
clearly states that SimpleAlignment returns SymbolList instances, and
does not make any guarantees about the exact implementation details of
the objects it returns. To attempt to cast it to anything other than
SymbolList would be a mistake! (Although actually it is now returning a
guarantee of GappedSymbolList, which is what your code can now take
advantage of). To assume it will return SimpleSequence is outside the
behaviour defined by the API and therefore should not be relied upon.

A more correct behaviour would be to test each item returned:

	SymbolList symlist = aSequences.next();
	if (symlist instanceof SimpleSequence) {
		SimpleSequence seq = (SimpleSequence)symlist;
		// Do simple-sequence stuff
	} else {
		// Do something else!
	}

In future, I will modify the API to change the SymbolList guarantee to a
GappedSymbolList guarantee, but I can't do this right now as this really
would break everyone's code!

We are currently planning a redesign as you may be aware, so issues like
this will hopefully be resolved as part of that process. For a start, if
we use Java 5 generics in future as we plan, we can strictly specify
what kinds of objects will be returned by things such as the alignment
API, making it easier for us to enforce API-compliant behaviour in
user's code.

cheers,
Richard
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHPWev4C5LeMEKA/QRAvTOAJ9tqdBGWangZ9YQPpEDJ4WWBP/vjQCdHlMB
ITj7O/foDly4aOT4SV1Jb+k=
=g7Vs
-----END PGP SIGNATURE-----


More information about the Biojava-l mailing list