<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _background_to_bed(back_file, data):
 """Convert a seq2c background file with calls into BED regions for coverage. seq2c background files are a concatenation of mapping and sample_coverages from potentially multiple samples. We use the coverage information from the first sample to translate into BED. """

    out_file = os.path.join(utils.safe_makedir(os.path.join(dd.get_work_dir(data), "bedprep")),
                            "%s-regions.bed" % utils.splitext_plus(os.path.basename(back_file))[0])
    if not utils.file_exists(out_file):
        with file_transaction(data, out_file) as tx_out_file:
            with open(back_file) as in_handle:
                with open(tx_out_file, "w") as out_handle:
                    sample = in_handle.readline().split("\t")[0]
                    for line in in_handle:
                        if line.startswith(sample) and len(line.split()) >= 5:
                            _, gene, chrom, start, end = line.split()[:5]
                            out_handle.write("%s\n" % ("\t".join([chrom, str(int(start) - 1), end, gene])))
    return out_file