Browse Source

Apply PEP8 and PEP263.

snapgene-write
Damien Goutte-Gattat 3 years ago
parent
commit
1a86aa1c15
  1. 23
      incenp/bio/seqio/SnapGeneIO.py
  2. 26
      incenp/bio/seqio/XdnaIO.py
  3. 15
      incenp/bio/seqio/__init__.py

23
incenp/bio/seqio/SnapGeneIO.py

@ -1,6 +1,5 @@
#!/usr/bin/env python
# binseqs - Support for binary sequence formats in Biopython
# Copyright (C) 2017 Damien Goutte-Gattat
# -*- coding: utf-8 -*-
# Copyright © 2017,2018 Damien Goutte-Gattat
#
# Redistribution and use of this script, with or without modifications,
# are permitted provided that the following conditions are met:
@ -20,14 +19,21 @@
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""SnapGene format support for Biopython
Provide read support for the binary format used by SnapGene.
"""
from datetime import datetime
from re import sub
from struct import unpack
from xml.dom.minidom import parseString
from Bio import Alphabet
from Bio.Seq import Seq
from Bio.SeqRecord import SeqRecord
from Bio.SeqFeature import SeqFeature, FeatureLocation
from struct import unpack
from xml.dom.minidom import parseString
from datetime import datetime
from re import sub
from Bio.SeqRecord import SeqRecord
class _SegmentIterator:
@ -190,6 +196,7 @@ _segment_handlers = {
def _decode(text):
return sub('<[^>]+>', '', text)
def _get_attribute_value(node, name, default=None, error=None):
if node.hasAttribute(name):
return _decode(node.attributes[name].value)

26
incenp/bio/seqio/XdnaIO.py

@ -1,6 +1,5 @@
#!/usr/bin/env python
# binseqs - Support for binary sequence formats in Biopython
# Copyright (C) 2017 Damien Goutte-Gattat
# -*- coding: utf-8 -*-
# Copyright © 2017,2018 Damien Goutte-Gattat
#
# Redistribution and use of this script, with or without modifications,
# are permitted provided that the following conditions are met:
@ -20,13 +19,21 @@
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""Xdna format support for Biopython
Provide read/write support for the binary format used by DNA Strider
and SerialCloner.
"""
from re import match
from struct import pack, unpack
from Bio import Alphabet
from Bio.Seq import Seq
from Bio.SeqIO.Interfaces import SequenceWriter
from Bio.SeqRecord import SeqRecord
from Bio.SeqFeature import SeqFeature, FeatureLocation, ExactPosition
from struct import unpack, pack
from re import match
from Bio.SeqRecord import SeqRecord
_seq_types = {
0: Alphabet.generic_alphabet,
@ -41,19 +48,23 @@ _seq_topologies = {
1: 'circular'
}
def _read(handle, length):
data = handle.read(length)
if len(data) < length:
raise ValueError("Cannot read %d bytes from handle" % length)
return data
def _read_pstring(handle):
length = unpack('>B', _read(handle, 1))[0]
return unpack('%ds' % length, _read(handle, length))[0].decode('ASCII')
def _read_pstring_as_integer(handle):
return int(_read_pstring(handle))
def _read_overhang(handle):
# An overhang is represented in a XDNA file as:
# - a Pascal string containing the text representation of the
@ -67,6 +78,7 @@ def _read_overhang(handle):
else:
return (None, None)
def _parse_feature_description(desc, qualifiers):
# The 'description' field of a feature sometimes contains
# several GenBank-like qualifiers, separated by CR characters.
@ -78,6 +90,7 @@ def _parse_feature_description(desc, qualifiers):
elif not '"' in part: # Reject ill-formed qualifiers
qualifiers['note'] = [part]
def _read_feature(handle, record):
name = _read_pstring(handle)
desc = _read_pstring(handle)
@ -114,6 +127,7 @@ def _read_feature(handle, record):
feature = SeqFeature(location, type=type, qualifiers=qualifiers)
record.features.append(feature)
def XdnaIterator(handle):
# Parse fixed-size header and do some rudimentary checks

15
incenp/bio/seqio/__init__.py

@ -1,6 +1,5 @@
#!/usr/bin/env python
# binseqs - Support for binary sequence formats in Biopython
# Copyright (C) 2017 Damien Goutte-Gattat
# -*- coding: utf-8 -*-
# Copyright © 2017,2018 Damien Goutte-Gattat
#
# Redistribution and use of this script, with or without modifications,
# are permitted provided that the following conditions are met:
@ -20,9 +19,17 @@
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""Support for binary sequence formats in Biopython
Load this module to enable support of SnapGene and Xdna
formats in Biopython's SeqIO.
"""
from Bio import SeqIO
from . import XdnaIO
from . import SnapGeneIO
from . import XdnaIO
if not 'xdna' in SeqIO._FormatToIterator:
SeqIO._FormatToIterator['xdna'] = XdnaIO.XdnaIterator

Loading…
Cancel
Save