diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..225187c --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +__pycache__ +*.png +*.svg +!example.png \ No newline at end of file diff --git a/draw_all.py b/draw_all.py index 91635e4..f5789c4 100644 --- a/draw_all.py +++ b/draw_all.py @@ -1,4 +1,5 @@ -import draw_rna as d +from __future__ import absolute_import, division, print_function +from . import draw_rna as d import argparse import sys import os @@ -27,7 +28,7 @@ def main(): seq = next(f).strip() secstruct = next(f).strip() except Exception as e: - print e + print(e) raise ValueError('improper format') try: @@ -35,7 +36,7 @@ def main(): except: col = None - print 'drawing %s' % name + print('drawing %s' % name) if col: d.draw_rna(seq, secstruct, col, name, line=args.line) else: diff --git a/draw_rna.py b/draw_rna.py index 5e5e839..e1ffdbf 100644 --- a/draw_rna.py +++ b/draw_rna.py @@ -1,6 +1,7 @@ -import render_rna_flip as render_rna -import svg -import inv_utils +from __future__ import absolute_import, division, print_function +from . import render_rna +from . import svg +from . import inv_utils import argparse import re from matplotlib import cm @@ -31,7 +32,7 @@ #"i": [0, 204, 153], #"h": [46, 184, 46]} -def draw_rna(sequence, secstruct, colors, filename="secstruct", line=False): +def draw_rna(sequence, secstruct, colors, filename="secstruct", line=False, square=True, flipped=True, draw_pairs=True): r = render_rna.RNARenderer() pairmap = render_rna.get_pairmap_from_secstruct(secstruct) @@ -39,7 +40,7 @@ def draw_rna(sequence, secstruct, colors, filename="secstruct", line=False): for i in range(len(pairmap)): if pairmap[i] > i: pairs.append({"from":i, "to":pairmap[i], "p":1.0, "color":COLORS["e"]}) - r.setup_tree(secstruct, NODE_R, PRIMARY_SPACE, PAIR_SPACE) + r.setup_tree(secstruct, NODE_R, PRIMARY_SPACE, PAIR_SPACE, False) size = r.get_size() cell_size = max(size) + CELL_PADDING * 2 @@ -55,8 +56,11 @@ def draw_rna(sequence, secstruct, colors, filename="secstruct", line=False): except: colors = [COLORS[x] for x in list(colors)] - svgobj = svg.svg("%s.svg" % filename, cell_size, cell_size) - r.draw(svgobj, CELL_PADDING, CELL_PADDING, colors, pairs, sequence, RENDER_IN_LETTERS, line) + width = cell_size if square else size[0] + height = cell_size if square else size[1] + + svgobj = svg.svg("%s.svg" % filename, width, height) + r.draw(svgobj, CELL_PADDING, CELL_PADDING, colors, pairs if draw_pairs else None, sequence, RENDER_IN_LETTERS, line) def parse_colors(color_string): colorings = color_string.strip().split(",") diff --git a/inv_utils.py b/inv_utils.py index 97926e2..1487f0c 100755 --- a/inv_utils.py +++ b/inv_utils.py @@ -1,3 +1,4 @@ +from __future__ import absolute_import, division, print_function import os import random, string import re diff --git a/render_rna.py b/render_rna.py index c73e49f..5280462 100755 --- a/render_rna.py +++ b/render_rna.py @@ -1,5 +1,6 @@ +from __future__ import absolute_import, division, print_function import sys -import svg +from . import svg import re import random import math @@ -54,7 +55,7 @@ def get_pairmap_from_secstruct(secstruct): pairs_array[pair_stack[ii]] = end_stack[-ii] pairs_array[end_stack[-ii]] = pair_stack[ii] else: - print "ERROR: pairing incorrect %s" % secstruct + print("ERROR: pairing incorrect %s" % secstruct) return pairs_array @@ -62,8 +63,7 @@ def get_pairmap_from_secstruct(secstruct): def add_nodes_recursive(bi_pairs, rootnode, start_index, end_index): if(start_index > end_index) : - print ("Error occured while drawing RNA %d %d" % (start_index, end_index)) - sys.exit(0) + raise RuntimeError("Error occured while drawing RNA %d %d" % (start_index, end_index)) if(bi_pairs[start_index] == end_index) : @@ -91,7 +91,7 @@ def add_nodes_recursive(bi_pairs, rootnode, start_index, end_index): rootnode.children_.append(newnode) -def setup_coords_recursive(rootnode, parentnode, start_x, start_y, go_x, go_y, NODE_R, PRIMARY_SPACE, PAIR_SPACE): +def setup_coords_recursive(rootnode, parentnode, start_x, start_y, go_x, go_y, NODE_R, PRIMARY_SPACE, PAIR_SPACE, FLIPPED): cross_x = -go_y cross_y = go_x @@ -106,11 +106,11 @@ def setup_coords_recursive(rootnode, parentnode, start_x, start_y, go_x, go_y, N rootnode.y_ = start_y if(rootnode.children_[0].is_pair_): - setup_coords_recursive(rootnode.children_[0], rootnode, start_x + go_x * PRIMARY_SPACE, start_y + go_y * PRIMARY_SPACE, go_x, go_y, NODE_R, PRIMARY_SPACE, PAIR_SPACE) + setup_coords_recursive(rootnode.children_[0], rootnode, start_x + go_x * PRIMARY_SPACE, start_y + (-1 if FLIPPED else 1) * go_y * PRIMARY_SPACE, go_x, go_y, NODE_R, PRIMARY_SPACE, PAIR_SPACE, FLIPPED) elif(rootnode.children_[0].is_pair_ == False and rootnode.children_[0].index_a_ < 0): - setup_coords_recursive(rootnode.children_[0], rootnode, start_x, start_y, go_x, go_y, NODE_R, PRIMARY_SPACE, PAIR_SPACE) + setup_coords_recursive(rootnode.children_[0], rootnode, start_x, start_y, go_x, go_y, NODE_R, PRIMARY_SPACE, PAIR_SPACE, FLIPPED) else: - setup_coords_recursive(rootnode.children_[0], rootnode, start_x + go_x * PRIMARY_SPACE, start_y + go_y * PRIMARY_SPACE, go_x, go_y, NODE_R, PRIMARY_SPACE, PAIR_SPACE) + setup_coords_recursive(rootnode.children_[0], rootnode, start_x + go_x * PRIMARY_SPACE, start_y + (-1 if FLIPPED else 1) * go_y * PRIMARY_SPACE, go_x, go_y, NODE_R, PRIMARY_SPACE, PAIR_SPACE, FLIPPED) elif(len(rootnode.children_) > 1) : @@ -128,7 +128,7 @@ def setup_coords_recursive(rootnode, parentnode, start_x, start_y, go_x, go_y, N rootnode.y_ = go_y * circle_radius else : rootnode.x_ = parentnode.x_ + go_x * circle_radius - rootnode.y_ = parentnode.y_ + go_y * circle_radius + rootnode.y_ = parentnode.y_ + (-1 if FLIPPED else 1) * go_y * circle_radius for ii in range(0,len(rootnode.children_)): @@ -139,13 +139,13 @@ def setup_coords_recursive(rootnode, parentnode, start_x, start_y, go_x, go_y, N rad_angle = length_walker/circle_length * 2 * math.pi - math.pi / 2.0 child_x = rootnode.x_ + math.cos(rad_angle) * cross_x * circle_radius + math.sin(rad_angle) * go_x * circle_radius - child_y = rootnode.y_ + math.cos(rad_angle) * cross_y * circle_radius + math.sin(rad_angle) * go_y * circle_radius + child_y = rootnode.y_ + (-1 if FLIPPED else 1) * math.cos(rad_angle) * cross_y * circle_radius + (-1 if FLIPPED else 1) * math.sin(rad_angle) * go_y * circle_radius child_go_x = child_x - rootnode.x_ child_go_y = child_y - rootnode.y_ child_go_len = math.sqrt(child_go_x * child_go_x + child_go_y * child_go_y) - setup_coords_recursive(rootnode.children_[ii], rootnode, child_x, child_y, child_go_x / child_go_len, child_go_y / child_go_len, NODE_R, PRIMARY_SPACE, PAIR_SPACE) + setup_coords_recursive(rootnode.children_[ii], rootnode, child_x, child_y, child_go_x / child_go_len, (-1 if FLIPPED else 1) * child_go_y / child_go_len, NODE_R, PRIMARY_SPACE, PAIR_SPACE, FLIPPED) if(rootnode.children_[ii].is_pair_) : length_walker += PAIR_SPACE / 2.0 @@ -154,7 +154,7 @@ def setup_coords_recursive(rootnode, parentnode, start_x, start_y, go_x, go_y, N rootnode.x_ = start_x rootnode.y_ = start_y -def get_coords_recursive(rootnode, xarray, yarray, PRIMARY_SPACE, PAIR_SPACE): +def get_coords_recursive(rootnode, xarray, yarray, PRIMARY_SPACE, PAIR_SPACE, FLIPPED): if(rootnode.is_pair_) : cross_x = -rootnode.go_y_ cross_y = rootnode.go_x_ @@ -162,14 +162,14 @@ def get_coords_recursive(rootnode, xarray, yarray, PRIMARY_SPACE, PAIR_SPACE): xarray[rootnode.index_a_] = rootnode.x_ + cross_x * PAIR_SPACE/2.0 xarray[rootnode.index_b_] = rootnode.x_ - cross_x * PAIR_SPACE/2.0 - yarray[rootnode.index_a_] = rootnode.y_ + cross_y * PAIR_SPACE/2.0 - yarray[rootnode.index_b_] = rootnode.y_ - cross_y * PAIR_SPACE/2.0 + yarray[rootnode.index_a_] = rootnode.y_ + (-1 if FLIPPED else 1) * cross_y * PAIR_SPACE/2.0 + yarray[rootnode.index_b_] = rootnode.y_ - (-1 if FLIPPED else 1) * cross_y * PAIR_SPACE/2.0 elif(rootnode.index_a_ >= 0) : xarray[rootnode.index_a_] = rootnode.x_ yarray[rootnode.index_a_] = rootnode.y_ for ii in range(0, len(rootnode.children_)): - get_coords_recursive(rootnode.children_[ii], xarray, yarray, PRIMARY_SPACE, PAIR_SPACE) + get_coords_recursive(rootnode.children_[ii], xarray, yarray, PRIMARY_SPACE, PAIR_SPACE, FLIPPED) @@ -181,7 +181,7 @@ def __init__(self): self.yarray_ = None self.size_ = None - def setup_tree(self, secstruct, NODE_R,PRIMARY_SPACE, PAIR_SPACE): + def setup_tree(self, secstruct, NODE_R, PRIMARY_SPACE, PAIR_SPACE, FLIPPED=True): dangling_start = 0 dangling_end = 0 @@ -223,8 +223,8 @@ def setup_tree(self, secstruct, NODE_R,PRIMARY_SPACE, PAIR_SPACE): xarray.append(0.0) yarray.append(0.0) - self.setup_coords(NODE_R,PRIMARY_SPACE,PAIR_SPACE) - self.get_coords(xarray,yarray,PRIMARY_SPACE,PAIR_SPACE) + self.setup_coords(NODE_R,PRIMARY_SPACE,PAIR_SPACE,FLIPPED) + self.get_coords(xarray,yarray,PRIMARY_SPACE,PAIR_SPACE,FLIPPED) min_x = xarray[0] - NODE_R min_y = yarray[0] - NODE_R @@ -271,46 +271,36 @@ def draw(self,svgobj,offset_x,offset_y,colors, pairs, sequence, render_in_letter for pair in pairs: svgobj.line(offset_x + self.xarray_[pair['from']], offset_y + self.yarray_[pair['from']], offset_x + self.xarray_[pair['to']], offset_y + self.yarray_[pair['to']], pair['color'], self.NODE_R) - if not render_in_letter: - for ii in range(0,len(self.xarray_)): - if colors == None: - svgobj.circle(self.xarray_[ii] + offset_x,self.yarray_[ii] + offset_y, self.NODE_R, "#000000", "#000000") - else: - svgobj.circle(self.xarray_[ii] + offset_x,self.yarray_[ii] + offset_y, self.NODE_R, colors[ii], colors[ii]) + for ii in range(0,len(self.xarray_)): + if colors == None: + svgobj.circle(self.xarray_[ii] + offset_x,self.yarray_[ii] + offset_y, self.NODE_R, "#000000", "#000000") + else: + svgobj.circle(self.xarray_[ii] + offset_x,self.yarray_[ii] + offset_y, self.NODE_R, colors[ii], colors[ii]) - if sequence: + if sequence and render_in_letter: for ii in range(0,len(self.xarray_)): - if not render_in_letter: - text_size = self.NODE_R * 1.5 - if colors[ii] == [0,0,0]: - color = "#FFFFFF" - else: - color = "#000000" - text_offset_x = -4.0 - text_offset_y = (text_size)/2.0 - 1.0 + text_size = self.NODE_R * 1.5 + if colors[ii] == [0,0,0]: + color = "#FFFFFF" else: - if colors == None: - color = "#000000" - else: - color = colors[ii] - text_size = self.NODE_R * 2.0 - text_offset_x = -2 - text_offset_y = (text_size)/2.0 + color = "#000000" + text_offset_x = -4.0 + text_offset_y = (text_size)/2.0 - 1.0 svgobj.text(self.xarray_[ii] + offset_x + text_offset_x, self.yarray_[ii] + offset_y + text_offset_y, text_size, color, "center", sequence[ii]) - def get_coords(self, xarray, yarray, PRIMARY_SPACE, PAIR_SPACE): + def get_coords(self, xarray, yarray, PRIMARY_SPACE, PAIR_SPACE, FLIPPED): if(self.root_ != None) : - get_coords_recursive(self.root_, xarray, yarray, PRIMARY_SPACE, PAIR_SPACE) + get_coords_recursive(self.root_, xarray, yarray, PRIMARY_SPACE, PAIR_SPACE, FLIPPED) else : for ii in range(0,len(xarray)): xarray[ii] = 0 yarray[ii] = ii * PRIMARY_SPACE - def setup_coords(self, NODE_R, PRIMARY_SPACE, PAIR_SPACE): + def setup_coords(self, NODE_R, PRIMARY_SPACE, PAIR_SPACE, FLIPPED): if self.root_ != None: - setup_coords_recursive(self.root_, None, 0, 0, 0, 1, NODE_R, PRIMARY_SPACE, PAIR_SPACE) + setup_coords_recursive(self.root_, None, 0, 0, 0, 1, NODE_R, PRIMARY_SPACE, PAIR_SPACE, FLIPPED) diff --git a/render_rna_flip.py b/render_rna_flip.py deleted file mode 100755 index 111dc0d..0000000 --- a/render_rna_flip.py +++ /dev/null @@ -1,305 +0,0 @@ -import sys -import svg -import re -import random -import math - - -class RNATreeNode: - - def __init__(self): - self.children_ = [] - self.is_pair_ = False - self.index_a_ = -1 - self.index_b_ = -1 - self.x_ = 0 - self.y_ = 0 - self.go_x_ = 0 - self.go_y_ = 0 - - -def get_pairmap_from_secstruct(secstruct): - """ - generates dictionary containing pair mappings - - args: - secstruct contains secondary structure string - - returns: - dictionary with pair mappings - """ - pair_stack = [] - end_stack = [] - pairs_array = [] - i_range = range(0,len(secstruct)) - - # initialize all values to -1, meaning no pair - for ii in i_range: - pairs_array.append(-1) - - # assign pairs based on secstruct - for ii in i_range: - if(secstruct[ii] == "("): - pair_stack.append(ii) - elif(secstruct[ii] == ")"): - if not pair_stack: - end_stack.append(ii) - else: - index = pair_stack.pop() - pairs_array[index] = ii - pairs_array[ii] = index - if len(pair_stack) == len(end_stack): - n = len(pair_stack) - for ii in range(n): - pairs_array[pair_stack[ii]] = end_stack[-ii] - pairs_array[end_stack[-ii]] = pair_stack[ii] - else: - print "ERROR: pairing incorrect %s" % secstruct - - return pairs_array - - -def add_nodes_recursive(bi_pairs, rootnode, start_index, end_index): - - if(start_index > end_index) : - print ("Error occured while drawing RNA %d %d" % (start_index, end_index)) - sys.exit(0) - - if(bi_pairs[start_index] == end_index) : - - newnode = RNATreeNode() - newnode.is_pair_ = True - newnode.index_a_ = start_index - newnode.index_b_ = end_index - - add_nodes_recursive(bi_pairs, newnode, start_index+1, end_index-1) - - else : - - newnode = RNATreeNode() - jj = start_index - while jj <= end_index: - if(bi_pairs[jj] > jj) : - add_nodes_recursive(bi_pairs,newnode, jj, bi_pairs[jj]) - jj = bi_pairs[jj] + 1 - else : - newsubnode = RNATreeNode() - newsubnode.is_pair_ = False - newsubnode.index_a_ = jj - newnode.children_.append(newsubnode) - jj += 1 - - rootnode.children_.append(newnode) - -def setup_coords_recursive(rootnode, parentnode, start_x, start_y, go_x, go_y, NODE_R, PRIMARY_SPACE, PAIR_SPACE): - - cross_x = -go_y - cross_y = go_x - - children_width = len(rootnode.children_) * NODE_R * 2 - - rootnode.go_x_ = go_x - rootnode.go_y_ = go_y - - if(len(rootnode.children_) == 1) : - rootnode.x_ = start_x - rootnode.y_ = start_y - - if(rootnode.children_[0].is_pair_): - setup_coords_recursive(rootnode.children_[0], rootnode, start_x + go_x * PRIMARY_SPACE, start_y - go_y * PRIMARY_SPACE, go_x, go_y, NODE_R, PRIMARY_SPACE, PAIR_SPACE) - elif(rootnode.children_[0].is_pair_ == False and rootnode.children_[0].index_a_ < 0): - setup_coords_recursive(rootnode.children_[0], rootnode, start_x, start_y, go_x, go_y, NODE_R, PRIMARY_SPACE, PAIR_SPACE) - else: - setup_coords_recursive(rootnode.children_[0], rootnode, start_x + go_x * PRIMARY_SPACE, start_y - go_y * PRIMARY_SPACE, go_x, go_y, NODE_R, PRIMARY_SPACE, PAIR_SPACE) - - elif(len(rootnode.children_) > 1) : - - npairs = 0 - for ii in range(0, len(rootnode.children_)): - if(rootnode.children_[ii].is_pair_) : - npairs+=1 - - circle_length = (len(rootnode.children_) + 1) * PRIMARY_SPACE + (npairs + 1) * PAIR_SPACE - circle_radius = circle_length / (2 * math.pi) - length_walker = PAIR_SPACE / 2.0 - - if (parentnode == None) : - rootnode.x_ = go_x * circle_radius - rootnode.y_ = go_y * circle_radius - else : - rootnode.x_ = parentnode.x_ + go_x * circle_radius - rootnode.y_ = parentnode.y_ - go_y * circle_radius - - for ii in range(0,len(rootnode.children_)): - - length_walker += PRIMARY_SPACE - - if(rootnode.children_[ii].is_pair_) : - length_walker += PAIR_SPACE / 2.0 - - rad_angle = length_walker/circle_length * 2 * math.pi - math.pi / 2.0 - child_x = rootnode.x_ + math.cos(rad_angle) * cross_x * circle_radius + math.sin(rad_angle) * go_x * circle_radius - child_y = rootnode.y_ - math.cos(rad_angle) * cross_y * circle_radius - math.sin(rad_angle) * go_y * circle_radius - - child_go_x = child_x - rootnode.x_ - child_go_y = child_y - rootnode.y_ - child_go_len = math.sqrt(child_go_x * child_go_x + child_go_y * child_go_y) - - setup_coords_recursive(rootnode.children_[ii], rootnode, child_x, child_y, child_go_x / child_go_len, -child_go_y / child_go_len, NODE_R, PRIMARY_SPACE, PAIR_SPACE) - - if(rootnode.children_[ii].is_pair_) : - length_walker += PAIR_SPACE / 2.0 - - else : - rootnode.x_ = start_x - rootnode.y_ = start_y - -def get_coords_recursive(rootnode, xarray, yarray, PRIMARY_SPACE, PAIR_SPACE): - if(rootnode.is_pair_) : - cross_x = -rootnode.go_y_ - cross_y = rootnode.go_x_ - - xarray[rootnode.index_a_] = rootnode.x_ + cross_x * PAIR_SPACE/2.0 - xarray[rootnode.index_b_] = rootnode.x_ - cross_x * PAIR_SPACE/2.0 - - yarray[rootnode.index_a_] = rootnode.y_ - cross_y * PAIR_SPACE/2.0 - yarray[rootnode.index_b_] = rootnode.y_ + cross_y * PAIR_SPACE/2.0 - elif(rootnode.index_a_ >= 0) : - xarray[rootnode.index_a_] = rootnode.x_ - yarray[rootnode.index_a_] = rootnode.y_ - - for ii in range(0, len(rootnode.children_)): - get_coords_recursive(rootnode.children_[ii], xarray, yarray, PRIMARY_SPACE, PAIR_SPACE) - - - -class RNARenderer: - - def __init__(self): - self.root_ = None - self.xarray_ = None - self.yarray_ = None - self.size_ = None - - def setup_tree(self, secstruct, NODE_R,PRIMARY_SPACE, PAIR_SPACE): - - dangling_start = 0 - dangling_end = 0 - bi_pairs = get_pairmap_from_secstruct(secstruct) - - self.NODE_R = NODE_R - self.root_ = None - - for ii in range(0,len(bi_pairs)): - if bi_pairs[ii] < 0: - dangling_start+=1 - else: - break - - for ii in (len(bi_pairs)-1,-1, -1) : - if(bi_pairs[ii] < 0): - dangling_end+=1 - else: - break - - self.root_ = RNATreeNode() - - #for jj in range(0,len(bi_pairs)): - jj = 0 - while (jj < len(bi_pairs)): - if (bi_pairs[jj] > jj) : - add_nodes_recursive(bi_pairs,self.root_, jj, bi_pairs[jj]) - jj = bi_pairs[jj] + 1 - else: - newsubnode = RNATreeNode() - newsubnode.is_pair_ = False - newsubnode.index_a_ = jj - self.root_.children_.append(newsubnode) - jj += 1 - xarray = [] - yarray = [] - - for ii in range(0,len(secstruct)): - xarray.append(0.0) - yarray.append(0.0) - - self.setup_coords(NODE_R,PRIMARY_SPACE,PAIR_SPACE) - self.get_coords(xarray,yarray,PRIMARY_SPACE,PAIR_SPACE) - - min_x = xarray[0] - NODE_R - min_y = yarray[0] - NODE_R - max_x = xarray[0] + NODE_R - max_y = xarray[0] + NODE_R - - for x in xarray: - if x - NODE_R < min_x: - min_x = x - NODE_R - if x + NODE_R > max_x: - max_x = x + NODE_R - - for y in yarray: - if y - NODE_R < min_y: - min_y = y - NODE_R - if y + NODE_R > max_y: - max_y = y + NODE_R - - for ii in range(0,len(xarray)): - xarray[ii] -= min_x - yarray[ii] -= min_y - - self.size_ = [max_x - min_x, max_y - min_y] - self.xarray_ = xarray - self.yarray_ = yarray - - def get_size(self): - return self.size_ - - def draw(self,svgobj,offset_x,offset_y,colors, pairs, sequence, render_in_letter, line=False): - if self.xarray_ != None: - - if line: - for ii in range(len(self.xarray_)-1): - if colors == None: - svgobj.line(self.xarray_[ii], self.yarray_[ii], self.xarray_[ii+1], self.yarray_[ii+1], - 'black') - else: - svgobj.line(self.xarray_[ii], self.yarray_[ii], self.xarray_[ii+1], self.yarray_[ii+1], - colors[ii]) - else: - if pairs: - for pair in pairs: - svgobj.line(offset_x + self.xarray_[pair['from']], offset_y + self.yarray_[pair['from']], offset_x + self.xarray_[pair['to']], offset_y + self.yarray_[pair['to']], pair['color'], self.NODE_R) - - for ii in range(0,len(self.xarray_)): - if colors == None: - svgobj.circle(self.xarray_[ii] + offset_x,self.yarray_[ii] + offset_y, self.NODE_R, "#000000", "#000000") - else: - svgobj.circle(self.xarray_[ii] + offset_x,self.yarray_[ii] + offset_y, self.NODE_R, colors[ii], colors[ii]) - - if sequence and render_in_letter: - - for ii in range(0,len(self.xarray_)): - text_size = self.NODE_R * 1.5 - if colors[ii] == [0,0,0]: - color = "#FFFFFF" - else: - color = "#000000" - text_offset_x = -4.0 - text_offset_y = (text_size)/2.0 - 1.0 - svgobj.text(self.xarray_[ii] + offset_x + text_offset_x, self.yarray_[ii] + offset_y + text_offset_y, text_size, color, "center", sequence[ii]) - - def get_coords(self, xarray, yarray, PRIMARY_SPACE, PAIR_SPACE): - - if(self.root_ != None) : - get_coords_recursive(self.root_, xarray, yarray, PRIMARY_SPACE, PAIR_SPACE) - else : - for ii in range(0,len(xarray)): - xarray[ii] = 0 - yarray[ii] = ii * PRIMARY_SPACE - - def setup_coords(self, NODE_R, PRIMARY_SPACE, PAIR_SPACE): - if self.root_ != None: - setup_coords_recursive(self.root_, None, 0, 0, 0, 1, NODE_R, PRIMARY_SPACE, PAIR_SPACE) - - - diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..623ed2d --- /dev/null +++ b/setup.py @@ -0,0 +1,16 @@ +import os.path + +from setuptools import setup, find_packages + +root_path = os.path.abspath(os.path.join(__file__, '..')) + +setup( + name='draw_rna', + author='wuami', + url='https://github.com/wuami/draw_rna/', + packages=['draw_rna'], + package_dir={'draw_rna':root_path}, + install_requires=[ + 'matplotlib>=3.1.2' + ] +) \ No newline at end of file diff --git a/svg.py b/svg.py index a7ca66c..1cf0a24 100755 --- a/svg.py +++ b/svg.py @@ -1,5 +1,7 @@ """Methods for outputting SVG files.""" +from __future__ import absolute_import, division, print_function + def convert_color(color): """Converts a color object (be it touple-like, or string to an SVG-readable color string).""" if type(color) == str: @@ -10,12 +12,12 @@ def convert_color(color): class svg(object): def __init__(self, filename, w, h): # create the file - self.__out = file(filename, 'w') + self.__out = open(filename, 'w') # write the header self.__out.write(""" -