-
Notifications
You must be signed in to change notification settings - Fork 0
/
prepare_vcfanno_conf.py
51 lines (35 loc) · 1.11 KB
/
prepare_vcfanno_conf.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
#written by Noah Friedman
#writes a .toml configuration file for vcf anno based on inputs
confHead = '[[annotation]]\n'
confFooter = '[[postannotation]]\nfields=[\"lua_start\"]\nop=\"lua:lua_start - 2\"\nname=\"lua_start_minus_2\"\ntype=\"Integer\"\n'
#pass the function the open file and it'll write the appropriate line
def write_file_name(f, filename):
line = 'file=' + '\"' + filename + '\"' + '\n'
print line
f.write(line)
def write_annotation_fields(f, fields):
writeStr = 'fields = ['
cntr = 1
for field in fields:
s = '\"' + field + '\"'
writeStr += s
if cntr != len(fields):
writeStr += ', '
writeStr += ']\n'
print writeStr
f.write(writeStr)
def write_ops_line(f, fields):
writeStr = 'ops=['
writeStr += ','.join(['\"first\"' for i in range(len(fields))])
writeStr += ']\n'
print writeStr
f.write(writeStr)
def write_conf_file(fname, annotationFileDict):
with open(fname, 'w') as f:
for key, value in annotationFileDict.items():
f.write(confHead)
write_file_name(f, key)
write_annotation_fields(f, value)
write_ops_line(f, value)
f.write('\n')
f.write(confFooter)