From ce5d2b86af694c266cc0159be0438f187a058c20 Mon Sep 17 00:00:00 2001 From: Zachary Sloan Date: Tue, 24 Sep 2013 13:11:21 -0500 Subject: Fixed the db_tools import in mrna_assay_tissue_data.py Added file for the interval mapping page and wrote code that gets/sets some parameters --- wqflask/base/mrna_assay_tissue_data.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'wqflask/base') diff --git a/wqflask/base/mrna_assay_tissue_data.py b/wqflask/base/mrna_assay_tissue_data.py index 8ae71858..a08f3f21 100644 --- a/wqflask/base/mrna_assay_tissue_data.py +++ b/wqflask/base/mrna_assay_tissue_data.py @@ -4,8 +4,8 @@ import collections from flask import g -from utility import dbtools -from uitility import Bunch +from utility import db_tools +from utility import Bunch from MySQLdb import escape_string as escape -- cgit v1.2.3 From 3325184b1dd310619626dd31852ab84cae6dc7fc Mon Sep 17 00:00:00 2001 From: Zachary Sloan Date: Tue, 8 Oct 2013 12:13:56 -0500 Subject: Did some work with interval mapping page; will use qtl reaper to do the mapping, since it is reliable/fast and avoids us having to rewrite from scratch using something like r/qtl --- wqflask/base/data_set.py | 20 ++++---- wqflask/maintenance/quick_search_table.py | 4 +- .../wqflask/interval_mapping/interval_mapping.py | 53 ++++++++++++++++++++++ 3 files changed, 67 insertions(+), 10 deletions(-) (limited to 'wqflask/base') diff --git a/wqflask/base/data_set.py b/wqflask/base/data_set.py index 96e04df0..befbd518 100755 --- a/wqflask/base/data_set.py +++ b/wqflask/base/data_set.py @@ -168,13 +168,13 @@ class Markers(object): for marker, p_value in itertools.izip(self.markers, p_values): marker['p_value'] = p_value - if marker['p_value'] == 0: - marker['lod_score'] = 0 - marker['lrs_value'] = 0 - else: - 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 + if math.isnan(marker['p_value']): + print("p_value is:", marker['p_value']) + 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 + + class HumanMarkers(Markers): @@ -189,6 +189,8 @@ class HumanMarkers(Markers): marker['name'] = splat[1] marker['Mb'] = float(splat[3]) / 1000000 self.markers.append(marker) + + #print("markers is: ", pf(self.markers)) def add_pvalues(self, p_values): @@ -315,10 +317,10 @@ class DatasetGroup(object): #determine default genotype object if self.incparentsf1 and genotype_1.type != "intercross": - genotype = genotype_2 + self.genotype = genotype_2 else: self.incparentsf1 = 0 - genotype = genotype_1 + self.genotype = genotype_1 self.samplelist = list(genotype.prgy) diff --git a/wqflask/maintenance/quick_search_table.py b/wqflask/maintenance/quick_search_table.py index 9cd792ef..23bd505c 100644 --- a/wqflask/maintenance/quick_search_table.py +++ b/wqflask/maintenance/quick_search_table.py @@ -11,8 +11,10 @@ each trait, its dataset, and several columns determined by its trait type (pheno """ -from __future__ import print_function, division, absolute_import +from __future__ import absolute_import, division, print_function +# We do this here so we can use zach_settings +# Not to avoid other absoulte_imports import sys sys.path.append("../../..") diff --git a/wqflask/wqflask/interval_mapping/interval_mapping.py b/wqflask/wqflask/interval_mapping/interval_mapping.py index 48e8018e..5d660224 100644 --- a/wqflask/wqflask/interval_mapping/interval_mapping.py +++ b/wqflask/wqflask/interval_mapping/interval_mapping.py @@ -12,6 +12,7 @@ import collections import numpy as np from scipy import linalg +import rpy2.robjects import simplejson as json @@ -83,6 +84,28 @@ class IntervalMapping(object): """Generates qtl results for plotting interval map""" self.dataset.group.get_markers() + self.dataset.read_genotype_file() + + samples, values, variances = self.trait.export_informative() + if self.control_locus: + if self.weighted_regression: + qtl_result = self.dataset.genotype.regression(strains = samples, + trait = values, + variance = variances, + control = self.control_locus) + else: + qtl_result = self.dataset.genotype.regression(strains = samples, + trait = values, + control = self.control_locus) + else: + if self.weighted_regression: + qtl_result = self.dataset.genotype.regression(strains = samples, + trait = values, + variance = variances) + else: + qtl_result = self.dataset.genotype.regression(strains = samples, + trait = values) + pheno_vector = np.array([val == "x" and np.nan or float(val) for val in self.vals]) @@ -108,6 +131,36 @@ class IntervalMapping(object): self.qtl_results = self.dataset.group.markers.markers + #def gen_qtl_results_2(self, tempdata): + # """Generates qtl results for plotting interval map""" + # + # self.dataset.group.get_markers() + # self.dataset.read_genotype_file() + # + # pheno_vector = np.array([val == "x" and np.nan or float(val) for val in self.vals]) + # + # #if self.dataset.group.species == "human": + # # p_values, t_stats = self.gen_human_results(pheno_vector, tempdata) + # #else: + # genotype_data = [marker['genotypes'] for marker in self.dataset.group.markers.markers] + # + # no_val_samples = self.identify_empty_samples() + # trimmed_genotype_data = self.trim_genotypes(genotype_data, no_val_samples) + # + # genotype_matrix = np.array(trimmed_genotype_data).T + # + # t_stats, p_values = lmm.run( + # pheno_vector, + # genotype_matrix, + # restricted_max_likelihood=True, + # refit=False, + # temp_data=tempdata + # ) + # + # self.dataset.group.markers.add_pvalues(p_values) + # + # self.qtl_results = self.dataset.group.markers.markers + def identify_empty_samples(self): no_val_samples = [] -- cgit v1.2.3 From a823e66f8dc742e1608b3e0db6d521d5f63b641a Mon Sep 17 00:00:00 2001 From: Zachary Sloan Date: Tue, 15 Oct 2013 15:06:36 -0500 Subject: Changed templates to call the header macro Correlation page now works with Non-BXD (or whatever group) or All Samples options --- wqflask/base/data_set.py | 14 ++++++++------ wqflask/wqflask/correlation/show_corr_results.py | 4 ++-- wqflask/wqflask/templates/base.html | 4 ++-- wqflask/wqflask/templates/correlation_page.html | 8 ++------ wqflask/wqflask/templates/index_page.html | 2 -- wqflask/wqflask/templates/marker_regression.html | 10 ++-------- wqflask/wqflask/templates/quick_search.html | 11 +++-------- wqflask/wqflask/templates/search_result_page.html | 10 ++-------- wqflask/wqflask/templates/show_trait.html | 11 +++-------- 9 files changed, 24 insertions(+), 50 deletions(-) (limited to 'wqflask/base') diff --git a/wqflask/base/data_set.py b/wqflask/base/data_set.py index 9fa7beb3..f25e7974 100755 --- a/wqflask/base/data_set.py +++ b/wqflask/base/data_set.py @@ -322,7 +322,7 @@ class DatasetGroup(object): self.incparentsf1 = 0 self.genotype = genotype_1 - self.samplelist = list(genotype.prgy) + self.samplelist = list(self.genotype.prgy) #class DataSets(object): @@ -440,10 +440,12 @@ class DataSet(object): def get_trait_data(self, sample_list=None): if sample_list: - self.samplelist = sample_list + self.group.parlist + self.group.f1list + self.samplelist = sample_list else: - self.samplelist = self.group.samplelist + self.group.parlist + self.group.f1list - + self.samplelist = self.group.samplelist + + if (self.group.parlist + self.group.f1list) in self.samplelist: + self.samplelist += self.group.parlist + self.group.f1list query = """ SELECT Strain.Name, Strain.Id FROM Strain, Species @@ -503,8 +505,8 @@ class DataSet(object): and {}Freeze.Name = '{}' and {}.Id = {}XRef.{}Id order by {}.Id - """.format(*mescape(self.type, self.type, self.type, self.type, - self.name, dataset_type, self.type, self.type, dataset_type)) + """.format(*mescape(self.type, self.type, self.type, self.name, + dataset_type, self.type, dataset_type, dataset_type)) else: query += """ WHERE {}XRef.{}FreezeId = {}Freeze.Id diff --git a/wqflask/wqflask/correlation/show_corr_results.py b/wqflask/wqflask/correlation/show_corr_results.py index a5c80674..8f23165c 100644 --- a/wqflask/wqflask/correlation/show_corr_results.py +++ b/wqflask/wqflask/correlation/show_corr_results.py @@ -178,10 +178,10 @@ class CorrelationResults(object): trait_object.lit_corr = lit_corr_data[trait][1] self.correlation_results.append(trait_object) - if self.corr_type != "lit": + if self.corr_type != "lit" and self.dataset.type == "ProbeSet": self.do_lit_correlation_for_trait_list() - if self.corr_type != "tissue": + if self.corr_type != "tissue" and self.dataset.type == "ProbeSet": self.do_tissue_correlation_for_trait_list() #print("self.correlation_results: ", pf(self.correlation_results)) diff --git a/wqflask/wqflask/templates/base.html b/wqflask/wqflask/templates/base.html index 8efba6a7..a14eeb44 100644 --- a/wqflask/wqflask/templates/base.html +++ b/wqflask/wqflask/templates/base.html @@ -29,9 +29,9 @@ {% macro header(main, second) %}
-

