Class ArrayRepr
Defined in: ArrayRepr.js.
Constructor Attributes | Constructor Name and Description |
---|---|
ArrayRepr(classes)
Class for operating on indexed array representations of objects.
|
Method Attributes | Method Name and Description |
---|---|
Returns fast pre-compiled getter and setter functions for use with
Arrays that use this representation.
|
|
construct(self, obj, klass)
|
|
get(obj, attr)
|
|
makeFastGetter(attr)
|
|
makeFastSetter(attr)
|
|
makeGetter(attr)
|
|
makeSetter(attr)
|
|
set(obj, attr, val)
|
Class Detail
ArrayRepr(classes)
Class for operating on indexed array representations of objects.
For example, if we have a lot of objects with similar attrbutes, e.g.:
: true mappings
for each attribute that is meant to be an array.
Also, in cases where some attribute values are the same for all objects
in a particular set, it may be convenient to define a "prototype"
with default values for all objects in the set
In the end, we get something like this:
[ {start: 1, end: 2, strand: -1}, {start: 5, end: 6, strand: 1}, ... ]we can represent them more compactly (e.g., in JSON) something like this:
class = ["start", "end", "strand"] [ [1, 2, -1], [5, 6, 1], ... ]If we want to represent a few different kinds of objects in our big list, we can have multiple "class" arrays, and tag each object to identify which "class" array describes it. For example, if we have a lot of instances of a few types of objects, like this:
[ {start: 1, end: 2, strand: 1, id: 1}, {start: 5, end: 6, strand: 1, id: 2}, ... {start: 10, end: 20, chunk: 1}, {start: 30, end: 40, chunk: 2}, ... ]We could use the first array position to indicate the "class" for the object, like this:
classes = [["start", "end", "strand", "id"], ["start", "end", "chunk"]] [ [0, 1, 2, 1, 1], [0, 5, 6, 1, 2], ... [1, 10, 20, 1], [1, 30, 40, 1] ]Also, if we occasionally want to add an ad-hoc attribute, we could just stick an optional dictionary onto the end:
classes = [["start", "end", "strand", "id"], ["start", "end", "chunk"]] [ [0, 1, 2, 1, 1], [0, 5, 6, 1, 2, {foo: 1}] ]Given that individual objects are being represented by arrays, generic code needs some way to differentiate arrays that are meant to be objects from arrays that are actually meant to be arrays. So for each class, we include a dict with
classes=[ {'attributes': ['Start', 'End', 'Subfeatures'], 'proto': {'Chrom': 'chr1'}, 'isArrayAttr': {Subfeatures: true}} ]That's what this class facilitates.
- Parameters:
- classes
Method Detail
{Object}
accessors()
Returns fast pre-compiled getter and setter functions for use with
Arrays that use this representation.
When the returned
get
and set
functions are
added as methods to an Array that contains data in this
representation, they provide fast access by name to the data.
var accessors = attrs.accessors(); var feature = get_feature_from_someplace(); feature.get = accessors.get; // print out the feature start and end console.log( feature.get('start') + ',' + feature.get('end') );
- Returns:
- {Object}
{ get: function() {...}, set: function(val) {...} }
construct(self, obj, klass)
- Parameters:
- self
- obj
- klass
get(obj, attr)
- Parameters:
- obj
- attr
makeFastGetter(attr)
- Parameters:
- attr
makeFastSetter(attr)
- Parameters:
- attr
makeGetter(attr)
- Parameters:
- attr
makeSetter(attr)
- Parameters:
- attr
set(obj, attr, val)
- Parameters:
- obj
- attr
- val