aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gn3/api/heatmaps.py8
-rw-r--r--gn3/app.py5
-rw-r--r--gn3/computations/qtlreaper.py8
-rw-r--r--gn3/db/genotypes.py1
-rw-r--r--gn3/db/traits.py2
-rw-r--r--gn3/heatmaps.py28
6 files changed, 37 insertions, 15 deletions
diff --git a/gn3/api/heatmaps.py b/gn3/api/heatmaps.py
index 1022a35..fe47aee 100644
--- a/gn3/api/heatmaps.py
+++ b/gn3/api/heatmaps.py
@@ -1,3 +1,7 @@
+"""
+Module to hold the entrypoint functions that generate heatmaps
+"""
+
import io
from flask import jsonify
from flask import request
@@ -9,6 +13,10 @@ heatmaps = Blueprint("heatmaps", __name__)
@heatmaps.route("/clustered", methods=("POST",))
def clustered_heatmaps():
+ """
+ Parses the incoming data and responds with the JSON-serialized plotly figure
+ representing the clustered heatmap.
+ """
heatmap_request = request.get_json()
traits_names = heatmap_request.get("traits_names", tuple())
if len(traits_names) < 2:
diff --git a/gn3/app.py b/gn3/app.py
index 6b4c57e..8badb65 100644
--- a/gn3/app.py
+++ b/gn3/app.py
@@ -3,7 +3,10 @@ import os
from typing import Dict
from typing import Union
+
from flask import Flask
+from flask_cors import CORS
+
from gn3.api.gemma import gemma
from gn3.api.rqtl import rqtl
from gn3.api.general import general
@@ -11,8 +14,6 @@ from gn3.api.heatmaps import heatmaps
from gn3.api.correlation import correlation
from gn3.api.data_entry import data_entry
-from flask_cors import CORS
-
def create_app(config: Union[Dict, str, None] = None) -> Flask:
"""Create a new flask object"""
app = Flask(__name__)
diff --git a/gn3/computations/qtlreaper.py b/gn3/computations/qtlreaper.py
index 377db9b..5d17fed 100644
--- a/gn3/computations/qtlreaper.py
+++ b/gn3/computations/qtlreaper.py
@@ -87,11 +87,17 @@ def run_reaper(
return (output_filename, permu_output_filename)
def chromosome_sorter_key_fn(val):
+ """
+ Useful for sorting the chromosomes
+ """
if isinstance(val, int):
return val
return ord(val)
def organise_reaper_main_results(parsed_results):
+ """
+ Provide the results of running reaper in a format that is easier to use.
+ """
def __organise_by_chromosome(chr_name, items):
chr_items = [item for item in items if item["Chr"] == chr_name]
return {
@@ -129,12 +135,14 @@ def parse_reaper_main_results(results_file):
lines = infile.readlines()
def __parse_column_float_value(value):
+ # pylint: disable=W0702
try:
return float(value)
except:
return value
def __parse_column_int_value(value):
+ # pylint: disable=W0702
try:
return int(value)
except:
diff --git a/gn3/db/genotypes.py b/gn3/db/genotypes.py
index 9d052d9..919c539 100644
--- a/gn3/db/genotypes.py
+++ b/gn3/db/genotypes.py
@@ -115,6 +115,7 @@ def parse_genotype_marker(line: str, geno_obj: dict, parlist: list):
Reworks
https://github.com/genenetwork/genenetwork1/blob/master/web/webqtl/utility/gen_geno_ob.py#L143-L190
"""
+ # pylint: disable=W0702
marker_row = [item.strip() for item in line.split("\t")]
geno_table = {
geno_obj["mat"]: -1, geno_obj["pat"]: 1, geno_obj["het"]: 0,
diff --git a/gn3/db/traits.py b/gn3/db/traits.py
index bfe887e..747ed27 100644
--- a/gn3/db/traits.py
+++ b/gn3/db/traits.py
@@ -46,7 +46,7 @@ def update_sample_data(conn: Any,
count: Union[int, str]):
"""Given the right parameters, update sample-data from the relevant
table."""
- # pylint: disable=[R0913, R0914]
+ # pylint: disable=[R0913, R0914, C0103]
STRAIN_ID_SQL: str = "UPDATE Strain SET Name = %s WHERE Id = %s"
PUBLISH_DATA_SQL: str = ("UPDATE PublishData SET value = %s "
"WHERE StrainId = %s AND Id = %s")
diff --git a/gn3/heatmaps.py b/gn3/heatmaps.py
index cd93b3f..9d82fb2 100644
--- a/gn3/heatmaps.py
+++ b/gn3/heatmaps.py
@@ -3,29 +3,28 @@ This module will contain functions to be used in computation of the data used to
generate various kinds of heatmaps.
"""
+from functools import reduce
from typing import Any, Dict, Sequence
+
import numpy as np
-from functools import reduce
-from gn3.settings import TMPDIR
import plotly.graph_objects as go
import plotly.figure_factory as ff
+from plotly.subplots import make_subplots
+
+from gn3.settings import TMPDIR
from gn3.random import random_string
from gn3.computations.slink import slink
-from plotly.subplots import make_subplots
from gn3.computations.correlations2 import compute_correlation
from gn3.db.genotypes import (
- build_genotype_file, load_genotype_samples, parse_genotype_file)
+ build_genotype_file, load_genotype_samples)
from gn3.db.traits import (
- retrieve_trait_data,
- retrieve_trait_info,
- generate_traits_filename)
+ retrieve_trait_data, retrieve_trait_info)
from gn3.computations.qtlreaper import (
run_reaper,
generate_traits_file,
chromosome_sorter_key_fn,
parse_reaper_main_results,
- organise_reaper_main_results,
- parse_reaper_permutation_results)
+ organise_reaper_main_results)
def export_trait_data(
trait_data: dict, strainlist: Sequence[str], dtype: str = "val",
@@ -159,13 +158,13 @@ def build_heatmap(traits_names, conn: Any):
PARAMETERS:
TODO: Elaborate on the parameters here...
"""
+ # pylint: disable=[R0914]
threshold = 0 # webqtlConfig.PUBLICTHRESH
traits = [
retrieve_trait_info(threshold, fullname, conn)
for fullname in traits_names]
traits_data_list = [retrieve_trait_data(t, conn) for t in traits]
genotype_filename = build_genotype_file(traits[0]["riset"])
- # genotype = parse_genotype_file(genotype_filename)
strains = load_genotype_samples(genotype_filename)
exported_traits_data_list = [
export_trait_data(td, strains) for td in traits_data_list]
@@ -336,6 +335,7 @@ def generate_clustered_heatmap(
Generate a dendrogram, and heatmaps for each chromosome, and put them all
into one plot.
"""
+ # pylint: disable=[R0913, R0914]
num_cols = 1 + len(x_axis)
fig = make_subplots(
rows=1,
@@ -359,14 +359,18 @@ def generate_clustered_heatmap(
"height": 800,
"xaxis": {
"mirror": False,
- "showgrid": True
+ "showgrid": True,
+ "title": x_label
+ },
+ "yaxis": {
+ "title": y_label
}
})
x_axes_layouts = {
"xaxis{}".format(i+1 if i > 0 else ""): {
"mirror": False,
- "showticklabels": True if i == 0 else False,
+ "showticklabels": i == 0,
"ticks": "outside" if i == 0 else ""
}
for i in range(num_cols)}