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.

109 lines
4.3 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. "person_name": (name of person who uploaded, string)
  57. # name, formula, and mass are required fields!
  58. "metabolite_name": (name of the chemical, is a string),
  59. "formula": (molecular formula, is a string),
  60. "mass": (monoisotopic mass, is a float),
  61. "pubchem_cid": &lt;string&gt;,
  62. "pubmed_refcount": &lt;integer&gt;
  63. "standard_class": &lt;string&gt;
  64. "inchikey": &lt;string&gt;,
  65. "inchikey14": &lt;string&gt;,
  66. # final_mz and final_rt are required fields!
  67. "final_mz": (m/z ratio after experiment, is a float),
  68. "final_rt": (retention time after experiment, is a float),
  69. "final_adduct": &lt;string&gt;,
  70. "final_adduct": &lt;string&gt;,
  71. "detected_adducts": &lt;string&gt;,
  72. "adduct_calc_mz": &lt;string&gt;,
  73. "msms_detected": &lt;string if yes, do not include this field otherwise&gt;
  74. "msms_purity": &lt;float&gt;
  75. "date": "YYYY-MM-DD"
  76. }
  77. session.post(baseurl + "/chemical/create", fields)
  78. </code></pre>
  79. <h2>Programmatically Searching For Matching Compounds</h2>
  80. <pre><code class="language-python">
  81. import requests
  82. baseurl = "chemicaldb.teidkim.me"
  83. # initialize parameters
  84. def generate_parameters(mz, mz_range_ppm, rt, rt_range):
  85. return dict(
  86. mz_min=(mz - mz_range_ppm/10**6),
  87. mz_max=(mz + mz_range_ppm/10**6),
  88. rt_min=(rt - rt_range),
  89. rt_max=(rt + rt_range)
  90. )
  91. mz = &lt; theoretical mz ratio &gt;
  92. mz_range_ppm = &lt;threshold the mz value should be in ppm units&gt;
  93. rt = &lt; theoretical retention time &gt;
  94. rt_range = &lt; seconds in which the rt needs to be in &gt;
  95. # make a request to the endpoint.
  96. response = requests.get(baseurl + "/chemical/search", params=generate_parameters(mz, mz_range_ppm, rt, rt_range))
  97. # make sure to include some error handling code.
  98. results = response.json()
  99. # results is a json containing a list of chemicals with the same schema as above.
  100. # There are up to 10 search results per query, so you should write some code to
  101. # determine which result is best.
  102. </code></pre>
  103. </article>
  104. {% endblock %}