projects
/
htsworkflow.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
3c442a6
)
Use isinstance(object, (types)) pattern instead of type(object) == types.Type
author
Diane Trout
<diane@ghic.org>
Fri, 20 Mar 2015 21:13:54 +0000
(14:13 -0700)
committer
Diane Trout
<diane@ghic.org>
Fri, 20 Mar 2015 21:13:54 +0000
(14:13 -0700)
htsworkflow/pipelines/retrieve_config.py
patch
|
blob
|
history
htsworkflow/pipelines/sequences.py
patch
|
blob
|
history
htsworkflow/pipelines/summary.py
patch
|
blob
|
history
htsworkflow/submission/condorfastq.py
patch
|
blob
|
history
htsworkflow/submission/daf.py
patch
|
blob
|
history
htsworkflow/submission/encoded.py
patch
|
blob
|
history
htsworkflow/util/rdfhelp.py
patch
|
blob
|
history
htsworkflow/util/test/test_rdfhelp.py
patch
|
blob
|
history
samples/models.py
patch
|
blob
|
history
diff --git
a/htsworkflow/pipelines/retrieve_config.py
b/htsworkflow/pipelines/retrieve_config.py
index c8fa9d23021a0de0a7acbbc52fce5cfd2a7d1c99..26ff2d1cec0dab22467e97b9b486d0fe554459f3 100644
(file)
--- a/
htsworkflow/pipelines/retrieve_config.py
+++ b/
htsworkflow/pipelines/retrieve_config.py
@@
-7,8
+7,7
@@
from optparse import OptionParser, IndentedHelpFormatter
import os
import sys
import types
import os
import sys
import types
-import urllib
-import urllib2
+import six
try:
import json
try:
import json
@@
-403,12
+402,11
@@
def format_pooled_libraries(shared, library):
sequences = library.get('index_sequence', None)
if sequences is None:
return []
sequences = library.get('index_sequence', None)
if sequences is None:
return []
- elif (type(sequences) in types.StringTypes and
- sequences.lower().startswith('err')):
+ elif isinstance(sequences, six.string_types):
shared['Index'] = ''
shared['SampleProject'] = library['library_id']
return [shared]
shared['Index'] = ''
shared['SampleProject'] = library['library_id']
return [shared]
- elif
(type(sequences) == types.DictType
):
+ elif
isinstance(sequences, dict
):
pooled = []
multiplex_ids = sequences.keys()
multiplex_ids.sort(key=natural_sort_key)
pooled = []
multiplex_ids = sequences.keys()
multiplex_ids.sort(key=natural_sort_key)
diff --git
a/htsworkflow/pipelines/sequences.py
b/htsworkflow/pipelines/sequences.py
index 17e65cf91d6ce9f848ca18947ee2ed279e8b3c8c..1d746c9844f8a82a15a586f76b8baa65dd594b9a 100644
(file)
--- a/
htsworkflow/pipelines/sequences.py
+++ b/
htsworkflow/pipelines/sequences.py
@@
-7,6
+7,7
@@
import os
import types
import re
import sys
import types
import re
import sys
+import six
from six.moves.urllib.parse import urljoin, urlparse
import RDF
from six.moves.urllib.parse import urljoin, urlparse
import RDF
@@
-376,7
+377,7
@@
def scan_for_sequences(dirs):
Scan through a list of directories for sequence like files
"""
sequences = []
Scan through a list of directories for sequence like files
"""
sequences = []
- if
type(dirs) in types.StringTypes
:
+ if
isinstance(dirs, six.string_types)
:
raise ValueError("You probably want a list or set, not a string")
for d in dirs:
raise ValueError("You probably want a list or set, not a string")
for d in dirs:
diff --git
a/htsworkflow/pipelines/summary.py
b/htsworkflow/pipelines/summary.py
index c1108a2e83abf25661bcf779f44bd87e3c7cca74..8c3ec7747b551e011fae474ef257f9a276a7ba69 100644
(file)
--- a/
htsworkflow/pipelines/summary.py
+++ b/
htsworkflow/pipelines/summary.py
@@
-6,7
+6,6
@@
from __future__ import print_function, unicode_literals
import os
import logging
import re
import os
import logging
import re
-import types
from pprint import pprint
from lxml import html
from pprint import pprint
from lxml import html
@@
-287,8
+286,7
@@
class LaneResultSummary(object):
value = getattr(self, variable_name)
if value is None:
continue
value = getattr(self, variable_name)
if value is None:
continue
- # it looks like a sequence
- elif type(value) in (types.TupleType, types.ListType):
+ elif isinstance(value, (tuple, list)):
element = make_mean_range_element(
lane_result,
tag,
element = make_mean_range_element(
lane_result,
tag,
diff --git
a/htsworkflow/submission/condorfastq.py
b/htsworkflow/submission/condorfastq.py
index 705d47e0412587b287010985c90b2469f325cca2..8c35e57f88aae3984c202c35dde01f18a263de99 100644
(file)
--- a/
htsworkflow/submission/condorfastq.py
+++ b/
htsworkflow/submission/condorfastq.py
@@
-5,6
+5,7
@@
import os
from pprint import pformat,pprint
import sys
import types
from pprint import pformat,pprint
import sys
import types
+import six
from six.moves.urllib.parse import urljoin, urlparse
from htsworkflow.pipelines.sequences import scan_for_sequences, \
from six.moves.urllib.parse import urljoin, urlparse
from htsworkflow.pipelines.sequences import scan_for_sequences, \
@@
-335,7
+336,7
@@
class SequenceResult(object):
self.cycle = fromTypedNode(result['cycle'])
self.lane_number = fromTypedNode(result['lane_number'])
self.read = fromTypedNode(result['read'])
self.cycle = fromTypedNode(result['cycle'])
self.lane_number = fromTypedNode(result['lane_number'])
self.read = fromTypedNode(result['read'])
- if
type(self.read) in types.StringTypes
:
+ if
isinstance(self.read, six.string_types)
:
self.read = 1
self.library = result['library']
self.library_id = fromTypedNode(result['library_id'])
self.read = 1
self.library = result['library']
self.library_id = fromTypedNode(result['library_id'])
diff --git
a/htsworkflow/submission/daf.py
b/htsworkflow/submission/daf.py
index b2d7419784e0ebf257b688b9867cecdfee3bed22..90993def35d8058618325fdf9d0c114f527e7e19 100644
(file)
--- a/
htsworkflow/submission/daf.py
+++ b/
htsworkflow/submission/daf.py
@@
-1,5
+1,6
@@
"""Parse UCSC DAF File
"""
"""Parse UCSC DAF File
"""
+import collections
import logging
import os
from pprint import pformat
import logging
import os
from pprint import pformat
@@
-265,7
+266,7
@@
class UCSCSubmission(object):
else:
self.model = get_model()
else:
self.model = get_model()
- if
hasattr(daf_file, 'next'
):
+ if
isinstance(daf_file, collections.Iterable
):
# its some kind of stream
self.daf = daf_file.read()
else:
# its some kind of stream
self.daf = daf_file.read()
else:
diff --git
a/htsworkflow/submission/encoded.py
b/htsworkflow/submission/encoded.py
index 334a03f24db2ec7945aa34d94aff41cdc60c8df0..5a7866f7c35cde54f73f33b4f5ea0e85ffcab12f 100644
(file)
--- a/
htsworkflow/submission/encoded.py
+++ b/
htsworkflow/submission/encoded.py
@@
-11,7
+11,7
@@
import json
import jsonschema
import os
import requests
import jsonschema
import os
import requests
-import
types
+import
six
from six.moves.urllib.parse import urljoin, urlparse, urlunparse
LOGGER = logging.getLogger(__name__)
from six.moves.urllib.parse import urljoin, urlparse, urlunparse
LOGGER = logging.getLogger(__name__)
@@
-132,7
+132,7
@@
class ENCODED:
and I needed a way to properly compute a the correct base URL.
'''
# pretend strings aren't iterable
and I needed a way to properly compute a the correct base URL.
'''
# pretend strings aren't iterable
- if
type(obj) in types.StringTypes
:
+ if
isinstance(obj, six.string_types)
:
return
# recurse on container types
return
# recurse on container types
@@
-223,7
+223,7
@@
class ENCODED:
obj_type = obj.get('@type')
if not obj_type:
raise ValueError('None type')
obj_type = obj.get('@type')
if not obj_type:
raise ValueError('None type')
- if
type(obj_type) in types.StringTypes
:
+ if
isinstance(obj_type, six.string_types)
:
raise ValueError('@type should be a list, not a string')
if not isinstance(obj_type, collections.Sequence):
raise ValueError('@type is not a sequence')
raise ValueError('@type should be a list, not a string')
if not isinstance(obj_type, collections.Sequence):
raise ValueError('@type is not a sequence')
diff --git
a/htsworkflow/util/rdfhelp.py
b/htsworkflow/util/rdfhelp.py
index ea1020c7b28fde8e4213b960afb7b90233d40300..ebd2d2695781a5166d2955aefdc2be9375a5af9d 100644
(file)
--- a/
htsworkflow/util/rdfhelp.py
+++ b/
htsworkflow/util/rdfhelp.py
@@
-5,6
+5,7
@@
from __future__ import print_function
import collections
from datetime import datetime
from glob import glob
import collections
from datetime import datetime
from glob import glob
+import six
from six.moves import urllib
import logging
import os
from six.moves import urllib
import logging
import os
@@
-78,7
+79,7
@@
def blankOrUri(value=None):
node = None
if value is None:
node = RDF.Node()
node = None
if value is None:
node = RDF.Node()
- elif
type(value) in types.StringTypes
:
+ elif
isinstance(value, six.string_types)
:
node = RDF.Node(uri_string=value)
elif isinstance(value, RDF.Node):
node = value
node = RDF.Node(uri_string=value)
elif isinstance(value, RDF.Node):
node = value
@@
-89,16
+90,16
@@
def blankOrUri(value=None):
def toTypedNode(value, language="en"):
"""Convert a python variable to a RDF Node with its closest xsd type
"""
def toTypedNode(value, language="en"):
"""Convert a python variable to a RDF Node with its closest xsd type
"""
- if
type(value) == types.BooleanType
:
+ if
isinstance(value, bool)
:
value_type = xsdNS['boolean'].uri
if value:
value = u'1'
else:
value = u'0'
value_type = xsdNS['boolean'].uri
if value:
value = u'1'
else:
value = u'0'
- elif
type(value) in (types.IntType, types.LongType
):
+ elif
isinstance(value, int
):
value_type = xsdNS['decimal'].uri
value = unicode(value)
value_type = xsdNS['decimal'].uri
value = unicode(value)
- elif
type(value) == types.FloatType
:
+ elif
isinstance(value, float)
:
value_type = xsdNS['float'].uri
value = unicode(value)
elif isinstance(value, datetime):
value_type = xsdNS['float'].uri
value = unicode(value)
elif isinstance(value, datetime):
@@
-252,7
+253,7
@@
def get_model(model_name=None, directory=None, use_contexts=True):
def load_into_model(model, parser_name, path, ns=None):
def load_into_model(model, parser_name, path, ns=None):
- if
type(ns) in types.StringTypes
:
+ if
isinstance(ns, six.string_types)
:
ns = RDF.Uri(ns)
if isinstance(path, RDF.Node):
ns = RDF.Uri(ns)
if isinstance(path, RDF.Node):
@@
-304,7
+305,7
@@
def load_string_into_model(model, parser_name, data, ns=None):
def fixup_namespace(ns):
if ns is None:
ns = RDF.Uri("http://localhost/")
def fixup_namespace(ns):
if ns is None:
ns = RDF.Uri("http://localhost/")
- elif
type(ns) in types.StringTypes
:
+ elif
isinstance(ns, six.string_types)
:
ns = RDF.Uri(ns)
elif not(isinstance(ns, RDF.Uri)):
errmsg = "Namespace should be string or uri not {0}"
ns = RDF.Uri(ns)
elif not(isinstance(ns, RDF.Uri)):
errmsg = "Namespace should be string or uri not {0}"
diff --git
a/htsworkflow/util/test/test_rdfhelp.py
b/htsworkflow/util/test/test_rdfhelp.py
index 2ea38daa6966a1956af54167c0a0dba4c669fd2c..c71d3d76899c04e0ea9e6afa3413d8d6366cd566 100644
(file)
--- a/
htsworkflow/util/test/test_rdfhelp.py
+++ b/
htsworkflow/util/test/test_rdfhelp.py
@@
-3,8
+3,8
@@
from __future__ import print_function
import os
import types
from unittest import TestCase
import os
import types
from unittest import TestCase
-
from datetime import datetime
from datetime import datetime
+import six
from htsworkflow.util.rdfhelp import \
add_default_schemas, \
from htsworkflow.util.rdfhelp import \
add_default_schemas, \
@@
-69,7
+69,7
@@
try:
s = "Argh matey"
node = toTypedNode(s)
self.assertEqual(fromTypedNode(node), s)
s = "Argh matey"
node = toTypedNode(s)
self.assertEqual(fromTypedNode(node), s)
- self.assert
Equal(type(fromTypedNode(node)), types.UnicodeType
)
+ self.assert
True(isinstance(fromTypedNode(node), six.text_type)
)
def test_blank_or_uri_blank(self):
node = blankOrUri()
def test_blank_or_uri_blank(self):
node = blankOrUri()
@@
-90,8
+90,7
@@
try:
def test_unicode_node_roundtrip(self):
literal = u'\u5927'
roundtrip = fromTypedNode(toTypedNode(literal))
def test_unicode_node_roundtrip(self):
literal = u'\u5927'
roundtrip = fromTypedNode(toTypedNode(literal))
- self.assertEqual(roundtrip, literal)
- self.assertEqual(type(roundtrip), types.UnicodeType)
+ self.assertTrue(isinstance(roundtrip, six.text_type))
def test_datetime_no_microsecond(self):
dateTimeType = xsdNS['dateTime'].uri
def test_datetime_no_microsecond(self):
dateTimeType = xsdNS['dateTime'].uri
diff --git
a/samples/models.py
b/samples/models.py
index 94cd075bd641b2ad949b080a253289e31549236d..eaa433b7f86caf6367b3d036e8805cba96f8bdf4 100644
(file)
--- a/
samples/models.py
+++ b/
samples/models.py
@@
-7,6
+7,7
@@
from django.contrib.auth.models import User, UserManager
from django.core import urlresolvers
from django.db.models.signals import pre_save, post_save
from django.db import connection
from django.core import urlresolvers
from django.db.models.signals import pre_save, post_save
from django.db import connection
+import six
logger = logging.getLogger(__name__)
logger = logging.getLogger(__name__)
@@
-281,7
+282,7
@@
class Library(models.Model):
sequences = self.index_sequences()
if sequences is None:
return ""
sequences = self.index_sequences()
if sequences is None:
return ""
- if
type(sequences) in types.StringTypes
:
+ if
isinstance(sequences, six.string_types)
:
return sequences
multiplex_ids = sequences.keys()
multiplex_ids.sort()
return sequences
multiplex_ids = sequences.keys()
multiplex_ids.sort()