Skip to content

Commit

Permalink
remove six dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
daler committed Apr 11, 2024
1 parent 5ea3881 commit 308f956
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 63 deletions.
3 changes: 1 addition & 2 deletions gffutils/attributes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import six
import collections

try:
Expand Down Expand Up @@ -95,7 +94,7 @@ def __str__(self):
return "\n".join(s)

def update(self, *args, **kwargs):
for k, v in six.iteritems(dict(*args, **kwargs)):
for k, v in dict(*args, **kwargs).items():
self[k] = v


Expand Down
8 changes: 4 additions & 4 deletions gffutils/biopython_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Module for integration with BioPython, specifically SeqRecords and SeqFeature
objects.
"""
import six

try:
from Bio.SeqFeature import SeqFeature, FeatureLocation
Expand All @@ -15,7 +14,8 @@
_biopython_strand = {
"+": 1,
"-": -1,
".": 0,
".": None,
"?": 0,
}
_feature_strand = dict((v, k) for k, v in _biopython_strand.items())

Expand All @@ -33,7 +33,7 @@ def to_seqfeature(feature):
If string, assume it is a GFF or GTF-format line; otherwise just use
the provided feature directly.
"""
if isinstance(feature, six.string_types):
if isinstance(feature, str):
feature = feature_from_line(feature)

