manulera / ShareYourCloning

A web application to generate molecular cloning strategies in json format, and share them with others.
MIT License
18 stars 3 forks source link

eLabFTW as a source for plasmids #8

Open NicolasCARPi opened 8 months ago

NicolasCARPi commented 8 months ago

What we want

Allow SYC to browse the Resources in eLab (such as plasmids, or primers, or dna sequences...).

How it could be done

  1. User selects "eLabFTW" as a source (similar to Addgene/Genbank source)
  2. app asks for two things: the URL of the eLabFTW instance, and an API key
  3. the app makes a request to eLab api to get a list of Resources Categories
  4. the list is displayed to the user that can pick for instance the Category: "Plasmid"
  5. the app makes a request to this category based on the search string the user input
  6. the app downloads the sequence file attached to the found entry

Caveats

The target instance needs to be configured to accept CORS requests, but this is already configurable in eLab: https://github.com/elabftw/elabimg/blob/5e44a25ef6b4e496f67273fbe50ee98100d41bbb/src/docker-compose.yml-EXAMPLE#L203-L223

The queries

To fetch a list of Resources categories:

GET /api/v2/items_types https://doc.elabftw.net/api/v2/#/Items%20types/read-items_types

To look for a particular resource, add cat=X query string to GET /api/v2/items, where X is the ID of the Category we're interested in.

To list the attached files of a Resource, GET /api/v2/items/Y, where Y is the ID of the Resource.

To fetch the binary file attached: GET /api/v2/items/Y/uploads/Z?format=binary where Z is the upload ID.

Hopefully we can get a demo working for the next Community Meeting!

NicolasCARPi commented 8 months ago

Ideally, the app is able to remember the info about URL and api key, but I'm thinking it could be loaded in an iframe or something, or the initial request can send the info in request headers, then the app can store that in the state:

X-elabftw-url: https://elab.local:3148 X-elabftw-key: 3-1293aie39219ea...

manulera commented 8 months ago

Hello @NicolasCARPi, I gave it a first go with the hard-coded url and with the API key in an env var, just to see if I managed with the elab api and so, and this is how the user flow could look. Let me know what you think (the video has sound btw)

https://github.com/manulera/ShareYourCloning/assets/22526102/843d1114-b8b2-4420-aae3-a7992a7e349f

The code is in this commit if you are interested: https://github.com/manulera/ShareYourCloning_frontend/commit/120604db1919e9f80c0815dc56454bb8e5516fad

For now it uses the uploadFile backend api endpoint, which only stores the file name, but it would make sense to record a unique identifier for the sequence file.

Would the combination item_id + file_id be a good unique identifier, or is there something better to use?

{
  "uploads": [
    {
      "id": 3,
      "real_name": "pFA6a-kanMX6.gbk",
      "long_name": "c1/c19618b4f962448111fded517e9fbbd4b66f34c164202f506936dd2258587452364a7b8defa4a5e953633a9f8c67b98c36d9fbbba6d3b2a0cdcc8c83566a4bf5.gbk",
      "comment": null,
      "item_id": 2,
      "userid": 1,
      "type": "items",
      "created_at": "2024-03-20 12:24:56",
      "hash": "c279632e7b2e529ae4a2ca62224c87516114c1c75d3a09c61581e0068bb81f2d",
      "hash_algorithm": "sha256",
      "storage": 1,
      "filesize": 9757,
      "state": 1,
      "immutable": 0,
      "fullname": "Manuel Lera Ramirez"
    }
  ]
}
NicolasCARPi commented 8 months ago

Wow great, it looks super good! :clap:

but it would make sense to record a unique identifier for the sequence file.

I'm not sure I understand what you're talking about here. Where would this unique id be found and what would be its purpose?

This is already a very good concrete example for the upcoming user meeting. Now the user should have a way to upload the result back to eLab, but you told me you wanted to stabilize the format before, right?

manulera commented 8 months ago

Hi @NicolasCARPi, yes the format is subject to change, but even for the demo we could show that the history of the cloning is stored as json in a field shareyourcloning_history, or something in those lines. All sequences are linked that shows where they come from, for example, a plasmid from addgene looks like this:

{
    "id": 1,
    "input": [],
    "output": 2,
    "type": "repository_id",
    "kind": "source",
    "info": {
        "url": "https://media.addgene.org/snapgene-media/v1.7.9-0-g88a3305/sequences/240599/4936a6ae-6b4d-4d24-b7ac-2339fad5755d/addgene-plasmid-39282-sequence-240599.gbk",
        "type": "addgene-full"
    },
    "repository": "addgene",
    "repository_id": "39282"
}

For the sequences read from eLab, a unique identifier of the file could be stored.

NicolasCARPi commented 8 months ago

unique identifier of the file could be stored

The id could simply be the URL: https://example.org/api/v2/resources/123/uploads/32. This also becomes super convenient to GET it, and it's guaranteed to be unique. You should also store the hash, like I do.

history of the cloning is stored as json in a field shareyourcloning_history

Yep, in fact in elab's metadata there is an elabftw key, so we could have a shareyourcloning key, and then whatever you want behind it. I've been meaning to add a JSON metadata to uploads, that would be a good incentive to do so quickly!

manulera commented 8 months ago

Hey @NicolasCARPi I think this could go in the demo as well, let me know what you think. I think it shows more or less how the workflow could be.

https://github.com/manulera/ShareYourCloning/assets/22526102/ac9f3c7b-5f9c-471a-bb3f-c7131c056b0b

I have created an issue in elabftw about something I noticed: https://github.com/elabftw/elabftw/issues/5006