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.

98 lines
3.9 KiB

2 years ago
2 years ago
2 years ago
2 years ago
  1. {% extends "base.html" %}
  2. {% block content %}
  3. <link rel="stylesheet"
  4. href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/styles/default.min.css">
  5. <script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/highlight.min.js"></script>
  6. <script>hljs.highlightAll();</script>
  7. <h1>Admin Dashboard</h1>
  8. <article>
  9. <p>Logged in as {{user}}</p>
  10. <a href="{{url_for('chemical_create')}}">
  11. <button>
  12. Add a Chemical
  13. </button>
  14. </a>
  15. <h2>Admin Authentication</h2>
  16. <p>
  17. Since there is now an admin, only admins can create new admin accounts. You can do so through the <code>/admin/create</code>
  18. route.
  19. </p>
  20. <h2>API Routes</h2>
  21. <ul>
  22. <li><code>/chemical/all</code> - returns all chemicals in the database as JSON</li>
  23. <li><code>/chemical/search</code> - returns JSON for search queries. This endpoint takes GET parameters as follows:
  24. <ul>
  25. <li>mz_min: Minimum M/Z Ratio</li>
  26. <li>mz_max: Maximum M/Z Ratio</li>
  27. <li>rt_min: Minimum Retention Time</li>
  28. <li>rt_max: Maximum Retention Time</li>
  29. </ul>
  30. </li>
  31. <li><code>/chemical/&lt;chemical id&gt;/{view,update,delete}</code> - CRUD endpoints for chemicals.</li>
  32. </ul>
  33. <h2>Programmatically adding Chemicals</h2>
  34. <p>
  35. You need admin credentials to access the <code>/chemical/create</code> endpoint, so using an HTTP library
  36. like python's requests library is highly recommended for keeping track of session cookies.
  37. </p>
  38. <pre><code class="language-python">
  39. import requests
  40. session = requests.session()
  41. baseurl = "chemicaldb.teidkim.me"
  42. session.post(baseurl + "/admin/login", {"username": (username), "password": (password)})
  43. fields = {
  44. "chemical_db_id": &lt;db id from another database&gt;,
  45. "library": (library, is a string),
  46. # name, formula, and mass are required fields!
  47. "name": (name of the chemical, is a string),
  48. "formula": (molecular formula, is a string),
  49. "mass": (monoisotopic mass, is a float),
  50. "pubchem_cid": &lt;string&gt;,
  51. "pubmed_refcount": &lt;integer&gt;
  52. "standard_class": &lt;string&gt;
  53. "inchikey": &lt;string&gt;,
  54. "inchikey14": &lt;string&gt;,
  55. # final_mz and final_rt are required fields!
  56. "final_mz": (m/z ratio after experiment, is a float),
  57. "final_rt": (retention time after experiment, is a float),
  58. "final_adduct": &lt;string&gt;,
  59. "final_adduct": &lt;string&gt;,
  60. "detected_adducts": &lt;string&gt;,
  61. "adduct_calc_mz": &lt;string&gt;,
  62. "msms_detected": &lt;string if yes, do not include this field otherwise&gt;
  63. "msms_purity": &lt;float&gt;
  64. "date": "YYYY-MM-DD"
  65. }
  66. session.post(baseurl + "/chemical/create", fields)
  67. </code></pre>
  68. <h2>Programmatically Searching For Matching Compounds</h2>
  69. <pre><code class="language-python">
  70. import requests
  71. baseurl = "chemicaldb.teidkim.me"
  72. # initialize parameters
  73. def generate_parameters(mz, mz_range_ppm, rt, rt_range):
  74. return dict(
  75. mz_min=(mz - mz_range_ppm/10**6),
  76. mz_max=(mz + mz_range_ppm/10**6),
  77. rt_min=(rt - rt_range),
  78. rt_max=(rt + rt_range)
  79. )
  80. mz = &lt; theoretical mz ratio &gt;
  81. mz_range_ppm = &lt;threshold the mz value should be in ppm units&gt;
  82. rt = &lt; theoretical retention time &gt;
  83. rt_range = &lt; seconds in which the rt needs to be in &gt;
  84. # make a request to the endpoint.
  85. response = requests.get(baseurl + "/chemical/search", params=generate_parameters(mz, mz_range_ppm, rt, rt_range))
  86. # make sure to include some error handling code.
  87. results = response.json()
  88. # results is a json containing a list of chemicals with the same schema as above.
  89. # There are up to 10 search results per query, so you should write some code to
  90. # determine which result is best.
  91. </code></pre>
  92. </article>
  93. {% endblock %}