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.

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