A data retrieval workflow using NCBI E-Utils + Python Part II: Jinja2 / Flask John Pinney Tech talk Tue 19 th Nov.

Slides:



Advertisements
Similar presentations
12 October 2011 Andrew Brown IMu Technology EMu Global Users Group 12 October 2011 IMu Technology.
Advertisements

Adding Dynamic Content to your Web Site
Wrapping up our last topic: You and your (DNA) parasites Events like these, happening over and over again, have led to… Edward Marcotte/Univ. of Texas/BCH391L/Spring.
Introduction to PHP MIS 3501, Fall 2014 Jeremy Shafer
A data retrieval workflow using NCBI E-Utils + Python John Pinney Tech talk Tue 12 th Nov.
Languages for Dynamic Web Documents
BY: ALBERTO CABEZAS 4/19/2010. INTRODUCTION: PHP is considered today as one of the most famous scripting languages. PHP is widely used as a general purpose.
PHP (2) – Functions, Arrays, Databases, and sessions.
A simple PHP application We are going to develop a simple PHP application with a Web interface. The user enters two numbers and the application returns.
J4www/jea Week 3 Version Slide edits: nas1 Format of lecture: Assignment context: CRUD - “update details” JSP models.
Design of Web-based Systems IS Development: lecture 10.
Master’s course Bioinformatics Data Analysis and Tools Lecture 6: Internet Basics Centre for Integrative Bioinformatics.
Web Servers How do our requests for resources on the Internet get handled? Can they be located anywhere? Global?
Multiple Tiers in Action
INTRO TO MAKING A WEBSITE Mark Zhang.  HTML  CSS  Javascript  PHP  MySQL  …That’s a lot of stuff!
2440: 141 Web Site Administration Web Server-Side Programming Professor: Enoch E. Damson.
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
UNIT-V The MVC architecture and Struts Framework.
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
Python quick start guide
Chapter 9 Using Perl for CGI Programming. Computation is required to support sophisticated web applications Computation can be done by the server or the.
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
NETWORK CENTRIC COMPUTING (With included EMBEDDED SYSTEMS)
Introduction to PHP and Server Side Technology. Slide 2 PHP History Created in 1995 PHP 5.0 is the current version It’s been around since 2004.
Server-side Scripting Powering the webs favourite services.
Basics of Web Databases With the advent of Web database technology, Web pages are no longer static, but dynamic with connection to a back-end database.
About Dynamic Sites (Front End / Back End Implementations) by Janssen & Associates Affordable Website Solutions for Individuals and Small Businesses.
What is Architecture  Architecture is a subjective thing, a shared understanding of a system’s design by the expert developers on a project  In the.
Lecture 7 Interaction. Topics Implementing data flows An internet solution Transactions in MySQL 4-tier systems – business rule/presentation separation.
Cloud computing lectures: Programming with Google App Engine Keke Chen.
GDT V5 Web Services. GDT V5 Web Services Doug Evans and Detlef Lexut GDT 2008 International User Conference August 10 – 13  Lake Las Vegas, Nevada GDT.
OracleAS Reports Services. Problem Statement To simplify the process of managing, creating and execution of Oracle Reports.
ITIS 1210 Introduction to Web-Based Information Systems Chapter 23 How Web Host Servers Work.
USING PERL FOR CGI PROGRAMMING
Class 1Intro to Databases Goals of this class Understand the architecture behind web database applications Gain a basic understanding of what relational.
Java CGI Lecture notes by Theodoros Anagnostopoulos.
COMP3121 E-Commerce Technologies Richard Henson University of Worcester November 2011.
PHP MySQL Introduction. MySQL is the most popular open-source database system. What is MySQL? MySQL is a database. The data in MySQL is stored in database.
PHP and MySQL CS How Web Site Architectures Work  User’s browser sends HTTP request.  The request may be a form where the action is to call PHP.
Who uses it? MichaelMoore.com What's it all about? Rapid Development Clean, Pragmatic Design.
Website Development with PHP and MySQL Saving Data.
Chapter 6 Server-side Programming: Java Servlets
1 © Netskills Quality Internet Training, University of Newcastle HTML Forms © Netskills, Quality Internet Training, University of Newcastle Netskills is.
First Indico Workshop WEB FRAMEWORKS Adrian Mönnich May 2013 CERN.
Google App Engine Using Templates Jim Eng Thanks to Chuck Severance
Dynamic web content HTTP and HTML: Berners-Lee’s Basics.
1 MSCS 237 Overview of web technologies (A specific type of distributed systems)
Google App Engine Data Store ae-10-datastore
Rails & Ajax Module 5. Introduction to Rails Overview of Rails Rails is Ruby based “A development framework for Web-based applications” Rails uses the.
RUBRIC IP1 Ruben Botero Web Design III. The different approaches to accessing data in a database through client-side scripting languages. – On the client.
Server-side Programming The combination of –HTML –JavaScript –DOM is sometimes referred to as Dynamic HTML (DHTML) Web pages that include scripting are.
App Engine Web App Framework Jim Eng
Class 1Intro to Databases Goals of this class Understand the architecture behind web database applications Gain a basic understanding of what relational.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Web Services An Introduction Copyright © Curt Hill.
Since you’ll need a place for the user to enter a search query. Every form must have these basic components: – The submission type defined with the method.
Servers- Apache Tomcat Server Server-side scripts- Java Server Pages.
8 th Semester, Batch 2009 Department Of Computer Science SSUET.
Chapter 16 Web Pages And CGI Scripts Department of Biomedical Informatics University of Pittsburgh School of Medicine
COSC 2328 – Web Programming.  PHP is a server scripting language  It’s widely-used and free  It’s an alternative to Microsoft’s ASP and Ruby  PHP.
Web Design Terminology Unit 2 STEM. 1. Accessibility – a web page or site that address the users limitations or disabilities 2. Active server page (ASP)
World Wide Web has been created to share the text document across the world. In static web pages the requesting user has no ability to interact with the.
Pyragen A PYTHON WRAPPER GENERATOR TO APPLICATION CORE LIBRARIES Fernando PEREIRA, Christian THEIS - HSE/RP EDMS tech note:
Wrapping up our last topic: You and your (DNA) parasites Events like these, happening over and over again, have led to…
Upnl 24th workshop kim jae chan
PHP / MySQL Introduction
MapServer In its most basic form, MapServer is a CGI program that sits inactive on your Web server. When a request is sent to MapServer, it uses.
New Mexico State University
PHP Forms and Databases.
Data Visualizer for CommCare
Presentation transcript:

