Presentation is loading. Please wait.

Presentation is loading. Please wait.

Topics web applications Practical Biocomputing 2018 Week 12.

Similar presentations


Presentation on theme: "Topics web applications Practical Biocomputing 2018 Week 12."— Presentation transcript:

1 Topics web applications Practical Biocomputing Week 12

2 Web applications Traditional
Web server resides on a server, typically running Apache CGI, common gateway interface, applications are run on the server by Apache when requests are received Problems Apache is big and complicated Typically requires admin/superuser privileges Security issues Practical Biocomputing Week 12

3 Web applications Recent Web applications can act as their own server
Full stack frameworks. Server, database, application interface, content templating Django TurboGears web2py Other frameworks (not full stack) CherryPy bottle flask hug see Practical Biocomputing Week 12

4 Web applications CherryPy Write standard python object
Expose through a web interface using cherrypie wrapper __init__(self)? import cherrypy class seqServe(): """============================================================================================= cherrypy sequence analysis =============================================================================================""" @cherrypy.expose def home(self): return 'welcome home' # ================================================================================================== # main/testing if __name__ == '__main__': cherrypy.quickstart(seqServe()) Practical Biocomputing Week 12

5 Web applications CherryPy Run the application
Method name is the name of the web page when i go to the url i see the following in the console. Normally you would redirect this to a file to save a log C:\Users\gribs\PycharmProjects\cherry\venv\Scripts\python.exe C:/Users/gribs/PycharmProjects/cherry/ex1.py [04/Apr/2018:07:44:45] ENGINE Listening for SIGTERM. [04/Apr/2018:07:44:45] ENGINE Bus STARTING CherryPy Checker: The Application mounted at '' has an empty config. [04/Apr/2018:07:44:45] ENGINE Set handler for console events. [04/Apr/2018:07:44:45] ENGINE Started monitor thread 'Autoreloader'. [04/Apr/2018:07:44:45] ENGINE Serving on [04/Apr/2018:07:44:45] ENGINE Bus STARTED [04/Apr/2018:07:45:18] "GET /home HTTP/1.1" "" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/ (KHTML, like Gecko) Chrome/ Safari/537.36" [04/Apr/2018:07:45:18] "GET /favicon.ico HTTP/1.1" " Practical Biocomputing Week 12

6 Web applications HTML formatting
learn HTML: Don’t forget to expose the page! def query(self): """ Query form page :return: string, query html """ return """ <html> <head></head> <body> <h1>Query</h1> Enter a sequence </body> </html> """ Practical Biocomputing Week 12

7 Web applications HTML formatting Don’t forget to expose the page!
@cherrypy.expose def query(self): """ Query form page :return: string, query html """ return """ <html> <head></head> <body> <h1>Query</h1> Enter a sequence </body> </html> """ Practical Biocomputing Week 12

8 Web applications HTML add form need submit button need action
@cherrypy.expose def query(self): """ Query form page :return: string, query html """ return """ <html> <head></head> <body> <h1>Query</h1> <form> <textarea rows="4" cols="50"> Enter your sequence here in Fasta format </textarea> </form> </body> </html> """ Practical Biocomputing Week 12

9 Web applications HTML complete form
need the action method (composition) @cherrypy.expose def query(self): """ Query form page :return: string, query html """ return """ <html> <head></head> <body> <h1>Query</h1> <form action="composition"> <textarea rows="4" cols="50"> Enter your sequence here in Fasta format </textarea> <br/> <input type="submit" Value="Go"> </form> </body> </html> """ Practical Biocomputing Week 12

10 Web applications HTML Must give form inputs names to send to methods
@cherrypy.expose def query(self): """ Query form page :return: string, query html """ return """ <html> <head></head> <body> <h1>Query</h1> <form action="composition"> <textarea name="sequence" rows="4" cols="50"> Enter your sequence here in Fasta format </textarea> <br/> <input type="submit" Value="Go"> </form> </body> </html> """ Practical Biocomputing Week 12

11 Web applications HTML html parameters are named arguments to method
use method=“post” to hide values @cherrypy.expose def composition(self, sequence=''): """ Calculate and display the composition of the sequence :return: string, html page """ sequence = sequence.replace(' ','').rstrip() count = dict() for letter in sequence: try: count[letter] += 1 except KeyError: count[letter] = 1 table = '<table>\n' table += ' <tr><td>Residue</td><td>Count</td></tr>\n' for letter in sorted(count.keys()): table += ' <tr><td>{}</td><td>{}</td></tr>\n'.format(letter, count[letter]) table += '</table>' return """ <html> <head></head> <body> """ + table + """ </body> </html> """ Practical Biocomputing Week 12


Download ppt "Topics web applications Practical Biocomputing 2018 Week 12."

Similar presentations


Ads by Google