Browse Source

Fix Python3 compatibility issue.

Replace obsolete 'has_key' method with 'in' keyword.
snapgene-write
Damien Goutte-Gattat 3 years ago
parent
commit
c0bd5c7975
  1. 10
      incenp/bio/seqio/SnapGeneIO.py
  2. 4
      incenp/bio/seqio/XdnaIO.py
  3. 6
      incenp/bio/seqio/__init__.py

10
incenp/bio/seqio/SnapGeneIO.py

@ -136,11 +136,11 @@ def _parse_features_segment(length, data, record):
error="Missing qualifier name")
qvalues = []
for value in qualifier.getElementsByTagName('V'):
if value.attributes.has_key('text'):
if 'text' in value.attributes:
qvalues.append(_decode(value.attributes['text'].value))
elif value.attributes.has_key('predef'):
elif 'predef' in value.attributes:
qvalues.append(_decode(value.attributes['predef'].value))
elif value.attributes.has_key('int'):
elif 'int' in value.attributes:
qvalues.append(int(value.attributes['int'].value))
quals[qname] = qvalues
@ -187,7 +187,7 @@ def _decode(text):
return sub('<[^>]+>', '', text).encode('ascii', 'ignore')
def _get_attribute_value(node, name, default=None, error=None):
if node.attributes.has_key(name):
if name in node.attributes:
return _decode(node.attributes[name].value)
elif error:
raise ValueError(error)
@ -214,7 +214,7 @@ def SnapGeneIterator(handle):
if n == 0 and type != 0x09:
raise ValueError("The file does not start with a File Description Segment")
if _segment_handlers.has_key(type):
if type in _segment_handlers:
_segment_handlers[type](length, data, record)
n = n + 1

4
incenp/bio/seqio/XdnaIO.py

@ -122,7 +122,7 @@ def XdnaIterator(handle):
unpack('>BBB25xII60xI12x', header)
if version != 0:
raise ValueError("Unsupported XDNA version")
if not _seq_types.has_key(type):
if not type in _seq_types:
raise ValueError("Unknown sequence type")
# Read actual sequence and comment found in all XDNA files
@ -137,7 +137,7 @@ def XdnaIterator(handle):
# Create record object
record = SeqRecord(Seq(sequence, _seq_types[type]),
description=comment, name=name)
if _seq_topologies.has_key(topology):
if topology in _seq_topologies:
record.annotations['topology'] = _seq_topologies[topology]
if len(handle.read(1)) == 1:

6
incenp/bio/seqio/__init__.py

@ -24,16 +24,16 @@ from Bio import SeqIO
from . import XdnaIO
from . import SnapGeneIO
if not SeqIO._FormatToIterator.has_key('xdna'):
if not 'xdna' in SeqIO._FormatToIterator:
SeqIO._FormatToIterator['xdna'] = XdnaIO.XdnaIterator
if not SeqIO._FormatToWriter.has_key('xdna'):
if not 'xdna' in SeqIO._FormatToWriter:
SeqIO._FormatToWriter['xdna'] = XdnaIO.XdnaWriter
if not 'xdna' in SeqIO._BinaryFormats:
SeqIO._BinaryFormats.append('xdna')
if not SeqIO._FormatToIterator.has_key('snapgene'):
if not 'snapgene' in SeqIO._FormatToIterator:
SeqIO._FormatToIterator['snapgene'] = SnapGeneIO.SnapGeneIterator
if not 'snapgene' in SeqIO._BinaryFormats:

Loading…
Cancel
Save