8.6 Exercises

Exercise 8.1

Add an argument "linelength=>50" to Restrictionmap to set the length of lines in the graphic output.

Exercise 8.2

What happens if you request a graphic type for which no corresponding method has been defined? Would there be a better way to handle this situation than the current behavior of the module?

Exercise 8.3

If more than one enzyme is present, draw each enzyme in a different color. You'll have to solve the problem of how to define the required number of colors and how to choose them so that they'll be easily distinguishable from each other. You'll also have to rework the annotation lines when more than one type of enzyme appears on an annotation line, drawing the different sections individually with different colors.

Exercise 8.4

Add header information such as filename, count of restriction sites for each enzyme, and date, to the text or PNG or JPEG graphic generated by _drawmap_text or _drawmap_png or _drawmap_jpg.

Exercise 8.5

In _drawmap_text, add a number at the beginning of each line of sequence giving the position of the first base on that line. First figure out the number of digits needed for the last line, so you can make the appropriate amount of space before each line. Can you right-justify the numbers in the allotted space?

Exercise 8.6

In _drawmap_text, put a space between each group of 10 bases on a line to make it easier to find a particular base position.

Exercise 8.7

In _drawmap_png or _drawmap_jpg, instead of putting the enzyme names in annotation lines above the sequence lines, try simply printing the sequence lines, but highlight each restriction site with color and enclosing it in a box. Try giving each type of enzyme in the map a different color and type of box and add a key that shows which enzyme matches up with each color/box.

This works fine with a single enzyme. Does it work with two enzymes? With three or more? Do you need to change the output of _drawmap_text to accomplish this?

Exercise 8.8

Rewrite the webrebase1 CGI Perl script so that it is two programs: one that displays the opening screen form, and the other that calculates the PNG image. Say you call the image-generating CGI script rebase_png. Then use the CGI for an HTML tag such as:

print img({ -src => "/cgi-bin/rebase_png?enzyme=EcoRI;fileseq=
    sampleecori.dna2" });

In this way, you can embed a dynamically generated image into a larger HTML document; it's an alternative to the method shown in the text in which the image is shown by itself in the web browser.

Exercise 8.9

The _drawmap_jpg and _drawmap_png methods are almost identical. Add a third method that does most of the work of these methods, taking as an argument the file type desired for output. Then rewrite _drawmap_jpg and _drawmap_png so that they're much shorter. Now add a _drawmap_wbmp method.

Exercise 8.10

The _drawmap_png method assumes that annotation lines contain spaces while sequence lines do not. This is called an heuristic, a rule of thumb that is easy to compute and leads to a simplification of program logic. What if there is an annotation line that has no spaces because it annotates a line of sequence that is solid, wall-to-wall restriction sites? Invent another method of distinguishing between annotation and sequence lines.

Exercise 8.11

Use GD::Graph to make a different representation of a restriction map.