Browse Source

More Python3 compatibility fixes.

snapgene-write
Damien Goutte-Gattat 3 years ago
parent
commit
9ce08eee3e
  1. 18
      incenp/bio/seqio/SnapGeneIO.py

18
incenp/bio/seqio/SnapGeneIO.py

@ -43,7 +43,7 @@ class _SegmentIterator:
# - 1 big-endian long integer (4bytes) indicating the length
# of the segment's data;
# - the segment's data.
def next(self):
def __next__(self):
type = self.handle.read(1)
if len(type) < 1: # No more segment
raise StopIteration
@ -60,13 +60,17 @@ class _SegmentIterator:
return (type, length, data)
# Python2 compatibility
def next(self):
return self.__next__()
def _parse_dna_segment(length, data, record):
if record.seq:
raise ValueError("The file contains more than one DNA Segment")
flags, sequence = unpack(">B%ds" % (length - 1), data)
record.seq = Seq(sequence, alphabet=Alphabet.generic_dna)
record.seq = Seq(sequence.decode('ASCII'), alphabet=Alphabet.generic_dna)
if flags & 0x01:
record.annotations['topology'] = 'circular'
else:
@ -80,7 +84,7 @@ _months = [
def _parse_notes_segment(length, data, record):
xml = parseString(data)
xml = parseString(data.decode('ASCII'))
type = _get_child_value(xml, 'Type')
if type == 'Synthetic':
record.annotations['data_file_division'] = 'SYN'
@ -99,12 +103,12 @@ def _parse_notes_segment(length, data, record):
def _parse_file_description_segment(length, data, record):
cookie, seq_type, exp_version, imp_version = unpack('>8sHHH', data)
if cookie != 'SnapGene':
if cookie.decode('ASCII') != 'SnapGene':
raise ValueError("The file is not a valid SnapGene file")
def _parse_features_segment(length, data, record):
xml = parseString(data)
xml = parseString(data.decode('ASCII'))
for feature in xml.getElementsByTagName('Feature'):
quals = {}
@ -149,7 +153,7 @@ def _parse_features_segment(length, data, record):
def _parse_primers_segment(length, data, record):
xml = parseString(data)
xml = parseString(data.decode('ASCII'))
for primer in xml.getElementsByTagName('primer'):
quals = {}
@ -184,7 +188,7 @@ _segment_handlers = {
# some of the segments
def _decode(text):
return sub('<[^>]+>', '', text).encode('ascii', 'ignore')
return sub('<[^>]+>', '', text)
def _get_attribute_value(node, name, default=None, error=None):
if node.hasAttribute(name):

Loading…
Cancel
Save