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
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							109 lines
						
					
					
						
							4.3 KiB
						
					
					
				| {% extends "base.html" %} | |
| {% block content %} | |
|     <link rel="stylesheet" | |
|           href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/styles/default.min.css"> | |
|     <script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/highlight.min.js"></script> | |
|     <script>hljs.highlightAll();</script> | |
|     <h1>Admin Dashboard</h1> | |
|     <article> | |
|         <p>Logged in as {{user}}</p> | |
|         <a href="{{url_for('chemical_create')}}"> | |
|             <button> | |
|                 Add a Chemical | |
|             </button> | |
|         </a> | |
|         <a href="{{url_for('batch_add_request')}}"> | |
|             <button> | |
|                 Batch Add Chemicals | |
|             </button> | |
|         </a> | |
|         <a href="{{url_for('batch_query_request')}}"> | |
|             <button> | |
|                 Batch Search Chemicals | |
|             </button> | |
|         </a> | |
|         <h2>Admin Authentication</h2> | |
|         <p> | |
|             Since there is now an admin, only admins can create new admin accounts. You can do so through the <code>/admin/create</code> | |
|             route. | |
|         </p> | |
|         <h2>API Routes</h2> | |
|         <ul> | |
|             <li><code>/chemical/all</code> - returns all chemicals in the database as JSON</li> | |
|             <li><code>/chemical/search</code> - returns JSON for search queries. This endpoint takes GET parameters as follows: | |
|                 <ul> | |
|                     <li>mz_min: Minimum M/Z Ratio</li> | |
|                     <li>mz_max: Maximum M/Z Ratio</li> | |
|                     <li>rt_min: Minimum Retention Time</li> | |
|                     <li>rt_max: Maximum Retention Time</li> | |
|                 </ul> | |
|             </li> | |
|             <li><code>/chemical/<chemical id>/{view,update,delete}</code> - CRUD endpoints for chemicals.</li> | |
|         </ul> | |
|         <h2>Programmatically adding Chemicals</h2> | |
|         <p> | |
|             You need admin credentials to access the <code>/chemical/create</code> endpoint, so using an HTTP library | |
|             like python's requests library is highly recommended for keeping track of session cookies. | |
|         </p> | |
|         <pre><code class="language-python"> | |
| import requests | |
| session = requests.session() | |
| baseurl = "chemicaldb.teidkim.me" | |
| session.post(baseurl + "/admin/login", {"username": (username), "password": (password)}) | |
| fields = { | |
|     "chemical_db_id": <db id from another database>, | |
|     "library": (library, is a string), | |
|     "person_name": (name of person who uploaded, string) | |
|     # name, formula, and mass are required fields! | |
|     "metabolite_name": (name of the chemical, is a string), | |
|     "formula": (molecular formula, is a string), | |
|     "mass": (monoisotopic mass, is a float), | |
|     "pubchem_cid": <string>, | |
|     "pubmed_refcount": <integer> | |
|     "standard_class": <string> | |
|     "inchikey": <string>, | |
|     "inchikey14": <string>, | |
|     # final_mz and final_rt are required fields! | |
|     "final_mz": (m/z ratio after experiment, is a float), | |
|     "final_rt": (retention time after experiment, is a float), | |
|     "final_adduct": <string>, | |
|     "final_adduct": <string>, | |
|     "detected_adducts": <string>, | |
|     "adduct_calc_mz": <string>, | |
|     "msms_detected": <string if yes, do not include this field otherwise> | |
|     "msms_purity": <float> | |
|     "date": "YYYY-MM-DD" | |
| } | |
| session.post(baseurl + "/chemical/create", fields) | |
|         </code></pre> | |
|     <h2>Programmatically Searching For Matching Compounds</h2> | |
|     <pre><code class="language-python"> | |
| import requests | |
| baseurl = "chemicaldb.teidkim.me" | |
| # initialize parameters | |
| 
 | |
| def generate_parameters(mz, mz_range_ppm, rt, rt_range): | |
|     return dict( | |
|       mz_min=(mz - mz_range_ppm/10**6), | |
|       mz_max=(mz + mz_range_ppm/10**6), | |
|       rt_min=(rt - rt_range), | |
|       rt_max=(rt + rt_range) | |
|     ) | |
| 
 | |
| mz = < theoretical mz ratio > | |
| mz_range_ppm = <threshold the mz value should be in ppm units> | |
| rt = < theoretical retention time > | |
| rt_range = < seconds in which the rt needs to be in > | |
| 
 | |
| # make a request to the endpoint. | |
| response = requests.get(baseurl + "/chemical/search", params=generate_parameters(mz, mz_range_ppm, rt, rt_range)) | |
| # make sure to include some error handling code. | |
| results = response.json() | |
| 
 | |
| # results is a json containing a list of chemicals with the same schema as above. | |
| # There are up to 10 search results per query, so you should write some code to | |
| # determine which result is best. | |
|     </code></pre> | |
| 
 | |
|     </article> | |
| {% endblock %}
 |