Skip to content

Not all calls to .keys() should be deleted. - #30

Closed
slowkow wants to merge 1 commit into
biopython:masterfrom
slowkow:patch-1
Closed

slowkow wants to merge 1 commit into
biopython:masterfrom
slowkow:patch-1

Conversation

@slowkow

@slowkow slowkow commented Mar 20, 2012

Copy link
Copy Markdown
Contributor

Commit bdf94b3 deleted a lot of calls to .keys(). Some of those calls should not be deleted. I spotted one of them.

Removing the call to keys() on line 999 caused prev_partitions to be a shallow copy of self.charpartitions instead of a previous copy of the keys. In the next line, self.charpartitions is modified and therefore so is prev_partitions. So, the requirement in the list comprehension n not in prev_partitions is impossible to meet and the NexusError will always be raised. I encountered the raised error when trying to read a nexus file.

Removing the call to `keys()` on line 999 caused `prev_partitions` to be a shallow copy of `self.charpartitions` instead of a previous copy of the keys. In the next line, `self.charpartitions` is modified and therefore so is `prev_partitions`. So, the requirement in the list comprehension `n not in prev_partitions` is impossible to meet and the `NexusError` will always be raised. I encountered the raised error when trying to read a nexus file.
@peterjc

peterjc commented Mar 20, 2012

Copy link
Copy Markdown
Member

That does look sensible.... do you have a specific example of the error we can turn into a unit test?

@slowkow

slowkow commented Mar 20, 2012

Copy link
Copy Markdown
Contributor Author

I apologize for the poor commit message -- using github's interface, I forgot that I was writing a commit message and treated it as a comment field.

I believe all nexus files with a CODONPOSSET command in the CODONS block will raise the NexusError 'Formatting Error in codonposset: %s '.

I made a minimal nexus file that reproduces my experience. Perhaps this is a good start for writing the unit test. I'm using BioPython version 1.57 in the code example below, not the latest version from github (version 1.59+), so the line numbers are slightly off. I fear breaking something if I try to install 1.59+ when 1.57 is already installed... but I've looked at the code and the same bug is in both versions.

Edit1
I downloaded the github version, ran python setup.py test, and encountered a few failed tests with HTTPError: HTTP Error 500: Internal Server Error. This information is irrelevant to the bug in this comment, but I just wanted to explain why I'm using the version of BioPython in the Ubuntu repo rather than the github version. I don't know if version 1.57 has the same failed tests or not because I don't know how to run the tests for 1.57.

$ cat test_codonposset.nex 
#NEXUS 
[MacClade 4.05 registered to Computational Biologist, University]


BEGIN DATA;
    DIMENSIONS  NTAX=2 NCHAR=22;
    FORMAT DATATYPE=DNA  MISSING=? GAP=- ;
MATRIX
[                           10        20 ]
[                           .         .  ]

Aegotheles         AAAAAGGCATTGTGGTGGGAAT   [22]
Aerodramus         ?????????TTGTGGTGGGAAT   [13]
;
END;


BEGIN CODONS;
    CODONPOSSET * CodonPositions = 
        N: 1-10, 
        1: 11-22\3, 
        2: 12-22\3, 
        3: 13-22\3;
    CODESET  * UNTITLED = Universal: all ;
END;

$ python -c 'import sys; from Bio import AlignIO; AlignIO.read(sys.argv[1], "nexus")' test_codonposset.nex 
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/pymodules/python2.7/Bio/AlignIO/__init__.py", line 427, in read
    first = iterator.next()
  File "/usr/lib/pymodules/python2.7/Bio/AlignIO/__init__.py", line 373, in parse
    for a in i:
  File "/usr/lib/pymodules/python2.7/Bio/AlignIO/NexusIO.py", line 39, in NexusIterator
    n = Nexus.Nexus(handle)
  File "/usr/lib/pymodules/python2.7/Bio/Nexus/Nexus.py", line 548, in __init__
    self.read(input)
  File "/usr/lib/pymodules/python2.7/Bio/Nexus/Nexus.py", line 602, in read
    self._parse_nexus_block(title, contents)
  File "/usr/lib/pymodules/python2.7/Bio/Nexus/Nexus.py", line 643, in _parse_nexus_block
    getattr(self,'_'+line.command)(line.options)
  File "/usr/lib/pymodules/python2.7/Bio/Nexus/Nexus.py", line 1005, in _codonposset
    raise NexusError('Formatting Error in codonposset: %s ' % options)
Bio.Nexus.Nexus.NexusError: Formatting Error in codonposset: * CodonPositions = N: 1-10, 1: 11-22\3, 2: 12-22\3, 3: 13-22\3 

@peterjc

peterjc commented Mar 20, 2012

Copy link
Copy Markdown
Member

Excellent - fix applied,
541f2b5

your example turned into a unit test,
475de4d

and you're thanked in the release notes:
212152c

Thank you!

@peterjc peterjc closed this Mar 20, 2012
@peterjc

peterjc commented Mar 20, 2012

Copy link
Copy Markdown
Member

