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

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