<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def bed2interval(align_file, bed, out_file=None):
 """Converts a bed file to an interval file for use with some of the Picard tools by grabbing the header from the alignment file, reording the bed file columns and gluing them together. align_file can be in BAM or SAM format. bed needs to be in bed12 format: http://genome.ucsc.edu/FAQ/FAQformat.html#format1.5 """

    import pysam
    base, ext = os.path.splitext(align_file)
    if out_file is None:
        out_file = base + ".interval"

    with pysam.Samfile(align_file, "r" if ext.endswith(".sam") else "rb") as in_bam:
        header = in_bam.text

    def reorder_line(line):
        splitline = line.strip().split("\t")
        reordered = "\t".join([splitline[0], str(int(splitline[1]) + 1), splitline[2],
                               splitline[5], splitline[3]])
        return reordered + "\n"

    with file_transaction(out_file) as tx_out_file:
        with open(bed) as bed_handle:
            with open(tx_out_file, "w") as out_handle:
                out_handle.write(header)
                for line in bed_handle:
                    out_handle.write(reorder_line(line))
    return out_file