[Biococoa-dev] Annotation
Alexander Griekspoor
mek at mekentosj.com
Mon Feb 21 14:45:55 EST 2005
> * do we need a BCFeature class? do we need a BCFeatureSet class?
> Probably only the latter. It seems the bsml format would require a
> BCFeatureSet class which could not be broken down into BCFeature
> elements, because it has a nested structure. If any of you has
> experience with data structures for xml, speak up!
Yes sir, well in fact I would strongly suggest that we make BOTH a
BCAnnotation AND a BCFeature class. In thought of the way BSML nicely
described a feature as a special, position related, annotation, I would
make BCFeature a subclass of a more general BCAnnotation class. It
would only have to implement in addition the position specific methods.
Now why do I want that? Because I've just seen how much better it is to
have an cocoa object instead of fetching it from a plist. It offers so
many advantages that I could throw away half of my code in EnzymeX a
week ago ;-)
An example, in EnzymeX I have 600 enzymes of which the data is in a
plist. I was fetching all of it again and again from the ordinary
dictionary instantiated from the plist. Say I wanted to have a button
colored based on the average efficiency of Enzyme X in Buffer A from
Manufacturer B. Do you know how many times I had to call
"objectForKey:"? Well many many times.
Now what I do is parse the plist once into custom enzyme objects and
just call colorForBuffer: buf ofManufacturer: man... the logic is in
the enzyme class and it knows how to calculate the efficiency and
return an NSColor object: just to give you an idea what this means for
your controller class:
BEFORE:
lEff = ([[[amershamDict objectForKey: @"L"] objectAtIndex: 0]
floatValue]+
[[[amershamDict objectForKey: @"L"] objectAtIndex: 1]
floatValue]) / 2;
// L
lColor = [NSColor colorWithCalibratedRed: [[minColorArray
objectAtIndex: 0] floatValue] -
([[colorRangeArray objectAtIndex: 0] floatValue] * (lEff/100))
green: [[minColorArray
objectAtIndex: 1] floatValue] -
([[colorRangeArray objectAtIndex: 1] floatValue] * (lEff/100))
blue: [[minColorArray
objectAtIndex: 2] floatValue] -
([[colorRangeArray objectAtIndex: 2] floatValue] * (lEff/100))
alpha: 1.0];
[amershamBufferL setBackgroundColor: lColor];
if ([[[amershamDict objectForKey: @"L"] objectAtIndex: 0] intValue]
== 100){
[amershamBufferL setStringValue: @"100%"];
}else if ([[[amershamDict objectForKey: @"L"] objectAtIndex: 0]
intValue] ==
[[[amershamDict objectForKey: @"L"] objectAtIndex: 1]
intValue]){
[amershamBufferL setStringValue: [NSString stringWithFormat:
@"%d\%%",
[[[amershamDict objectForKey: @"L"] objectAtIndex: 0]
intValue]]];
}
else {
[amershamBufferL setStringValue: [NSString stringWithFormat:
@"%d-%d\%%",
[[[amershamDict objectForKey: @"L"] objectAtIndex: 0]
intValue],
[[[amershamDict objectForKey: @"L"] objectAtIndex: 1]
intValue]]];
}
BECAME:
[amershamBufferL setBackgroundColor: [maincontroller
colorForPercentage: [enz efficiencyForBuffer: @"L" ofCompany:
@"Amersham"]]];
[amershamBufferL setStringValue: [enz efficiencyStringForBuffer: @"L"
ofCompany: @"Amersham"]];
And this about 40 times.... It also centralizes the code to for
instance calculate the color at one place (the enzyme class).
But that's not all, for instance, just to call
[enzymeX forwardSequence]
instead of
[[[dict objectForKey: enzyme] objectForKey: @"sequence"] objectForKey:
@"forwardsequence"];
is a dream come true...
Finally, think of sorting for a moment, how do you for instance sort
all features ranked on position?
With the plain dictionary approach you need to do all this in a
controller object, enumerating, comparing etc
In the object approach: simply call [myarrayofenzymes
sortUsingSelector: @selector(sortOnPositionAscending:)];
The actual sortOnPositionAscending method in the class would be three
lines of code.
Simple, clean, brilliant...
If we want flexibility, we should go for an annotation and feature
(sub)class IMHO,
Cheers,
Alex
Ps. Remember these can still be kept in the dictionary with a key!
i.e. in EnzymeX I store all enzyme object in a dictionary with the
enzyme name as its key. that way I still can get all enzyme names with
a simple [enzymeDict allKeys]; instead of enumerating the whole thing
again and again...
>
> charles
>
> --
> Help science go fast forward:
> http://cmgm.stanford.edu/~cparnot/xgrid-stanford/
>
> Charles Parnot
> charles.parnot at stanford.edu
>
> Room B157 in Beckman Center
> 279, Campus Drive
> Stanford University
> Stanford, CA 94305 (USA)
>
> Tel +1 650 725 7754
> Fax +1 650 725 8021
> _______________________________________________
> Biococoa-dev mailing list
> Biococoa-dev at bioinformatics.org
> https://bioinformatics.org/mailman/listinfo/biococoa-dev
>
>
*********************************************************
** 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.
*********************************************************
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: text/enriched
Size: 7454 bytes
Desc: not available
URL: <http://www.bioinformatics.org/pipermail/biococoa-dev/attachments/20050221/a4632d81/attachment.bin>
More information about the Biococoa-dev
mailing list