[Biococoa-dev] Re: Using annotations

Alexander Griekspoor mek at mekentosj.com
Thu Feb 24 04:51:24 EST 2005


> Suppose I want to add a BCAnnotation for an organism to the 
> annotations dictionary of BCSequence. My instinct would say to use the 
> key @"organism" and the value @"Homo Sapiens". However, if I look at 
> your code, both strings are supposed to go into a BCAnnotation object:
>
> newAnnotation = [[BCAnnotation alloc] initWithName: @"organism" 
> content: @"Homo sapiens"];

The idea was to store the annotation object in a mutable dictionary 
with the name as key. Yes, this duplicates the name string, but it has 
several big advantages to store the name in the object itself. For 
instance sorting. An object can't ask it's enclosing dictionary for the 
key under which it is stored. Also if you pass annotation objects 
around, you always know its name.
Well, why don't we just store it in a mutable array then? That's a 
possibility, but say I want the object with name "organism" then in an 
array we would have to enumerate it, while in a dictionary you can 
simply ask it. NSDictionary is highly optimized for this, so at the 
cost of the duplicated string I take the far higher optimization in 
return. I took the same approach for the enzyme example, and I simply 
love it. Now of course that doesn't say much if it is the best way to 
do things... ;-)
>
> Now how do I add it to the dictionary of the sequence? I already used 
> the key (organism) inside BCAnnotation, so should I use it again? If 
> yes, why is the key/name repeated inside the annotation object? This 
> is not a critisicm, because I really like the way it is set up now. I 
> am just trying to understand how it works :-)
No problem, and I can see why it sounds strange at first so criticism 
is at place here, hope it has become more clear now why I choose for 
this approach. About how to add an annotation? I still have to add that 
code to the sequence class ;-)

Something else, as I proposed to make BCFeature a subclass of 
BCAnnotation, do we want a single mutable dictionary annotations in the 
sequence class containing both, or one annotations and one features 
dict? I think the first or not?
Alex

*********************************************************
                      ** Alexander Griekspoor **
*********************************************************
                The Netherlands Cancer Institute
                Department of Tumorbiology (H4)
          Plesmanlaan 121, 1066 CX, Amsterdam
                   Tel:  + 31 20 - 512 2023
                   Fax:  + 31 20 - 512 2029
                  AIM: mekentosj at mac.com
                   E-mail: a.griekspoor at nki.nl
               Web: http://www.mekentosj.com

    The requirements said: Windows 2000 or better.
    So I got a Macintosh.

*********************************************************




More information about the Biococoa-dev mailing list