Repository navigation
Record missing data in Bio.Phylo.PAML.codeml - #1012
Conversation
parse all site parameters of a pairwise codeml analysis
Current coverage is 80.40% (diff: 100%)@@ master #1012 diff @@
==========================================
Files 319 319
Lines 48798 48800 +2
Methods 0 0
Messages 0 0
Branches 0 0
==========================================
+ Hits 39228 39238 +10
+ Misses 9570 9562 -8
Partials 0 0
|
|
@brandoninvergo could you look at this please? There isn't a test file to look at as you requested on #483, but @alpae has included a unit test. |
|
At first glance it seems OK, although it's been a while since I looked at the code. The patch changes the code to use Anyway, it seems to me that it could have just as easily been fixed by unindenting lines 423-437 by one level. That looks like it was the source of the bug (ah that Python "feature" of indentation-as-structural-delimiter can really bite you if you miss something). But if we go that route, please change 423 and 425 to read |
| # t= 0.0126 S= 81.4 N= 140.6 dN/dS= 0.0010 dN= 0.0000 dS= 0.0115 | ||
| pair_re = re.compile("\d+ \((.+)\) ... \d+ \((.+)\)") | ||
| pairwise = {} | ||
| pairwise, seq1, seq2 = collections.defaultdict(dict), None, None |
There was a problem hiding this comment.
As noted by @brandoninvergo using three separate lines would be more in line with the rest of Biopython here.
|
@brandoninvergo the change in line 423/425 is not the same whether you test that the seq1/seq2 are in pairwise or None. The logLiklihood value and the other values are not read from the same line. I'm happy do adapt line 415 to single assignment statements. The defaultdict has been introduced in python2.5. Given that Py2.6 is required for biopython, I guess that is fine. |
|
We have no dependency problem using defaultdict now (or the ordered dict either). |
|
Biopython 1.68 was our last release to support Python 2.6, so you can now assume Python 2.7 or Python 3.3 onwards. |
| for param in ("t", "S", "N", "omega", "dN", "dS", "lnL"): | ||
| self.assertTrue(param in data, version_msg + | ||
| ": '%s' not in parsed parameters" % param) | ||
| self.assertTrue(isinstance(data[param], numbers.Number)) |
There was a problem hiding this comment.
I don't think we've ever used the numbers module before in Biopython (at least, searching for import numbers didn't show any matches). Maybe we should, or would checking against int and float work just as well?
There was a problem hiding this comment.
in this case for sure, testing for float would be just as good. numbers module came with Py2.6. probably that's why it is not yet used in biopython. But I'll change that one.
There was a problem hiding this comment.
Thanks. Please open an issue on taking advantage of the numbers module in Biopython if you think it would be useful.
|
(I've given the pull request a more descriptive name, although I did muddle this with another open issue first - whoops) |
|
@brandoninvergo are you happy for this to be merged now? Is the proposed test enough? |
brandoninvergo
left a comment
There was a problem hiding this comment.
The test doesn't catch the problem...
| % version.replace('_', '.') | ||
| results_path = os.path.join(res_dir, results_file) | ||
| results = codeml.read(results_path) | ||
| for seq2 in results['pairwise'].values(): |
There was a problem hiding this comment.
The test doesn't actually catch the problem as written. Changing 484-485 to this should work:
for seq in results["pairwise"]:
seq_vals = results["pairwise"][seq]
self.assertTrue(len(seq_vals) > 0, "no parsed parameters for '%s'" \
% seq)
for data in seq_vals:
There was a problem hiding this comment.
Hang on, my suggestion seems to be buggy too.
thanks to Brandon Invergo for spotting this
|
Here's a working, simplified (flat is better than nested...) version of the test. Also, the original testPairwise was broken, so it's fixed here. There's a bit of overlap between the two tests. Oh well |
|
@peterjc dual licence: of course, fine with me, also about being mentioned in news/contribs. my real name is Adrian Altenhoff. ;-) |
|
As for the |
|
And what about this for a fix to the |
|
@brandoninvergo your suggested test changes do not work, as in the test files the pairwise runs are done with more than 2 sequences. then you end up with several pairs, so the len(pairwise)==2 check generally fails. Also, because in a result file generally you find more than one pairwise result, only checking initially if seq1/seq2 are None is not enough: you need to test multiple times, but ignore float-lines until you have the first matching sequence pair... I kept the spirit of your suggestions for both test and parse code, including the standard dict instead of the defaultdict (valid point that all other functions don't use it). Hope this is ok. |
|
Ah right, I see my mistake with the updated tests. You're correct. Sorry, I've never used codeml in pairwise mode and I didn't look closely at the test results file. Thanks for the fix! @peterjc everything looks ok to me now. |
Squashed commit from pull request biopython#1012, fixes biopython#483. The codeml parser parses now all site parameters of a pairwise codeml analysis. Thanks to Brandon Invergo for his input and review.
See pull request biopython#1012 and issue biopython#483.
Original author Brandon Invergo and contributors since as tracked with version control have all agreed: - Adrian Altenhoff (@alpae) biopython#1012 (comment) - Brandon Invergo (@brandoninvergo) biopython#898 (comment) - Brian Osborne (@bosborne) biopython#898 (comment) - Carlos Pena (@carlosp420) biopython#898 (comment) - Christian Brueffer (@cbrueffer) biopython#898 (comment) - Eric Talevich (@etal) biopython#898 (comment) - Jeremy LaBarge (@biojerm) biopython#1847 (comment) - @morrme biopython#1172 (comment) - Peter Cock (@peterjc) biopython#898 (comment) - Sergio Valqui (@svalqui) biopython#1749
Original author Brandon Invergo and contributors since as tracked with version control have all agreed: - Adrian Altenhoff (@alpae) biopython#1012 (comment) - Brandon Invergo (@brandoninvergo) biopython#898 (comment) - Brian Osborne (@bosborne) biopython#898 (comment) - Carlos Pena (@carlosp420) biopython#898 (comment) - Christian Brueffer (@cbrueffer) biopython#898 (comment) - Eric Talevich (@etal) biopython#898 (comment) - Jeremy LaBarge (@biojerm) biopython#1847 (comment) - @morrme biopython#1172 (comment) - Peter Cock (@peterjc) biopython#898 (comment) - Sergio Valqui (@svalqui) biopython#1749
Original author Brandon Invergo and contributors since as tracked with version control have all agreed: - Adrian Altenhoff (@alpae) #1012 (comment) - Brandon Invergo (@brandoninvergo) #898 (comment) - Brian Osborne (@bosborne) #898 (comment) - Carlos Pena (@carlosp420) #898 (comment) - Christian Brueffer (@cbrueffer) #898 (comment) - Eric Talevich (@etal) #898 (comment) - Jeremy LaBarge (@biojerm) #1847 (comment) - @morrme #1172 (comment) - Peter Cock (@peterjc) #898 (comment) - Sergio Valqui (@svalqui) #1749
The long existing issue #483 was also a problem in one of my analysis. I've added a fix and a unittest. The codeml parser parses now all site parameters of a pairwise codeml analysis.