aboutsummaryrefslogtreecommitdiff
path: root/wqflask/utility
diff options
context:
space:
mode:
authorBonfaceKilz2021-04-30 12:26:19 +0300
committerBonfaceKilz2021-04-30 13:45:15 +0300
commit406eb27859cca232a562c722cbbd37aca2e3be84 (patch)
treeba3fba783e33cc56c535b68bd64d757bc6cde608 /wqflask/utility
parentc7e661b8ff9f70955418fbc4527378904beb0cf4 (diff)
downloadgenenetwork2-406eb27859cca232a562c722cbbd37aca2e3be84.tar.gz
autopep8: Fix E301,E302,E303,E304,E305,E306
Diffstat (limited to 'wqflask/utility')
-rw-r--r--wqflask/utility/Plot.py13
-rw-r--r--wqflask/utility/__init__.py2
-rw-r--r--wqflask/utility/after.py1
-rw-r--r--wqflask/utility/authentication_tools.py1
-rw-r--r--wqflask/utility/benchmark.py1
-rw-r--r--wqflask/utility/corestats.py2
-rw-r--r--wqflask/utility/elasticsearch_tools.py7
-rw-r--r--wqflask/utility/external.py1
-rw-r--r--wqflask/utility/gen_geno_ob.py3
-rw-r--r--wqflask/utility/genofile_parser.py1
-rw-r--r--wqflask/utility/logger.py3
-rw-r--r--wqflask/utility/pillow_utils.py4
-rw-r--r--wqflask/utility/startup_config.py1
-rw-r--r--wqflask/utility/svg.py67
-rw-r--r--wqflask/utility/temp_data.py1
-rw-r--r--wqflask/utility/tools.py25
-rw-r--r--wqflask/utility/type_checking.py5
-rw-r--r--wqflask/utility/webqtlUtil.py5
18 files changed, 141 insertions, 2 deletions
diff --git a/wqflask/utility/Plot.py b/wqflask/utility/Plot.py
index 68c2cb72..d35b2089 100644
--- a/wqflask/utility/Plot.py
+++ b/wqflask/utility/Plot.py
@@ -47,6 +47,7 @@ COUR_FILE = "./wqflask/static/fonts/courbd.ttf"
TAHOMA_FILE = "./wqflask/static/fonts/tahoma.ttf"
# ---- END: FONT FILES ---- #
+
def cformat(d, rank=0):
'custom string format'
strD = "%2.6f" % d
@@ -68,6 +69,7 @@ def cformat(d, rank=0):
strD = '0.0'
return strD
+
def frange(start, end=None, inc=1.0):
"A faster range-like function that does accept float increments..."
if end == None:
@@ -84,6 +86,7 @@ def frange(start, end=None, inc=1.0):
L[i] = start + i * inc
return L
+
def find_outliers(vals):
"""Calculates the upper and lower bounds of a set of sample/case values
@@ -119,6 +122,8 @@ def find_outliers(vals):
# parameter: data is either object returned by reaper permutation function (called by MarkerRegressionPage.py)
# or the first object returned by direct (pair-scan) permu function (called by DirectPlotPage.py)
+
+
def plotBar(canvas, data, barColor=BLUE, axesColor=BLACK, labelColor=BLACK, XLabel=None, YLabel=None, title=None, offset=(60, 20, 40, 40), zoom=1):
im_drawer = ImageDraw.Draw(canvas)
xLeftOffset, xRightOffset, yTopOffset, yBottomOffset = offset
@@ -230,6 +235,8 @@ def plotBar(canvas, data, barColor=BLUE, axesColor=BLACK, labelColor=BLACK, XLab
font=labelFont, fill=labelColor)
# This function determines the scale of the plot
+
+
def detScaleOld(min, max):
if min >= max:
return None
@@ -246,6 +253,7 @@ def detScaleOld(min, max):
high = c * ceil(max / c)
return [low, high, round((high - low) / c)]
+
def detScale(min=0, max=0):
if min >= max:
@@ -283,15 +291,19 @@ def detScale(min=0, max=0):
return [low, high, n]
+
def bluefunc(x):
return 1.0 / (1.0 + exp(-10 * (x - 0.6)))
+
def redfunc(x):
return 1.0 / (1.0 + exp(10 * (x - 0.5)))
+
def greenfunc(x):
return 1 - pow(redfunc(x + 0.2), 2) - bluefunc(x - 0.3)
+
def colorSpectrum(n=100):
multiple = 10
if n == 1:
@@ -319,6 +331,7 @@ def colorSpectrum(n=100):
out2.append(out[-1])
return out2
+
def _test():
import doctest
doctest.testmod()
diff --git a/wqflask/utility/__init__.py b/wqflask/utility/__init__.py
index ec7e72d0..d540c96e 100644
--- a/wqflask/utility/__init__.py
+++ b/wqflask/utility/__init__.py
@@ -2,8 +2,10 @@ from pprint import pformat as pf
# Todo: Move these out of __init__
+
class Bunch:
"""Like a dictionary but using object notation"""
+
def __init__(self, **kw):
self.__dict__ = kw
diff --git a/wqflask/utility/after.py b/wqflask/utility/after.py
index 06091ecb..2b560e48 100644
--- a/wqflask/utility/after.py
+++ b/wqflask/utility/after.py
@@ -7,6 +7,7 @@ from flask import g
from wqflask import app
+
def after_this_request(f):
if not hasattr(g, 'after_request_callbacks'):
g.after_request_callbacks = []
diff --git a/wqflask/utility/authentication_tools.py b/wqflask/utility/authentication_tools.py
index 672b36d5..57dbf8ba 100644
--- a/wqflask/utility/authentication_tools.py
+++ b/wqflask/utility/authentication_tools.py
@@ -11,6 +11,7 @@ from utility.redis_tools import (get_redis_conn,
add_resource)
Redis = get_redis_conn()
+
def check_resource_availability(dataset, trait_id=None):
# At least for now assume temporary entered traits are accessible
if type(dataset) == str or dataset.type == "Temp":
diff --git a/wqflask/utility/benchmark.py b/wqflask/utility/benchmark.py
index 3d40a3b8..48ab1dc0 100644
--- a/wqflask/utility/benchmark.py
+++ b/wqflask/utility/benchmark.py
@@ -6,6 +6,7 @@ from utility.tools import LOG_BENCH
from utility.logger import getLogger
logger = getLogger(__name__)
+
class Bench:
entries = collections.OrderedDict()
diff --git a/wqflask/utility/corestats.py b/wqflask/utility/corestats.py
index 15d1cb8d..523280a1 100644
--- a/wqflask/utility/corestats.py
+++ b/wqflask/utility/corestats.py
@@ -16,6 +16,8 @@
import sys
# ZS: Should switch to using some third party library for this; maybe scipy has an equivalent
+
+
class Stats:
def __init__(self, sequence):
diff --git a/wqflask/utility/elasticsearch_tools.py b/wqflask/utility/elasticsearch_tools.py
index ae1181e4..9415cef0 100644
--- a/wqflask/utility/elasticsearch_tools.py
+++ b/wqflask/utility/elasticsearch_tools.py
@@ -47,11 +47,13 @@ logger = getLogger(__name__)
from utility.tools import ELASTICSEARCH_HOST, ELASTICSEARCH_PORT
+
def test_elasticsearch_connection():
es = Elasticsearch(['http://' + ELASTICSEARCH_HOST + ":" + str(ELASTICSEARCH_PORT) + '/'], verify_certs=True)
if not es.ping():
logger.warning("Elasticsearch is DOWN")
+
def get_elasticsearch_connection(for_user=True):
"""Return a connection to ES. Returns None on failure"""
logger.info("get_elasticsearch_connection")
@@ -77,6 +79,7 @@ def get_elasticsearch_connection(for_user=True):
return es
+
def setup_users_index(es_connection):
if es_connection:
index_settings = {
@@ -87,12 +90,15 @@ def setup_users_index(es_connection):
es_connection.indices.create(index='users', ignore=400)
es_connection.indices.put_mapping(body=index_settings, index="users", doc_type="local")
+
def get_user_by_unique_column(es, column_name, column_value, index="users", doc_type="local"):
return get_item_by_unique_column(es, column_name, column_value, index=index, doc_type=doc_type)
+
def save_user(es, user, user_id):
es_save_data(es, "users", "local", user, user_id)
+
def get_item_by_unique_column(es, column_name, column_value, index, doc_type):
item_details = None
try:
@@ -106,6 +112,7 @@ def get_item_by_unique_column(es, column_name, column_value, index, doc_type):
pass
return item_details
+
def es_save_data(es, index, doc_type, data_item, data_id,):
from time import sleep
es.create(index, doc_type, body=data_item, id=data_id)
diff --git a/wqflask/utility/external.py b/wqflask/utility/external.py
index c1bf4043..805d2ffe 100644
--- a/wqflask/utility/external.py
+++ b/wqflask/utility/external.py
@@ -4,6 +4,7 @@ import os
import sys
import subprocess
+
def shell(command):
if subprocess.call(command, shell=True) != 0:
raise Exception("ERROR: failed on " + command)
diff --git a/wqflask/utility/gen_geno_ob.py b/wqflask/utility/gen_geno_ob.py
index 9cfa39f9..24604e58 100644
--- a/wqflask/utility/gen_geno_ob.py
+++ b/wqflask/utility/gen_geno_ob.py
@@ -1,6 +1,7 @@
import utility.logger
logger = utility.logger.getLogger(__name__)
+
class genotype:
"""
Replacement for reaper.Dataset so we can remove qtlreaper use while still generating mapping output figure
@@ -119,6 +120,7 @@ class genotype:
self.chromosomes.append(chr_ob)
+
class Chr:
def __init__(self, name, geno_ob):
self.name = name
@@ -140,6 +142,7 @@ class Chr:
def add_marker(self, marker_row):
self.loci.append(Locus(self.geno_ob, marker_row))
+
class Locus:
def __init__(self, geno_ob, marker_row=None):
self.chr = None
diff --git a/wqflask/utility/genofile_parser.py b/wqflask/utility/genofile_parser.py
index f8e96d19..94a08c17 100644
--- a/wqflask/utility/genofile_parser.py
+++ b/wqflask/utility/genofile_parser.py
@@ -12,6 +12,7 @@ import simplejson as json
from pprint import pformat as pf
+
class Marker:
def __init__(self):
self.name = None
diff --git a/wqflask/utility/logger.py b/wqflask/utility/logger.py
index 16912e58..47079818 100644
--- a/wqflask/utility/logger.py
+++ b/wqflask/utility/logger.py
@@ -35,6 +35,7 @@ import datetime
from utility.tools import LOG_LEVEL, LOG_LEVEL_DEBUG, LOG_SQL
+
class GNLogger:
"""A logger class with some additional functionality, such as
multiple parameter logging, SQL logging, timing, colors, and lazy
@@ -139,6 +140,8 @@ LOG_LEVEL_DEBUG (NYI).
# Get the module logger. You can override log levels at the
# module level
+
+
def getLogger(name, level=None):
gnlogger = GNLogger(name)
logger = gnlogger.logger
diff --git a/wqflask/utility/pillow_utils.py b/wqflask/utility/pillow_utils.py
index 6e95beb0..5713e155 100644
--- a/wqflask/utility/pillow_utils.py
+++ b/wqflask/utility/pillow_utils.py
@@ -9,6 +9,8 @@ BLACK = ImageColor.getrgb("black")
WHITE = ImageColor.getrgb("white")
# def draw_rotated_text(canvas: Image, text: str, font: ImageFont, xy: tuple, fill: ImageColor=BLACK, angle: int=-90):
+
+
def draw_rotated_text(canvas, text, font, xy, fill=BLACK, angle=-90):
# type: (Image, str, ImageFont, tuple, ImageColor, int)
"""Utility function draw rotated text"""
@@ -20,6 +22,8 @@ def draw_rotated_text(canvas, text, font, xy, fill=BLACK, angle=-90):
canvas.paste(im=tmp_img2, box=tuple([int(i) for i in xy]))
# def draw_open_polygon(canvas: Image, xy: tuple, fill: ImageColor=WHITE, outline: ImageColor=BLACK):
+
+
def draw_open_polygon(canvas, xy, fill=None, outline=BLACK, width=0):
# type: (Image, tuple, ImageColor, ImageColor)
draw_ctx = ImageDraw.Draw(canvas)
diff --git a/wqflask/utility/startup_config.py b/wqflask/utility/startup_config.py
index f22f4b14..92f944bc 100644
--- a/wqflask/utility/startup_config.py
+++ b/wqflask/utility/startup_config.py
@@ -10,6 +10,7 @@ GREEN = '\033[92m'
BOLD = '\033[1m'
ENDC = '\033[0m'
+
def app_config():
app.config['SESSION_TYPE'] = 'filesystem'
if not app.config.get('SECRET_KEY'):
diff --git a/wqflask/utility/svg.py b/wqflask/utility/svg.py
index 4c478c36..f5ef81e1 100644
--- a/wqflask/utility/svg.py
+++ b/wqflask/utility/svg.py
@@ -459,11 +459,13 @@ class rect(SVGelement):
if stroke_width != None:
self.attributes['stroke-width'] = stroke_width
+
class ellipse(SVGelement):
"""e=ellipse(rx,ry,x,y,fill,stroke,stroke_width,**args)
an ellipse is defined as a center and a x and y radius.
"""
+
def __init__(self, cx=None, cy=None, rx=None, ry=None,fill=None,stroke=None,stroke_width=None,**args):
if rx == None or ry == None:
raise ValueError('both rx and ry are required')
@@ -486,6 +488,7 @@ class circle(SVGelement):
The circle creates an element using a x, y and radius values eg
"""
+
def __init__(self, cx=None, cy=None, r=None, fill=None,stroke=None,stroke_width=None,**args):
if r == None:
raise ValueError('r is required')
@@ -501,20 +504,24 @@ class circle(SVGelement):
if stroke_width != None:
self.attributes['stroke-width'] = stroke_width
+
class point(circle):
"""p=point(x,y,color)
A point is defined as a circle with a size 1 radius. It may be more efficient to use a
very small rectangle if you use many points because a circle is difficult to render.
"""
+
def __init__(self, x, y, fill='black', **args):
circle.__init__(self, x, y, 1, fill, **args)
+
class line(SVGelement):
"""l=line(x1,y1,x2,y2,stroke,stroke_width,**args)
A line is defined by a begin x,y pair and an end x,y pair
"""
+
def __init__(self, x1=None, y1=None, x2=None, y2=None,stroke=None,stroke_width=None,**args):
SVGelement.__init__(self, 'line', **args)
if x1 != None:
@@ -530,11 +537,13 @@ class line(SVGelement):
if stroke != None:
self.attributes['stroke'] = stroke
+
class polyline(SVGelement):
"""pl=polyline([[x1,y1],[x2,y2],...],fill,stroke,stroke_width,**args)
a polyline is defined by a list of xy pairs
"""
+
def __init__(self, points, fill=None, stroke=None, stroke_width=None,**args):
SVGelement.__init__(self, 'polyline', {'points': _xypointlist(points)}, **args)
if fill != None:
@@ -544,11 +553,13 @@ class polyline(SVGelement):
if stroke != None:
self.attributes['stroke'] = stroke
+
class polygon(SVGelement):
"""pl=polyline([[x1,y1],[x2,y2],...],fill,stroke,stroke_width,**args)
a polygon is defined by a list of xy pairs
"""
+
def __init__(self, points, fill=None, stroke=None, stroke_width=None,**args):
SVGelement.__init__(self, 'polygon', {'points': _xypointlist(points)}, **args)
if fill != None:
@@ -558,11 +569,13 @@ class polygon(SVGelement):
if stroke != None:
self.attributes['stroke'] = stroke
+
class path(SVGelement):
"""p=path(path,fill,stroke,stroke_width,**args)
a path is defined by a path object and optional width, stroke and fillcolor
"""
+
def __init__(self, pathdata, fill=None, stroke=None, stroke_width=None,id=None,**args):
SVGelement.__init__(self, 'path', {'d': str(pathdata)}, **args)
if stroke != None:
@@ -580,6 +593,7 @@ class text(SVGelement):
a text element can bge used for displaying text on the screen
"""
+
def __init__(self, x=None, y=None, text=None, font_size=None,font_family=None,text_anchor=None,**args):
SVGelement.__init__(self, 'text', **args)
if x != None:
@@ -601,11 +615,13 @@ class textpath(SVGelement):
a textpath places a text on a path which is referenced by a link.
"""
+
def __init__(self, link, text=None, **args):
SVGelement.__init__(self, 'textPath', {'xlink:href': link}, **args)
if text != None:
self.text = text
+
class pattern(SVGelement):
"""p=pattern(x,y,width,height,patternUnits,**args)
@@ -613,6 +629,7 @@ class pattern(SVGelement):
graphic object which can be replicated ("tiled") at fixed intervals
in x and y to cover the areas to be painted.
"""
+
def __init__(self, x=None, y=None, width=None, height=None,patternUnits=None,**args):
SVGelement.__init__(self, 'pattern', **args)
if x != None:
@@ -626,34 +643,40 @@ class pattern(SVGelement):
if patternUnits != None:
self.attributes['patternUnits'] = patternUnits
+
class title(SVGelement):
"""t=title(text,**args)
a title is a text element. The text is displayed in the title bar
add at least one to the root svg element
"""
+
def __init__(self, text=None, **args):
SVGelement.__init__(self, 'title', **args)
if text != None:
self.text = text
+
class description(SVGelement):
"""d=description(text,**args)
a description can be added to any element and is used for a tooltip
Add this element before adding other elements.
"""
+
def __init__(self, text=None, **args):
SVGelement.__init__(self, 'desc', **args)
if text != None:
self.text = text
+
class lineargradient(SVGelement):
"""lg=lineargradient(x1,y1,x2,y2,id,**args)
defines a lineargradient using two xy pairs.
stop elements van be added to define the gradient colors.
"""
+
def __init__(self, x1=None, y1=None, x2=None, y2=None,id=None,**args):
SVGelement.__init__(self, 'linearGradient', **args)
if x1 != None:
@@ -667,12 +690,14 @@ class lineargradient(SVGelement):
if id != None:
self.attributes['id'] = id
+
class radialgradient(SVGelement):
"""rg=radialgradient(cx,cy,r,fx,fy,id,**args)
defines a radial gradient using a outer circle which are defined by a cx,cy and r and by using a focalpoint.
stop elements van be added to define the gradient colors.
"""
+
def __init__(self, cx=None, cy=None, r=None, fx=None,fy=None,id=None,**args):
SVGelement.__init__(self, 'radialGradient', **args)
if cx != None:
@@ -688,21 +713,25 @@ class radialgradient(SVGelement):
if id != None:
self.attributes['id'] = id
+
class stop(SVGelement):
"""st=stop(offset,stop_color,**args)
Puts a stop color at the specified radius
"""
+
def __init__(self, offset, stop_color=None, **args):
SVGelement.__init__(self, 'stop', {'offset': offset}, **args)
if stop_color != None:
self.attributes['stop-color'] = stop_color
+
class style(SVGelement):
"""st=style(type,cdata=None,**args)
Add a CDATA element to this element for defing in line stylesheets etc..
"""
+
def __init__(self, type, cdata=None, **args):
SVGelement.__init__(self, 'style', {'type': type}, cdata=cdata, **args)
@@ -712,6 +741,7 @@ class image(SVGelement):
adds an image to the drawing. Supported formats are .png, .jpg and .svg.
"""
+
def __init__(self, url, x=None, y=None, width=None,height=None,**args):
if width == None or height == None:
raise ValueError('both height and width are required')
@@ -721,11 +751,13 @@ class image(SVGelement):
if y != None:
self.attributes['y'] = y
+
class cursor(SVGelement):
"""c=cursor(url,**args)
defines a custom cursor for a element or a drawing
"""
+
def __init__(self, url, **args):
SVGelement.__init__(self, 'cursor', {'xlink:href': url}, **args)
@@ -736,6 +768,7 @@ class marker(SVGelement):
defines a marker which can be used as an endpoint for a line or other pathtypes
add an element to it which should be used as a marker.
"""
+
def __init__(self, id=None, viewBox=None, refx=None, refy=None,markerWidth=None,markerHeight=None,**args):
SVGelement.__init__(self, 'marker', **args)
if id != None:
@@ -751,17 +784,20 @@ class marker(SVGelement):
if markerHeight != None:
self.attributes['markerHeight'] = markerHeight
+
class group(SVGelement):
"""g=group(id,**args)
a group is defined by an id and is used to contain elements
g.addElement(SVGelement)
"""
+
def __init__(self, id=None, **args):
SVGelement.__init__(self, 'g', **args)
if id != None:
self.attributes['id'] = id
+
class symbol(SVGelement):
"""sy=symbol(id,viewbox,**args)
@@ -778,14 +814,17 @@ class symbol(SVGelement):
if viewBox != None:
self.attributes['viewBox'] = _viewboxlist(viewBox)
+
class defs(SVGelement):
"""d=defs(**args)
container for defining elements
"""
+
def __init__(self, **args):
SVGelement.__init__(self, 'defs', **args)
+
class switch(SVGelement):
"""sw=switch(**args)
@@ -793,6 +832,7 @@ class switch(SVGelement):
requiredFeatures, requiredExtensions and systemLanguage.
Refer to the SVG specification for details.
"""
+
def __init__(self, **args):
SVGelement.__init__(self, 'switch', **args)
@@ -802,6 +842,7 @@ class use(SVGelement):
references a symbol by linking to its id and its position, height and width
"""
+
def __init__(self, link, x=None, y=None, width=None,height=None,**args):
SVGelement.__init__(self, 'use', {'xlink:href': link}, **args)
if x != None:
@@ -821,32 +862,39 @@ class link(SVGelement):
a link is defined by a hyperlink. add elements which have to be linked
a.addElement(SVGelement)
"""
+
def __init__(self, link='', **args):
SVGelement.__init__(self, 'a', {'xlink:href': link}, **args)
+
class view(SVGelement):
"""v=view(id,**args)
a view can be used to create a view with different attributes"""
+
def __init__(self, id=None, **args):
SVGelement.__init__(self, 'view', **args)
if id != None:
self.attributes['id'] = id
+
class script(SVGelement):
"""sc=script(type,type,cdata,**args)
adds a script element which contains CDATA to the SVG drawing
"""
+
def __init__(self, type, cdata=None, **args):
SVGelement.__init__(self, 'script', {'type': type}, cdata=cdata, **args)
+
class animate(SVGelement):
"""an=animate(attribute,from,to,during,**args)
animates an attribute.
"""
+
def __init__(self, attribute, fr=None, to=None, dur=None,**args):
SVGelement.__init__(self, 'animate', {'attributeName': attribute}, **args)
if fr != None:
@@ -856,11 +904,13 @@ class animate(SVGelement):
if dur != None:
self.attributes['dur'] = dur
+
class animateMotion(SVGelement):
"""an=animateMotion(pathdata,dur,**args)
animates a SVGelement over the given path in dur seconds
"""
+
def __init__(self, pathdata, dur, **args):
SVGelement.__init__(self, 'animateMotion', **args)
if pathdata != None:
@@ -868,11 +918,13 @@ class animateMotion(SVGelement):
if dur != None:
self.attributes['dur'] = dur
+
class animateTransform(SVGelement):
"""antr=animateTransform(type,from,to,dur,**args)
transform an element from and to a value.
"""
+
def __init__(self, type=None, fr=None, to=None, dur=None,**args):
SVGelement.__init__(self, 'animateTransform', {'attributeName': 'transform'}, **args)
# As far as I know the attributeName is always transform
@@ -884,11 +936,14 @@ class animateTransform(SVGelement):
self.attributes['to'] = to
if dur != None:
self.attributes['dur'] = dur
+
+
class animateColor(SVGelement):
"""ac=animateColor(attribute,type,from,to,dur,**args)
Animates the color of a element
"""
+
def __init__(self, attribute, type=None, fr=None, to=None,dur=None,**args):
SVGelement.__init__(self, 'animateColor', {'attributeName': attribute}, **args)
if type != None:
@@ -899,11 +954,14 @@ class animateColor(SVGelement):
self.attributes['to'] = to
if dur != None:
self.attributes['dur'] = dur
+
+
class set(SVGelement):
"""st=set(attribute,to,during,**args)
sets an attribute to a value for a
"""
+
def __init__(self, attribute, to=None, dur=None, **args):
SVGelement.__init__(self, 'set', {'attributeName': attribute}, **args)
if to != None:
@@ -912,7 +970,6 @@ class set(SVGelement):
self.attributes['dur'] = dur
-
class svg(SVGelement):
"""s=svg(viewbox,width,height,**args)
@@ -928,6 +985,7 @@ class svg(SVGelement):
d.setSVG(s)
d.toXml()
"""
+
def __init__(self, viewBox=None, width=None, height=None, **args):
SVGelement.__init__(self, 'svg', **args)
if viewBox != None:
@@ -938,6 +996,7 @@ class svg(SVGelement):
self.attributes['height'] = height
self.namespace = "http://www.w3.org/2000/svg"
+
class drawing:
"""d=drawing()
@@ -952,6 +1011,7 @@ class drawing:
def __init__(self, entity={}):
self.svg = None
self.entity = entity
+
def setSVG(self, svg):
self.svg = svg
# Voeg een element toe aan de grafiek toe.
@@ -1005,6 +1065,7 @@ class drawing:
root = implementation.createDocument(None, None, doctype)
# Create the xml document.
global appender
+
def appender(element, elementroot):
"""This recursive function appends elements to an element and sets the attributes
and type. It stops when alle elements have been appended"""
@@ -1053,6 +1114,7 @@ class drawing:
f.close()
except:
print(("Cannot write SVG file: " + filename))
+
def validate(self):
try:
import xml.parsers.xmlproc.xmlval
@@ -1066,9 +1128,10 @@ class drawing:
raise Exception("SVG is not well formed, see messages above")
else:
print("SVG well formed")
-if __name__ == '__main__':
+if __name__ == '__main__':
+
d = drawing()
s = svg((0, 0, 100, 100))
r = rect(-100, -100, 300, 300, 'cyan')
diff --git a/wqflask/utility/temp_data.py b/wqflask/utility/temp_data.py
index 2088ba9a..07c5a318 100644
--- a/wqflask/utility/temp_data.py
+++ b/wqflask/utility/temp_data.py
@@ -2,6 +2,7 @@ from redis import Redis
import simplejson as json
+
class TempData:
def __init__(self, temp_uuid):
diff --git a/wqflask/utility/tools.py b/wqflask/utility/tools.py
index 9b751344..4fe4db08 100644
--- a/wqflask/utility/tools.py
+++ b/wqflask/utility/tools.py
@@ -13,11 +13,13 @@ logger = logging.getLogger(__name__)
OVERRIDES = {}
+
def app_set(command_id, value):
"""Set application wide value"""
app.config.setdefault(command_id, value)
return value
+
def get_setting(command_id, guess=None):
"""Resolve a setting from the environment or the global settings in
app.config, with valid_path is a function checking whether the
@@ -66,12 +68,14 @@ def get_setting(command_id, guess=None):
# print("Set "+command_id+"="+str(command))
return command
+
def get_setting_bool(id):
v = get_setting(id)
if v not in [0, False, 'False', 'FALSE', None]:
return True
return False
+
def get_setting_int(id):
v = get_setting(id)
if isinstance(v, str):
@@ -80,21 +84,25 @@ def get_setting_int(id):
return 0
return v
+
def valid_bin(bin):
if os.path.islink(bin) or valid_file(bin):
return bin
return None
+
def valid_file(fn):
if os.path.isfile(fn):
return fn
return None
+
def valid_path(dir):
if os.path.isdir(dir):
return dir
return None
+
def js_path(module=None):
"""
Find the JS module in the two paths
@@ -107,38 +115,47 @@ def js_path(module=None):
return try_guix
raise "No JS path found for " + module + " (if not in Guix check JS_GN_PATH)"
+
def reaper_command(guess=None):
return get_setting("REAPER_COMMAND", guess)
+
def gemma_command(guess=None):
return assert_bin(get_setting("GEMMA_COMMAND", guess))
+
def gemma_wrapper_command(guess=None):
return assert_bin(get_setting("GEMMA_WRAPPER_COMMAND", guess))
+
def plink_command(guess=None):
return assert_bin(get_setting("PLINK_COMMAND", guess))
+
def flat_file_exists(subdir):
base = get_setting("GENENETWORK_FILES")
return valid_path(base + "/" + subdir)
+
def flat_files(subdir=None):
base = get_setting("GENENETWORK_FILES")
if subdir:
return assert_dir(base + "/" + subdir)
return assert_dir(base)
+
def assert_bin(fn):
if not valid_bin(fn):
raise Exception("ERROR: can not find binary " + fn)
return fn
+
def assert_dir(dir):
if not valid_path(dir):
raise Exception("ERROR: can not find directory " + dir)
return dir
+
def assert_writable_dir(dir):
try:
fn = dir + "/test.txt"
@@ -150,16 +167,19 @@ def assert_writable_dir(dir):
raise Exception('Unable to write test.txt to directory ' + dir)
return dir
+
def assert_file(fn):
if not valid_file(fn):
raise Exception('Unable to find file ' + fn)
return fn
+
def mk_dir(dir):
if not valid_path(dir):
os.makedirs(dir)
return assert_dir(dir)
+
def locate(name, subdir=None):
"""
Locate a static flat file in the GENENETWORK_FILES environment.
@@ -179,9 +199,11 @@ def locate(name, subdir=None):
if subdir: sys.stderr.write(subdir)
raise Exception("Can not locate " + name + " in " + base)
+
def locate_phewas(name, subdir=None):
return locate(name, '/phewas/' + subdir)
+
def locate_ignore_error(name, subdir=None):
"""
Locate a static flat file in the GENENETWORK_FILES environment.
@@ -200,17 +222,20 @@ def locate_ignore_error(name, subdir=None):
logger.info("WARNING: file " + name + " not found\n")
return None
+
def tempdir():
"""
Get UNIX TMPDIR by default
"""
return valid_path(get_setting("TMPDIR", "/tmp"))
+
BLUE = '\033[94m'
GREEN = '\033[92m'
BOLD = '\033[1m'
ENDC = '\033[0m'
+
def show_settings():
from utility.tools import LOG_LEVEL
diff --git a/wqflask/utility/type_checking.py b/wqflask/utility/type_checking.py
index 662bf794..00f14ba9 100644
--- a/wqflask/utility/type_checking.py
+++ b/wqflask/utility/type_checking.py
@@ -7,6 +7,7 @@ def is_float(value):
except:
return False
+
def is_int(value):
try:
int(value)
@@ -14,6 +15,7 @@ def is_int(value):
except:
return False
+
def is_str(value):
if value is None:
return False
@@ -23,18 +25,21 @@ def is_str(value):
except:
return False
+
def get_float(vars_obj, name, default=None):
if name in vars_obj:
if is_float(vars_obj[name]):
return float(vars_obj[name])
return default
+
def get_int(vars_obj, name, default=None):
if name in vars_obj:
if is_int(vars_obj[name]):
return float(vars_obj[name])
return default
+
def get_string(vars_obj, name, default=None):
if name in vars_obj:
if not vars_obj[name] is None:
diff --git a/wqflask/utility/webqtlUtil.py b/wqflask/utility/webqtlUtil.py
index ed59b0eb..f355a865 100644
--- a/wqflask/utility/webqtlUtil.py
+++ b/wqflask/utility/webqtlUtil.py
@@ -64,6 +64,7 @@ ParInfo = {
# Accessory Functions
#########################################
+
def genRandStr(prefix="", length=8, chars=string.ascii_letters + string.digits):
from random import choice
_str = prefix[:]
@@ -71,6 +72,7 @@ def genRandStr(prefix="", length=8, chars=string.ascii_letters + string.digits):
_str += choice(chars)
return _str
+
def ListNotNull(lst):
'''Obsolete - Use built in function any (or all or whatever)
@@ -83,6 +85,7 @@ def ListNotNull(lst):
return 1
return None
+
def readLineCSV(line): # dcrowell July 2008
"""Parses a CSV string of text and returns a list containing each element as a string.
Used by correlationPage"""
@@ -91,6 +94,7 @@ def readLineCSV(line): # dcrowell July 2008
returnList[0] = returnList[0][1:]
return returnList
+
def cmpEigenValue(A, B):
try:
if A[0] > B[0]:
@@ -102,6 +106,7 @@ def cmpEigenValue(A, B):
except:
return 0
+
def hasAccessToConfidentialPhenotypeTrait(privilege, userName, authorized_users):
access_to_confidential_phenotype_trait = 0
if webqtlConfig.USERDICT[privilege] > webqtlConfig.USERDICT['user']: