def int_if_possible(val):
    """
    Returns integer value of s if conversion succeeds, else s.
    """
    if type(val) is list or type(val) is tuple:
        val = val[0]
    try:
        i = int(val)
    except ValueError:
        i = val
    return i

    # def make_info_dict(callers, records, pos1, pos2):
    #     """ generate 'median' results for info fields from all records """
    #     callermap = {
    #         "delly": {"fields": ["DV", "RV"], "tumor": 0},
    #         "svaba": {"fields": ["SR", "DR"], "tumor": 1},
    #         "gridss": {"fields": ["RP", "SR"], "tumor": 1},
    #         "brass": {"fields": ["PS", "RC"], "tumor": 1},
    #         "smoove": {"fields": ["SR", "PE"], "tumor": 0},
    #     }
    #     # fields = ['CHR2', 'END', 'SVTYPE', 'SVLEN'] + ["SR", "DR"] + ["DV", "RV"] + ["RP"]
    #     fields = [x["fields"] for x in callermap.values()]
    #     fields = [item for sublist in fields for item in sublist]
    #     info = {}
    #     for field in fields:
    #         answers = []
    #         for caller, record in zip(callers, records):
    #             if caller in callermap.keys() and field in callermap[caller]["fields"]:
    #                 if field in record.format:
    #                     answers.append([caller,int_if_possible(record.samples[callermap[caller]["tumor"]][field])])
    #                 elif field in record.info:
    #                     answers.append([caller,int_if_possible(record.info[field])])
    #                 # elif field in record.format:
    #                 #     answers.append([caller,int_if_possible(record.samples[callermap[caller]["tumor"]][field])])
    #             nanswers = len(answers)
    #         if nanswers > 0:
    #             # sorted_answers = sorted(answers)
    #             # # doesn't quite deal with even #s correctly - can't average strings
    #             # median_pos = int(nanswers / 2)
    #             # median_answer = sorted_answers[median_pos]
    #             # if not median_answer == 0:
    #             #     info[field] = median_answer
    #             for a in answers:
    #                 info[a[0] + "_" + field] = a[1]

    if "SVTYPE" in info and info["SVTYPE"] in ["DUP", "DUP:TANDEM", "DEL", "INV"]:
        if not "SVLEN" in info:
            info["SVLEN"] = pos2 - pos1
    return info