diff options
author | BonfaceKilz | 2021-04-30 13:05:21 +0300 |
---|---|---|
committer | BonfaceKilz | 2021-04-30 13:45:15 +0300 |
commit | 114e7d3395f28ddead0ff3a94c10d0bf534fb493 (patch) | |
tree | 39e2f8132a55b2a1a080a548e5bb463a3ac13f77 /wqflask/utility | |
parent | 90ec57905c8afdbd5e9e8c44dcc369bd0e9c2d1b (diff) | |
download | genenetwork2-114e7d3395f28ddead0ff3a94c10d0bf534fb493.tar.gz |
autopep8: Fix E101, E11
Diffstat (limited to 'wqflask/utility')
-rw-r--r-- | wqflask/utility/Plot.py | 98 | ||||
-rw-r--r-- | wqflask/utility/__init__.py | 2 | ||||
-rw-r--r-- | wqflask/utility/genofile_parser.py | 150 | ||||
-rw-r--r-- | wqflask/utility/tools.py | 2 |
4 files changed, 126 insertions, 126 deletions
diff --git a/wqflask/utility/Plot.py b/wqflask/utility/Plot.py index 00658d10..f61e3b88 100644 --- a/wqflask/utility/Plot.py +++ b/wqflask/utility/Plot.py @@ -79,7 +79,7 @@ def frange(start, end=None, inc=1.0): start += 0.0 # force it to be a float count = int((end - start) / inc) if start + count * inc != end: - # Need to adjust the count. AFAICT, it always comes up one short. + # Need to adjust the count. AFAICT, it always comes up one short. count += 1 L = [start] * count for i in range(1, count): @@ -131,16 +131,16 @@ def plotBar(canvas, data, barColor=BLUE, axesColor=BLACK, labelColor=BLACK, XLab plotWidth = canvas.size[0] - xLeftOffset - xRightOffset plotHeight = canvas.size[1] - yTopOffset - yBottomOffset if plotHeight <= 0 or plotWidth <= 0: - return + return if len(data) < 2: - return + return max_D = max(data) min_D = min(data) # add by NL 06-20-2011: fix the error: when max_D is infinite, log function in detScale will go wrong if max_D == float('inf') or max_D > webqtlConfig.MAXLRS: - max_D = webqtlConfig.MAXLRS # maximum LRS value + max_D = webqtlConfig.MAXLRS # maximum LRS value xLow, xTop, stepX = detScale(min_D, max_D) @@ -151,15 +151,15 @@ def plotBar(canvas, data, barColor=BLUE, axesColor=BLACK, labelColor=BLACK, XLab dataXY = [] Count = [] while j <= xTop: - dataXY.append(j) - Count.append(0) - j += step + dataXY.append(j) + Count.append(0) + j += step for i, item in enumerate(data): - if item == float('inf') or item > webqtlConfig.MAXLRS: - item = webqtlConfig.MAXLRS # maximum LRS value - j = int((item - xLow) / step) - Count[j] += 1 + if item == float('inf') or item > webqtlConfig.MAXLRS: + item = webqtlConfig.MAXLRS # maximum LRS value + j = int((item - xLow) / step) + Count[j] += 1 yLow, yTop, stepY = detScale(0, max(Count)) @@ -169,12 +169,12 @@ def plotBar(canvas, data, barColor=BLUE, axesColor=BLACK, labelColor=BLACK, XLab barWidth = xScale * step for i, count in enumerate(Count): - if count: - xc = (dataXY[i] - xLow) * xScale + xLeftOffset - yc = -(count - yLow) * yScale + yTopOffset + plotHeight - im_drawer.rectangle( - xy=((xc + 2, yc), (xc + barWidth - 2, yTopOffset + plotHeight)), - outline=barColor, fill=barColor) + if count: + xc = (dataXY[i] - xLow) * xScale + xLeftOffset + yc = -(count - yLow) * yScale + yTopOffset + plotHeight + im_drawer.rectangle( + xy=((xc + 2, yc), (xc + barWidth - 2, yTopOffset + plotHeight)), + outline=barColor, fill=barColor) # draw drawing region im_drawer.rectangle( @@ -186,39 +186,39 @@ def plotBar(canvas, data, barColor=BLUE, axesColor=BLACK, labelColor=BLACK, XLab 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)), - 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) - x += (xTop - xLow) / stepX + xc = xLeftOffset + (x - xLow) * xScale + im_drawer.line( + 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) + 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) - strY = "%d" % y - im_drawer.text( - text=strY, - xy=(xLeftOffset - im_drawer.textsize(strY, - font=scaleFont)[0] - 6, yc + 5), - font=scaleFont) - y += (yTop - yLow) / stepY + yc = yTopOffset + plotHeight - (y - yLow) * yScale + 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), + font=scaleFont) + y += (yTop - yLow) / stepY # draw label 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, - yTopOffset + plotHeight + yBottomOffset-10), - font=labelFont, fill=labelColor) + im_drawer.text( + text=XLabel, + xy=(xLeftOffset + ( + plotWidth - im_drawer.textsize(XLabel, font=labelFont)[0]) / 2.0, + yTopOffset + plotHeight + yBottomOffset-10), + font=labelFont, fill=labelColor) if YLabel: draw_rotated_text(canvas, text=YLabel, @@ -230,12 +230,12 @@ def plotBar(canvas, data, barColor=BLUE, axesColor=BLACK, labelColor=BLACK, XLab 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, - 20), - font=labelFont, fill=labelColor) + im_drawer.text( + text=title, + xy=(xLeftOffset + (plotWidth - im_drawer.textsize( + title, font=labelFont)[0]) / 2.0, + 20), + font=labelFont, fill=labelColor) # This function determines the scale of the plot diff --git a/wqflask/utility/__init__.py b/wqflask/utility/__init__.py index 816bc4df..6c8cd546 100644 --- a/wqflask/utility/__init__.py +++ b/wqflask/utility/__init__.py @@ -7,7 +7,7 @@ class Bunch: """Like a dictionary but using object notation""" def __init__(self, **kw): - self.__dict__ = kw + self.__dict__ = kw def __repr__(self): return pf(self.__dict__) diff --git a/wqflask/utility/genofile_parser.py b/wqflask/utility/genofile_parser.py index c0629b5d..eb545478 100644 --- a/wqflask/utility/genofile_parser.py +++ b/wqflask/utility/genofile_parser.py @@ -14,87 +14,87 @@ from pprint import pformat as pf class Marker: - def __init__(self): - self.name = None - self.chr = None - self.cM = None - self.Mb = None - self.genotypes = [] + def __init__(self): + self.name = None + self.chr = None + self.cM = None + self.Mb = None + self.genotypes = [] class ConvertGenoFile: - def __init__(self, input_file): - self.mb_exists = False - self.cm_exists = False - self.markers = [] + def __init__(self, input_file): + self.mb_exists = False + self.cm_exists = False + self.markers = [] - self.latest_row_pos = None - self.latest_col_pos = None + self.latest_row_pos = None + self.latest_col_pos = None - self.latest_row_value = None - self.latest_col_value = None - self.input_fh = open(input_file) - print("!!!!!!!!!!!!!!!!PARSER!!!!!!!!!!!!!!!!!!") - self.haplotype_notation = { - '@mat': "1", - '@pat': "2", - '@het': "-999", - '@unk': "-999" - } - self.configurations = {} + self.latest_row_value = None + self.latest_col_value = None + self.input_fh = open(input_file) + print("!!!!!!!!!!!!!!!!PARSER!!!!!!!!!!!!!!!!!!") + self.haplotype_notation = { + '@mat': "1", + '@pat': "2", + '@het': "-999", + '@unk': "-999" + } + self.configurations = {} - def process_rows(self): - for self.latest_row_pos, row in enumerate(self.input_fh): - self.latest_row_value = row - # Take care of headers - if not row.strip(): - continue - if row.startswith('#'): - continue - if row.startswith('Chr'): - if 'Mb' in row.split(): - self.mb_exists = True - if 'cM' in row.split(): - self.cm_exists = True - skip = 2 + self.cm_exists + self.mb_exists - self.individuals = row.split()[skip:] - continue - if row.startswith('@'): - key, _separater, value = row.partition(':') - key = key.strip() - value = value.strip() - if key in self.haplotype_notation: - self.configurations[value] = self.haplotype_notation[key] - continue - if not len(self.configurations): - raise EmptyConfigurations - yield row + def process_rows(self): + for self.latest_row_pos, row in enumerate(self.input_fh): + self.latest_row_value = row + # Take care of headers + if not row.strip(): + continue + if row.startswith('#'): + continue + if row.startswith('Chr'): + if 'Mb' in row.split(): + self.mb_exists = True + if 'cM' in row.split(): + self.cm_exists = True + skip = 2 + self.cm_exists + self.mb_exists + self.individuals = row.split()[skip:] + continue + if row.startswith('@'): + key, _separater, value = row.partition(':') + key = key.strip() + value = value.strip() + if key in self.haplotype_notation: + self.configurations[value] = self.haplotype_notation[key] + continue + if not len(self.configurations): + raise EmptyConfigurations + yield row - def process_csv(self): - for row in self.process_rows(): - row_items = row.split("\t") + def process_csv(self): + for row in self.process_rows(): + row_items = row.split("\t") - this_marker = Marker() - this_marker.name = row_items[1] - this_marker.chr = row_items[0] - if self.cm_exists and self.mb_exists: - this_marker.cM = row_items[2] - this_marker.Mb = row_items[3] - genotypes = row_items[4:] - elif self.cm_exists: - this_marker.cM = row_items[2] - genotypes = row_items[3:] - elif self.mb_exists: - this_marker.Mb = row_items[2] - genotypes = row_items[3:] - else: - genotypes = row_items[2:] - for item_count, genotype in enumerate(genotypes): - if genotype.upper().strip() in self.configurations: - this_marker.genotypes.append( - self.configurations[genotype.upper().strip()]) - else: - print("WARNING:", genotype.upper()) - this_marker.genotypes.append("NA") - self.markers.append(this_marker.__dict__) + this_marker = Marker() + this_marker.name = row_items[1] + this_marker.chr = row_items[0] + if self.cm_exists and self.mb_exists: + this_marker.cM = row_items[2] + this_marker.Mb = row_items[3] + genotypes = row_items[4:] + elif self.cm_exists: + this_marker.cM = row_items[2] + genotypes = row_items[3:] + elif self.mb_exists: + this_marker.Mb = row_items[2] + genotypes = row_items[3:] + else: + genotypes = row_items[2:] + for item_count, genotype in enumerate(genotypes): + if genotype.upper().strip() in self.configurations: + this_marker.genotypes.append( + self.configurations[genotype.upper().strip()]) + else: + print("WARNING:", genotype.upper()) + this_marker.genotypes.append("NA") + self.markers.append(this_marker.__dict__) diff --git a/wqflask/utility/tools.py b/wqflask/utility/tools.py index d82e478d..4f09176a 100644 --- a/wqflask/utility/tools.py +++ b/wqflask/utility/tools.py @@ -73,7 +73,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]: - return True + return True return False |