aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--wqflask/base/data_set.py62
-rw-r--r--wqflask/utility/startup_config.py4
-rw-r--r--wqflask/utility/tools.py8
-rw-r--r--wqflask/wqflask/api/gen_menu.py1
-rw-r--r--wqflask/wqflask/collect.py2
-rw-r--r--wqflask/wqflask/marker_regression/display_mapping_results.py3
-rw-r--r--wqflask/wqflask/marker_regression/rqtl_mapping.py29
-rw-r--r--wqflask/wqflask/marker_regression/run_mapping.py9
-rw-r--r--wqflask/wqflask/show_trait/SampleList.py84
-rw-r--r--wqflask/wqflask/show_trait/show_trait.py4
-rw-r--r--wqflask/wqflask/static/new/javascript/show_trait.js2
-rw-r--r--wqflask/wqflask/templates/mapping_results.html22
-rw-r--r--wqflask/wqflask/templates/search_result_page.html2
-rw-r--r--wqflask/wqflask/user_login.py41
-rw-r--r--wqflask/wqflask/user_session.py13
-rw-r--r--wqflask/wqflask/views.py20
16 files changed, 204 insertions, 102 deletions
diff --git a/wqflask/base/data_set.py b/wqflask/base/data_set.py
index ebf3f021..fae62875 100644
--- a/wqflask/base/data_set.py
+++ b/wqflask/base/data_set.py
@@ -67,7 +67,6 @@ DS_NAME_MAP = {}
def create_dataset(dataset_name, rebuild=True, dataset_type = None, get_samplelist = True, group_name = None):
if not dataset_type:
dataset_type = Dataset_Getter(dataset_name)
- logger.debug("dataset_type", dataset_type)
dataset_ob = DS_NAME_MAP[dataset_type]
dataset_class = globals()[dataset_ob]
@@ -96,7 +95,6 @@ Publish or ProbeSet. E.g.
self.datasets = {}
if rebuild: #ZS: May make this the only option
data = json.loads(requests.get("http://gn2.genenetwork.org/api/v_pre1/gen_dropdown").content)
- logger.debug("THE DATA:", data)
#data = gen_menu.gen_dropdown_json()
else:
file_name = "wqflask/static/new/javascript/dataset_menu_structure.json"
@@ -120,7 +118,65 @@ Publish or ProbeSet. E.g.
logger.debugf(5, "datasets",self.datasets)
def __call__(self, name):
- return self.datasets[name]
+ if name not in self.datasets:
+ mrna_expr_query = """
+ SELECT
+ ProbeSetFreeze.Id
+ FROM
+ ProbeSetFreeze
+ WHERE
+ ProbeSetFreeze.Name = "{0}"
+ """.format(name)
+
+ results = g.db.execute(geno_query).fetchall()
+ if len(results):
+ self.datasets[name] = "ProbeSet"
+ return self.datasets[name]
+
+ group_name = name.replace("Publish", "")
+
+ pheno_query = """SELECT InfoFiles.GN_AccesionId
+ FROM InfoFiles, PublishFreeze, InbredSet
+ WHERE InbredSet.Name = '{0}' AND
+ PublishFreeze.InbredSetId = InbredSet.Id AND
+ InfoFiles.InfoPageName = PublishFreeze.Name""".format(group_name)
+
+ results = g.db.execute(pheno_query).fetchall()
+ if len(results):
+ self.datasets[name] = "Publish"
+ return self.datasets[name]
+
+ #ZS: For when there isn't an InfoFiles ID; not sure if this and the preceding query are both necessary
+ other_pheno_query = """SELECT PublishFreeze.Name
+ FROM PublishFreeze, InbredSet
+ WHERE InbredSet.Name = '{}' AND
+ PublishFreeze.InbredSetId = InbredSet.Id""".format(group_name)
+
+ results = g.db.execute(other_pheno_query).fetchall()
+ if len(results):
+ self.datasets[name] = "Publish"
+ return self.datasets[name]
+
+ geno_query = """
+ SELECT
+ GenoFreezeId
+ FROM
+ GenoFreeze
+ WHERE
+ GenoFreeze.Name = "{0}"
+ {1}
+ """.format(name)
+
+ results = g.db.execute(geno_query).fetchall()
+ if len(results):
+ self.datasets[name] = "Geno"
+ return self.datasets[name]
+
+ #ZS: It shouldn't ever reach this
+ return None
+
+ else:
+ return self.datasets[name]
# Do the intensive work at startup one time only
Dataset_Getter = Dataset_Types()
diff --git a/wqflask/utility/startup_config.py b/wqflask/utility/startup_config.py
index 5a62cc50..817284dd 100644
--- a/wqflask/utility/startup_config.py
+++ b/wqflask/utility/startup_config.py
@@ -33,7 +33,7 @@ def app_config():
if page.status_code != 200:
raise Exception("API server not found!")
- import utility.elasticsearch_tools as es
- es.test_elasticsearch_connection()
+ # 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")))
diff --git a/wqflask/utility/tools.py b/wqflask/utility/tools.py
index 75bddb24..0fbedccb 100644
--- a/wqflask/utility/tools.py
+++ b/wqflask/utility/tools.py
@@ -267,10 +267,10 @@ if ORCID_CLIENT_ID != 'UNKNOWN' and ORCID_CLIENT_SECRET:
ORCID_CLIENT_ID+"&client_secret="+ORCID_CLIENT_SECRET
ORCID_TOKEN_URL = get_setting('ORCID_TOKEN_URL')
-ELASTICSEARCH_HOST = get_setting('ELASTICSEARCH_HOST')
-ELASTICSEARCH_PORT = get_setting('ELASTICSEARCH_PORT')
-import utility.elasticsearch_tools as es
-es.test_elasticsearch_connection()
+# ELASTICSEARCH_HOST = get_setting('ELASTICSEARCH_HOST')
+# ELASTICSEARCH_PORT = get_setting('ELASTICSEARCH_PORT')
+# import utility.elasticsearch_tools as es
+# es.test_elasticsearch_connection()
SMTP_CONNECT = get_setting('SMTP_CONNECT')
SMTP_USERNAME = get_setting('SMTP_USERNAME')
diff --git a/wqflask/wqflask/api/gen_menu.py b/wqflask/wqflask/api/gen_menu.py
index 7d2d243c..64a413c2 100644
--- a/wqflask/wqflask/api/gen_menu.py
+++ b/wqflask/wqflask/api/gen_menu.py
@@ -47,7 +47,6 @@ def get_species():
"""Build species list"""
results = g.db.execute("""SELECT Name, MenuName
FROM Species
- WHERE Species.Name != 'macaque monkey'
ORDER BY OrderId""").fetchall()
species = []
diff --git a/wqflask/wqflask/collect.py b/wqflask/wqflask/collect.py
index fa6e03b4..1d74b699 100644
--- a/wqflask/wqflask/collect.py
+++ b/wqflask/wqflask/collect.py
@@ -108,7 +108,7 @@ def collections_new():
if 'existing_collection' not in params:
collections = g.user_session.user_collections
for collection in collections:
- if collection["name"] == "Default Collection":
+ if collection["name"] == "Your Default Collection":
collection_id = collection["id"]
collection_name = collection["name"]
default_collection_exists = True
diff --git a/wqflask/wqflask/marker_regression/display_mapping_results.py b/wqflask/wqflask/marker_regression/display_mapping_results.py
index a7e11738..2a53b60e 100644
--- a/wqflask/wqflask/marker_regression/display_mapping_results.py
+++ b/wqflask/wqflask/marker_regression/display_mapping_results.py
@@ -166,6 +166,7 @@ class DisplayMappingResults(object):
#Needing for form submission when doing single chr mapping or remapping after changing options
self.samples = start_vars['samples']
self.vals = start_vars['vals']
+ self.transform = start_vars['transform']
self.mapping_method = start_vars['mapping_method']
self.mapping_results_path = start_vars['mapping_results_path']
if self.mapping_method == "rqtl_geno":
@@ -233,6 +234,8 @@ class DisplayMappingResults(object):
self.covariates = start_vars['covariates']
if 'maf' in start_vars.keys():
self.maf = start_vars['maf']
+ else:
+ self.maf = ""
if 'output_files' in start_vars.keys():
self.output_files = start_vars['output_files']
if 'use_loco' in start_vars.keys() and self.mapping_method == "gemma":
diff --git a/wqflask/wqflask/marker_regression/rqtl_mapping.py b/wqflask/wqflask/marker_regression/rqtl_mapping.py
index aae8e602..e1aa290b 100644
--- a/wqflask/wqflask/marker_regression/rqtl_mapping.py
+++ b/wqflask/wqflask/marker_regression/rqtl_mapping.py
@@ -36,7 +36,10 @@ def run_rqtl_geno(vals, samples, dataset, method, model, permCheck, num_perm, pe
generate_cross_from_geno(dataset)
GENOtoCSVR = ro.r["GENOtoCSVR"] # Map the local GENOtoCSVR function
crossfilelocation = TMPDIR + crossname + ".cross"
- genofilelocation = locate(dataset.group.genofile, "genotype")
+ if dataset.group.genofile:
+ genofilelocation = locate(dataset.group.genofile, "genotype")
+ else:
+ genofilelocation = locate(dataset.group.name + ".geno", "genotype")
cross_object = GENOtoCSVR(genofilelocation, crossfilelocation) # TODO: Add the SEX if that is available
if manhattan_plot:
@@ -91,9 +94,11 @@ def run_rqtl_geno(vals, samples, dataset, method, model, permCheck, num_perm, pe
perm_data_frame = scanone(cross_object, pheno_col = "the_pheno", n_perm = num_perm, model=model, method=method)
perm_output, suggestive, significant = process_rqtl_perm_results(num_perm, perm_data_frame) # Functions that sets the thresholds for the webinterface
- return perm_output, suggestive, significant, process_rqtl_results(result_data_frame, dataset.group.species)
+ the_scale = check_mapping_scale(genofilelocation)
+ return perm_output, suggestive, significant, process_rqtl_results(result_data_frame, dataset.group.species), the_scale
else:
- return process_rqtl_results(result_data_frame, dataset.group.species)
+ the_scale = check_mapping_scale(genofilelocation)
+ return process_rqtl_results(result_data_frame, dataset.group.species), the_scale
def generate_cross_from_rdata(dataset):
rdata_location = locate(dataset.group.name + ".RData", "genotype/rdata")
@@ -286,4 +291,20 @@ def process_rqtl_results(result, species_name): # TODO: how to make this
marker['lod_score'] = output[i][2]
qtl_results.append(marker)
- return qtl_results \ No newline at end of file
+ return qtl_results
+
+def check_mapping_scale(genofile_location):
+ scale = "physic"
+ with open(genofile_location, "r") as geno_fh:
+ for line in geno_fh:
+ if line[0] == "@" or line[0] == "#":
+
+ if "@scale" in line:
+ scale = line.split(":")[1].strip()
+ break
+ else:
+ continue
+ else:
+ break
+
+ return scale \ No newline at end of file
diff --git a/wqflask/wqflask/marker_regression/run_mapping.py b/wqflask/wqflask/marker_regression/run_mapping.py
index e191902c..589be702 100644
--- a/wqflask/wqflask/marker_regression/run_mapping.py
+++ b/wqflask/wqflask/marker_regression/run_mapping.py
@@ -150,6 +150,10 @@ class RunMapping(object):
self.suggestive = ""
self.significant = ""
self.pair_scan = False # Initializing this since it is checked in views to determine which template to use
+ if 'transform' in start_vars:
+ self.transform = start_vars['transform']
+ else:
+ self.transform = ""
self.score_type = "LRS" #ZS: LRS or LOD
self.mapping_scale = "physic"
self.num_perm = 0
@@ -241,7 +245,6 @@ class RunMapping(object):
perm_strata = get_perm_strata(self.this_trait, primary_samples, self.categorical_vars, self.samples)
self.score_type = "LOD"
- #self.mapping_scale = "morgan"
self.control_marker = start_vars['control_marker']
self.do_control = start_vars['do_control']
if 'mapmethod_rqtl_geno' in start_vars:
@@ -252,9 +255,9 @@ class RunMapping(object):
#if start_vars['pair_scan'] == "true":
# self.pair_scan = True
if self.permCheck and self.num_perm > 0:
- self.perm_output, self.suggestive, self.significant, results = rqtl_mapping.run_rqtl_geno(self.vals, self.samples, self.dataset, self.method, self.model, self.permCheck, self.num_perm, perm_strata, self.do_control, self.control_marker, self.manhattan_plot, self.pair_scan, self.covariates)
+ self.perm_output, self.suggestive, self.significant, results, self.mapping_scale = rqtl_mapping.run_rqtl_geno(self.vals, self.samples, self.dataset, self.method, self.model, self.permCheck, self.num_perm, perm_strata, self.do_control, self.control_marker, self.manhattan_plot, self.pair_scan, self.covariates)
else:
- results = rqtl_mapping.run_rqtl_geno(self.vals, self.samples, self.dataset, self.method, self.model, self.permCheck, self.num_perm, perm_strata, self.do_control, self.control_marker, self.manhattan_plot, self.pair_scan, self.covariates)
+ results, self.mapping_scale = rqtl_mapping.run_rqtl_geno(self.vals, self.samples, self.dataset, self.method, self.model, self.permCheck, self.num_perm, perm_strata, self.do_control, self.control_marker, self.manhattan_plot, self.pair_scan, self.covariates)
elif self.mapping_method == "reaper":
if "startMb" in start_vars: #ZS: Check if first time page loaded, so it can default to ON
if "additiveCheck" in start_vars:
diff --git a/wqflask/wqflask/show_trait/SampleList.py b/wqflask/wqflask/show_trait/SampleList.py
index 7e126a36..ad78ebcc 100644
--- a/wqflask/wqflask/show_trait/SampleList.py
+++ b/wqflask/wqflask/show_trait/SampleList.py
@@ -14,8 +14,6 @@ import simplejson as json
import itertools
-from utility.elasticsearch_tools import get_elasticsearch_connection
-
import utility.logger
logger = utility.logger.getLogger(__name__ )
@@ -158,47 +156,47 @@ class SampleList(object):
return any(sample.variance for sample in self.sample_list)
-def get_transform_vals(dataset, trait):
- es = get_elasticsearch_connection(for_user=False)
-
- logger.info("DATASET NAME:", dataset.name)
-
- query = '{"bool": {"must": [{"match": {"name": "%s"}}, {"match": {"dataset": "%s"}}]}}' % (trait.name, dataset.name)
-
- es_body = {
- "query": {
- "bool": {
- "must": [
- {
- "match": {
- "name": "%s" % (trait.name)
- }
- },
- {
- "match": {
- "dataset": "%s" % (dataset.name)
- }
- }
- ]
- }
- }
- }
-
- response = es.search( index = "traits", doc_type = "trait", body = es_body )
- logger.info("THE RESPONSE:", response)
- results = response['hits']['hits']
-
- if len(results) > 0:
- samples = results[0]['_source']['samples']
-
- sample_dict = {}
- for sample in samples:
- sample_dict[sample['name']] = sample['qnorm']
-
- #logger.info("SAMPLE DICT:", sample_dict)
- return sample_dict
- else:
- return None
+# def get_transform_vals(dataset, trait):
+# es = get_elasticsearch_connection(for_user=False)
+
+# logger.info("DATASET NAME:", dataset.name)
+
+# query = '{"bool": {"must": [{"match": {"name": "%s"}}, {"match": {"dataset": "%s"}}]}}' % (trait.name, dataset.name)
+
+# es_body = {
+# "query": {
+# "bool": {
+# "must": [
+# {
+# "match": {
+# "name": "%s" % (trait.name)
+# }
+# },
+# {
+# "match": {
+# "dataset": "%s" % (dataset.name)
+# }
+# }
+# ]
+# }
+# }
+# }
+
+# response = es.search( index = "traits", doc_type = "trait", body = es_body )
+# logger.info("THE RESPONSE:", response)
+# results = response['hits']['hits']
+
+# if len(results) > 0:
+# samples = results[0]['_source']['samples']
+
+# sample_dict = {}
+# for sample in samples:
+# sample_dict[sample['name']] = sample['qnorm']
+
+# #logger.info("SAMPLE DICT:", sample_dict)
+# return sample_dict
+# else:
+# return None
def natural_sort_key(x):
"""Get expected results when using as a key for sort - ints or strings are sorted properly"""
diff --git a/wqflask/wqflask/show_trait/show_trait.py b/wqflask/wqflask/show_trait/show_trait.py
index d35ba749..8883e627 100644
--- a/wqflask/wqflask/show_trait/show_trait.py
+++ b/wqflask/wqflask/show_trait/show_trait.py
@@ -364,8 +364,8 @@ class ShowTrait(object):
if self.dataset:
dataset_menu_selected = self.dataset.name
- return_results_menu = (100, 200, 500, 1000, 2000, 5000, 10000, 15000, 20000)
- return_results_menu_selected = 500
+ return_results_menu = (100, 200, 500, 1000, 2000, 5000, 10000, 15000, 20000)
+ return_results_menu_selected = 500
self.corr_tools = dict(dataset_menu = dataset_menu,
dataset_menu_selected = dataset_menu_selected,
diff --git a/wqflask/wqflask/static/new/javascript/show_trait.js b/wqflask/wqflask/static/new/javascript/show_trait.js
index 28d13345..d94a2347 100644
--- a/wqflask/wqflask/static/new/javascript/show_trait.js
+++ b/wqflask/wqflask/static/new/javascript/show_trait.js
@@ -367,6 +367,8 @@ make_table = function() {
var header, key, row, row_line, table, the_id, the_rows, value, _i, _len, _ref, _ref1;
if (js_data.trait_symbol != null) {
header = "<thead><tr><th style=\"color: white; background-color: #369; text-align: center;\" colspan=\"100%\">Trait " + js_data.trait_id + " - " + js_data.trait_symbol + "</th></tr><tr><th style=\"text-align: right; padding-left: 5px;\">Statistic</th>";
+ } else if (js_data.dataset_type == "Geno"){
+ header = "<thead><tr><th style=\"color: white; background-color: #369; text-align: center;\" colspan=\"100%\">Marker " + js_data.trait_id + "</th></tr><tr><th style=\"text-align: right; padding-left: 5px;\">Statistic</th>";
} else {
header = "<thead><tr><th style=\"color: white; background-color: #369; text-align: center;\" colspan=\"100%\">Trait " + js_data.trait_id + ": " + js_data.short_description + "</th></tr><tr><th style=\"text-align: right; padding-left: 5px;\">Statistic</th>";
}
diff --git a/wqflask/wqflask/templates/mapping_results.html b/wqflask/wqflask/templates/mapping_results.html
index ba0ebef9..7e05be18 100644
--- a/wqflask/wqflask/templates/mapping_results.html
+++ b/wqflask/wqflask/templates/mapping_results.html
@@ -36,7 +36,7 @@
<input type="hidden" name="value:{{ sample }}" value="{{ vals[loop.index - 1] }}">
{% endfor %}
<input type="hidden" name="num_vals" value="{{ n_samples }}">
- <input type="hidden" name="maf">
+ <input type="hidden" name="maf" value="{{ maf }}">
<input type="hidden" name="use_loco" value="{{ use_loco }}">
<input type="hidden" name="selected_chr" value="{{ selectedChr }}">
<input type="hidden" name="manhattan_plot" value="{{ manhattan_plot }}">
@@ -45,10 +45,14 @@
<input type="hidden" name="num_bootstrap" value="{{ nboot }}">
<input type="hidden" name="do_control" value="{{ doControl }}">
<input type="hidden" name="control_marker" value="{{ controlLocus }}">
- <input type="hidden" name="covariates" values="{{ covariates }}">
+ <input type="hidden" name="covariates" value="{{ covariates }}">
<input type="hidden" name="mapmethod_rqtl_geno" value="{{ mapmethod_rqtl_geno }}">
<input type="hidden" name="mapmodel_rqtl_geno" value="{{ mapmodel_rqtl_geno }}">
<input type="hidden" name="pair_scan" value="{{ pair_scan }}">
+ <input type="hidden" name="transform" value="{{ transform }}">
+ <input type="hidden" name="tool_used" value="Mapping">
+ <input type="hidden" name="wanted_inputs" value="">
+ <input type="hidden" name="form_url" value="/run_mapping">
<div class="container">
<div class="col-xs-5">
@@ -422,11 +426,19 @@
});
+ var mapping_input_list = ['temp_uuid', 'trait_id', 'dataset', 'tool_used', 'form_url', 'method', 'transform', 'trimmed_markers', 'selected_chr', 'chromosomes', 'mapping_scale',
+ 'score_type', 'suggestive', 'significant', 'num_perm', 'permCheck', 'perm_output', 'perm_strata', 'categorical_vars', 'num_bootstrap', 'bootCheck', 'bootstrap_results',
+ 'LRSCheck', 'covariates', 'maf', 'use_loco', 'manhattan_plot', 'control_marker', 'control_marker_db', 'do_control', 'genofile',
+ 'pair_scan', 'startMb', 'endMb', 'graphWidth', 'lrsMax', 'additiveCheck', 'showSNP', 'showGenes', 'viewLegend', 'haplotypeAnalystCheck',
+ 'mapmethod_rqtl_geno', 'mapmodel_rqtl_geno', 'temp_trait', 'group', 'species', 'reaper_version', 'primary_samples', 'num_vals']
+
+ $('input[name=wanted_inputs]').val(mapping_input_list.join(","));
+
chrView = function(this_chr, chr_mb_list) {
$('input[name=selected_chr]').val(this_chr)
$('input[name=chr_mb_list]').val(chr_mb_list)
- $('#marker_regression_form').attr('action', '/run_mapping');
+ $('#marker_regression_form').attr('action', '/loading');
return $('#marker_regression_form').submit();
};
@@ -436,13 +448,13 @@
$('input[name=endMb]').val(end_mb)
//$('input[name=mb_range]').val(start_mb + "," + end_mb)
- $('#marker_regression_form').attr('action', '/run_mapping');
+ $('#marker_regression_form').attr('action', '/loading');
return $('#marker_regression_form').submit();
};
remap = function() {
$('input[name=selected_chr]').val($('select[name=chromosomes]').val());
- $('#marker_regression_form').attr('action', '/run_mapping');
+ $('#marker_regression_form').attr('action', '/loading');
return $('#marker_regression_form').submit();
};
diff --git a/wqflask/wqflask/templates/search_result_page.html b/wqflask/wqflask/templates/search_result_page.html
index 33221e0f..0f5c39b0 100644
--- a/wqflask/wqflask/templates/search_result_page.html
+++ b/wqflask/wqflask/templates/search_result_page.html
@@ -27,6 +27,8 @@
with <u>GeneWiki</u> containing <strong>{{ word.search_term[0] }}</strong>{% if loop.last %}.{% else %} and {% endif %}
{% elif word.key|lower == "mean" %}
with <u>MEAN</u> between <strong>{{ word.search_term[0] }}</strong> and <strong>{{ word.search_term[1] }}</strong>{% if loop.last %}.{% else %} and {% endif %}
+ {% elif word.key|lower == "range" %}
+ with <u>RANGE</u> between <strong>{{ word.search_term[0] }}</strong> and <strong>{{ word.search_term[1] }}</strong>{% if loop.last %}.{% else %} and {% endif %}
{% elif word.key|lower == "lrs" or word.key|lower == "lod" or word.key|lower == "translrs" or word.key|lower == "cislrs" or word.key|lower == "translod" or word.key|lower == "cislod" %}
{% if word.search_term|length == 1 %}
with {% if word.key|lower == "translrs" %}trans{% elif word.key|lower == "cislrs" %}cis{% endif %}LRS {% if word.separator == ">" %} greater than {% elif word.separator == "<" %} less than {% elif word.separator == ">=" %} greater than or equal to {% elif word.separator == "<=" %} less than or equal to {% endif %} <strong>{{ word.search_term[0] }}</strong>{% if loop.last %}.{% else %} and {% endif %}
diff --git a/wqflask/wqflask/user_login.py b/wqflask/wqflask/user_login.py
index da3cc504..edd272c2 100644
--- a/wqflask/wqflask/user_login.py
+++ b/wqflask/wqflask/user_login.py
@@ -6,7 +6,6 @@ import datetime
import time
import logging
import uuid
-import hashlib
import hmac
import base64
import requests
@@ -42,17 +41,20 @@ def basic_info():
ip_address = request.remote_addr,
user_agent = request.headers.get('User-Agent'))
-def encode_password(pass_gen_fields):
+def encode_password(pass_gen_fields, unencrypted_password):
hashfunc = getattr(hashlib, pass_gen_fields['hashfunc'])
salt = base64.b64decode(pass_gen_fields['salt'])
- password = pbkdf2.pbkdf2_hex(str(pass_gen_fields['unencrypted_password']),
+ encrypted_password = pbkdf2.pbkdf2_hex(str(unencrypted_password),
pass_gen_fields['salt'],
pass_gen_fields['iterations'],
pass_gen_fields['keylength'],
hashfunc)
- return password
+ pass_gen_fields.pop("unencrypted_password", None)
+ pass_gen_fields["password"] = encrypted_password
+
+ return pass_gen_fields
def set_password(password):
pass_gen_fields = {
@@ -67,19 +69,10 @@ def set_password(password):
assert len(password) >= 6, "Password shouldn't be shorter than 6 characters"
- encoded_password = encode_password(pass_gen_fields)
+ encoded_password = encode_password(pass_gen_fields, pass_gen_fields['unencrypted_password'])
return encoded_password
-def encrypt_password(unencrypted_password, pwfields):
- hashfunc = getattr(hashlib, pwfields['hashfunc'])
- salt = base64.b64decode(pwfields['salt'])
- iterations = pwfields['iterations']
- keylength = pwfields['keylength']
- encrypted_password = pbkdf2.pbkdf2_hex(str(unencrypted_password),
- salt, iterations, keylength, hashfunc)
- return encrypted_password
-
def get_signed_session_id(user):
session_id = str(uuid.uuid4())
@@ -186,9 +179,12 @@ def login():
password_match = False
if user_details:
submitted_password = params['password']
- pwfields = json.loads(user_details['password'])
- encrypted_pass = encrypt_password(submitted_password, pwfields)
- password_match = pbkdf2.safe_str_cmp(encrypted_pass, pwfields['password'])
+ pwfields = user_details['password']
+ if type(pwfields) is 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'])
+
else: # Invalid e-mail
flash("Invalid e-mail address. Please try again.", "alert-danger")
response = make_response(redirect(url_for('login')))
@@ -226,7 +222,7 @@ def github_oauth2():
"client_secret": GITHUB_CLIENT_SECRET,
"code": code
}
- logger.debug("LOGIN DATA:", data)
+
result = requests.post("https://github.com/login/oauth/access_token", json=data)
result_dict = {arr[0]:arr[1] for arr in [tok.split("=") for tok in [token.encode("utf-8") for token in result.text.split("&")]]}
@@ -437,19 +433,18 @@ def register_user(params):
if params.get('password_confirm') != password:
errors.append("Passwords don't match.")
- if errors:
- return errors
-
user_details['password'] = set_password(password)
user_details['user_id'] = str(uuid.uuid4())
user_details['confirmed'] = 1
- user_details['registration_info'] = json.dumps(basic_info(), sort_keys=True)
+ user_details['registration_info'] = basic_info()
save_user(user_details, user_details['user_id'])
+ return errors
+
@app.route("/n/register", methods=('GET', 'POST'))
def register():
- errors = None
+ errors = []
params = request.form if request.form else request.args
params = params.to_dict(flat=True)
diff --git a/wqflask/wqflask/user_session.py b/wqflask/wqflask/user_session.py
index d75a03df..fd1779fb 100644
--- a/wqflask/wqflask/user_session.py
+++ b/wqflask/wqflask/user_session.py
@@ -9,6 +9,7 @@ import simplejson as json
import redis # used for collections
Redis = redis.StrictRedis()
+
from flask import (Flask, g, render_template, url_for, request, make_response,
redirect, flash, abort)
@@ -69,19 +70,23 @@ class UserSession(object):
if not self.record or self.record == []:
if user_cookie:
self.logged_in = False
+ self.record = dict(login_time = time.time(),
+ user_type = "anon",
+ user_id = str(uuid.uuid4()))
+ Redis.hmset(self.redis_key, self.record)
+ Redis.expire(self.redis_key, THIRTY_DAYS)
+ response = make_response(redirect(url_for('login')))
+ response.set_cookie(self.user_cookie_name, '', expires=0)
########### Grrr...this won't work because of the way flask handles cookies
# Delete the cookie
- response = make_response(redirect(url_for('login')))
- #response.set_cookie(self.cookie_name, '', expires=0)
flash("Due to inactivity your session has expired. If you'd like please login again.")
- #return response
+ return response
#return
else:
self.record = dict(login_time = time.time(),
user_type = "anon",
user_id = str(uuid.uuid4()))
-
Redis.hmset(self.redis_key, self.record)
Redis.expire(self.redis_key, THIRTY_DAYS)
else:
diff --git a/wqflask/wqflask/views.py b/wqflask/wqflask/views.py
index b91d58d7..7d3dfa48 100644
--- a/wqflask/wqflask/views.py
+++ b/wqflask/wqflask/views.py
@@ -589,18 +589,23 @@ def loading_page():
if key in wanted or key.startswith(('value:')):
start_vars[key] = value
- if 'primary_samples' in start_vars:
- samples = start_vars['primary_samples'].split(",")
- for sample in samples:
- value = start_vars.get('value:' + sample)
- if value != "x":
- num_vals += 1
+ if 'num_vals' in start_vars:
+ num_vals = int(start_vars['num_vals'])
+ else:
+ if 'primary_samples' in start_vars:
+ samples = start_vars['primary_samples'].split(",")
+ for sample in samples:
+ value = start_vars.get('value:' + sample)
+ if value != "x":
+ num_vals += 1
start_vars['num_vals'] = num_vals
+ start_vars['wanted_inputs'] = initial_start_vars['wanted_inputs']
start_vars_container['start_vars'] = start_vars
else:
start_vars_container['start_vars'] = initial_start_vars
+
rendered_template = render_template("loading.html", **start_vars_container)
return rendered_template
@@ -664,7 +669,8 @@ def mapping_results_page():
'mapmodel_rqtl_geno',
'temp_trait',
'reaper_version',
- 'num_vals'
+ 'num_vals',
+ 'transform'
)
start_vars = {}
for key, value in initial_start_vars.iteritems():