Commit 876086e8 authored by Penom Nom's avatar Penom Nom
Browse files

remove xopen file and add xopen to seqio

parent 3f3ba262
import os
import re
from jflow.xopen import xopen
from jflow.seqio import xopen
from jflow.seqio import FormatError
from jflow.seqio import UnknownFileType
......
import os
import re
from jflow.xopen import xopen
from jflow.seqio import FormatError
from jflow.seqio import UnknownFileType
......
import os
import re
from jflow.xopen import xopen
from jflow.seqio import FormatError
from jflow.seqio import UnknownFileType
......
import os
import re
from jflow.xopen import xopen
from jflow.seqio import FormatError
from jflow.seqio import UnknownFileType
......
import os
import re
from jflow.xopen import xopen
from jflow.seqio import xopen
from jflow.seqio import FormatError
from jflow.seqio import UnknownFileType
......
import os
import re
from jflow.xopen import xopen
from jflow.seqio import FormatError
from jflow.seqio import UnknownFileType
......
......@@ -27,13 +27,20 @@ from collections import namedtuple
import sys
import struct
import os
import io
if sys.version_info[0] < 3:
from itertools import izip as zip
else:
basestring = str
from codecs import getreader, getwriter
if sys.version_info < (2, 7):
buffered_reader = lambda x: x
else:
buffered_reader = io.BufferedReader
from os.path import splitext
import sys, gzip
import sys, gzip, bz2
def xopen(filename, mode='r'):
......@@ -49,12 +56,23 @@ def xopen(filename, mode='r'):
return sys.stdin if 'r' in mode else sys.stdout
if filename.endswith('.gz'):
if sys.version_info[0] < 3:
return gzip.open(filename, mode)
if 'r' in mode:
return buffered_reader(gzip.open(filename, mode))
else:
return gzip.open(filename, mode)
else:
if 'r' in mode:
return getreader('ascii')(gzip.open(filename, mode))
else:
return getwriter('ascii')(gzip.open(filename, mode))
elif filename.endswith('.bz2'):
if sys.version_info[0] < 3:
return bz2.BZ2File(filename, mode)
else:
if 'r' in mode:
return getreader('ascii')(bz2.BZ2File(filename, mode))
else:
return getwriter('ascii')(bz2.BZ2File(filename, mode))
else:
return open(filename, mode)
......
#
# Copyright (C) 2012 INRA
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
__author__ = 'Marcel Martin'
import gzip
import sys
import io
import sys
if sys.version_info[0] >= 3:
basestring = str
from codecs import getreader, getwriter
if sys.version_info < (2, 7):
buffered_reader = lambda x: x
else:
buffered_reader = io.BufferedReader
def xopen(filename, mode='r'):
"""
Replacement for the "open" function that can also open
files that have been compressed with gzip. If the filename ends with .gz,
the file is opened with gzip.open(). If it doesn't, the regular open()
is used. If the filename is '-', standard output (mode 'w') or input
(mode 'r') is returned.
"""
assert isinstance(filename, basestring)
if filename == '-':
return sys.stdin if 'r' in mode else sys.stdout
if filename.endswith('.gz'):
if sys.version_info[0] < 3:
if 'r' in mode:
return buffered_reader(gzip.open(filename, mode))
else:
return gzip.open(filename, mode)
else:
if 'r' in mode:
return getreader('ascii')(gzip.open(filename, mode))
else:
return getwriter('ascii')(gzip.open(filename, mode))
else:
return open(filename, mode)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment