Skip to content

Commit

Permalink
more py3 compatibility decode
Browse files Browse the repository at this point in the history
  • Loading branch information
llipkinMGH committed Dec 9, 2019
1 parent dd2d053 commit f3061be
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 6 additions & 0 deletions demultiplex.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def fq(file):
fastq = gzip.open(file, 'rb')
else:
fastq = open(file, 'r')
should_decode = sys.version_info[0] >= 3
with fastq as f:
while True:
l1 = f.readline()
Expand All @@ -32,6 +33,11 @@ def fq(file):
l2 = f.readline()
l3 = f.readline()
l4 = f.readline()
if should_decode:
l1 = l1.decode()
l2 = l2.decode()
l3 = l3.decode()
l4 = l4.decode()
yield [l1, l2, l3, l4]


Expand Down
10 changes: 8 additions & 2 deletions demultiplex_nobuff.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def fq(file):
fastq = gzip.open(file, 'rb')
else:
fastq = open(file, 'r')
should_decode = sys.version_info[0] >= 3
with fastq as f:
while True:
l1 = f.readline()
Expand All @@ -37,6 +38,11 @@ def fq(file):
l2 = f.readline()
l3 = f.readline()
l4 = f.readline()
if should_decode:
l1 = l1.decode()
l2 = l2.decode()
l3 = l3.decode()
l4 = l4.decode()
yield [l1, l2, l3, l4]


Expand Down Expand Up @@ -75,8 +81,8 @@ def add_file_to_dict(fname, d):
# helper functions
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def get_sample_name(i1,i2,id_array):
index1=i1[1][1:8] if sys.version_info[0] < 3 else i1[1].decode()[1:8]
index2=i2[1][1:8] if sys.version_info[0] < 3 else i2[1].decode()[1:8]
index1=i1[1][1:8] # if sys.version_info[0] < 3 else i1[1].decode()[1:8]
index2=i2[1][1:8] # if sys.version_info[0] < 3 else i2[1].decode()[1:8]
dictA=id_array[0]
dictP=id_array[1]
Aname=''
Expand Down

0 comments on commit f3061be

Please sign in to comment.