-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfilter-maf.py
executable file
·51 lines (43 loc) · 2.02 KB
/
filter-maf.py
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python
#=========================================================================
# This is OPEN SOURCE SOFTWARE governed by the Gnu General Public
# License (GPL) version 3, as described at www.opensource.org.
# Copyright (C)2021 William H. Majoros <[email protected]>
#=========================================================================
from __future__ import (absolute_import, division, print_function,
unicode_literals, generators, nested_scopes, with_statement)
from builtins import (bytes, dict, int, list, object, range, str, ascii,
chr, hex, input, next, oct, open, pow, round, super, filter, map, zip)
# The above imports should allow this program to run in both Python 2 and
# Python 3. You might need to update your version of module "future".
import sys
import ProgramName
from PooledParser import PooledParser
from PooledVariant import PooledVariant
#=========================================================================
# main()
#=========================================================================
if(len(sys.argv)!=6):
exit(ProgramName.get()+" <in:pooled.essex> <in:collapsed.essex> <threshold> <out:pooled.essex> <out:collapsed.essex>\n")
(pooledInfile,collapsedInfile,threshold,pooledOutfile,collapsedOutfile)=\
sys.argv[1:]
threshold=float(threshold)
OUT_POOLED=open(pooledOutfile,"wt")
OUT_COLLAPSED=open(collapsedOutfile,"wt")
pooledParser=PooledParser(pooledInfile)
collapsedParser=PooledParser(collapsedInfile)
while(True):
varP=pooledParser.nextVariant()
varC=collapsedParser.nextVariant()
if(varP is None or varC is None): break
if(varP.ID!=varC.ID): raise Exception("Files not in sync")
freqs=varC.getFreqs()
if(len(freqs)!=1): raise Exception("Freqs array has unexpected size")
maf=freqs[0]
#print(maf,threshold,maf<=threshold,sep="\t")
if(maf>threshold): continue
textP=varP.print()
textC=varC.print()
print(textP,file=OUT_POOLED,flush=True)
print(textC,file=OUT_COLLAPSED,flush=True)
OUT_POOLED.close(); OUT_COLLAPSED.close()