A data retrieval workflow using NCBI E-Utils + Python Part II: Jinja2 / Flask John Pinney Tech talk Tue 19 th Nov

My tasks 1. Produce a list of human genes that are associated with at least one resolved structure in PDB AND at least one genetic disorder in OMIM 2. Make an online table to display them ✓

Workflow for gene list

Python modules used in part 1 PyCogent Simple request handling for the main EUtils. pycogent.org urllib2 General HTTP request handler. docs.python.org/2/library/urllib2.html BeautifulSoup Amazingly easy to use object model for XML/HTML.

Some REST services need API keys The OMIM server requires a license agreement but is free for academic use. They provide a personal API key which must be submitted with each HTTP request. OMIM_APIKEY = 'E835870B16FBAF479E826FA5168CB2615EDA0F11' result = urllib2.urlopen( \ " + \ omimid + "&apiKey=" + OMIM_APIKEY \ ).read()

Throttling queries Most bioinformatics web servers have limits on the number of queries that can be sent from the same IP address (per day / per second etc.) They will ban you from accessing the site if you attempt too many requests. This can have serious consequences (e.g. the whole institution being blocked from NCBI).

Throttling queries To ensure compliance with usage limits, implement a simple throttle: def omim_info(omimid): checktime('api.europe.omim.org') result = urllib2.urlopen(...

Throttling queries import time lastRequestTime = {} throttleDelay = {'eutils.ncbi.nlm.nih.gov':0.25, \ 'api.europe.omim.org':0.5} def checktime(host): if((host in lastRequestTime) and (time.time() - \ lastRequestTime[host] < throttleDelay[host])): time.sleep(throttleDelay[host] - (time.time() - \ lastRequestTime[host])) lastRequestTime[host] = time.time()

HTML templating I need to produce an HTML table containing basic information about the genes I have collected. The Jinja2 templating engine is an easy way to generate these kinds of documents. I will use web services at NCBI and OMIM to assemble the information I need.

Jinja2 Using Jinja2 as an HTML templating engine, we need to split the work between 2 files: a normal python script (in which I call the web services). an HTML template with embedded python commands. Not all python functions are available within the template, so it makes sense to do as much work as possible within the script before passing the data over.

Jinja2 (script) from jinja2 import Template template = Template(file("gene_row_template.html").read()) fout = open("gene_list.html",'w')... for g in sorted_genes: fout.write( template.render( g=g, gene=gene_info(g), omim=[omim_info(x) for x in omim_links(g)], struc=[struc_info(x) for x in struc_links(g)] ) (variables passed to template as kwargs)

Jinja2 (template) {{gene.find('Gene-ref_locus').text}} {{gene.find('Gene-ref_desc').text}} {% for m in omim %} {{m.preferredTitle.text}} {% endfor %} {% for s in struc -%} {{s.find('Item',attrs={'Name':'PdbAcc'}).text}} {%- endfor %}

Jinja2 (template) {{gene.find('Gene-ref_locus').text}} {{gene.find('Gene-ref_desc').text}} {% for m in omim %} {{m.preferredTitle.text}} {% endfor %} {% for s in struc -%} {{s.find('Item',attrs={'Name':'PdbAcc'}).text}} {%- endfor %} {{ }} = print statement {% %} = other command I can access the methods of an object from within the template, so I can make use of all the nice BeautifulSoup shortcuts

Jinja2 (output) ACVRL1 activin A receptor type II-like 1 TELANGIECTASIA, HEREDITARY HEMORRHAGIC, TYPE 2; HHT2 4FAO 3MY0

Something more interactive What if I need to produce a report on-the-fly? Flask is a ‘micro’ web development framework for Python, which is useful for putting together a simple webserver. For anything more substantial (e.g. if database queries are needed), consider using Django. Flask uses Jinja2 as its template engine.

A simple webapp in Flask from flask import Flask, request, render_template, Response app = def report_handler(): gene = request.args.get('gene') if( gene == None): return render_template('report_form.html', unfound=None) else: return report_for_gene_name(gene) if __name__ == '__main__': app.run(debug=True)

Summary Some web services may be more fiddly than others to set up, especially if they involve API keys Request limits (requires throttling) Combining web services with an HTML template (either offline or on-the-fly via a webserver) is an easy way to generate user- friendly reports.

Python modules used in part 2 Jinja2 An elegant and highly versatile templating engine. Flask Python ‘micro’ web development framework.