Skip to content

Commit 680e56a

Browse files
committed
fix: count reads in fastq without zcat
1 parent e78e7ea commit 680e56a

File tree

2 files changed

+7
-18
lines changed

2 files changed

+7
-18
lines changed

hicstuff/io.py

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,7 +1435,7 @@ def check_is_fasta(in_file):
14351435

14361436
def check_fastq_entries(in_file):
14371437
"""
1438-
Check how many reads are in the input fastq. Requires zcat.
1438+
Check how many reads are in the input fastq.
14391439
14401440
Parameters
14411441
----------
@@ -1450,24 +1450,12 @@ def check_fastq_entries(in_file):
14501450

14511451
with open(in_file, 'rb') as f:
14521452
is_gzip = f.read(2) == b'\x1f\x8b'
1453-
14541453
if is_gzip:
1455-
n_lines = sp.run(
1456-
"zcat < {f} | wc -l".format(f = in_file),
1457-
stdout=sp.PIPE,
1458-
stderr=sp.PIPE,
1459-
shell = True,
1460-
encoding = 'utf-8'
1461-
).stdout[:-2].split(" ")[0]
1454+
with gzip.open(in_file, "rt") as input_fastq:
1455+
n_lines = sum(1 for line in input_fastq)
14621456
else:
1463-
n_lines = sp.run(
1464-
"wc -l {f}".format(f = in_file),
1465-
stdout=sp.PIPE,
1466-
stderr=sp.PIPE,
1467-
shell = True,
1468-
encoding = 'utf-8'
1469-
).stdout[:-2].split(" ")[0]
1470-
1457+
with open(in_file, "r") as input_fastq:
1458+
n_lines = sum(1 for line in input_fastq)
14711459
n_reads = int(n_lines)/4
14721460
return n_reads
14731461

hicstuff/pipeline.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,7 @@ def _out_file(fname):
886886
pairs_idx = input1
887887

888888
# Perform genome alignment
889+
nreads_input1 = 0
889890
if start_stage == 0:
890891

891892
# Check number of reads in both fastqs
@@ -895,7 +896,7 @@ def _out_file(fname):
895896
if (nreads_input1 != nreads_input2):
896897
logger.error("Fastq files do not have the same number of reads.")
897898
else:
898-
logger.info("{n} reads found in each fastq file.".format(n = nreads_input1))
899+
logger.info("{n} reads found in each fastq file.".format(n = int(nreads_input1)))
899900

900901
# Define mapping choice (default normal):
901902
if mapping == "normal":

0 commit comments

Comments
 (0)