Closed LelandBarnard closed 6 years ago
I think this should work:
var data = JSON.parse(input_assoc_json);
data.forEach(function(d) { d.id = d.variant; delete d.variant; });
my_data_sources.add('assoc', ['StaticJSON', data]);
That forEach
is necessary because StaticJSON
doesn't have a params:
field.
LocusZoom often modifies data that you pass in, so if you need another copy of that data, do a separate JSON.parse(input_assoc_json)
to get it.
Thanks! I think this will be exactly what I need.
StaticJSON is a great choice if the data is directly embedded in the page.
Related to this: if your data is a separate JSON file, and already in the exact format required by AssociationLZ
, you can alternately use the URL of the JSON file with the AssociationLZ
data source directly. This is how the [index.html offline mode] works, for example.
Anyway, I notice that you've reopened the ticket- can we help with anything?
This approach works well for the association results data, however when I try to use the same approach for the LD data and the genes data, I receive some errors. When I try
var ld_data = JSON.parse(input_ld_json);
var genes_data = JSON.parse(input_genes_json);
my_data_sources.add('ld', ['StaticJSON', ld_data]);
my_data_sources.add('gene', ['StaticJSON', genes_data]);
I receive the following errors: On the Association panel "field state not found in ld:state" and on the Genes panel, "field gene not found in gene:gene"
My LD and Gene data JSON objects have the following format:
ld_data
{"data":{ "variant2": [...], "chromosome2": [...], "position2": [...], "rsquare": [...]}, "lastpage": null }
genes_data
{"data": [{ "gene_id": <id>, "gene_name": <name>,"chromosome": "chr<n>", "start": <startPos>, "end": endPos, "strand": "+","transcripts": [ { "transcript_id": <t_id>, "transcript_name": <t_name>, "start": <t_startPos>, "end": <t_endPos>, "exons": [{"exon_id": <e_id>, "start": <e_startPos>, "end": <e_endPos>}] } ] }], "lastpage": null }
When I inspect the elements of the plot, the data appears to be loaded into the DataSources
object correctly, however in the plot
object the data
fields of the panel.datalayer
objects are empty arrays.
This is a good question!
The short answer is that some data sources are more interchangeable than others, and the file-approach may help you in those cases. Both GeneLZ
and LDLZ
perform some additional transformations on the data that come back from the server.
Essentially, this means that gene and LD layers can't take a blob of raw JSON directly- they depend on the extra payload logic of our custom data sources. This is, generally speaking, on our radar for the future.
I see, thanks for being so responsive. It sounds like for the time being we should try to reroute things to read in from local files.
I see, thanks for being so responsive. It sounds like for the time being we should try to reroute things to read in from local files.
Looking forward to seeing if this worked!
Closing this ticket for now, but free to reopen if the local-file option didn't work for your needs.
I am trying to figure out a way to pass data to a LocusZoom plot as a string, rather than giving it a url to fetch the data. Essentially, I would just like to pass the file contents manually, so I am looking for something like
var input_assoc_json = <get association.json file content from somewhere>; my_data_sources.add("assoc", ["AssociationLZ, {data: input_assoc_json}, params: {id_field: "variant}}]);
Does LocusZoom have some means to accomplish this?