aboutsummaryrefslogtreecommitdiff
path: root/wqflask
diff options
context:
space:
mode:
Diffstat (limited to 'wqflask')
-rw-r--r--wqflask/base/GeneralObject.py8
-rw-r--r--wqflask/base/data_set.py16
-rw-r--r--wqflask/base/trait.py15
-rw-r--r--wqflask/db/call.py21
-rw-r--r--wqflask/db/webqtlDatabaseFunction.py8
-rw-r--r--wqflask/maintenance/gen_select_dataset.py12
-rw-r--r--wqflask/maintenance/generate_probesetfreeze_file.py2
-rw-r--r--wqflask/maintenance/quantile_normalize.py12
-rw-r--r--wqflask/maintenance/set_resource_defaults.py6
-rw-r--r--wqflask/run_gunicorn.py2
-rw-r--r--wqflask/utility/Plot.py52
-rw-r--r--wqflask/utility/__init__.py4
-rw-r--r--wqflask/utility/authentication_tools.py2
-rw-r--r--wqflask/utility/benchmark.py4
-rw-r--r--wqflask/utility/elasticsearch_tools.py2
-rw-r--r--wqflask/utility/gen_geno_ob.py2
-rw-r--r--wqflask/utility/helper_functions.py2
-rw-r--r--wqflask/utility/logger.py26
-rw-r--r--wqflask/utility/pillow_utils.py4
-rw-r--r--wqflask/utility/startup_config.py4
-rw-r--r--wqflask/utility/svg.py692
-rw-r--r--wqflask/utility/temp_data.py2
-rw-r--r--wqflask/utility/tools.py38
-rw-r--r--wqflask/utility/webqtlUtil.py22
-rw-r--r--wqflask/wqflask/api/correlation.py16
-rw-r--r--wqflask/wqflask/api/gen_menu.py6
-rw-r--r--wqflask/wqflask/api/router.py24
-rw-r--r--wqflask/wqflask/collect.py4
-rw-r--r--wqflask/wqflask/comparison_bar_chart/comparison_bar_chart.py2
-rw-r--r--wqflask/wqflask/correlation/corr_scatter_plot.py6
-rw-r--r--wqflask/wqflask/correlation/correlation_functions.py4
-rw-r--r--wqflask/wqflask/correlation/show_corr_results.py55
-rw-r--r--wqflask/wqflask/correlation_matrix/show_corr_matrix.py26
-rw-r--r--wqflask/wqflask/ctl/ctl_analysis.py4
-rw-r--r--wqflask/wqflask/do_search.py4
-rw-r--r--wqflask/wqflask/export_traits.py10
-rw-r--r--wqflask/wqflask/external_tools/send_to_geneweaver.py8
-rw-r--r--wqflask/wqflask/heatmap/heatmap.py8
-rw-r--r--wqflask/wqflask/interval_analyst/GeneUtil.py2
-rw-r--r--wqflask/wqflask/marker_regression/display_mapping_results.py216
-rw-r--r--wqflask/wqflask/marker_regression/plink_mapping.py16
-rw-r--r--wqflask/wqflask/marker_regression/qtlreaper_mapping.py2
-rw-r--r--wqflask/wqflask/marker_regression/rqtl_mapping.py2
-rw-r--r--wqflask/wqflask/marker_regression/run_mapping.py28
-rw-r--r--wqflask/wqflask/network_graph/network_graph.py6
-rw-r--r--wqflask/wqflask/news.py3
-rw-r--r--wqflask/wqflask/pbkdf2.py28
-rw-r--r--wqflask/wqflask/resource_manager.py2
-rw-r--r--wqflask/wqflask/search_results.py4
-rw-r--r--wqflask/wqflask/show_trait/SampleList.py4
-rw-r--r--wqflask/wqflask/show_trait/export_trait_data.py2
-rw-r--r--wqflask/wqflask/show_trait/show_trait.py12
-rw-r--r--wqflask/wqflask/snp_browser/snp_browser.py6
-rw-r--r--wqflask/wqflask/user_login.py2
-rw-r--r--wqflask/wqflask/user_manager.py4
-rw-r--r--wqflask/wqflask/views.py30
-rw-r--r--wqflask/wqflask/wgcna/wgcna_analysis.py12
57 files changed, 772 insertions, 744 deletions
diff --git a/wqflask/base/GeneralObject.py b/wqflask/base/GeneralObject.py
index 0fccaab3..707569db 100644
--- a/wqflask/base/GeneralObject.py
+++ b/wqflask/base/GeneralObject.py
@@ -33,7 +33,7 @@ class GeneralObject:
def __init__(self, *args, **kw):
self.contents = list(args)
- for name, value in kw.items():
+ for name, value in list(kw.items()):
setattr(self, name, value)
def __setitem__(self, key, value):
@@ -50,16 +50,16 @@ class GeneralObject:
def __str__(self):
s = ''
- for key in self.__dict__.keys():
+ for key in list(self.__dict__.keys()):
if key != 'contents':
s += '%s = %s\n' % (key, self.__dict__[key])
return s
def __repr__(self):
s = ''
- for key in self.__dict__.keys():
+ for key in list(self.__dict__.keys()):
s += '%s = %s\n' % (key, self.__dict__[key])
return s
def __cmp__(self, other):
- return len(self.__dict__.keys()).__cmp__(len(other.__dict__.keys()))
+ return len(list(self.__dict__.keys())).__cmp__(len(list(other.__dict__.keys())))
diff --git a/wqflask/base/data_set.py b/wqflask/base/data_set.py
index cfba9104..8151a29d 100644
--- a/wqflask/base/data_set.py
+++ b/wqflask/base/data_set.py
@@ -34,7 +34,6 @@ from utility import webqtlUtil
from db import webqtlDatabaseFunction
from base import species
from base import webqtlConfig
-import reaper
from flask import Flask, g
import os
import math
@@ -45,7 +44,7 @@ import codecs
import json
import requests
import gzip
-import cPickle as pickle
+import pickle as pickle
import itertools
from redis import Redis
@@ -254,12 +253,12 @@ class Markers(object):
logger.debug("length of self.markers:", len(self.markers))
logger.debug("length of p_values:", len(p_values))
- if type(p_values) is list:
+ if isinstance(p_values, list):
# THIS IS only needed for the case when we are limiting the number of p-values calculated
# if len(self.markers) > len(p_values):
# self.markers = self.markers[:len(p_values)]
- for marker, p_value in itertools.izip(self.markers, p_values):
+ for marker, p_value in zip(self.markers, p_values):
if not p_value:
continue
marker['p_value'] = float(p_value)
@@ -270,7 +269,7 @@ class Markers(object):
marker['lod_score'] = -math.log10(marker['p_value'])
# Using -log(p) for the LRS; need to ask Rob how he wants to get LRS from p-values
marker['lrs_value'] = -math.log10(marker['p_value']) * 4.61
- elif type(p_values) is dict:
+ elif isinstance(p_values, dict):
filtered_markers = []
for marker in self.markers:
#logger.debug("marker[name]", marker['name'])
@@ -456,12 +455,7 @@ class DatasetGroup(object):
full_filename = str(locate(self.genofile, 'genotype'))
else:
full_filename = str(locate(self.name + '.geno', 'genotype'))
-
- if use_reaper:
- genotype_1 = reaper.Dataset()
- genotype_1.read(full_filename)
- else:
- genotype_1 = gen_geno_ob.genotype(full_filename)
+ genotype_1 = gen_geno_ob.genotype(full_filename)
if genotype_1.type == "group" and self.parlist:
genotype_2 = genotype_1.add(
diff --git a/wqflask/base/trait.py b/wqflask/base/trait.py
index 7666348e..a19b66f7 100644
--- a/wqflask/base/trait.py
+++ b/wqflask/base/trait.py
@@ -6,7 +6,6 @@ import resource
import codecs
import requests
import random
-import urllib
from base import webqtlConfig
from base.webqtlCaseData import webqtlCaseData
@@ -118,7 +117,7 @@ class GeneralTrait(object):
vals = []
the_vars = []
sample_aliases = []
- for sample_name, sample_data in self.data.items():
+ for sample_name, sample_data in list(self.data.items()):
if sample_data.value != None:
if not include_variance or sample_data.variance != None:
samples.append(sample_name)
@@ -193,7 +192,7 @@ class GeneralTrait(object):
'''
if self.chr and self.mb:
- self.location = 'Chr %s @ %s Mb' % (self.chr,self.mb)
+ self.location = 'Chr %s @ %s Mb' % (self.chr, self.mb)
elif self.chr:
self.location = 'Chr %s @ Unknown position' % (self.chr)
else:
@@ -260,7 +259,7 @@ def get_sample_data():
trait_dict['pubmed_link'] = trait_ob.pubmed_link
trait_dict['pubmed_text'] = trait_ob.pubmed_text
- return json.dumps([trait_dict, {key: value.value for key, value in trait_ob.data.iteritems() }])
+ return json.dumps([trait_dict, {key: value.value for key, value in list(trait_ob.data.items()) }])
else:
return None
@@ -440,7 +439,7 @@ def retrieve_trait_info(trait, dataset, get_qtl_info=False):
#XZ, 05/08/2009: We also should use Geno.Id to find marker instead of just using Geno.Name
# to avoid the problem of same marker name from different species.
elif dataset.type == 'Geno':
- display_fields_string = string.join(dataset.display_fields,',Geno.')
+ display_fields_string = string.join(dataset.display_fields, ',Geno.')
display_fields_string = 'Geno.' + display_fields_string
query = """
SELECT %s
@@ -459,7 +458,7 @@ def retrieve_trait_info(trait, dataset, get_qtl_info=False):
query = """SELECT %s FROM %s WHERE Name = %s"""
logger.sql(query)
trait_info = g.db.execute(query,
- (string.join(dataset.display_fields,','),
+ (string.join(dataset.display_fields, ','),
dataset.type, trait.name)).fetchone()
if trait_info:
@@ -605,6 +604,6 @@ def retrieve_trait_info(trait, dataset, get_qtl_info=False):
if trait.lrs != "":
trait.LRS_score_repr = LRS_score_repr = '%3.1f' % trait.lrs
else:
- raise KeyError, `trait.name`+' information is not found in the database.'
+ raise KeyError(repr(trait.name)+' information is not found in the database.')
- return trait \ No newline at end of file
+ return trait
diff --git a/wqflask/db/call.py b/wqflask/db/call.py
index 1a1b3adc..0971d2a2 100644
--- a/wqflask/db/call.py
+++ b/wqflask/db/call.py
@@ -3,7 +3,10 @@
from flask import g
import string
-import urllib2
+try: # Python2 support
+ import urllib.request, urllib.error, urllib.parse
+except:
+ import urllib2
import json
from utility.tools import USE_GN_SERVER, LOG_SQL, GN_SERVER_URL
from utility.benchmark import Bench
@@ -26,8 +29,8 @@ GN_SERVER result when set (which should return a Tuple)
else:
res2 = result,
if LOG_SQL:
- logger.debug("Replaced SQL call",query)
- logger.debug(path,res2)
+ logger.debug("Replaced SQL call", query)
+ logger.debug(path, res2)
return res2
else:
return fetchone(query)
@@ -37,7 +40,7 @@ def fetchone(query):
original fetchone, but with logging)
"""
- with Bench("SQL",LOG_SQL):
+ with Bench("SQL", LOG_SQL):
def helper(query):
res = g.db.execute(query)
return res.fetchone()
@@ -48,7 +51,7 @@ def fetchall(query):
original fetchall, but with logging)
"""
- with Bench("SQL",LOG_SQL):
+ with Bench("SQL", LOG_SQL):
def helper(query):
res = g.db.execute(query)
return res.fetchall()
@@ -58,8 +61,12 @@ def gn_server(path):
"""Return JSON record by calling GN_SERVER
"""
- with Bench("GN_SERVER",LOG_SQL):
- res = urllib2.urlopen(GN_SERVER_URL+path)
+ with Bench("GN_SERVER", LOG_SQL):
+ res = ()
+ try:
+ res = urllib.request.urlopen(GN_SERVER_URL+path)
+ except:
+ res = urllib2.urlopen(GN_SERVER_URL+path)
rest = res.read()
res2 = json.loads(rest)
logger.debug(res2)
diff --git a/wqflask/db/webqtlDatabaseFunction.py b/wqflask/db/webqtlDatabaseFunction.py
index 8a9dc79d..2805febd 100644
--- a/wqflask/db/webqtlDatabaseFunction.py
+++ b/wqflask/db/webqtlDatabaseFunction.py
@@ -35,13 +35,13 @@ def retrieve_species(group):
"""Get the species of a group (e.g. returns string "mouse" on "BXD"
"""
- result = fetch1("select Species.Name from Species, InbredSet where InbredSet.Name = '%s' and InbredSet.SpeciesId = Species.Id" % (group),"/cross/"+group+".json",lambda r: (r["species"],))[0]
- logger.debug("retrieve_species result:",result)
+ result = fetch1("select Species.Name from Species, InbredSet where InbredSet.Name = '%s' and InbredSet.SpeciesId = Species.Id" % (group), "/cross/"+group+".json", lambda r: (r["species"],))[0]
+ logger.debug("retrieve_species result:", result)
return result
def retrieve_species_id(group):
- result = fetch1("select SpeciesId from InbredSet where Name = '%s'" % (group),"/cross/"+group+".json",lambda r: (r["species_id"],))[0]
- logger.debug("retrieve_species_id result:",result)
+ result = fetch1("select SpeciesId from InbredSet where Name = '%s'" % (group), "/cross/"+group+".json", lambda r: (r["species_id"],))[0]
+ logger.debug("retrieve_species_id result:", result)
return result
diff --git a/wqflask/maintenance/gen_select_dataset.py b/wqflask/maintenance/gen_select_dataset.py
index 647e58a2..fd65a52a 100644
--- a/wqflask/maintenance/gen_select_dataset.py
+++ b/wqflask/maintenance/gen_select_dataset.py
@@ -41,7 +41,7 @@ from __future__ import print_function, division
import sys
# NEW: Note we prepend the current path - otherwise a guix instance of GN2 may be used instead
-sys.path.insert(0,'./')
+sys.path.insert(0, './')
# NEW: import app to avoid a circular dependency on utility.tools
from wqflask import app
@@ -50,7 +50,7 @@ from utility.tools import locate, locate_ignore_error, TEMPDIR, SQL_URI
import MySQLdb
import simplejson as json
-import urlparse
+import urllib.parse
#import sqlalchemy as sa
@@ -66,7 +66,7 @@ from pprint import pformat as pf
def parse_db_uri():
"""Converts a database URI to the db name, host name, user name, and password"""
- parsed_uri = urlparse.urlparse(SQL_URI)
+ parsed_uri = urllib.parse.urlparse(SQL_URI)
db_conn_info = dict(
db = parsed_uri.path[1:],
@@ -108,7 +108,7 @@ def get_types(groups):
"""Build types list"""
types = {}
#print("Groups: ", pf(groups))
- for species, group_dict in groups.iteritems():
+ for species, group_dict in list(groups.items()):
types[species] = {}
for group_name, _group_full_name in group_dict:
# make group an alias to shorten the code
@@ -195,9 +195,9 @@ def build_types(species, group):
def get_datasets(types):
"""Build datasets list"""
datasets = {}
- for species, group_dict in types.iteritems():
+ for species, group_dict in list(types.items()):
datasets[species] = {}
- for group, type_list in group_dict.iteritems():
+ for group, type_list in list(group_dict.items()):
datasets[species][group] = {}
for type_name in type_list:
these_datasets = build_datasets(species, group, type_name[0])
diff --git a/wqflask/maintenance/generate_probesetfreeze_file.py b/wqflask/maintenance/generate_probesetfreeze_file.py
index b7b2dc8e..4231cc7c 100644
--- a/wqflask/maintenance/generate_probesetfreeze_file.py
+++ b/wqflask/maintenance/generate_probesetfreeze_file.py
@@ -82,7 +82,7 @@ def get_probeset_vals(cursor, dataset_name):
def trim_strains(strains, probeset_vals):
trimmed_strains = []
#print("probeset_vals is:", pf(probeset_vals))
- first_probeset = list(probeset_vals.itervalues())[0]
+ first_probeset = list(probeset_vals.values())[0]
print("\n**** first_probeset is:", pf(first_probeset))
for strain in strains:
print("\n**** strain is:", pf(strain))
diff --git a/wqflask/maintenance/quantile_normalize.py b/wqflask/maintenance/quantile_normalize.py
index 41a3aad8..4d6e03bf 100644
--- a/wqflask/maintenance/quantile_normalize.py
+++ b/wqflask/maintenance/quantile_normalize.py
@@ -1,12 +1,12 @@
from __future__ import absolute_import, print_function, division
import sys
-sys.path.insert(0,'./')
+sys.path.insert(0, './')
+
-from itertools import izip
import MySQLdb
-import urlparse
+import urllib.parse
import numpy as np
import pandas as pd
@@ -22,7 +22,7 @@ from utility.tools import ELASTICSEARCH_HOST, ELASTICSEARCH_PORT, SQL_URI
def parse_db_uri():
"""Converts a database URI to the db name, host name, user name, and password"""
- parsed_uri = urlparse.urlparse(SQL_URI)
+ parsed_uri = urllib.parse.urlparse(SQL_URI)
db_conn_info = dict(
db = parsed_uri.path[1:],
@@ -37,7 +37,7 @@ def create_dataframe(input_file):
with open(input_file) as f:
ncols = len(f.readline().split("\t"))
- input_array = np.loadtxt(open(input_file, "rb"), delimiter="\t", skiprows=1, usecols=range(1, ncols))
+ input_array = np.loadtxt(open(input_file, "rb"), delimiter="\t", skiprows=1, usecols=list(range(1, ncols)))
return pd.DataFrame(input_array)
#This function taken from https://github.com/ShawnLYU/Quantile_Normalize
@@ -60,7 +60,7 @@ def set_data(dataset_name):
sample_list = []
with open(orig_file, 'r') as orig_fh, open('/home/zas1024/cfw_data/quant_norm.csv', 'r') as quant_fh:
- for i, (line1, line2) in enumerate(izip(orig_fh, quant_fh)):
+ for i, (line1, line2) in enumerate(zip(orig_fh, quant_fh)):
trait_dict = {}
sample_list = []
if i == 0:
diff --git a/wqflask/maintenance/set_resource_defaults.py b/wqflask/maintenance/set_resource_defaults.py
index 54fd8e7e..abd5416c 100644
--- a/wqflask/maintenance/set_resource_defaults.py
+++ b/wqflask/maintenance/set_resource_defaults.py
@@ -22,7 +22,7 @@ import sys
import json
# NEW: Note we prepend the current path - otherwise a guix instance of GN2 may be used instead
-sys.path.insert(0,'./')
+sys.path.insert(0, './')
# NEW: import app to avoid a circular dependency on utility.tools
from wqflask import app
@@ -34,7 +34,7 @@ Redis = get_redis_conn()
import MySQLdb
-import urlparse
+import urllib.parse
from utility.logger import getLogger
logger = getLogger(__name__)
@@ -42,7 +42,7 @@ logger = getLogger(__name__)
def parse_db_uri():
"""Converts a database URI to the db name, host name, user name, and password"""
- parsed_uri = urlparse.urlparse(SQL_URI)
+ parsed_uri = urllib.parse.urlparse(SQL_URI)
db_conn_info = dict(
db = parsed_uri.path[1:],
diff --git a/wqflask/run_gunicorn.py b/wqflask/run_gunicorn.py
index adffdca3..58108e03 100644
--- a/wqflask/run_gunicorn.py
+++ b/wqflask/run_gunicorn.py
@@ -7,7 +7,7 @@
# from flask import Flask
# application = Flask(__name__)
-print "===> Starting up Gunicorn process"
+print("===> Starting up Gunicorn process")
from wqflask import app
from utility.startup_config import app_config
diff --git a/wqflask/utility/Plot.py b/wqflask/utility/Plot.py
index b9b71129..7d9d7649 100644
--- a/wqflask/utility/Plot.py
+++ b/wqflask/utility/Plot.py
@@ -54,7 +54,7 @@ def cformat(d, rank=0):
strD = "%2.6f" % d
if rank == 0:
- while strD[-1] in ('0','.'):
+ while strD[-1] in ('0', '.'):
if strD[-1] == '0' and strD[-2] == '.' and len(strD) <= 4:
break
elif strD[-1] == '.':
@@ -82,7 +82,7 @@ def frange(start, end=None, inc=1.0):
# Need to adjust the count. AFAICT, it always comes up one short.
count += 1
L = [start] * count
- for i in xrange(1, count):
+ for i in range(1, count):
L[i] = start + i * inc
return L
@@ -93,7 +93,7 @@ def find_outliers(vals):
>>> find_outliers([3.504, 5.234, 6.123, 7.234, 3.542, 5.341, 7.852, 4.555, 12.537])
(11.252500000000001, 0.5364999999999993)
- >>> >>> find_outliers([9,12,15,17,31,50,7,5,6,8])
+ >>> find_outliers([9,12,15,17,31,50,7,5,6,8])
(32.0, -8.0)
If there are no vals, returns None for the upper and lower bounds,
@@ -158,7 +158,7 @@ def plotBar(canvas, data, barColor=BLUE, axesColor=BLACK, labelColor=BLACK, XLab
j = int((item-xLow)/step)
Count[j] += 1
- yLow, yTop, stepY=detScale(0,max(Count))
+ yLow, yTop, stepY=detScale(0, max(Count))
#draw data
xScale = plotWidth/(xTop-xLow)
@@ -170,7 +170,7 @@ def plotBar(canvas, data, barColor=BLUE, axesColor=BLACK, labelColor=BLACK, XLab
xc = (dataXY[i]-xLow)*xScale+xLeftOffset
yc =-(count-yLow)*yScale+yTopOffset+plotHeight
im_drawer.rectangle(
- xy=((xc+2,yc),(xc+barWidth-2,yTopOffset+plotHeight)),
+ xy=((xc+2, yc), (xc+barWidth-2, yTopOffset+plotHeight)),
outline=barColor, fill=barColor)
#draw drawing region
@@ -179,81 +179,81 @@ def plotBar(canvas, data, barColor=BLUE, axesColor=BLACK, labelColor=BLACK, XLab
)
#draw scale
- scaleFont=ImageFont.truetype(font=COUR_FILE,size=11)
+ scaleFont=ImageFont.truetype(font=COUR_FILE, size=11)
x=xLow
for i in range(int(stepX)+1):
xc=xLeftOffset+(x-xLow)*xScale
im_drawer.line(
- xy=((xc,yTopOffset+plotHeight),(xc,yTopOffset+plotHeight+5)),
+ xy=((xc, yTopOffset+plotHeight), (xc, yTopOffset+plotHeight+5)),
fill=axesColor)
strX = cformat(d=x, rank=0)
im_drawer.text(
text=strX,
- xy=(xc-im_drawer.textsize(strX,font=scaleFont)[0]/2,
- yTopOffset+plotHeight+14),font=scaleFont)
+ xy=(xc-im_drawer.textsize(strX, font=scaleFont)[0]/2,
+ yTopOffset+plotHeight+14), font=scaleFont)
x+= (xTop - xLow)/stepX
y=yLow
for i in range(int(stepY)+1):
yc=yTopOffset+plotHeight-(y-yLow)*yScale
- im_drawer.line(xy=((xLeftOffset,yc),(xLeftOffset-5,yc)), fill=axesColor)
+ im_drawer.line(xy=((xLeftOffset, yc), (xLeftOffset-5, yc)), fill=axesColor)
strY = "%d" %y
im_drawer.text(
text=strY,
- xy=(xLeftOffset-im_drawer.textsize(strY,font=scaleFont)[0]-6,yc+5),
+ xy=(xLeftOffset-im_drawer.textsize(strY, font=scaleFont)[0]-6, yc+5),
font=scaleFont)
y+= (yTop - yLow)/stepY
#draw label
- labelFont=ImageFont.truetype(font=TAHOMA_FILE,size=17)
+ labelFont=ImageFont.truetype(font=TAHOMA_FILE, size=17)
if XLabel:
im_drawer.text(
text=XLabel,
xy=(xLeftOffset+(
- plotWidth-im_drawer.textsize(XLabel,font=labelFont)[0])/2.0,
+ plotWidth-im_drawer.textsize(XLabel, font=labelFont)[0])/2.0,
yTopOffset+plotHeight+yBottomOffset-10),
- font=labelFont,fill=labelColor)
+ font=labelFont, fill=labelColor)
if YLabel:
draw_rotated_text(canvas, text=YLabel,
xy=(19,
yTopOffset+plotHeight-(
plotHeight-im_drawer.textsize(
- YLabel,font=labelFont)[0])/2.0),
+ YLabel, font=labelFont)[0])/2.0),
font=labelFont, fill=labelColor, angle=90)
- labelFont=ImageFont.truetype(font=VERDANA_FILE,size=16)
+ labelFont=ImageFont.truetype(font=VERDANA_FILE, size=16)
if title:
im_drawer.text(
text=title,
xy=(xLeftOffset+(plotWidth-im_drawer.textsize(
- title,font=labelFont)[0])/2.0,
+ title, font=labelFont)[0])/2.0,
20),
- font=labelFont,fill=labelColor)
+ font=labelFont, fill=labelColor)
# This function determines the scale of the plot
-def detScaleOld(min,max):
+def detScaleOld(min, max):
if min>=max:
return None
elif min == -1.0 and max == 1.0:
- return [-1.2,1.2,12]
+ return [-1.2, 1.2, 12]
else:
a=max-min
b=floor(log10(a))
- c=pow(10.0,b)
+ c=pow(10.0, b)
if a < c*5.0:
c/=2.0
#print a,b,c
low=c*floor(min/c)
high=c*ceil(max/c)
- return [low,high,round((high-low)/c)]
+ return [low, high, round((high-low)/c)]
def detScale(min=0,max=0):
if min>=max:
return None
elif min == -1.0 and max == 1.0:
- return [-1.2,1.2,12]
+ return [-1.2, 1.2, 12]
else:
a=max-min
if max != 0:
@@ -265,7 +265,7 @@ def detScale(min=0,max=0):
min -= 0.1*a
a=max-min
b=floor(log10(a))
- c=pow(10.0,b)
+ c=pow(10.0, b)
low=c*floor(min/c)
high=c*ceil(max/c)
n = round((high-low)/c)
@@ -283,7 +283,7 @@ def detScale(min=0,max=0):
high=c*ceil(max/c)
n = round((high-low)/c)
- return [low,high,n]
+ return [low, high, n]
def bluefunc(x):
return 1.0 / (1.0 + exp(-10*(x-0.6)))
@@ -292,7 +292,7 @@ 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)
+ return 1 - pow(redfunc(x+0.2), 2) - bluefunc(x-0.3)
def colorSpectrum(n=100):
multiple = 10
diff --git a/wqflask/utility/__init__.py b/wqflask/utility/__init__.py
index d9856eed..204ff59a 100644
--- a/wqflask/utility/__init__.py
+++ b/wqflask/utility/__init__.py
@@ -19,7 +19,7 @@ class Struct(object):
'''
def __init__(self, obj):
- for k, v in obj.iteritems():
+ for k, v in list(obj.items()):
if isinstance(v, dict):
setattr(self, k, Struct(v))
else:
@@ -30,6 +30,6 @@ class Struct(object):
def __repr__(self):
return '{%s}' % str(', '.join('%s : %s' % (k, repr(v)) for
- (k, v) in self.__dict__.iteritems()))
+ (k, v) in list(self.__dict__.items())))
diff --git a/wqflask/utility/authentication_tools.py b/wqflask/utility/authentication_tools.py
index ece7022c..bc03eb55 100644
--- a/wqflask/utility/authentication_tools.py
+++ b/wqflask/utility/authentication_tools.py
@@ -17,7 +17,7 @@ logger = logging.getLogger(__name__ )
def check_resource_availability(dataset, trait_id=None):
#At least for now assume temporary entered traits are accessible
- if type(dataset) == str:
+ if isinstance(dataset, str):
return webqtlConfig.DEFAULT_PRIVILEGES
if dataset.type == "Temp":
return webqtlConfig.DEFAULT_PRIVILEGES
diff --git a/wqflask/utility/benchmark.py b/wqflask/utility/benchmark.py
index 8f1c916b..221e5151 100644
--- a/wqflask/utility/benchmark.py
+++ b/wqflask/utility/benchmark.py
@@ -38,9 +38,9 @@ class Bench(object):
@classmethod
def report(cls):
- total_time = sum((time_taken for time_taken in cls.entries.itervalues()))
+ total_time = sum((time_taken for time_taken in list(cls.entries.values())))
print("\nTiming report\n")
- for name, time_taken in cls.entries.iteritems():
+ for name, time_taken in list(cls.entries.items()):
percent = int(round((time_taken/total_time) * 100))
print("[{}%] {}: {}".format(percent, name, time_taken))
print()
diff --git a/wqflask/utility/elasticsearch_tools.py b/wqflask/utility/elasticsearch_tools.py
index 15cdd0bc..a5580811 100644
--- a/wqflask/utility/elasticsearch_tools.py
+++ b/wqflask/utility/elasticsearch_tools.py
@@ -59,7 +59,7 @@ def get_elasticsearch_connection(for_user=True):
try:
assert(ELASTICSEARCH_HOST)
assert(ELASTICSEARCH_PORT)
- logger.info("ES HOST",ELASTICSEARCH_HOST)
+ logger.info("ES HOST", ELASTICSEARCH_HOST)
es = Elasticsearch([{
"host": ELASTICSEARCH_HOST, "port": ELASTICSEARCH_PORT
diff --git a/wqflask/utility/gen_geno_ob.py b/wqflask/utility/gen_geno_ob.py
index 23b0b650..ae42f834 100644
--- a/wqflask/utility/gen_geno_ob.py
+++ b/wqflask/utility/gen_geno_ob.py
@@ -175,7 +175,7 @@ class Locus(object):
start_pos = 3
for allele in marker_row[start_pos:]:
- if allele in geno_table.keys():
+ if allele in list(geno_table.keys()):
self.genotype.append(geno_table[allele])
else: #ZS: Some genotype appears that isn't specified in the metadata, make it unknown
self.genotype.append("U") \ No newline at end of file
diff --git a/wqflask/utility/helper_functions.py b/wqflask/utility/helper_functions.py
index 9ce809b6..9a4a235a 100644
--- a/wqflask/utility/helper_functions.py
+++ b/wqflask/utility/helper_functions.py
@@ -13,7 +13,7 @@ logger = logging.getLogger(__name__ )
def get_species_dataset_trait(self, start_vars):
#assert type(read_genotype) == type(bool()), "Expecting boolean value for read_genotype"
- if "temp_trait" in start_vars.keys():
+ if "temp_trait" in list(start_vars.keys()):
if start_vars['temp_trait'] == "True":
self.dataset = data_set.create_dataset(dataset_name = "Temp", dataset_type = "Temp", group_name = start_vars['group'])
else:
diff --git a/wqflask/utility/logger.py b/wqflask/utility/logger.py
index 510b1041..e904eb94 100644
--- a/wqflask/utility/logger.py
+++ b/wqflask/utility/logger.py
@@ -42,10 +42,10 @@ class GNLogger:
"""
- def __init__(self,name):
+ def __init__(self, name):
self.logger = logging.getLogger(name)
- def setLevel(self,value):
+ def setLevel(self, value):
"""Set the undelying log level"""
self.logger.setLevel(value)
@@ -54,7 +54,7 @@ class GNLogger:
level=num to filter on LOG_LEVEL_DEBUG.
"""
- self.collect(self.logger.debug,*args)
+ self.collect(self.logger.debug, *args)
def debug20(self,*args):
"""Call logging.debug for multiple args. Use level=num to filter on
@@ -63,15 +63,15 @@ LOG_LEVEL_DEBUG (NYI).
"""
if level <= LOG_LEVEL_DEBUG:
if self.logger.getEffectiveLevel() < 20:
- self.collect(self.logger.debug,*args)
+ self.collect(self.logger.debug, *args)
def info(self,*args):
"""Call logging.info for multiple args"""
- self.collect(self.logger.info,*args)
+ self.collect(self.logger.info, *args)
def warning(self,*args):
"""Call logging.warning for multiple args"""
- self.collect(self.logger.warning,*args)
+ self.collect(self.logger.warning, *args)
# self.logger.warning(self.collect(*args))
def error(self,*args):
@@ -79,13 +79,13 @@ LOG_LEVEL_DEBUG (NYI).
now = datetime.datetime.utcnow()
time_str = now.strftime('%H:%M:%S UTC %Y%m%d')
l = [time_str]+list(args)
- self.collect(self.logger.error,*l)
+ self.collect(self.logger.error, *l)
def infof(self,*args):
"""Call logging.info for multiple args lazily"""
# only evaluate function when logging
if self.logger.getEffectiveLevel() < 30:
- self.collectf(self.logger.debug,*args)
+ self.collectf(self.logger.debug, *args)
def debugf(self,level=0,*args):
"""Call logging.debug for multiple args lazily and handle
@@ -95,15 +95,15 @@ LOG_LEVEL_DEBUG (NYI).
# only evaluate function when logging
if level <= LOG_LEVEL_DEBUG:
if self.logger.getEffectiveLevel() < 20:
- self.collectf(self.logger.debug,*args)
+ self.collectf(self.logger.debug, *args)
def sql(self, sqlcommand, fun = None):
"""Log SQL command, optionally invoking a timed fun"""
if LOG_SQL:
caller = stack()[1][3]
- if caller in ['fetchone','fetch1','fetchall']:
+ if caller in ['fetchone', 'fetch1', 'fetchall']:
caller = stack()[2][3]
- self.info(caller,sqlcommand)
+ self.info(caller, sqlcommand)
if fun:
result = fun(sqlcommand)
if LOG_SQL:
@@ -119,7 +119,7 @@ LOG_LEVEL_DEBUG (NYI).
if isinstance(a, str):
out = out + a
else:
- out = out + pf(a,width=160)
+ out = out + pf(a, width=160)
fun(out)
def collectf(self,fun,*args):
@@ -134,7 +134,7 @@ LOG_LEVEL_DEBUG (NYI).
if isinstance(a, str):
out = out + a
else:
- out = out + pf(a,width=160)
+ out = out + pf(a, width=160)
fun(out)
# Get the module logger. You can override log levels at the
diff --git a/wqflask/utility/pillow_utils.py b/wqflask/utility/pillow_utils.py
index 0c2ce7af..c486abba 100644
--- a/wqflask/utility/pillow_utils.py
+++ b/wqflask/utility/pillow_utils.py
@@ -12,9 +12,9 @@ WHITE = ImageColor.getrgb("white")
def draw_rotated_text(canvas, text, font, xy, fill=BLACK, angle=-90):
# type: (Image, str, ImageFont, tuple, ImageColor, int)
"""Utility function draw rotated text"""
- tmp_img = Image.new("RGBA", font.getsize(text), color=(0,0,0,0))
+ tmp_img = Image.new("RGBA", font.getsize(text), color=(0, 0, 0, 0))
draw_text = ImageDraw.Draw(tmp_img)
- draw_text.text(text=text, xy=(0,0), font=font, fill=fill)
+ draw_text.text(text=text, xy=(0, 0), font=font, fill=fill)
tmp_img2 = tmp_img.rotate(angle, expand=1)
tmp_img2.save("/{0}/{1}.png".format(TEMPDIR, text), format="png")
canvas.paste(im=tmp_img2, box=tuple([int(i) for i in xy]))
diff --git a/wqflask/utility/startup_config.py b/wqflask/utility/startup_config.py
index 817284dd..f1aaebb6 100644
--- a/wqflask/utility/startup_config.py
+++ b/wqflask/utility/startup_config.py
@@ -27,7 +27,7 @@ def app_config():
port = get_setting_int("SERVER_PORT")
if get_setting_bool("USE_GN_SERVER"):
- print("GN2 API server URL is ["+BLUE+get_setting("GN_SERVER_URL")+ENDC+"]")
+ print(("GN2 API server URL is ["+BLUE+get_setting("GN_SERVER_URL")+ENDC+"]"))
import requests
page = requests.get(get_setting("GN_SERVER_URL"))
if page.status_code != 200:
@@ -36,4 +36,4 @@ def app_config():
# import utility.elasticsearch_tools as es
# es.test_elasticsearch_connection()
- print("GN2 is running. Visit %s[http://localhost:%s/%s](%s)" % (BLUE,str(port),ENDC,get_setting("WEBSERVER_URL")))
+ print(("GN2 is running. Visit %s[http://localhost:%s/%s](%s)" % (BLUE, str(port), ENDC, get_setting("WEBSERVER_URL"))))
diff --git a/wqflask/utility/svg.py b/wqflask/utility/svg.py
index db13b9d1..b92cc2d1 100644
--- a/wqflask/utility/svg.py
+++ b/wqflask/utility/svg.py
@@ -25,54 +25,56 @@
# Last updated by GeneNetwork Core Team 2010/10/20
#!/usr/bin/env python
-##Copyright (c) 2002, Fedor Baart & Hans de Wit (Stichting Farmaceutische Kengetallen)
-##All rights reserved.
+# Copyright (c) 2002, Fedor Baart & Hans de Wit (Stichting Farmaceutische Kengetallen)
+# All rights reserved.
##
-##Redistribution and use in source and binary forms, with or without modification,
-##are permitted provided that the following conditions are met:
+# Redistribution and use in source and binary forms, with or without modification,
+# are permitted provided that the following conditions are met:
##
-##Redistributions of source code must retain the above copyright notice, this
-##list of conditions and the following disclaimer.
+# Redistributions of source code must retain the above copyright notice, this
+# list of conditions and the following disclaimer.
##
-##Redistributions in binary form must reproduce the above copyright notice,
-##this list of conditions and the following disclaimer in the documentation and/or
-##other materials provided with the distribution.
+# Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation and/or
+# other materials provided with the distribution.
##
-##Neither the name of the Stichting Farmaceutische Kengetallen nor the names of
-##its contributors may be used to endorse or promote products derived from this
-##software without specific prior written permission.
+# Neither the name of the Stichting Farmaceutische Kengetallen nor the names of
+# its contributors may be used to endorse or promote products derived from this
+# software without specific prior written permission.
##
-##THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-##AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-##IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-##DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
-##FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-##DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-##SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-##CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-##OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-##OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+# Thanks to Gerald Rosennfellner for his help and useful comments.
-##Thanks to Gerald Rosennfellner for his help and useful comments.
-
-__doc__="""Use SVGdraw to generate your SVGdrawings.
+import sys
+import exceptions
+__doc__ = """Use SVGdraw to generate your SVGdrawings.
SVGdraw uses an object model drawing and a method toXML to create SVG graphics
by using easy to use classes and methods usualy you start by creating a drawing eg
d=drawing()
- #then you create a SVG root element
+ # then you create a SVG root element
s=svg()
- #then you add some elements eg a circle and add it to the svg root element
+ # then you add some elements eg a circle and add it to the svg root element
c=circle()
- #you can supply attributes by using named arguments.
+ # you can supply attributes by using named arguments.
c=circle(fill='red',stroke='blue')
- #or by updating the attributes attribute:
+ # or by updating the attributes attribute:
c.attributes['stroke-width']=1
s.addElement(c)
- #then you add the svg root element to the drawing
+ # then you add the svg root element to the drawing
d.setSVG(s)
- #and finaly you xmlify the drawing
+ # and finaly you xmlify the drawing
d.toXml()
@@ -82,7 +84,7 @@ This module was created using the SVG specification of www.w3c.org and the
O'Reilly (www.oreilly.com) python books as information sources. A svg viewer
is available from www.adobe.com"""
-__version__="1.0"
+__version__ = "1.0"
# there are two possibilities to generate svg:
# via a dom implementation and directly using <element>text</element> strings
@@ -93,33 +95,34 @@ __version__="1.0"
# Note that PyXML is required for using the dom implementation.
# It is also possible to use the standard minidom. But I didn't try that one.
# Anyway the text based approach is about 60 times faster than using the full dom implementation.
-use_dom_implementation=0
+use_dom_implementation = 0
-import exceptions
-if use_dom_implementation<>0:
+if use_dom_implementation != 0:
try:
from xml.dom import implementation
from xml.dom.ext import PrettyPrint
except:
- raise exceptions.ImportError, "PyXML is required for using the dom implementation"
-#The implementation is used for the creating the XML document.
-#The prettyprint module is used for converting the xml document object to a xml file
+ raise exceptions.ImportError(
+ "PyXML is required for using the dom implementation")
+# The implementation is used for the creating the XML document.
+# The prettyprint module is used for converting the xml document object to a xml file
+
+assert sys.version_info[0] >= 2
+if sys.version_info[1] < 2:
+ True = 1
+ False = 0
+ file = open
+
+sys.setrecursionlimit = 50
+# The recursion limit is set conservative so mistakes like s=svg() s.addElement(s)
+# won't eat up too much processor time.
+
+# the following code is pasted form xml.sax.saxutils
+# it makes it possible to run the code without the xml sax package installed
+# To make it possible to have <rubbish> in your text elements, it is necessary to escape the texts
+
-import sys
-assert sys.version_info[0]>=2
-if sys.version_info[1]<2:
- True=1
- False=0
- file=open
-
-sys.setrecursionlimit=50
-#The recursion limit is set conservative so mistakes like s=svg() s.addElement(s)
-#won't eat up too much processor time.
-
-#the following code is pasted form xml.sax.saxutils
-#it makes it possible to run the code without the xml sax package installed
-#To make it possible to have <rubbish> in your text elements, it is necessary to escape the texts
def _escape(data, entities={}):
"""Escape &, <, and > in a string of data.
@@ -127,13 +130,14 @@ def _escape(data, entities={}):
the optional entities parameter. The keys and values must all be
strings; each key will be replaced with its corresponding value.
"""
- #data = data.replace("&", "&amp;")
+ # data = data.replace("&", "&amp;")
data = data.replace("<", "&lt;")
data = data.replace(">", "&gt;")
- for chars, entity in entities.items():
+ for chars, entity in list(entities.items()):
data = data.replace(chars, entity)
return data
+
def _quoteattr(data, entities={}):
"""Escape and quote an attribute value.
@@ -156,96 +160,121 @@ def _quoteattr(data, entities={}):
return data
-
def _xypointlist(a):
"""formats a list of xy pairs"""
- s=''
- for e in a: #this could be done more elegant
- s+=str(e)[1:-1] +' '
+ s = ''
+ for e in a: # this could be done more elegant
+ s += str(e)[1:-1] + ' '
return s
+
def _viewboxlist(a):
"""formats a tuple"""
- s=''
+ s = ''
for e in a:
- s+=str(e)+' '
+ s += str(e)+' '
return s
+
def _pointlist(a):
"""formats a list of numbers"""
return str(a)[1:-1]
+
class pathdata:
"""class used to create a pathdata object which can be used for a path.
although most methods are pretty straightforward it might be useful to look at the SVG specification."""
- #I didn't test the methods below.
- def __init__(self,x=None,y=None):
- self.path=[]
+ # I didn't test the methods below.
+
+ def __init__(self, x=None, y=None):
+ self.path = []
if x is not None and y is not None:
self.path.append('M '+str(x)+' '+str(y))
+
def closepath(self):
"""ends the path"""
self.path.append('z')
- def move(self,x,y):
+
+ def move(self, x, y):
"""move to absolute"""
self.path.append('M '+str(x)+' '+str(y))
- def relmove(self,x,y):
+
+ def relmove(self, x, y):
"""move to relative"""
self.path.append('m '+str(x)+' '+str(y))
- def line(self,x,y):
+
+ def line(self, x, y):
"""line to absolute"""
self.path.append('L '+str(x)+' '+str(y))
- def relline(self,x,y):
+
+ def relline(self, x, y):
"""line to relative"""
self.path.append('l '+str(x)+' '+str(y))
- def hline(self,x):
+
+ def hline(self, x):
"""horizontal line to absolute"""
self.path.append('H'+str(x))
- def relhline(self,x):
+
+ def relhline(self, x):
"""horizontal line to relative"""
self.path.append('h'+str(x))
- def vline(self,y):
+
+ def vline(self, y):
"""verical line to absolute"""
self.path.append('V'+str(y))
- def relvline(self,y):
+
+ def relvline(self, y):
"""vertical line to relative"""
self.path.append('v'+str(y))
- def bezier(self,x1,y1,x2,y2,x,y):
+
+ def bezier(self, x1, y1, x2, y2, x, y):
"""bezier with xy1 and xy2 to xy absolut"""
- self.path.append('C'+str(x1)+','+str(y1)+' '+str(x2)+','+str(y2)+' '+str(x)+','+str(y))
- def relbezier(self,x1,y1,x2,y2,x,y):
+ self.path.append('C'+str(x1)+','+str(y1)+' '+str(x2) +
+ ','+str(y2)+' '+str(x)+','+str(y))
+
+ def relbezier(self, x1, y1, x2, y2, x, y):
"""bezier with xy1 and xy2 to xy relative"""
- self.path.append('c'+str(x1)+','+str(y1)+' '+str(x2)+','+str(y2)+' '+str(x)+','+str(y))
- def smbezier(self,x2,y2,x,y):
+ self.path.append('c'+str(x1)+','+str(y1)+' '+str(x2) +
+ ','+str(y2)+' '+str(x)+','+str(y))
+
+ def smbezier(self, x2, y2, x, y):
"""smooth bezier with xy2 to xy absolut"""
self.path.append('S'+str(x2)+','+str(y2)+' '+str(x)+','+str(y))
- def relsmbezier(self,x2,y2,x,y):
+
+ def relsmbezier(self, x2, y2, x, y):
"""smooth bezier with xy2 to xy relative"""
self.path.append('s'+str(x2)+','+str(y2)+' '+str(x)+','+str(y))
- def qbezier(self,x1,y1,x,y):
+
+ def qbezier(self, x1, y1, x, y):
"""quadratic bezier with xy1 to xy absolut"""
self.path.append('Q'+str(x1)+','+str(y1)+' '+str(x)+','+str(y))
- def relqbezier(self,x1,y1,x,y):
+
+ def relqbezier(self, x1, y1, x, y):
"""quadratic bezier with xy1 to xy relative"""
self.path.append('q'+str(x1)+','+str(y1)+' '+str(x)+','+str(y))
- def smqbezier(self,x,y):
+
+ def smqbezier(self, x, y):
"""smooth quadratic bezier to xy absolut"""
self.path.append('T'+str(x)+','+str(y))
- def relsmqbezier(self,x,y):
+
+ def relsmqbezier(self, x, y):
"""smooth quadratic bezier to xy relative"""
self.path.append('t'+str(x)+','+str(y))
- def ellarc(self,rx,ry,xrot,laf,sf,x,y):
+
+ def ellarc(self, rx, ry, xrot, laf, sf, x, y):
"""elliptival arc with rx and ry rotating with xrot using large-arc-flag and sweep-flag to xy absolut"""
- self.path.append('A'+str(rx)+','+str(ry)+' '+str(xrot)+' '+str(laf)+' '+str(sf)+' '+str(x)+' '+str(y))
- def relellarc(self,rx,ry,xrot,laf,sf,x,y):
+ self.path.append('A'+str(rx)+','+str(ry)+' '+str(xrot) +
+ ' '+str(laf)+' '+str(sf)+' '+str(x)+' '+str(y))
+
+ def relellarc(self, rx, ry, xrot, laf, sf, x, y):
"""elliptival arc with rx and ry rotating with xrot using large-arc-flag and sweep-flag to xy relative"""
- self.path.append('a'+str(rx)+','+str(ry)+' '+str(xrot)+' '+str(laf)+' '+str(sf)+' '+str(x)+' '+str(y))
+ self.path.append('a'+str(rx)+','+str(ry)+' '+str(xrot) +
+ ' '+str(laf)+' '+str(sf)+' '+str(x)+' '+str(y))
+
def __repr__(self):
return ' '.join(self.path)
-
-
class SVGelement:
"""SVGelement(type,attributes,elements,text,namespace,**args)
Creates a arbitrary svg element and is intended to be subclassed not used on its own.
@@ -256,52 +285,56 @@ class SVGelement:
namespace. Note the elements==None, if elements = None:self.elements=[] construction.
This is done because if you default to elements=[] every object has a reference
to the same empty list."""
- def __init__(self,type='',attributes=None,elements=None,text='',namespace='',cdata=None, **args):
- self.type=type
- if attributes==None:
- self.attributes={}
+
+ def __init__(self, type='', attributes=None, elements=None, text='', namespace='', cdata=None, **args):
+ self.type = type
+ if attributes == None:
+ self.attributes = {}
else:
- self.attributes=attributes
- if elements==None:
- self.elements=[]
+ self.attributes = attributes
+ if elements == None:
+ self.elements = []
else:
- self.elements=elements
- self.text=text
- self.namespace=namespace
- self.cdata=cdata
- for arg in args.keys():
+ self.elements = elements
+ self.text = text
+ self.namespace = namespace
+ self.cdata = cdata
+ for arg in list(args.keys()):
arg2 = arg.replace("__", ":")
arg2 = arg2.replace("_", "-")
- self.attributes[arg2]=args[arg]
- def addElement(self,SVGelement):
+ self.attributes[arg2] = args[arg]
+
+ def addElement(self, SVGelement):
"""adds an element to a SVGelement
SVGelement.addElement(SVGelement)
"""
self.elements.append(SVGelement)
- def toXml(self,level,f):
+ def toXml(self, level, f):
f.write('\t'*level)
f.write('<'+self.type)
- for attkey in self.attributes.keys():
- f.write(' '+_escape(str(attkey))+'='+_quoteattr(str(self.attributes[attkey])))
+ for attkey in list(self.attributes.keys()):
+ f.write(' '+_escape(str(attkey))+'=' +
+ _quoteattr(str(self.attributes[attkey])))
if self.namespace:
- f.write(' xmlns="'+ _escape(str(self.namespace))+'" xmlns:xlink="http://www.w3.org/1999/xlink"')
+ f.write(' xmlns="' + _escape(str(self.namespace)) +
+ '" xmlns:xlink="http://www.w3.org/1999/xlink"')
if self.elements or self.text or self.cdata:
f.write('>')
if self.elements:
f.write('\n')
for element in self.elements:
- element.toXml(level+1,f)
+ element.toXml(level+1, f)
if self.cdata:
f.write('\n'+'\t'*(level+1)+'<![CDATA[')
for line in self.cdata.splitlines():
f.write('\n'+'\t'*(level+2)+line)
f.write('\n'+'\t'*(level+1)+']]>\n')
if self.text:
- if type(self.text)==type(''): #If the text is only text
+ if isinstance(self.text, type('')): # If the text is only text
f.write(_escape(str(self.text)))
- else: #If the text is a spannedtext class
+ else: # If the text is a spannedtext class
f.write(str(self.text))
if self.elements:
f.write('\t'*level+'</'+self.type+'>\n')
@@ -312,6 +345,7 @@ class SVGelement:
else:
f.write('/>\n')
+
class tspan(SVGelement):
"""ts=tspan(text='',**args)
@@ -323,19 +357,22 @@ class tspan(SVGelement):
st.addtspan(ts)
t=text(3,5,st)
"""
- def __init__(self,text=None,**args):
- SVGelement.__init__(self,'tspan',**args)
- if self.text<>None:
- self.text=text
+
+ def __init__(self, text=None, **args):
+ SVGelement.__init__(self, 'tspan', **args)
+ if self.text != None:
+ self.text = text
+
def __repr__(self):
- s="<tspan"
- for key,value in self.attributes.items():
- s+= ' %s="%s"' % (key,value)
- s+='>'
- s+=self.text
- s+='</tspan>'
+ s = "<tspan"
+ for key, value in list(self.attributes.items()):
+ s += ' %s="%s"' % (key, value)
+ s += '>'
+ s += self.text
+ s += '</tspan>'
return s
+
class tref(SVGelement):
"""tr=tref(link='',**args)
@@ -346,16 +383,19 @@ class tref(SVGelement):
st.addtref(tr)
t=text(3,5,st)
"""
- def __init__(self,link,**args):
- SVGelement.__init__(self,'tref',{'xlink:href':link},**args)
+
+ def __init__(self, link, **args):
+ SVGelement.__init__(self, 'tref', {'xlink:href': link}, **args)
+
def __repr__(self):
- s="<tref"
+ s = "<tref"
- for key,value in self.attributes.items():
- s+= ' %s="%s"' % (key,value)
- s+='/>'
+ for key, value in list(self.attributes.items()):
+ s += ' %s="%s"' % (key, value)
+ s += '/>'
return s
+
class spannedtext:
"""st=spannedtext(textlist=[])
@@ -374,46 +414,49 @@ class spannedtext:
st.addtext('This text is not bold')
t=text(3,5,st)
"""
- def __init__(self,textlist=None):
- if textlist==None:
- self.textlist=[]
+
+ def __init__(self, textlist=None):
+ if textlist == None:
+ self.textlist = []
else:
- self.textlist=textlist
- def addtext(self,text=''):
+ self.textlist = textlist
+
+ def addtext(self, text=''):
self.textlist.append(text)
- def addtspan(self,tspan):
+
+ def addtspan(self, tspan):
self.textlist.append(tspan)
- def addtref(self,tref):
+
+ def addtref(self, tref):
self.textlist.append(tref)
+
def __repr__(self):
- s=""
+ s = ""
for element in self.textlist:
- s+=str(element)
+ s += str(element)
return s
+
class rect(SVGelement):
"""r=rect(width,height,x,y,fill,stroke,stroke_width,**args)
a rectangle is defined by a width and height and a xy pair
"""
- def __init__(self,x=None,y=None,width=None,height=None,fill=None,stroke=None,stroke_width=None,**args):
- if width==None or height==None:
- if width<>None:
- raise ValueError, 'height is required'
- if height<>None:
- raise ValueError, 'width is required'
- else:
- raise ValueError, 'both height and width are required'
- SVGelement.__init__(self,'rect',{'width':width,'height':height},**args)
- if x<>None:
+
+ def __init__(self, x=None, y=None, width=None, height=None, fill=None, stroke=None, stroke_width=None, **args):
+ if width == None or height == None:
+ raise ValueError('both height and width are required')
+
+ SVGelement.__init__(self, 'rect', {'width':width,'height':height}, **args)
+ if x!=None:
self.attributes['x']=x
- if y<>None:
+ if y!=None:
self.attributes['y']=y
- if fill<>None:
+ if fill!=None:
self.attributes['fill']=fill
- if stroke<>None:
+ if stroke!=None:
self.attributes['stroke']=stroke
- if stroke_width<>None:
+ if stroke_width!=None:
self.attributes['stroke-width']=stroke_width
class ellipse(SVGelement):
@@ -423,22 +466,18 @@ class ellipse(SVGelement):
"""
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:
- if rx<>None:
- raise ValueError, 'rx is required'
- if ry<>None:
- raise ValueError, 'ry is required'
- else:
- raise ValueError, 'both rx and ry are required'
- SVGelement.__init__(self,'ellipse',{'rx':rx,'ry':ry},**args)
- if cx<>None:
+ raise ValueError('both rx and ry are required')
+
+ SVGelement.__init__(self, 'ellipse', {'rx':rx,'ry':ry}, **args)
+ if cx!=None:
self.attributes['cx']=cx
- if cy<>None:
+ if cy!=None:
self.attributes['cy']=cy
- if fill<>None:
+ if fill!=None:
self.attributes['fill']=fill
- if stroke<>None:
+ if stroke!=None:
self.attributes['stroke']=stroke
- if stroke_width<>None:
+ if stroke_width!=None:
self.attributes['stroke-width']=stroke_width
@@ -449,17 +488,17 @@ class circle(SVGelement):
"""
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'
- SVGelement.__init__(self,'circle',{'r':r},**args)
- if cx<>None:
+ raise ValueError('r is required')
+ SVGelement.__init__(self, 'circle', {'r':r}, **args)
+ if cx!=None:
self.attributes['cx']=cx
- if cy<>None:
+ if cy!=None:
self.attributes['cy']=cy
- if fill<>None:
+ if fill!=None:
self.attributes['fill']=fill
- if stroke<>None:
+ if stroke!=None:
self.attributes['stroke']=stroke
- if stroke_width<>None:
+ if stroke_width!=None:
self.attributes['stroke-width']=stroke_width
class point(circle):
@@ -469,7 +508,7 @@ class point(circle):
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)
+ circle.__init__(self, x, y, 1, fill, **args)
class line(SVGelement):
"""l=line(x1,y1,x2,y2,stroke,stroke_width,**args)
@@ -477,18 +516,18 @@ class line(SVGelement):
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:
+ SVGelement.__init__(self, 'line', **args)
+ if x1!=None:
self.attributes['x1']=x1
- if y1<>None:
+ if y1!=None:
self.attributes['y1']=y1
- if x2<>None:
+ if x2!=None:
self.attributes['x2']=x2
- if y2<>None:
+ if y2!=None:
self.attributes['y2']=y2
- if stroke_width<>None:
+ if stroke_width!=None:
self.attributes['stroke-width']=stroke_width
- if stroke<>None:
+ if stroke!=None:
self.attributes['stroke']=stroke
class polyline(SVGelement):
@@ -497,12 +536,12 @@ class polyline(SVGelement):
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:
+ SVGelement.__init__(self, 'polyline', {'points':_xypointlist(points)}, **args)
+ if fill!=None:
self.attributes['fill']=fill
- if stroke_width<>None:
+ if stroke_width!=None:
self.attributes['stroke-width']=stroke_width
- if stroke<>None:
+ if stroke!=None:
self.attributes['stroke']=stroke
class polygon(SVGelement):
@@ -511,12 +550,12 @@ class polygon(SVGelement):
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:
+ SVGelement.__init__(self, 'polygon', {'points':_xypointlist(points)}, **args)
+ if fill!=None:
self.attributes['fill']=fill
- if stroke_width<>None:
+ if stroke_width!=None:
self.attributes['stroke-width']=stroke_width
- if stroke<>None:
+ if stroke!=None:
self.attributes['stroke']=stroke
class path(SVGelement):
@@ -525,14 +564,14 @@ class path(SVGelement):
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:
+ SVGelement.__init__(self, 'path', {'d':str(pathdata)}, **args)
+ if stroke!=None:
self.attributes['stroke']=stroke
- if fill<>None:
+ if fill!=None:
self.attributes['fill']=fill
- if stroke_width<>None:
+ if stroke_width!=None:
self.attributes['stroke-width']=stroke_width
- if id<>None:
+ if id!=None:
self.attributes['id']=id
@@ -542,18 +581,18 @@ 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:
+ SVGelement.__init__(self, 'text', **args)
+ if x!=None:
self.attributes['x']=x
- if y<>None:
+ if y!=None:
self.attributes['y']=y
- if font_size<>None:
+ if font_size!=None:
self.attributes['font-size']=font_size
- if font_family<>None:
+ if font_family!=None:
self.attributes['font-family']=font_family
- if text<>None:
+ if text!=None:
self.text=text
- if text_anchor<>None:
+ if text_anchor!=None:
self.attributes['text-anchor']=text_anchor
@@ -563,8 +602,8 @@ 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:
+ SVGelement.__init__(self, 'textPath', {'xlink:href':link}, **args)
+ if text!=None:
self.text=text
class pattern(SVGelement):
@@ -575,16 +614,16 @@ class pattern(SVGelement):
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:
+ SVGelement.__init__(self, 'pattern', **args)
+ if x!=None:
self.attributes['x']=x
- if y<>None:
+ if y!=None:
self.attributes['y']=y
- if width<>None:
+ if width!=None:
self.attributes['width']=width
- if height<>None:
+ if height!=None:
self.attributes['height']=height
- if patternUnits<>None:
+ if patternUnits!=None:
self.attributes['patternUnits']=patternUnits
class title(SVGelement):
@@ -594,8 +633,8 @@ class title(SVGelement):
add at least one to the root svg element
"""
def __init__(self,text=None,**args):
- SVGelement.__init__(self,'title',**args)
- if text<>None:
+ SVGelement.__init__(self, 'title', **args)
+ if text!=None:
self.text=text
class description(SVGelement):
@@ -605,8 +644,8 @@ class description(SVGelement):
Add this element before adding other elements.
"""
def __init__(self,text=None,**args):
- SVGelement.__init__(self,'desc',**args)
- if text<>None:
+ SVGelement.__init__(self, 'desc', **args)
+ if text!=None:
self.text=text
class lineargradient(SVGelement):
@@ -616,16 +655,16 @@ class lineargradient(SVGelement):
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:
+ SVGelement.__init__(self, 'linearGradient', **args)
+ if x1!=None:
self.attributes['x1']=x1
- if y1<>None:
+ if y1!=None:
self.attributes['y1']=y1
- if x2<>None:
+ if x2!=None:
self.attributes['x2']=x2
- if y2<>None:
+ if y2!=None:
self.attributes['y2']=y2
- if id<>None:
+ if id!=None:
self.attributes['id']=id
class radialgradient(SVGelement):
@@ -635,18 +674,18 @@ class radialgradient(SVGelement):
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:
+ SVGelement.__init__(self, 'radialGradient', **args)
+ if cx!=None:
self.attributes['cx']=cx
- if cy<>None:
+ if cy!=None:
self.attributes['cy']=cy
- if r<>None:
+ if r!=None:
self.attributes['r']=r
- if fx<>None:
+ if fx!=None:
self.attributes['fx']=fx
- if fy<>None:
+ if fy!=None:
self.attributes['fy']=fy
- if id<>None:
+ if id!=None:
self.attributes['id']=id
class stop(SVGelement):
@@ -655,8 +694,8 @@ class stop(SVGelement):
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:
+ SVGelement.__init__(self, 'stop', {'offset':offset}, **args)
+ if stop_color!=None:
self.attributes['stop-color']=stop_color
class style(SVGelement):
@@ -665,7 +704,7 @@ class style(SVGelement):
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)
+ SVGelement.__init__(self, 'style', {'type':type}, cdata=cdata, **args)
class image(SVGelement):
@@ -675,16 +714,11 @@ class image(SVGelement):
"""
def __init__(self,url,x=None,y=None,width=None,height=None,**args):
if width==None or height==None:
- if width<>None:
- raise ValueError, 'height is required'
- if height<>None:
- raise ValueError, 'width is required'
- else:
- raise ValueError, 'both height and width are required'
- SVGelement.__init__(self,'image',{'xlink:href':url,'width':width,'height':height},**args)
- if x<>None:
+ raise ValueError('both height and width are required')
+ SVGelement.__init__(self, 'image', {'xlink:href':url,'width':width,'height':height}, **args)
+ if x!=None:
self.attributes['x']=x
- if y<>None:
+ if y!=None:
self.attributes['y']=y
class cursor(SVGelement):
@@ -693,7 +727,7 @@ class cursor(SVGelement):
defines a custom cursor for a element or a drawing
"""
def __init__(self,url,**args):
- SVGelement.__init__(self,'cursor',{'xlink:href':url},**args)
+ SVGelement.__init__(self, 'cursor', {'xlink:href':url}, **args)
class marker(SVGelement):
@@ -703,18 +737,18 @@ class marker(SVGelement):
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:
+ SVGelement.__init__(self, 'marker', **args)
+ if id!=None:
self.attributes['id']=id
- if viewBox<>None:
+ if viewBox!=None:
self.attributes['viewBox']=_viewboxlist(viewBox)
- if refx<>None:
+ if refx!=None:
self.attributes['refX']=refx
- if refy<>None:
+ if refy!=None:
self.attributes['refY']=refy
- if markerWidth<>None:
+ if markerWidth!=None:
self.attributes['markerWidth']=markerWidth
- if markerHeight<>None:
+ if markerHeight!=None:
self.attributes['markerHeight']=markerHeight
class group(SVGelement):
@@ -724,8 +758,8 @@ class group(SVGelement):
g.addElement(SVGelement)
"""
def __init__(self,id=None,**args):
- SVGelement.__init__(self,'g',**args)
- if id<>None:
+ SVGelement.__init__(self, 'g', **args)
+ if id!=None:
self.attributes['id']=id
class symbol(SVGelement):
@@ -738,10 +772,10 @@ class symbol(SVGelement):
"""
def __init__(self,id=None,viewBox=None,**args):
- SVGelement.__init__(self,'symbol',**args)
- if id<>None:
+ SVGelement.__init__(self, 'symbol', **args)
+ if id!=None:
self.attributes['id']=id
- if viewBox<>None:
+ if viewBox!=None:
self.attributes['viewBox']=_viewboxlist(viewBox)
class defs(SVGelement):
@@ -750,7 +784,7 @@ class defs(SVGelement):
container for defining elements
"""
def __init__(self,**args):
- SVGelement.__init__(self,'defs',**args)
+ SVGelement.__init__(self, 'defs', **args)
class switch(SVGelement):
"""sw=switch(**args)
@@ -760,7 +794,7 @@ class switch(SVGelement):
Refer to the SVG specification for details.
"""
def __init__(self,**args):
- SVGelement.__init__(self,'switch',**args)
+ SVGelement.__init__(self, 'switch', **args)
class use(SVGelement):
@@ -769,15 +803,15 @@ 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:
+ SVGelement.__init__(self, 'use', {'xlink:href':link}, **args)
+ if x!=None:
self.attributes['x']=x
- if y<>None:
+ if y!=None:
self.attributes['y']=y
- if width<>None:
+ if width!=None:
self.attributes['width']=width
- if height<>None:
+ if height!=None:
self.attributes['height']=height
@@ -788,15 +822,15 @@ class link(SVGelement):
a.addElement(SVGelement)
"""
def __init__(self,link='',**args):
- SVGelement.__init__(self,'a',{'xlink:href':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:
+ SVGelement.__init__(self, 'view', **args)
+ if id!=None:
self.attributes['id']=id
class script(SVGelement):
@@ -806,7 +840,7 @@ class script(SVGelement):
"""
def __init__(self,type,cdata=None,**args):
- SVGelement.__init__(self,'script',{'type':type},cdata=cdata,**args)
+ SVGelement.__init__(self, 'script', {'type':type}, cdata=cdata, **args)
class animate(SVGelement):
"""an=animate(attribute,from,to,during,**args)
@@ -814,12 +848,12 @@ class animate(SVGelement):
animates an attribute.
"""
def __init__(self,attribute,fr=None,to=None,dur=None,**args):
- SVGelement.__init__(self,'animate',{'attributeName':attribute},**args)
- if fr<>None:
+ SVGelement.__init__(self, 'animate', {'attributeName':attribute}, **args)
+ if fr!=None:
self.attributes['from']=fr
- if to<>None:
+ if to!=None:
self.attributes['to']=to
- if dur<>None:
+ if dur!=None:
self.attributes['dur']=dur
class animateMotion(SVGelement):
@@ -828,10 +862,10 @@ class animateMotion(SVGelement):
animates a SVGelement over the given path in dur seconds
"""
def __init__(self,pathdata,dur,**args):
- SVGelement.__init__(self,'animateMotion',**args)
- if pathdata<>None:
+ SVGelement.__init__(self, 'animateMotion', **args)
+ if pathdata!=None:
self.attributes['path']=str(pathdata)
- if dur<>None:
+ if dur!=None:
self.attributes['dur']=dur
class animateTransform(SVGelement):
@@ -840,15 +874,15 @@ class animateTransform(SVGelement):
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
- if type<>None:
+ SVGelement.__init__(self, 'animateTransform', {'attributeName':'transform'}, **args)
+ # As far as I know the attributeName is always transform
+ if type!=None:
self.attributes['type']=type
- if fr<>None:
+ if fr!=None:
self.attributes['from']=fr
- if to<>None:
+ if to!=None:
self.attributes['to']=to
- if dur<>None:
+ if dur!=None:
self.attributes['dur']=dur
class animateColor(SVGelement):
"""ac=animateColor(attribute,type,from,to,dur,**args)
@@ -856,14 +890,14 @@ class animateColor(SVGelement):
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:
+ SVGelement.__init__(self, 'animateColor', {'attributeName':attribute}, **args)
+ if type!=None:
self.attributes['type']=type
- if fr<>None:
+ if fr!=None:
self.attributes['from']=fr
- if to<>None:
+ if to!=None:
self.attributes['to']=to
- if dur<>None:
+ if dur!=None:
self.attributes['dur']=dur
class set(SVGelement):
"""st=set(attribute,to,during,**args)
@@ -871,10 +905,10 @@ class set(SVGelement):
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:
+ SVGelement.__init__(self, 'set', {'attributeName':attribute}, **args)
+ if to!=None:
self.attributes['to']=to
- if dur<>None:
+ if dur!=None:
self.attributes['dur']=dur
@@ -895,12 +929,12 @@ class svg(SVGelement):
d.toXml()
"""
def __init__(self,viewBox=None, width=None, height=None,**args):
- SVGelement.__init__(self,'svg',**args)
- if viewBox<>None:
+ SVGelement.__init__(self, 'svg', **args)
+ if viewBox!=None:
self.attributes['viewBox']=_viewboxlist(viewBox)
- if width<>None:
+ if width!=None:
self.attributes['width']=width
- if height<>None:
+ if height!=None:
self.attributes['height']=height
self.namespace="http://www.w3.org/2000/svg"
@@ -918,27 +952,27 @@ class drawing:
def __init__(self, entity={}):
self.svg=None
self.entity = entity
- def setSVG(self,svg):
+ def setSVG(self, svg):
self.svg=svg
- #Voeg een element toe aan de grafiek toe.
+ # Voeg een element toe aan de grafiek toe.
if use_dom_implementation==0:
def toXml(self, filename='',compress=False):
- import cStringIO
- xml=cStringIO.StringIO()
+ import io
+ xml=io.StringIO()
xml.write("<?xml version='1.0' encoding='UTF-8'?>\n")
xml.write("<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.0//EN\" \"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd\"")
if self.entity:
xml.write(" [\n")
- for item in self.entity.keys():
+ for item in list(self.entity.keys()):
xml.write("<!ENTITY %s \"%s\">\n" % (item, self.entity[item]))
xml.write("]")
xml.write(">\n")
- self.svg.toXml(0,xml)
+ self.svg.toXml(0, xml)
if not filename:
if compress:
import gzip
- f=cStringIO.StringIO()
- zf=gzip.GzipFile(fileobj=f,mode='wb')
+ f=io.StringIO()
+ zf=gzip.GzipFile(fileobj=f, mode='wb')
zf.write(xml.getvalue())
zf.close()
f.seek(0)
@@ -948,11 +982,11 @@ class drawing:
else:
if filename[-4:]=='svgz':
import gzip
- f=gzip.GzipFile(filename=filename,mode="wb", compresslevel=9)
+ f=gzip.GzipFile(filename=filename, mode="wb", compresslevel=9)
f.write(xml.getvalue())
f.close()
else:
- f=file(filename,'w')
+ f=file(filename, 'w')
f.write(xml.getvalue())
f.close()
@@ -963,40 +997,40 @@ class drawing:
writes a svg drawing to the screen or to a file
compresses if filename ends with svgz or if compress is true
"""
- doctype = implementation.createDocumentType('svg',"-//W3C//DTD SVG 1.0//EN""",'http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd ')
+ doctype = implementation.createDocumentType('svg', "-//W3C//DTD SVG 1.0//EN""", 'http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd ')
global root
- #root is defined global so it can be used by the appender. Its also possible to use it as an arugument but
- #that is a bit messy.
- root=implementation.createDocument(None,None,doctype)
- #Create the xml document.
+ # root is defined global so it can be used by the appender. Its also possible to use it as an arugument but
+ # that is a bit messy.
+ root=implementation.createDocument(None, None, doctype)
+ # Create the xml document.
global appender
- def appender(element,elementroot):
+ 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"""
if element.namespace:
- e=root.createElementNS(element.namespace,element.type)
+ e=root.createElementNS(element.namespace, element.type)
else:
e=root.createElement(element.type)
if element.text:
textnode=root.createTextNode(element.text)
e.appendChild(textnode)
- for attribute in element.attributes.keys(): #in element.attributes is supported from python 2.2
- e.setAttribute(attribute,str(element.attributes[attribute]))
+ for attribute in list(element.attributes.keys()): #in element.attributes is supported from python 2.2
+ e.setAttribute(attribute, str(element.attributes[attribute]))
if element.elements:
for el in element.elements:
- e=appender(el,e)
+ e=appender(el, e)
elementroot.appendChild(e)
return elementroot
- root=appender(self.svg,root)
+ root=appender(self.svg, root)
if not filename:
- import cStringIO
- xml=cStringIO.StringIO()
- PrettyPrint(root,xml)
+ import io
+ xml=io.StringIO()
+ PrettyPrint(root, xml)
if compress:
import gzip
- f=cStringIO.StringIO()
- zf=gzip.GzipFile(fileobj=f,mode='wb')
+ f=io.StringIO()
+ zf=gzip.GzipFile(fileobj=f, mode='wb')
zf.write(xml.getvalue())
zf.close()
f.seek(0)
@@ -1007,23 +1041,23 @@ class drawing:
try:
if filename[-4:]=='svgz':
import gzip
- import cStringIO
- xml=cStringIO.StringIO()
- PrettyPrint(root,xml)
- f=gzip.GzipFile(filename=filename,mode='wb',compresslevel=9)
+ import io
+ xml=io.StringIO()
+ PrettyPrint(root, xml)
+ f=gzip.GzipFile(filename=filename, mode='wb', compresslevel=9)
f.write(xml.getvalue())
f.close()
else:
- f=open(filename,'w')
- PrettyPrint(root,f)
+ f=open(filename, 'w')
+ PrettyPrint(root, f)
f.close()
except:
- print "Cannot write SVG file: " + filename
+ print(("Cannot write SVG file: " + filename))
def validate(self):
try:
import xml.parsers.xmlproc.xmlval
except:
- raise exceptions.ImportError,'PyXml is required for validating SVG'
+ raise exceptions.ImportError('PyXml is required for validating SVG')
svg=self.toXml()
xv=xml.parsers.xmlproc.xmlval.XMLValidator()
try:
@@ -1031,38 +1065,38 @@ class drawing:
except:
raise Exception("SVG is not well formed, see messages above")
else:
- print "SVG well formed"
+ print("SVG well formed")
if __name__=='__main__':
d=drawing()
- s=svg((0,0,100,100))
- r=rect(-100,-100,300,300,'cyan')
+ s=svg((0, 0, 100, 100))
+ r=rect(-100, -100, 300, 300, 'cyan')
s.addElement(r)
t=title('SVGdraw Demo')
s.addElement(t)
g=group('animations')
- e=ellipse(0,0,5,2)
+ e=ellipse(0, 0, 5, 2)
g.addElement(e)
- c=circle(0,0,1,'red')
+ c=circle(0, 0, 1, 'red')
g.addElement(c)
- pd=pathdata(0,-10)
+ pd=pathdata(0, -10)
for i in range(6):
- pd.relsmbezier(10,5,0,10)
- pd.relsmbezier(-10,5,0,10)
- an=animateMotion(pd,10)
+ pd.relsmbezier(10, 5, 0, 10)
+ pd.relsmbezier(-10, 5, 0, 10)
+ an=animateMotion(pd, 10)
an.attributes['rotate']='auto-reverse'
an.attributes['repeatCount']="indefinite"
g.addElement(an)
s.addElement(g)
- for i in range(20,120,20):
- u=use('#animations',i,0)
+ for i in range(20, 120, 20):
+ u=use('#animations', i, 0)
s.addElement(u)
- for i in range(0,120,20):
- for j in range(5,105,10):
- c=circle(i,j,1,'red','black',.5)
+ for i in range(0, 120, 20):
+ for j in range(5, 105, 10):
+ c=circle(i, j, 1, 'red', 'black', .5)
s.addElement(c)
d.setSVG(s)
- print d.toXml()
+ print((d.toXml()))
diff --git a/wqflask/utility/temp_data.py b/wqflask/utility/temp_data.py
index 5bf700c9..2f2726c6 100644
--- a/wqflask/utility/temp_data.py
+++ b/wqflask/utility/temp_data.py
@@ -20,6 +20,6 @@ class TempData(object):
if __name__ == "__main__":
redis = Redis()
- for key in redis.keys():
+ for key in list(redis.keys()):
for field in redis.hkeys(key):
print("{}.{}={}".format(key, field, redis.hget(key, field)))
diff --git a/wqflask/utility/tools.py b/wqflask/utility/tools.py
index 77db5d53..68ef0f04 100644
--- a/wqflask/utility/tools.py
+++ b/wqflask/utility/tools.py
@@ -15,7 +15,7 @@ OVERRIDES = {}
def app_set(command_id, value):
"""Set application wide value"""
- app.config.setdefault(command_id,value)
+ app.config.setdefault(command_id, value)
return value
def get_setting(command_id,guess=None):
@@ -45,7 +45,7 @@ def get_setting(command_id,guess=None):
def value(command):
if command:
# sys.stderr.write("Found "+command+"\n")
- app_set(command_id,command)
+ app_set(command_id, command)
return command
else:
return None
@@ -68,7 +68,7 @@ def get_setting(command_id,guess=None):
def get_setting_bool(id):
v = get_setting(id)
- if v not in [0,False,'False','FALSE',None]:
+ if v not in [0, False, 'False', 'FALSE', None]:
return True
return False
@@ -108,16 +108,16 @@ def js_path(module=None):
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)
+ return get_setting("REAPER_COMMAND", guess)
def gemma_command(guess=None):
- return assert_bin(get_setting("GEMMA_COMMAND",guess))
+ return assert_bin(get_setting("GEMMA_COMMAND", guess))
def gemma_wrapper_command(guess=None):
- return assert_bin(get_setting("GEMMA_WRAPPER_COMMAND",guess))
+ return assert_bin(get_setting("GEMMA_WRAPPER_COMMAND", guess))
def plink_command(guess=None):
- return assert_bin(get_setting("PLINK_COMMAND",guess))
+ return assert_bin(get_setting("PLINK_COMMAND", guess))
def flat_file_exists(subdir):
base = get_setting("GENENETWORK_FILES")
@@ -180,7 +180,7 @@ def locate(name, subdir=None):
raise Exception("Can not locate "+name+" in "+base)
def locate_phewas(name, subdir=None):
- return locate(name,'/phewas/'+subdir)
+ return locate(name, '/phewas/'+subdir)
def locate_ignore_error(name, subdir=None):
"""
@@ -204,7 +204,7 @@ def tempdir():
"""
Get UNIX TMPDIR by default
"""
- return valid_path(get_setting("TMPDIR","/tmp"))
+ return valid_path(get_setting("TMPDIR", "/tmp"))
BLUE = '\033[94m'
GREEN = '\033[92m'
@@ -214,20 +214,20 @@ ENDC = '\033[0m'
def show_settings():
from utility.tools import LOG_LEVEL
- print("Set global log level to "+BLUE+LOG_LEVEL+ENDC)
+ print(("Set global log level to "+BLUE+LOG_LEVEL+ENDC))
log_level = getattr(logging, LOG_LEVEL.upper())
logging.basicConfig(level=log_level)
logger.info(OVERRIDES)
logger.info(BLUE+"Mr. Mojo Risin 2"+ENDC)
- print "runserver.py: ****** Webserver configuration - k,v pairs from app.config ******"
- keylist = app.config.keys()
+ keylist = list(app.config.keys())
+ print("runserver.py: ****** Webserver configuration - k,v pairs from app.config ******")
keylist.sort()
for k in keylist:
try:
- print("%s: %s%s%s%s" % (k,BLUE,BOLD,get_setting(k),ENDC))
+ print(("%s: %s%s%s%s" % (k, BLUE, BOLD, get_setting(k), ENDC)))
except:
- print("%s: %s%s%s%s" % (k,GREEN,BOLD,app.config[k],ENDC))
+ print(("%s: %s%s%s%s" % (k, GREEN, BOLD, app.config[k], ENDC)))
# Cached values
@@ -279,10 +279,10 @@ SMTP_CONNECT = get_setting('SMTP_CONNECT')
SMTP_USERNAME = get_setting('SMTP_USERNAME')
SMTP_PASSWORD = get_setting('SMTP_PASSWORD')
-REAPER_COMMAND = app_set("REAPER_COMMAND",reaper_command())
-GEMMA_COMMAND = app_set("GEMMA_COMMAND",gemma_command())
+REAPER_COMMAND = app_set("REAPER_COMMAND", reaper_command())
+GEMMA_COMMAND = app_set("GEMMA_COMMAND", gemma_command())
assert(GEMMA_COMMAND is not None)
-PLINK_COMMAND = app_set("PLINK_COMMAND",plink_command())
+PLINK_COMMAND = app_set("PLINK_COMMAND", plink_command())
GEMMA_WRAPPER_COMMAND = gemma_wrapper_command()
TEMPDIR = tempdir() # defaults to UNIX TMPDIR
assert_dir(TEMPDIR)
@@ -295,11 +295,11 @@ assert_dir(JS_GUIX_PATH+'/cytoscape-panzoom')
CSS_PATH = JS_GUIX_PATH # The CSS is bundled together with the JS
# assert_dir(JS_PATH)
-JS_TWITTER_POST_FETCHER_PATH = get_setting("JS_TWITTER_POST_FETCHER_PATH",js_path("javascript-twitter-post-fetcher"))
+JS_TWITTER_POST_FETCHER_PATH = get_setting("JS_TWITTER_POST_FETCHER_PATH", js_path("javascript-twitter-post-fetcher"))
assert_dir(JS_TWITTER_POST_FETCHER_PATH)
assert_file(JS_TWITTER_POST_FETCHER_PATH+"/js/twitterFetcher_min.js")
-JS_CYTOSCAPE_PATH = get_setting("JS_CYTOSCAPE_PATH",js_path("cytoscape"))
+JS_CYTOSCAPE_PATH = get_setting("JS_CYTOSCAPE_PATH", js_path("cytoscape"))
assert_dir(JS_CYTOSCAPE_PATH)
assert_file(JS_CYTOSCAPE_PATH+'/cytoscape.min.js')
diff --git a/wqflask/utility/webqtlUtil.py b/wqflask/utility/webqtlUtil.py
index 53661ae4..d4979011 100644
--- a/wqflask/utility/webqtlUtil.py
+++ b/wqflask/utility/webqtlUtil.py
@@ -41,22 +41,22 @@ ParInfo ={
'C57BL-6JxC57BL-6NJF2':['', '', 'C57BL/6J', 'C57BL/6NJ'],
'BXD300':['B6D2F1', 'D2B6F1', 'C57BL/6J', 'DBA/2J'],
'B6BTBRF2':['B6BTBRF1', 'BTBRB6F1', 'C57BL/6J', 'BTBRT<+>tf/J'],
-'BHHBF2':['B6HF2','HB6F2','C57BL/6J','C3H/HeJ'],
-'BHF2':['B6HF2','HB6F2','C57BL/6J','C3H/HeJ'],
+'BHHBF2':['B6HF2', 'HB6F2', 'C57BL/6J', 'C3H/HeJ'],
+'BHF2':['B6HF2', 'HB6F2', 'C57BL/6J', 'C3H/HeJ'],
'B6D2F2':['B6D2F1', 'D2B6F1', 'C57BL/6J', 'DBA/2J'],
'BDF2-1999':['B6D2F2', 'D2B6F2', 'C57BL/6J', 'DBA/2J'],
'BDF2-2005':['B6D2F1', 'D2B6F1', 'C57BL/6J', 'DBA/2J'],
-'CTB6F2':['CTB6F2','B6CTF2','C57BL/6J','Castaneous'],
+'CTB6F2':['CTB6F2', 'B6CTF2', 'C57BL/6J', 'Castaneous'],
'CXB':['CBF1', 'BCF1', 'C57BL/6ByJ', 'BALB/cByJ'],
'AXBXA':['ABF1', 'BAF1', 'C57BL/6J', 'A/J'],
'AXB':['ABF1', 'BAF1', 'C57BL/6J', 'A/J'],
'BXA':['BAF1', 'ABF1', 'C57BL/6J', 'A/J'],
'LXS':['LSF1', 'SLF1', 'ISS', 'ILS'],
'HXBBXH':['SHR_BNF1', 'BN_SHRF1', 'BN-Lx/Cub', 'SHR/OlaIpcv'],
-'BayXSha':['BayXShaF1', 'ShaXBayF1', 'Bay-0','Shahdara'],
-'ColXBur':['ColXBurF1', 'BurXColF1', 'Col-0','Bur-0'],
-'ColXCvi':['ColXCviF1', 'CviXColF1', 'Col-0','Cvi'],
-'SXM':['SMF1', 'MSF1', 'Steptoe','Morex'],
+'BayXSha':['BayXShaF1', 'ShaXBayF1', 'Bay-0', 'Shahdara'],
+'ColXBur':['ColXBurF1', 'BurXColF1', 'Col-0', 'Bur-0'],
+'ColXCvi':['ColXCviF1', 'CviXColF1', 'Col-0', 'Cvi'],
+'SXM':['SMF1', 'MSF1', 'Steptoe', 'Morex'],
'HRDP':['SHR_BNF1', 'BN_SHRF1', 'BN-Lx/Cub', 'SHR/OlaIpcv']
}
@@ -64,7 +64,7 @@ ParInfo ={
# Accessory Functions
#########################################
-def genRandStr(prefix = "", length=8, chars=string.letters+string.digits):
+def genRandStr(prefix = "", length=8, chars=string.ascii_letters+string.digits):
from random import choice
_str = prefix[:]
for i in range(length):
@@ -91,7 +91,7 @@ def readLineCSV(line): ### dcrowell July 2008
returnList[0]=returnList[0][1:]
return returnList
-def cmpEigenValue(A,B):
+def cmpEigenValue(A, B):
try:
if A[0] > B[0]:
return -1
@@ -107,7 +107,7 @@ def hasAccessToConfidentialPhenotypeTrait(privilege, userName, authorized_users)
if webqtlConfig.USERDICT[privilege] > webqtlConfig.USERDICT['user']:
access_to_confidential_phenotype_trait = 1
else:
- AuthorizedUsersList=map(string.strip, string.split(authorized_users, ','))
+ AuthorizedUsersList=list(map(string.strip, string.split(authorized_users, ',')))
if AuthorizedUsersList.__contains__(userName):
access_to_confidential_phenotype_trait = 1
- return access_to_confidential_phenotype_trait \ No newline at end of file
+ return access_to_confidential_phenotype_trait
diff --git a/wqflask/wqflask/api/correlation.py b/wqflask/wqflask/api/correlation.py
index 7f5312c1..eb05645e 100644
--- a/wqflask/wqflask/api/correlation.py
+++ b/wqflask/wqflask/api/correlation.py
@@ -36,7 +36,7 @@ def do_correlation(start_vars):
#corr_results = collections.OrderedDict(sorted(corr_results.items(), key=lambda t: -abs(t[1][0])))
final_results = []
- for _trait_counter, trait in enumerate(corr_results.keys()[:corr_params['return_count']]):
+ for _trait_counter, trait in enumerate(list(corr_results.keys())[:corr_params['return_count']]):
if corr_params['type'] == "tissue":
[sample_r, num_overlap, sample_p, symbol] = corr_results[trait]
result_dict = {
@@ -76,20 +76,20 @@ def calculate_results(this_trait, this_dataset, target_dataset, corr_params):
if corr_params['type'] == "tissue":
trait_symbol_dict = this_dataset.retrieve_genes("Symbol")
corr_results = do_tissue_correlation_for_all_traits(this_trait, trait_symbol_dict, corr_params)
- sorted_results = collections.OrderedDict(sorted(corr_results.items(),
+ sorted_results = collections.OrderedDict(sorted(list(corr_results.items()),
key=lambda t: -abs(t[1][1])))
elif corr_params['type'] == "literature" or corr_params['type'] == "lit": #ZS: Just so a user can use either "lit" or "literature"
trait_geneid_dict = this_dataset.retrieve_genes("GeneId")
corr_results = do_literature_correlation_for_all_traits(this_trait, this_dataset, trait_geneid_dict, corr_params)
- sorted_results = collections.OrderedDict(sorted(corr_results.items(),
+ sorted_results = collections.OrderedDict(sorted(list(corr_results.items()),
key=lambda t: -abs(t[1][1])))
else:
- for target_trait, target_vals in target_dataset.trait_data.iteritems():
+ for target_trait, target_vals in list(target_dataset.trait_data.items()):
result = get_sample_r_and_p_values(this_trait, this_dataset, target_vals, target_dataset, corr_params['type'])
if result is not None:
corr_results[target_trait] = result
- sorted_results = collections.OrderedDict(sorted(corr_results.items(), key=lambda t: -abs(t[1][0])))
+ sorted_results = collections.OrderedDict(sorted(list(corr_results.items()), key=lambda t: -abs(t[1][0])))
return sorted_results
@@ -100,10 +100,10 @@ def do_tissue_correlation_for_all_traits(this_trait, trait_symbol_dict, corr_par
if this_trait.symbol.lower() in primary_trait_tissue_vals_dict:
primary_trait_tissue_values = primary_trait_tissue_vals_dict[this_trait.symbol.lower()]
- corr_result_tissue_vals_dict = correlation_functions.get_trait_symbol_and_tissue_values(symbol_list=trait_symbol_dict.values())
+ corr_result_tissue_vals_dict = correlation_functions.get_trait_symbol_and_tissue_values(symbol_list=list(trait_symbol_dict.values()))
tissue_corr_data = {}
- for trait, symbol in trait_symbol_dict.iteritems():
+ for trait, symbol in list(trait_symbol_dict.items()):
if symbol and symbol.lower() in corr_result_tissue_vals_dict:
this_trait_tissue_values = corr_result_tissue_vals_dict[symbol.lower()]
@@ -119,7 +119,7 @@ def do_literature_correlation_for_all_traits(this_trait, target_dataset, trait_g
input_trait_mouse_gene_id = convert_to_mouse_gene_id(target_dataset.group.species.lower(), this_trait.geneid)
lit_corr_data = {}
- for trait, gene_id in trait_geneid_dict.iteritems():
+ for trait, gene_id in list(trait_geneid_dict.items()):
mouse_gene_id = convert_to_mouse_gene_id(target_dataset.group.species.lower(), gene_id)
if mouse_gene_id and str(mouse_gene_id).find(";") == -1:
diff --git a/wqflask/wqflask/api/gen_menu.py b/wqflask/wqflask/api/gen_menu.py
index fedf3e0b..41966f78 100644
--- a/wqflask/wqflask/api/gen_menu.py
+++ b/wqflask/wqflask/api/gen_menu.py
@@ -61,7 +61,7 @@ def get_types(groups):
"""Build types list"""
types = {}
- for species, group_dict in groups.iteritems():
+ for species, group_dict in list(groups.items()):
types[species] = {}
for group_name, _group_full_name, _family_name in group_dict:
if phenotypes_exist(group_name):
@@ -136,9 +136,9 @@ def build_types(species, group):
def get_datasets(types):
"""Build datasets list"""
datasets = {}
- for species, group_dict in types.iteritems():
+ for species, group_dict in list(types.items()):
datasets[species] = {}
- for group, type_list in group_dict.iteritems():
+ for group, type_list in list(group_dict.items()):
datasets[species][group] = {}
for type_name in type_list:
these_datasets = build_datasets(species, group, type_name[0])
diff --git a/wqflask/wqflask/api/router.py b/wqflask/wqflask/api/router.py
index 6324cabe..5f9b81b8 100644
--- a/wqflask/wqflask/api/router.py
+++ b/wqflask/wqflask/api/router.py
@@ -6,7 +6,7 @@ import os, io, csv, json, datetime, requests, yaml
import zlib
from zipfile import ZipFile, ZIP_DEFLATED
-import StringIO
+import io
import flask
from flask import g, Response, request, make_response, render_template, send_from_directory, jsonify, redirect, send_file
@@ -308,7 +308,7 @@ def fetch_traits(dataset_name, file_format = "json"):
else:
filename = dataset_name + "_trait_ids.csv"
- si = StringIO.StringIO()
+ si = io.StringIO()
csv_writer = csv.writer(si)
csv_writer.writerows([[trait_id] for trait_id in trait_ids])
output = make_response(si.getvalue())
@@ -322,7 +322,7 @@ def fetch_traits(dataset_name, file_format = "json"):
else:
filename = dataset_name + "_trait_names.csv"
- si = StringIO.StringIO()
+ si = io.StringIO()
csv_writer = csv.writer(si)
csv_writer.writerows([[trait_name] for trait_name in trait_names])
output = make_response(si.getvalue())
@@ -413,7 +413,7 @@ def fetch_traits(dataset_name, file_format = "json"):
for result in g.db.execute(final_query).fetchall():
results_list.append(result)
- si = StringIO.StringIO()
+ si = io.StringIO()
csv_writer = csv.writer(si)
csv_writer.writerows(results_list)
output = make_response(si.getvalue())
@@ -517,9 +517,9 @@ def all_sample_data(dataset_name, file_format = "csv"):
line_list.append("x")
results_list.append(line_list)
- results_list = map(list, zip(*results_list))
+ results_list = list(map(list, zip(*results_list)))
- si = StringIO.StringIO()
+ si = io.StringIO()
csv_writer = csv.writer(si)
csv_writer.writerows(results_list)
output = make_response(si.getvalue())
@@ -558,10 +558,10 @@ def trait_sample_data(dataset_name, trait_name, file_format = "json"):
sample_list = []
for sample in sample_data:
sample_dict = {
- "sample_name" : sample[0],
- "sample_name_2" : sample[1],
- "value" : sample[2],
- "data_id" : sample[3],
+ "sample_name": sample[0],
+ "sample_name_2": sample[1],
+ "value": sample[2],
+ "data_id": sample[3],
}
if sample[4]:
sample_dict["se"] = sample[4]
@@ -706,7 +706,7 @@ def get_mapping_results():
if format == "csv":
filename = "mapping_" + datetime.datetime.utcnow().strftime("%b_%d_%Y_%I:%M%p") + ".csv"
- si = StringIO.StringIO()
+ si = io.StringIO()
csv_writer = csv.writer(si)
csv_writer.writerows(results)
output = make_response(si.getvalue())
@@ -732,7 +732,7 @@ def get_genotypes(group_name, file_format="csv", dataset_name=None):
if request.args['limit_to'].isdigit():
limit_num = int(request.args['limit_to'])
- si = StringIO.StringIO()
+ si = io.StringIO()
if file_format == "csv" or file_format == "geno":
filename = group_name + ".geno"
diff --git a/wqflask/wqflask/collect.py b/wqflask/wqflask/collect.py
index 42a09fed..d77567f8 100644
--- a/wqflask/wqflask/collect.py
+++ b/wqflask/wqflask/collect.py
@@ -10,7 +10,7 @@ import uuid
import hashlib
import base64
-import urlparse
+import urllib.parse
import simplejson as json
@@ -193,7 +193,7 @@ def view_collection():
params = request.args
uc_id = params['uc_id']
- uc = (collection for collection in g.user_session.user_collections if collection["id"] == uc_id).next()
+ uc = next((collection for collection in g.user_session.user_collections if collection["id"] == uc_id))
traits = uc["members"]
trait_obs = []
diff --git a/wqflask/wqflask/comparison_bar_chart/comparison_bar_chart.py b/wqflask/wqflask/comparison_bar_chart/comparison_bar_chart.py
index 09d6b9cc..3e5daa50 100644
--- a/wqflask/wqflask/comparison_bar_chart/comparison_bar_chart.py
+++ b/wqflask/wqflask/comparison_bar_chart/comparison_bar_chart.py
@@ -24,7 +24,7 @@ import sys
# sys.path.append(".") Never do this in a webserver!
import string
-import cPickle
+import pickle
import os
import time
import pp
diff --git a/wqflask/wqflask/correlation/corr_scatter_plot.py b/wqflask/wqflask/correlation/corr_scatter_plot.py
index 819836b1..57a8d85f 100644
--- a/wqflask/wqflask/correlation/corr_scatter_plot.py
+++ b/wqflask/wqflask/correlation/corr_scatter_plot.py
@@ -36,13 +36,13 @@ class CorrScatterPlot(object):
samples_1, samples_2, num_overlap = corr_result_helpers.normalize_values_with_samples(self.trait_1.data, self.trait_2.data)
self.data = []
- self.indIDs = samples_1.keys()
+ self.indIDs = list(samples_1.keys())
vals_1 = []
- for sample in samples_1.keys():
+ for sample in list(samples_1.keys()):
vals_1.append(samples_1[sample].value)
self.data.append(vals_1)
vals_2 = []
- for sample in samples_2.keys():
+ for sample in list(samples_2.keys()):
vals_2.append(samples_2[sample].value)
self.data.append(vals_2)
diff --git a/wqflask/wqflask/correlation/correlation_functions.py b/wqflask/wqflask/correlation/correlation_functions.py
index 06dec795..abaa212f 100644
--- a/wqflask/wqflask/correlation/correlation_functions.py
+++ b/wqflask/wqflask/correlation/correlation_functions.py
@@ -50,12 +50,12 @@ from flask import Flask, g
def cal_zero_order_corr_for_tiss (primaryValue=[], targetValue=[], method='pearson'):
- R_primary = rpy2.robjects.FloatVector(range(len(primaryValue)))
+ R_primary = rpy2.robjects.FloatVector(list(range(len(primaryValue))))
N = len(primaryValue)
for i in range(len(primaryValue)):
R_primary[i] = primaryValue[i]
- R_target = rpy2.robjects.FloatVector(range(len(targetValue)))
+ R_target = rpy2.robjects.FloatVector(list(range(len(targetValue))))
for i in range(len(targetValue)):
R_target[i]=targetValue[i]
diff --git a/wqflask/wqflask/correlation/show_corr_results.py b/wqflask/wqflask/correlation/show_corr_results.py
index de7a1c0c..233a3a03 100644
--- a/wqflask/wqflask/correlation/show_corr_results.py
+++ b/wqflask/wqflask/correlation/show_corr_results.py
@@ -20,22 +20,11 @@
from __future__ import absolute_import, print_function, division
-import sys
-
-import string
-import cPickle
-import os
-import time
-import pp
-import math
import collections
-import resource
import json
-
import scipy
import numpy
import rpy2.robjects as ro # R Objects
-import rpy2.rinterface as ri
from rpy2.robjects.packages import importr
utils = importr("utils")
@@ -108,17 +97,17 @@ class CorrelationResults(object):
self.sample_data = {}
self.corr_type = start_vars['corr_type']
self.corr_method = start_vars['corr_sample_method']
- self.min_expr = get_float(start_vars,'min_expr')
- self.p_range_lower = get_float(start_vars,'p_range_lower',-1.0)
- self.p_range_upper = get_float(start_vars,'p_range_upper',1.0)
+ self.min_expr = get_float(start_vars, 'min_expr')
+ self.p_range_lower = get_float(start_vars, 'p_range_lower', -1.0)
+ self.p_range_upper = get_float(start_vars, 'p_range_upper', 1.0)
if ('loc_chr' in start_vars and
'min_loc_mb' in start_vars and
'max_loc_mb' in start_vars):
- self.location_chr = get_string(start_vars,'loc_chr')
- self.min_location_mb = get_int(start_vars,'min_loc_mb')
- self.max_location_mb = get_int(start_vars,'max_loc_mb')
+ self.location_chr = get_string(start_vars, 'loc_chr')
+ self.min_location_mb = get_int(start_vars, 'min_loc_mb')
+ self.max_location_mb = get_int(start_vars, 'max_loc_mb')
else:
self.location_chr = self.min_location_mb = self.max_location_mb = None
@@ -145,10 +134,10 @@ class CorrelationResults(object):
if corr_samples_group == 'samples_other':
primary_samples = [x for x in primary_samples if x not in (
self.dataset.group.parlist + self.dataset.group.f1list)]
- self.process_samples(start_vars, self.this_trait.data.keys(), primary_samples)
+ self.process_samples(start_vars, list(self.this_trait.data.keys()), primary_samples)
self.target_dataset = data_set.create_dataset(start_vars['corr_dataset'])
- self.target_dataset.get_trait_data(self.sample_data.keys())
+ self.target_dataset.get_trait_data(list(self.sample_data.keys()))
self.header_fields = get_header_fields(self.target_dataset.type, self.corr_method)
@@ -168,41 +157,41 @@ class CorrelationResults(object):
tissue_corr_data = self.do_tissue_correlation_for_all_traits()
if tissue_corr_data != None:
- for trait in tissue_corr_data.keys()[:self.return_number]:
+ for trait in list(tissue_corr_data.keys())[:self.return_number]:
self.get_sample_r_and_p_values(trait, self.target_dataset.trait_data[trait])
else:
- for trait, values in self.target_dataset.trait_data.iteritems():
+ for trait, values in list(self.target_dataset.trait_data.items()):
self.get_sample_r_and_p_values(trait, values)
elif self.corr_type == "lit":
self.trait_geneid_dict = self.dataset.retrieve_genes("GeneId")
lit_corr_data = self.do_lit_correlation_for_all_traits()
- for trait in lit_corr_data.keys()[:self.return_number]:
+ for trait in list(lit_corr_data.keys())[:self.return_number]:
self.get_sample_r_and_p_values(trait, self.target_dataset.trait_data[trait])
elif self.corr_type == "sample":
- for trait, values in self.target_dataset.trait_data.iteritems():
+ for trait, values in list(self.target_dataset.trait_data.items()):
self.get_sample_r_and_p_values(trait, values)
- self.correlation_data = collections.OrderedDict(sorted(self.correlation_data.items(),
+ self.correlation_data = collections.OrderedDict(sorted(list(self.correlation_data.items()),
key=lambda t: -abs(t[1][0])))
if self.target_dataset.type == "ProbeSet" or self.target_dataset.type == "Geno":
#ZS: Convert min/max chromosome to an int for the location range option
range_chr_as_int = None
- for order_id, chr_info in self.dataset.species.chromosomes.chromosomes.iteritems():
+ for order_id, chr_info in list(self.dataset.species.chromosomes.chromosomes.items()):
if 'loc_chr' in start_vars:
if chr_info.name == self.location_chr:
range_chr_as_int = order_id
- for _trait_counter, trait in enumerate(self.correlation_data.keys()[:self.return_number]):
+ for _trait_counter, trait in enumerate(list(self.correlation_data.keys())[:self.return_number]):
trait_object = create_trait(dataset=self.target_dataset, name=trait, get_qtl_info=True, get_sample_info=False)
if self.target_dataset.type == "ProbeSet" or self.target_dataset.type == "Geno":
#ZS: Convert trait chromosome to an int for the location range option
chr_as_int = 0
- for order_id, chr_info in self.dataset.species.chromosomes.chromosomes.iteritems():
+ for order_id, chr_info in list(self.dataset.species.chromosomes.chromosomes.items()):
if chr_info.name == trait_object.chr:
chr_as_int = order_id
@@ -297,14 +286,14 @@ class CorrelationResults(object):
#print("trait_gene_symbols: ", pf(trait_gene_symbols.values()))
corr_result_tissue_vals_dict= correlation_functions.get_trait_symbol_and_tissue_values(
- symbol_list=self.trait_symbol_dict.values())
+ symbol_list=list(self.trait_symbol_dict.values()))
#print("corr_result_tissue_vals: ", pf(corr_result_tissue_vals_dict))
#print("trait_gene_symbols: ", pf(trait_gene_symbols))
tissue_corr_data = {}
- for trait, symbol in self.trait_symbol_dict.iteritems():
+ for trait, symbol in list(self.trait_symbol_dict.items()):
if symbol and symbol.lower() in corr_result_tissue_vals_dict:
this_trait_tissue_values = corr_result_tissue_vals_dict[symbol.lower()]
@@ -314,7 +303,7 @@ class CorrelationResults(object):
tissue_corr_data[trait] = [symbol, result[0], result[2]]
- tissue_corr_data = collections.OrderedDict(sorted(tissue_corr_data.items(),
+ tissue_corr_data = collections.OrderedDict(sorted(list(tissue_corr_data.items()),
key=lambda t: -abs(t[1][1])))
return tissue_corr_data
@@ -359,7 +348,7 @@ class CorrelationResults(object):
input_trait_mouse_gene_id = self.convert_to_mouse_gene_id(self.dataset.group.species.lower(), self.this_trait.geneid)
lit_corr_data = {}
- for trait, gene_id in self.trait_geneid_dict.iteritems():
+ for trait, gene_id in list(self.trait_geneid_dict.items()):
mouse_gene_id = self.convert_to_mouse_gene_id(self.dataset.group.species.lower(), gene_id)
if mouse_gene_id and str(mouse_gene_id).find(";") == -1:
@@ -387,7 +376,7 @@ class CorrelationResults(object):
else:
lit_corr_data[trait] = [gene_id, 0]
- lit_corr_data = collections.OrderedDict(sorted(lit_corr_data.items(),
+ lit_corr_data = collections.OrderedDict(sorted(list(lit_corr_data.items()),
key=lambda t: -abs(t[1][1])))
return lit_corr_data
@@ -648,4 +637,4 @@ def get_header_fields(data_type, corr_method):
'N',
'Sample p(r)']
- return header_fields \ No newline at end of file
+ return header_fields
diff --git a/wqflask/wqflask/correlation_matrix/show_corr_matrix.py b/wqflask/wqflask/correlation_matrix/show_corr_matrix.py
index 0ac94139..ea786289 100644
--- a/wqflask/wqflask/correlation_matrix/show_corr_matrix.py
+++ b/wqflask/wqflask/correlation_matrix/show_corr_matrix.py
@@ -24,7 +24,7 @@ import sys
# sys.path.append(".") Never do this in a webserver!
import string
-import cPickle
+import pickle
import os
import datetime
import time
@@ -42,6 +42,10 @@ import rpy2.robjects as robjects
from pprint import pformat as pf
from utility.redis_tools import get_redis_conn
+try: # Only import this for Python3
+ from functools import reduce
+except:
+ pass
Redis = get_redis_conn()
THIRTY_DAYS = 60 * 60 * 24 * 30
@@ -190,7 +194,7 @@ class CorrelationMatrix(object):
if self.do_PCA == True:
self.pca_works = "True"
self.pca_trait_ids = []
- pca = self.calculate_pca(range(len(self.traits)), corr_eigen_value, corr_eigen_vectors)
+ pca = self.calculate_pca(list(range(len(self.traits))), corr_eigen_value, corr_eigen_vectors)
self.loadings_array = self.process_loadings()
else:
self.pca_works = "False"
@@ -199,8 +203,8 @@ class CorrelationMatrix(object):
self.js_data = dict(traits = [trait.name for trait in self.traits],
groups = groups,
- cols = range(len(self.traits)),
- rows = range(len(self.traits)),
+ cols = list(range(len(self.traits))),
+ rows = list(range(len(self.traits))),
samples = self.all_sample_list,
sample_data = self.sample_data,)
# corr_results = [result[1] for result in result_row for result_row in self.corr_results])
@@ -271,14 +275,14 @@ def zScore(trait_data_array):
i = 0
for data in trait_data_array:
N = len(data)
- S = reduce(lambda x,y: x+y, data, 0.)
- SS = reduce(lambda x,y: x+y*y, data, 0.)
+ S = reduce(lambda x, y: x+y, data, 0.)
+ SS = reduce(lambda x, y: x+y*y, data, 0.)
mean = S/N
var = SS - S*S/N
stdev = math.sqrt(var/(N-1))
if stdev == 0:
stdev = 1e-100
- data2 = map(lambda x:(x-mean)/stdev,data)
+ data2 = [(x-mean)/stdev for x in data]
trait_data_array[i] = data2
i += 1
return trait_data_array
@@ -290,7 +294,7 @@ def sortEigenVectors(vector):
combines = []
i = 0
for item in eigenValues:
- combines.append([eigenValues[i],eigenVectors[i]])
+ combines.append([eigenValues[i], eigenVectors[i]])
i += 1
combines.sort(webqtlUtil.cmpEigenValue)
A = []
@@ -298,8 +302,8 @@ def sortEigenVectors(vector):
for item in combines:
A.append(item[0])
B.append(item[1])
- sum = reduce(lambda x,y: x+y, A, 0.0)
- A = map(lambda x:x*100.0/sum, A)
+ sum = reduce(lambda x, y: x+y, A, 0.0)
+ A = [x*100.0/sum for x in A]
return [A, B]
except:
- return [] \ No newline at end of file
+ return []
diff --git a/wqflask/wqflask/ctl/ctl_analysis.py b/wqflask/wqflask/ctl/ctl_analysis.py
index 35067036..e58a7b87 100644
--- a/wqflask/wqflask/ctl/ctl_analysis.py
+++ b/wqflask/wqflask/ctl/ctl_analysis.py
@@ -125,7 +125,7 @@ class CTL(object):
gt = create_trait(name = ts[0], dataset_name = ts[1])
gt = retrieve_sample_data(gt, dataset, individuals)
for ind in individuals:
- if ind in gt.data.keys():
+ if ind in list(gt.data.keys()):
traits.append(gt.data[ind].value)
else:
traits.append("-999")
@@ -175,7 +175,7 @@ class CTL(object):
sys.stdout.flush()
# Create the interactive graph for cytoscape visualization (Nodes and Edges)
- if not type(significant) == ri.RNULLType:
+ if not isinstance(significant, ri.RNULLType):
for x in range(len(significant[0])):
logger.debug(significant[0][x], significant[1][x], significant[2][x]) # Debug to console
tsS = significant[0][x].split(':') # Source
diff --git a/wqflask/wqflask/do_search.py b/wqflask/wqflask/do_search.py
index 1e15d28f..cc9c1860 100644
--- a/wqflask/wqflask/do_search.py
+++ b/wqflask/wqflask/do_search.py
@@ -46,8 +46,8 @@ class DoSearch(object):
def handle_wildcard(self, str):
keyword = str.strip()
- keyword = keyword.replace("*",".*")
- keyword = keyword.replace("?",".")
+ keyword = keyword.replace("*", ".*")
+ keyword = keyword.replace("?", ".")
return keyword
diff --git a/wqflask/wqflask/export_traits.py b/wqflask/wqflask/export_traits.py
index 3272c03d..2f4e9aac 100644
--- a/wqflask/wqflask/export_traits.py
+++ b/wqflask/wqflask/export_traits.py
@@ -2,7 +2,7 @@ from __future__ import print_function, division
import csv
import xlsxwriter
-import StringIO
+import io
import datetime
import itertools
@@ -61,9 +61,9 @@ def export_search_results_csv(targs):
traits_by_group = sort_traits_by_group(trait_list)
file_list = []
- for group in traits_by_group.keys():
+ for group in list(traits_by_group.keys()):
group_traits = traits_by_group[group]
- buff = StringIO.StringIO()
+ buff = io.StringIO()
writer = csv.writer(buff)
csv_rows = []
@@ -122,7 +122,7 @@ def export_search_results_csv(targs):
csv_rows.append(row_contents)
- csv_rows = map(list, itertools.izip_longest(*[row for row in csv_rows]))
+ csv_rows = list(map(list, itertools.zip_longest(*[row for row in csv_rows])))
writer.writerows(csv_rows)
csv_data = buff.getvalue()
buff.close()
@@ -135,7 +135,7 @@ def export_search_results_csv(targs):
def sort_traits_by_group(trait_list=[]):
traits_by_group = {}
for trait in trait_list:
- if trait.dataset.group.name not in traits_by_group.keys():
+ if trait.dataset.group.name not in list(traits_by_group.keys()):
traits_by_group[trait.dataset.group.name] = []
traits_by_group[trait.dataset.group.name].append(trait)
diff --git a/wqflask/wqflask/external_tools/send_to_geneweaver.py b/wqflask/wqflask/external_tools/send_to_geneweaver.py
index 7a5dba73..9844bab4 100644
--- a/wqflask/wqflask/external_tools/send_to_geneweaver.py
+++ b/wqflask/wqflask/external_tools/send_to_geneweaver.py
@@ -54,10 +54,10 @@ class SendToGeneWeaver(object):
trait_name_list = get_trait_name_list(self.trait_list)
self.hidden_vars = {
- 'client' : "genenetwork",
- 'species' : species_name,
- 'idtype' : self.chip_name,
- 'list' : string.join(trait_name_list, ","),
+ 'client': "genenetwork",
+ 'species': species_name,
+ 'idtype': self.chip_name,
+ 'list': string.join(trait_name_list, ","),
}
def get_trait_name_list(trait_list):
diff --git a/wqflask/wqflask/heatmap/heatmap.py b/wqflask/wqflask/heatmap/heatmap.py
index 5098a184..4fdc1f13 100644
--- a/wqflask/wqflask/heatmap/heatmap.py
+++ b/wqflask/wqflask/heatmap/heatmap.py
@@ -4,7 +4,7 @@ import sys
# sys.path.append(".") Never in a running webserver
import string
-import cPickle
+import pickle
import os
import datetime
import time
@@ -30,7 +30,7 @@ from utility.tools import flat_files, REAPER_COMMAND, TEMPDIR
from MySQLdb import escape_string as escape
-import cPickle as pickle
+import pickle as pickle
import simplejson as json
from pprint import pformat as pf
@@ -60,7 +60,7 @@ class Heatmap(object):
chrnames = []
self.species = species.TheSpecies(dataset=self.trait_list[0][1])
- for key in self.species.chromosomes.chromosomes.keys():
+ for key in list(self.species.chromosomes.chromosomes.keys()):
chrnames.append([self.species.chromosomes.chromosomes[key].name, self.species.chromosomes.chromosomes[key].mb_length])
for trait_db in self.trait_list:
@@ -93,7 +93,7 @@ class Heatmap(object):
pos = []
markernames = []
- for trait in self.trait_results.keys():
+ for trait in list(self.trait_results.keys()):
lodnames.append(trait)
self.dataset.group.get_markers()
diff --git a/wqflask/wqflask/interval_analyst/GeneUtil.py b/wqflask/wqflask/interval_analyst/GeneUtil.py
index 2c60dd70..a39e5d0f 100644
--- a/wqflask/wqflask/interval_analyst/GeneUtil.py
+++ b/wqflask/wqflask/interval_analyst/GeneUtil.py
@@ -24,7 +24,7 @@ def loadGenes(chrName, diffCol, startMb, endMb, species='mouse'):
##List current Species and other Species
speciesId = speciesDict[species]
- otherSpecies = map(lambda X: [X, speciesDict[X]], speciesDict.keys())
+ otherSpecies = [[X, speciesDict[X]] for X in list(speciesDict.keys())]
otherSpecies.remove([species, speciesId])
results = g.db.execute("""
diff --git a/wqflask/wqflask/marker_regression/display_mapping_results.py b/wqflask/wqflask/marker_regression/display_mapping_results.py
index a92adb90..255e3b74 100644
--- a/wqflask/wqflask/marker_regression/display_mapping_results.py
+++ b/wqflask/wqflask/marker_regression/display_mapping_results.py
@@ -47,7 +47,11 @@ from base.webqtlConfig import GENERATED_IMAGE_DIR
from utility.pillow_utils import draw_rotated_text, draw_open_polygon
import utility.logger
-logger = utility.logger.getLogger(__name__)
+try: # Only import this for Python3
+ from functools import reduce
+except:
+ pass
+logger = utility.logger.getLogger(__name__ )
RED = ImageColor.getrgb("red")
BLUE = ImageColor.getrgb("blue")
@@ -265,7 +269,7 @@ class DisplayMappingResults(object):
self.manhattan_plot = start_vars['manhattan_plot']
- if 'permCheck' in start_vars.keys():
+ if 'permCheck' in list(start_vars.keys()):
self.permChecked = start_vars['permCheck']
else:
self.permChecked = False
@@ -278,46 +282,46 @@ class DisplayMappingResults(object):
else:
self.nperm = 0
- if 'bootCheck' in start_vars.keys():
+ if 'bootCheck' in list(start_vars.keys()):
self.bootChecked = start_vars['bootCheck']
else:
self.bootChecked = False
- if 'num_bootstrap' in start_vars.keys():
+ if 'num_bootstrap' in list(start_vars.keys()):
self.nboot = int(start_vars['num_bootstrap'])
else:
self.nboot = 0
- if 'bootstrap_results' in start_vars.keys():
+ if 'bootstrap_results' in list(start_vars.keys()):
self.bootResult = start_vars['bootstrap_results']
else:
self.bootResult = []
- if 'do_control' in start_vars.keys():
+ if 'do_control' in list(start_vars.keys()):
self.doControl = start_vars['do_control']
else:
self.doControl = "false"
- if 'control_marker' in start_vars.keys():
+ if 'control_marker' in list(start_vars.keys()):
self.controlLocus = start_vars['control_marker']
else:
self.controlLocus = ""
- if 'covariates' in start_vars.keys():
+ if 'covariates' in list(start_vars.keys()):
self.covariates = start_vars['covariates']
- if 'maf' in start_vars.keys():
+ if 'maf' in list(start_vars.keys()):
self.maf = start_vars['maf']
else:
self.maf = ""
- if 'output_files' in start_vars.keys():
+ if 'output_files' in list(start_vars.keys()):
self.output_files = start_vars['output_files']
- if 'use_loco' in start_vars.keys() and self.mapping_method == "gemma":
+ if 'use_loco' in list(start_vars.keys()) and self.mapping_method == "gemma":
self.use_loco = start_vars['use_loco']
- if 'reaper_version' in start_vars.keys() and self.mapping_method == "reaper":
+ if 'reaper_version' in list(start_vars.keys()) and self.mapping_method == "reaper":
self.reaper_version = start_vars['reaper_version']
if 'output_files' in start_vars:
self.output_files = ",".join(start_vars['output_files'])
self.categorical_vars = ""
self.perm_strata = ""
- if 'perm_strata' in start_vars.keys() and 'categorical_vars' in start_vars.keys():
+ if 'perm_strata' in list(start_vars.keys()) and 'categorical_vars' in list(start_vars.keys()):
self.categorical_vars = start_vars['categorical_vars']
self.perm_strata = start_vars['perm_strata']
@@ -359,7 +363,7 @@ class DisplayMappingResults(object):
self.graphWidth = self.MULT_GRAPH_DEFAULT_WIDTH
## BEGIN HaplotypeAnalyst
- if 'haplotypeAnalystCheck' in start_vars.keys():
+ if 'haplotypeAnalystCheck' in list(start_vars.keys()):
self.haplotypeAnalystChecked = start_vars['haplotypeAnalystCheck']
else:
self.haplotypeAnalystChecked = False
@@ -367,25 +371,25 @@ class DisplayMappingResults(object):
self.graphHeight = self.GRAPH_DEFAULT_HEIGHT
self.dominanceChecked = False
- if 'LRSCheck' in start_vars.keys():
+ if 'LRSCheck' in list(start_vars.keys()):
self.LRS_LOD = start_vars['LRSCheck']
else:
self.LRS_LOD = start_vars['score_type']
self.intervalAnalystChecked = True
self.draw2X = False
- if 'additiveCheck' in start_vars.keys():
+ if 'additiveCheck' in list(start_vars.keys()):
self.additiveChecked = start_vars['additiveCheck']
else:
self.additiveChecked = False
- if 'viewLegend' in start_vars.keys():
+ if 'viewLegend' in list(start_vars.keys()):
self.legendChecked = start_vars['viewLegend']
else:
self.legendChecked = False
- if 'showSNP' in start_vars.keys():
+ if 'showSNP' in list(start_vars.keys()):
self.SNPChecked = start_vars['showSNP']
else:
self.SNPChecked = False
- if 'showGenes' in start_vars.keys():
+ if 'showGenes' in list(start_vars.keys()):
self.geneChecked = start_vars['showGenes']
else:
self.geneChecked = False
@@ -425,9 +429,9 @@ class DisplayMappingResults(object):
Chr_Length.Name in (%s)
Order by
Chr_Length.OrderId
- """ % (self.dataset.group.name, string.join(map(lambda X: "'%s'" % X[0], self.ChrList[1:]), ", ")))
+ """ % (self.dataset.group.name, string.join(["'%s'" % X[0] for X in self.ChrList[1:]], ", ")))
- self.ChrLengthMbList = map(lambda x: x[0]/1000000.0, self.ChrLengthMbList)
+ self.ChrLengthMbList = [x[0]/1000000.0 for x in self.ChrLengthMbList]
self.ChrLengthMbSum = reduce(lambda x, y:x+y, self.ChrLengthMbList, 0.0)
if self.ChrLengthMbList:
self.MbGraphInterval = self.ChrLengthMbSum/(len(self.ChrLengthMbList)*12) #Empirical Mb interval
@@ -458,7 +462,7 @@ class DisplayMappingResults(object):
else:
continue
samplelist = list(self.genotype.prgy)
- for j,_geno in enumerate (self.genotype[0][1].genotype):
+ for j, _geno in enumerate (self.genotype[0][1].genotype):
for item in smd:
if item.name == samplelist[j]:
self.NR_INDIVIDUALS = self.NR_INDIVIDUALS + 1
@@ -554,7 +558,7 @@ class DisplayMappingResults(object):
#Scales plot differently for high resolution
if self.draw2X:
- intCanvasX2 = Image.new("RGBA", size=(self.graphWidth*2,self.graphHeight*2))
+ intCanvasX2 = Image.new("RGBA", size=(self.graphWidth*2, self.graphHeight*2))
gifmapX2 = self.plotIntMapping(intCanvasX2, startMb = self.startMb, endMb = self.endMb, showLocusForm= showLocusForm, zoom=2)
intCanvasX2.save(
"{}.png".format(
@@ -788,17 +792,17 @@ class DisplayMappingResults(object):
bootScale = bootScale[:-1] + [highestPercent]
bootOffset = 50*fontZoom
- bootScaleFont=ImageFont.truetype(font=VERDANA_FILE,size=13*fontZoom)
+ bootScaleFont=ImageFont.truetype(font=VERDANA_FILE, size=13*fontZoom)
im_drawer.rectangle(
xy=((canvas.size[0]-bootOffset, yZero-bootHeightThresh),
- (canvas.size[0]-bootOffset-15*zoom,yZero)),
+ (canvas.size[0]-bootOffset-15*zoom, yZero)),
fill = YELLOW, outline=BLACK)
im_drawer.line(
xy=((canvas.size[0]-bootOffset+4, yZero),
(canvas.size[0]-bootOffset, yZero)),
fill=BLACK)
TEXT_Y_DISPLACEMENT = -8
- im_drawer.text(xy=(canvas.size[0]-bootOffset+10,yZero+TEXT_Y_DISPLACEMENT), text='0%',
+ im_drawer.text(xy=(canvas.size[0]-bootOffset+10, yZero+TEXT_Y_DISPLACEMENT), text='0%',
font=bootScaleFont, fill=BLACK)
for item in bootScale:
@@ -806,10 +810,10 @@ class DisplayMappingResults(object):
continue
bootY = yZero-bootHeightThresh*item/highestPercent
im_drawer.line(
- xy=((canvas.size[0]-bootOffset+4,bootY),
- (canvas.size[0]-bootOffset,bootY)),
+ xy=((canvas.size[0]-bootOffset+4, bootY),
+ (canvas.size[0]-bootOffset, bootY)),
fill=BLACK)
- im_drawer.text(xy=(canvas.size[0]-bootOffset+10,bootY+TEXT_Y_DISPLACEMENT),
+ im_drawer.text(xy=(canvas.size[0]-bootOffset+10, bootY+TEXT_Y_DISPLACEMENT),
text='%2.1f'%item, font=bootScaleFont, fill=BLACK)
if self.legendChecked:
@@ -818,7 +822,7 @@ class DisplayMappingResults(object):
smallLabelFont = ImageFont.truetype(font=TREBUC_FILE, size=12*fontZoom)
leftOffset = xLeftOffset+(nCol-1)*200
im_drawer.rectangle(
- xy=((leftOffset,startPosY-6), (leftOffset+12,startPosY+6)),
+ xy=((leftOffset, startPosY-6), (leftOffset+12, startPosY+6)),
fill=YELLOW, outline=BLACK)
im_drawer.text(xy=(leftOffset+ 20, startPosY+TEXT_Y_DISPLACEMENT),
text='Frequency of the Peak LRS',
@@ -915,7 +919,7 @@ class DisplayMappingResults(object):
TEXT_Y_DISPLACEMENT = -8
im_drawer.text(
text="Sequence Site",
- xy=(leftOffset+15,startPosY+TEXT_Y_DISPLACEMENT), font=smallLabelFont,
+ xy=(leftOffset+15, startPosY+TEXT_Y_DISPLACEMENT), font=smallLabelFont,
fill=self.TOP_RIGHT_INFO_COLOR)
def drawSNPTrackNew(self, canvas, offset= (40, 120, 80, 10), zoom = 1, startMb = None, endMb = None):
@@ -965,7 +969,7 @@ class DisplayMappingResults(object):
def drawMultiTraitName(self, fd, canvas, gifmap, showLocusForm, offset= (40, 120, 80, 10), zoom = 1):
nameWidths = []
yPaddingTop = 10
- colorFont=ImageFont.truetype(font=TREBUC_FILE,size=12)
+ colorFont=ImageFont.truetype(font=TREBUC_FILE, size=12)
if len(self.qtlresults) >20 and self.selectedChr > -1:
rightShift = 20
rightShiftStep = 60
@@ -984,20 +988,20 @@ class DisplayMappingResults(object):
rightShift += rightShiftStep
name = thisTrait.displayName()
- nameWidth, nameHeight = im_drawer.textsize(name,font=colorFont)
+ nameWidth, nameHeight = im_drawer.textsize(name, font=colorFont)
nameWidths.append(nameWidth)
im_drawer.rectangle(
- xy=((rightShift,yPaddingTop+kstep*15),
- (rectWidth+rightShift,yPaddingTop+10+kstep*15)),
+ xy=((rightShift, yPaddingTop+kstep*15),
+ (rectWidth+rightShift, yPaddingTop+10+kstep*15)),
fill=thisLRSColor, outline=BLACK)
im_drawer.text(
- text=name,xy=(rectWidth+2+rightShift,yPaddingTop+10+kstep*15),
- font=colorFont,fill=BLACK)
+ text=name, xy=(rectWidth+2+rightShift, yPaddingTop+10+kstep*15),
+ font=colorFont, fill=BLACK)
if thisTrait.db:
- COORDS = "%d,%d,%d,%d" %(rectWidth+2+rightShift,yPaddingTop+kstep*15,rectWidth+2+rightShift+nameWidth,yPaddingTop+10+kstep*15,)
+ COORDS = "%d,%d,%d,%d" %(rectWidth+2+rightShift, yPaddingTop+kstep*15, rectWidth+2+rightShift+nameWidth, yPaddingTop+10+kstep*15,)
HREF= "javascript:showDatabase3('%s','%s','%s','');" % (showLocusForm, thisTrait.db.name, thisTrait.name)
- Areas = HtmlGenWrapper.create_area_tag(shape='rect',coords=COORDS,href=HREF)
+ Areas = HtmlGenWrapper.create_area_tag(shape='rect', coords=COORDS, href=HREF)
gifmap.areas.append(Areas) ### TODO
def drawLegendPanel(self, canvas, offset= (40, 120, 80, 10), zoom = 1):
@@ -1011,80 +1015,80 @@ class DisplayMappingResults(object):
if zoom == 2:
fontZoom = 1.5
- labelFont=ImageFont.truetype(font=TREBUC_FILE,size=12*fontZoom)
+ labelFont=ImageFont.truetype(font=TREBUC_FILE, size=12*fontZoom)
startPosY = 15
stepPosY = 12*fontZoom
if self.manhattan_plot != True:
im_drawer.line(
- xy=((xLeftOffset,startPosY),(xLeftOffset+32,startPosY)),
+ xy=((xLeftOffset, startPosY), (xLeftOffset+32, startPosY)),
fill=self.LRS_COLOR, width=2)
im_drawer.text(
- text=self.LRS_LOD, xy=(xLeftOffset+40,startPosY+TEXT_Y_DISPLACEMENT),
- font=labelFont,fill=BLACK)
+ text=self.LRS_LOD, xy=(xLeftOffset+40, startPosY+TEXT_Y_DISPLACEMENT),
+ font=labelFont, fill=BLACK)
startPosY += stepPosY
if self.additiveChecked:
startPosX = xLeftOffset
im_drawer.line(
- xy=((startPosX,startPosY),(startPosX+17,startPosY)),
+ xy=((startPosX, startPosY), (startPosX+17, startPosY)),
fill=self.ADDITIVE_COLOR_POSITIVE, width=2)
im_drawer.line(
- xy=((startPosX+18,startPosY),(startPosX+32,startPosY)),
+ xy=((startPosX+18, startPosY), (startPosX+32, startPosY)),
fill=self.ADDITIVE_COLOR_NEGATIVE, width=2)
im_drawer.text(
- text='Additive Effect',xy=(startPosX+40,startPosY+TEXT_Y_DISPLACEMENT),
- font=labelFont,fill=BLACK)
+ text='Additive Effect', xy=(startPosX+40, startPosY+TEXT_Y_DISPLACEMENT),
+ font=labelFont, fill=BLACK)
if self.genotype.type == 'intercross' and self.dominanceChecked:
startPosX = xLeftOffset
startPosY += stepPosY
im_drawer.line(
- xy=((startPosX,startPosY),(startPosX+17,startPosY)),
+ xy=((startPosX, startPosY), (startPosX+17, startPosY)),
fill=self.DOMINANCE_COLOR_POSITIVE, width=4)
im_drawer.line(
- xy=((startPosX+18,startPosY),(startPosX+35,startPosY)),
+ xy=((startPosX+18, startPosY), (startPosX+35, startPosY)),
fill=self.DOMINANCE_COLOR_NEGATIVE, width=4)
im_drawer.text(
- text='Dominance Effect', xy=(startPosX+42,startPosY+5),
- font=labelFont,fill=BLACK)
+ text='Dominance Effect', xy=(startPosX+42, startPosY+5),
+ font=labelFont, fill=BLACK)
if self.haplotypeAnalystChecked:
startPosY += stepPosY
startPosX = xLeftOffset
im_drawer.line(
- xy=((startPosX,startPosY),(startPosX+17,startPosY)),
+ xy=((startPosX, startPosY), (startPosX+17, startPosY)),
fill=self.HAPLOTYPE_POSITIVE, width=4)
im_drawer.line(
- xy=((startPosX+18,startPosY),(startPosX+35,startPosY)),
+ xy=((startPosX+18, startPosY), (startPosX+35, startPosY)),
fill=self.HAPLOTYPE_NEGATIVE, width=4)
im_drawer.line(
- xy=((startPosX+36,startPosY),(startPosX+53,startPosY)),
+ xy=((startPosX+36, startPosY), (startPosX+53, startPosY)),
fill=self.HAPLOTYPE_HETEROZYGOUS, width=4)
im_drawer.line(
- xy=((startPosX+54,startPosY),(startPosX+67,startPosY)),
+ xy=((startPosX+54, startPosY), (startPosX+67, startPosY)),
fill=self.HAPLOTYPE_RECOMBINATION, width=4)
im_drawer.text(
text='Haplotypes (Pat, Mat, Het, Unk)',
- xy=(startPosX+76,startPosY+5),font=labelFont,fill=BLACK)
+ xy=(startPosX+76, startPosY+5), font=labelFont, fill=BLACK)
if self.permChecked and self.nperm > 0:
startPosY += stepPosY
startPosX = xLeftOffset
im_drawer.line(
- xy=((startPosX, startPosY),( startPosX + 32, startPosY)),
+ xy=((startPosX, startPosY), ( startPosX + 32, startPosY)),
fill=self.SIGNIFICANT_COLOR, width=self.SIGNIFICANT_WIDTH)
im_drawer.line(
- xy=((startPosX, startPosY + stepPosY),( startPosX + 32, startPosY + stepPosY)),
+ xy=((startPosX, startPosY + stepPosY), ( startPosX + 32, startPosY + stepPosY)),
fill=self.SUGGESTIVE_COLOR, width=self.SUGGESTIVE_WIDTH)
im_drawer.text(
- text='Significant %s = %2.2f' % (self.LRS_LOD,self.significant),
- xy=(xLeftOffset+42,startPosY+TEXT_Y_DISPLACEMENT),font=labelFont,fill=BLACK)
+ text='Significant %s = %2.2f' % (self.LRS_LOD, self.significant),
+ xy=(xLeftOffset+42, startPosY+TEXT_Y_DISPLACEMENT), font=labelFont, fill=BLACK)
im_drawer.text(
text='Suggestive %s = %2.2f' % (self.LRS_LOD, self.suggestive),
- xy=(xLeftOffset+42,startPosY + TEXT_Y_DISPLACEMENT +stepPosY),font=labelFont,
+ xy=(xLeftOffset+42, startPosY + TEXT_Y_DISPLACEMENT +stepPosY), font=labelFont,
fill=BLACK)
- labelFont = ImageFont.truetype(font=VERDANA_FILE,size=12*fontZoom)
+ labelFont = ImageFont.truetype(font=VERDANA_FILE, size=12*fontZoom)
labelColor = BLACK
if self.dataset.type == "Publish" or self.dataset.type == "Geno":
dataset_label = self.dataset.fullname
@@ -1152,22 +1156,22 @@ class DisplayMappingResults(object):
im_drawer.textsize(string2, font=labelFont)[0])
im_drawer.text(
text=identification,
- xy=(canvas.size[0] - xRightOffset-d,20*fontZoom),font=labelFont,
+ xy=(canvas.size[0] - xRightOffset-d, 20*fontZoom), font=labelFont,
fill=labelColor)
else:
d = 4+ max(
im_drawer.textsize(string1, font=labelFont)[0],
im_drawer.textsize(string2, font=labelFont)[0])
im_drawer.text(
- text=string1,xy=(canvas.size[0] - xRightOffset-d,35*fontZoom),
- font=labelFont,fill=labelColor)
+ text=string1, xy=(canvas.size[0] - xRightOffset-d, 35*fontZoom),
+ font=labelFont, fill=labelColor)
im_drawer.text(
- text=string2,xy=(canvas.size[0] - xRightOffset-d,50*fontZoom),
- font=labelFont,fill=labelColor)
+ text=string2, xy=(canvas.size[0] - xRightOffset-d, 50*fontZoom),
+ font=labelFont, fill=labelColor)
if string3 != '':
im_drawer.text(
- text=string3,xy=(canvas.size[0] - xRightOffset-d,65*fontZoom),
- font=labelFont,fill=labelColor)
+ text=string3, xy=(canvas.size[0] - xRightOffset-d, 65*fontZoom),
+ font=labelFont, fill=labelColor)
def drawGeneBand(self, canvas, gifmap, plotXScale, offset= (40, 120, 80, 10), zoom = 1, startMb = None, endMb = None):
@@ -1194,8 +1198,8 @@ class DisplayMappingResults(object):
tenPercentLength = geneLength*0.0001
SNPdensity = theGO["snpCount"]/geneLength
- exonStarts = map(float, theGO['exonStarts'].split(",")[:-1])
- exonEnds = map(float, theGO['exonEnds'].split(",")[:-1])
+ exonStarts = list(map(float, theGO['exonStarts'].split(",")[:-1]))
+ exonEnds = list(map(float, theGO['exonEnds'].split(",")[:-1]))
cdsStart = theGO['cdsStart']
cdsEnd = theGO['cdsEnd']
accession = theGO['NM_ID']
@@ -1388,7 +1392,7 @@ class DisplayMappingResults(object):
labelText = "3'"
im_drawer.text(
text=labelText,
- xy=(utrEndPix+2,geneYLocation+self.EACH_GENE_HEIGHT),
+ xy=(utrEndPix+2, geneYLocation+self.EACH_GENE_HEIGHT),
font=ImageFont.truetype(font=ARIAL_FILE, size=2))
#draw the genes as rectangles
@@ -1541,7 +1545,7 @@ class DisplayMappingResults(object):
counter = counter + 1
if item.name == samplelist[k]:
ind = counter
- maxind=max(ind,maxind)
+ maxind=max(ind, maxind)
# lines
if (oldgeno[k] == -1 and _geno == -1):
@@ -1710,7 +1714,7 @@ class DisplayMappingResults(object):
outline=self.CLICKABLE_WEBQTL_REGION_COLOR,
fill=self.CLICKABLE_WEBQTL_REGION_COLOR)
im_drawer.line(
- xy=((xBrowse1, paddingTop),( xBrowse1, (paddingTop + self.BAND_HEIGHT))),
+ xy=((xBrowse1, paddingTop), ( xBrowse1, (paddingTop + self.BAND_HEIGHT))),
fill=self.CLICKABLE_WEBQTL_REGION_OUTLINE_COLOR)
if self.dataset.group.species == "mouse" or self.dataset.group.species == "rat":
@@ -1732,7 +1736,7 @@ class DisplayMappingResults(object):
outline=self.CLICKABLE_PHENOGEN_REGION_COLOR,
fill=self.CLICKABLE_PHENOGEN_REGION_COLOR)
im_drawer.line(
- xy=((xBrowse1, phenogenPaddingTop),( xBrowse1, (phenogenPaddingTop+self.BAND_HEIGHT))),
+ xy=((xBrowse1, phenogenPaddingTop), ( xBrowse1, (phenogenPaddingTop+self.BAND_HEIGHT))),
fill=self.CLICKABLE_PHENOGEN_REGION_OUTLINE_COLOR)
UCSC_COORDS = "%d, %d, %d, %d" %(xBrowse1, ucscPaddingTop, xBrowse2, (ucscPaddingTop+self.BAND_HEIGHT))
@@ -1864,8 +1868,8 @@ class DisplayMappingResults(object):
continue
Xc = xLeftOffset + plotXScale*(_Mb - startMb)
if counter % NUM_MINOR_TICKS == 0: # Draw a MAJOR mark, not just a minor tick mark
- im_drawer.line(xy=((Xc,yZero),
- (Xc,yZero+xMajorTickHeight)),
+ im_drawer.line(xy=((Xc, yZero),
+ (Xc, yZero+xMajorTickHeight)),
fill=xAxisTickMarkColor,
width=X_MAJOR_TICK_THICKNESS) # Draw the MAJOR tick mark
labelStr = str(formatStr % _Mb) # What Mbase location to put on the label
@@ -1875,8 +1879,8 @@ class DisplayMappingResults(object):
text=labelStr, font=MBLabelFont,
fill=xAxisLabelColor)
else:
- im_drawer.line(xy=((Xc,yZero),
- (Xc,yZero+xMinorTickHeight)),
+ im_drawer.line(xy=((Xc, yZero),
+ (Xc, yZero+xMinorTickHeight)),
fill=xAxisTickMarkColor,
width=X_MINOR_TICK_THICKNESS) # Draw the MINOR tick mark
@@ -1909,7 +1913,7 @@ class DisplayMappingResults(object):
text="Megabases",
xy=(
xLeftOffset+(plotWidth-im_drawer.textsize(
- "Megabases",font=megabaseLabelFont)[0])/2,
+ "Megabases", font=megabaseLabelFont)[0])/2,
strYLoc+MBLabelFont.font.height+10*(zoom%2)),
font=megabaseLabelFont, fill=BLACK)
pass
@@ -1964,7 +1968,7 @@ class DisplayMappingResults(object):
for j, ChrInfo in enumerate(ChrAInfo):
preLpos = -1
for i, item in enumerate(ChrInfo):
- Lname,Lpos = item
+ Lname, Lpos = item
if Lpos != preLpos:
offsetA += stepA
differ = 1
@@ -1978,17 +1982,17 @@ class DisplayMappingResults(object):
Zorder = 0
if differ:
im_drawer.line(
- xy=((startPosX+Lpos,yZero),(xLeftOffset+offsetA,\
+ xy=((startPosX+Lpos, yZero), (xLeftOffset+offsetA,\
yZero+25)),
fill=lineColor)
im_drawer.line(
- xy=((xLeftOffset+offsetA,yZero+25),(xLeftOffset+offsetA,\
+ xy=((xLeftOffset+offsetA, yZero+25), (xLeftOffset+offsetA,\
yZero+40+Zorder*(LRectWidth+3))),
fill=lineColor)
rectColor = ORANGE
else:
im_drawer.line(
- xy=((xLeftOffset+offsetA, yZero+40+Zorder*(LRectWidth+3)-3),(\
+ xy=((xLeftOffset+offsetA, yZero+40+Zorder*(LRectWidth+3)-3), (\
xLeftOffset+offsetA, yZero+40+Zorder*(LRectWidth+3))),
fill=lineColor)
rectColor = DEEPPINK
@@ -1996,7 +2000,7 @@ class DisplayMappingResults(object):
xy=((xLeftOffset+offsetA, yZero+40+Zorder*(LRectWidth+3)),
(xLeftOffset+offsetA-LRectHeight,
yZero+40+Zorder*(LRectWidth+3)+LRectWidth)),
- outline=rectColor,fill=rectColor,width = 0)
+ outline=rectColor, fill=rectColor, width = 0)
COORDS="%d,%d,%d,%d"%(xLeftOffset+offsetA-LRectHeight, yZero+40+Zorder*(LRectWidth+3),\
xLeftOffset+offsetA,yZero+40+Zorder*(LRectWidth+3)+LRectWidth)
HREF = "/show_trait?trait_id=%s&dataset=%s" % (Lname, self.dataset.group.name+"Geno")
@@ -2011,7 +2015,7 @@ class DisplayMappingResults(object):
##piddle bug
if j == 0:
im_drawer.line(
- xy=((startPosX,yZero),(startPosX,yZero+40)),
+ xy=((startPosX, yZero), (startPosX, yZero+40)),
fill=lineColor)
startPosX += (self.ChrLengthDistList[j]+self.GraphInterval)*plotXScale
@@ -2023,7 +2027,7 @@ class DisplayMappingResults(object):
strYLoc + MBLabelFont.font.height+ 10*(zoom%2)),
font=centimorganLabelFont, fill=BLACK)
- im_drawer.line(xy=((xLeftOffset,yZero), (xLeftOffset+plotWidth,yZero)),
+ im_drawer.line(xy=((xLeftOffset, yZero), (xLeftOffset+plotWidth, yZero)),
fill=BLACK, width=X_AXIS_THICKNESS) # Draw the X axis itself
@@ -2167,7 +2171,7 @@ class DisplayMappingResults(object):
LRS_LOD_Max = 0.000001
yTopOffset + 30*(zoom - 1)
yLRS = yZero - (item/LRS_LOD_Max) * LRSHeightThresh
- im_drawer.line(xy=((xLeftOffset,yLRS), (xLeftOffset-4,yLRS)),
+ im_drawer.line(xy=((xLeftOffset, yLRS), (xLeftOffset-4, yLRS)),
fill=self.LRS_COLOR, width=1*zoom)
if all_int:
scaleStr = "%d" % item
@@ -2243,7 +2247,7 @@ class DisplayMappingResults(object):
lrsEdgeWidth = 1
else:
if self.additiveChecked:
- additiveMax = max(map(lambda X : abs(X['additive']), self.qtlresults))
+ additiveMax = max([abs(X['additive']) for X in self.qtlresults])
lrsEdgeWidth = 3
if zoom == 2:
@@ -2410,7 +2414,7 @@ class DisplayMappingResults(object):
im_drawer.text(
text="5",
xy=(
- Xc-im_drawer.textsize("5",font=symbolFont)[0]/2+1,
+ Xc-im_drawer.textsize("5", font=symbolFont)[0]/2+1,
Yc-4),
fill=point_color, font=symbolFont)
else:
@@ -2477,8 +2481,8 @@ class DisplayMappingResults(object):
)
else:
im_drawer.line(
- xy=((Xc0,yZero-(Yc0-yZero)),
- (Xc,yZero-(Yc-yZero))),
+ xy=((Xc0, yZero-(Yc0-yZero)),
+ (Xc, yZero-(Yc-yZero))),
fill=minusColor, width=lineWidth
#, clipX=(xLeftOffset, xLeftOffset + plotWidth)
)
@@ -2565,8 +2569,8 @@ class DisplayMappingResults(object):
###draw additive scale
if not self.multipleInterval and self.additiveChecked:
- additiveScaleFont=ImageFont.truetype(font=VERDANA_FILE,size=16*zoom)
- additiveScale = Plot.detScaleOld(0,additiveMax)
+ additiveScaleFont=ImageFont.truetype(font=VERDANA_FILE, size=16*zoom)
+ additiveScale = Plot.detScaleOld(0, additiveMax)
additiveStep = (additiveScale[1]-additiveScale[0])/additiveScale[2]
additiveAxisList = Plot.frange(0, additiveScale[1], additiveStep)
addPlotScale = AdditiveHeightThresh/additiveMax
@@ -2576,18 +2580,18 @@ class DisplayMappingResults(object):
for item in additiveAxisList:
additiveY = yZero - item*addPlotScale
im_drawer.line(
- xy=((xLeftOffset + plotWidth,additiveY),
- (xLeftOffset+4+ plotWidth,additiveY)),
+ xy=((xLeftOffset + plotWidth, additiveY),
+ (xLeftOffset+4+ plotWidth, additiveY)),
fill=self.ADDITIVE_COLOR_POSITIVE, width=1*zoom)
scaleStr = "%2.3f" % item
im_drawer.text(
text=scaleStr,
- xy=(xLeftOffset + plotWidth +6,additiveY+TEXT_Y_DISPLACEMENT),
- font=additiveScaleFont,fill=self.ADDITIVE_COLOR_POSITIVE)
+ xy=(xLeftOffset + plotWidth +6, additiveY+TEXT_Y_DISPLACEMENT),
+ font=additiveScaleFont, fill=self.ADDITIVE_COLOR_POSITIVE)
im_drawer.line(
- xy=((xLeftOffset+plotWidth,additiveY),
- (xLeftOffset+plotWidth,yZero)),
+ xy=((xLeftOffset+plotWidth, additiveY),
+ (xLeftOffset+plotWidth, yZero)),
fill=self.ADDITIVE_COLOR_POSITIVE, width=1*zoom)
im_drawer.line(
@@ -2647,7 +2651,7 @@ class DisplayMappingResults(object):
chrFontZoom = 2
else:
chrFontZoom = 1
- chrLabelFont=ImageFont.truetype(font=VERDANA_FILE,size=24*chrFontZoom)
+ chrLabelFont=ImageFont.truetype(font=VERDANA_FILE, size=24*chrFontZoom)
for i, _chr in enumerate(self.genotype):
if (i % 2 == 0):
@@ -2669,10 +2673,10 @@ class DisplayMappingResults(object):
TEXT_Y_DISPLACEMENT = 0
im_drawer.text(xy=(chrStartPix, yTopOffset + TEXT_Y_DISPLACEMENT),
text=_chr.name, font=chrLabelFont, fill=BLACK)
- COORDS = "%d,%d,%d,%d" %(chrStartPix, yTopOffset, chrEndPix,yTopOffset +20)
+ COORDS = "%d,%d,%d,%d" %(chrStartPix, yTopOffset, chrEndPix, yTopOffset +20)
#add by NL 09-03-2010
- HREF = "javascript:chrView(%d,%s);" % (i,self.ChrLengthMbList)
+ HREF = "javascript:chrView(%d,%s);" % (i, self.ChrLengthMbList)
#HREF = "javascript:changeView(%d,%s);" % (i,self.ChrLengthMbList)
Areas = HtmlGenWrapper.create_area_tag(
shape='rect',
@@ -2821,7 +2825,7 @@ class DisplayMappingResults(object):
else:
chr_as_int = int(theGO["Chromosome"]) - 1
if refGene:
- literatureCorrelationString = str(self.getLiteratureCorrelation(self.cursor,refGene,theGO['GeneID']) or "N/A")
+ literatureCorrelationString = str(self.getLiteratureCorrelation(self.cursor, refGene, theGO['GeneID']) or "N/A")
this_row = [selectCheck.__str__(),
str(tableIterationsCnt),
@@ -2959,8 +2963,8 @@ class DisplayMappingResults(object):
lCorr = None
try:
query = 'SELECT Value FROM LCorrRamin3 WHERE GeneId1 = %s and GeneId2 = %s'
- for x,y in [(geneId1,geneId2),(geneId2,geneId1)]:
- cursor.execute(query,(x,y))
+ for x, y in [(geneId1, geneId2), (geneId2, geneId1)]:
+ cursor.execute(query, (x, y))
lCorr = cursor.fetchone()
if lCorr:
lCorr = lCorr[0]
diff --git a/wqflask/wqflask/marker_regression/plink_mapping.py b/wqflask/wqflask/marker_regression/plink_mapping.py
index 2f327faf..2f282adc 100644
--- a/wqflask/wqflask/marker_regression/plink_mapping.py
+++ b/wqflask/wqflask/marker_regression/plink_mapping.py
@@ -54,7 +54,7 @@ def gen_pheno_txt_file_plink(this_trait, dataset, vals, pheno_filename = ''):
for i, sample in enumerate(ped_sample_list):
try:
value = vals[i]
- value = str(value).replace('value=','')
+ value = str(value).replace('value=', '')
value = value.strip()
except:
value = -9999
@@ -78,13 +78,13 @@ def gen_pheno_txt_file_plink(this_trait, dataset, vals, pheno_filename = ''):
# get strain name from ped file in order
def get_samples_from_ped_file(dataset):
- ped_file= open("{}{}.ped".format(flat_files('mapping'), dataset.group.name),"r")
+ ped_file= open("{}{}.ped".format(flat_files('mapping'), dataset.group.name), "r")
line = ped_file.readline()
sample_list=[]
while line:
lineList = string.split(string.strip(line), '\t')
- lineList = map(string.strip, lineList)
+ lineList = list(map(string.strip, lineList))
sample_name = lineList[0]
sample_list.append(sample_name)
@@ -111,7 +111,7 @@ def parse_plink_output(output_filename, species):
line_list = build_line_list(line=line)
# only keep the records whose chromosome name is in db
- if species.chromosomes.chromosomes.has_key(int(line_list[0])) and line_list[-1] and line_list[-1].strip()!='NA':
+ if int(line_list[0]) in species.chromosomes.chromosomes and line_list[-1] and line_list[-1].strip()!='NA':
chr_name = species.chromosomes.chromosomes[int(line_list[0])]
snp = line_list[1]
@@ -121,7 +121,7 @@ def parse_plink_output(output_filename, species):
if p_value < threshold_p_value:
p_value_dict[snp] = float(p_value)
- if plink_results.has_key(chr_name):
+ if chr_name in plink_results:
value_list = plink_results[chr_name]
# pvalue range is [0,1]
@@ -155,8 +155,8 @@ def parse_plink_output(output_filename, species):
# output: lineList list
#######################################################
def build_line_list(line=None):
- line_list = string.split(string.strip(line),' ')# irregular number of whitespaces between columns
- line_list = [item for item in line_list if item <>'']
- line_list = map(string.strip, line_list)
+ line_list = string.split(string.strip(line), ' ')# irregular number of whitespaces between columns
+ line_list = [item for item in line_list if item !='']
+ line_list = list(map(string.strip, line_list))
return line_list \ No newline at end of file
diff --git a/wqflask/wqflask/marker_regression/qtlreaper_mapping.py b/wqflask/wqflask/marker_regression/qtlreaper_mapping.py
index 0c560582..189c1985 100644
--- a/wqflask/wqflask/marker_regression/qtlreaper_mapping.py
+++ b/wqflask/wqflask/marker_regression/qtlreaper_mapping.py
@@ -228,4 +228,4 @@ def natural_sort(marker_list):
"""
convert = lambda text: int(text) if text.isdigit() else text.lower()
alphanum_key = lambda key: [ convert(c) for c in re.split('([0-9]+)', str(marker_list[key]['chr'])) ]
- return sorted(range(len(marker_list)), key = alphanum_key) \ No newline at end of file
+ return sorted(list(range(len(marker_list))), key = alphanum_key) \ No newline at end of file
diff --git a/wqflask/wqflask/marker_regression/rqtl_mapping.py b/wqflask/wqflask/marker_regression/rqtl_mapping.py
index c5590a85..0a5758af 100644
--- a/wqflask/wqflask/marker_regression/rqtl_mapping.py
+++ b/wqflask/wqflask/marker_regression/rqtl_mapping.py
@@ -42,7 +42,7 @@ def run_rqtl_geno(vals, samples, dataset, mapping_scale, method, model, permChec
png = ro.r["png"] # Map the png function
dev_off = ro.r["dev.off"] # Map the device off function
- print(r_library("qtl")) # Load R/qtl
+ print((r_library("qtl"))) # Load R/qtl
logger.info("QTL library loaded");
diff --git a/wqflask/wqflask/marker_regression/run_mapping.py b/wqflask/wqflask/marker_regression/run_mapping.py
index c9d10f7c..67512bc6 100644
--- a/wqflask/wqflask/marker_regression/run_mapping.py
+++ b/wqflask/wqflask/marker_regression/run_mapping.py
@@ -18,7 +18,7 @@ import uuid
import rpy2.robjects as ro
import numpy as np
-import cPickle as pickle
+import pickle as pickle
import itertools
import simplejson as json
@@ -347,7 +347,7 @@ class RunMapping(object):
if marker['chr1'] > 0 or marker['chr1'] == "X" or marker['chr1'] == "X/Y":
if marker['chr1'] > highest_chr or marker['chr1'] == "X" or marker['chr1'] == "X/Y":
highest_chr = marker['chr1']
- if 'lod_score' in marker.keys():
+ if 'lod_score' in list(marker.keys()):
self.qtl_results.append(marker)
self.trimmed_markers = results
@@ -411,7 +411,7 @@ class RunMapping(object):
if marker['chr'] > 0 or marker['chr'] == "X" or marker['chr'] == "X/Y":
if marker['chr'] > highest_chr or marker['chr'] == "X" or marker['chr'] == "X/Y":
highest_chr = marker['chr']
- if ('lod_score' in marker.keys()) or ('lrs_value' in marker.keys()):
+ if ('lod_score' in list(marker.keys())) or ('lrs_value' in list(marker.keys())):
self.qtl_results.append(marker)
with Bench("Exporting Results"):
@@ -538,28 +538,28 @@ def export_mapping_results(dataset, trait, markers, results_path, mapping_scale,
output_file.write("Mb," + score_type)
else:
output_file.write("Cm," + score_type)
- if "additive" in markers[0].keys():
+ if "additive" in list(markers[0].keys()):
output_file.write(",Additive")
- if "dominance" in markers[0].keys():
+ if "dominance" in list(markers[0].keys()):
output_file.write(",Dominance")
output_file.write("\n")
for i, marker in enumerate(markers):
output_file.write(marker['name'] + "," + str(marker['chr']) + "," + str(marker['Mb']) + ",")
- if "lod_score" in marker.keys():
+ if "lod_score" in list(marker.keys()):
output_file.write(str(marker['lod_score']))
else:
output_file.write(str(marker['lrs_value']))
- if "additive" in marker.keys():
+ if "additive" in list(marker.keys()):
output_file.write("," + str(marker['additive']))
- if "dominance" in marker.keys():
+ if "dominance" in list(marker.keys()):
output_file.write("," + str(marker['dominance']))
if i < (len(markers) - 1):
output_file.write("\n")
def trim_markers_for_figure(markers):
- if 'p_wald' in markers[0].keys():
+ if 'p_wald' in list(markers[0].keys()):
score_type = 'p_wald'
- elif 'lod_score' in markers[0].keys():
+ elif 'lod_score' in list(markers[0].keys()):
score_type = 'lod_score'
else:
score_type = 'lrs_value'
@@ -617,7 +617,7 @@ def trim_markers_for_figure(markers):
return filtered_markers
def trim_markers_for_table(markers):
- if 'lod_score' in markers[0].keys():
+ if 'lod_score' in list(markers[0].keys()):
sorted_markers = sorted(markers, key=lambda k: k['lod_score'], reverse=True)
else:
sorted_markers = sorted(markers, key=lambda k: k['lrs_value'], reverse=True)
@@ -695,10 +695,10 @@ def get_genofile_samplelist(dataset):
def get_perm_strata(this_trait, sample_list, categorical_vars, used_samples):
perm_strata_strings = []
for sample in used_samples:
- if sample in sample_list.sample_attribute_values.keys():
+ if sample in list(sample_list.sample_attribute_values.keys()):
combined_string = ""
for var in categorical_vars:
- if var in sample_list.sample_attribute_values[sample].keys():
+ if var in list(sample_list.sample_attribute_values[sample].keys()):
combined_string += str(sample_list.sample_attribute_values[sample][var])
else:
combined_string += "NA"
@@ -707,7 +707,7 @@ def get_perm_strata(this_trait, sample_list, categorical_vars, used_samples):
perm_strata_strings.append(combined_string)
- d = dict([(y,x+1) for x,y in enumerate(sorted(set(perm_strata_strings)))])
+ d = dict([(y, x+1) for x, y in enumerate(sorted(set(perm_strata_strings)))])
list_to_numbers = [d[x] for x in perm_strata_strings]
perm_strata = list_to_numbers
diff --git a/wqflask/wqflask/network_graph/network_graph.py b/wqflask/wqflask/network_graph/network_graph.py
index f61c40b4..7916651f 100644
--- a/wqflask/wqflask/network_graph/network_graph.py
+++ b/wqflask/wqflask/network_graph/network_graph.py
@@ -23,7 +23,7 @@ from __future__ import absolute_import, print_function, division
import sys
import string
-import cPickle
+import pickle
import os
import time
import pp
@@ -202,8 +202,8 @@ class NetworkGraph(object):
self.js_data = dict(traits = [trait.name for trait in self.traits],
groups = groups,
- cols = range(len(self.traits)),
- rows = range(len(self.traits)),
+ cols = list(range(len(self.traits))),
+ rows = list(range(len(self.traits))),
samples = self.all_sample_list,
sample_data = self.sample_data,
elements = self.elements,)
diff --git a/wqflask/wqflask/news.py b/wqflask/wqflask/news.py
index 8bc6b889..20319756 100644
--- a/wqflask/wqflask/news.py
+++ b/wqflask/wqflask/news.py
@@ -1,7 +1,4 @@
from __future__ import absolute_import, print_function, division
-import sys
-reload(sys)
-sys.setdefaultencoding('utf8')
from flask import g
class News(object):
diff --git a/wqflask/wqflask/pbkdf2.py b/wqflask/wqflask/pbkdf2.py
index f7f61a09..917b9d31 100644
--- a/wqflask/wqflask/pbkdf2.py
+++ b/wqflask/wqflask/pbkdf2.py
@@ -44,7 +44,7 @@ import hmac
import hashlib
from struct import Struct
from operator import xor
-from itertools import izip, starmap
+from itertools import starmap
_pack_int = Struct('>I').pack
@@ -66,13 +66,13 @@ def pbkdf2_bin(data, salt, iterations=1000, keylen=24, hashfunc=None):
def _pseudorandom(x, mac=mac):
h = mac.copy()
h.update(x)
- return map(ord, h.digest())
+ return list(map(ord, h.digest()))
buf = []
- for block in xrange(1, -(-keylen // mac.digest_size) + 1):
+ for block in range(1, -(-keylen // mac.digest_size) + 1):
rv = u = _pseudorandom(salt + _pack_int(block))
- for i in xrange(iterations - 1):
+ for i in range(iterations - 1):
u = _pseudorandom(''.join(map(chr, u)))
- rv = list(starmap(xor, izip(rv, u)))
+ rv = list(starmap(xor, zip(rv, u)))
buf.extend(rv)
return ''.join(map(chr, buf))[:keylen]
@@ -81,7 +81,7 @@ def safe_str_cmp(a, b):
if len(a) != len(b):
return False
rv = 0
- for x, y in izip(a, b):
+ for x, y in zip(a, b):
rv |= ord(x) ^ ord(y)
return rv == 0
@@ -92,14 +92,14 @@ def test():
def check(data, salt, iterations, keylen, expected):
rv = pbkdf2_hex(data, salt, iterations, keylen)
if rv != expected:
- print 'Test failed:'
- print ' Expected: %s' % expected
- print ' Got: %s' % rv
- print ' Parameters:'
- print ' data=%s' % data
- print ' salt=%s' % salt
- print ' iterations=%d' % iterations
- print
+ print('Test failed:')
+ print((' Expected: %s' % expected))
+ print((' Got: %s' % rv))
+ print(' Parameters:')
+ print((' data=%s' % data))
+ print((' salt=%s' % salt))
+ print((' iterations=%d' % iterations))
+ print()
failed.append(1)
# From RFC 6070
diff --git a/wqflask/wqflask/resource_manager.py b/wqflask/wqflask/resource_manager.py
index 39a07310..6b3e00fb 100644
--- a/wqflask/wqflask/resource_manager.py
+++ b/wqflask/wqflask/resource_manager.py
@@ -125,7 +125,7 @@ def add_group_to_resource():
def get_group_names(group_masks):
group_masks_with_names = {}
- for group_id, group_mask in group_masks.iteritems():
+ for group_id, group_mask in list(group_masks.items()):
this_mask = group_mask
group_name = get_group_info(group_id)['name']
this_mask['name'] = group_name
diff --git a/wqflask/wqflask/search_results.py b/wqflask/wqflask/search_results.py
index de4b01eb..c07a7670 100644
--- a/wqflask/wqflask/search_results.py
+++ b/wqflask/wqflask/search_results.py
@@ -53,7 +53,7 @@ views.py).
search = self.search_terms
self.original_search_string = self.search_terms
# check for dodgy search terms
- rx = re.compile(r'.*\W(href|http|sql|select|update)\W.*',re.IGNORECASE)
+ rx = re.compile(r'.*\W(href|http|sql|select|update)\W.*', re.IGNORECASE)
if rx.match(search):
logger.info("Regex failed search")
self.search_term_exists = False
@@ -266,7 +266,7 @@ def get_GO_symbols(a_search):
def insert_newlines(string, every=64):
""" This is because it is seemingly impossible to change the width of the description column, so I'm just manually adding line breaks """
lines = []
- for i in xrange(0, len(string), every):
+ for i in range(0, len(string), every):
lines.append(string[i:i+every])
return '\n'.join(lines)
diff --git a/wqflask/wqflask/show_trait/SampleList.py b/wqflask/wqflask/show_trait/SampleList.py
index ad78ebcc..f17e825e 100644
--- a/wqflask/wqflask/show_trait/SampleList.py
+++ b/wqflask/wqflask/show_trait/SampleList.py
@@ -43,7 +43,7 @@ class SampleList(object):
for counter, sample_name in enumerate(sample_names, 1):
sample_name = sample_name.replace("_2nd_", "")
- if type(self.this_trait) is list: #ZS: self.this_trait will be a list if it is a Temp trait
+ if isinstance(self.this_trait, list): #ZS: self.this_trait will be a list if it is a Temp trait
if counter <= len(self.this_trait) and str(self.this_trait[counter-1]).upper() != 'X':
sample = webqtlCaseData.webqtlCaseData(name=sample_name, value=float(self.this_trait[counter-1]))
else:
@@ -57,7 +57,7 @@ class SampleList(object):
sample = webqtlCaseData.webqtlCaseData(name=sample_name)
sample.extra_info = {}
- if self.dataset.group.name == 'AXBXA' and sample_name in ('AXB18/19/20','AXB13/14','BXA8/17'):
+ if self.dataset.group.name == 'AXBXA' and sample_name in ('AXB18/19/20', 'AXB13/14', 'BXA8/17'):
sample.extra_info['url'] = "/mouseCross.html#AXB/BXA"
sample.extra_info['css_class'] = "fs12"
diff --git a/wqflask/wqflask/show_trait/export_trait_data.py b/wqflask/wqflask/show_trait/export_trait_data.py
index 253c887b..68c3ad7d 100644
--- a/wqflask/wqflask/show_trait/export_trait_data.py
+++ b/wqflask/wqflask/show_trait/export_trait_data.py
@@ -47,7 +47,7 @@ def get_export_metadata(trait_id, dataset_name):
def dict_to_sorted_list(dictionary):
- sorted_list = [item for item in dictionary.iteritems()]
+ sorted_list = [item for item in list(dictionary.items())]
sorted_list = sorted(sorted_list, cmp=cmp_samples)
sorted_values = [item[1] for item in sorted_list]
return sorted_values
diff --git a/wqflask/wqflask/show_trait/show_trait.py b/wqflask/wqflask/show_trait/show_trait.py
index f188fd9d..738aa28a 100644
--- a/wqflask/wqflask/show_trait/show_trait.py
+++ b/wqflask/wqflask/show_trait/show_trait.py
@@ -3,7 +3,7 @@ from __future__ import absolute_import, print_function, division
import string
import os
import datetime
-import cPickle
+import pickle
import uuid
import requests
import json as json
@@ -261,7 +261,7 @@ class ShowTrait(object):
hddn['export_data'] = ""
hddn['export_format'] = "excel"
if len(self.scales_in_geno) < 2:
- hddn['mapping_scale'] = self.scales_in_geno[self.scales_in_geno.keys()[0]][0][0]
+ hddn['mapping_scale'] = self.scales_in_geno[list(self.scales_in_geno.keys())[0]][0][0]
# We'll need access to this_trait and hddn in the Jinja2 Template, so we put it inside self
self.hddn = hddn
@@ -405,7 +405,7 @@ class ShowTrait(object):
if not self.temp_trait:
other_sample_names = []
- for sample in self.this_trait.data.keys():
+ for sample in list(self.this_trait.data.keys()):
if (self.this_trait.data[sample].name2 in primary_sample_names) and (self.this_trait.data[sample].name not in primary_sample_names):
primary_sample_names.append(self.this_trait.data[sample].name)
primary_sample_names.remove(self.this_trait.data[sample].name2)
@@ -558,7 +558,7 @@ def get_table_widths(sample_groups, has_num_cases=False):
def has_num_cases(this_trait):
has_n = False
if this_trait.dataset.type != "ProbeSet" and this_trait.dataset.type != "Geno":
- for name, sample in this_trait.data.iteritems():
+ for name, sample in list(this_trait.data.items()):
if sample.num_cases:
has_n = True
break
@@ -611,7 +611,7 @@ def get_categorical_variables(this_trait, sample_list):
if len(sample_list.attributes) > 0:
for attribute in sample_list.attributes:
attribute_vals = []
- for sample_name in this_trait.data.keys():
+ for sample_name in list(this_trait.data.keys()):
if sample_list.attributes[attribute].name in this_trait.data[sample_name].extra_attributes:
attribute_vals.append(this_trait.data[sample_name].extra_attributes[sample_list.attributes[attribute].name])
else:
@@ -625,7 +625,7 @@ def get_categorical_variables(this_trait, sample_list):
def get_genotype_scales(genofiles):
geno_scales = {}
- if type(genofiles) is list:
+ if isinstance(genofiles, list):
for the_file in genofiles:
file_location = the_file['location']
geno_scales[file_location] = get_scales_from_genofile(file_location)
diff --git a/wqflask/wqflask/snp_browser/snp_browser.py b/wqflask/wqflask/snp_browser/snp_browser.py
index 1d28d76a..b18bfc62 100644
--- a/wqflask/wqflask/snp_browser/snp_browser.py
+++ b/wqflask/wqflask/snp_browser/snp_browser.py
@@ -459,7 +459,7 @@ class SnpBrowser(object):
function_list = []
if function_details:
function_list = string.split(string.strip(function_details), ",")
- function_list = map(string.strip, function_list)
+ function_list = list(map(string.strip, function_list))
function_list[0] = function_list[0].title()
function_details = ", ".join(item for item in function_list)
function_details = function_details.replace("_", " ")
@@ -725,11 +725,11 @@ def get_effect_details_by_category(effect_name = None, effect_value = None):
codon_effect_group_list = ['Start Lost', 'Stop Gained', 'Stop Lost', 'Nonsynonymous', 'Synonymous']
effect_detail_list = string.split(string.strip(effect_value), '|')
- effect_detail_list = map(string.strip, effect_detail_list)
+ effect_detail_list = list(map(string.strip, effect_detail_list))
for index, item in enumerate(effect_detail_list):
item_list = string.split(string.strip(item), ',')
- item_list = map(string.strip, item_list)
+ item_list = list(map(string.strip, item_list))
gene_id = item_list[0]
gene_name = item_list[1]
diff --git a/wqflask/wqflask/user_login.py b/wqflask/wqflask/user_login.py
index cfee0079..04672b45 100644
--- a/wqflask/wqflask/user_login.py
+++ b/wqflask/wqflask/user_login.py
@@ -193,7 +193,7 @@ def login():
if user_details:
submitted_password = params['password']
pwfields = user_details['password']
- if type(pwfields) is str:
+ if isinstance(pwfields, str):
pwfields = json.loads(pwfields)
encrypted_pass_fields = encode_password(pwfields, submitted_password)
password_match = pbkdf2.safe_str_cmp(encrypted_pass_fields['password'], pwfields['password'])
diff --git a/wqflask/wqflask/user_manager.py b/wqflask/wqflask/user_manager.py
index a871e91a..56d1c084 100644
--- a/wqflask/wqflask/user_manager.py
+++ b/wqflask/wqflask/user_manager.py
@@ -9,7 +9,7 @@ import uuid
import hashlib
import hmac
import base64
-import urlparse
+import urllib.parse
import simplejson as json
@@ -867,7 +867,7 @@ def forgot_password_submit():
email_address = params['email_address']
next_page = None
if email_address != "":
- logger.debug("Wants to send password E-mail to ",email_address)
+ logger.debug("Wants to send password E-mail to ", email_address)
user_details = get_user_by_unique_column("email_address", email_address)
if user_details:
ForgotPasswordEmail(user_details["email_address"])
diff --git a/wqflask/wqflask/views.py b/wqflask/wqflask/views.py
index dde22bf7..83d5202e 100644
--- a/wqflask/wqflask/views.py
+++ b/wqflask/wqflask/views.py
@@ -14,13 +14,13 @@ import csv
import simplejson as json
import yaml
import xlsxwriter
-import StringIO # Todo: Use cStringIO?
+import io # Todo: Use cStringIO?
from zipfile import ZipFile, ZIP_DEFLATED
import gc
import numpy as np
-import cPickle as pickle
+import pickle as pickle
import uuid
import flask
@@ -55,7 +55,7 @@ from wqflask.ctl import ctl_analysis
from wqflask.snp_browser import snp_browser
from utility import temp_data
-from utility.tools import SQL_URI,TEMPDIR,USE_REDIS,USE_GN_SERVER,GN_SERVER_URL,GN_VERSION,JS_TWITTER_POST_FETCHER_PATH,JS_GUIX_PATH, CSS_PATH
+from utility.tools import SQL_URI, TEMPDIR, USE_REDIS, USE_GN_SERVER, GN_SERVER_URL, GN_VERSION, JS_TWITTER_POST_FETCHER_PATH, JS_GUIX_PATH, CSS_PATH
from utility.helper_functions import get_species_groups
from utility.authentication_tools import check_resource_availability
from utility.redis_tools import get_redis_conn
@@ -133,10 +133,10 @@ def handle_bad_request(e):
list = [fn for fn in os.listdir("./wqflask/static/gif/error") if fn.endswith(".gif") ]
animation = random.choice(list)
- resp = make_response(render_template("error.html",message=err_msg,stack=formatted_lines,error_image=animation,version=GN_VERSION))
+ resp = make_response(render_template("error.html", message=err_msg, stack=formatted_lines, error_image=animation, version=GN_VERSION))
# logger.error("Set cookie %s with %s" % (err_msg, animation))
- resp.set_cookie(err_msg[:32],animation)
+ resp.set_cookie(err_msg[:32], animation)
return resp
@app.route("/authentication_needed")
@@ -257,7 +257,7 @@ def docedit():
@app.route('/generated/<filename>')
def generated_file(filename):
logger.info(request.url)
- return send_from_directory(GENERATED_IMAGE_DIR,filename)
+ return send_from_directory(GENERATED_IMAGE_DIR, filename)
@app.route("/help")
def help():
@@ -373,7 +373,7 @@ def export_trait_excel():
logger.info("sample_data - type: %s -- size: %s" % (type(sample_data), len(sample_data)))
- buff = StringIO.StringIO()
+ buff = io.StringIO()
workbook = xlsxwriter.Workbook(buff, {'in_memory': True})
worksheet = workbook.add_worksheet()
for i, row in enumerate(sample_data):
@@ -397,7 +397,7 @@ def export_trait_csv():
logger.info("sample_data - type: %s -- size: %s" % (type(sample_data), len(sample_data)))
- buff = StringIO.StringIO()
+ buff = io.StringIO()
writer = csv.writer(buff)
for row in sample_data:
writer.writerow(row)
@@ -417,7 +417,7 @@ def export_traits_csv():
file_list = export_traits.export_search_results_csv(request.form)
if len(file_list) > 1:
- memory_file = StringIO.StringIO()
+ memory_file = io.StringIO()
with ZipFile(memory_file, mode='w', compression=ZIP_DEFLATED) as zf:
for the_file in file_list:
zf.writestr(the_file[0], the_file[1])
@@ -460,7 +460,7 @@ def export_perm_data():
["#Comment: Results sorted from low to high peak linkage"]
]
- buff = StringIO.StringIO()
+ buff = io.StringIO()
writer = csv.writer(buff)
writer.writerows(the_rows)
for item in perm_info['perm_data']:
@@ -533,7 +533,7 @@ def heatmap_page():
result = template_vars.__dict__
- for item in template_vars.__dict__.keys():
+ for item in list(template_vars.__dict__.keys()):
logger.info(" ---**--- {}: {}".format(type(template_vars.__dict__[item]), item))
pickled_result = pickle.dumps(result, pickle.HIGHEST_PROTOCOL)
@@ -637,7 +637,7 @@ def loading_page():
if 'wanted_inputs' in initial_start_vars:
wanted = initial_start_vars['wanted_inputs'].split(",")
start_vars = {}
- for key, value in initial_start_vars.iteritems():
+ for key, value in list(initial_start_vars.items()):
if key in wanted or key.startswith(('value:')):
start_vars[key] = value
@@ -737,7 +737,7 @@ def mapping_results_page():
'transform'
)
start_vars = {}
- for key, value in initial_start_vars.iteritems():
+ for key, value in list(initial_start_vars.items()):
if key in wanted or key.startswith(('value:')):
start_vars[key] = value
#logger.debug("Mapping called with start_vars:", start_vars)
@@ -943,5 +943,5 @@ def json_default_handler(obj):
# logger.info("Not going to serialize Dataset")
# return None
else:
- raise TypeError, 'Object of type %s with value of %s is not JSON serializable' % (
- type(obj), repr(obj))
+ raise TypeError('Object of type %s with value of %s is not JSON serializable' % (
+ type(obj), repr(obj)))
diff --git a/wqflask/wqflask/wgcna/wgcna_analysis.py b/wqflask/wqflask/wgcna/wgcna_analysis.py
index 880a1cb2..d79ad6df 100644
--- a/wqflask/wqflask/wgcna/wgcna_analysis.py
+++ b/wqflask/wqflask/wgcna/wgcna_analysis.py
@@ -60,7 +60,7 @@ class WGCNA(object):
print("Starting WGCNA analysis on dataset")
self.r_enableWGCNAThreads() # Enable multi threading
self.trait_db_list = [trait.strip() for trait in requestform['trait_list'].split(',')]
- print("Retrieved phenotype data from database", requestform['trait_list'])
+ print(("Retrieved phenotype data from database", requestform['trait_list']))
helper_functions.get_trait_db_obs(self, self.trait_db_list)
self.input = {} # self.input contains the phenotype values we need to send to R
@@ -101,13 +101,13 @@ class WGCNA(object):
if requestform.get('SoftThresholds') is not None:
powers = [int(threshold.strip()) for threshold in requestform['SoftThresholds'].rstrip().split(",")]
rpow = r_unlist(r_c(powers))
- print "SoftThresholds: {} == {}".format(powers, rpow)
+ print(("SoftThresholds: {} == {}".format(powers, rpow)))
self.sft = self.r_pickSoftThreshold(rM, powerVector = rpow, verbose = 5)
- print "PowerEstimate: {}".format(self.sft[0])
+ print(("PowerEstimate: {}".format(self.sft[0])))
self.results['PowerEstimate'] = self.sft[0]
if self.sft[0][0] is ri.NA_Integer:
- print "No power is suitable for the analysis, just use 1"
+ print("No power is suitable for the analysis, just use 1")
self.results['Power'] = 1 # No power could be estimated
else:
self.results['Power'] = self.sft[0][0] # Use the estimated power
@@ -122,7 +122,7 @@ class WGCNA(object):
self.results['network'] = network
# How many modules and how many gene per module ?
- print "WGCNA found {} modules".format(r_table(network[1]))
+ print(("WGCNA found {} modules".format(r_table(network[1]))))
self.results['nmod'] = r_length(r_table(network[1]))[0]
# The iconic WCGNA plot of the modules in the hanging tree
@@ -135,7 +135,7 @@ class WGCNA(object):
sys.stdout.flush()
def render_image(self, results):
- print("pre-loading imgage results:", self.results['imgloc'])
+ print(("pre-loading imgage results:", self.results['imgloc']))
imgfile = open(self.results['imgloc'], 'rb')
imgdata = imgfile.read()
imgB64 = imgdata.encode("base64")