P.S. Those HTTP Error 500 errors from the TogoWS tests are harmless - the DDBJ in Japan are/were upgrading their super computer and as a result some of the DDBJ resources have been offline.

@peterjc

peterjc commented Sep 20, 2018

Copy link
Copy Markdown
Member

@slowkow Hello again Kamil. Are you happy to dual licence your contributions under both the Biopython License Agreement AND the BSD 3-Clause License? See #898. Thank you.

@slowkow

slowkow commented Sep 20, 2018

Copy link
Copy Markdown
Contributor Author

Hi Peter, 6 years later it's nice to hear from you :)

I hereby give my explicit permission to license my contributions under the Biopython License Agreement AND the BSD 3-Clause License.

Thanks for asking!

@peterjc

peterjc commented Sep 20, 2018

Copy link
Copy Markdown
Member

Thank you!

peterjc added a commit to peterjc/biopython that referenced this pull request Sep 2, 2019
Original authors Frank Kauff and Cymon J. Cox and all the contributors
since as tracked with version control have agreed:

 - Adhemar Zerlotini (@azneto)
   biopython#1412 (comment)
 - @Amrithasuresh
   biopython#1575
 - @biojerm
   biopython#1847 (comment)
 - Carlos Pena (@carlosp420)
   biopython#898 (comment)
 - Chris Rands (@chris-rands)
   biopython#1301
 - Chris Warth (@cswarth)
   biopython#898 (comment)
 - Christian Brueffer (@cbrueffer)
   biopython#898 (comment)
 - Connor McCoy (@cmccoy)
   biopython#898 (comment)
 - Cymon J. Cox (@cymon)
   biopython#898 (comment)
 - Eric Talevich (@etal)
   biopython#898 (comment)
 - Francesco Gastaldello (@Gasta88)
   biopython#1063
 - Frank Kauff (CVS username fkauff, on GitHub as @frankkl)
   biopython#2246 (comment)
 - Iddo Friedberg (@idoerg)
   biopython#898 (comment)
 - Joe Cora (@JoeCora)
   biopython#898 (comment)
 - Kamil Slowikowski (@slowkow)
   biopython#30 (comment)
 - Lenna Peterson (@lennax)
   biopython#898 (comment)
 - Michiel de Hoon (@mdehoon)
   biopython#898 (comment)
 - @morrme
   biopython#1172 (comment)
 - Nick Negretti (@nimne)
   biopython#1768 (comment)
 - Peter Cock (@peterjc)
   biopython#898 (comment)
 - Sergei Lebedev (@superbobry)
   biopython#898 (comment)
 - Sergio Valqui (@svalqui)
   biopython#1749
 - Sourav Singh (@souravsingh)
   biopython#957
 - Tiago Antao (@tiagoantao)
   biopython#898 (comment)
 - Travis Wrightsman (@twrightsman)
   biopython#898 (comment)
 - @unify
   N/A
 - Vincent Davis (@vincentdavis)
   biopython#898 (comment)
 - Wayne Decatur (@fomightez)
   biopython#898 (comment)
 - Wibowo Arindrarto (@bow)
   biopython#898 (comment)
peterjc added a commit that referenced this pull request Nov 4, 2019
Original authors Frank Kauff and Cymon J. Cox and all the contributors
since as tracked with version control have agreed:

 - Adhemar Zerlotini (@azneto)
   #1412 (comment)
 - @Amrithasuresh
   #1575
 - @biojerm
   #1847 (comment)
 - Carlos Pena (@carlosp420)
   #898 (comment)
 - Chris Rands (@chris-rands)
   #1301
 - Chris Warth (@cswarth)
   #898 (comment)
 - Christian Brueffer (@cbrueffer)
   #898 (comment)
 - Connor McCoy (@cmccoy)
   #898 (comment)
 - Cymon J. Cox (@cymon)
   #898 (comment)
 - Eric Talevich (@etal)
   #898 (comment)
 - Francesco Gastaldello (@Gasta88)
   #1063
 - Frank Kauff (CVS username fkauff, on GitHub as @frankkl)
   #2246 (comment)
 - Iddo Friedberg (@idoerg)
   #898 (comment)
 - Joe Cora (@JoeCora)
   #898 (comment)
 - Kamil Slowikowski (@slowkow)
   #30 (comment)
 - Lenna Peterson (@lennax)
   #898 (comment)
 - Michiel de Hoon (@mdehoon)
   #898 (comment)
 - @morrme
   #1172 (comment)
 - Nick Negretti (@nimne)
   #1768 (comment)
 - Peter Cock (@peterjc)
   #898 (comment)
 - Sergei Lebedev (@superbobry)
   #898 (comment)
 - Sergio Valqui (@svalqui)
   #1749
 - Sourav Singh (@souravsingh)
   #957
 - Tiago Antao (@tiagoantao)
   #898 (comment)
 - Travis Wrightsman (@twrightsman)
   #898 (comment)
 - @unify
   N/A
 - Vincent Davis (@vincentdavis)
   #898 (comment)
 - Wayne Decatur (@fomightez)
   #898 (comment)
 - Wibowo Arindrarto (@bow)
   #898 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants