@@ -798,17 +798,19 @@ def gather_text_chunks(suffix):
798798 f_out = gzip .open (out_path , "wt" )
799799 first_chunk = f"{ output_prefix } .1{ suffix } "
800800 chunk_paths = [first_chunk ]
801- with open (first_chunk ) as f_in :
802- for line in f_in :
803- f_out .write (line )
801+ if os .path .exists (first_chunk ):
802+ with open (first_chunk ) as f_in :
803+ for line in f_in :
804+ f_out .write (line )
804805 # Copy the remaining chunks
805806 for i in range (1 , num_chunks ):
806807 chunk_path = f"{ output_prefix } .{ i + 1 } { suffix } "
807- with open (chunk_path ) as f_in :
808- f_in .readline () # Skip the header
809- for line in f_in :
810- f_out .write (line )
811- chunk_paths .append (chunk_path )
808+ if os .path .exists (chunk_path ):
809+ with open (chunk_path ) as f_in :
810+ f_in .readline () # Skip the header
811+ for line in f_in :
812+ f_out .write (line )
813+ chunk_paths .append (chunk_path )
812814 f_out .close ()
813815 # Delete the chunk data
814816 logging .info ("Data combining complete. Deleting chunk data (*%s)." , suffix )
@@ -826,17 +828,20 @@ def gather_text_chunks(suffix):
826828 # Copy the first chunk over
827829 first_bam_chunk = f"{ output_prefix } .1.tagged.bam"
828830 bam_chunk_paths = [first_bam_chunk ]
829- bam_reader = pysam .AlignmentFile (first_bam_chunk , "rb" , check_sq = False )
830831 outpath_bam = output_prefix + ".tagged.bam"
832+ bam_reader = pysam .AlignmentFile (first_bam_chunk , "rb" , check_sq = False )
831833 f_tagged_bam = pysam .AlignmentFile (outpath_bam , "wb" , template = bam_reader )
832- for r in bam_reader :
833- f_tagged_bam .write (r )
834+
835+ if os .path .exists (first_bam_chunk ):
836+ for r in bam_reader :
837+ f_tagged_bam .write (r )
834838 # Copy the remaining chunks
835839 for i in range (1 , num_chunks ):
836840 chunk_path = f"{ output_prefix } .{ i + 1 } .tagged.bam"
837- for r in pysam .AlignmentFile (chunk_path , "rb" , check_sq = False ):
838- f_tagged_bam .write (r )
839- bam_chunk_paths .append (chunk_path )
841+ if os .path .exists (chunk_path ):
842+ for r in pysam .AlignmentFile (chunk_path , "rb" , check_sq = False ):
843+ f_tagged_bam .write (r )
844+ bam_chunk_paths .append (chunk_path )
840845 f_tagged_bam .close ()
841846 bam_reader .close ()
842847 # Delete the chunk data
0 commit comments