Login

+

{{ main }}

- Gain access to GeneNetwork. + {{ second }}

diff --git a/wqflask/wqflask/templates/correlation_page.html b/wqflask/wqflask/templates/correlation_page.html index 4d09cf20..7e149506 100644 --- a/wqflask/wqflask/templates/correlation_page.html +++ b/wqflask/wqflask/templates/correlation_page.html @@ -6,12 +6,8 @@ {% endblock %} {% block content %} - -
-
-

Correlation

-
-
+ + {{ header("Correlation", 'Trait: {} Dataset: {}'.format(this_trait.name, dataset.name)) }} diff --git a/wqflask/wqflask/templates/index_page.html b/wqflask/wqflask/templates/index_page.html index 98682e57..d177a7bd 100644 --- a/wqflask/wqflask/templates/index_page.html +++ b/wqflask/wqflask/templates/index_page.html @@ -3,8 +3,6 @@ {% block content %} - -

GeneNetwork

diff --git a/wqflask/wqflask/templates/marker_regression.html b/wqflask/wqflask/templates/marker_regression.html index 9260acab..64d2e9b7 100644 --- a/wqflask/wqflask/templates/marker_regression.html +++ b/wqflask/wqflask/templates/marker_regression.html @@ -9,14 +9,8 @@ {% endblock %} {% block content %} -
-
-

Marker Regression

-

- {{ this_trait.name }}: {{ this_trait.description_fmt }} -

-
-
+ {{ header("Marker Regression", + '{}: {}'.format(this_trait.name, this_trait.description_fmt)) }}
diff --git a/wqflask/wqflask/templates/quick_search.html b/wqflask/wqflask/templates/quick_search.html index b0e38708..2f268c5a 100644 --- a/wqflask/wqflask/templates/quick_search.html +++ b/wqflask/wqflask/templates/quick_search.html @@ -2,14 +2,9 @@ {% block title %}QuickSearch Results{% endblock %} {% block content %} -
-
-

QuickSearch Results

-

- GeneNetwork found {{ numify(results|count, "record", "records") }}. -

-
-
+ + {{ header("QuickSearch Results", + 'GeneNetwork found {}.'.format(numify(results|count, "record", "records"))) }}