You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

108 lines
4.2 KiB

{% extends "base.html" %}
{% block content %}
<link rel="stylesheet"
href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/styles/default.min.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/highlight.min.js"></script>
<script>hljs.highlightAll();</script>
<h1>Admin Dashboard</h1>
<article>
<p>Logged in as {{user}}</p>
<a href="{{url_for('chemical_create')}}">
<button>
Add a Chemical
</button>
</a>
<a href="{{url_for('batch_add_request')}}">
<button>
Batch Add Chemicals
</button>
</a>
<a href="{{url_for('batch_query_request')}}">
<button>
Batch Search Chemicals
</button>
</a>
<h2>Admin Authentication</h2>
<p>
Since there is now an admin, only admins can create new admin accounts. You can do so through the <code>/admin/create</code>
route.
</p>
<h2>API Routes</h2>
<ul>
<li><code>/chemical/all</code> - returns all chemicals in the database as JSON</li>
<li><code>/chemical/search</code> - returns JSON for search queries. This endpoint takes GET parameters as follows:
<ul>
<li>mz_min: Minimum M/Z Ratio</li>
<li>mz_max: Maximum M/Z Ratio</li>
<li>rt_min: Minimum Retention Time</li>
<li>rt_max: Maximum Retention Time</li>
</ul>
</li>
<li><code>/chemical/&lt;chemical id&gt;/{view,update,delete}</code> - CRUD endpoints for chemicals.</li>
</ul>
<h2>Programmatically adding Chemicals</h2>
<p>
You need admin credentials to access the <code>/chemical/create</code> endpoint, so using an HTTP library
like python's requests library is highly recommended for keeping track of session cookies.
</p>
<pre><code class="language-python">
import requests
session = requests.session()
baseurl = "chemicaldb.teidkim.me"
session.post(baseurl + "/admin/login", {"username": (username), "password": (password)})
fields = {
"chemical_db_id": &lt;db id from another database&gt;,
"library": (library, is a string),
# name, formula, and mass are required fields!
"name": (name of the chemical, is a string),
"formula": (molecular formula, is a string),
"mass": (monoisotopic mass, is a float),
"pubchem_cid": &lt;string&gt;,
"pubmed_refcount": &lt;integer&gt;
"standard_class": &lt;string&gt;
"inchikey": &lt;string&gt;,
"inchikey14": &lt;string&gt;,
# final_mz and final_rt are required fields!
"final_mz": (m/z ratio after experiment, is a float),
"final_rt": (retention time after experiment, is a float),
"final_adduct": &lt;string&gt;,
"final_adduct": &lt;string&gt;,
"detected_adducts": &lt;string&gt;,
"adduct_calc_mz": &lt;string&gt;,
"msms_detected": &lt;string if yes, do not include this field otherwise&gt;
"msms_purity": &lt;float&gt;
"date": "YYYY-MM-DD"
}
session.post(baseurl + "/chemical/create", fields)
</code></pre>
<h2>Programmatically Searching For Matching Compounds</h2>
<pre><code class="language-python">
import requests
baseurl = "chemicaldb.teidkim.me"
# initialize parameters
def generate_parameters(mz, mz_range_ppm, rt, rt_range):
return dict(
mz_min=(mz - mz_range_ppm/10**6),
mz_max=(mz + mz_range_ppm/10**6),
rt_min=(rt - rt_range),
rt_max=(rt + rt_range)
)
mz = &lt; theoretical mz ratio &gt;
mz_range_ppm = &lt;threshold the mz value should be in ppm units&gt;
rt = &lt; theoretical retention time &gt;
rt_range = &lt; seconds in which the rt needs to be in &gt;
# make a request to the endpoint.
response = requests.get(baseurl + "/chemical/search", params=generate_parameters(mz, mz_range_ppm, rt, rt_range))
# make sure to include some error handling code.
results = response.json()
# results is a json containing a list of chemicals with the same schema as above.
# There are up to 10 search results per query, so you should write some code to
# determine which result is best.
</code></pre>
</article>
{% endblock %}