Coder Social home page Coder Social logo

Comments (1)

edeutsch avatar edeutsch commented on July 25, 2024

After pondering this for a while and playing with various options, here's what I suggest. We can support two modes, a synchronous mode where the final answer is transmitted as one object when everything is ready. This is the traditional way of doing things. For your example query above, it might look like this:

{ 
    "query": "/psms?resultType=compact&accession=PXD005942"
    "responses": [
        {
            "source": "PeptideAtlas",
            "code": 200
            "elapsed_seconds": 5.2322
            "psms": [
                {
                    "peptideSequence": "LSSPATLNSR",
                    "usi": "mzspec:PXD005942:030219_ywt_sf-39:scan:10:LSSPATLNSR/2",
                },
                {
                    "peptideSequence": "APLVCLPVFVSR",
                    "usi": "mzspec:PXD005942:030219_ywt_sf-39:scan:120:APLVC[Carbamidomethyl]LPVFVSR/2",
                }
            ]
        },
        {
            "source": "PRIDE":
            "code": 200,
            "elapsed_seconds": 1.3243
            "psms": [
                {
                    "peptideSequence": "LSSPATLNSR",
                    "usi": "mzspec:PXD005942:030219_ywt_sf-39:scan:10:LSSPATLNSR/2",
                }
            ]
        },
        {
            "source": "MassIVE"
            "code": 404,
            "elapsed_seconds": 0.2342
            "message": "PSMs for PXD005942 not available"
        },
        {
            "source": "jPOST"
            "code": 0,
            "message": "Timed out after 30 seconds"
            "elapsed_seconds": 30.0000
        }
    ]
}

This would not arrive until 30 seconds (the timeout) has elapsed but the returned result is a single JSON object.

The second, fancy way is to stream objects as they become available with a special final object to signal that the stream is done. this might be:

{
    "source": "MassIVE"
    "code": 404,
    "elapsed_seconds": 0.2342
    "message": "PSMs for PXD005942 not available"
}
{
    "source": "PRIDE"
    "code": 200,
    "elapsed_seconds": 1.3243
    "psms": [
        {
            "peptideSequence": "LSSPATLNSR",
            "usi": "mzspec:PXD005942:030219_ywt_sf-39:scan:10:LSSPATLNSR/2",
        }
    ]
}
{ 
    "source": "PeptideAtlas",
    "code": 200,
    "elapsed_seconds": 5.2322
    "psms": [
        {
            "peptideSequence": "LSSPATLNSR",
            "usi": "mzspec:PXD005942:030219_ywt_sf-39:scan:10:LSSPATLNSR/2",
        },
        {
            "peptideSequence": "APLVCLPVFVSR",
            "usi": "mzspec:PXD005942:030219_ywt_sf-39:scan:120:APLVC[Carbamidomethyl]LPVFVSR/2",
        }
    ]
}
{
    "responses": {
        "PeptideAtlas": {
            "code": 200,
            "elapsed_seconds": 5.2322
        },
        "PRIDE": {
            "code": 200,
            "elapsed_seconds": 1.3243
        }
        "MassIVE": {
            "code": 404,
            "message": "PSMs for PXD005942 not available"
            "elapsed_seconds": 0.2342
        }
        "jPOST": {
            "code": 0,
            "message": "Timed out after 30 seconds"
            "elapsed_seconds": 30.0000
        }
    }
}

The objects are transmitted as they become available. Unlike the way they are depicted above, objects do not contain newlines, but are separated by newlines. If an object contains "source" then it is a new transmitted result. If the object contains "responses" then the client knows that that is the final object and it can stop reading from the stream. This allows the first results to be available in seconds with late results trickling in later. This latter model is what we currently use for this page:
http://proteomecentral.proteomexchange.org/PROXI.php
to pleasing effect. You can see the raw stream that the client uses here:
http://proteomecentral.proteomexchange.org/cgi/PROXI_status

The client chooses which model they want to use: complete response or streamed objects. either way, the responses from each source are the same and can be accessed with the same code. The content of "psms" is what we current return with /psms

The only snag is that this model vastly different than the current /psms. I wanted them to be the same.

To make them compatible, we'd need to think about this some more, but I'm out of time for now..

from proxi-schemas.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.