Skip to content

Commit 84be9a0

Browse files
committed
Fixing an issue with singleton files
1 parent 3985483 commit 84be9a0

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

neat/read_simulator/utils/output_file_writer.py

+14-14
Original file line numberDiff line numberDiff line change
@@ -218,30 +218,30 @@ def merge_temp_fastqs(
218218
# Either both will have data, or neither, so checking one is sufficient
219219
if file1_index:
220220
if contig_name not in fastq_index_dict:
221-
fastq_index_dict[contig_name] = []
221+
fastq_index_dict[contig_name] = {}
222222
# 1 and 2 for read 1 and read 2
223223
fastq_index_dict[contig_name] = {1: file1_index, 2: file2_index}
224224
paired_keys.extend(list(zip(file1_index, file2_index)))
225225

226226
# Index the singletons, or for single-ended reads, all reads
227227
for file_pair in singleton_files:
228-
if file_pair[0]:
229-
file_index = SeqIO.index(str(file_pair[0]), 'fastq')
228+
file_index_r1 = SeqIO.index(str(file_pair[0]), 'fastq')
229+
file_index_r2 = SeqIO.index(str(file_pair[1]), 'fastq')
230+
if file_index_r1:
231+
file_index = file_index_r1
230232
contig_name = Path(file_pair[0]).name.removesuffix('_r1_single.fq.bgz')
231-
elif file_pair[1]:
232-
file_index = SeqIO.index(str(file_pair[1]), 'fastq')
233+
elif file_index_r2:
234+
file_index = file_index_r2
233235
contig_name = Path(file_pair[1]).name.removesuffix('_r2_single.fq.bgz')
234236
else:
235-
# So singletons for this contig, so move on
237+
# No singletons for this contig, so move on
236238
continue
237239

238-
# A check in case all reads were properly paired and there are no singletons
239-
if file_index:
240-
if contig_name not in fastq_index_dict:
241-
fastq_index_dict[contig_name] = []
242-
# To keep the data structure consistent, we point both keys at the same file
243-
fastq_index_dict[contig_name] = {1: file_index, 2: file_index}
244-
singleton_keys.extend(list(file_index))
240+
if contig_name not in fastq_index_dict:
241+
fastq_index_dict[contig_name] = {}
242+
# To keep the data structure consistent, we point both keys at the same file
243+
fastq_index_dict[contig_name][3] = file_index
244+
singleton_keys.extend(list(file_index))
245245

246246
shuffled_paired_keys = paired_keys.copy()
247247
shuffled_singleton_keys = singleton_keys.copy()
@@ -279,7 +279,7 @@ def merge_temp_fastqs(
279279
chrom_name_with_rdnm = current_key.removeprefix("NEAT-generated_").split('/')[0]
280280
suffix = re.findall(r"_\d*$", chrom_name_with_rdnm)[0]
281281
chrom_name = chrom_name_with_rdnm.removesuffix(suffix)
282-
read = fastq_index_dict[chrom_name][1][current_key]
282+
read = fastq_index_dict[chrom_name][3][current_key]
283283
SeqIO.write(read, fq1, 'fastq')
284284

285285
_LOG.info(f"Fastq(s) written in {(time.time() - t)/60:.2f} m")

0 commit comments

Comments
 (0)