-
Notifications
You must be signed in to change notification settings - Fork 4
/
chrVis.py
98 lines (64 loc) · 2.34 KB
/
chrVis.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# -*- coding: utf-8 -*-
# from pysvg.structure import *
# from pysvg.chromose import *
from svgwrite import *
from framework import *
import sys
import argparse
import logging
import configparser
import pprint
pp = pprint.PrettyPrinter(indent=4)
logging.basicConfig(level = logging.DEBUG,format = '[%(levelname)s] - %(name)s -> %(message)s')
logger = logging.getLogger(__name__)
def main(args):
cf = configparser.ConfigParser()
cf.read(args.conf)
outputFile = args.output
karyotypeFile = cf.get('general','karyotype')
bandFile = cf.get('general','bandfile')
scale = cf.getfloat('general','scale')
imgWidth = cf.getint('general','imgWidth')
imgHeight = cf.getint('general','imgHeight')
thickness = cf.getfloat('ideogram','thickness')
bandSize = cf.getfloat('band','thickness')
label_size = cf.getfloat('ideogram','label_size')
spacing = cf.getfloat('ideogram','spacing') + thickness
showBandName = cf.getboolean('band','show_name')
logger.debug('scale: {}'.format(scale))
svg = Drawing(debug=True)
svg.viewbox(width=1400,height=900)
logger.debug('reading karyotype file')
dchr = readKaryotype(karyotypeFile)
logger.debug('{} chromosomes to draw'.format(len(dchr)))
logger.debug('reading band file')
dband = readBand(bandFile)
# pp.pprint(dband)
for chrName,chrValue in dchr.items():
logger.info('processing {}'.format(chrName))
if chrName in dband:
bandNow = dband[chrName]
else:
bandNow = []
logger.warning('{} have no band info.'.format(chrName))
svgObj = VectorChr(
chrValue['name'],chrValue,bandNow,scale
)
svgObj.set_labelSize(16)
svgObj.set_bandSize(bandSize)
svgObj.set_showBandName(showBandName)
svgObj.set_spacing(spacing)
svgObj.set_thickness(thickness)
e = svgObj.get_svg()
this = svg.add(e)
p = svg.tostring()
print(p)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description="")
parser.add_argument('-c', '--conf', type=str,default = None, help='configure file')
parser.add_argument('-o','--output',type =str , default = None, help='output filename')
args = parser.parse_args()
if args.conf is None:
parser.print_help()
sys.exit()
main(args)