Repository navigation
Closed
Description
I m loading ~ 150 aligned sequences and want to generate a Phylotree,
yet at some point, a ZeroDivisionError is raised.
The stacktrace:
Traceback (most recent call last):
File "/Users/marcel/dev/prototype/wrapper.py", line 56, in tree
self._tree = DistanceTreeConstructor().nj(self.distance_matrix)
File "/Users/marcel/dev/prototype/wrapper.py", line 49, in distance_matrix
self._distance_matrix = DistanceCalculator('blosum62').get_distance(self.msa)
File "/Users/marcel/dev/venv/prototype/lib/python2.7/site-packages/Bio/Phylo/TreeConstruction.py", line 465, in get_distance
dm[seq1.id, seq2.id] = self._pairwise(seq1, seq2)
File "/Users/marcel/dev/venv/prototype/lib/python2.7/site-packages/Bio/Phylo/TreeConstruction.py", line 448, in _pairwise
return 1 - (score * 1.0 / max_score)
ZeroDivisionError: float division by zeroThe sequences which seem to fail are the following:
seq1:
-------------------------------------------------------GCTTGCTGCTTGGCTGACGAGTGGCGGACGGGTGAGTAATGT-CTGGGAAACTG-----CCTGATGGAGGGGGATAAC-TACTGGAAACGGT-AGCTAATA--CCGCATAA----TGT----CGCAAGA--CCAAAGAGGGGGAC--CTTCGGGCCTCTTGCCAT-CGGATGTGCCC-AGATGGGATTAGC-TAGTTGGTGGGGT---AACGGCTC---ACCTAGGCGACG--ATCCCTAGCTGGTCTGAGA-GGATGAC--CAGCCACA--CTGGAACTGAGACAC---GGTCCAGACTCCTACGGGAGGCAGCAG-TGGGGAATAT--------TGCACAA--TGGGCG---CAAGCCTG-ATGCAGC-------CATGCCGCGTGTATGAA-GAAGGCCTTCGGGTTGTAAAGTACTTTCAGCGGGGAGGAAGGG-AGTAAAGTT-AATACCTTT----GCTCATTGACGTTACCCGCAGAAGAAGCACC-GGCTAAC-TCCGTGCCAGCAGCCGCGGTAATACGG-A-GGGTGC-AAGCGTTAATCGG-AATTACT-GGGCGTAAAGCGC-ACGC-AGGC-GGT--TTGTT-AAGTC-AGATGTGAAATC-----CCCG-GGCT----CAA-CCTGGGAACTGCATCTGATAC--TGG-CAA--------GCTTGAGTCT---CGTAGAGGGGGGTAGAA-TTCCAGGTGT-AGCGGTGAAATGCGTAGAGATCTGG-AGGAATA---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
seq2:
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------CCGGAGCTAACGCGTT-AAGTCGACCGCC-TGGG-----------GAGTACGGCCGCAAGGTTAAAACTCAAATGAATTGACG-----GGGGCCCGCACAAGCGGT-GGAGCA-TGTGGTTTAATTCGATGCAACGCGAAGAACCTTA-CCTACTC-TTGACATCCAGA-GAACTTAGCAGAG-ATG--CTATGGTGCCTTCGGG-AACTCTGAGACA-GGTGCT-GCAT-GGCTGTCGTCAGCTCGTGTTGTG-AAATGTT-GGGTTAAGTCCCGCAACGA-GCGC-AACCCTTATCCTTTGTTGCCAGCG-GTTCGGTCGGGAACTCAAAGGAGACTGCCAGTGATAAACTGGAGGAAGGTGGGGATGACGTCAAGTCATCATGGCCC-TTACGAGTAGGGCTACACACGTGCTACAATGGC-ATATACAAAGAGAAGC-GACCTCGCGAGAGCAA-GCGGACCTCATAAAGTAT-GTCGTAGTCCGGATCGGAGTCTGCAACTCG-ACTCCGTGAAGTCGGAAT-CGCTAGTAATCGTGGATCA-GAATGCCA-----CGGTGAATACGTTCCCGGGCCTTGTACACACCGCCCGTCACACCATGGGAGTGGGTTGCAAAAGAA------------------------------------------------------------------
Metadata
Metadata
Assignees
Labels
No labels
Activity
peterjc commentedon Mar 21, 2015
What is interesting about that pair of aligned sequences is every position (column in the full alignment) has a gap in either sequence. Nowhere can two bases be compared directly to get a score.
So, also long as gap-vs-gap scores zero, and gap-vs-base scores zero, this pairwise alignment scores zero. I guess we need to special case this to return the maximum possible distance?
peterjc commentedon Mar 21, 2015
@etal how about we insert this into the
_pairwisemethod?etal commentedon Mar 25, 2015
Yes,I think that should do it.
On Mar 21, 2015 3:19 AM, "Peter Cock" [email protected] wrote:
peterjc commentedon Mar 25, 2015
@etal - Can you construct a little test case for this, and verify the fix?
quiqua commentedon Apr 7, 2015
Will this case ever get fulfilled?
In the example, both sequences have a length of 1723.
As a fallback I would propose the following:
or
etal commentedon Apr 7, 2015
Sorry, I'm not going to have time to test this myself within a reasonable amount of time.
kianho commentedon May 25, 2015
@etal @peterjc I can take care of this if it is still open.
peterjc commentedon May 25, 2015
Yes, please @kianho - another set of eyes on this code would be great.
Avoid a ZeroDivisionError in TreeConstruction.DistanceCalculator (#491)
Add unit test for TreeConstructor.DistanceCalculator edge case (#491)
etal commentedon May 27, 2015
I pushed a fix and a test.
I noticed an interesting behavior that @lijax must have intended (?), but wasn't obvious at first -- if no scoring matrix is specified, the distances are based on character identity, which is like the "identity" scoring scheme but without skipping gap characters. The test includes checking this behavior, too. It would be more clear to have another name for this type of scoring (maybe it's useful for odd encodings of phenotypic data), e.g.
character, and for this_distancemethod to simply fall back to either thecharacteroridentityscoring matrix if self.scoring_matrix isn't specified.lijax commentedon May 28, 2015
Sorry, I'm a little too late to notice this issue.
Yes, @etal . That was Intended for some general usage. I agree with your suggestion. It'll be more obvious to give it a name. How about making
skip_letterschangeable to make this class more generalized?peterjc commentedon May 16, 2017
@lijax @etal is this scoring question still relevant, or can we close this issue?
TreeConstruction: Add 'skip_letters' parameter to DistanceCalculator (#…
etal commentedon Jul 3, 2017
I made the
skip_lettersa parameter as @lijax suggested. I'll leave it to your discretion if/when the default behavior should change to make the "identity" model skip gap and stop characters in calculating the score.TreeConstruction: Add 'skip_letters' parameter to DistanceCalculator (b…