NAME
Bio::JBrowse::Store::NCList::ArrayRepr - compact array-based serialization of hashrefs
DESCRIPTION
The ArrayRepr class is
for
operating on indexed representations of objects.
For example,
if
we have a lot of objects
with
similar attributes, e.g.:
[
{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},
...
]
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
<attribute name>: 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
(
"proto"
)
with
default
values
for
all objects in the set
In the end, we get something like this:
classes = [
{
"attributes"
: [
"start"
,
"end"
,
"subfeatures"
],
"proto"
: {
"Chrom"
:
"chr1"
},
"isArrayAttr"
: {
"Subfeatures"
: true }
}
]
That's what this class facilitates.
AUTHOR
Robert Buels <rbuels@gmail.com>
COPYRIGHT AND LICENSE
This software is copyright (c) 2013 by Robert Buels.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.