@@ -255,7 +255,8 @@ def write_read_pair_seqs(pair_count_by_type, pair_seqs_by_type, out_fs_by_type):
255
255
out_f = out_fs_by_type [pair_type ]
256
256
with open (out_f , 'w' ) as out_fh :
257
257
print BtLog .status_d ['24' ] % out_f
258
- out_fh .write ("\n " .join (pair_seqs_by_type [pair_type ]) + "\n " )
258
+ #out_fh.write("\n".join(pair_seqs_by_type[pair_type]) + "\n")
259
+ out_fh .write ("\n " .join ([pair for pair in pair_seqs_by_type [pair_type ]]) + "\n " )
259
260
260
261
261
262
def get_read_pair_seqs (read1 , read2 ):
@@ -278,7 +279,8 @@ def get_read_pair_seqs(read1, read2):
278
279
#fq[5] = "".join([COMPLEMENT.get(nt.upper(), '') for nt in fq[5][::-1]])
279
280
fq [5 ] = "" .join ([COMPLEMENT .get (nt , '' ) for nt in fq [5 ][::- 1 ]])
280
281
fq [7 ] = fq [7 ][::- 1 ]
281
- return tuple (fq )
282
+ #return tuple(fq)
283
+ return "\n " .join (fq )
282
284
283
285
284
286
def init_read_pairs (outfile , include_unmapped , include , exclude ):
@@ -291,17 +293,14 @@ def init_read_pairs(outfile, include_unmapped, include, exclude):
291
293
read_pair_types .append ('UnUn' )
292
294
pair_count_by_type = {read_pair_type : 0 for read_pair_type in read_pair_types }
293
295
# initialise read_pair tuples
294
- read_pair_seqs = {read_pair_type : tuple () for read_pair_type in read_pair_types }
296
+ # read_pair_seqs = {read_pair_type : tuple() for read_pair_type in read_pair_types}
297
+ read_pair_seqs = {read_pair_type : [] for read_pair_type in read_pair_types }
295
298
# initialise read_pair files
296
299
read_pair_out_fs = {}
297
300
for read_pair_type in read_pair_types :
298
301
read_pair_out_fs [read_pair_type ] = getOutFile (outfile , None , read_pair_type + ".fq" )
299
302
return pair_count_by_type , read_pair_seqs , read_pair_out_fs
300
303
301
- def close_fhs (used_fhs ):
302
- for fh in used_fhs .values ():
303
- fh .close ()
304
-
305
304
def print_bam (read_pair_out_fs , read_pair_type , read1 , read2 ):
306
305
with open (read_pair_out_fs [read_pair_type ] + ".txt" , 'a' ) as fh :
307
306
fh .write ("\t " .join (read1 ) + "\n " )
@@ -356,10 +355,11 @@ def parseBamForFilter(infile, progress_flag, include_unmapped, outfile, include,
356
355
read2 = sam_lines [i + 1 ].split ()
357
356
read_pair_type = "" .join (sorted ([sequence_to_type_dict [read1 [2 ]], sequence_to_type_dict [read2 [2 ]]]))
358
357
if read_pair_type in pair_seqs_by_type :
359
- pair_seqs_by_type [read_pair_type ] += get_read_pair_seqs (read1 , read2 )
358
+ #pair_seqs_by_type[read_pair_type] += get_read_pair_seqs(read1, read2)
359
+ pair_seqs_by_type [read_pair_type ].append (get_read_pair_seqs (read1 , read2 ))
360
360
pair_count_by_type [read_pair_type ] += 1
361
- BtLog .progress (seen_reads , progress_unit , reads_total )
362
- except StopIteration :
361
+ BtLog .progress (seen_reads , progress_unit , reads_total )
362
+ except IndexError :
363
363
print BtLog .warn_d ['11' ]
364
364
#print_bam(read_pair_out_fs, read_pair_type, read1, read2) # this prints SAM files for debugging
365
365
if progress_flag :
0 commit comments