@@ -5,21 +5,21 @@ Subject: [PATCH] Glenn Gaffield modifications
55
66---
77 __init__.py | 13 +++++++------
8- axis.py | 3 ++-
98 bedtrack.py | 55 +++++++++++++++++++++++++++++++++++++++----------------
109 genomeview.py | 3 ++-
10+ intervaltrack.py | 1 +
1111 svg.py | 3 ++-
1212 5 files changed, 51 insertions(+), 24 deletions(-)
1313
1414diff --git a/__init__.py b/__init__.py
15- index 5a29ee8..cbd87f6 100644
15+ index 5a29ee8..cbd87f6 100755
1616--- a/__init__.py
1717+++ b/__init__.py
1818@@ -5,14 +5,15 @@ from genomeview.genomesource import *
1919
2020 try:
2121 from genomeview._quickconsensus import *
22- - except ImportError :
22+ - except ValueError :
2323- import logging
2424- logging.warn("Unable to load cythonized quickconsensus module; "
2525- "drawing reads using quick consensus mode will be "
@@ -37,55 +37,11 @@ index 5a29ee8..cbd87f6 100644
3737 logging.error("Unable to load cythonized quickconsensus module; "
3838 "this is likely because pysam has been updated "
3939 "since genomeview was originally install. To "
40- diff --git a/genomeview.py b/genomeview.py
41- index 748239b..81a59c2 100644
42- --- a/genomeview.py
43- +++ b/genomeview.py
44- @@ -5,7 +5,8 @@ from genomeview.svg import Renderer, SVG
45-
46-
47- class Document:
48- - header = """<svg version="1.1" baseProfile="full" width="{width}" height="{height}" xmlns="http://www.w3.org/2000/svg">"""
49- + #GG header = """<svg version="1.1" baseProfile="full" width="{width}" height="{height}" xmlns="http://www.w3.org/2000/svg">"""
50- + header = """<svg version="1.1" baseProfile="full" width="{width}" height="{height}" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">"""
51- footer = """</svg>"""
52-
53- def __init__(self, width):
54- diff --git a/svg.py b/svg.py
55- index fd69227..aa2d5a4 100644
56- --- a/svg.py
57- +++ b/svg.py
58- @@ -19,7 +19,8 @@ class SVG(GraphicsBackend):
59- def text(self, x, y, text, size=10, anchor="middle", family="Helvetica", **kwdargs):
60- defaults = {}
61- assert anchor in ["start", "middle", "end"]
62- - yield """<text x="{x:.2f}" y="{y:.2f}" font-size="{size}" font-family="{family}" text-anchor="{anchor}" {more}>{text}</text>""".format(
63- + #GG yield """<text x="{x:.2f}" y="{y:.2f}" font-size="{size}" font-family="{family}" text-anchor="{anchor}" {more}>{text}</text>""".format(
64- + yield """<a xlink:href="https://www.ncbi.nlm.nih.gov/protein/YP_034512.1" target="_blank"><text x="{x:.2f}" y="{y:.2f}" font-size="{size}" font-family="{family}" text-anchor="{anchor}" {more}>{text}</text></a>""".format(
65- x=x, y=y, size=size, family=family, anchor=anchor, more=_addOptions(kwdargs, defaults), text=text)
66-
67- def text_with_background(self, x, y, text, size=10, anchor="middle", text_color="black", bg="white", bg_opacity=0.8, **kwdargs):
68- diff --git a/axis.py b/axis.py
69- index fd69227..aa2d5a4 100644
70- --- a/axis.py
71- +++ b/axis.py
72- @@ -72,9 +72,9 @@
73- for i in range(int(roundStart), end, res):
74- res_digits = math.log10(res)
75- if res_digits >= 6:
76- - label = "{}mb".format(i / 1e6)
77- + label = "{}mb".format(int(i / 1e6))
78- elif res_digits >= 3:
79- - label = "{:,}kb".format(i / 1e3)
80- + label = "{:,}kb".format(int(i / 1e3))
81- else:
82- label = "{:,}".format(i)
83-
8440diff --git a/bedtrack.py b/bedtrack.py
85- index 048b7a6..7d90013 100644
41+ index 048b7a6..7d90013 100755
8642--- a/bedtrack.py
8743+++ b/bedtrack.py
88- @@ -41,6 +41,8 @@
44+ @@ -41,6 +41,8 @@ def tx_from_bedfields(bedfields):
8945 name = coding_start = coding_end = exons = color = None
9046 strand = "+"
9147
@@ -94,7 +50,7 @@ index 048b7a6..7d90013 100644
9450 if len(bedfields) >= 4:
9551 name = bedfields[3]
9652 if len(bedfields) >= 6:
97- @@ -106,7 +108,8 @@
53+ @@ -106,7 +108,8 @@ def fetch_from_bigbed(path, chrom, start, end):
9854 def fetch_from_plainbed(path, chrom, start, end):
9955 found_chrom = False
10056 for line in open(path):
@@ -104,7 +60,7 @@ index 048b7a6..7d90013 100644
10460 if fields[0] != chrom: continue
10561 found_chrom = True
10662
107- @@ -135,8 +138,10 @@
63+ @@ -135,8 +138,10 @@ class BEDTrack(IntervalTrack):
10864 self.draw_locus_labels = True
10965 self.include_locus_fn = None
11066
@@ -117,7 +73,7 @@ index 048b7a6..7d90013 100644
11773 self.thin_width = 5
11874 self.thinnest_width = 1
11975
120- @@ -171,10 +176,11 @@
76+ @@ -171,10 +176,11 @@ class BEDTrack(IntervalTrack):
12177 def draw_interval(self, renderer, interval):
12278 # print(interval)
12379 interval_pixel_width = self.scale.relpixels(interval.tx.end-interval.tx.start)
@@ -133,7 +89,7 @@ index 048b7a6..7d90013 100644
13389
13490 # print(1)
13591 row = self.intervals_to_rows[interval.id]
136- @@ -214,7 +220,8 @@
92+ @@ -214,7 +220,8 @@ class BEDTrack(IntervalTrack):
13793
13894 # Draw the "exons", both thin (non-coding/UTR) and thick (coding)
13995 # print(interval, tx.exons)
@@ -143,7 +99,7 @@ index 048b7a6..7d90013 100644
14399 for cur_start, cur_end in tx.exons:
144100 if which == "thick":
145101 cur_y = top
146- @@ -227,11 +234,13 @@
102+ @@ -227,11 +234,13 @@ class BEDTrack(IntervalTrack):
147103 cur_start = max(tx.coding_start, cur_start)
148104 cur_end = min(tx.coding_end, cur_end)
149105 else:
@@ -161,7 +117,7 @@ index 048b7a6..7d90013 100644
161117
162118 cur_start = self.scale.topixels(cur_start)
163119 cur_end = self.scale.topixels(cur_end)
164- @@ -241,12 +250,42 @@
120+ @@ -241,12 +250,26 @@ class BEDTrack(IntervalTrack):
165121 cur_start -= self.min_exon_width / 2
166122 width = self.min_exon_width
167123
@@ -185,27 +141,53 @@ index 048b7a6..7d90013 100644
185141 if interval.label is not None:
186142 end = self.scale.topixels(interval.end)
187143+ end+= 5 if interval.strand=="+" else 0 #GG
188- +
189- + #GG yield from renderer.text(end+self.label_distance, top+self.row_height-2, interval.label, anchor="start")
190- + start = self.scale.topixels(interval.start)
191- +
192- + #GG prevent truncation of label on left side of image
193- + if start < 0:
194- + start = 0
195144
196145- yield from renderer.text(end+self.label_distance, top+self.row_height-2, interval.label, anchor="start")
197146-
198147\ No newline at end of file
199- + #GG prevent label truncation on the right side of image
200- + # calculate an approximation of the rendered length
201- + arr=[4.3,4.3,5.45,8.5,8.5,19.5,10.15,3.0,5.15,5.15,6.0,8.9,4.3,5.15,4.3,4.3,8.5,7.45,8.5,8.5,8.5,8.5,8.5,8.5,8.5,8.5,4.3,4.3,8.9,8.9,8.9,8.5,15.35,10.15,10.15,11.0,11.0,10.15,9.3,11.8,11.0,4.3,7.45,10.15,8.5,12.65,11.0,11.8,10.15,11.8,11.0,10.15,9.3,11.0,10.15,14.3,10.15,10.15,9.3,4.3,4.3,4.3,7.20,8.5,5.15,8.5,8.5,7.45,8.5,8.5,4.0,8.5,8.5,3.45,3.45,7.45,3.45,12.65,8.5,8.5,8.5,8.5,5.15,7.45,4.3,8.5,7.45,11.0,7.45,7.45,7.45,5.15,4.0,5.15,8.9]
202- +
203- + label_len=0
204- + for i, ch in enumerate(interval.label):
205- + label_len += arr[ord(ch)-32] * 0.6666667
206- +
207- + if start + label_len >= 892:
208- + start = 892 - label_len
209- +
148+ + #GG yield from renderer.text(end+self.label_distance, top+self.row_height-2, interval.label, anchor="start")
149+ + start = self.scale.topixels(interval.start)
210150+ yield from renderer.text(start, top+self.row_height-5, interval.label, anchor="start")
211- +
151+ +
152+ diff --git a/genomeview.py b/genomeview.py
153+ index 748239b..81a59c2 100755
154+ --- a/genomeview.py
155+ +++ b/genomeview.py
156+ @@ -5,7 +5,8 @@ from genomeview.svg import Renderer, SVG
157+
158+
159+ class Document:
160+ - header = """<svg version="1.1" baseProfile="full" width="{width}" height="{height}" xmlns="http://www.w3.org/2000/svg">"""
161+ + #GG header = """<svg version="1.1" baseProfile="full" width="{width}" height="{height}" xmlns="http://www.w3.org/2000/svg">"""
162+ + header = """<svg version="1.1" baseProfile="full" width="{width}" height="{height}" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">"""
163+ footer = """</svg>"""
164+
165+ def __init__(self, width):
166+ diff --git a/intervaltrack.py b/intervaltrack.py
167+ index 01bb4f9..d5b89e6 100755
168+ --- a/intervaltrack.py
169+ +++ b/intervaltrack.py
170+ @@ -96,6 +96,7 @@ class IntervalTrack(Track):
171+ arrow_width = min(self.row_height / 2, self.margin_x * 0.7, self.scale.relpixels(30))
172+ direction = "right" if interval.strand=="+" else "left"
173+
174+ + #print("rendered block arrow")
175+ yield from renderer.block_arrow(start, top, end-start, self.row_height,
176+ arrow_width=arrow_width, direction=direction,
177+ fill=color, **{"stroke":"none", "id":temp_label})
178+ diff --git a/svg.py b/svg.py
179+ index fd69227..aa2d5a4 100755
180+ --- a/svg.py
181+ +++ b/svg.py
182+ @@ -19,7 +19,8 @@ class SVG(GraphicsBackend):
183+ def text(self, x, y, text, size=10, anchor="middle", family="Helvetica", **kwdargs):
184+ defaults = {}
185+ assert anchor in ["start", "middle", "end"]
186+ - yield """<text x="{x:.2f}" y="{y:.2f}" font-size="{size}" font-family="{family}" text-anchor="{anchor}" {more}>{text}</text>""".format(
187+ + #GG yield """<text x="{x:.2f}" y="{y:.2f}" font-size="{size}" font-family="{family}" text-anchor="{anchor}" {more}>{text}</text>""".format(
188+ + yield """<a xlink:href="https://www.ncbi.nlm.nih.gov/protein/YP_034512.1" target="_blank"><text x="{x:.2f}" y="{y:.2f}" font-size="{size}" font-family="{family}" text-anchor="{anchor}" {more}>{text}</text></a>""".format(
189+ x=x, y=y, size=size, family=family, anchor=anchor, more=_addOptions(kwdargs, defaults), text=text)
190+
191+ def text_with_background(self, x, y, text, size=10, anchor="middle", text_color="black", bg="white", bg_opacity=0.8, **kwdargs):
192+ - -
193+ 2.7.4
0 commit comments