GenSpectrum / cov-spectrum-website

A web platform to detect and analyze variants of SARS-CoV-2
https://cov-spectrum.org
GNU General Public License v3.0
59 stars 13 forks source link

ENH: Allow export/import of collections as JSON or YAML #596

Open corneliusroemer opened 1 year ago

corneliusroemer commented 1 year ago

I was wondering if it was possible to save the work we do on collections in case something happens, e.g. compromised password or outage etc.

Once export works, one could also do import.

That may also open the door to auto-generated collections, e.g. one could quickly programatically create a collection for all pango lineages etc.

chaoran-chen commented 1 year ago

That's already possible through the API. I just have to document it.

Don't worry about losing the data. I maintain daily backups.

corneliusroemer commented 1 year ago

Excellent, thanks :)

murallcl commented 1 year ago

Hi all, would it be possible to have these Collections tables downloadable as a csv right off the page? e.g. you choose a baseline, it generates the table, and then you can export it with a csv button? thanks

chaoran-chen commented 1 year ago

Regarding importing/updating a collection, let me just document the API here for now because it still might be changed.

After creating a collection, it can be updated by sending a PUT request to the following URL:

https://cov-spectrum.org/api/v2/resource/collection/<collection ID>?adminKey=<admin key>

with the following body:

{
    "id": ...,
    "title": "...",
    "description": "...",
    "maintainers": "...",
    "email": "...",
    "variants":
    [
        {
            "name": "...",
            "description": "...",
            "highlighted": false,
            "query": "{\"aaMutations\":[\"S:S371F\", \"S:Q498R\"],\"nucMutations\":[],\"aaInsertions\":[],\"nucInsertions\":[],\"nextcladePangoLineage\":\"BA.4*\"}",
        },
        {
            "name": "...",
            "description": "...",
            "highlighted": false,
            "query": "{\"variantQuery\":\"nextcladePangoLineage:BA.5*\"}",
        },
    ]
}

The highlighted field corresponds to the star. The query field contains a JSON as string. It defines either a normal search and can have the fields aaMutations, nucMutations, aaInsertions, nucInsertions, pangoLineage, nextcladePangoLineage, and nextstrainClade (does not need to have all the fields). Or it defines an advanced search, then it has only the field variantQuery.

murallcl commented 1 year ago

Hi all, would it be possible to have these Collections tables downloadable as a csv right off the page? e.g. you choose a baseline, it generates the table, and then you can export it with a csv button? thanks

Thanks for add this feature! :)

chaoran-chen commented 1 year ago

@murallcl, thanks for suggesting it!