How To Interact with MoNA Search via cURL or Spectra Browser

General query format


Here is a cURL search request that can be sent to MoNA. MoNA utilizes the Spring Filter library to create dynamic queries. Let's dissect the following cURL command.

curl -G -H "Content-Type: application/json" --data-urlencode "query=exists(metaData.name:'ionization mode' and metaData.value:'positive')" --data-urlencode "size=10" --data-urlencode "page=1" http://mona.fiehnlab.ucdavis.edu/rest/spectra/search

1) -G ensures the cURL call is GET

2) -H "Content-Type: application/json" tells cURL to return a JSON payload.

3) --data-urlencode "query=exists(metaData.name:'ionization mode' and metaData.value:'positive')" will encode the query parameter to ensure all values of the text are passed to the backend. The query itself will be further explained later.

4) --data-urlencode "size=10" sets the JSON result size to 10 spectra. Please use size is possible! Large result sets can cause strain on the database and extend query times.

5) --data-urlencode "page=1" accesses the first page of the above size of a given result set. If the above query results in 200 total results, and you designate a size of 10 like above, you'll have 20 available pages of results.

6) http://mona.fiehnlab.ucdavis.edu/rest/spectra/search is the REST endpoint you'll contact for your searches.

How To Create Spring Filter Query


Please take some time to read the README.md from the Spring Filter project! The MoNA team has decided to use Spring Filter for all of its querying. The library allows for nested querying and provides an extensive amount of functions and operations to create custom queries.

Referencing Spectrum Objects

Spring Filter uses dot notation to reference nested objects. Let's a simplified Spectrum object for example:

                
                  {
                    "id": "MoNA000001",
                    "compound": [
                      {
                        "metaData": {"name": "InChIKey", value: "BRMWTNUJHUMWMS-LURJTMIESA-N"}
                  }
                    ],
                  "metaData": {"name": "ionization mode", value: "positive"},
                  }
                  
              

If we want to check the id value, then we reference: id

If we want to check compound metadata name, then we reference: compound.metaData.name

Or if we want to check spectrum metadata value, then we reference: metaData.value

There will be a spectrum data object on the bottom of this page for you to reference when creating queries. Simply put, you can use Javascript like dot notation to reference fields within a spectrum object for searching.

Operators

LiteralDescriptionExample
andAND Condition Between Two Expressionsid : 'MoNA000001' and metaData.name : 'positive'
orOR Condition Between Two Expressionsid : 'MoNA000001' or metaData.name : 'positive'
notNOT Condition For Given Expressionsnot (metaData.name : 'positive')
Comparators

LiteralDescriptionExample
~checks if the left (string) expression is similar to the right (string) expressionmetaData.name ~ '*ionization'
:checks if the left expression is equal to the right expressionid : MoNA000001
!checks if the left expression is not equal to the right expressioncompound.metaData.value ! 'BRMWTNUJHUMWMS-LURJTMIESA-N'
>checks if the left expression is greater than the right expressionmetaData.value > 100
>: checks if the left expression is greater or equal to the right expressionmetaData.value >: 100
<checks if the left expression is smaller than the right expressionmetaData.value < 100
<:checks if the left expression is smaller or equal to the right expressionmetaData.value <: 100
is nullchecks if an expression is nullmetaData.value is null
is not nullchecks if an expression is not nullmetaData.value is not null
is empty checks if the (collection) expression is emptycompound is empty
is not emptychecks if the (collection) expression is not emptycompound is not empty
inchecks if an expression is present in the right expressionsmetaData.value in ('positive', 'negative')
Subqueries

NameDescriptionExampleExplanation
exists returns the existence of a subquery result exists(metaData.value: 'positive' and metaData.name: 'ionization mode') returns true if metadata name is ionization mode and the value is positive

Subquries are the most important function as they allow of to query a given table multiple times. Normally, we are limited to searching each field a single time such as only being able to visit metaData.name once in a given query statement. But, with subqueries, we are able to join the metaData table multiple times and check various field values.

Subqueries allow us to perform custom queries like the following that searches for dirty spectra:

exists(metaData.name:'normalized entropy' and metaData.value>'0.8') and exists(metaData.name:'spectral entropy' and metaData.value>'3.0')

Use Query In Spectra Browser

The queries that you construct for cURL commands work exactly the same as they do in the Spectrum Browser. Simply do the following:

1) Look at the top of the page and click on Display Generated Query

2) Next to Generated Query you will see the button , click it and it will allow you to edit the field.

3) Type or copy your query into the field and then click on Update Query. This will execute the query and provide you results! In addition you'll be provided a cURL command that you can then execute on the command line.

Note: The generated cURL command will already be url encoded so it is a simple copy and paste onto the command line.
Example Spectrum Object