5 from pathlib
import Path
6 from pysam
import VariantFile
10 def readVcfDat(fname
):
11 vcf_in
= VariantFile(fname
)
12 for rec
in vcf_in
.fetch():
14 print ([rec
.chrom
,rec
.pos
,rec
.id,rec
.alleles
])
15 if rec
.id.startswith('rs'):
19 for key
,value
in rec
.samples
.iteritems():
20 print((key
, value
['GT']))
25 p
= Path('unphased_all_vcf')
28 if '.vcf' in f
.suffixes
:
32 print ('[!]Done', file=sys
.stderr
)
34 except BrokenPipeError
: # https://stackoverflow.com/a/58517082
35 # https://docs.python.org/3/library/signal.html#note-on-sigpipe
36 # Python flushes standard streams on exit; redirect remaining output
37 # to devnull to avoid another BrokenPipeError at shutdown
38 devnull
= os
.open(os
.devnull
, os
.O_WRONLY
)
39 os
.dup2(devnull
, sys
.stdout
.fileno())
40 sys
.exit(1) # Python exits with error code 1 on EPIPE
42 if __name__
== '__main__':