def writeRow(row, col, outputFile, contigSequence, chromosomeOffsets):

    chr = str(row[col["chr"]]).strip()
    pos = row[col["lo"]]+1
    ref = row[col["ref"]].strip()
    alt = row[col["alt"]].strip()

    ids = '.'
    if col.get("ids") is not None:
        if row[col["ids"]] != '':
            ids = row[col["ids"]].strip()

    filt = '.'
    if col.get("filter") is not None:
        if row[col["filter"]] != '':
            filt = row[col["filter"]].strip()
        else:
            filt = "PASS"
            
    qual = '.'
    if col.get("qual") is not None:
        if row[col["qual"]] != dxpy.NULL or row[col["qual"]] == -999999:
            qual = row[col["qual"]]
        
    #Check if any types are ins/del, if so pull out the character before as well.
    sample = 0
    printPreceedingCharacter = False
    altOptions = row[col["alt"]].split(",")
    if altOptions == ['']:
        printPreceedingCharacter = True
    for x in altOptions:
        if (len(ref) != len(x) or len(ref) == 0 or len(alt) == 0) and not re.search("[^ATGCNatgcn\.-]", x):
            printPreceedingCharacter = True
            
    if printPreceedingCharacter:
        ref = contigSequence[chromosomeOffsets[chr]+2-int(pos)]+ref
        altOptions = row[col["alt"]].split(",")
        alt = ''
        for x in altOptions:
            if re.search("[^ATGCNatgcn\.-]", x):
                alt += x+","
            else:
                alt += contigSequence[chromosomeOffsets[chr]+int(pos)-2]+x+","
                validAlt = False
        alt = alt.rstrip(",")
        pos -= 1
                
    outputFile.write(chr+"\t"+str(pos).strip()+"\t"+str(ids).strip()+"\t"+ref.upper().strip()+"\t"+alt.upper().strip()+"\t"+str(qual).strip()+"\t"+str(filt).strip())

    infos = ''
    for x in col:
        if "info_" in x:
            if col.get(x) is not None:
                if isinstance(row[col[x]], bool):
                    if row[col[x]] == True:
                        infos += x.lstrip("info_")+";"
                elif isDefault(row[col[x]]):
                    infos += x.lstrip("info_")+"="+str(row[col[x]])+";"
    if infos == '':
        infos = '.'
    outputFile.write("\t"+infos.rstrip(";"))
    
    #Check whether the reserved fields coverage and total coverage are present, and put them into the info index if so
    sample = 0
    coverage = False
    totalCoverage = False
    while 1:
        if col.get("type_"+str(sample)) is None:
            break
        if coverage == False:
            coverage = col.get("coverage_"+str(sample))
        if totalCoverage == False:
            totalCoverage = col.get("total_coverage_"+str(sample))
        sample += 1
    
    #Check which info tags are present and use them to construct the info Index
    observedFormats = []
    for x in col:
        if "format_" in x:
            if col.get(x) is not None:
                entrySplit = x.split("_")[1:]
                entrySplit.pop()
                tag = '_'.join(entrySplit)
                if tag not in observedFormats:
                    observedFormats.append(tag)
    if col.get("type_0") is not None:
        outputFile.write("\t")
        formatOrdering = 'GT:'
        if coverage:
            formatOrdering += "AD:"
        if totalCoverage:
            formatOrdering += "DP:"
        for x in observedFormats:
            formatOrdering += x+":"
        outputFile.write(formatOrdering.rstrip(":"))
    
        sample = 0
        while 1:
            if col.get("type_"+str(sample)) is not None:
                formats = row[col["genotype_"+str(sample)]]+":"
                if coverage:
                    if col.get("coverage_"+str(sample)):
                        cov = row[col.get("coverage_"+str(sample))]
                        formats += cov+":"
                    else:
                        cov += ".:"
                if totalCoverage:
                    if col.get("total_coverage_"+str(sample)) is not None:
                        tCov = row[col.get("total_coverage_"+str(sample))]
                        if tCov == dxpy.NULL or tCov == -999999:
                            formats += "0:"
                        else:
                            formats += str(tCov)+":"
                    else:
                        formats += ".:"
                for x in observedFormats:
                    if col.get("format_"+x+"_"+str(sample)) is not None:
                        if isinstance(row[col["format_"+x+"_"+str(sample)]], bool):
                            if row[col["format_"+x+"_"+str(sample)]]:
                                formats += x
                            else:
                                formats += "."
                        elif row[col["format_"+x+"_"+str(sample)]] == dxpy.NULL or row[col["format_"+x+"_"+str(sample)]] == -999999:
                            formats += "."
                        else:
                            formats += str(row[col["format_"+x+"_"+str(sample)]])
                    else:
                        formats += "."
                    formats += ":"
                outputFile.write("\t"+formats.rstrip(":"))
            else:
                break
            sample += 1
    outputFile.write("\n")
dataset/ETHPy150Open dnanexus/dx-toolkit/src/python/dxpy/scripts/dx_variants_to_vcf.py/writeRow/swapped operands of `-`