[Biopython-dev] pypaml

Brandon Invergo b.invergo at gmail.com
Sun Jun 12 12:28:31 UTC 2011


> I only have one more small suggestion. A number of the functions
> take a results dictionary and then modify it directly, taking
> advantage of the fact that it's the same object. For instance,
> 'parse_parameters' in _parse_baseml.py looks like:
>
> results["parameters"] = {}
> parse_parameter_list(lines, results, num_params)
> parse_kappas(lines, results)
> parse_rates(lines, results)
> parse_freqs(lines, results)
>
> A nice way to do this is to pass in and return the modified
> dictionary, so it is clear what is happening in the function.
> Ideally, this would look like:
>
> parameters = {}
> parameters = parse_parameter_list(lines, parameters, num_params)
> parameters = parse_kappas(lines, parameters)
> parameters = parse_rates(lines, parameters)
> parameters = parse_freqs(lines, parameters)
> results["parameters"] = parameters
>
> For someone reading the code this makes it more explicit that each
> of those functions modifies the 'parameters' dictionary. Otherwise
> the side effects that change the results or parameters dictionary
> could be missed.

Done!
Funnily enough, it was originally that way but then I remembered that
Python passes arguments by reference, so I changed it to not return
the dict every time. I thought I was being clever and Pythonic but I
agree that this way is more readable/maintainable.

> For the Chi2 question, I'm 100% agreed with Peter and Eric. The pure
> python version could be useful, but no sense re-writing a C version
> if an external one exists in Scipy. PyCogent also has some
> functionality here as well:
>
> http://pycogent.sourceforge.net/cookbook/standard_statistical_analyses.html#chi-square

Ok, the pure Python version is back in. Once PAML is officially part
of Biopython, I can write some documentation for the wiki and provide
a warning about the high df values...

Cheers,
Brandon



More information about the Biopython-dev mailing list