Skip to content

Commit

Permalink
conversion of binary string to normal string added
Browse files Browse the repository at this point in the history
  • Loading branch information
bpucker authored Dec 2, 2022
1 parent 94883db commit 85b2ea6
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions LRW.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
### Boas Pucker ###
### b.pucker@tu-bs.de ###
### v0.21 ###
### v0.22 ###
### Long Read Walker (LRW) ###

#USE FILTLONG to reduce coverage to 5x ???
Expand Down Expand Up @@ -218,12 +218,13 @@ def get_read_file_type( read_file ):

if read_file.split('.')[-1] in [ "gz", "gzip", "GZ", "GZIP" ]: #compressed read input file
with gzip.open( read_file, "rb" ) as f:
line = f.readline()
line = f.readline().decode('ascii')
if line[0] == ">":
return "fasta"
elif line[0] == "@":
return "fastq"
else:
print( line )
sys.exit( "ERROR: read input file type not recognized" )
else:
with open( read_file, "r" ) as f:
Expand All @@ -242,7 +243,7 @@ def load_sequences_fastq( read_file ):
sequences = {}
if read_file.split('.')[-1] in [ "gz", "gzip", "GZ", "GZIP" ]: #compressed read input file
with gzip.open( read_file, "rb" ) as f:
line = f.readline()
line = f.readline().decode('ascii')
while line:
header = line.strip()
if " " in header:
Expand All @@ -251,7 +252,7 @@ def load_sequences_fastq( read_file ):
sequences.update( { header: seq } )
f.readline() #useless row
f.readline() #quality row
line = f.readline()
line = f.readline().decode('ascii')
else: #uncompressed read input file
with open( read_file, "r" ) as f:
line = f.readline()
Expand All @@ -274,12 +275,12 @@ def fastq2fasta( read_file, output_folder ):
if read_file.split('.')[-1] in [ "gz", "gzip", "GZ", "GZIP" ]: #compressed read input file
with open( fasta_file, "w" ) as out:
with gzip.open( read_file, "rb" ) as f:
line = f.readline()
line = f.readline().decode('ascii')
while line:
out.write( '>' + line + f.readline() )
out.write( '>' + line + f.readline().decode('ascii') )
f.readline() #useless line
f.readline() #sequence quality
line = f.readline()
line = f.readline().decode('ascii')
else:
with open( fasta_file, "w" ) as out:
with open( read_file, "r" ) as f:
Expand Down

0 comments on commit 85b2ea6

Please sign in to comment.