From: Diane Trout Date: Fri, 20 Mar 2015 20:47:36 +0000 (-0700) Subject: Specify text vs binary mode for opening files. X-Git-Url: http://woldlab.caltech.edu/gitweb/?p=htsworkflow.git;a=commitdiff_plain;h=3c442a662e3553dbb3b70da4e95bdc3c1625cf20 Specify text vs binary mode for opening files. (And another smart_text cast sliped in) --- diff --git a/experiments/views.py b/experiments/views.py index e5f675d..7d30bbe 100644 --- a/experiments/views.py +++ b/experiments/views.py @@ -176,7 +176,7 @@ def read_result_file(self, key): content_type = data_file.file_type.mimetype if os.path.exists(data_file.pathname): - return HttpResponse(open(data_file.pathname,'r'), + return HttpResponse(open(data_file.pathname,'rb'), content_type=content_type) raise Http404 diff --git a/htsworkflow/pipelines/eland.py b/htsworkflow/pipelines/eland.py index b9a7ca3..3298ae4 100644 --- a/htsworkflow/pipelines/eland.py +++ b/htsworkflow/pipelines/eland.py @@ -150,7 +150,7 @@ class ElandLane(ResultLane): self._reads = 0 for pathname in self.pathnames: - stream = autoopen(pathname, 'r') + stream = autoopen(pathname, 'rt') if self.eland_type == ELAND_SINGLE: result = self._update_eland_result(stream) elif self.eland_type == ELAND_MULTI or \ @@ -548,7 +548,7 @@ class SequenceLane(ResultLane): """ Determine if we have a scarf or fastq sequence file """ - f = open(pathname,'r') + f = open(pathname,'rt') l = f.readline() f.close() @@ -575,8 +575,8 @@ class SequenceLane(ResultLane): LOGGER.info("summarizing results for %s" % (pathname)) lines = 0 - f = open(pathname) - for l in f.xreadlines(): + f = open(pathname, 'rt') + for l in f: lines += 1 f.close() diff --git a/htsworkflow/submission/daf.py b/htsworkflow/submission/daf.py index 9c4b30e..b2d7419 100644 --- a/htsworkflow/submission/daf.py +++ b/htsworkflow/submission/daf.py @@ -270,7 +270,7 @@ class UCSCSubmission(object): self.daf = daf_file.read() else: # file - stream = open(daf_file, 'r') + stream = open(daf_file, 'rt') self.daf = stream.read() stream.close() diff --git a/htsworkflow/util/hashfile.py b/htsworkflow/util/hashfile.py index 9762883..c6cc0f9 100644 --- a/htsworkflow/util/hashfile.py +++ b/htsworkflow/util/hashfile.py @@ -14,7 +14,7 @@ def make_md5sum(filename): md5_cache = os.path.join(filename+".md5") if os.path.exists(md5_cache): logger.debug("Found md5sum in {0}".format(md5_cache)) - stream = open(md5_cache,'r') + stream = open(md5_cache,'rt') lines = stream.readlines() md5sum = parse_md5sum_line(lines, filename) else: @@ -35,13 +35,13 @@ def make_md5sum_unix(filename, md5_cache): md5sum = parse_md5sum_line(lines, filename) if md5sum is not None: logger.debug("Caching sum in {0}".format(md5_cache)) - stream = open(md5_cache, "w") - stream.write(stdin) + stream = open(md5_cache, "wt") + stream.write(smart_text(stdin)) stream.close() return md5sum def parse_md5sum_line(lines, filename): - md5sum, md5sum_filename = lines[0].split() + md5sum, md5sum_filename = smart_text(lines[0]).split() md5sum_filename = os.path.basename(md5sum_filename) filename = os.path.basename(filename) if md5sum_filename != filename: diff --git a/htsworkflow/util/rdfhelp.py b/htsworkflow/util/rdfhelp.py index 33197dd..ea1020c 100644 --- a/htsworkflow/util/rdfhelp.py +++ b/htsworkflow/util/rdfhelp.py @@ -344,7 +344,7 @@ def add_default_schemas(model, schema_path=None): for path in schema_path: for pathname in glob(os.path.join(path, '*.turtle')): url = 'file://' + os.path.splitext(pathname)[0] - stream = open(pathname, 'r') + stream = open(pathname, 'rt') add_schema(model, stream, url) stream.close()