aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZachary Sloan2014-01-24 20:52:46 +0000
committerZachary Sloan2014-01-24 20:52:46 +0000
commit2df34255de526e1e016100a8772d2c8e10eb970f (patch)
tree8818a002dce0a933b63f6532f9ef0c182ade4a5b
parent6b367e3e2ee144aae5b79c50234faf0ea49adba6 (diff)
downloadgenenetwork2-2df34255de526e1e016100a8772d2c8e10eb970f.tar.gz
Added natural sort to sort the index column for the sample data in
the trait page Hid the Quick Search on the index page until it is working well. Started writing a file to run the pyLMM code in the background to avoid memory issues/timing out
-rw-r--r--misc/notes.txt4
-rw-r--r--wqflask/wqflask/my_pylmm/run_pylmm.py77
-rw-r--r--wqflask/wqflask/static/new/packages/DataTables/js/dataTables.naturalSort.js56
-rw-r--r--wqflask/wqflask/templates/index_page.html6
4 files changed, 140 insertions, 3 deletions
diff --git a/misc/notes.txt b/misc/notes.txt
index 5a43ab8a..fa2152d9 100644
--- a/misc/notes.txt
+++ b/misc/notes.txt
@@ -273,6 +273,10 @@ grep -ir (search string) (directory)
===========================================
+Use argparse to deal with command line arguments (instead of argv)
+
+===========================================
+
Change owner/group:
chown zas1024 somefile (change owner of somefile to zas1024)
diff --git a/wqflask/wqflask/my_pylmm/run_pylmm.py b/wqflask/wqflask/my_pylmm/run_pylmm.py
new file mode 100644
index 00000000..9ac03ad2
--- /dev/null
+++ b/wqflask/wqflask/my_pylmm/run_pylmm.py
@@ -0,0 +1,77 @@
+from __future__ import absolute_import, print_function, division
+
+from base import data_set
+from base.species import TheSpecies
+
+ def run(dataset_name, vals, temp_uuid):
+ """Generates p-values for each marker"""
+
+ tempdata = temp_data.TempData(temp_uuid)
+
+ dataset = data_set.create_dataset(dataset_name)
+ species = TheSpecies(dataset=dataset)
+
+ samples = [] # Want only ones with values
+ vals = vals
+
+ for sample in dataset.group.samplelist:
+ samples.append(str(sample))
+
+ gen_data(dataset, vals, tempdata)
+
+
+ def gen_data(dataset, vals)
+ dataset.group.get_markers()
+
+ pheno_vector = np.array([val == "x" and np.nan or float(val) for val in vals])
+
+ if dataset.group.species == "human":
+ p_values, t_stats = 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
+
+ #print("pheno_vector: ", pf(pheno_vector))
+ #print("genotype_matrix: ", pf(genotype_matrix))
+ #print("genotype_matrix.shape: ", pf(genotype_matrix.shape))
+
+ t_stats, p_values = lmm.run(
+ pheno_vector,
+ genotype_matrix,
+ restricted_max_likelihood=True,
+ refit=False,
+ temp_data=tempdata
+ )
+ #print("p_values:", p_values)
+
+ self.dataset.group.markers.add_pvalues(p_values)
+ return self.dataset.group.markers.markers
+
+
+ def gen_human_results(self, pheno_vector, tempdata):
+ file_base = os.path.join(webqtlConfig.PYLMM_PATH, self.dataset.group.name)
+
+ plink_input = input.plink(file_base, type='b')
+ input_file_name = os.path.join(webqtlConfig.SNP_PATH, self.dataset.group.name + ".snps.gz")
+
+ pheno_vector = pheno_vector.reshape((len(pheno_vector), 1))
+ covariate_matrix = np.ones((pheno_vector.shape[0],1))
+ kinship_matrix = np.fromfile(open(file_base + '.kin','r'),sep=" ")
+ kinship_matrix.resize((len(plink_input.indivs),len(plink_input.indivs)))
+
+ p_values, t_stats = lmm.run_human(
+ pheno_vector,
+ covariate_matrix,
+ input_file_name,
+ kinship_matrix,
+ loading_progress=tempdata
+ )
+
+ return p_values, t_stats
+
+if __name__ == '__main__':
+ run(dataset_name, vals, temp_uuid) \ No newline at end of file
diff --git a/wqflask/wqflask/static/new/packages/DataTables/js/dataTables.naturalSort.js b/wqflask/wqflask/static/new/packages/DataTables/js/dataTables.naturalSort.js
new file mode 100644
index 00000000..c9e26682
--- /dev/null
+++ b/wqflask/wqflask/static/new/packages/DataTables/js/dataTables.naturalSort.js
@@ -0,0 +1,56 @@
+(function() {
+
+/*
+ * Natural Sort algorithm for Javascript - Version 0.7 - Released under MIT license
+ * Author: Jim Palmer (based on chunking idea from Dave Koelle)
+ * Contributors: Mike Grier (mgrier.com), Clint Priest, Kyle Adams, guillermo
+ * See: http://js-naturalsort.googlecode.com/svn/trunk/naturalSort.js
+ */
+function naturalSort (a, b) {
+ var re = /(^-?[0-9]+(\.?[0-9]*)[df]?e?[0-9]?$|^0x[0-9a-f]+$|[0-9]+)/gi,
+ sre = /(^[ ]*|[ ]*$)/g,
+ dre = /(^([\w ]+,?[\w ]+)?[\w ]+,?[\w ]+\d+:\d+(:\d+)?[\w ]?|^\d{1,4}[\/\-]\d{1,4}[\/\-]\d{1,4}|^\w+, \w+ \d+, \d{4})/,
+ hre = /^0x[0-9a-f]+$/i,
+ ore = /^0/,
+ // convert all to strings and trim()
+ x = a.toString().replace(sre, '') || '',
+ y = b.toString().replace(sre, '') || '',
+ // chunk/tokenize
+ xN = x.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0'),
+ yN = y.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0'),
+ // numeric, hex or date detection
+ xD = parseInt(x.match(hre)) || (xN.length != 1 && x.match(dre) && Date.parse(x)),
+ yD = parseInt(y.match(hre)) || xD && y.match(dre) && Date.parse(y) || null;
+ // first try and sort Hex codes or Dates
+ if (yD)
+ if ( xD < yD ) return -1;
+ else if ( xD > yD ) return 1;
+ // natural sorting through split numeric strings and default strings
+ for(var cLoc=0, numS=Math.max(xN.length, yN.length); cLoc < numS; cLoc++) {
+ // find floats not starting with '0', string or 0 if not defined (Clint Priest)
+ var oFxNcL = !(xN[cLoc] || '').match(ore) && parseFloat(xN[cLoc]) || xN[cLoc] || 0;
+ var oFyNcL = !(yN[cLoc] || '').match(ore) && parseFloat(yN[cLoc]) || yN[cLoc] || 0;
+ // handle numeric vs string comparison - number < string - (Kyle Adams)
+ if (isNaN(oFxNcL) !== isNaN(oFyNcL)) return (isNaN(oFxNcL)) ? 1 : -1;
+ // rely on string comparison if different types - i.e. '02' < 2 != '02' < '2'
+ else if (typeof oFxNcL !== typeof oFyNcL) {
+ oFxNcL += '';
+ oFyNcL += '';
+ }
+ if (oFxNcL < oFyNcL) return -1;
+ if (oFxNcL > oFyNcL) return 1;
+ }
+ return 0;
+}
+
+jQuery.extend( jQuery.fn.dataTableExt.oSort, {
+ "natural-asc": function ( a, b ) {
+ return naturalSort(a,b);
+ },
+
+ "natural-desc": function ( a, b ) {
+ return naturalSort(a,b) * -1;
+ }
+} );
+
+}()); \ No newline at end of file
diff --git a/wqflask/wqflask/templates/index_page.html b/wqflask/wqflask/templates/index_page.html
index d177a7bd..a7d7b513 100644
--- a/wqflask/wqflask/templates/index_page.html
+++ b/wqflask/wqflask/templates/index_page.html
@@ -17,7 +17,7 @@
<div class="row">
<div class="span3 bs-docs-sidebar">
<ul class="nav nav-list bs-docs-sidenav">
- <li><a href="#quick-search"><i class="icon-chevron-right"></i> Quick Search</a></li>
+<!-- <li><a href="#quick-search"><i class="icon-chevron-right"></i> Quick Search</a></li>-->
<li><a href="#search"><i class="icon-chevron-right"></i> Search</a></li>
<li><a href="#getting-started"><i class="icon-chevron-right"></i> Getting started</a></li>
<li><a href="#advanced"><i class="icon-chevron-right"></i> Advanced commands</a></li>
@@ -27,7 +27,7 @@
</div>
<div class="span9">
- <section id="quick-search">
+<!-- <section id="quick-search">
<div class="page-header">
<h1>Quick search</h1>
</div>
@@ -52,7 +52,7 @@
</div>
</fieldset>
</form>
- </section>
+ </section>-->
<section id="search">
<div class="page-header">
<h1>Select and search</h1>