File: vcfnulldotslashdot

package info (click to toggle)
libvcflib 1.0.12%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 70,520 kB
  • sloc: cpp: 39,837; python: 532; perl: 474; ansic: 317; ruby: 295; sh: 254; lisp: 148; makefile: 123; javascript: 94
file content (27 lines) | stat: -rwxr-xr-x 742 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/env python3
# Rewrite null genotypes to ./.
#
import sys
import math

def bincoeff(n,k): return math.factorial(n) / (math.factorial(n-k)*math.factorial(k))
def multcoeff(n,k): return bincoeff(n+k-1,k)

if len(sys.argv) > 1:
    inf = open(sys.argv[1])
else:
    inf = sys.stdin

for line in inf:
    if line.startswith("#"):
        print(line.strip())
        continue
    fields = line.strip().split("\t")
    alleles = len(fields[4].split(","))+1
    # assume that we have GT:GL
    # how many genotypes?  assume diploid
    flatgls = ",".join([str(x) for x in [0]*int(multcoeff(alleles,2))])
    for i in range(9, len(fields)):
        if fields[i] == ".":
            fields[i] = "./.:" + flatgls
    print("\t".join(fields))