statgen / locuszoom

A Javascript/d3 embeddable plugin for interactively visualizing statistical genetic data from customizable sources.
https://statgen.github.io/locuszoom/
MIT License
154 stars 29 forks source link

Data Source Updates #53

Closed MrFlick closed 8 years ago

MrFlick commented 8 years ago

This request adds some new features to the data sources for the API.

First, it incorporates the new Recombination Rate API endpoint. On the demo page, this data can be accessed via

 demo_instance.lzd.
      getData(demo_instance.state, ["recomb:position", "recomb:recomb_rate"]).
      then(console.log.bind(console)).done();

Secondly, there is now a data class for Static data. You can add static sources like this

data_sources.addSource("hello", ["StaticJSON", {a:[1,2,3], b:[4,5,6], c:[7,8,9]}])
data_sources.addSource("bye", ["StaticJSON", [{a:1, c:7},{a:2, c:8},{a:3, c:9}]])

and then retrieve the data with

demo_instance.lzd.
    getData(demo_instance.state, ["hello:a", "hello:c|neglog10"]).
     then(console.log.bind(console)).done();
demo_instance.lzd.
     getData(demo_instance.state, ["bye:a", "bye:c|neglog10"]).
     then(console.log.bind(console)).done();

This method accepts either arrays of named objects, or a named object of arrays. It allows for the application of transformations as indicated by this example

Finally, the code required to create a new Data Source has been streamlined. There is now the

LocusZoom.Data.Source.extend()

function which takes a constructor (and an optional unique ID for serialization) and sets up all the prototypes correctly for the object. There is now also a default parseResponse() method that takes care of copying over names with the proper namespace and applying transformations. This should make it much easier to create custom data sources.

Frencil commented 8 years ago

All looks good! Merging.