@@ -218,30 +218,30 @@ def merge_temp_fastqs(
218
218
# Either both will have data, or neither, so checking one is sufficient
219
219
if file1_index :
220
220
if contig_name not in fastq_index_dict :
221
- fastq_index_dict [contig_name ] = []
221
+ fastq_index_dict [contig_name ] = {}
222
222
# 1 and 2 for read 1 and read 2
223
223
fastq_index_dict [contig_name ] = {1 : file1_index , 2 : file2_index }
224
224
paired_keys .extend (list (zip (file1_index , file2_index )))
225
225
226
226
# Index the singletons, or for single-ended reads, all reads
227
227
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
230
232
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
233
235
contig_name = Path (file_pair [1 ]).name .removesuffix ('_r2_single.fq.bgz' )
234
236
else :
235
- # So singletons for this contig, so move on
237
+ # No singletons for this contig, so move on
236
238
continue
237
239
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 ))
245
245
246
246
shuffled_paired_keys = paired_keys .copy ()
247
247
shuffled_singleton_keys = singleton_keys .copy ()
@@ -279,7 +279,7 @@ def merge_temp_fastqs(
279
279
chrom_name_with_rdnm = current_key .removeprefix ("NEAT-generated_" ).split ('/' )[0 ]
280
280
suffix = re .findall (r"_\d*$" , chrom_name_with_rdnm )[0 ]
281
281
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 ]
283
283
SeqIO .write (read , fq1 , 'fastq' )
284
284
285
285
_LOG .info (f"Fastq(s) written in { (time .time () - t )/ 60 :.2f} m" )
0 commit comments