[Bioperl-l] zero length sequence in PrimarySeq
Heikki Lehvaslaiho
heikki@ebi.ac.uk
Thu, 15 Mar 2001 10:34:43 +0000
Hilmar Lapp wrote:
>
> Heikki Lehvaslaiho wrote:
> >
> > If you reset the sequence of a PrimarySeq to a zero length after first
> > setting it to some value and you had not set moltype, method _guess_type
> > got called and threw an exception. I've now fixed it in both 07 branch and
> > main trunk by conditionally calling _guess_type only if the sequence ne ''.
> >
> > One could argue that one should always set the moltype but I think that is
> > expecting a bit too much from a casual user.
> >
> > One alternative would be for _guess_type to silently do nothing rather than
> > throw an exception.
> >
> > If you feel that some other implementation of the fix is better than the
> > one I did, feel free to change the code, but please keep the functionality.
> >
>
> I have to admit that I am not happy with this change. It renders
> the sequence object in an undetermined state, because then there
> is no way to find out what type of sequence it is, which is
> against the API definition.
>
> So, I suggest to do one of the following:
> 1) Change the API definition of moltype() such that there is an
> additional type 'unknown' allowed.
> 2) Change the code such that it retains the last active moltype if
> the sequence is reset to zero length. (This then still requires a
> moltype be supplied at initialization with a zero length seq,
> which I'm a strong supporter of.)
>
> I'd rather prefer option 2), because it seems cleaner to me, and I
> don't see the use case that really needs option 1).
>
> What do you think?
Your option 2) is the way I changed it into. The objects does keep the last
active moltype. See the code below:
-----------------------------------------
use Bio::PrimarySeq;
$a = new Bio::PrimarySeq;
print $a->seq, ": ", $a->moltype, "\n";
$a->seq('a');
print $a->seq, ": ", $a->moltype, "\n";
$a->seq('');
print $a->seq, ": ", $a->moltype, "\n";
-----------------------------------------
The output is:
----------
:
a: dna
: dna
----------
All objects need to be able to be created without any attributes set, don't
you agree? The moltype remains undef until explicitly set or seq is set.
OK?
-Heikki
> Hilmar
> --
> -----------------------------------------------------------------
> Hilmar Lapp email: hlapp@gmx.net
> GNF, San Diego, Ca. 92122 phone: +1 858 812 1757
> -----------------------------------------------------------------
>
> _________________________________________________________
> Do You Yahoo!?
> Get your free @yahoo.com address at http://mail.yahoo.com
--
______ _/ _/_____________________________________________________
_/ _/ http://www.ebi.ac.uk/mutations/
_/ _/ _/ Heikki Lehvaslaiho heikki@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
___ _/_/_/_/_/________________________________________________________