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.

123 lines
4.6 KiB

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