qualifiers = {
Expand Down Expand Up @@ -68,7 +68,7 @@ def from_seqfeature(s, **kwargs):
score = s.qualifiers.get("score", ".")[0]
seqid = s.qualifiers.get("seqid", ".")[0]
frame = s.qualifiers.get("frame", ".")[0]
strand = _feature_strand[s.strand]
strand = _feature_strand[s.location.strand]

# BioPython parses 1-based GenBank positions into 0-based for use within
# Python. We need to convert back to 1-based GFF format here.
Expand Down
3 changes: 1 addition & 2 deletions gffutils/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Conversion functions that operate on :class:`FeatureDB` classes.
"""

import six


def to_bed12(f, db, child_type="exon", name_field="ID"):
Expand All @@ -22,7 +21,7 @@ def to_bed12(f, db, child_type="exon", name_field="ID"):
Attribute to be used in the "name" field of the BED12 entry. Usually
"ID" for GFF; "transcript_id" for GTF.
"""
if isinstance(f, six.string_types):
if isinstance(f, str):
f = db[f]
children = list(db.children(f, featuretype=child_type, order_by="start"))
sizes = [len(i) for i in children]
Expand Down
11 changes: 5 additions & 6 deletions gffutils/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import sys
import os
import sqlite3
import six
from textwrap import dedent
from gffutils import constants
from gffutils import version
Expand Down Expand Up @@ -119,7 +118,7 @@ def __init__(
os.unlink(dbfn)
self.dbfn = dbfn
self.id_spec = id_spec
if isinstance(dbfn, six.string_types):
if isinstance(dbfn, str):
conn = sqlite3.connect(dbfn)
else:
conn = dbfn
Expand Down Expand Up @@ -171,7 +170,7 @@ def _id_handler(self, f):
"""

# If id_spec is a string or callable, convert to iterable for later
if isinstance(self.id_spec, six.string_types):
if isinstance(self.id_spec, str):
id_key = [self.id_spec]
elif hasattr(self.id_spec, "__call__"):
id_key = [self.id_spec]
Expand All @@ -181,7 +180,7 @@ def _id_handler(self, f):
elif isinstance(self.id_spec, dict):
try:
id_key = self.id_spec[f.featuretype]
if isinstance(id_key, six.string_types):
if isinstance(id_key, str):
id_key = [id_key]

# Otherwise, use default auto-increment.
Expand Down Expand Up @@ -684,7 +683,7 @@ def _update_relations(self):
# c.execute('CREATE INDEX childindex ON relations (child)')
# self.conn.commit()

if isinstance(self._keep_tempfiles, six.string_types):
if isinstance(self._keep_tempfiles, str):
suffix = self._keep_tempfiles
else:
suffix = ".gffutils"
Expand Down Expand Up @@ -883,7 +882,7 @@ def _update_relations(self):
msg = "transcript"
logger.info("Inferring %s extents " "and writing to tempfile" % msg)

if isinstance(self._keep_tempfiles, six.string_types):
if isinstance(self._keep_tempfiles, str):
suffix = self._keep_tempfiles
else:
suffix = ".gffutils"
Expand Down
12 changes: 4 additions & 8 deletions gffutils/feature.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from pyfaidx import Fasta
import six
import simplejson as json
from gffutils import constants
from gffutils import helpers
Expand Down Expand Up @@ -166,7 +165,7 @@ def __init__(
# for testing.
attributes = attributes or dict_class()

if isinstance(attributes, six.string_types):
if isinstance(attributes, str):
try:
attributes = helpers._unjsonify(attributes, isattributes=True)

Expand All @@ -182,7 +181,7 @@ def __init__(
# If string, then try un-JSONifying it into a list; if that doesn't
# work then assume it's tab-delimited and convert to a list.
extra = extra or []
if isinstance(extra, six.string_types):
if isinstance(extra, str):
try:
extra = helpers._unjsonify(extra)
except json.JSONDecodeError:
Expand Down Expand Up @@ -254,10 +253,7 @@ def __setitem__(self, key, value):
self.attributes[key] = value

def __str__(self):
if six.PY3:
return self.__unicode__()
else:
return unicode(self).encode("utf-8")
return self.__unicode__()

def __unicode__(self):

Expand Down Expand Up @@ -387,7 +383,7 @@ def sequence(self, fasta, use_strand=True):
-------
string
"""
if isinstance(fasta, six.string_types):
if isinstance(fasta, str):
fasta = Fasta(fasta, as_raw=False)

# recall GTF/GFF is 1-based closed; pyfaidx uses Python slice notation
Expand Down
3 changes: 1 addition & 2 deletions gffutils/gffwriter.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
##
## GFF Writer (writer): serializing gffutils records as GFF text files.
##
import six
import tempfile
import shutil
from time import strftime, localtime
Expand Down Expand Up @@ -41,7 +40,7 @@ def __init__(self, out, with_header=True, in_place=False):
self.temp_file = None
# Output stream to write to
self.out_stream = None
if isinstance(out, six.string_types):
if isinstance(out, str):
if self.in_place:
# Use temporary file
self.temp_file = tempfile.NamedTemporaryFile(delete=False)
Expand Down
15 changes: 7 additions & 8 deletions gffutils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import simplejson as json
import time
import tempfile
import six
from gffutils import constants
from gffutils import bins
import gffutils
Expand Down Expand Up @@ -202,7 +201,7 @@ def make_query(
# e.g., "featuretype = 'exon'"
#
# or, "featuretype IN ('exon', 'CDS')"
if isinstance(featuretype, six.string_types):
if isinstance(featuretype, str):
d["FEATURETYPE"] = "features.featuretype = ?"
args.append(featuretype)
else:
Expand All @@ -218,7 +217,7 @@ def make_query(
# `limit` is a string or a tuple of (chrom, start, stop)
#
# e.g., "seqid = 'chr2L' AND start > 1000 AND end < 5000"
if isinstance(limit, six.string_types):
if isinstance(limit, str):
seqid, startstop = limit.split(":")
start, end = startstop.split("-")
else:
Expand Down Expand Up @@ -257,7 +256,7 @@ def make_query(
# Default is essentially random order.
#
# e.g. "ORDER BY seqid, start DESC"
if isinstance(order_by, six.string_types):
if isinstance(order_by, str):
_order_by.append(order_by)

else:
Expand Down Expand Up @@ -387,7 +386,7 @@ def merge_attributes(attr1, attr2, numeric_sort=False):
if not isinstance(v, list):
new_d[k] = [v]

for k, v in six.iteritems(attr1):
for k, v in attr1.items():
if k in attr2:
if not isinstance(v, list):
v = [v]
Expand Down Expand Up @@ -507,9 +506,9 @@ def is_gff_db(db_fname):


def to_unicode(obj, encoding="utf-8"):
if isinstance(obj, six.string_types):
if not isinstance(obj, six.text_type):
obj = six.text_type(obj, encoding)
if isinstance(obj, str):
if not isinstance(obj, str):
obj = str(obj, encoding)
return obj


Expand Down
17 changes: 8 additions & 9 deletions gffutils/interface.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import collections
import os
import six
import sqlite3
import shutil
import warnings
Expand Down Expand Up @@ -694,7 +693,7 @@ def region(
"If region is supplied, do not supply seqid, "
"start, or end as separate kwargs"
)
if isinstance(region, six.string_types):
if isinstance(region, str):
toks = region.split(":")
if len(toks) == 1:
seqid = toks[0]
Expand Down Expand Up @@ -774,7 +773,7 @@ def region(

# Add the featuretype clause
if featuretype is not None:
if isinstance(featuretype, six.string_types):
if isinstance(featuretype, str):
featuretype = [featuretype]
feature_clause = " or ".join(["featuretype = ?" for _ in featuretype])
query += " AND (%s) " % feature_clause
Expand Down Expand Up @@ -994,7 +993,7 @@ def delete(self, features, make_backup=True, **kwargs):
FeatureDB object, with features deleted.
"""
if make_backup:
if isinstance(self.dbfn, six.string_types):
if isinstance(self.dbfn, str):
shutil.copy2(self.dbfn, self.dbfn + ".bak")

c = self.conn.cursor()
Expand All @@ -1006,12 +1005,12 @@ def delete(self, features, make_backup=True, **kwargs):
"""
if isinstance(features, FeatureDB):
features = features.all_features()
if isinstance(features, six.string_types):
if isinstance(features, str):
features = [features]
if isinstance(features, Feature):
features = [features]
for feature in features:
if isinstance(feature, six.string_types):
if isinstance(feature, str):
_id = feature
else:
_id = feature.id
Expand Down Expand Up @@ -1060,7 +1059,7 @@ def update(self, data, make_backup=True, **kwargs):
from gffutils import iterators

if make_backup:
if isinstance(self.dbfn, six.string_types):
if isinstance(self.dbfn, str):
shutil.copy2(self.dbfn, self.dbfn + ".bak")

# get iterator-specific kwargs
Expand Down Expand Up @@ -1139,9 +1138,9 @@ def child_func(parent, child):
-------
FeatureDB object with new relations added.
"""
if isinstance(parent, six.string_types):
if isinstance(parent, str):
parent = self[parent]
if isinstance(child, six.string_types):
if isinstance(child, str):
child = self[child]

c = self.conn.cursor()
Expand Down
15 changes: 5 additions & 10 deletions gffutils/iterators.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,8 @@
from gffutils.interface import FeatureDB
from gffutils import helpers
from textwrap import dedent
import six
from six.moves.urllib.request import urlopen

if six.PY3:
from urllib import parse as urlparse
else:
import urlparse
from urllib.request import urlopen
from urllib import parse as urlparse


class Directive(object):
Expand Down Expand Up @@ -133,7 +128,7 @@ def _custom_iter(self):
valid_lines = 0
with self.open_function(self.data) as fh:
for i, line in enumerate(fh):
if isinstance(line, six.binary_type):
if isinstance(line, bytes):
line = line.decode("utf-8")
line = line.rstrip("\n\r")
self.current_item = line
Expand Down Expand Up @@ -295,11 +290,11 @@ def DataIterator(
force_dialect_check=force_dialect_check,
**kwargs,
)
if isinstance(data, six.string_types):
if isinstance(data, str):
if from_string:
tmp = tempfile.NamedTemporaryFile(delete=False)
data = dedent(data)
if isinstance(data, six.text_type):
if isinstance(data, str):
data = data.encode("utf-8")
tmp.write(data)
tmp.close()
Expand Down
2 changes: 1 addition & 1 deletion gffutils/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import re
import copy
import collections
from six.moves import urllib
import urllib
from gffutils import constants
from gffutils.exceptions import AttributeStringError

Expand Down
3 changes: 1 addition & 2 deletions gffutils/pybedtools_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import pybedtools
from pybedtools import featurefuncs
from gffutils import helpers
import six


def to_bedtool(iterator):
Expand Down Expand Up @@ -210,7 +209,7 @@ def gen():

if merge_overlapping or as_bed6:

if isinstance(attrs, six.string_types):
if isinstance(attrs, str):
attrs = [attrs]

def to_bed(f):
Expand Down
2 changes: 0 additions & 2 deletions gffutils/scripts/gffutils-cli
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/usr/bin/python

from __future__ import print_function

"""
Command line interface for gffutils.
Expand Down
Loading

0 comments on commit 308f956

Please sign in to comment.