import re


def get_info(var, entry):
    """Return a value for a user selected field in a line from a vcf (provided as a list split by whitespace)"""

    ret_val = None

    try:
        #Loop through vcf fields backwards
        for field in var[::-1]:
            #First try fields seperated with an ':' e.g. GT:AO	0/1:23
            found = re.search("['\t', ':']{}['\t', ':']".format(entry), field)
            if found:
                field_split = field.split(':')
                entry_index = field_split.index('{}'.format(entry))
                field_index = var.index(field)
                ret_val = var[field_index+1].split(':')[entry_index]
                break

            #Second try fields with an '=' e.g. AO=23;RO=45
            found = re.search("['\t', ';']{}=".format(entry), field)
            if found:
                ret_val = re.split("['\t', ';']{}=".format(entry), field)[1].split(';')[0]
                break
    except:
        pass

    return ret_val