def delayed_bam_merge(data):
    """Perform a merge on previously prepped files, delayed in processing.

    Handles merging of associated split read and discordant files if present.
    """
    if data.get("combine"):
        assert len(data["combine"].keys()) == 1
        file_key = list(data["combine"].keys())[0]
        extras = []
        for x in data["combine"][file_key].get("extras", []):
            if isinstance(x, (list, tuple)):
                extras.extend(x)
            else:
                extras.append(x)
        if file_key in data:
            extras.append(data[file_key])
        in_files = sorted(list(set(extras)))
        out_file = tz.get_in(["combine", file_key, "out"], data, _merge_out_from_infiles(in_files))
        sup_exts = data.get(file_key + "_plus", {}).keys()
        for ext in list(sup_exts) + [""]:
            merged_file = None
            if os.path.exists(utils.append_stem(out_file, "-" + ext)):
                cur_out_file, cur_in_files = out_file, []
            if ext:
                cur_in_files = list(filter(os.path.exists, (utils.append_stem(f, "-" + ext) for f in in_files)))
                cur_out_file = utils.append_stem(out_file, "-" + ext) if len(cur_in_files) > 0 else None
            else:
                cur_in_files, cur_out_file = in_files, out_file
            if cur_out_file:
                config = copy.deepcopy(data["config"])
                if len(cur_in_files) > 0:
                    merged_file = merge_bam_files(cur_in_files, os.path.dirname(cur_out_file), data,
                                                  out_file=cur_out_file)
                else:
                    assert os.path.exists(cur_out_file)
                    merged_file = cur_out_file
            if merged_file:
                if ext:
                    data[file_key + "_plus"][ext] = merged_file
                else:
                    data[file_key] = merged_file
        data.pop("region", None)
        data.pop("combine", None)
    return [[data]]
def delayed_bam_merge ( data ) : if data . get ( "combine" ) : assert len ( data [ "combine" ] . keys ( ) ) == 1 file_key = list ( data [ "combine" ] . keys ( ) ) [ 0 ] extras = [ ] for x in data [ "combine" ] [ file_key ] . get ( "extras" , [ ] ) : if isinstance ( x , ( list , tuple ) ) : extras . extend ( x ) else : extras . append ( x ) if file_key in data : extras . append ( data [ file_key ] ) in_files = sorted ( list ( set ( extras ) ) ) out_file = tz . get_in ( [ "combine" , file_key , "out" ] , data , _merge_out_from_infiles ( in_files ) ) sup_exts = data . get ( file_key + "_plus" , { } ) . keys ( ) for ext in list ( sup_exts ) + [ "" ] : merged_file = None if os . path . exists ( utils . append_stem ( out_file , "-" + ext ) ) : cur_out_file , cur_in_files = out_file , [ ] if ext : cur_in_files = list ( filter ( os . path . exists , ( utils . append_stem ( f , "-" + ext ) for f in in_files ) ) ) cur_out_file = utils . append_stem ( out_file , "-" + ext ) if len ( cur_in_files ) > 0 else None else : cur_in_files , cur_out_file = in_files , out_file if cur_out_file : config = copy . deepcopy ( data [ "config" ] ) if len ( cur_in_files ) > 0 : merged_file = merge_bam_files ( cur_in_files , os . path . dirname ( cur_out_file ) , data , out_file = cur_out_file ) else : assert os . path . exists ( cur_out_file ) merged_file = cur_out_file if merged_file : if ext : data [ file_key + "_plus" ] [ ext ] = merged_file else : data [ file_key ] = merged_file data . pop ( "region" , None ) data . pop ( "combine" , None ) return [ [ data ] ]
Perform a merge on previously prepped files, delayed in processing.

    Handles merging of associated split read and discordant files if present.