Here are the answers to the questions.

There are 3 pieces of sample code provided as answers. Here is one, another can be found here. The third version dealling with top hits is here and e-value less than 1e-10 is here