Process the RADIA vcf to for passing calls and additionally sites having multiple alt alleles
    to pick out on the most likely ones.

    :param toil.fileStore.FileID radia_vcf: fsID for a RADIA generated chromosome vcf
    :param str work_dir: Working directory
    :param dict univ_options: Dict of universal options used by almost all tools
    :return: Path to the processed vcf
    :rtype: str

def process_radia_vcf(job, radia_vcf, work_dir, univ_options):
    """
    Process the RADIA vcf to for passing calls and additionally sites having multiple alt alleles
    to pick out on the most likely ones.

    :param toil.fileStore.FileID radia_vcf: fsID for a RADIA generated chromosome vcf
    :param str work_dir: Working directory
    :param dict univ_options: Dict of universal options used by almost all tools
    :return: Path to the processed vcf
    :rtype: str
    """
    radia_vcf = job.fileStore.readGlobalFile(radia_vcf)
    with open(radia_vcf, 'r') as infile, open(radia_vcf + 'radia_parsed.tmp', 'w') as outfile:
        # The columns in INFILE are
        # [0] CHROM
        # [1] POS
        # [2] ID
        # [3] REF
        # [4] ALT
        # [5] QUAL
        # [6] FILTER
        # [7] INFO
        # [8] FORMAT
        # [9] DNA_NORMAL
        # [10] DNA_TUMOR
        # [11] RNA_TUMOR  -  Not always present
        for line in infile:
            # Print header to outfile
            if line.startswith('#'):
                print(line.strip(), file=outfile)
                continue
            line = line.strip().split('\t')
            # If the call was not PASSing, or if the call was germline: skip
            if line[6] != 'PASS' or 'MT=GERM' in line[7]:
                continue
            # If there is just 1 ALT allele, print and continue
            if len(line[4]) == 1:
                print('\t'.join(line), file=outfile)
            # If not, process
            else:
                seq_field_indeces = [9, 10]
                alleles = [line[3]] + line[4].split(',')  # all alleles, incl. REF
                # collect tumor, normal and (if present) rna AD and AFs
                # AD = Depth of reads supporting each allele
                # AF = Fraction of reads supporting each allele
                # normal_ad = line[9].split(':')[5].split(',')
                normal_af = line[9].split(':')[6].split(',')
                tumor_ad = line[10].split(':')[5].split(',')
                tumor_af = line[10].split(':')[6].split(',')
                if len(line[11]) > 1:
                    rna_ad = line[11].split(':')[5].split(',')
                    rna_af = line[11].split(':')[6].split(',')
                    seq_field_indeces += [11]  # append rna since it is present
                else:
                    # If rna is missing, set RNA_AD and RNA_AF to null sets for easily
                    # integrating into the logic in the following code
                    rna_ad = rna_af = [0, 0, 0, 0]
                # Initialise variables to store the probable ALT alleles and the index values of
                # the same wrt AD and AF
                out_alleles = set([])
                out_af_ad_index = {0}
                # parse AD and AF to get most probable ALT alleles
                for i in range(1, len(normal_af)):
                    # Criteria for selection = AD > 4 and AF >0.1 in either tumor or RNA, given
                    # normal AF < 0.1
                    if ((float(tumor_af[i]) >= 0.1 and int(tumor_ad[i]) >= 4) or
                            (float(rna_af[i]) >= 0.1 and int(rna_ad[i]) >= 4)) and \
                            (float(normal_af[i]) < 0.1):
                        out_alleles.add(alleles[i])
                        out_af_ad_index.add(i)
                # If the number of probable alleles is greater than 0 the print to outfile with
                # the modified allele fraction representing reads corrresponding to all alleles
                if len(out_alleles) > 0:
                    line[4] = ','.join(out_alleles)  # set alt alleles
                    # Modify the AD and AF values in the TUMOR/NORMAL/RNA fields
                    # one at a time.  Seq fields contain
                    # [0] GT* - Genotype
                    # [1] DP - Read depth at this position in the sample
                    # [2] INDEL - Number of indels
                    # [3] START - Number of reads starting at this position
                    # [4] STOP - Number of reads stopping at this position
                    # [5] AD* - Depth of reads supporting alleles
                    # [6] AF* - Fraction of reads supporting alleles
                    # [7] BQ* - Avg base quality for reads supporting alleles
                    # [8] SB* - Strand Bias for reads supporting alleles
                    # Fields marked with *s are teh ones that contain info for each seq field
                    # and need to be modified
                    for seq_field_index in seq_field_indeces:
                        # Get the details for seq_field
                        deets = line[seq_field_index].split(':')
                        # modify fields 5 thu 8 to hold only info for the probable
                        # alleles
                        for field_index in range(5, 9):
                            field = deets[field_index].split(",")
                            deets[field_index] = ",".join([x for i, x in enumerate(field)
                                                           if i in out_af_ad_index])
                        # Modify DP to hold the new total of reads
                        deets[1] = str(sum([int(x) for x in deets[5].split(",")]))
                        # get the most likely genotypes based on AD and AF
                        gt_by_ad = set([i for i, x in enumerate(deets[5].split(","))
                                        if int(x) >= 4])
                        gt_by_af = set([i for i, x in enumerate(deets[6].split(","))
                                        if float(x) >= 0.1])
                        # Get the consensus genotype
                        genotype = gt_by_ad.intersection(gt_by_af)
                        if len(genotype) == 0:
                            deets[0] = "0/0"
                        elif len(genotype) == 1:
                            deets[0] = "/".join([str(x) for x in genotype] +
                                                [str(x) for x in genotype])
                        elif len(genotype) == 2:
                            deets[0] = "/".join([str(x) for x in genotype])
                        else:
                            print("ERROR : triple genotype detected", file=sys.stderr)
                            print(line, file=sys.stdout)
                        # Rejoin the details line
                        line[seq_field_index] = ":".join(deets)
                    # Print the modified line to output
                    print("\t".join(line), file=outfile)
                # Else do nothing
                else:
                    pass
    return outfile.name