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

How do I convert LD-files( tsv format) to Json? #154

Closed songtaogui closed 5 years ago

songtaogui commented 5 years ago

Hi,

I have LD file formated like: snp1 snp2 D-prime R2 And how could I convert the LD file to json format? I have read the staticdata/ld_10_114550452-115067678.json, and found that their are only infomation for variant2:

{
    "data":{
        "variant2":Array[14840],
        "chromosome2":Array[14840],
        "position2":Array[14840],
        "rsquare":Array[14840]
    },
    "lastPage":null
}

Should there also be infomation for variant1 ?

Thanks!

SongtaoGui

abought commented 5 years ago

Thanks for the question. The documentation hints at this, but not very clearly.

When we request LD from our server, we are usually doing so with respect to a "reference variant" (automatically chosen as the most significant p value in the displayed region).

What this means in practice is that variant1 is always the same value (as shown in query string below), and we're omitting it from our payloads to save space.

Sample API url: https://portaldev.sph.umich.edu/api/v1/pair/LD/results/?filter=reference eq 1 and chromosome2 eq '10' and position2 ge 114550452 and position2 le 115067678 and variant1 eq '10:114758349_C/T'&fields=chr,pos,rsquare

It might be possible to use LD calculated according to different assumptions, but you'd probably have to write a fair bit of custom code to use and display it cleanly.

songtaogui commented 5 years ago

Thank you for the kindly help.

I have learned that LocusZoom allows users to change LD ref snps. My understanding was that when variant1 changes, we need to re-calculate variant2 R2 to creat a new json file. So, how could I format the whole LD data to LocusZoom so it can extract variant2 LD based on user selected variant1, and which script of LocusZoom does that?

Thank you ! Best wishes.

abought commented 5 years ago

Changing reference SNPs is indeed a feature of LocusZoom.js. However, in any web application, we try to avoid sending all possible to the browser at once.

There are a few possible approaches, depending on the size of your task and how comfortable you are writing custom code here.

  1. In theory, you could create an entire directory of LD files, and write a small bit of javascript to fetch the correct JSON file whenever the refvar is changed. However, this wouldn't scale very well across genomic regions- you'd find yourselves with quite a lot of files!
  2. For all of our own LocusZoom sites, we have a special RESTful API server that calculates LD on the fly. It's new, but my colleagues have put real effort into making it reusable so that anyone could deploy it on their own servers with their own data: https://github.com/statgen/ldserver

Although you could put all the data into all one file, you'd be writing a lot of code for a not very optimal strategy- if deploying your own LD server is at all an option, I recommend that route.

songtaogui commented 5 years ago

Thank you for the explanation, I will use local script to fetch the JSON to LocusZoom.