Dalke Scientific Software: More science. Less time. Products

Assignment 7 - web applications

As before, email the "assignment7" directory as an archive.

In this assignment you will some simple web services. I have two variants; the second is for those who are getting bored with sequence data and want to try some small molecule chemistry work using OpenEye. If you are in the latter group you will need to download the latest version of the OEChem toolkit and have me install the license on your machine.

Part 1 - Multiply

Make a CherryPy server program named "mult_server.py". In the index method return an HTML form which takes two numbers, "a" and "b" and sends them to the service "/mult". This will display the product of those two numbers.

Hint: Use the "add" method from the cherrypy_echo.py as the basis for your "mult" method.

Hint: You will need to implement an "index" method. You can either embed the HTML in the Python code or get the HTML from a file, like this:

    def index(self):
        return open("index.html").read()
This gets the HTML from the file "index.html", which you can create with your normal editor and view directly in a file.

Part 2 - Base count

Make a CherryPy server program named "count_server.py". The index method will return an HTML form which asks for a sequence in a <textarea>. It will send the results to "/basecount". This will count the number of each letter in the sequence and display the results in a table. The table rows should be in ASCII (alphabetical) order. For example, the results table may look like

CharacterCount
A120
C8
G62
T1053

Ignore newlines and other whitespace characters. You should allow "." and "-" and other non-alphabetical characters, including < and &. To make the numbers line up correctly, the count column should be right-aligned instead of the default of left-aligned and the character column should be centered.

Part 2 (alternate) - Atom count

Make a CherryPy server program named "count_server.py". The index method will return an HTML form which asks for a SMILES string. It will send the results to "/atomcount". This will count the number of each atomic element in the sequence and display the results in a table. The table rows should be in ASCII (alphabetical) order. For example, the results table may look like

SymbolCount
C12
H22
S1

You should include the implicit hydrogen count for the "H" row. To make the numbers line up correctly, the count column should be right-aligned instead of the default of left-aligned.

Part 3 - Embedding images

Go to the RCSB/PDB site and bring up the record for "2PLV". Follow the hyperlink on the left labeled "View Structure". At the bottom of the page, under "Custom Size Images" is a form with fields for size, format and a checkbox labeled "Cylinders". Keep the format as "jpeg". and select a size of 250, without checking the cylinders box. Press "Create image".

Go back to the "View Structure" page and check the cylinders box. Press "Create image" How do you think you would change the URL to show the structure for 9PTI? Try it out.

Make a file called "structures.html". This will contain information about three structures – 1REV, 1XTC and 2DHB. For each structure list the structure ID, its title, and its deposition date. Also include an <img> element with the src= the RCSB URL for the "with cylinders" image of the given structure.

When making this file, strive for a readable sense of style. A good style should make it easier for someone to read a document and understand what's going on. A table with a border around all the cells is too noisy, though easy to do. Meaningless colors and animations are similarly distracting.

Part 4 - an image link server

Make a CherryPy server program named "img_linker.py". The index method will return an HTML form which asks for a PDB id. The PDB id is only 4 characters long so read the specification (or other resource) so the text input field only allows 4 characters as input.

Send the form request to the new service named "img_link". This will display the text "Image for $PDBID" (where $PDBID is the 4-letter PDB code) and an in-line image using RCSB as the image source, based on what you learned in part 3. The $PDBID should be hyperlinked to the RCSB entry for that page.

After the image have a form which asks for another SMILES string and sends a request back to the img_link service.

For example, if I enter "3CLN" then the result should look something like:

Image for 3CLN
Enter PDB ID:

Part 4 (alternate) - an image link server

Go to OpenEye's viewmol page. Enter the SMILES string "c1ccccc1O" and "view" it.

The SMILES string is base64 encoded.
>>> import base64
>>> base64.decodestring("YzFjY2MoY2MxKU8g")
'c1ccc(cc1)O '
>>> base64.encodestring("c1ccccc1O")
'YzFjY2NjYzFP\n'
>>>
More precisely the base64 encoded string has the newlines removed and the "+" characters escaped for use in an HTML element attribute value. The short version is, use the following to encode the SMILES string for use as an href.
def encode_smiles(smiles):
    t = base64.encodestring(smiles)
    t = t.replace("\n", "")  # don't need the newlines
    t = t.replace("+", "%2B")  # escape the + for use in an HTML tab value
    return t

Make a CherryPy server program named "img_linker.py". The index method will return an HTML form which asks for a SMILES string. The string may be long so read the specification (or other resource) to make sure that the text input element is at least 50 characters wide.

Send the form request to the new service "img_link". This will display the text "Depiction of $SMILES" (where $SMILES is the input SMILES string – remember to escape it!) and an in-line image using OpenEye's depiction service. Choose appropriate values for the other viewing options.

After the image have a form which asks for another SMILES string and sends a request back to the img_link service.

For example, if I enter "c1ccccc1O" then the result should look something like:

Depiction of c1ccccc1O

Enter a new SMILES:

(Note: SMILES input element will be 50 characters wide.)



Copyright © 2001-2020 Andrew Dalke Scientific AB