def update_vcf_header(vcf, slop, insert_size, arg_cmd):
    """
    update the VCF header with new lines, new fields and new flags when needed
    Add the new flags to the header in INFO and FORMAT fields
    :param vcf: pysam vcf_file object
    :param slop: value of the slop used to capture the discordant reads
    :param insert_size: value of the insert_size used by read aligner to estimate if reads are properly paired or not
    :param arg_cmd: arguments used in the command
    :return: updated pysam vcf_file object
    """

    # -----#
    # INFO #
    # -----#
    vcf.header.info.add("TRA", ".", "Flag",
                        "Variant is a TRANSLOCATION")
    vcf.header.info.add("INV", ".", "Flag",
                        "Variant is a BND Inversion")
    vcf.header.info.add("INVDUP", ".", "Flag",
                        "Variant is a BND Inverted Duplication")
    vcf.header.info.add("DUPTANDEM", ".", "Flag",
                        "Variant is a BND DUP-TANDEM")
    vcf.header.info.add("CHR2", "1", "String",
                        "Chromosome name of the associated breakend")
    vcf.header.info.add("ENDPOSSV", "1", "Integer",
                        "POSition of the associated breakend in CHR2")
    vcf.header.info.add("RO", "1", "String",
                        "read orientation for break ends")
    vcf.header.info.add("UNTESTED", "0", "Flag",
                        "indicate if we tried to recapture the discordant reads; apply to any INS, or to DEL with SVLEN within specific range")
    # --------#
    # FORMAT  #
    # --------#
    vcf.header.formats.add("RUT1", "1", "Float", "for POS region, Ratio of Unique Start positions over the Total of number of Start Positions (aka total number of reads)")
    vcf.header.formats.add("RUT2", "1", "Float",
                           "for ENDPOSSV region, Ratio of Unique Start positions over the Total of number of Start Positions (aka total number of reads)")
    vcf.header.formats.add("RDISTDISC1", "1", "Integer",
                           "Distribution size of Discordant pair at CHR:POS ; value 0 means no discordant reads in [POS+SLOP] interval")
    vcf.header.formats.add("RDISTDISC2", "1", "Integer",
                           "Distribution size of Discordant pair at CHR2:ENDPOSSV ; value 0 means no discordant reads in [POS+SLOP] interval")
    vcf.header.formats.add("RCDIS1", "1", "Integer",
                           "Number of Recaptured Discordant Pairs in Left Region (POS) with which we calculated the range distribution RDISTDISC1")
    vcf.header.formats.add("RCDIS2", "1", "Integer",
                           "Number of Recaptured Discordant Pairs in Right Region (ENDPOSSV) with which we calculated the range distribution RDISTDISC2")
    vcf.header.formats.add("DRNOISE1", "6", "Integer",
                           "Number of Recaptured Discordant Pairs not associated with current event; we may consider this as read noise within and around current left breakend; "
                           " idx1=DEL, idx2=DUP, idx3=INS, idx4=INV, idx5=TRA, idx6=TOTAL_READ_COUNTED_AS_NOISE")
    vcf.header.formats.add("DRNOISE2", "6", "Integer",
                           "Same as DRNOISE1 but for ENDPOSSV region")
    vcf.header.formats.add("EVALRCNOISE", "2", "Float",
                           "This variable represent a way of evaluating the noise related to the total number of reads counted for the current event. Is is calculated as follow: "
                           "(PR+SR)/(PR+SR+DRNOISE1) for first value and (RCDIS1/(RCDIS1+DRNOISE1)) for the second value")
    vcf.header.formats.add("CLMQ1", "3", "Integer",
                           "Count of the reads with Low Mapping Quality in region of interest;"
                           "1) first value is count of reads with MAPQ of Zero, "
                           "2) second value is count of reads with MAPQ value between 1 and the minmapq (default 15), "
                           "3) the total number of reads recaptured by fetch within POS+/-SLOP interval")
    vcf.header.formats.add("CLMQ2", "3", "Integer",
                           "same as CLMQ1 but for partner breakend")
    # ADDED LINES for COMMENTS
    vcf.header.add_line("##INSERTSIZE=" + str(insert_size) + ". Insert size value used to define whether we may have discordant reads associated to the variant")
    vcf.header.add_line("##SLOP=" + str(slop) + ". If CIPOS or/and CIEND exist in record, CIPOS is added to slop for POS, CIEND is added to slop for ENDPOSSV")
    if arg_cmd is not None:
        str_arg_cmd = ' '.join([str(x) for x in arg_cmd])
        vcf.header.add_line("##CommandPrepareSVvcf='{}'".format(str(str_arg_cmd)))
    return vcf