2.10 Exercises

Exercise 2.1

Suggest a programming situation in which it would make sense to have several scalar references to one scalar variable that contains a peptide fragment.

Exercise 2.2

When might you want to use a reference to an (anonymous) scalar constant?

Exercise 2.3

Is $$arr[0] the same as $arr->[0]? Why or why not?

Exercise 2.4

Write a subroutine that returns a reference to a hash. Declare a reference to this subroutine and call it using the reference, then print out the hash whose reference is returned from the subroutine.

Exercise 2.5

Write a subroutine that returns a new anonymous subroutine based on its arguments, which are passed to it as references. Call the subroutine and then call the new subroutine that is returned.

Exercise 2.6

Write a subroutine to multiply two matrices.

Exercise 2.7

Develop a data structure that is a hash at the top level and can be used to record the data from microarray runs.

Exercise 2.8

Write a min subroutine that returns the minimum of two integers. Rewrite min3 using it.

Exercise 2.9

Make a subroutine that prints the distance matrix. Make it handle the display of longer numbers appropriately.

Exercise 2.10

Make the subroutine from Exercise 2.9 also display the pattern and string aligned with the output of the edit distance matrix.

Exercise 2.11

Make a subroutine that returns the edit distance array, the best score, and the locations of the best matches.

Exercise 2.12

Any difference in Exercise 2.11 if you calculate row by row instead of column by column?

Exercise 2.13

In Exercise 2.11, save space by keeping only two rows in memory.

Exercise 2.14

In Exercise 2.11, report on types of edits of matches.

Exercise 2.15

In Exercise 2.14, show the strings aligned, extra spaces for insertions or deletions, and flag mismatches.

Exercise 2.16

In Exercise 2.11, can you speed the program up by skipping computations when it becomes clear that the best score you've already found can't be matched or bettered in that column? Why or why not?

Exercise 2.17

Run the approximate string matching program on large text, such as entire chromosomes. How is the performance?

Exercise 2.18

Make a version of the approximate string matching program that searches for the pattern in libraries of text, and then reports on, say, the top 25 hits. (For example, search for a DNA pattern in all the records of a GenBank library.)

Exercise 2.19

How can you alter the approximate string matching algorithm to give different weights to the three edit possibilities, or to different types of mismatches (e.g., by giving a fairly low weight to mismatches between hydrophobic amino acids or the codons that encode them)?

Exercise 2.20

Write an array that handles eleven dimensions.

Exercise 2.21

Answer the questions at the end of Section 2.3.3: Why do you need two exists tests? Is $array a hash or a reference to an anonymous hash? Can you implement it the other way?