#!bin/usr/python
'''
Filter TransferScript
usage:
bcftools view <filename> | python filter_transfer.py | bcftools view -O z > <filename.het.polarized.vcf.gz>
Copies the filter column to a FORMAT (gt) field.
'''
import sys
def main():
format_added = False
for l in sys.stdin.xreadlines():
l = l.strip()
if l.startswith("#CHROM"):
# Get Sample information and count
samples = l.strip().split("\t")[9:]
elif l.startswith("#"):
# Add Info line for het polarization flag
if l.startswith("##FORMAT") and format_added == False:
format_added = True
l = l + "\n##FORMAT=<ID=GF,Number=1,Type=String,Description=\"Genotype Filter\">"
else:
l = l.split("\t")
FILTER = l[6]
l[8] = l[8] + ":" + "GF"
l[9:] = [x + ":" + FILTER for x in l[9:]]
l = '\t'.join(l)
sys.stdout.write(l + "\n")
if __name__ == '__main__':
main()