diff options
84 files changed, 3677 insertions, 3183 deletions
diff --git a/bin/genenetwork2 b/bin/genenetwork2 index d7d1c325..52d3155c 100755 --- a/bin/genenetwork2 +++ b/bin/genenetwork2 @@ -26,6 +26,10 @@ GN2_BASE_DIR=$(dirname $(dirname "$SCRIPT")) echo GN2_BASE_DIR=$GN2_BASE_DIR +GIT_HASH=$(git rev-parse HEAD) +GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD) +export GN_VERSION=$(cat $GN2_BASE_DIR/VERSION)-$GIT_BRANCH-${GIT_HASH:0:9} +echo GN_VERSION=$GN_VERSION # Handle settings parameter (can be .py or .json) settings=$1 @@ -79,13 +83,13 @@ fi # We may change this one: export PYTHONPATH=$GN2_BASE_DIR/wqflask:$PYTHONPATH -# TEMPDIR defaults to /tmp if nothing else -if [ -z $TEMPDIR ]; then - TEMPDIR="/tmp" +# Our UNIX TMPDIR defaults to /tmp - change this on a shared server +if [ -z $TMPDIR ]; then + TMPDIR="/tmp" fi set|grep $GN2_PROFILE -set|grep TEMPDIR +set|grep TMPDIR # Now handle command parameter -c if [ "$1" = '-c' ] ; then @@ -98,7 +102,7 @@ if [ "$1" = '-c' ] ; then fi echo "Starting the redis server:" -echo -n "dir $TEMPDIR +echo -n "dir $TMPDIR dbfilename gn2.rdb " | redis-server - & diff --git a/bin/test-website b/bin/test-website index c9a72a5e..be223d94 100755 --- a/bin/test-website +++ b/bin/test-website @@ -52,12 +52,12 @@ opts = OptionParser.new do |o| options[:link_checker] = true end - o.on('--navigation-test', 'Check for navigation') do - options[:navigation_test] = true + o.on('--navigation', 'Check for navigation') do + options[:navigation] = true end - o.on('--mapping-test', 'Check for mapping') do - options[:mapping_test] = true + o.on('--mapping', 'Check for mapping') do + options[:mapping] = true end o.on('--skip-broken', 'Skip tests that are known to be broken') do @@ -98,7 +98,7 @@ $: << File.join(libpath,'test/lib') require 'main_web_functionality' -if options[:all] or options[:mapping_test] +if options[:all] or options[:mapping] require 'mapping' end @@ -106,6 +106,6 @@ if options[:all] or options[:link_checker] require 'link_checker' end -if options[:all] or options[:navigation_test] +if options[:all] or options[:navigation] require 'navigation' end diff --git a/doc/README.org b/doc/README.org index 0f56914a..b38ea664 100644 --- a/doc/README.org +++ b/doc/README.org @@ -31,7 +31,7 @@ of GN2. Large system deployments can get very [[http://biogems.info/contrib/genenetwork/gn2.svg ][complex]]. In this document we explain the GeneNetwork version 2 (GN2) reproducible deployment system -which is based on GNU Guix (see also Pjotr's [[https://github.com/pjotrp/guix-notes/blob/master/README.md][Guix-notes]]). The Guix +which is based on GNU Guix (see also [[https://github.com/pjotrp/guix-notes/blob/master/README.md][Guix-notes]]). The Guix system can be used to install GN with all its files and dependencies. The official installation path is from a checked out version of the @@ -52,15 +52,16 @@ Linux distribution (including CentOS). For more elaborate installation instructions see [[#source-deployment][Source deployment]]. Note that GN2 consists of an approx. 5 GB installation including -database. +database. If you use a virtual machine we recommend to use at least +double. ** Step 1: Install GNU Guix Fetch the GNU Guix binary from [[https://www.gnu.org/software/guix/download/][here]] (middle panel) and follow -[[https://www.gnu.org/software/guix/manual/html_node/Binary-Installation.html][instructions]]. Essentially you have to download and unpack the tar ball -(which creates directories in /gnu and /var/guix), add build users and -group (Guix builds software as unpriviliged users) and run the Guix -daemon after fixing the paths (also known as the 'profile'). +[[https://www.gnu.org/software/guix/manual/html_node/Binary-Installation.html][instructions]]. Essentially, download and unpack the tar ball (which +creates directories in /gnu and /var/guix), add build users and group +(Guix builds software as unpriviliged users) and run the Guix daemon +after fixing the paths (also known as the 'profile'). Once you have succeeded, you have to [[https://github.com/pjotrp/guix-notes/blob/master/INSTALL.org#set-the-key][set the key]] (getting permission to download binaries from the GNU server) and you should be able to @@ -104,17 +105,23 @@ guix package -i git export GIT_SSL_CAINFO=/etc/ssl/certs/ca-certificates.crt #+end_src -check out the git repsitories (gn-latest branch) +check out the git repositories (gn-deploy branch) #+begin_src bash cd ~ mkdir genenetwork cd genenetwork -git clone --branch gn-latest https://github.com/genenetwork/guix-bioinformatics -git clone --branch gn-latest --recursive https://github.com/genenetwork/guix guix-gn-latest -cd guix-gn-latest +git clone --branch gn-deploy https://github.com/genenetwork/guix-bioinformatics +git clone --branch gn-deploy --recursive https://github.com/genenetwork/guix guix-gn-deploy +cd guix-gn-deploy #+end_src bash +To test whether this is working try: + +#+begin_src bash +#+end_src bash + + ** Step 3: Authorize the GN Guix server GN2 has its own GNU Guix binary distribution server. To trust it you have @@ -146,7 +153,7 @@ GNU Guix package path by pointing the package path to our repository: #+begin_src bash rm /root/.config/guix/latest -ln -s ~/genenetwork/guix-gn-latest/ /root/.config/guix/latest +ln -s ~/genenetwork/guix-gn-deploy/ /root/.config/guix/latest #+end_src Now check whether you can find the GN2 package with @@ -164,13 +171,16 @@ And install with #+begin_src bash env GUIX_PACKAGE_PATH=~/genenetwork/guix-bioinformatics/ \ guix package -i genenetwork2 \ - --substitute-urls="http://guix.genenetwork.org:8080 https://mirror.guixsd.org" \ - --fallback + --substitute-urls="http://guix.genenetwork.org" #+end_src Note: the order of the substitute url's may make a difference in speed (put the one first that is fastest for your location and time of day). +Note: if your system starts building or gives an error it may well be +Step 3 did not succeed. The installation should actually be smooth at +this point and only do binary installs (no compiling). + After installation you should be able to run genenetwork2 after updating the Guix suggested environment vars. Check the output of @@ -367,7 +377,7 @@ Create, install and run a recent version of the guix-daemon by compiling the guix repository you have installed with git in step 2. Follow [[https://github.com/pjotrp/guix-notes/blob/master/INSTALL.org#building-gnu-guix-from-source-using-guix][these]] steps carefully after -: cd ~/genenetwork/guix-gn-latest +: cd ~/genenetwork/guix-gn-deploy Make sure to restart the guix daemon and run guix client from this directory. @@ -377,7 +387,7 @@ directory. Reinstall genenetwork2 using the new tree #+begin_src bash -env GUIX_PACKAGE_PATH=~/genenetwork/guix-bioinformatics/ ./pre-inst-env guix package -i genenetwork2 --substitute-urls="http://guix.genenetwork.org:8080 https://mirror.guixsd.org" +env GUIX_PACKAGE_PATH=~/genenetwork/guix-bioinformatics/ ./pre-inst-env guix package -i genenetwork2 --substitute-urls="http://guix.genenetwork.org https://mirror.guixsd.org" #+end_src bash Note the use of ./pre-inst-env here! @@ -486,7 +496,7 @@ and a download of the test database. <pjotrp> right? <user01> yep <user01> set to the ones in ~/.guix-profile/ -<pjotrp> good, and you are in gn-latest-guix repo [07:06] +<pjotrp> good, and you are in gn-deploy-guix repo [07:06] <user01> yep [07:07] <pjotrp> git log shows @@ -645,7 +655,7 @@ The following derivations would be built: <pjotrp> and see what this lists [08:31] <pjotrp> env GUIX_PACKAGE_PATH=../guix-bioinformatics ./pre-inst-env guix package -i genenetwork2 - --substitute-urls=http://guix.genenetwork.org:8080 --dry-run + --substitute-urls=http://guix.genenetwork.org --dry-run <pjotrp> should be all binary installs <user01> it's not.. [08:32] <user01> if I remove --substitute-urls, the list changes, does that mean I @@ -716,7 +726,7 @@ The following derivations would be built: <pjotrp> should not [09:24] <pjotrp> what does env GUIX_PACKAGE_PATH=../guix-bioinformatics/ ./pre-inst-env guix package -i genenetwork2 - --substitute-urls="http://guix.genenetwork.org:8080" --dry-run + --substitute-urls="http://guix.genenetwork.org" --dry-run [09:25] <pjotrp> say for r-prepocesscore <pjotrp> download or build? @@ -869,7 +879,7 @@ The following derivations would be built: <pjotrp> I wrote an elixir package for guix :) <pjotrp> env GUIX_PACKAGE_PATH=../guix-bioinformatics/ ./pre-inst-env guix package -A elixir - --substitute-urls="http://guix.genenetwork.org:8080" [10:08] + --substitute-urls="http://guix.genenetwork.org" [10:08] <pjotrp> elixir 1.2.3 out ../guix-bioinformatics/gn/packages/elixir.scm:31:2 <pjotrp> diff --git a/doc/database.org b/doc/database.org index 624174a4..5107b660 100644 --- a/doc/database.org +++ b/doc/database.org @@ -1,9 +1,19 @@ -- github Document reduction issue +* Database Information + +WARNING: This document contains information on the GN databases which +will change over time. The GN database is currently MySQL based and, +while efficient, contains a number of design choices we want to grow +'out' of. Especially with an eye on reproducibility we want to +introduce versioning. + +So do not treat the information in this document as a final way of +accessing data. It is better to use the +[[https://github.com/genenetwork/gn_server/blob/master/doc/API.md][REST API]]. * The small test database (2GB) The default install comes with a smaller database which includes a -number of the BSD's and the Human liver dataset (GSE9588). +number of the BXD's and the Human liver dataset (GSE9588). * GeneNetwork database @@ -750,9 +760,30 @@ show indexes from ProbeSetFreeze; | 1 | 5 | 0.303492 | +--------+----------+----------+ -** Publication and publishdata (all pheno) +** Publication + +Publication: + +| Id | PubMed_ID | Abstract | Title | Pages | Month | Year | + -Phenotype pubs +** Publishdata (all pheno) + +One of three phenotype tables. + +mysql> select * from PublishData limit 5; ++---------+----------+-------+ +| Id | StrainId | value | ++---------+----------+-------+ +| 8966353 | 349 | 29.6 | +| 8966353 | 350 | 27.8 | +| 8966353 | 351 | 26.6 | +| 8966353 | 352 | 28.5 | +| 8966353 | 353 | 24.6 | ++---------+----------+-------+ +5 rows in set (0.25 sec) + +See below for phenotype access. ** QuickSearch @@ -1073,7 +1104,37 @@ select * from ProbeSetXRef limit 5; i.e., for Strain Id 1 (DataId) 1, the locus '10.095.400' has a phenotype value of 5.742. -GeneNetwork1 already has a limited REST interface, if you do +Interestingly ProbeData and PublishData have the same layout as +ProbeSetData. ProbeData is only in use for Affy assays - and not used +for computations. PublishData contains trait values. ProbeSetData.id +matches ProbeSetXRef.DataId while PublishData.id matches +PublishXRef.DataId. + +select * from PublishXRef limit 3; ++-------+-------------+-------------+---------------+---------+----------------+------------------+-----------+----------+-------------------------------------------------------+ +| Id | InbredSetId | PhenotypeId | PublicationId | DataId | Locus | LRS | additive | Sequence | comments | ++-------+-------------+-------------+---------------+---------+----------------+------------------+-----------+----------+-------------------------------------------------------+ +| 10001 | 8 | 1 | 1 | 8966353 | D2Mit5 | 10.18351644706 | -1.20875 | 1 | | +| 10001 | 7 | 2 | 53 | 8966813 | D7Mit25UT | 9.85534330983917 | -2.86875 | 1 | | +| 10001 | 4 | 3 | 81 | 8966947 | CEL-6_57082524 | 11.7119505898121 | -23.28875 | 1 | elissa modified Abstract at Tue Jun 7 11:38:00 2005 | ++-------+-------------+-------------+---------------+---------+----------------+------------------+-----------+----------+-------------------------------------------------------+ +3 rows in set (0.00 sec) + +ties the trait data (PublishData) with the inbredsetid (matching +PublishFreeze.InbredSetId), locus and publication. + +select * from PublishFreeze -> ; ++----+------------+--------------------------+-------------+------------+--------+-------------+-----------------+-----------------+ +| Id | Name | FullName | ShortName | CreateTime | public | InbredSetId | confidentiality | AuthorisedUsers | ++----+------------+--------------------------+-------------+------------+--------+-------------+-----------------+-----------------+ +| 1 | BXDPublish | BXD Published Phenotypes | BXDPublish | 2004-07-17 | 2 | 1 | 0 | NULL | +| 18 | HLCPublish | HLC Published Phenotypes | HLC Publish | 2012-02-20 | 2 | 34 | 0 | NULL | ++----+------------+--------------------------+-------------+------------+--------+-------------+-----------------+-----------------+ +2 rows in set (0.02 sec) + +which gives us the datasets. + +GeneNetwork1 has a limited REST interface, if you do : curl "http://robot.genenetwork.org/webqtl/main.py?cmd=get&probeset=1443823_s_at&db=HC_M2_0606_P" @@ -1082,6 +1143,9 @@ we get : ProbeSetID B6D2F1 C57BL/6J DBA/2J BXD1 BXD2 BXD5 BXD6 BXD8 BXD9 BXD11 BXD12 BXD13 BXD15 BXD16 BXD19 BXD20 BXD21 BXD22 BXD23 BXD24 BXD27 BXD28 BXD29 BXD31 BXD32 BXD33 BXD34 BXD38 BXD39 BXD40 BXD42 BXD67 BXD68 BXD43 BXD44 BXD45 BXD48 BXD50 BXD51 BXD55 BXD60 BXD61 BXD62 BXD63 BXD64 BXD65 BXD66 BXD69 BXD70 BXD73 BXD74 BXD75 BXD76 BXD77 BXD79 BXD73a BXD83 BXD84 BXD85 BXD86 BXD87 BXD89 BXD90 BXD65b BXD93 BXD94 A/J AKR/J C3H/HeJ C57BL/6ByJ CXB1 CXB2 CXB3 CXB4 CXB5 CXB6 CXB7 CXB8 CXB9 CXB10 CXB11 CXB12 CXB13 BXD48a 129S1/SvImJ BALB/cJ BALB/cByJ LG/J NOD/ShiLtJ PWD/PhJ BXD65a BXD98 BXD99 CAST/EiJ KK/HlJ WSB/EiJ NZO/HlLtJ PWK/PhJ D2B6F1 : 1443823_s_at 15.251 15.626 14.716 15.198 14.918 15.057 15.232 14.968 14.87 15.084 15.192 14.924 15.343 15.226 15.364 15.36 14.792 14.908 15.344 14.948 15.08 15.021 15.176 15.14 14.796 15.443 14.636 14.921 15.22 15.62 14.816 15.39 15.428 14.982 15.05 15.13 14.722 14.636 15.242 15.527 14.825 14.416 15.125 15.362 15.226 15.176 15.328 14.895 15.141 15.634 14.922 14.764 15.122 15.448 15.398 15.089 14.765 15.234 15.302 14.774 14.979 15.212 15.29 15.012 15.041 15.448 14.34 14.338 14.809 15.046 14.816 15.232 14.933 15.255 15.21 14.766 14.8 15.506 15.749 15.274 15.599 15.673 14.651 14.692 14.552 14.563 14.164 14.546 15.044 14.695 15.162 14.772 14.645 15.493 14.75 14.786 15.003 15.148 15.221 +(see https://github.com/genenetwork/gn_server/blob/master/doc/API.md +for the latest REST API). + getTraitData is defined in the file [[https://github.com/genenetwork/genenetwork/blob/master/web/webqtl/textUI/cmdClass.py#L134][web/webqtl/textUI/cmdClass.py]]. probe is None, so the code at line 199 is run @@ -1165,6 +1229,97 @@ select * from ProbeSetData limit 5; 5 rows in set (0.00 sec) linked by ProbeSetXRef.dataid. + +*** For PublishData: + +List datasets for BXD (InbredSetId=1): + +select * from PublishXRef where InbredSetId=1 limit 3; ++-------+-------------+-------------+---------------+---------+-----------+------------------+------------------+----------+--------------------------------------------------------------------------------+ +| Id | InbredSetId | PhenotypeId | PublicationId | DataId | Locus | LRS | additive | Sequence | comments | ++-------+-------------+-------------+---------------+---------+-----------+------------------+------------------+----------+--------------------------------------------------------------------------------+ +| 10001 | 1 | 4 | 116 | 8967043 | rs8253516 | 13.4974914158039 | 2.39444444444444 | 1 | robwilliams modified post_publication_description at Mon Jul 30 14:58:10 2012 + | +| 10002 | 1 | 10 | 116 | 8967044 | rs3666069 | 22.0042692151629 | 2.08178571428572 | 1 | robwilliams modified phenotype at Thu Oct 28 21:43:28 2010 + | +| 10003 | 1 | 15 | 116 | 8967045 | D18Mit4 | 15.5929163293343 | 19.0882352941176 | 1 | robwilliams modified phenotype at Mon May 23 20:52:19 2011 + | ++-------+-------------+-------------+---------------+---------+-----------+------------------+------------------+----------+--------------------------------------------------------------------------------+ + +where ID is the 'record' or, effectively, dataset. + +select distinct(publicationid) from PublishXRef where InbredSetId=1 limit 3; ++---------------+ +| publicationid | ++---------------+ +| 116 | +| 117 | +| 118 | ++---------------+ + +select distinct +PublishXRef.id,publicationid,phenotypeid,Phenotype.post_publication_description +from PublishXRef,Phenotype where InbredSetId=1 and +phenotypeid=Phenotype.id limit 3; ++-------+---------------+-------------+----------------------------------------------------------------------------------------------------------------------------+ +| id | publicationid | phenotypeid | post_publication_description | ++-------+---------------+-------------+----------------------------------------------------------------------------------------------------------------------------+ +| 10001 | 116 | 4 | Central nervous system, morphology: Cerebellum weight [mg] | +| 10002 | 116 | 10 | Central nervous system, morphology: Cerebellum weight after adjustment for covariance with brain size [mg] | +| 10003 | 116 | 15 | Central nervous system, morphology: Brain weight, male and female adult average, unadjusted for body weight, age, sex [mg] | ++-------+---------------+-------------+----------------------------------------------------------------------------------------------------------------------------+ + +The id field is the same that is used in the GN2 web interface and the +PublicationID ties the datasets together. + +To list trait values: + +SELECT Strain.Name, PublishData.id, PublishData.value from +(Strain,PublishData, PublishXRef) Where PublishData.StrainId = +Strain.id limit 3; + ++------+---------+-------+ +| Name | id | value | ++------+---------+-------+ +| CXB1 | 8966353 | 29.6 | +| CXB1 | 8966353 | 29.6 | +| CXB1 | 8966353 | 29.6 | ++------+---------+-------+ + +here id should match dataid again: + +SELECT Strain.Name, PublishData.id, PublishData.value from +(Strain,PublishData, PublishXRef) Where PublishData.StrainId = +Strain.id and PublishXRef.dataid=8967043 and +PublishXRef.dataid=PublishData.id limit 3; ++------+---------+-------+ +| Name | id | value | ++------+---------+-------+ +| BXD1 | 8967043 | 61.4 | +| BXD2 | 8967043 | 49 | +| BXD5 | 8967043 | 62.5 | ++------+---------+-------+ + +*** Datasets + +The REST API aims to present a unified interface for genotype and +phenotype data. Phenotype datasets appear in two major forms in the +database and we want to present them as one resource. + +Dataset names are defined in ProbeSetFreeze.name and Published.id -> +publication (we'll ignore the probe dataset that uses +ProbeFreeze.name). These tables should be meshed. It looks like the +ids are non-overlapping with the publish record IDs starting at 10,001 +(someone has been smart, though it sets the limit of probesets now to +10,000). + +The datasets are organized differently in these tables. All published +BXD data is grouped on BXDpublished with the publications as +'datasets'. So, that is how we list them in the REST API. + +To fetch all the datasets we first list ProbeSetFreeze entries. Then +we list the Published entries. + ** Fetch genotype information *** SNPs diff --git a/etc/default_settings.py b/etc/default_settings.py index d8e57f38..08eae024 100644 --- a/etc/default_settings.py +++ b/etc/default_settings.py @@ -2,26 +2,31 @@ # webserver running in developer mode with limited console # output. Copy this file and run it from ./bin/genenetwork2 configfile # -# Note that these settings are fetched in ./wqflask/utilities/tools.py +# Note: these settings are fetched in ./wqflask/utilities/tools.py # which has support for overriding them through environment variables, # e.g. # # env LOG_SQL=True USE_REDIS=False ./bin/genenetwork2 # env LOG_LEVEL=DEBUG ./bin/genenetwork2 ~/gn2_settings.py # -# Note also that in the near future we will additionally fetch +# Note: in the near future we will additionally fetch # settings from a JSON file # -# Note that values for False and 0 have to be strings here - otherwise +# Note: values for False and 0 have to be strings here - otherwise # Flask won't pick them up +# +# For GNU Guix deployment also check the paths in +# +# ~/.guix-profile/lib/python2.7/site-packages/genenetwork2-2.0-py2.7.egg/etc/default_settings.py import os import sys +GN_VERSION = open("../VERSION","r").read() SQL_URI = "mysql://gn2:mysql_password@localhost/db_webqtl_s" SQLALCHEMY_DATABASE_URI = 'mysql://gn2:mysql_password@localhost/db_webqtl_s' SQLALCHEMY_POOL_RECYCLE = 3600 -GN_SERVER_URL = "http://localhost:8880/" +GN_SERVER_URL = "http://test-gn2.genenetwork.org/" # ---- Flask configuration (see website) TRAP_BAD_REQUEST_ERRORS = True @@ -32,7 +37,7 @@ SECURITY_RECOVERABLE = True SECURITY_EMAIL_SENDER = "no-reply@genenetwork.org" SECURITY_POST_LOGIN_VIEW = "/thank_you" -SERVER_PORT = 5003 +SERVER_PORT = 5003 # running on localhost SECRET_HMAC_CODE = '\x08\xdf\xfa\x93N\x80\xd9\\H@\\\x9f`\x98d^\xb4a;\xc6OM\x946a\xbc\xfc\x80:*\xebc' # ---- Behavioural settings (defaults) note that logger and log levels can @@ -40,6 +45,7 @@ SECRET_HMAC_CODE = '\x08\xdf\xfa\x93N\x80\xd9\\H@\\\x9f`\x98d^\xb4a;\xc6OM\x946a WEBSERVER_MODE = 'DEV' # Python webserver mode (DEBUG|DEV|PROD) WEBSERVER_BRANDING = None # Set the branding (nyi) WEBSERVER_DEPLOY = None # Deployment specifics (nyi) +WEBSERVER_URL = "http://localhost:"+str(SERVER_PORT)+"/" # external URL LOG_LEVEL = 'WARNING' # Logger mode (DEBUG|INFO|WARNING|ERROR|CRITICAL) LOG_LEVEL_DEBUG = '0' # logger.debugf log level (0-5, 5 = show all) @@ -50,6 +56,11 @@ LOG_BENCH = True # Log bench marks USE_REDIS = True # REDIS caching (note that redis will be phased out) USE_GN_SERVER = 'False' # Use GN_SERVER SQL calls +# Paths to JS libraries + +JS_BIODALLIANCE = os.environ['HOME']+"/genenetwork/biodalliance" +JS_TWITTER_POST_FETCHER = os.environ['HOME']+"/genenetwork/Twitter-Post-Fetcher" + # ---- Path overrides for Genenetwork # TMPDIR is normally picked up from the environment HOME=os.environ['HOME'] @@ -58,6 +69,7 @@ GENENETWORK_FILES = HOME+"/gn2_data" # base dir for all static data files LOCAL_PRIVATE_FILES = HOME+"/gn2_private_data" # private static data files # ---- GN2 Executables +# Paths to invoked binaries PYLMM_COMMAND = str.strip(os.popen("which pylmm_redis").read()) PLINK_COMMAND = str.strip(os.popen("which plink2").read()) GEMMA_COMMAND = str.strip(os.popen("which gemma").read()) diff --git a/test/lib/gntest.rb b/test/lib/gntest.rb index 865ef51d..5b21b3d5 100644 --- a/test/lib/gntest.rb +++ b/test/lib/gntest.rb @@ -1,5 +1,6 @@ require 'minitest/autorun' require 'mechanize' +require 'json' # ---- Use some default parameters if not set $host = "http://localhost:5003" if !$host diff --git a/test/lib/mapping.rb b/test/lib/mapping.rb index d6a3cd7b..20e5bd40 100644 --- a/test/lib/mapping.rb +++ b/test/lib/mapping.rb @@ -36,6 +36,7 @@ describe MappingTest do json, ({'Content-Type' => 'application/x-www-form-urlencoded'})) form = page.forms_with("marker_regression")[0] + p form form.fields.select { |fld| fld.name == 'dataset' }.first.value.must_equal 'HC_M2_0606_P' form.fields.select { |fld| fld.name == 'value:BXD1' }.first.value.must_equal "15.034" end diff --git a/wqflask/base/data_set.py b/wqflask/base/data_set.py index fddfce58..54dd3c4b 100644 --- a/wqflask/base/data_set.py +++ b/wqflask/base/data_set.py @@ -44,7 +44,7 @@ from db import webqtlDatabaseFunction from utility import webqtlUtil from utility.benchmark import Bench from utility import chunks -from utility.tools import locate, locate_ignore_error +from utility.tools import locate, locate_ignore_error, flat_files from maintenance import get_group_samplelists @@ -53,7 +53,7 @@ from pprint import pformat as pf from db.gn_server import menu_main from db.call import fetchall,fetchone,fetch1 -from utility.tools import USE_GN_SERVER, USE_REDIS +from utility.tools import USE_GN_SERVER, USE_REDIS, flat_files, flat_file_exists from utility.logger import getLogger logger = getLogger(__name__ ) @@ -226,7 +226,7 @@ class Markers(object): class HumanMarkers(Markers): def __init__(self, name, specified_markers = []): - marker_data_fh = open(locate('genotype') + '/' + name + '.bim') + marker_data_fh = open(flat_files('mapping') + '/' + name + '.bim') self.markers = [] for line in marker_data_fh: splat = line.strip().split() @@ -264,96 +264,74 @@ class DatasetGroup(object): def __init__(self, dataset): """This sets self.group and self.group_id""" #logger.debug("DATASET NAME2:", dataset.name) - self.name, self.id = fetchone(dataset.query_for_group) + self.name, self.id, self.genetic_type = fetchone(dataset.query_for_group) if self.name == 'BXD300': self.name = "BXD" self.f1list = None self.parlist = None self.get_f1_parent_strains() - #logger.debug("parents/f1s: {}:{}".format(self.parlist, self.f1list)) + + self.accession_id = self.get_accession_id() + self.mapping_id, self.mapping_names = self.get_mapping_methods() self.species = webqtlDatabaseFunction.retrieve_species(self.name) self.incparentsf1 = False self.allsamples = None self._datasets = None + self.genofile = None + + def get_accession_id(self): + results = g.db.execute("""select InfoFiles.GN_AccesionId from InfoFiles, PublishFreeze, InbredSet where + InbredSet.Name = %s and + PublishFreeze.InbredSetId = InbredSet.Id and + InfoFiles.InfoPageName = PublishFreeze.Name and + PublishFreeze.public > 0 and + PublishFreeze.confidentiality < 1 order by + PublishFreeze.CreateTime desc""", (self.name)).fetchone() + + if results != None: + return str(results[0]) + else: + return "None" + + def get_mapping_methods(self): + + mapping_id = g.db.execute("select MappingMethodId from InbredSet where Name= '%s'" % self.name).fetchone()[0] + if mapping_id == "1": + mapping_names = ["QTLReaper", "PYLMM", "R/qtl"] + elif mapping_id == "2": + mapping_names = ["GEMMA"] + elif mapping_id == "4": + mapping_names = ["PLINK"] + else: + mapping_names = [] + + return mapping_id, mapping_names def get_specified_markers(self, markers = []): self.markers = HumanMarkers(self.name, markers) def get_markers(self): - #logger.debug("self.species is:", self.species) - if self.species == "human": + logger.debug("self.species is:", self.species) + + def check_plink_gemma(): + if flat_file_exists("mapping"): + MAPPING_PATH = flat_files("mapping")+"/" + if (os.path.isfile(MAPPING_PATH+self.name+".bed") and + (os.path.isfile(MAPPING_PATH+self.name+".map") or + os.path.isfile(MAPPING_PATH+self.name+".bim"))): + return True + return False + + if check_plink_gemma(): marker_class = HumanMarkers else: - marker_class = Markers + marker_class = Markers self.markers = marker_class(self.name) - def datasets(self): - key = "group_dataset_menu:v2:" + self.name - logger.debug("key is2:", key) - dataset_menu = [] - logger.debug("[tape4] webqtlConfig.PUBLICTHRESH:", webqtlConfig.PUBLICTHRESH) - logger.debug("[tape4] type webqtlConfig.PUBLICTHRESH:", type(webqtlConfig.PUBLICTHRESH)) - the_results = fetchall(''' - (SELECT '#PublishFreeze',PublishFreeze.FullName,PublishFreeze.Name - FROM PublishFreeze,InbredSet - WHERE PublishFreeze.InbredSetId = InbredSet.Id - and InbredSet.Name = '%s' - and PublishFreeze.public > %s) - UNION - (SELECT '#GenoFreeze',GenoFreeze.FullName,GenoFreeze.Name - FROM GenoFreeze, InbredSet - WHERE GenoFreeze.InbredSetId = InbredSet.Id - and InbredSet.Name = '%s' - and GenoFreeze.public > %s) - UNION - (SELECT Tissue.Name, ProbeSetFreeze.FullName,ProbeSetFreeze.Name - FROM ProbeSetFreeze, ProbeFreeze, InbredSet, Tissue - WHERE ProbeSetFreeze.ProbeFreezeId = ProbeFreeze.Id - and ProbeFreeze.TissueId = Tissue.Id - and ProbeFreeze.InbredSetId = InbredSet.Id - and InbredSet.Name like %s - and ProbeSetFreeze.public > %s - ORDER BY Tissue.Name, ProbeSetFreeze.CreateTime desc, ProbeSetFreeze.AvgId) - ''' % (self.name, webqtlConfig.PUBLICTHRESH, - self.name, webqtlConfig.PUBLICTHRESH, - "'" + self.name + "'", webqtlConfig.PUBLICTHRESH)) - - #for tissue_name, dataset in itertools.groupby(the_results, itemgetter(0)): - for dataset_item in the_results: - tissue_name = dataset_item[0] - dataset = dataset_item[1] - dataset_short = dataset_item[2] - if tissue_name in ['#PublishFreeze', '#GenoFreeze']: - dataset_menu.append(dict(tissue=None, datasets=[(dataset, dataset_short)])) - else: - dataset_sub_menu = [item[1:] for item in dataset] - - tissue_already_exists = False - tissue_position = None - for i, tissue_dict in enumerate(dataset_menu): - if tissue_dict['tissue'] == tissue_name: - tissue_already_exists = True - tissue_position = i - break - - if tissue_already_exists: - #logger.debug("dataset_menu:", dataset_menu[i]['datasets']) - dataset_menu[i]['datasets'].append((dataset, dataset_short)) - else: - dataset_menu.append(dict(tissue=tissue_name, - datasets=[(dataset, dataset_short)])) - - if USE_REDIS: - Redis.set(key, pickle.dumps(dataset_menu, pickle.HIGHEST_PROTOCOL)) - Redis.expire(key, 60*5) - self._datasets = dataset_menu - - return self._datasets - def get_f1_parent_strains(self): try: # NL, 07/27/2010. ParInfo has been moved from webqtlForm.py to webqtlUtil.py; @@ -408,7 +386,10 @@ class DatasetGroup(object): genotype_1 = reaper.Dataset() # reaper barfs on unicode filenames, so here we ensure it's a string - full_filename = str(locate(self.name+'.geno','genotype')) + if self.genofile: + full_filename = str(locate(self.genofile, 'genotype')) + else: + full_filename = str(locate(self.name + '.geno', 'genotype')) genotype_1.read(full_filename) if genotype_1.type == "group" and self.parlist: @@ -427,6 +408,71 @@ class DatasetGroup(object): return genotype +def datasets(group_name, this_group = None): + key = "group_dataset_menu:v2:" + group_name + logger.debug("key is2:", key) + dataset_menu = [] + logger.debug("[tape4] webqtlConfig.PUBLICTHRESH:", webqtlConfig.PUBLICTHRESH) + logger.debug("[tape4] type webqtlConfig.PUBLICTHRESH:", type(webqtlConfig.PUBLICTHRESH)) + the_results = fetchall(''' + (SELECT '#PublishFreeze',PublishFreeze.FullName,PublishFreeze.Name + FROM PublishFreeze,InbredSet + WHERE PublishFreeze.InbredSetId = InbredSet.Id + and InbredSet.Name = '%s' + and PublishFreeze.public > %s) + UNION + (SELECT '#GenoFreeze',GenoFreeze.FullName,GenoFreeze.Name + FROM GenoFreeze, InbredSet + WHERE GenoFreeze.InbredSetId = InbredSet.Id + and InbredSet.Name = '%s' + and GenoFreeze.public > %s) + UNION + (SELECT Tissue.Name, ProbeSetFreeze.FullName,ProbeSetFreeze.Name + FROM ProbeSetFreeze, ProbeFreeze, InbredSet, Tissue + WHERE ProbeSetFreeze.ProbeFreezeId = ProbeFreeze.Id + and ProbeFreeze.TissueId = Tissue.Id + and ProbeFreeze.InbredSetId = InbredSet.Id + and InbredSet.Name like %s + and ProbeSetFreeze.public > %s + ORDER BY Tissue.Name, ProbeSetFreeze.CreateTime desc, ProbeSetFreeze.AvgId) + ''' % (group_name, webqtlConfig.PUBLICTHRESH, + group_name, webqtlConfig.PUBLICTHRESH, + "'" + group_name + "'", webqtlConfig.PUBLICTHRESH)) + + #for tissue_name, dataset in itertools.groupby(the_results, itemgetter(0)): + for dataset_item in the_results: + tissue_name = dataset_item[0] + dataset = dataset_item[1] + dataset_short = dataset_item[2] + if tissue_name in ['#PublishFreeze', '#GenoFreeze']: + dataset_menu.append(dict(tissue=None, datasets=[(dataset, dataset_short)])) + else: + dataset_sub_menu = [item[1:] for item in dataset] + + tissue_already_exists = False + tissue_position = None + for i, tissue_dict in enumerate(dataset_menu): + if tissue_dict['tissue'] == tissue_name: + tissue_already_exists = True + tissue_position = i + break + + if tissue_already_exists: + #logger.debug("dataset_menu:", dataset_menu[i]['datasets']) + dataset_menu[i]['datasets'].append((dataset, dataset_short)) + else: + dataset_menu.append(dict(tissue=tissue_name, + datasets=[(dataset, dataset_short)])) + + if USE_REDIS: + Redis.set(key, pickle.dumps(dataset_menu, pickle.HIGHEST_PROTOCOL)) + Redis.expire(key, 60*5) + + if this_group != None: + this_group._datasets = dataset_menu + return this_group._datasets + else: + return dataset_menu class DataSet(object): """ @@ -650,7 +696,7 @@ class PhenotypeDataSet(DataSet): self.query_for_group = ''' SELECT - InbredSet.Name, InbredSet.Id + InbredSet.Name, InbredSet.Id, InbredSet.GeneticType FROM InbredSet, PublishFreeze WHERE @@ -720,8 +766,8 @@ class PhenotypeDataSet(DataSet): if this_trait.lrs: query = """ select Geno.Chr, Geno.Mb from Geno, Species - where Species.Name = %s and - Geno.Name = %s and + where Species.Name = '%s' and + Geno.Name = '%s' and Geno.SpeciesId = Species.Id """ % (species, this_trait.locus) logger.sql(query) @@ -793,7 +839,7 @@ class GenotypeDataSet(DataSet): self.query_for_group = ''' SELECT - InbredSet.Name, InbredSet.Id + InbredSet.Name, InbredSet.Id, InbredSet.GeneticType FROM InbredSet, GenoFreeze WHERE @@ -919,7 +965,7 @@ class MrnaAssayDataSet(DataSet): self.query_for_group = ''' SELECT - InbredSet.Name, InbredSet.Id + InbredSet.Name, InbredSet.Id, InbredSet.GeneticType FROM InbredSet, ProbeSetFreeze, ProbeFreeze WHERE diff --git a/wqflask/base/trait.py b/wqflask/base/trait.py index 32032ba7..bf87e879 100644 --- a/wqflask/base/trait.py +++ b/wqflask/base/trait.py @@ -23,6 +23,8 @@ from flask import Flask, g, request from utility.logger import getLogger logger = getLogger(__name__ ) +from wqflask import user_manager + def print_mem(stage=""): mem = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss print("{}: {}".format(stage, mem/1024)) @@ -55,6 +57,7 @@ class GeneralTrait(object): self.lrs = None self.pvalue = None self.mean = None + self.additive = None self.num_overlap = None self.strand_probe = None self.symbol = None @@ -69,20 +72,10 @@ class GeneralTrait(object): # Todo: These two lines are necessary most of the time, but perhaps not all of the time # So we could add a simple if statement to short-circuit this if necessary - self.retrieve_info(get_qtl_info=get_qtl_info) + self = retrieve_trait_info(self, self.dataset, get_qtl_info=get_qtl_info) if get_sample_info != False: - self.retrieve_sample_data() - - - def jsonable(self): - """Return a dict suitable for using as json + self = retrieve_sample_data(self, self.dataset) - Actual turning into json doesn't happen here though""" - return dict(name=self.name, - dataset=self.dataset.name, - description=self.description_display, - mean=self.mean) - def get_name(self): stringy = "" @@ -187,410 +180,6 @@ class GeneralTrait(object): return samples, vals, the_vars, sample_aliases - # - # In ProbeSet, there are maybe several annotations match one sequence - # so we need use sequence(BlatSeq) as the identification, when we update - # one annotation, we update the others who match the sequence also. - # - # Hongqiang Li, 3/3/2008 - # - #def getSequence(self): - # assert self.cursor - # if self.dataset.type == 'ProbeSet': - # self.cursor.execute(''' - # SELECT - # ProbeSet.BlatSeq - # FROM - # ProbeSet, ProbeSetFreeze, ProbeSetXRef - # WHERE - # ProbeSet.Id=ProbeSetXRef.ProbeSetId and - # ProbeSetFreeze.Id = ProbeSetXRef.ProbSetFreezeId and - # ProbeSet.Name = %s - # ProbeSetFreeze.Name = %s - # ''', self.name, self.dataset.name) - # #self.cursor.execute(query) - # results = self.fetchone() - # - # return results[0] - - - - def retrieve_sample_data(self, samplelist=None): - if samplelist == None: - samplelist = [] - - results = self.dataset.retrieve_sample_data(self.name) - - # Todo: is this necessary? If not remove - self.data.clear() - - all_samples_ordered = self.dataset.group.all_samples_ordered() - - if results: - for item in results: - name, value, variance, num_cases, name2 = item - if not samplelist or (samplelist and name in samplelist): - self.data[name] = webqtlCaseData(*item) #name, value, variance, num_cases) - - def retrieve_info(self, get_qtl_info=False): - assert self.dataset, "Dataset doesn't exist" - if self.dataset.type == 'Publish': - query = """ - SELECT - PublishXRef.Id, Publication.PubMed_ID, - Phenotype.Pre_publication_description, Phenotype.Post_publication_description, Phenotype.Original_description, - Phenotype.Pre_publication_abbreviation, Phenotype.Post_publication_abbreviation, - Phenotype.Lab_code, Phenotype.Submitter, Phenotype.Owner, Phenotype.Authorized_Users, - Publication.Authors, Publication.Title, Publication.Abstract, - Publication.Journal, Publication.Volume, Publication.Pages, - Publication.Month, Publication.Year, PublishXRef.Sequence, - Phenotype.Units, PublishXRef.comments - FROM - PublishXRef, Publication, Phenotype, PublishFreeze - WHERE - PublishXRef.Id = %s AND - Phenotype.Id = PublishXRef.PhenotypeId AND - Publication.Id = PublishXRef.PublicationId AND - PublishXRef.InbredSetId = PublishFreeze.InbredSetId AND - PublishFreeze.Id = %s - """ % (self.name, self.dataset.id) - - logger.sql(query) - trait_info = g.db.execute(query).fetchone() - - - #XZ, 05/08/2009: Xiaodong add this block to use ProbeSet.Id to find the probeset instead of just using ProbeSet.Name - #XZ, 05/08/2009: to avoid the problem of same probeset name from different platforms. - elif self.dataset.type == 'ProbeSet': - display_fields_string = ', ProbeSet.'.join(self.dataset.display_fields) - display_fields_string = 'ProbeSet.' + display_fields_string - query = """ - SELECT %s - FROM ProbeSet, ProbeSetFreeze, ProbeSetXRef - WHERE - ProbeSetXRef.ProbeSetFreezeId = ProbeSetFreeze.Id AND - ProbeSetXRef.ProbeSetId = ProbeSet.Id AND - ProbeSetFreeze.Name = '%s' AND - ProbeSet.Name = '%s' - """ % (escape(display_fields_string), - escape(self.dataset.name), - escape(str(self.name))) - logger.sql(query) - trait_info = g.db.execute(query).fetchone() - #XZ, 05/08/2009: We also should use Geno.Id to find marker instead of just using Geno.Name - # to avoid the problem of same marker name from different species. - elif self.dataset.type == 'Geno': - display_fields_string = string.join(self.dataset.display_fields,',Geno.') - display_fields_string = 'Geno.' + display_fields_string - query = """ - SELECT %s - FROM Geno, GenoFreeze, GenoXRef - WHERE - GenoXRef.GenoFreezeId = GenoFreeze.Id AND - GenoXRef.GenoId = Geno.Id AND - GenoFreeze.Name = '%s' AND - Geno.Name = '%s' - """ % (escape(display_fields_string), - escape(self.dataset.name), - escape(self.name)) - logger.sql(query) - trait_info = g.db.execute(query).fetchone() - else: #Temp type - query = """SELECT %s FROM %s WHERE Name = %s""" - logger.sql(query) - trait_info = g.db.execute(query, - (string.join(self.dataset.display_fields,','), - self.dataset.type, self.name)).fetchone() - if trait_info: - self.haveinfo = True - - #XZ: assign SQL query result to trait attributes. - for i, field in enumerate(self.dataset.display_fields): - holder = trait_info[i] - if isinstance(trait_info[i], basestring): - holder = unicode(trait_info[i], "utf8", "ignore") - setattr(self, field, holder) - - if self.dataset.type == 'Publish': - self.confidential = 0 - if self.pre_publication_description and not self.pubmed_id: - self.confidential = 1 - - description = self.post_publication_description - - #If the dataset is confidential and the user has access to confidential - #phenotype traits, then display the pre-publication description instead - #of the post-publication description - if self.confidential: - self.description_display = self.pre_publication_description - - #if not webqtlUtil.hasAccessToConfidentialPhenotypeTrait( - # privilege=self.dataset.privilege, - # userName=self.dataset.userName, - # authorized_users=self.authorized_users): - # - # description = self.pre_publication_description - else: - if description: - self.description_display = description.strip() - else: - self.description_display = "" - - if not self.year.isdigit(): - self.pubmed_text = "N/A" - else: - self.pubmed_text = self.year - - if self.pubmed_id: - self.pubmed_link = webqtlConfig.PUBMEDLINK_URL % self.pubmed_id - - - self.homologeneid = None - if self.dataset.type == 'ProbeSet' and self.dataset.group: - if self.geneid: - #XZ, 05/26/2010: From time to time, this query get error message because some geneid values in database are not number. - #XZ: So I have to test if geneid is number before execute the query. - #XZ: The geneid values in database should be cleaned up. - #try: - # float(self.geneid) - # geneidIsNumber = True - #except ValueError: - # geneidIsNumber = False - #if geneidIsNumber: - query = """ - SELECT - HomologeneId - FROM - Homologene, Species, InbredSet - WHERE - Homologene.GeneId ='%s' AND - InbredSet.Name = '%s' AND - InbredSet.SpeciesId = Species.Id AND - Species.TaxonomyId = Homologene.TaxonomyId - """ % (escape(str(self.geneid)), escape(self.dataset.group.name)) - logger.sql(query) - result = g.db.execute(query).fetchone() - #else: - # result = None - - if result: - self.homologeneid = result[0] - - description_string = unicode(str(self.description).strip(codecs.BOM_UTF8), 'utf-8') - target_string = unicode(str(self.probe_target_description).strip(codecs.BOM_UTF8), 'utf-8') - - if len(description_string) > 1 and description_string != 'None': - description_display = description_string - else: - description_display = self.symbol - - if (len(description_display) > 1 and description_display != 'N/A' and - len(target_string) > 1 and target_string != 'None'): - description_display = description_display + '; ' + target_string.strip() - - # Save it for the jinja2 template - self.description_display = description_display - - #XZ: trait_location_value is used for sorting - trait_location_repr = 'N/A' - trait_location_value = 1000000 - - if self.chr and self.mb: - #Checks if the chromosome number can be cast to an int (i.e. isn't "X" or "Y") - #This is so we can convert the location to a number used for sorting - trait_location_value = convert_location_to_value(self.chr, self.mb) - #try: - # trait_location_value = int(self.chr)*1000 + self.mb - #except ValueError: - # if self.chr.upper() == 'X': - # trait_location_value = 20*1000 + self.mb - # else: - # trait_location_value = (ord(str(self.chr).upper()[0])*1000 + - # self.mb) - - #ZS: Put this in function currently called "convert_location_to_value" - self.location_repr = 'Chr%s: %.6f' % (self.chr, float(self.mb)) - self.location_value = trait_location_value - - - if get_qtl_info: - #LRS and its location - self.LRS_score_repr = "N/A" - self.LRS_score_value = 0 - self.LRS_location_repr = "N/A" - self.LRS_location_value = 1000000 - if self.dataset.type == 'ProbeSet' and not self.cellid: - query = """ - SELECT - ProbeSetXRef.Locus, ProbeSetXRef.LRS, ProbeSetXRef.pValue, ProbeSetXRef.mean, ProbeSetXRef.additive - FROM - ProbeSetXRef, ProbeSet - WHERE - ProbeSetXRef.ProbeSetId = ProbeSet.Id AND - ProbeSet.Name = "{}" AND - ProbeSetXRef.ProbeSetFreezeId ={} - """.format(self.name, self.dataset.id) - logger.sql(query) - trait_qtl = g.db.execute(query).fetchone() - if trait_qtl: - self.locus, self.lrs, self.pvalue, self.mean, self.additive= trait_qtl - if self.locus: - query = """ - select Geno.Chr, Geno.Mb from Geno, Species - where Species.Name = '{}' and - Geno.Name = '{}' and - Geno.SpeciesId = Species.Id - """.format(self.dataset.group.species, self.locus) - logger.sql(query) - result = g.db.execute(query).fetchone() - if result: - self.locus_chr = result[0] - self.locus_mb = result[1] - else: - self.locus = self.locus_chr = self.locus_mb = self.additive = "" - else: - self.locus = self.locus_chr = self.locus_mb = self.additive = "" - else: - self.locus = self.locus_chr = self.locus_mb = self.lrs = self.pvalue = self.mean = self.additive = "" - - - if self.dataset.type == 'Publish': - query = """ - SELECT - PublishXRef.Locus, PublishXRef.LRS, PublishXRef.additive - FROM - PublishXRef, PublishFreeze - WHERE - PublishXRef.Id = %s AND - PublishXRef.InbredSetId = PublishFreeze.InbredSetId AND - PublishFreeze.Id =%s - """ % (self.name, self.dataset.id) - logger.sql(query) - trait_qtl = g.db.execute(query).fetchone() - if trait_qtl: - self.locus, self.lrs, self.additive = trait_qtl - if self.locus: - query = """ - select Geno.Chr, Geno.Mb from Geno, Species - where Species.Name = '{}' and - Geno.Name = '{}' and - Geno.SpeciesId = Species.Id - """.format(self.dataset.group.species, self.locus) - logger.sql(query) - result = g.db.execute(query).fetchone() - if result: - self.locus_chr = result[0] - self.locus_mb = result[1] - else: - self.locus = self.locus_chr = self.locus_mb = self.additive = "" - else: - self.locus = self.locus_chr = self.locus_mb = self.additive = "" - else: - self.locus = self.lrs = self.additive = "" - - if (self.dataset.type == 'Publish' or self.dataset.type == "ProbeSet") and self.locus_chr != "" and self.locus_mb != "": - #XZ: LRS_location_value is used for sorting - try: - LRS_location_value = int(self.locus_chr)*1000 + float(self.locus_mb) - except: - if self.locus_chr.upper() == 'X': - LRS_location_value = 20*1000 + float(self.locus_mb) - else: - LRS_location_value = ord(str(self.locus_chr).upper()[0])*1000 + float(self.locus_mb) - - self.LRS_location_repr = LRS_location_repr = 'Chr%s: %.6f' % (self.locus_chr, float(self.locus_mb)) - if self.lrs != "": - self.LRS_score_repr = LRS_score_repr = '%3.1f' % self.lrs - self.LRS_score_value = LRS_score_value = self.lrs - else: - raise KeyError, `self.name`+' information is not found in the database.' - - def genHTML(self, formName = "", dispFromDatabase=0, privilege="guest", userName="Guest", authorized_users=""): - if not self.haveinfo: - self.retrieveInfo() - - if self.dataset.type == 'Publish': - PubMedLink = "" - if self.pubmed_id: - PubMedLink = HT.Href(text="PubMed %d : " % self.pubmed_id, - target = "_blank", url = webqtlConfig.PUBMEDLINK_URL % self.pubmed_id) - else: - PubMedLink = HT.Span("Unpublished : ", Class="fs15") - - if formName: - setDescription2 = HT.Href(url="javascript:showDatabase3('%s','%s','%s','')" % - (formName, self.dataset.name, self.name), Class = "fs14") - else: - setDescription2 = HT.Href(url="javascript:showDatabase2('%s','%s','')" % - (self.dataset.name,self.name), Class = "fs14") - - if self.confidential and not webqtlUtil.hasAccessToConfidentialPhenotypeTrait(privilege=privilege, userName=userName, authorized_users=authorized_users): - setDescription2.append('RecordID/%s - %s' % (self.name, self.pre_publication_description)) - else: - setDescription2.append('RecordID/%s - %s' % (self.name, self.post_publication_description)) - - #XZ 03/26/2011: Xiaodong comment out the following two lins as Rob asked. Need to check with Rob why in PublishXRef table, there are few row whose Sequence > 1. - #if self.sequence > 1: - # setDescription2.append(' btach %d' % self.sequence) - if self.authors: - a1 = string.split(self.authors,',')[0] - while a1[0] == '"' or a1[0] == "'" : - a1 = a1[1:] - setDescription2.append(' by ') - setDescription2.append(HT.Italic('%s, and colleagues' % a1)) - setDescription = HT.Span(PubMedLink, setDescription2) - - elif self.dataset.type == 'Temp': - setDescription = HT.Href(text="%s" % (self.description),url="javascript:showDatabase2\ - ('%s','%s','')" % (self.dataset.name,self.name), Class = "fs14") - setDescription = HT.Span(setDescription) - - elif self.dataset.type == 'Geno': # Genome DB only available for single search - if formName: - setDescription = HT.Href(text="Locus %s [Chr %s @ %s Mb]" % (self.name,self.chr,\ - '%2.3f' % self.mb),url="javascript:showDatabase3('%s','%s','%s','')" % \ - (formName, self.dataset.name, self.name), Class = "fs14") - else: - setDescription = HT.Href(text="Locus %s [Chr %s @ %s Mb]" % (self.name,self.chr,\ - '%2.3f' % self.mb),url="javascript:showDatabase2('%s','%s','')" % \ - (self.dataset.name,self.name), Class = "fs14") - - setDescription = HT.Span(setDescription) - - else: - if self.cellid: - if formName: - setDescription = HT.Href(text="ProbeSet/%s/%s" % (self.name, self.cellid),url=\ - "javascript:showDatabase3('%s','%s','%s','%s')" % (formName, self.dataset.name,self.name,self.cellid), \ - Class = "fs14") - else: - setDescription = HT.Href(text="ProbeSet/%s/%s" % (self.name,self.cellid),url=\ - "javascript:showDatabase2('%s','%s','%s')" % (self.dataset.name,self.name,self.cellid), \ - Class = "fs14") - else: - if formName: - setDescription = HT.Href(text="ProbeSet/%s" % self.name, url=\ - "javascript:showDatabase3('%s','%s','%s','')" % (formName, self.dataset.name,self.name), \ - Class = "fs14") - else: - setDescription = HT.Href(text="ProbeSet/%s" % self.name, url=\ - "javascript:showDatabase2('%s','%s','')" % (self.dataset.name,self.name), \ - Class = "fs14") - if self.symbol and self.chr and self.mb: - setDescription.append(' [') - setDescription.append(HT.Italic('%s' % self.symbol,Class="cdg fwb")) - setDescription.append(' on Chr %s @ %s Mb]' % (self.chr,self.mb)) - if self.description: - setDescription.append(': %s' % self.description) - if self.probe_target_description: - setDescription.append('; %s' % self.probe_target_description) - setDescription = HT.Span(setDescription) - - if self.dataset.type != 'Temp' and dispFromDatabase: - setDescription.append( ' --- FROM : ') - setDescription.append(self.dataset.genHTML(Class='cori')) - return setDescription - @property def name_header_fmt(self): '''Return a human-readable name for use in page header''' @@ -618,7 +207,7 @@ class GeneralTrait(object): formatted = self.post_publication_description else: formatted = "Not available" - return formatted.capitalize() + return formatted @property def alias_fmt(self): @@ -656,62 +245,48 @@ class GeneralTrait(object): return fmt - - def get_database(self): - """ - Returns the database, and the url referring to the database if it exists - - We're going to to return two values here, and we don't want to have to call this twice from - the template. So it's not a property called from the template, but instead is called from the view - - """ - if self.cellid: - query = """ select ProbeFreeze.Name from ProbeFreeze, ProbeSetFreeze where - ProbeFreeze.Id = - ProbeSetFreeze.ProbeFreezeId AND - ProbeSetFreeze.Id = %d""" % thisTrait.dataset.id - logger.sql(query) - probeDBName = g.db.execute(query).fetchone()[0] - return dict(name = probeDBName, - url = None) - else: - return dict(name = self.dataset.fullname, - url = webqtlConfig.INFOPAGEHREF % self.dataset.name) - - def calculate_correlation(self, values, method): - """Calculate the correlation value and p value according to the method specified""" - - #ZS: This takes the list of values of the trait our selected trait is being correlated against and removes the values of the samples our trait has no value for - #There's probably a better way of dealing with this, but I'll have to ask Christian - updated_raw_values = [] - updated_values = [] - for i in range(len(values)): - if values[i] != "None": - updated_raw_values.append(self.raw_values[i]) - updated_values.append(values[i]) - - self.raw_values = updated_raw_values - values = updated_values - - if method == METHOD_SAMPLE_PEARSON or method == METHOD_LIT or method == METHOD_TISSUE_PEARSON: - corr, nOverlap = webqtlUtil.calCorrelation(self.raw_values, values, len(values)) - else: - corr, nOverlap = webqtlUtil.calCorrelationRank(self.raw_values, values, len(values)) - - self.correlation = corr - self.overlap = nOverlap - - if self.overlap < 3: - self.p_value = 1.0 - else: - #ZS - This is probably the wrong way to deal with this. Correlation values of 1.0 definitely exist (the trait correlated against itself), so zero division needs to br prevented. - if abs(self.correlation) >= 1.0: - self.p_value = 0.0 - else: - ZValue = 0.5*log((1.0+self.correlation)/(1.0-self.correlation)) - ZValue = ZValue*sqrt(self.overlap-3) - self.p_value = 2.0*(1.0 - reaper.normp(abs(ZValue))) - +# In ProbeSet, there are maybe several annotations match one sequence +# so we need use sequence(BlatSeq) as the identification, when we update +# one annotation, we update the others who match the sequence also. +# +# Hongqiang Li, 3/3/2008 +def getSequence(trait, dataset_name): + dataset = create_dataset(dataset_name) + + if dataset.type == 'ProbeSet': + results = g.db.execute(''' + SELECT + ProbeSet.BlatSeq + FROM + ProbeSet, ProbeSetFreeze, ProbeSetXRef + WHERE + ProbeSet.Id=ProbeSetXRef.ProbeSetId and + ProbeSetFreeze.Id = ProbeSetXRef.ProbSetFreezeId and + ProbeSet.Name = %s + ProbeSetFreeze.Name = %s + ''', trait.name, dataset.name).fetchone() + + return results[0] + +def retrieve_sample_data(trait, dataset, samplelist=None): + if samplelist == None: + samplelist = [] + + results = dataset.retrieve_sample_data(trait.name) + + # Todo: is this necessary? If not remove + trait.data.clear() + + all_samples_ordered = dataset.group.all_samples_ordered() + + if results: + for item in results: + name, value, variance, num_cases, name2 = item + if not samplelist or (samplelist and name in samplelist): + trait.data[name] = webqtlCaseData(*item) #name, value, variance, num_cases) + + return trait + def convert_location_to_value(chromosome, mb): try: location_value = int(chromosome)*1000 + float(mb) @@ -739,3 +314,398 @@ def get_sample_data(): # jsonable_sample_data[sample] = trait_ob.data[sample].value # #return jsonable_sample_data + +def jsonable(trait, dataset_name): + """Return a dict suitable for using as json + + Actual turning into json doesn't happen here though""" + + dataset = create_dataset(dataset_name) + + if dataset.type == "ProbeSet": + return dict(name=trait.name, + symbol=trait.symbol, + dataset=dataset.name, + description=trait.description_display, + mean=trait.mean, + location=trait.location_repr, + lrs_score=trait.LRS_score_repr, + lrs_location=trait.LRS_location_repr, + additive=trait.additive + ) + elif dataset.type == "Publish": + if trait.pubmed_id: + return dict(name=trait.name, + dataset=dataset.name, + description=trait.description_display, + authors=trait.authors, + pubmed_text=trait.pubmed_text, + pubmed_link=trait.pubmed_link, + lrs_score=trait.LRS_score_repr, + lrs_location=trait.LRS_location_repr, + additive=trait.additive + ) + else: + return dict(name=trait.name, + dataset=dataset.name, + description=trait.description_display, + authors=trait.authors, + pubmed_text=trait.pubmed_text, + lrs_score=trait.LRS_score_repr, + lrs_location=trait.LRS_location_repr, + additive=trait.additive + ) + elif dataset.type == "Geno": + return dict(name=trait.name, + dataset=dataset.name, + location=trait.location_repr + ) + else: + return dict() + +def jsonable_table_row(trait, dataset_name, index): + """Return a list suitable for json and intended to be displayed in a table + + Actual turning into json doesn't happen here though""" + + dataset = create_dataset(dataset_name) + + if dataset.type == "ProbeSet": + if trait.mean == "": + mean = "N/A" + else: + mean = "%.3f" % round(float(trait.mean), 2) + if trait.additive == "": + additive = "N/A" + else: + additive = "%.3f" % round(float(trait.additive), 2) + return ['<input type="checkbox" name="searchResult" class="checkbox trait_checkbox" value="' + user_manager.data_hmac('{}:{}'.format(str(trait.name), dataset.name)) + '">', + index, + '<a href="/show_trait?trait_id='+str(trait.name)+'&dataset='+dataset.name+'">'+str(trait.name)+'</a>', + trait.symbol, + trait.description_display, + trait.location_repr, + mean, + trait.LRS_score_repr, + trait.LRS_location_repr, + additive] + elif dataset.type == "Publish": + if trait.additive == "": + additive = "N/A" + else: + additive = "%.2f" % round(float(trait.additive), 2) + if trait.pubmed_id: + return ['<input type="checkbox" name="searchResult" class="checkbox trait_checkbox" value="' + user_manager.data_hmac('{}:{}'.format(str(trait.name), dataset.name)) + '">', + index, + '<a href="/show_trait?trait_id='+str(trait.name)+'&dataset='+dataset.name+'">'+str(trait.name)+'</a>', + trait.description_display, + trait.authors, + '<a href="' + trait.pubmed_link + '">' + trait.pubmed_text + '</href>', + trait.LRS_score_repr, + trait.LRS_location_repr, + additive] + else: + return ['<input type="checkbox" name="searchResult" class="checkbox trait_checkbox" value="' + user_manager.data_hmac('{}:{}'.format(str(trait.name), dataset.name)) + '">', + index, + '<a href="/show_trait?trait_id='+str(trait.name)+'&dataset='+dataset.name+'">'+str(trait.name)+'</a>', + trait.description_display, + trait.authors, + trait.pubmed_text, + trait.LRS_score_repr, + trait.LRS_location_repr, + additive] + elif dataset.type == "Geno": + return ['<input type="checkbox" name="searchResult" class="checkbox trait_checkbox" value="' + user_manager.data_hmac('{}:{}'.format(str(trait.name), dataset.name)) + '">', + index, + '<a href="/show_trait?trait_id='+str(trait.name)+'&dataset='+dataset.name+'">'+str(trait.name)+'</a>', + trait.location_repr] + else: + return dict() + +def retrieve_trait_info(trait, dataset, get_qtl_info=False): + assert dataset, "Dataset doesn't exist" + + if dataset.type == 'Publish': + query = """ + SELECT + PublishXRef.Id, Publication.PubMed_ID, + Phenotype.Pre_publication_description, Phenotype.Post_publication_description, Phenotype.Original_description, + Phenotype.Pre_publication_abbreviation, Phenotype.Post_publication_abbreviation, + Phenotype.Lab_code, Phenotype.Submitter, Phenotype.Owner, Phenotype.Authorized_Users, + Publication.Authors, Publication.Title, Publication.Abstract, + Publication.Journal, Publication.Volume, Publication.Pages, + Publication.Month, Publication.Year, PublishXRef.Sequence, + Phenotype.Units, PublishXRef.comments + FROM + PublishXRef, Publication, Phenotype, PublishFreeze + WHERE + PublishXRef.Id = %s AND + Phenotype.Id = PublishXRef.PhenotypeId AND + Publication.Id = PublishXRef.PublicationId AND + PublishXRef.InbredSetId = PublishFreeze.InbredSetId AND + PublishFreeze.Id = %s + """ % (trait.name, dataset.id) + + logger.sql(query) + trait_info = g.db.execute(query).fetchone() + + + #XZ, 05/08/2009: Xiaodong add this block to use ProbeSet.Id to find the probeset instead of just using ProbeSet.Name + #XZ, 05/08/2009: to avoid the problem of same probeset name from different platforms. + elif dataset.type == 'ProbeSet': + display_fields_string = ', ProbeSet.'.join(dataset.display_fields) + display_fields_string = 'ProbeSet.' + display_fields_string + query = """ + SELECT %s + FROM ProbeSet, ProbeSetFreeze, ProbeSetXRef + WHERE + ProbeSetXRef.ProbeSetFreezeId = ProbeSetFreeze.Id AND + ProbeSetXRef.ProbeSetId = ProbeSet.Id AND + ProbeSetFreeze.Name = '%s' AND + ProbeSet.Name = '%s' + """ % (escape(display_fields_string), + escape(dataset.name), + escape(str(trait.name))) + logger.sql(query) + trait_info = g.db.execute(query).fetchone() + #XZ, 05/08/2009: We also should use Geno.Id to find marker instead of just using Geno.Name + # to avoid the problem of same marker name from different species. + elif dataset.type == 'Geno': + display_fields_string = string.join(dataset.display_fields,',Geno.') + display_fields_string = 'Geno.' + display_fields_string + query = """ + SELECT %s + FROM Geno, GenoFreeze, GenoXRef + WHERE + GenoXRef.GenoFreezeId = GenoFreeze.Id AND + GenoXRef.GenoId = Geno.Id AND + GenoFreeze.Name = '%s' AND + Geno.Name = '%s' + """ % (escape(display_fields_string), + escape(dataset.name), + escape(trait.name)) + logger.sql(query) + trait_info = g.db.execute(query).fetchone() + else: #Temp type + query = """SELECT %s FROM %s WHERE Name = %s""" + logger.sql(query) + trait_info = g.db.execute(query, + (string.join(dataset.display_fields,','), + dataset.type, trait.name)).fetchone() + if trait_info: + trait.haveinfo = True + + #XZ: assign SQL query result to trait attributes. + for i, field in enumerate(dataset.display_fields): + holder = trait_info[i] + if isinstance(trait_info[i], basestring): + holder = unicode(trait_info[i], "utf-8", "ignore") + setattr(trait, field, holder) + + if dataset.type == 'Publish': + trait.confidential = 0 + if trait.pre_publication_description and not trait.pubmed_id: + trait.confidential = 1 + + description = trait.post_publication_description + + #If the dataset is confidential and the user has access to confidential + #phenotype traits, then display the pre-publication description instead + #of the post-publication description + if trait.confidential: + trait.description_display = trait.pre_publication_description + + #if not webqtlUtil.hasAccessToConfidentialPhenotypeTrait( + # privilege=self.dataset.privilege, + # userName=self.dataset.userName, + # authorized_users=self.authorized_users): + # + # description = self.pre_publication_description + else: + if description: + trait.description_display = description.strip() + else: + trait.description_display = "" + + if not trait.year.isdigit(): + trait.pubmed_text = "N/A" + else: + trait.pubmed_text = trait.year + + if trait.pubmed_id: + trait.pubmed_link = webqtlConfig.PUBMEDLINK_URL % trait.pubmed_id + + + trait.homologeneid = None + if dataset.type == 'ProbeSet' and dataset.group: + if trait.geneid: + #XZ, 05/26/2010: From time to time, this query get error message because some geneid values in database are not number. + #XZ: So I have to test if geneid is number before execute the query. + #XZ: The geneid values in database should be cleaned up. + #try: + # float(self.geneid) + # geneidIsNumber = True + #except ValueError: + # geneidIsNumber = False + #if geneidIsNumber: + query = """ + SELECT + HomologeneId + FROM + Homologene, Species, InbredSet + WHERE + Homologene.GeneId ='%s' AND + InbredSet.Name = '%s' AND + InbredSet.SpeciesId = Species.Id AND + Species.TaxonomyId = Homologene.TaxonomyId + """ % (escape(str(trait.geneid)), escape(dataset.group.name)) + logger.sql(query) + result = g.db.execute(query).fetchone() + #else: + # result = None + + if result: + trait.homologeneid = result[0] + + description_string = unicode(str(trait.description).strip(codecs.BOM_UTF8), 'utf-8') + target_string = unicode(str(trait.probe_target_description).strip(codecs.BOM_UTF8), 'utf-8') + + if len(description_string) > 1 and description_string != 'None': + description_display = description_string + else: + description_display = trait.symbol + + if (len(description_display) > 1 and description_display != 'N/A' and + len(target_string) > 1 and target_string != 'None'): + description_display = description_display + '; ' + target_string.strip() + + # Save it for the jinja2 template + trait.description_display = description_display + + #XZ: trait_location_value is used for sorting + trait.location_repr = 'N/A' + trait.location_value = 1000000 + + if trait.chr and trait.mb: + #Checks if the chromosome number can be cast to an int (i.e. isn't "X" or "Y") + #This is so we can convert the location to a number used for sorting + trait_location_value = convert_location_to_value(trait.chr, trait.mb) + #try: + # trait_location_value = int(self.chr)*1000 + self.mb + #except ValueError: + # if self.chr.upper() == 'X': + # trait_location_value = 20*1000 + self.mb + # else: + # trait_location_value = (ord(str(self.chr).upper()[0])*1000 + + # self.mb) + + #ZS: Put this in function currently called "convert_location_to_value" + trait.location_repr = 'Chr%s: %.6f' % (trait.chr, float(trait.mb)) + trait.location_value = trait_location_value + + elif dataset.type == "Geno": + trait.location_repr = 'N/A' + trait.location_value = 1000000 + + if trait.chr and trait.mb: + #Checks if the chromosome number can be cast to an int (i.e. isn't "X" or "Y") + #This is so we can convert the location to a number used for sorting + trait_location_value = convert_location_to_value(trait.chr, trait.mb) + + #ZS: Put this in function currently called "convert_location_to_value" + trait.location_repr = 'Chr%s: %.6f' % (trait.chr, float(trait.mb)) + trait.location_value = trait_location_value + + if get_qtl_info: + #LRS and its location + trait.LRS_score_repr = "N/A" + trait.LRS_score_value = 0 + trait.LRS_location_repr = "N/A" + trait.LRS_location_value = 1000000 + if dataset.type == 'ProbeSet' and not trait.cellid: + query = """ + SELECT + ProbeSetXRef.Locus, ProbeSetXRef.LRS, ProbeSetXRef.pValue, ProbeSetXRef.mean, ProbeSetXRef.additive + FROM + ProbeSetXRef, ProbeSet + WHERE + ProbeSetXRef.ProbeSetId = ProbeSet.Id AND + ProbeSet.Name = "{}" AND + ProbeSetXRef.ProbeSetFreezeId ={} + """.format(trait.name, dataset.id) + logger.sql(query) + trait_qtl = g.db.execute(query).fetchone() + if trait_qtl: + trait.locus, trait.lrs, trait.pvalue, trait.mean, trait.additive = trait_qtl + if trait.locus: + query = """ + select Geno.Chr, Geno.Mb from Geno, Species + where Species.Name = '{}' and + Geno.Name = '{}' and + Geno.SpeciesId = Species.Id + """.format(dataset.group.species, trait.locus) + logger.sql(query) + result = g.db.execute(query).fetchone() + if result: + trait.locus_chr = result[0] + trait.locus_mb = result[1] + else: + trait.locus = trait.locus_chr = trait.locus_mb = trait.additive = "" + else: + trait.locus = trait.locus_chr = trait.locus_mb = trait.additive = "" + else: + trait.locus = trait.locus_chr = trait.locus_mb = trait.lrs = trait.pvalue = trait.mean = trait.additive = "" + + + if dataset.type == 'Publish': + query = """ + SELECT + PublishXRef.Locus, PublishXRef.LRS, PublishXRef.additive + FROM + PublishXRef, PublishFreeze + WHERE + PublishXRef.Id = %s AND + PublishXRef.InbredSetId = PublishFreeze.InbredSetId AND + PublishFreeze.Id =%s + """ % (trait.name, dataset.id) + logger.sql(query) + trait_qtl = g.db.execute(query).fetchone() + if trait_qtl: + trait.locus, trait.lrs, trait.additive = trait_qtl + if trait.locus: + query = """ + select Geno.Chr, Geno.Mb from Geno, Species + where Species.Name = '{}' and + Geno.Name = '{}' and + Geno.SpeciesId = Species.Id + """.format(dataset.group.species, trait.locus) + logger.sql(query) + result = g.db.execute(query).fetchone() + if result: + trait.locus_chr = result[0] + trait.locus_mb = result[1] + else: + trait.locus = trait.locus_chr = trait.locus_mb = trait.additive = "" + else: + trait.locus = trait.locus_chr = trait.locus_mb = trait.additive = "" + else: + trait.locus = trait.lrs = trait.additive = "" + + if (dataset.type == 'Publish' or dataset.type == "ProbeSet") and trait.locus_chr != "" and trait.locus_mb != "": + #XZ: LRS_location_value is used for sorting + try: + LRS_location_value = int(trait.locus_chr)*1000 + float(trait.locus_mb) + except: + if trait.locus_chr.upper() == 'X': + LRS_location_value = 20*1000 + float(trait.locus_mb) + else: + LRS_location_value = ord(str(trait.locus_chr).upper()[0])*1000 + float(trait.locus_mb) + + trait.LRS_location_repr = LRS_location_repr = 'Chr%s: %.6f' % (trait.locus_chr, float(trait.locus_mb)) + if trait.lrs != "": + trait.LRS_score_repr = LRS_score_repr = '%3.1f' % trait.lrs + trait.LRS_score_value = LRS_score_value = trait.lrs + else: + raise KeyError, `trait.name`+' information is not found in the database.' + + return trait
\ No newline at end of file diff --git a/wqflask/base/webqtlCaseData.py b/wqflask/base/webqtlCaseData.py index 2f88f778..845a7224 100644 --- a/wqflask/base/webqtlCaseData.py +++ b/wqflask/base/webqtlCaseData.py @@ -44,15 +44,15 @@ class webqtlCaseData(object): def __repr__(self): str = "<webqtlCaseData> " - if self.value != None: + if self.value: str += "value=%2.3f" % self.value - if self.variance != None: + if self.variance: str += " variance=%2.3f" % self.variance - if self.num_cases != None: + if self.num_cases: str += " ndata=%d" % self.num_cases - if self.name != None: + if self.name: str += " name=%s" % self.name - if self.name2 != None: + if self.name2: str += " name2=%s" % self.name2 return str diff --git a/wqflask/base/webqtlConfig.py b/wqflask/base/webqtlConfig.py index 6bbabdec..e5f10edf 100644 --- a/wqflask/base/webqtlConfig.py +++ b/wqflask/base/webqtlConfig.py @@ -8,7 +8,7 @@ # ######################################### -from utility.tools import valid_path, mk_dir, assert_dir, flat_files, TEMPDIR +from utility.tools import valid_path, mk_dir, assert_dir, assert_writable_dir, flat_files, TEMPDIR #Debug Level #1 for debug, mod python will reload import each time @@ -60,24 +60,36 @@ ENSEMBLETRANSCRIPT_URL="http://useast.ensembl.org/Mus_musculus/Lucene/Details?sp # HTMLPATH is replaced by GENODIR # IMGDIR is replaced by GENERATED_IMAGE_DIR -# Temporary storage (note that this TMPDIR is not the same directory -# as the UNIX TMPDIR) +# Temporary storage (note that this TMPDIR can be set as an +# environment variable - use utility.tools.TEMPDIR when you +# want to reach this base dir +assert_writable_dir(TEMPDIR) + TMPDIR = mk_dir(TEMPDIR+'/gn2/') +assert_writable_dir(TMPDIR) + CACHEDIR = mk_dir(TMPDIR+'/cache/') # We can no longer write into the git tree: GENERATED_IMAGE_DIR = mk_dir(TMPDIR+'/generated/') GENERATED_TEXT_DIR = mk_dir(TMPDIR+'/generated_text/') +# Make sure we have permissions to access these +assert_writable_dir(CACHEDIR) +assert_writable_dir(GENERATED_IMAGE_DIR) +assert_writable_dir(GENERATED_TEXT_DIR) + # Flat file directories GENODIR = flat_files('genotype')+'/' +assert_dir(GENODIR) + +# JSON genotypes are OBSOLETE JSON_GENODIR = flat_files('genotype/json')+'/' if not valid_path(JSON_GENODIR): # fall back on old location (move the dir, FIXME) JSON_GENODIR = flat_files('json') -assert_dir(GENODIR) +# Are we using the following...? PORTADDR = "http://50.16.251.170" - INFOPAGEHREF = '/dbdoc/%s.html' CGIDIR = '/webqtl/' #XZ: The variable name 'CGIDIR' should be changed to 'PYTHONDIR' SCRIPTFILE = 'main.py' diff --git a/wqflask/maintenance/gen_select_dataset.py b/wqflask/maintenance/gen_select_dataset.py index 542c0d83..e5726656 100644 --- a/wqflask/maintenance/gen_select_dataset.py +++ b/wqflask/maintenance/gen_select_dataset.py @@ -95,13 +95,13 @@ def get_groups(species): for species_name, _species_full_name in species: Cursor.execute("""select InbredSet.Name, InbredSet.FullName from InbredSet, Species, - ProbeFreeze, GenoFreeze, PublishFreeze where Species.Name = %s + ProbeFreeze, GenoFreeze, PublishFreeze where Species.Name = '%s' and InbredSet.SpeciesId = Species.Id and InbredSet.Name != 'BXD300' and (PublishFreeze.InbredSetId = InbredSet.Id or GenoFreeze.InbredSetId = InbredSet.Id or ProbeFreeze.InbredSetId = InbredSet.Id) group by InbredSet.Name - order by InbredSet.Name""", (species_name)) + order by InbredSet.Name""" % species_name) groups[species_name] = list(Cursor.fetchall()) return groups @@ -133,7 +133,7 @@ def get_types(groups): def phenotypes_exist(group_name): #print("group_name:", group_name) Cursor.execute("""select Name from PublishFreeze - where PublishFreeze.Name = %s""", (group_name+"Publish")) + where PublishFreeze.Name = '%s'""" % (group_name+"Publish")) results = Cursor.fetchone() #print("RESULTS:", results) @@ -146,7 +146,7 @@ def phenotypes_exist(group_name): def genotypes_exist(group_name): #print("group_name:", group_name) Cursor.execute("""select Name from GenoFreeze - where GenoFreeze.Name = %s""", (group_name+"Geno")) + where GenoFreeze.Name = '%s'""" % (group_name+"Geno")) results = Cursor.fetchone() #print("RESULTS:", results) @@ -166,13 +166,14 @@ def build_types(species, group): Cursor.execute("""select distinct Tissue.Name from ProbeFreeze, ProbeSetFreeze, InbredSet, Tissue, Species - where Species.Name = %s and Species.Id = InbredSet.SpeciesId and - InbredSet.Name = %s and + where Species.Name = '%s' and Species.Id = InbredSet.SpeciesId and + InbredSet.Name = '%s' and ProbeFreeze.TissueId = Tissue.Id and ProbeFreeze.InbredSetId = InbredSet.Id and ProbeSetFreeze.ProbeFreezeId = ProbeFreeze.Id and - ProbeSetFreeze.public > 0 - order by Tissue.Name""", (species, group)) + ProbeSetFreeze.public > 0 and + ProbeSetFreeze.confidentiality < 1 + order by Tissue.Name""" % (species, group)) results = [] for result in Cursor.fetchall(): @@ -205,12 +206,12 @@ def build_datasets(species, group, type_name): if type_name == "Phenotypes": print("GROUP:", group) Cursor.execute("""select InfoFiles.GN_AccesionId from InfoFiles, PublishFreeze, InbredSet where - InbredSet.Name = %s and + InbredSet.Name = '%s' and PublishFreeze.InbredSetId = InbredSet.Id and InfoFiles.InfoPageName = PublishFreeze.Name and PublishFreeze.public > 0 and PublishFreeze.confidentiality < 1 order by - PublishFreeze.CreateTime desc""", (group)) + PublishFreeze.CreateTime desc""" % group) results = Cursor.fetchone() if results != None: @@ -225,12 +226,12 @@ def build_datasets(species, group, type_name): elif type_name == "Genotypes": Cursor.execute("""select InfoFiles.GN_AccesionId from InfoFiles, GenoFreeze, InbredSet where - InbredSet.Name = %s and + InbredSet.Name = '%s' and GenoFreeze.InbredSetId = InbredSet.Id and InfoFiles.InfoPageName = GenoFreeze.ShortName and GenoFreeze.public > 0 and GenoFreeze.confidentiality < 1 order by - GenoFreeze.CreateTime desc""", (group)) + GenoFreeze.CreateTime desc""" % group) results = Cursor.fetchone() if results != None: @@ -245,12 +246,12 @@ def build_datasets(species, group, type_name): else: Cursor.execute("""select ProbeSetFreeze.Id, ProbeSetFreeze.Name, ProbeSetFreeze.FullName from ProbeSetFreeze, ProbeFreeze, InbredSet, Tissue, Species where - Species.Name = %s and Species.Id = InbredSet.SpeciesId and - InbredSet.Name = %s and - ProbeSetFreeze.ProbeFreezeId = ProbeFreeze.Id and Tissue.Name = %s and + Species.Name = '%s' and Species.Id = InbredSet.SpeciesId and + InbredSet.Name = '%s' and + ProbeSetFreeze.ProbeFreezeId = ProbeFreeze.Id and Tissue.Name = '%s' and ProbeFreeze.TissueId = Tissue.Id and ProbeFreeze.InbredSetId = InbredSet.Id and ProbeSetFreeze.confidentiality < 1 and ProbeSetFreeze.public > 0 order by - ProbeSetFreeze.CreateTime desc""", (species, group, type_name)) + ProbeSetFreeze.CreateTime desc""" % (species, group, type_name)) dataset_results = Cursor.fetchall() datasets = [] diff --git a/wqflask/maintenance/get_group_samplelists.py b/wqflask/maintenance/get_group_samplelists.py index 2d48ce78..04e94886 100644 --- a/wqflask/maintenance/get_group_samplelists.py +++ b/wqflask/maintenance/get_group_samplelists.py @@ -51,6 +51,6 @@ def get_samplelist_from_plink(genofilename): samplelist = [] for line in genofile: line = line.split(" ") - samplelist.append(line[0]) + samplelist.append(line[1]) return samplelist diff --git a/wqflask/runserver.py b/wqflask/runserver.py index 0342b7ad..adacc712 100644 --- a/wqflask/runserver.py +++ b/wqflask/runserver.py @@ -19,11 +19,18 @@ ENDC = '\033[0m' import os app.config['SECRET_KEY'] = os.urandom(24) -from utility.tools import WEBSERVER_MODE,get_setting_int +from utility.tools import WEBSERVER_MODE,get_setting_int,get_setting port = get_setting_int("SERVER_PORT") -logger.info("GN2 is running. Visit %shttp://localhost:%s/%s" % (BLUE,port,ENDC)) +print("GN2 API server URL is ["+BLUE+get_setting("GN_SERVER_URL")+ENDC+"]") + +import requests +page = requests.get(get_setting("GN_SERVER_URL")) +if page.status_code != 200: + raise Exception("API server not found!") + +print("GN2 is running. Visit %s[http://localhost:%s/%s](%s)" % (BLUE,str(port),ENDC,get_setting("WEBSERVER_URL"))) werkzeug_logger = logging.getLogger('werkzeug') diff --git a/wqflask/utility/helper_functions.py b/wqflask/utility/helper_functions.py index 377f6b26..cf16879f 100644 --- a/wqflask/utility/helper_functions.py +++ b/wqflask/utility/helper_functions.py @@ -5,6 +5,9 @@ from base import data_set from base.species import TheSpecies from wqflask import user_manager + +from flask import Flask, g + import logging logger = logging.getLogger(__name__ ) @@ -41,3 +44,20 @@ def get_trait_db_obs(self, trait_db_list): name=trait_name, cellid=None) self.trait_list.append((trait_ob, dataset_ob)) + +def get_species_groups(): + + species_query = "SELECT SpeciesId, MenuName FROM Species" + species_ids_and_names = g.db.execute(species_query).fetchall() + + species_and_groups = [] + for species_id, species_name in species_ids_and_names: + this_species_groups = {} + this_species_groups['species'] = species_name + groups_query = "SELECT InbredSetName FROM InbredSet WHERE SpeciesId = %s" % (species_id) + groups = [group[0] for group in g.db.execute(groups_query).fetchall()] + + this_species_groups['groups'] = groups + species_and_groups.append(this_species_groups) + + return species_and_groups diff --git a/wqflask/utility/logger.py b/wqflask/utility/logger.py index bacb0aa4..128706df 100644 --- a/wqflask/utility/logger.py +++ b/wqflask/utility/logger.py @@ -72,7 +72,7 @@ LOG_LEVEL_DEBUG (NYI). def warning(self,*args): """Call logging.warning for multiple args""" self.collect(self.logger.warning,*args) - self.logger.warning(self.collect(*args)) + # self.logger.warning(self.collect(*args)) def error(self,*args): """Call logging.error for multiple args""" diff --git a/wqflask/utility/tools.py b/wqflask/utility/tools.py index 23d6fb62..82ef136f 100644 --- a/wqflask/utility/tools.py +++ b/wqflask/utility/tools.py @@ -113,6 +113,21 @@ def assert_dir(dir): raise Exception("ERROR: can not find directory "+dir) return dir +def assert_writable_dir(dir): + try: + fn = dir + "/test.txt" + fh = open( fn, 'w' ) + fh.write("I am writing this text to the file\n") + fh.close() + os.remove(fn) + except IOError: + raise Exception('Unable to write test.txt to directory ' + dir) + return dir + +def assert_file(fn): + if not valid_file(fn): + raise Exception('Unable to find file '+fn) + return fn def mk_dir(dir): if not valid_path(dir): @@ -187,6 +202,7 @@ def show_settings(): # Cached values +GN_VERSION = get_setting('GN_VERSION') HOME = get_setting('HOME') WEBSERVER_MODE = get_setting('WEBSERVER_MODE') GN_SERVER_URL = get_setting('GN_SERVER_URL') @@ -201,11 +217,13 @@ USE_REDIS = get_setting_bool('USE_REDIS') USE_GN_SERVER = get_setting_bool('USE_GN_SERVER') GENENETWORK_FILES = get_setting('GENENETWORK_FILES') +TEMP_TRAITS = get_setting('TEMP_TRAITS') PYLMM_COMMAND = pylmm_command() GEMMA_COMMAND = gemma_command() +GEMMA_RESULTS_PATH = get_setting('GEMMA_RESULTS_PATH') PLINK_COMMAND = plink_command() -TEMPDIR = tempdir() +TEMPDIR = tempdir() # defaults to UNIX TMPDIR from six import string_types @@ -221,3 +239,9 @@ if os.environ.get('WQFLASK_OVERRIDES'): else: OVERRIDES[k] = cmd logger.debug(OVERRIDES) + +assert_dir(get_setting("JS_BIODALLIANCE")) +assert_file(get_setting("JS_BIODALLIANCE")+"/build/dalliance-all.js") +assert_file(get_setting("JS_BIODALLIANCE")+"/build/worker-all.js") +assert_dir(get_setting("JS_TWITTER_POST_FETCHER")) +assert_file(get_setting("JS_TWITTER_POST_FETCHER")+"/js/twitterFetcher_min.js") diff --git a/wqflask/wqflask/collect.py b/wqflask/wqflask/collect.py index 81d03d6c..ba555094 100644 --- a/wqflask/wqflask/collect.py +++ b/wqflask/wqflask/collect.py @@ -34,6 +34,7 @@ from utility import Bunch, Struct from utility.formatting import numify from base import trait +from base.data_set import create_dataset def get_collection(): if g.user_session.logged_in: @@ -55,7 +56,7 @@ class AnonCollection(object): #ZS: Find id and set it if the collection doesn't already exist if Redis.get(self.key) == "None" or Redis.get(self.key) == None: - Redis.set(self.key, None) #ZS: For some reason I get the error "Operation against a key holding the wrong kind of value" if I don't do this + Redis.set(self.key, None) #ZS: For some reason I get the error "Operation against a key holding the wrong kind of value" if I don't do this else: collections_list = json.loads(Redis.get(self.key)) collection_position = 0 #ZS: Position of collection in collection_list, if it exists @@ -66,9 +67,10 @@ class AnonCollection(object): collection_exists = True self.id = collection['id'] break + if self.id == None: self.id = str(uuid.uuid4()) - + def get_members(self): traits = [] collections_list = json.loads(Redis.get(self.key)) @@ -76,16 +78,16 @@ class AnonCollection(object): if collection['id'] == self.id: traits = collection['members'] return traits - + @property def num_members(self): - num_members = 0 + num_members = 0 collections_list = json.loads(Redis.get(self.key)) for collection in collections_list: if collection['id'] == self.id: num_members = collection['num_members'] return num_members - + def add_traits(self, params): #assert collection_name == "Default", "Unexpected collection name for anonymous user" self.traits = list(process_traits(params['traits'])) @@ -122,7 +124,7 @@ class AnonCollection(object): "num_members" : len(self.traits), "members" : self.traits} collections_list.append(collection_dict) - + Redis.set(self.key, json.dumps(collections_list)) #Redis.sadd(self.key, *list(traits)) #Redis.expire(self.key, 60 * 60 * 24 * 5) @@ -169,14 +171,14 @@ class UserCollection(object): len_before = len(members) traits = process_traits(params['traits']) - + members_now = members for trait in traits: if trait in members: continue else: members_now.append(trait) - + #members_now = list(members | traits) len_now = len(members_now) uc.members = json.dumps(members_now) @@ -191,6 +193,18 @@ class UserCollection(object): # Probably have to change that return redirect(url_for('view_collection', uc_id=uc.id)) +def process_traits(unprocessed_traits): + #print("unprocessed_traits are:", unprocessed_traits) + if isinstance(unprocessed_traits, basestring): + unprocessed_traits = unprocessed_traits.split(",") + traits = set() + for trait in unprocessed_traits: + #print("trait is:", trait) + data, _separator, hmac = trait.rpartition(':') + data = data.strip() + assert hmac==user_manager.actual_hmac_creation(data), "Data tampering?" + traits.add (str(data)) + return traits def report_change(len_before, len_now): new_length = len_now - len_before @@ -224,11 +238,10 @@ def collections_add(): collections = collection_names, ) - @app.route("/collections/new") def collections_new(): params = request.args - + if "sign_in" in params: return redirect(url_for('login')) @@ -248,26 +261,12 @@ def collections_new(): else: CauseAnError - -def process_traits(unprocessed_traits): - #print("unprocessed_traits are:", unprocessed_traits) - if isinstance(unprocessed_traits, basestring): - unprocessed_traits = unprocessed_traits.split(",") - traits = set() - for trait in unprocessed_traits: - #print("trait is:", trait) - data, _separator, hmac = trait.rpartition(':') - data = data.strip() - assert hmac==user_manager.actual_hmac_creation(data), "Data tampering?" - traits.add (str(data)) - return traits - def create_new(collection_name): params = request.args - + unprocessed_traits = params['traits'] traits = process_traits(unprocessed_traits) - + if g.user_session.logged_in: uc = model.UserCollection() uc.name = collection_name @@ -280,7 +279,7 @@ def create_new(collection_name): else: current_collections = user_manager.AnonUser().get_collections() ac = AnonCollection(collection_name) - ac.changed_timestamp = datetime.datetime.utcnow().strftime('%b %d %Y %I:%M%p') + ac.changed_timestamp = datetime.datetime.utcnow().strftime('%b %d %Y %I:%M%p') ac.add_traits(params) return redirect(url_for('view_collection', collection_id=ac.id)) @@ -345,7 +344,7 @@ def delete_collection(): else: collection_name = params['collection_name'] user_manager.AnonUser().delete_collection(collection_name) - + flash("We've deleted the collection: {}.".format(collection_name), "alert-info") return redirect(url_for('list_collections')) @@ -369,20 +368,21 @@ def view_collection(): break #this_collection = user_collections[params['collection_id']] traits = this_collection['members'] - + print("in view_collection traits are:", traits) trait_obs = [] json_version = [] for atrait in traits: - name, dataset_name = atrait.split(':') - - trait_ob = trait.GeneralTrait(name=name, dataset_name=dataset_name) - trait_ob.retrieve_info(get_qtl_info=True) + name, dataset_name = atrait.split(':') + dataset = create_dataset(dataset_name) + + trait_ob = trait.GeneralTrait(name=name, dataset=dataset) + trait_ob = trait.retrieve_trait_info(trait_ob, dataset, get_qtl_info=True) trait_obs.append(trait_ob) - json_version.append(trait_ob.jsonable()) + json_version.append(trait.jsonable(trait_ob, dataset_name)) if "uc_id" in params: collection_info = dict(trait_obs=trait_obs, diff --git a/wqflask/wqflask/correlation/show_corr_results.py b/wqflask/wqflask/correlation/show_corr_results.py index 401059fd..cc21d1bf 100644 --- a/wqflask/wqflask/correlation/show_corr_results.py +++ b/wqflask/wqflask/correlation/show_corr_results.py @@ -216,7 +216,7 @@ class CorrelationResults(object): for _trait_counter, trait in enumerate(self.correlation_data.keys()[:self.return_number]): trait_object = GeneralTrait(dataset=self.target_dataset, name=trait, get_qtl_info=True, get_sample_info=False) - if self.dataset.type == "ProbeSet" or self.dataset.type == "Geno": + if self.target_dataset.type == "ProbeSet" or self.target_dataset.type == "Geno": #ZS: Convert trait chromosome to an int for the location range option chr_as_int = 0 for order_id, chr_info in self.dataset.species.chromosomes.chromosomes.iteritems(): diff --git a/wqflask/wqflask/correlation_matrix/show_corr_matrix.py b/wqflask/wqflask/correlation_matrix/show_corr_matrix.py index 70e21917..630980c7 100644 --- a/wqflask/wqflask/correlation_matrix/show_corr_matrix.py +++ b/wqflask/wqflask/correlation_matrix/show_corr_matrix.py @@ -207,7 +207,11 @@ class CorrelationMatrix(object): print("before loop:", self.loadings[0]) for i in range(len(self.trait_list)): loadings_row = [] - for j in range(3): + if len(self.trait_list) > 2: + the_range = 3 + else: + the_range = 2 + for j in range(the_range): position = i + len(self.trait_list)*j loadings_row.append(self.loadings[0][position]) loadings_array.append(loadings_row) diff --git a/wqflask/wqflask/ctl/ctl_analysis.py b/wqflask/wqflask/ctl/ctl_analysis.py index 7a42b2f8..9515d23a 100644 --- a/wqflask/wqflask/ctl/ctl_analysis.py +++ b/wqflask/wqflask/ctl/ctl_analysis.py @@ -6,6 +6,8 @@ import scipy as sp # SciPy import rpy2.robjects as ro # R Objects import rpy2.rinterface as ri +import simplejson as json + from base.webqtlConfig import GENERATED_IMAGE_DIR from utility import webqtlUtil # Random number for the image from utility import genofile_parser # genofile_parser @@ -73,8 +75,30 @@ class CTL(object): self.r_CTLnetwork = ro.r["CTLnetwork"] # Map the CTLnetwork function self.r_CTLprofiles = ro.r["CTLprofiles"] # Map the CTLprofiles function self.r_plotCTLobject = ro.r["plot.CTLobject"] # Map the CTLsignificant function + self.nodes_list = [] + self.edges_list = [] print("Obtained pointers to CTL functions") + def addNode(self, gt): + node_dict = { 'data' : {'id' : str(gt.name) + ":" + str(gt.dataset.name), + 'sid' : str(gt.name), + 'dataset' : str(gt.dataset.name), + 'label' : gt.name, + 'symbol' : gt.symbol, + 'geneid' : gt.geneid, + 'omim' : gt.omim } } + self.nodes_list.append(node_dict) + + def addEdge(self, gtS, gtT, significant, x): + edge_data = {'id' : str(gtS.symbol) + '_' + significant[1][x] + '_' + str(gtT.symbol), + 'source' : str(gtS.name) + ":" + str(gtS.dataset.name), + 'target' : str(gtT.name) + ":" + str(gtT.dataset.name), + 'lod' : significant[3][x], + 'color' : "#ff0000", + 'width' : significant[3][x] } + edge_dict = { 'data' : edge_data } + self.edges_list.append(edge_dict) + def run_analysis(self, requestform): print("Starting CTL analysis on dataset") self.trait_db_list = [trait.strip() for trait in requestform['trait_list'].split(',')] @@ -99,7 +123,7 @@ class CTL(object): genofilelocation = locate(dataset.group.name + ".geno", "genotype") parser = genofile_parser.ConvertGenoFile(genofilelocation) parser.process_csv() - + print(dataset.group) # Create a genotype matrix individuals = parser.individuals markers = [] @@ -120,7 +144,7 @@ class CTL(object): if trait != "": ts = trait.split(':') gt = TRAIT.GeneralTrait(name = ts[0], dataset_name = ts[1]) - gt.retrieve_sample_data(individuals) + gt = TRAIT.retrieve_sample_data(gt, dataset, individuals) for ind in individuals: if ind in gt.data.keys(): traits.append(gt.data[ind].value) @@ -129,9 +153,11 @@ class CTL(object): rPheno = r_t(ro.r.matrix(r_as_numeric(r_unlist(traits)), nrow=len(self.trait_db_list), ncol=len(individuals), dimnames = r_list(self.trait_db_list, individuals), byrow=True)) + print(rPheno) + # Use a data frame to store the objects - rPheno = r_data_frame(rPheno) - rGeno = r_data_frame(rGeno) + rPheno = r_data_frame(rPheno, check_names = False) + rGeno = r_data_frame(rGeno, check_names = False) # Debug: Print the genotype and phenotype files to disk #r_write_table(rGeno, "~/outputGN/geno.csv") @@ -156,7 +182,7 @@ class CTL(object): self.r_lineplot(res, significance = significance) r_dev_off() - n = 2 + n = 2 # We start from 2, since R starts from 1 :) for trait in self.trait_db_list: # Create the QTL like CTL plots self.results['imgurl' + str(n)] = webqtlUtil.genRandStr("CTL_") + ".png" @@ -169,6 +195,24 @@ class CTL(object): # Flush any output from R sys.stdout.flush() + # Create the interactive graph for cytoscape visualization (Nodes and Edges) + print(type(significant)) + if not type(significant) == ri.RNULLType: + for x in range(len(significant[0])): + print(significant[0][x], significant[1][x], significant[2][x]) # Debug to console + tsS = significant[0][x].split(':') # Source + tsT = significant[2][x].split(':') # Target + gtS = TRAIT.GeneralTrait(name = tsS[0], dataset_name = tsS[1]) # Retrieve Source info from the DB + gtT = TRAIT.GeneralTrait(name = tsT[0], dataset_name = tsT[1]) # Retrieve Target info from the DB + self.addNode(gtS) + self.addNode(gtT) + self.addEdge(gtS, gtT, significant, x) + + significant[0][x] = gtS.symbol + " (" + gtS.name + ")" # Update the trait name for the displayed table + significant[2][x] = gtT.symbol + " (" + gtT.name + ")" # Update the trait name for the displayed table + + self.elements = json.dumps(self.nodes_list + self.edges_list) + def loadImage(self, path, name): print("pre-loading imgage results:", self.results[path]) imgfile = open(self.results[path], 'rb') @@ -188,6 +232,7 @@ class CTL(object): print("Processing CTL output") template_vars = {} template_vars["results"] = self.results + template_vars["elements"] = self.elements self.render_image(self.results) sys.stdout.flush() return(dict(template_vars)) diff --git a/wqflask/wqflask/do_search.py b/wqflask/wqflask/do_search.py index ad3eab79..e1df1e63 100644 --- a/wqflask/wqflask/do_search.py +++ b/wqflask/wqflask/do_search.py @@ -826,7 +826,8 @@ class PositionSearch(DoSearch): def get_where_clause(self): self.search_term = [float(value) if is_number(value) else value for value in self.search_term] - self.chr, self.mb_min, self.mb_max = self.search_term[:3] + chr, self.mb_min, self.mb_max = self.search_term[:3] + self.chr = str(chr).lower() self.get_chr() where_clause = """ %s.Chr = %s and @@ -846,9 +847,9 @@ class PositionSearch(DoSearch): self.chr = int(self.chr) except: if 'chr' in self.chr: - self.chr = int(self.chr.replace('chr', '')) + self.chr = self.chr.replace('chr', '') else: - self.chr = int(self.chr.replace('CHR', '')) + self.chr = self.chr.replace('CHR', '') def run(self): diff --git a/wqflask/wqflask/export_traits.py b/wqflask/wqflask/export_traits.py new file mode 100644 index 00000000..f8fce929 --- /dev/null +++ b/wqflask/wqflask/export_traits.py @@ -0,0 +1,41 @@ +from __future__ import print_function, division + +import operator +import csv +import xlsxwriter +import StringIO +import datetime + +import simplejson as json + +from pprint import pformat as pf + +def export_search_results_csv(targs): + + table_data = json.loads(targs['export_data']) + table_headers = table_data['headers'] + table_rows = table_data['rows'] + + buff = StringIO.StringIO() + writer = csv.writer(buff) + + metadata = [] + + metadata.append(["Citations: Please see www.genenetwork.org/reference.html"]) + if targs['database_name'] != "None": + metadata.append(["Database: " + targs['database_name']]) + metadata.append(["Date: " + datetime.datetime.now().strftime("%B %d, %Y")]) + metadata.append(["Time: " + datetime.datetime.now().strftime("%H:%M GMT")]) + metadata.append(["Status of data ownership: Possibly unpublished data; please see www.genenetwork.org/statusandContact.html for details on sources, ownership, and usage of these data."]) + + for metadata_row in metadata: + writer.writerow(metadata_row) + + writer.writerow(table_headers) + for trait_info in table_rows: + writer.writerow(trait_info) + + csv_data = buff.getvalue() + buff.close() + + return csv_data
\ No newline at end of file diff --git a/wqflask/wqflask/gsearch.py b/wqflask/wqflask/gsearch.py index 64d638b2..e33e04e1 100644 --- a/wqflask/wqflask/gsearch.py +++ b/wqflask/wqflask/gsearch.py @@ -40,6 +40,7 @@ class GSearch(object): AND ( MATCH (ProbeSet.Name,ProbeSet.description,ProbeSet.symbol,alias,GenbankId, UniGeneId, Probe_Target_Description) AGAINST ('%s' IN BOOLEAN MODE) ) AND ProbeSet.Id = ProbeSetXRef.ProbeSetId AND ProbeSetXRef.ProbeSetFreezeId=ProbeSetFreeze.Id + AND ProbeSetFreeze.confidentiality < 1 AND ProbeSetFreeze.public > 0 ORDER BY species_name, inbredset_name, tissue_name, probesetfreeze_name, probeset_name LIMIT 6000 diff --git a/wqflask/wqflask/marker_regression/gemma_mapping.py b/wqflask/wqflask/marker_regression/gemma_mapping.py index a56362ec..3bde61cd 100644 --- a/wqflask/wqflask/marker_regression/gemma_mapping.py +++ b/wqflask/wqflask/marker_regression/gemma_mapping.py @@ -1,7 +1,7 @@ -import os +import os, math from base import webqtlConfig -from utility.tools import GEMMA_COMMAND +from utility.tools import flat_files, GEMMA_COMMAND, GEMMA_RESULTS_PATH def run_gemma(this_dataset, samples, vals): """Generates p-values for each marker using GEMMA""" @@ -10,41 +10,62 @@ def run_gemma(this_dataset, samples, vals): gen_pheno_txt_file(this_dataset, samples, vals) - # Don't do this! - # os.chdir("{}gemma".format(webqtlConfig.GENODIR)) - # use GEMMA_RUN in the next one, create a unique temp file - gemma_command = GEMMA_COMMAND + ' -bfile %s/%s -k %s/output/%s.cXX.txt -lmm 1 -o %s_output' % (GEMMA_PATH, + gemma_command = GEMMA_COMMAND + ' -bfile %s/%s -k %s/%s.sXX.txt -lmm 1 -outdir %s/output -o %s_output' % (flat_files('mapping'), this_dataset.group.name, - GEMMA_PATH, + flat_files('mapping'), this_dataset.group.name, + GEMMA_RESULTS_PATH, this_dataset.group.name) print("gemma_command:" + gemma_command) os.system(gemma_command) - included_markers, p_values = parse_gemma_output(this_dataset) + marker_obs = parse_gemma_output(this_dataset) - return included_markers, p_values + return marker_obs def gen_pheno_txt_file(this_dataset, samples, vals): """Generates phenotype file for GEMMA""" - with open("{}/{}.fam".format(GEMMA_PATH, this_dataset.group.name), "w") as outfile: - for i, sample in enumerate(samples): - outfile.write(str(sample) + " " + str(sample) + " 0 0 0 " + str(vals[i]) + "\n") + current_file_data = [] + with open("{}/{}.fam".format(flat_files('mapping'), this_dataset.group.name), "r") as outfile: + for i, line in enumerate(outfile): + split_line = line.split() + current_file_data.append(split_line) + + with open("{}/{}.fam".format(flat_files('mapping'), this_dataset.group.name), "w") as outfile: + for i, line in enumerate(current_file_data): + if vals[i] == "x": + this_val = -9 + else: + this_val = vals[i] + outfile.write("0" + " " + line[1] + " " + line[2] + " " + line[3] + " " + line[4] + " " + str(this_val) + "\n") def parse_gemma_output(this_dataset): included_markers = [] p_values = [] - with open("{}/output/{}_output.assoc.txt".format(GEMMA_PATH, this_dataset.group.name)) as output_file: + marker_obs = [] + with open("{}/output/{}_output.assoc.txt".format(GEMMA_RESULTS_PATH, this_dataset.group.name)) as output_file: for line in output_file: if line.startswith("chr"): continue else: + marker = {} + marker['name'] = line.split("\t")[1] + marker['chr'] = int(line.split("\t")[0]) + marker['Mb'] = float(line.split("\t")[2]) / 1000000 + marker['p_value'] = float(line.split("\t")[10]) + if math.isnan(marker['p_value']) or (marker['p_value'] <= 0): + marker['lod_score'] = 0 + #marker['lrs_value'] = 0 + else: + marker['lod_score'] = -math.log10(marker['p_value']) + #marker['lrs_value'] = -math.log10(marker['p_value']) * 4.61 + marker_obs.append(marker) + included_markers.append(line.split("\t")[1]) p_values.append(float(line.split("\t")[10])) - #print("p_values: ", p_values) - return included_markers, p_values + return marker_obs diff --git a/wqflask/wqflask/marker_regression/marker_regression.py b/wqflask/wqflask/marker_regression/marker_regression.py index 37ee42a7..b1d2f811 100644 --- a/wqflask/wqflask/marker_regression/marker_regression.py +++ b/wqflask/wqflask/marker_regression/marker_regression.py @@ -35,9 +35,9 @@ from utility import helper_functions from utility import Plot, Bunch from utility import temp_data from utility.benchmark import Bench -from wqflask.marker_regression import gemma_mapping, rqtl_mapping +from wqflask.marker_regression import gemma_mapping, rqtl_mapping, qtlreaper_mapping, plink_mapping -from utility.tools import locate, locate_ignore_error, PYLMM_COMMAND, GEMMA_COMMAND, PLINK_COMMAND, TEMPDIR +from utility.tools import locate, locate_ignore_error, PYLMM_COMMAND, GEMMA_COMMAND, GEMMA_RESULTS_PATH, PLINK_COMMAND, TEMPDIR from utility.external import shell from base.webqtlConfig import TMPDIR, GENERATED_TEXT_DIR @@ -140,7 +140,6 @@ class MarkerRegression(object): except: self.num_perm = 0 - self.LRSCheck = self.score_type if self.num_perm > 0: self.permCheck = "ON" else: @@ -151,12 +150,10 @@ class MarkerRegression(object): self.dataset.group.get_markers() if self.mapping_method == "gemma": - self.score_type = "LOD" + self.score_type = "-log(p)" self.manhattan_plot = True with Bench("Running GEMMA"): - included_markers, p_values = gemma_mapping.run_gemma(self.dataset, self.samples, self.vals) - with Bench("Getting markers from csv"): - marker_obs = get_markers_from_csv(included_markers, p_values, self.dataset.group.name) + marker_obs = gemma_mapping.run_gemma(self.dataset, self.samples, self.vals) results = marker_obs elif self.mapping_method == "rqtl_plink": results = self.run_rqtl_plink() @@ -165,12 +162,13 @@ class MarkerRegression(object): self.mapping_scale = "morgan" self.control_marker = start_vars['control_marker'] self.do_control = start_vars['do_control'] + self.dataset.group.genofile = start_vars['genofile'] self.method = start_vars['mapmethod_rqtl_geno'] self.model = start_vars['mapmodel_rqtl_geno'] if start_vars['pair_scan'] == "true": self.pair_scan = True if self.permCheck and self.num_perm > 0: - perm_output, self.suggestive, self.significant, results = rqtl_mapping.run_rqtl_geno(self.vals, self.dataset, self.method, self.model, self.permCheck, self.num_perm, self.do_control, self.control_marker, self.manhattan_plot, self.pair_scan) + self.perm_output, self.suggestive, self.significant, results = rqtl_mapping.run_rqtl_geno(self.vals, self.dataset, self.method, self.model, self.permCheck, self.num_perm, self.do_control, self.control_marker, self.manhattan_plot, self.pair_scan) else: results = rqtl_mapping.run_rqtl_geno(self.vals, self.dataset, self.method, self.model, self.permCheck, self.num_perm, self.do_control, self.control_marker, self.manhattan_plot, self.pair_scan) elif self.mapping_method == "reaper": @@ -200,12 +198,24 @@ class MarkerRegression(object): self.control_marker = start_vars['control_marker'] self.do_control = start_vars['do_control'] + self.dataset.group.genofile = start_vars['genofile'] logger.info("Running qtlreaper") - results = self.gen_reaper_results() + results, self.json_data, self.perm_output, self.suggestive, self.significant, self.bootstrap_results = qtlreaper_mapping.gen_reaper_results(self.this_trait, + self.dataset, + self.samples, + self.json_data, + self.num_perm, + self.bootCheck, + self.num_bootstrap, + self.do_control, + self.control_marker, + self.manhattan_plot) elif self.mapping_method == "plink": - results = self.run_plink() + results = plink_mapping.run_plink(self.this_trait, self.dataset, self.species, self.vals, self.maf) + #results = self.run_plink() elif self.mapping_method == "pylmm": logger.debug("RUNNING PYLMM") + self.dataset.group.genofile = start_vars['genofile'] if self.num_perm > 0: self.run_permutations(str(temp_uuid)) results = self.gen_data(str(temp_uuid)) @@ -300,55 +310,12 @@ class MarkerRegression(object): perm_results = self.perm_output, ) - - def run_gemma(self): - """Generates p-values for each marker using GEMMA""" - - self.gen_pheno_txt_file() - - #os.chdir("/home/zas1024/gene/web/gemma") - - gemma_command = GEMMA_COMMAND + ' -bfile %s -k output_%s.cXX.txt -lmm 1 -o %s_output' % ( - self.dataset.group.name, - self.dataset.group.name, - self.dataset.group.name) - #logger.debug("gemma_command:" + gemma_command) - - os.system(gemma_command) - - included_markers, p_values = self.parse_gemma_output() - - self.dataset.group.get_specified_markers(markers = included_markers) - self.dataset.group.markers.add_pvalues(p_values) - return self.dataset.group.markers.markers - - def parse_gemma_output(self): - included_markers = [] - p_values = [] - # Use a temporary file name here! - with open(webqtlConfig.GENERATED_TEXT_DIR+"/{}_output.assoc.txt".format(self.dataset.group.name)) as output_file: - for line in output_file: - if line.startswith("chr"): - continue - else: - included_markers.append(line.split("\t")[1]) - p_values.append(float(line.split("\t")[10])) - #p_values[line.split("\t")[1]] = float(line.split("\t")[10]) - #logger.debug("p_values: ", p_values) - return included_markers, p_values - - def gen_pheno_txt_file(self): - """Generates phenotype file for GEMMA""" - with open(webqtlConfig.GENERATED_TEXT_DIR+"{}.fam".format(self.dataset.group.name), "w") as outfile: - for i, sample in enumerate(self.samples): - outfile.write(str(sample) + " " + str(sample) + " 0 0 0 " + str(self.vals[i]) + "\n") - def run_rqtl_plink(self): # os.chdir("") never do this inside a webserver!! output_filename = webqtlUtil.genRandStr("%s_%s_"%(self.dataset.group.name, self.this_trait.name)) - self.gen_pheno_txt_file_plink(pheno_filename = output_filename) + plink_mapping.gen_pheno_txt_file_plink(self.this_trait, self.dataset, self.vals, pheno_filename = output_filename) rqtl_command = './plink --noweb --ped %s.ped --no-fid --no-parents --no-sex --no-pheno --map %s.map --pheno %s/%s.txt --pheno-name %s --maf %s --missing-phenotype -9999 --out %s%s --assoc ' % (self.dataset.group.name, self.dataset.group.name, TMPDIR, plink_output_filename, self.this_trait.name, self.maf, TMPDIR, plink_output_filename) @@ -356,286 +323,6 @@ class MarkerRegression(object): count, p_values = self.parse_rqtl_output(plink_output_filename) - def run_plink(self): - plink_output_filename = webqtlUtil.genRandStr("%s_%s_"%(self.dataset.group.name, self.this_trait.name)) - - self.gen_pheno_txt_file_plink(pheno_filename = plink_output_filename) - - plink_command = PLINK_COMMAND + ' --noweb --ped %s/%s.ped --no-fid --no-parents --no-sex --no-pheno --map %s/%s.map --pheno %s%s.txt --pheno-name %s --maf %s --missing-phenotype -9999 --out %s%s --assoc ' % (PLINK_PATH, self.dataset.group.name, PLINK_PATH, self.dataset.group.name, TMPDIR, plink_output_filename, self.this_trait.name, self.maf, TMPDIR, plink_output_filename) - logger.debug("plink_command:", plink_command) - - os.system(plink_command) - - count, p_values = self.parse_plink_output(plink_output_filename) - - #for marker in self.dataset.group.markers.markers: - # if marker['name'] not in included_markers: - # logger.debug("marker:", marker) - # self.dataset.group.markers.markers.remove(marker) - # #del self.dataset.group.markers.markers[marker] - - logger.debug("p_values:", pf(p_values)) - - self.dataset.group.markers.add_pvalues(p_values) - - return self.dataset.group.markers.markers - - - def gen_pheno_txt_file_plink(self, pheno_filename = ''): - ped_sample_list = self.get_samples_from_ped_file() - output_file = open("%s%s.txt" % (TMPDIR, pheno_filename), "wb") - header = 'FID\tIID\t%s\n' % self.this_trait.name - output_file.write(header) - - new_value_list = [] - - #if valueDict does not include some strain, value will be set to -9999 as missing value - for i, sample in enumerate(ped_sample_list): - try: - value = self.vals[i] - value = str(value).replace('value=','') - value = value.strip() - except: - value = -9999 - - new_value_list.append(value) - - - new_line = '' - for i, sample in enumerate(ped_sample_list): - j = i+1 - value = new_value_list[i] - new_line += '%s\t%s\t%s\n'%(sample, sample, value) - - if j%1000 == 0: - output_file.write(newLine) - new_line = '' - - if new_line: - output_file.write(new_line) - - output_file.close() - - def gen_pheno_txt_file_rqtl(self, pheno_filename = ''): - ped_sample_list = self.get_samples_from_ped_file() - output_file = open("%s%s.txt" % (TMPDIR, pheno_filename), "wb") - header = 'FID\tIID\t%s\n' % self.this_trait.name - output_file.write(header) - - new_value_list = [] - - #if valueDict does not include some strain, value will be set to -9999 as missing value - for i, sample in enumerate(ped_sample_list): - try: - value = self.vals[i] - value = str(value).replace('value=','') - value = value.strip() - except: - value = -9999 - - new_value_list.append(value) - - - new_line = '' - for i, sample in enumerate(ped_sample_list): - j = i+1 - value = new_value_list[i] - new_line += '%s\t%s\t%s\n'%(sample, sample, value) - - if j%1000 == 0: - output_file.write(newLine) - new_line = '' - - if new_line: - output_file.write(new_line) - - output_file.close() - - # get strain name from ped file in order - def get_samples_from_ped_file(self): - ped_file= open("{}/{}.ped".format(PLINK_PATH, self.dataset.group.name),"r") - line = ped_file.readline() - sample_list=[] - - while line: - lineList = string.split(string.strip(line), '\t') - lineList = map(string.strip, lineList) - - sample_name = lineList[0] - sample_list.append(sample_name) - - line = ped_file.readline() - - return sample_list - - def gen_reaper_results(self): - genotype = self.dataset.group.read_genotype_file() - - if self.manhattan_plot != True: - genotype = genotype.addinterval() - - samples, values, variances, sample_aliases = self.this_trait.export_informative() - - trimmed_samples = [] - trimmed_values = [] - for i in range(0, len(samples)): - #if self.this_trait.data[samples[i]].name2 in self.dataset.group.samplelist: - if self.this_trait.data[samples[i]].name in self.samples: - trimmed_samples.append(samples[i]) - trimmed_values.append(values[i]) - - if self.num_perm < 100: - self.suggestive = 0 - self.significant = 0 - else: - self.perm_output = genotype.permutation(strains = trimmed_samples, trait = trimmed_values, nperm=self.num_perm) - self.suggestive = self.perm_output[int(self.num_perm*0.37-1)] - self.significant = self.perm_output[int(self.num_perm*0.95-1)] - self.highly_significant = self.perm_output[int(self.num_perm*0.99-1)] - - self.json_data['suggestive'] = self.suggestive - self.json_data['significant'] = self.significant - - if self.control_marker != "" and self.do_control == "true": - reaper_results = genotype.regression(strains = trimmed_samples, - trait = trimmed_values, - control = str(self.control_marker)) - if self.bootCheck: - control_geno = [] - control_geno2 = [] - _FIND = 0 - for _chr in genotype: - for _locus in _chr: - if _locus.name == self.control_marker: - control_geno2 = _locus.genotype - _FIND = 1 - break - if _FIND: - break - if control_geno2: - _prgy = list(genotype.prgy) - for _strain in trimmed_samples: - _idx = _prgy.index(_strain) - control_geno.append(control_geno2[_idx]) - - self.bootstrap_results = genotype.bootstrap(strains = trimmed_samples, - trait = trimmed_values, - control = control_geno, - nboot = self.num_bootstrap) - else: - reaper_results = genotype.regression(strains = trimmed_samples, - trait = trimmed_values) - - if self.bootCheck: - self.bootstrap_results = genotype.bootstrap(strains = trimmed_samples, - trait = trimmed_values, - nboot = self.num_bootstrap) - - self.json_data['chr'] = [] - self.json_data['pos'] = [] - self.json_data['lod.hk'] = [] - self.json_data['markernames'] = [] - #if self.additive: - # self.json_data['additive'] = [] - - #Need to convert the QTL objects that qtl reaper returns into a json serializable dictionary - qtl_results = [] - for qtl in reaper_results: - reaper_locus = qtl.locus - #ZS: Convert chr to int - converted_chr = reaper_locus.chr - if reaper_locus.chr != "X" and reaper_locus.chr != "X/Y": - converted_chr = int(reaper_locus.chr) - self.json_data['chr'].append(converted_chr) - self.json_data['pos'].append(reaper_locus.Mb) - self.json_data['lod.hk'].append(qtl.lrs) - self.json_data['markernames'].append(reaper_locus.name) - #if self.additive: - # self.json_data['additive'].append(qtl.additive) - locus = {"name":reaper_locus.name, "chr":reaper_locus.chr, "cM":reaper_locus.cM, "Mb":reaper_locus.Mb} - qtl = {"lrs_value": qtl.lrs, "chr":converted_chr, "Mb":reaper_locus.Mb, - "cM":reaper_locus.cM, "name":reaper_locus.name, "additive":qtl.additive, "dominance":qtl.dominance} - qtl_results.append(qtl) - - return qtl_results - - - def parse_plink_output(self, output_filename): - plink_results={} - - threshold_p_value = 0.01 - - result_fp = open("%s%s.qassoc"% (TMPDIR, output_filename), "rb") - - header_line = result_fp.readline()# read header line - line = result_fp.readline() - - value_list = [] # initialize value list, this list will include snp, bp and pvalue info - p_value_dict = {} - count = 0 - - while line: - #convert line from str to list - line_list = self.build_line_list(line=line) - - # only keep the records whose chromosome name is in db - if self.species.chromosomes.chromosomes.has_key(int(line_list[0])) and line_list[-1] and line_list[-1].strip()!='NA': - - chr_name = self.species.chromosomes.chromosomes[int(line_list[0])] - snp = line_list[1] - BP = line_list[2] - p_value = float(line_list[-1]) - if threshold_p_value >= 0 and threshold_p_value <= 1: - if p_value < threshold_p_value: - p_value_dict[snp] = float(p_value) - - if plink_results.has_key(chr_name): - value_list = plink_results[chr_name] - - # pvalue range is [0,1] - if threshold_p_value >=0 and threshold_p_value <= 1: - if p_value < threshold_p_value: - value_list.append((snp, BP, p_value)) - count += 1 - - plink_results[chr_name] = value_list - value_list = [] - else: - if threshold_p_value >= 0 and threshold_p_value <= 1: - if p_value < threshold_p_value: - value_list.append((snp, BP, p_value)) - count += 1 - - if value_list: - plink_results[chr_name] = value_list - - value_list=[] - - line = result_fp.readline() - else: - line = result_fp.readline() - - #if p_value_list: - # min_p_value = min(p_value_list) - #else: - # min_p_value = 0 - - return count, p_value_dict - - ###################################################### - # input: line: str,one line read from file - # function: convert line from str to list; - # output: lineList list - ####################################################### - def build_line_list(self, line=None): - - line_list = string.split(string.strip(line),' ')# irregular number of whitespaces between columns - line_list = [item for item in line_list if item <>''] - line_list = map(string.strip, line_list) - - return line_list - - def run_permutations(self, temp_uuid): """Runs permutations and gets significant and suggestive LOD scores""" @@ -821,8 +508,7 @@ class MarkerRegression(object): logger.debug("Before creating the command") - command = PYLMM_COMMAND+' --key {} --species {}'.format(key, - "human") + command = PYLMM_COMMAND+' --key {} --species {}'.format(key, "human") logger.debug("command is:", command) @@ -920,30 +606,5 @@ def trim_markers_for_table(markers): return sorted_markers -def get_markers_from_csv(included_markers, p_values, group_name): - marker_data_fh = open(os.path.join(webqtlConfig.PYLMM_PATH + group_name + '_markers.csv')) - markers = [] - for marker_name, p_value in itertools.izip(included_markers, p_values): - if not p_value or len(included_markers) < 1: - continue - for line in marker_data_fh: - splat = line.strip().split() - if splat[0] == marker_name: - marker = {} - marker['name'] = splat[0] - marker['chr'] = int(splat[1]) - marker['Mb'] = float(splat[2]) - marker['p_value'] = p_value - if math.isnan(marker['p_value']) or (marker['p_value'] <= 0): - marker['lod_score'] = 0 - marker['lrs_value'] = 0 - else: - marker['lod_score'] = -math.log10(marker['p_value']) - marker['lrs_value'] = -math.log10(marker['p_value']) * 4.61 - markers.append(marker) - break - - return markers - if __name__ == '__main__': import cPickle as pickle diff --git a/wqflask/wqflask/marker_regression/marker_regression_gn1.py b/wqflask/wqflask/marker_regression/marker_regression_gn1.py index bc147f75..392ad745 100644 --- a/wqflask/wqflask/marker_regression/marker_regression_gn1.py +++ b/wqflask/wqflask/marker_regression/marker_regression_gn1.py @@ -292,7 +292,10 @@ class MarkerRegression(object): self.graphHeight = self.GRAPH_DEFAULT_HEIGHT self.dominanceChecked = False - self.LRS_LOD = start_vars['LRSCheck'] + if 'LRSCheck' in start_vars.keys(): + self.LRS_LOD = start_vars['LRSCheck'] + else: + self.LRS_LOD = start_vars['score_type'] self.cutoff = start_vars['cutoff'] self.intervalAnalystChecked = True self.draw2X = False @@ -983,9 +986,25 @@ class MarkerRegression(object): except: return + previous_chr = 1 + previous_chr_as_int = 0 + if self.plotScale == "physic": + this_chr = str(self.ChrList[self.selectedChr][0]) + else: + this_chr = str(self.ChrList[self.selectedChr][1]+1) + # for i, qtlresult in enumerate(self.qtlresults): + # if Chr == this_chr: + # if Mb < self.startMb or Mb > self.endMb: + # return + # else: + # locPixel = xLeftOffset + (Mb-self.startMb)*plotXScale + # break + # elif self.selectedChr == -1: + # if str(qtlresult['chr']) != Chr: + if self.plotScale == 'physic': if self.selectedChr > -1: - if self.genotype[0].name != Chr or Mb < self.startMb or Mb > self.endMb: + if this_chr != Chr or Mb < self.startMb or Mb > self.endMb: return else: locPixel = xLeftOffset + (Mb-self.startMb)*plotXScale @@ -1169,7 +1188,10 @@ class MarkerRegression(object): if self.controlLocus and self.doControl != "false": string2 = 'Using %s as control' % self.controlLocus else: - string2 = 'Using Haldane mapping function with no control for other QTLs' + if self.mapping_method == "gemma": + string2 = 'Using GEMMA mapping method with no control for other QTLs.' + else: + string2 = 'Using Haldane mapping function with no control for other QTLs' d = 4+ max(canvas.stringWidth(string1,font=labelFont),canvas.stringWidth(string2,font=labelFont)) if self.this_trait.name: identification = "Trait ID: %s : %s" % (self.dataset.fullname, self.this_trait.name) @@ -2016,6 +2038,8 @@ class MarkerRegression(object): AdditiveCoordXY = [] DominanceCoordXY = [] + symbolFont = pid.Font(ttf="fnt_bs", size=5,bold=0) #ZS: For Manhattan Plot + previous_chr = 1 previous_chr_as_int = 0 lineWidth = 1 @@ -2119,7 +2143,7 @@ class MarkerRegression(object): # Yc = yZero - qtlresult['lrs_value']*LRSHeightThresh/LRS_LOD_Max if self.manhattan_plot == True: - canvas.drawEllipse(Xc-1, Yc-1, Xc+1, Yc+1, fillColor=pid.black) + canvas.drawString("5", Xc-canvas.stringWidth("5",font=symbolFont)/2+1,Yc+2,color=pid.black, font=symbolFont) else: LRSCoordXY.append((Xc, Yc)) diff --git a/wqflask/wqflask/marker_regression/plink_mapping.py b/wqflask/wqflask/marker_regression/plink_mapping.py new file mode 100644 index 00000000..b457b9a0 --- /dev/null +++ b/wqflask/wqflask/marker_regression/plink_mapping.py @@ -0,0 +1,161 @@ +import string +import os + +from base.webqtlConfig import TMPDIR +from utility import webqtlUtil +from utility.tools import PLINK_COMMAND + +import utility.logger +logger = utility.logger.getLogger(__name__ ) + +def run_plink(this_trait, dataset, species, vals, maf): + plink_output_filename = webqtlUtil.genRandStr("%s_%s_"%(dataset.group.name, this_trait.name)) + + gen_pheno_txt_file_plink(this_trait, dataset, vals, pheno_filename = plink_output_filename) + + plink_command = PLINK_COMMAND + ' --noweb --ped %s/%s.ped --no-fid --no-parents --no-sex --no-pheno --map %s/%s.map --pheno %s%s.txt --pheno-name %s --maf %s --missing-phenotype -9999 --out %s%s --assoc ' % ( + PLINK_PATH, dataset.group.name, PLINK_PATH, dataset.group.name, + TMPDIR, plink_output_filename, this_trait.name, maf, TMPDIR, + plink_output_filename) + logger.debug("plink_command:", plink_command) + + os.system(plink_command) + + count, p_values = parse_plink_output(plink_output_filename, species) + + #for marker in self.dataset.group.markers.markers: + # if marker['name'] not in included_markers: + # logger.debug("marker:", marker) + # self.dataset.group.markers.markers.remove(marker) + # #del self.dataset.group.markers.markers[marker] + + logger.debug("p_values:", pf(p_values)) + dataset.group.markers.add_pvalues(p_values) + + return dataset.group.markers.markers + + +def gen_pheno_txt_file_plink(this_trait, dataset, vals, pheno_filename = ''): + ped_sample_list = get_samples_from_ped_file(dataset) + output_file = open("%s%s.txt" % (TMPDIR, pheno_filename), "wb") + header = 'FID\tIID\t%s\n' % this_trait.name + output_file.write(header) + + new_value_list = [] + + #if valueDict does not include some strain, value will be set to -9999 as missing value + for i, sample in enumerate(ped_sample_list): + try: + value = vals[i] + value = str(value).replace('value=','') + value = value.strip() + except: + value = -9999 + + new_value_list.append(value) + + new_line = '' + for i, sample in enumerate(ped_sample_list): + j = i+1 + value = new_value_list[i] + new_line += '%s\t%s\t%s\n'%(sample, sample, value) + + if j%1000 == 0: + output_file.write(newLine) + new_line = '' + + if new_line: + output_file.write(new_line) + + output_file.close() + +# get strain name from ped file in order +def get_samples_from_ped_file(dataset): + ped_file= open("{}/{}.ped".format(PLINK_PATH, dataset.group.name),"r") + line = ped_file.readline() + sample_list=[] + + while line: + lineList = string.split(string.strip(line), '\t') + lineList = map(string.strip, lineList) + + sample_name = lineList[0] + sample_list.append(sample_name) + + line = ped_file.readline() + + return sample_list + +def parse_plink_output(output_filename, species): + plink_results={} + + threshold_p_value = 0.01 + + result_fp = open("%s%s.qassoc"% (TMPDIR, output_filename), "rb") + + header_line = result_fp.readline()# read header line + line = result_fp.readline() + + value_list = [] # initialize value list, this list will include snp, bp and pvalue info + p_value_dict = {} + count = 0 + + while line: + #convert line from str to list + line_list = build_line_list(line=line) + + # only keep the records whose chromosome name is in db + if species.chromosomes.chromosomes.has_key(int(line_list[0])) and line_list[-1] and line_list[-1].strip()!='NA': + + chr_name = species.chromosomes.chromosomes[int(line_list[0])] + snp = line_list[1] + BP = line_list[2] + p_value = float(line_list[-1]) + if threshold_p_value >= 0 and threshold_p_value <= 1: + if p_value < threshold_p_value: + p_value_dict[snp] = float(p_value) + + if plink_results.has_key(chr_name): + value_list = plink_results[chr_name] + + # pvalue range is [0,1] + if threshold_p_value >=0 and threshold_p_value <= 1: + if p_value < threshold_p_value: + value_list.append((snp, BP, p_value)) + count += 1 + + plink_results[chr_name] = value_list + value_list = [] + else: + if threshold_p_value >= 0 and threshold_p_value <= 1: + if p_value < threshold_p_value: + value_list.append((snp, BP, p_value)) + count += 1 + + if value_list: + plink_results[chr_name] = value_list + + value_list=[] + + line = result_fp.readline() + else: + line = result_fp.readline() + + #if p_value_list: + # min_p_value = min(p_value_list) + #else: + # min_p_value = 0 + + return count, p_value_dict + +###################################################### +# input: line: str,one line read from file +# function: convert line from str to list; +# output: lineList list +####################################################### +def build_line_list(line=None): + line_list = string.split(string.strip(line),' ')# irregular number of whitespaces between columns + line_list = [item for item in line_list if item <>''] + line_list = map(string.strip, line_list) + + return line_list diff --git a/wqflask/wqflask/marker_regression/qtlreaper_mapping.py b/wqflask/wqflask/marker_regression/qtlreaper_mapping.py new file mode 100644 index 00000000..50228b5e --- /dev/null +++ b/wqflask/wqflask/marker_regression/qtlreaper_mapping.py @@ -0,0 +1,91 @@ +def gen_reaper_results(this_trait, dataset, samples_before, json_data, num_perm, bootCheck, num_bootstrap, do_control, control_marker, manhattan_plot): + genotype = dataset.group.read_genotype_file() + + if manhattan_plot != True: + genotype = genotype.addinterval() + + samples, values, variances, sample_aliases = this_trait.export_informative() + + trimmed_samples = [] + trimmed_values = [] + for i in range(0, len(samples)): + if this_trait.data[samples[i]].name in samples_before: + trimmed_samples.append(samples[i]) + trimmed_values.append(values[i]) + + perm_output = [] + bootstrap_results = [] + + if num_perm < 100: + suggestive = 0 + significant = 0 + else: + perm_output = genotype.permutation(strains = trimmed_samples, trait = trimmed_values, nperm=num_perm) + suggestive = perm_output[int(num_perm*0.37-1)] + significant = perm_output[int(num_perm*0.95-1)] + highly_significant = perm_output[int(num_perm*0.99-1)] + + json_data['suggestive'] = suggestive + json_data['significant'] = significant + + if control_marker != "" and do_control == "true": + reaper_results = genotype.regression(strains = trimmed_samples, + trait = trimmed_values, + control = str(control_marker)) + if bootCheck: + control_geno = [] + control_geno2 = [] + _FIND = 0 + for _chr in genotype: + for _locus in _chr: + if _locus.name == control_marker: + control_geno2 = _locus.genotype + _FIND = 1 + break + if _FIND: + break + if control_geno2: + _prgy = list(genotype.prgy) + for _strain in trimmed_samples: + _idx = _prgy.index(_strain) + control_geno.append(control_geno2[_idx]) + + bootstrap_results = genotype.bootstrap(strains = trimmed_samples, + trait = trimmed_values, + control = control_geno, + nboot = num_bootstrap) + else: + reaper_results = genotype.regression(strains = trimmed_samples, + trait = trimmed_values) + + if bootCheck: + bootstrap_results = genotype.bootstrap(strains = trimmed_samples, + trait = trimmed_values, + nboot = num_bootstrap) + + json_data['chr'] = [] + json_data['pos'] = [] + json_data['lod.hk'] = [] + json_data['markernames'] = [] + #if self.additive: + # self.json_data['additive'] = [] + + #Need to convert the QTL objects that qtl reaper returns into a json serializable dictionary + qtl_results = [] + for qtl in reaper_results: + reaper_locus = qtl.locus + #ZS: Convert chr to int + converted_chr = reaper_locus.chr + if reaper_locus.chr != "X" and reaper_locus.chr != "X/Y": + converted_chr = int(reaper_locus.chr) + json_data['chr'].append(converted_chr) + json_data['pos'].append(reaper_locus.Mb) + json_data['lod.hk'].append(qtl.lrs) + json_data['markernames'].append(reaper_locus.name) + #if self.additive: + # self.json_data['additive'].append(qtl.additive) + locus = {"name":reaper_locus.name, "chr":reaper_locus.chr, "cM":reaper_locus.cM, "Mb":reaper_locus.Mb} + qtl = {"lrs_value": qtl.lrs, "chr":converted_chr, "Mb":reaper_locus.Mb, + "cM":reaper_locus.cM, "name":reaper_locus.name, "additive":qtl.additive, "dominance":qtl.dominance} + qtl_results.append(qtl) + return qtl_results, json_data, perm_output, suggestive, significant, bootstrap_results diff --git a/wqflask/wqflask/marker_regression/rqtl_mapping.py b/wqflask/wqflask/marker_regression/rqtl_mapping.py index 93bf717c..f3694f0b 100644 --- a/wqflask/wqflask/marker_regression/rqtl_mapping.py +++ b/wqflask/wqflask/marker_regression/rqtl_mapping.py @@ -1,193 +1,191 @@ -import rpy2.robjects as ro
-import numpy as np
-
-from base.webqtlConfig import TMPDIR
-from utility import webqtlUtil
-from utility.tools import locate, TEMPDIR
-
-def run_rqtl_geno(vals, dataset, method, model, permCheck, num_perm, do_control, control_marker, manhattan_plot, pair_scan):
- geno_to_rqtl_function(dataset)
-
- ## Get pointers to some common R functions
- r_library = ro.r["library"] # Map the library function
- r_c = ro.r["c"] # Map the c function
- r_sum = ro.r["sum"] # Map the sum function
- plot = ro.r["plot"] # Map the plot function
- postscript = ro.r["postscript"] # Map the postscript function
- png = ro.r["png"] # Map the png function
- dev_off = ro.r["dev.off"] # Map the device off function
-
- print(r_library("qtl")) # Load R/qtl
-
- ## Get pointers to some R/qtl functions
- scanone = ro.r["scanone"] # Map the scanone function
- scantwo = ro.r["scantwo"] # Map the scantwo function
- calc_genoprob = ro.r["calc.genoprob"] # Map the calc.genoprob function
- read_cross = ro.r["read.cross"] # Map the read.cross function
- write_cross = ro.r["write.cross"] # Map the write.cross function
- GENOtoCSVR = ro.r["GENOtoCSVR"] # Map the local GENOtoCSVR function
-
- crossname = dataset.group.name
- genofilelocation = locate(crossname + ".geno", "genotype")
- crossfilelocation = TMPDIR + crossname + ".cross"
-
- #print("Conversion of geno to cross at location:", genofilelocation, " to ", crossfilelocation)
-
- cross_object = GENOtoCSVR(genofilelocation, crossfilelocation) # TODO: Add the SEX if that is available
-
- if manhattan_plot:
- cross_object = calc_genoprob(cross_object)
- else:
- cross_object = calc_genoprob(cross_object, step=1, stepwidth="max")
-
- cross_object = add_phenotype(cross_object, sanitize_rqtl_phenotype(vals)) # Add the phenotype
-
- # for debug: write_cross(cross_object, "csvr", "test.csvr")
-
- # Scan for QTLs
- covar = create_covariates(control_marker, cross_object) # Create the additive covariate matrix
-
- if pair_scan:
- if do_control == "true": # If sum(covar) > 0 we have a covariate matrix
- print("Using covariate"); result_data_frame = scantwo(cross_object, pheno = "the_pheno", addcovar = covar, model=model, method=method, n_cluster = 16)
- else:
- print("No covariates"); result_data_frame = scantwo(cross_object, pheno = "the_pheno", model=model, method=method, n_cluster = 16)
-
- #print("Pair scan results:", result_data_frame)
-
- pair_scan_filename = webqtlUtil.genRandStr("scantwo_") + ".png"
- png(file=TEMPDIR+pair_scan_filename)
- plot(result_data_frame)
- dev_off()
-
- return process_pair_scan_results(result_data_frame)
- else:
- if do_control == "true":
- print("Using covariate"); result_data_frame = scanone(cross_object, pheno = "the_pheno", addcovar = covar, model=model, method=method)
- else:
- print("No covariates"); result_data_frame = scanone(cross_object, pheno = "the_pheno", model=model, method=method)
-
- if num_perm > 0 and permCheck == "ON": # Do permutation (if requested by user)
- if do_control == "true":
- perm_data_frame = scanone(cross_object, pheno_col = "the_pheno", addcovar = covar, n_perm = num_perm, model=model, method=method)
- else:
- 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)
- else:
- return process_rqtl_results(result_data_frame)
-
-def geno_to_rqtl_function(dataset): # TODO: Need to figure out why some genofiles have the wrong format and don't convert properly
-
- ro.r("""
- trim <- function( x ) { gsub("(^[[:space:]]+|[[:space:]]+$)", "", x) }
-
- getGenoCode <- function(header, name = 'unk'){
- mat = which(unlist(lapply(header,function(x){ length(grep(paste('@',name,sep=''), x)) })) == 1)
- return(trim(strsplit(header[mat],':')[[1]][2]))
- }
-
- GENOtoCSVR <- function(genotypes = '%s', out = 'cross.csvr', phenotype = NULL, sex = NULL, verbose = FALSE){
- header = readLines(genotypes, 40) # Assume a geno header is not longer than 40 lines
- toskip = which(unlist(lapply(header, function(x){ length(grep("Chr\t", x)) })) == 1)-1 # Major hack to skip the geno headers
-
- genocodes <- c(getGenoCode(header, 'mat'), getGenoCode(header, 'het'), getGenoCode(header, 'pat')) # Get the genotype codes
- type <- getGenoCode(header, 'type')
- genodata <- read.csv(genotypes, sep='\t', skip=toskip, header=TRUE, na.strings=getGenoCode(header,'unk'), colClasses='character', comment.char = '#')
- cat('Genodata:', toskip, " ", dim(genodata), genocodes, '\n')
- if(is.null(phenotype)) phenotype <- runif((ncol(genodata)-4)) # If there isn't a phenotype, generate a random one
- if(is.null(sex)) sex <- rep('m', (ncol(genodata)-4)) # If there isn't a sex phenotype, treat all as males
- outCSVR <- rbind(c('Pheno', '', '', phenotype), # Phenotype
- c('sex', '', '', sex), # Sex phenotype for the mice
- cbind(genodata[,c('Locus','Chr', 'cM')], genodata[, 5:ncol(genodata)])) # Genotypes
- write.table(outCSVR, file = out, row.names=FALSE, col.names=FALSE,quote=FALSE, sep=',') # Save it to a file
- require(qtl)
- cross = read.cross(file=out, 'csvr', genotypes=genocodes) # Load the created cross file using R/qtl read.cross
- if(type == 'riset') cross <- convert2riself(cross) # If its a RIL, convert to a RIL in R/qtl
- return(cross)
- }
- """ % (dataset.group.name + ".geno"))
-
-def add_phenotype(cross, pheno_as_string):
- ro.globalenv["the_cross"] = cross
- ro.r('the_cross$pheno <- cbind(pull.pheno(the_cross), the_pheno = '+ pheno_as_string +')')
- return ro.r["the_cross"]
-
-def create_covariates(control_marker, cross):
- ro.globalenv["the_cross"] = cross
- ro.r('genotypes <- pull.geno(the_cross)') # Get the genotype matrix
- userinputS = control_marker.replace(" ", "").split(",") # TODO: sanitize user input, Never Ever trust a user
- covariate_names = ', '.join('"{0}"'.format(w) for w in userinputS)
- #print("Marker names of selected covariates:", covariate_names)
- ro.r('covnames <- c(' + covariate_names + ')')
- ro.r('covInGeno <- which(covnames %in% colnames(genotypes))')
- ro.r('covnames <- covnames[covInGeno]')
- ro.r("cat('covnames (purged): ', covnames,'\n')")
- ro.r('covariates <- genotypes[,covnames]') # Get the covariate matrix by using the marker name as index to the genotype file
- #print("R/qtl matrix of covariates:", ro.r["covariates"])
- return ro.r["covariates"]
-
-def sanitize_rqtl_phenotype(vals):
- pheno_as_string = "c("
- for i, val in enumerate(vals):
- if val == "x":
- if i < (len(vals) - 1):
- pheno_as_string += "NA,"
- else:
- pheno_as_string += "NA"
- else:
- if i < (len(vals) - 1):
- pheno_as_string += str(val) + ","
- else:
- pheno_as_string += str(val)
- pheno_as_string += ")"
- return pheno_as_string
-
-def process_pair_scan_results(result):
- pair_scan_results = []
-
- result = result[1]
- output = [tuple([result[j][i] for j in range(result.ncol)]) for i in range(result.nrow)]
- #print("R/qtl scantwo output:", output)
-
- for i, line in enumerate(result.iter_row()):
- marker = {}
- marker['name'] = result.rownames[i]
- marker['chr1'] = output[i][0]
- marker['Mb'] = output[i][1]
- marker['chr2'] = int(output[i][2])
- pair_scan_results.append(marker)
-
- #print("pair_scan_results:", pair_scan_results)
-
- return pair_scan_results
-
-def process_rqtl_perm_results(num_perm, results):
- perm_vals = []
- for line in str(results).split("\n")[1:(num_perm+1)]:
- #print("R/qtl permutation line:", line.split())
- perm_vals.append(float(line.split()[1]))
-
- perm_output = perm_vals
- suggestive = np.percentile(np.array(perm_vals), 67)
- significant = np.percentile(np.array(perm_vals), 95)
- print("SIGNIFICANT:", significant)
-
- return perm_output, suggestive, significant
-
-def process_rqtl_results(result): # TODO: how to make this a one liner and not copy the stuff in a loop
- qtl_results = []
-
- output = [tuple([result[j][i] for j in range(result.ncol)]) for i in range(result.nrow)]
- #print("R/qtl scanone output:", output)
-
- for i, line in enumerate(result.iter_row()):
- marker = {}
- marker['name'] = result.rownames[i]
- marker['chr'] = output[i][0]
- marker['Mb'] = output[i][1]
- marker['lod_score'] = output[i][2]
- qtl_results.append(marker)
-
- return qtl_results
\ No newline at end of file +import rpy2.robjects as ro +import numpy as np + +from base.webqtlConfig import TMPDIR +from utility import webqtlUtil +from utility.tools import locate, TEMPDIR + +def run_rqtl_geno(vals, dataset, method, model, permCheck, num_perm, do_control, control_marker, manhattan_plot, pair_scan): + geno_to_rqtl_function(dataset) + + ## Get pointers to some common R functions + r_library = ro.r["library"] # Map the library function + r_c = ro.r["c"] # Map the c function + r_sum = ro.r["sum"] # Map the sum function + plot = ro.r["plot"] # Map the plot function + postscript = ro.r["postscript"] # Map the postscript function + png = ro.r["png"] # Map the png function + dev_off = ro.r["dev.off"] # Map the device off function + + print(r_library("qtl")) # Load R/qtl + + ## Get pointers to some R/qtl functions + scanone = ro.r["scanone"] # Map the scanone function + scantwo = ro.r["scantwo"] # Map the scantwo function + calc_genoprob = ro.r["calc.genoprob"] # Map the calc.genoprob function + read_cross = ro.r["read.cross"] # Map the read.cross function + write_cross = ro.r["write.cross"] # Map the write.cross function + GENOtoCSVR = ro.r["GENOtoCSVR"] # Map the local GENOtoCSVR function + + crossname = dataset.group.name + genofilelocation = locate(crossname + ".geno", "genotype") + crossfilelocation = TMPDIR + crossname + ".cross" + + #print("Conversion of geno to cross at location:", genofilelocation, " to ", crossfilelocation) + + cross_object = GENOtoCSVR(genofilelocation, crossfilelocation) # TODO: Add the SEX if that is available + + if manhattan_plot: + cross_object = calc_genoprob(cross_object) + else: + cross_object = calc_genoprob(cross_object, step=1, stepwidth="max") + + cross_object = add_phenotype(cross_object, sanitize_rqtl_phenotype(vals)) # Add the phenotype + + # for debug: write_cross(cross_object, "csvr", "test.csvr") + + # Scan for QTLs + covar = create_covariates(control_marker, cross_object) # Create the additive covariate matrix + + if pair_scan: + if do_control == "true": # If sum(covar) > 0 we have a covariate matrix + print("Using covariate"); result_data_frame = scantwo(cross_object, pheno = "the_pheno", addcovar = covar, model=model, method=method, n_cluster = 16) + else: + print("No covariates"); result_data_frame = scantwo(cross_object, pheno = "the_pheno", model=model, method=method, n_cluster = 16) + + #print("Pair scan results:", result_data_frame) + + pair_scan_filename = webqtlUtil.genRandStr("scantwo_") + ".png" + png(file=TEMPDIR+pair_scan_filename) + plot(result_data_frame) + dev_off() + + return process_pair_scan_results(result_data_frame) + else: + if do_control == "true": + print("Using covariate"); result_data_frame = scanone(cross_object, pheno = "the_pheno", addcovar = covar, model=model, method=method) + else: + print("No covariates"); result_data_frame = scanone(cross_object, pheno = "the_pheno", model=model, method=method) + + if num_perm > 0 and permCheck == "ON": # Do permutation (if requested by user) + if do_control == "true": + perm_data_frame = scanone(cross_object, pheno_col = "the_pheno", addcovar = covar, n_perm = num_perm, model=model, method=method) + else: + 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) + else: + return process_rqtl_results(result_data_frame) + +def geno_to_rqtl_function(dataset): # TODO: Need to figure out why some genofiles have the wrong format and don't convert properly + + ro.r(""" + trim <- function( x ) { gsub("(^[[:space:]]+|[[:space:]]+$)", "", x) } + + getGenoCode <- function(header, name = 'unk'){ + mat = which(unlist(lapply(header,function(x){ length(grep(paste('@',name,sep=''), x)) })) == 1) + return(trim(strsplit(header[mat],':')[[1]][2])) + } + + GENOtoCSVR <- function(genotypes = '%s', out = 'cross.csvr', phenotype = NULL, sex = NULL, verbose = FALSE){ + header = readLines(genotypes, 40) # Assume a geno header is not longer than 40 lines + toskip = which(unlist(lapply(header, function(x){ length(grep("Chr\t", x)) })) == 1)-1 # Major hack to skip the geno headers + + genocodes <- c(getGenoCode(header, 'mat'), getGenoCode(header, 'het'), getGenoCode(header, 'pat')) # Get the genotype codes + type <- getGenoCode(header, 'type') + genodata <- read.csv(genotypes, sep='\t', skip=toskip, header=TRUE, na.strings=getGenoCode(header,'unk'), colClasses='character', comment.char = '#') + cat('Genodata:', toskip, " ", dim(genodata), genocodes, '\n') + if(is.null(phenotype)) phenotype <- runif((ncol(genodata)-4)) # If there isn't a phenotype, generate a random one + if(is.null(sex)) sex <- rep('m', (ncol(genodata)-4)) # If there isn't a sex phenotype, treat all as males + outCSVR <- rbind(c('Pheno', '', '', phenotype), # Phenotype + c('sex', '', '', sex), # Sex phenotype for the mice + cbind(genodata[,c('Locus','Chr', 'cM')], genodata[, 5:ncol(genodata)])) # Genotypes + write.table(outCSVR, file = out, row.names=FALSE, col.names=FALSE,quote=FALSE, sep=',') # Save it to a file + require(qtl) + cross = read.cross(file=out, 'csvr', genotypes=genocodes) # Load the created cross file using R/qtl read.cross + if(type == 'riset') cross <- convert2riself(cross) # If its a RIL, convert to a RIL in R/qtl + return(cross) + } + """ % (dataset.group.name + ".geno")) + +def add_phenotype(cross, pheno_as_string): + ro.globalenv["the_cross"] = cross + ro.r('the_cross$pheno <- cbind(pull.pheno(the_cross), the_pheno = '+ pheno_as_string +')') + return ro.r["the_cross"] + +def create_covariates(control_marker, cross): + ro.globalenv["the_cross"] = cross + ro.r('genotypes <- pull.geno(the_cross)') # Get the genotype matrix + userinputS = control_marker.replace(" ", "").split(",") # TODO: sanitize user input, Never Ever trust a user + covariate_names = ', '.join('"{0}"'.format(w) for w in userinputS) + #print("Marker names of selected covariates:", covariate_names) + ro.r('covnames <- c(' + covariate_names + ')') + ro.r('covInGeno <- which(covnames %in% colnames(genotypes))') + ro.r('covnames <- covnames[covInGeno]') + ro.r("cat('covnames (purged): ', covnames,'\n')") + ro.r('covariates <- genotypes[,covnames]') # Get the covariate matrix by using the marker name as index to the genotype file + #print("R/qtl matrix of covariates:", ro.r["covariates"]) + return ro.r["covariates"] + +def sanitize_rqtl_phenotype(vals): + pheno_as_string = "c(" + for i, val in enumerate(vals): + if val == "x": + if i < (len(vals) - 1): + pheno_as_string += "NA," + else: + pheno_as_string += "NA" + else: + if i < (len(vals) - 1): + pheno_as_string += str(val) + "," + else: + pheno_as_string += str(val) + pheno_as_string += ")" + return pheno_as_string + +def process_pair_scan_results(result): + pair_scan_results = [] + + result = result[1] + output = [tuple([result[j][i] for j in range(result.ncol)]) for i in range(result.nrow)] + #print("R/qtl scantwo output:", output) + + for i, line in enumerate(result.iter_row()): + marker = {} + marker['name'] = result.rownames[i] + marker['chr1'] = output[i][0] + marker['Mb'] = output[i][1] + marker['chr2'] = int(output[i][2]) + pair_scan_results.append(marker) + + return pair_scan_results + +def process_rqtl_perm_results(num_perm, results): + perm_vals = [] + for line in str(results).split("\n")[1:(num_perm+1)]: + #print("R/qtl permutation line:", line.split()) + perm_vals.append(float(line.split()[1])) + + perm_output = perm_vals + suggestive = np.percentile(np.array(perm_vals), 67) + significant = np.percentile(np.array(perm_vals), 95) + + return perm_output, suggestive, significant + +def process_rqtl_results(result): # TODO: how to make this a one liner and not copy the stuff in a loop + qtl_results = [] + + output = [tuple([result[j][i] for j in range(result.ncol)]) for i in range(result.nrow)] + #print("R/qtl scanone output:", output) + + for i, line in enumerate(result.iter_row()): + marker = {} + marker['name'] = result.rownames[i] + marker['chr'] = output[i][0] + marker['Mb'] = output[i][1] + marker['lod_score'] = output[i][2] + qtl_results.append(marker) + + return qtl_results + diff --git a/wqflask/wqflask/search_results.py b/wqflask/wqflask/search_results.py index a924c7c9..59e100d8 100644 --- a/wqflask/wqflask/search_results.py +++ b/wqflask/wqflask/search_results.py @@ -16,7 +16,7 @@ from pprint import pformat as pf import json from base.data_set import create_dataset -from base.trait import GeneralTrait +from base import trait from wqflask import parser from wqflask import do_search from utility import webqtlUtil,tools @@ -86,12 +86,13 @@ views.py). """ self.trait_list = [] + json_trait_list = [] species = webqtlDatabaseFunction.retrieve_species(self.dataset.group.name) # result_set represents the results for each search term; a search of # "shh grin2b" would have two sets of results, one for each term logger.debug("self.results is:", pf(self.results)) - for result in self.results: + for index, result in enumerate(self.results): if not result: continue @@ -99,8 +100,11 @@ views.py). #logger.debug("foo locals are:", locals()) trait_id = result[0] - this_trait = GeneralTrait(dataset=self.dataset, name=trait_id, get_qtl_info=True, get_sample_info=False) + this_trait = trait.GeneralTrait(dataset=self.dataset, name=trait_id, get_qtl_info=True, get_sample_info=False) self.trait_list.append(this_trait) + json_trait_list.append(trait.jsonable_table_row(this_trait, self.dataset.name, index + 1)) + + self.json_trait_list = json.dumps(json_trait_list) #def get_group_species_tree(self): # self.species_groups = collections.default_dict(list) diff --git a/wqflask/wqflask/show_trait/show_trait.py b/wqflask/wqflask/show_trait/show_trait.py index d9617c7c..5d55ebe1 100644 --- a/wqflask/wqflask/show_trait/show_trait.py +++ b/wqflask/wqflask/show_trait/show_trait.py @@ -4,6 +4,7 @@ import string import os import cPickle import uuid +import json as json #import pyXLWriter as xl from collections import OrderedDict @@ -24,6 +25,7 @@ from basicStatistics import BasicStatisticsFunctions from pprint import pformat as pf from utility.tools import flat_files, flat_file_exists +from utility.tools import get_setting from utility.logger import getLogger logger = getLogger(__name__ ) @@ -46,60 +48,23 @@ class ShowTrait(object): helper_functions.get_species_dataset_trait(self, kw) else: self.temp_trait = True - self.create_temp_trait() + self.trait_vals = kw['trait_paste'].split() + self.temp_group = kw['group'] + self.temp_species = kw['species'] + #self.create_temp_trait() #self.dataset.group.read_genotype_file() - # Todo: Add back in the ones we actually need from below, as we discover we need them - hddn = OrderedDict() - - ## Some fields, like method, are defaulted to None; otherwise in IE the field can't be changed using jquery - #hddn = OrderedDict( - # FormID = fmID, - # group = fd.group, - # submitID = '', - # scale = 'physic', - # additiveCheck = 'ON', - # showSNP = 'ON', - # showGenes = 'ON', - # method = None, - # parentsf14regression = 'OFF', - # stats_method = '1', - # chromosomes = '-1', - # topten = '', - # viewLegend = 'ON', - # intervalAnalystCheck = 'ON', - # valsHidden = 'OFF', - # database = '', - # criteria = None, - # MDPChoice = None, - # bootCheck = None, - # permCheck = None, - # applyVarianceSE = None, - # sampleNames = '_', - # sampleVals = '_', - # sampleVars = '_', - # otherStrainNames = '_', - # otherStrainVals = '_', - # otherStrainVars = '_', - # extra_attributes = '_', - # other_extra_attributes = '_', - # export_data = None - # ) - #if this_trait: # if this_trait.dataset and this_trait.dataset.type and this_trait.dataset.type == 'ProbeSet': # self.cursor.execute("SELECT h2 from ProbeSetXRef WHERE DataId = %d" % # this_trait.mysqlid) # heritability = self.cursor.fetchone() - self.dispTraitInformation(kw, "", hddn, self.this_trait) #Display trait information + function buttons - - self.build_correlation_tools(self.this_trait) + self.build_correlation_tools() #Get nearest marker for composite mapping - logger.debug("self.dataset.type:", self.dataset.type) if hasattr(self.this_trait, 'locus_chr') and self.this_trait.locus_chr != "" and self.dataset.type != "Geno" and self.dataset.type != "Publish": self.nearest_marker = get_nearest_marker(self.this_trait, self.dataset) #self.nearest_marker1 = get_nearest_marker(self.this_trait, self.dataset)[0] @@ -111,6 +76,9 @@ class ShowTrait(object): self.make_sample_lists(self.this_trait) + # Todo: Add back in the ones we actually need from below, as we discover we need them + hddn = OrderedDict() + if self.dataset.group.allsamples: hddn['allsamples'] = string.join(self.dataset.group.allsamples, ' ') @@ -145,13 +113,18 @@ class ShowTrait(object): else: self.sample_group_types['samples_primary'] = self.dataset.group.name sample_lists = [group.sample_list for group in self.sample_groups] - # logger.debug("sample_lists is:", pf(sample_lists)) self.get_mapping_methods() self.trait_table_width = get_trait_table_width(self.sample_groups) - js_data = dict(dataset_type = self.dataset.type, + if self.this_trait.symbol: + trait_symbol = self.this_trait.symbol + else: + trait_symbol = None + js_data = dict(trait_id = self.this_trait.name, + trait_symbol = trait_symbol, + dataset_type = self.dataset.type, data_scale = self.dataset.data_scale, sample_group_types = self.sample_group_types, sample_lists = sample_lists, @@ -165,7 +138,8 @@ class ShowTrait(object): if flat_file_exists("mapping"): MAPPING_PATH = flat_files("mapping")+"/" if (os.path.isfile(MAPPING_PATH+self.dataset.group.name+".bed") and - os.path.isfile(MAPPING_PATH+self.dataset.group.name+".map")): + (os.path.isfile(MAPPING_PATH+self.dataset.group.name+".map") or + os.path.isfile(MAPPING_PATH+self.dataset.group.name+".bim"))): return True return False @@ -175,740 +149,16 @@ class ShowTrait(object): else: return False + self.genofiles = get_genofiles(self.this_trait) self.use_plink_gemma = check_plink_gemma() self.use_pylmm_rqtl = check_pylmm_rqtl() - def read_data(self, include_f1=False): - '''read user input data or from trait data and analysis form''' - - #if incf1 == None: - # incf1 = [] - - #if not self.genotype: - # self.dataset.read_genotype_file() - if not samplelist: - if include_f1: - samplelist = self.f1list + self.samplelist - else: - samplelist = self.samplelist - - traitfiledata = getattr(self, "traitfile", None) - traitpastedata = getattr(self, "traitpaste", None) - variancefiledata = getattr(self, "variancefile", None) - variancepastedata = getattr(self, "variancepaste", None) - Nfiledata = getattr(self, "Nfile", None) - - #### Todo: Rewrite below when we get to someone submitting their own trait ##### - - def to_float(item): - try: - return float(item) - except ValueError: - return None - - logger.debug("bottle samplelist is:", samplelist) - if traitfiledata: - tt = traitfiledata.split() - values = map(webqtlUtil.StringAsFloat, tt) - elif traitpastedata: - tt = traitpastedata.split() - values = map(webqtlUtil.StringAsFloat, tt) - else: - logger.debug("mapping formdataasfloat") - #values = map(self.FormDataAsFloat, samplelist) - values = [to_float(getattr(self, key)) for key in samplelist] - logger.debug("rocket values is:", values) - - - if len(values) < len(samplelist): - values += [None] * (len(samplelist) - len(values)) - elif len(values) > len(samplelist): - values = values[:len(samplelist)] - logger.debug("now values is:", values) - - - if variancefiledata: - tt = variancefiledata.split() - variances = map(webqtlUtil.StringAsFloat, tt) - elif variancepastedata: - tt = variancepastedata.split() - variances = map(webqtlUtil.StringAsFloat, tt) - else: - variances = map(self.FormVarianceAsFloat, samplelist) - - if len(variances) < len(samplelist): - variances += [None]*(len(samplelist) - len(variances)) - elif len(variances) > len(samplelist): - variances = variances[:len(samplelist)] - - if Nfiledata: - tt = string.split(Nfiledata) - nsamples = map(webqtlUtil.IntAsFloat, tt) - if len(nsamples) < len(samplelist): - nsamples += [None]*(len(samplelist) - len(nsamples)) - else: - nsamples = map(self.FormNAsFloat, samplelist) - - ##values, variances, nsamples is obsolete - self.allTraitData = {} - for i, _sample in enumerate(samplelist): - if values[i] != None: - self.allTraitData[_sample] = webqtlCaseData( - _sample, values[i], variances[i], nsamples[i]) - logger.debug("allTraitData is:", pf(self.allTraitData)) - - - def dispTraitInformation(self, args, title1Body, hddn, this_trait): - - self.species_name = webqtlDatabaseFunction.retrieve_species(group=self.dataset.group.name) - - #tbl = HT.TableLite(cellpadding=2, Class="collap", style="margin-left:20px;", width="840", valign="top", id="target1") - - #reset=HT.Input(type='Reset',name='',value=' Reset ',Class="button") - - #XZ, August 02, 2011: The display of icons is decided by the trait type (if trait exists), along with user log-in status. Note that the new submitted trait might not be trait object. - addSelectionButton = "" - verifyButton = "" - rnaseqButton = "" - geneWikiButton = "" - probeButton = "" - similarButton = "" - snpBrowserButton = "" - updateButton = "" - - addSelectionText = "" - verifyText = "" - rnaseqText = "" - geneWikiText = "" - probeText = "" - similarText = "" - snpBrowserText = "" - updateText = "" - - #if webqtlConfig.USERDICT[self.privilege] >= webqtlConfig.USERDICT['user']: - # - # if this_trait==None or this_trait.dataset.type=='Temp': - # updateButton = HT.Href(url="#redirect", onClick="dataEditingFunc(document.getElementsByName('dataInput')[0],'addPublish');") - # updateButton_img = HT.Image("/images/edit_icon.jpg", name="addnew", alt="Add To Publish", title="Add To Publish", style="border:none;") - # updateButton.append(updateButton_img) - # updateText = "Edit" - # elif this_trait.dataset.type != 'Temp': - # if this_trait.dataset.type == 'Publish' and this_trait.confidential: #XZ: confidential phenotype trait - # if webqtlUtil.hasAccessToConfidentialPhenotypeTrait(privilege=self.privilege, userName=self.userName, authorized_users=this_trait.authorized_users): - # updateButton = HT.Href(url="#redirect", onClick="dataEditingFunc(document.getElementsByName('dataInput')[0],'updateRecord');") - # updateButton_img = HT.Image("/images/edit_icon.jpg", name="update", alt="Edit", title="Edit", style="border:none;") - # updateButton.append(updateButton_img) - # updateText = "Edit" - # else: - # updateButton = HT.Href(url="#redirect", onClick="dataEditingFunc(document.getElementsByName('dataInput')[0],'updateRecord');") - # updateButton_img = HT.Image("/images/edit_icon.jpg", name="update", alt="Edit", title="Edit", style="border:none;") - # updateButton.append(updateButton_img) - # updateText = "Edit" - # else: - # pass - - result = g.db.execute("SELECT Name FROM InbredSet WHERE Name=%s", self.dataset.group.name) - if this_trait: - addSelectionButton = HT.Href(url="#redirect", onClick="addRmvSelection('%s', document.getElementsByName('%s')[0], 'addToSelection');" % (self.dataset.group.name, 'dataInput')) - addSelectionButton_img = HT.Image("/images/add_icon.jpg", name="addselect", alt="Add To Collection", title="Add To Collection", style="border:none;") - #addSelectionButton.append(addSelectionButton_img) - addSelectionText = "Add" - elif result.fetchall(): - addSelectionButton = HT.Href(url="#redirect", onClick="dataEditingFunc(document.getElementsByName('%s')[0], 'addRecord');" % ('dataInput')) - addSelectionButton_img = HT.Image("/images/add_icon.jpg", name="", alt="Add To Collection", title="Add To Collection", style="border:none;") - #addSelectionButton.append(addSelectionButton_img) - addSelectionText = "Add" - else: - pass - - - # Microarray database information to display - if this_trait and this_trait.dataset and this_trait.dataset.type == 'ProbeSet': #before, this line was only reached if this_trait != 0, but now we need to check - try: - hddn['GeneId'] = int(string.strip(this_trait.geneid)) - except: - pass - - #Info2Disp = HT.Paragraph() - - #XZ: Gene Symbol - if this_trait.symbol: - #XZ: Show SNP Browser only for mouse - if self.species_name == 'mouse': - geneName = g.db.execute("SELECT geneSymbol FROM GeneList WHERE geneSymbol = %s", this_trait.symbol).fetchone() - if geneName: - snpurl = os.path.join(webqtlConfig.CGIDIR, "main.py?FormID=SnpBrowserResultPage&submitStatus=1&diffAlleles=True&customStrain=True") + "&geneName=%s" % geneName[0] - else: - if this_trait.chr and this_trait.mb: - snpurl = os.path.join(webqtlConfig.CGIDIR, "main.py?FormID=SnpBrowserResultPage&submitStatus=1&diffAlleles=True&customStrain=True") + \ - "&chr=%s&start=%2.6f&end=%2.6f" % (this_trait.chr, this_trait.mb-0.002, this_trait.mb+0.002) - else: - snpurl = "" - - if snpurl: - snpBrowserButton = HT.Href(url="#redirect", onClick="openNewWin('%s')" % snpurl) - snpBrowserButton_img = HT.Image("/images/snp_icon.jpg", name="snpbrowser", alt=" View SNPs and Indels ", title=" View SNPs and Indels ", style="border:none;") - snpBrowserText = "SNPs" - - #XZ: Show GeneWiki for all species - geneWikiButton = HT.Href(url="#redirect", onClick="openNewWin('%s')" % (os.path.join(webqtlConfig.CGIDIR, webqtlConfig.SCRIPTFILE) + "?FormID=geneWiki&symbol=%s" % this_trait.symbol)) - geneWikiButton_img = HT.Image("/images/genewiki_icon.jpg", name="genewiki", alt=" Write or review comments about this gene ", title=" Write or review comments about this gene ", style="border:none;") - geneWikiText = 'GeneWiki' - - #XZ: display similar traits in other selected datasets - if this_trait and this_trait.dataset and this_trait.dataset.type=="ProbeSet" and this_trait.symbol: - if self.species_name in ("mouse", "rat", "human"): - similarUrl = "%s?cmd=sch&gene=%s&alias=1&species=%s" % (os.path.join(webqtlConfig.CGIDIR, webqtlConfig.SCRIPTFILE), this_trait.symbol, self.species_name) - similarButton = HT.Href(url="#redirect", onClick="openNewWin('%s')" % similarUrl) - similarButton_img = HT.Image("/images/find_icon.jpg", name="similar", alt=" Find similar expression data ", title=" Find similar expression data ", style="border:none;") - similarText = "Find" - else: - pass - else: - tbl.append(HT.TR( - HT.TD('Gene Symbol: ', Class="fwb fs13", valign="top", nowrap="on"), - HT.TD(width=10, valign="top"), - HT.TD(HT.Span('Not available', Class="fs13 fsI"), valign="top") - )) - - - - ##display Verify Location button - try: - blatsequence = this_trait.blatseq - if not blatsequence: - #XZ, 06/03/2009: ProbeSet name is not unique among platforms. We should use ProbeSet Id instead. - self.cursor.execute("""SELECT Probe.Sequence, Probe.Name - FROM Probe, ProbeSet, ProbeSetFreeze, ProbeSetXRef - WHERE ProbeSetXRef.ProbeSetFreezeId = ProbeSetFreeze.Id AND - ProbeSetXRef.ProbeSetId = ProbeSet.Id AND - ProbeSetFreeze.Name = '%s' AND - ProbeSet.Name = '%s' AND - Probe.ProbeSetId = ProbeSet.Id order by Probe.SerialOrder""" % (this_trait.dataset.name, this_trait.name) ) - seqs = self.cursor.fetchall() - if not seqs: - raise ValueError - else: - blatsequence = '' - for seqt in seqs: - if int(seqt[1][-1]) % 2 == 1: - blatsequence += string.strip(seqt[0])## NEEDED FOR UCSC GENOME BROWSER LINK - - #--------Hongqiang add this part in order to not only blat ProbeSet, but also blat Probe - blatsequence = '%3E'+this_trait.name+'%0A'+blatsequence+'%0A' - #XZ, 06/03/2009: ProbeSet name is not unique among platforms. We should use ProbeSet Id instead. - query = """SELECT Probe.Sequence, Probe.Name - FROM Probe, ProbeSet, ProbeSetFreeze, ProbeSetXRef - WHERE ProbeSetXRef.ProbeSetFreezeId = ProbeSetFreeze.Id AND - ProbeSetXRef.ProbeSetId = ProbeSet.Id AND - ProbeSetFreeze.Name = '{}' AND - ProbeSet.Name = '{}' AND - Probe.ProbeSetId = ProbeSet.Id order by Probe.SerialOrder""".format(this_trait.dataset.name, this_trait.name) - - logger.sql(query) - seqs = g.db.execute(query).fetchall() - - for seqt in seqs: - if int(seqt[1][-1]) %2 == 1: - blatsequence += '%3EProbe_'+string.strip(seqt[1])+'%0A'+string.strip(seqt[0])+'%0A' - - #XZ: Pay attention to the parameter of version (rn, mm, hg). They need to be changed if necessary. - if self.species_name == "rat": - self.UCSC_BLAT_URL = webqtlConfig.UCSC_BLAT % ('rat', 'rn3', blatsequence) - self.UTHSC_BLAT_URL = "" - elif self.species_name == "mouse": - self.UCSC_BLAT_URL = webqtlConfig.UCSC_BLAT % ('mouse', 'mm9', blatsequence) - self.UTHSC_BLAT_URL = webqtlConfig.UTHSC_BLAT % ('mouse', 'mm9', blatsequence) - elif self.species_name == "human": - self.UCSC_BLAT_URL = webqtlConfig.UCSC_BLAT % ('human', 'hg19', blatsequence) - self.UTHSC_BLAT_URL = "" - else: - self.UCSC_BLAT_URL = "" - self.UTHSC_BLAT_URL = "" - - if self.UCSC_BLAT_URL != "": - verifyButton = HT.Href(url="#", onClick="javascript:openNewWin('%s'); return false;" % UCSC_BLAT_URL) - verifyButtonImg = HT.Image("/images/verify_icon.jpg", name="verify", alt=" Check probe locations at UCSC ", - title=" Check probe locations at UCSC ", style="border:none;") - verifyButton.append(verifyButtonImg) - verifyText = 'Verify' - if self.UTHSC_BLAT_URL != "": - rnaseqButton = HT.Href(url="#", onClick="javascript:openNewWin('%s'); return false;" % UTHSC_BLAT_URL) - rnaseqButtonImg = HT.Image("/images/rnaseq_icon.jpg", name="rnaseq", alt=" View probes, SNPs, and RNA-seq at UTHSC ", - title=" View probes, SNPs, and RNA-seq at UTHSC ", style="border:none;") - rnaseqButton.append(rnaseqButtonImg) - rnaseqText = 'RNA-seq' - tSpan.append(HT.BR()) - except: - pass - - #Display probe information (if any) - if this_trait.dataset.name.find('Liver') >= 0 and this_trait.dataset.name.find('F2') < 0: - pass - else: - query = """SELECT count(*) - FROM Probe, ProbeSet - WHERE ProbeSet.Name = '%s' AND Probe.ProbeSetId = ProbeSet.Id""" % (this_trait.name) - #query database for number of probes associated with trait; if count > 0, set probe tool button and text - logger.sql(query) - probeResult = g.db.execute(query).fetchone() - if probeResult[0] > 0: - self.show_probes = "True" - probeurl = "%s?FormID=showProbeInfo&database=%s&ProbeSetID=%s&CellID=%s&group=%s&incparentsf1=ON" \ - % (os.path.join(webqtlConfig.CGIDIR, webqtlConfig.SCRIPTFILE), this_trait.dataset, this_trait.name, this_trait.cellid, self.dataset.group.name) - probeButton = HT.Href(url="#", onClick="javascript:openNewWin('%s'); return false;" % probeurl) - probeButton_img = HT.Image("/images/probe_icon.jpg", name="probe", alt=" Check sequence of probes ", title=" Check sequence of probes ", style="border:none;") - #probeButton.append(probeButton_img) - probeText = "Probes" - - this_trait.species = self.species_name # We need this in the template, so we tuck it into this_trait - this_trait.database = this_trait.get_database() - - #XZ: ID links - if this_trait.genbankid or this_trait.geneid or this_trait.unigeneid or this_trait.omim or this_trait.homologeneid: - idStyle = "background:#dddddd;padding:2" - tSpan = HT.Span(Class="fs13") - if this_trait.geneid: - gurl = HT.Href(text= 'Gene', target='_blank',\ - url=webqtlConfig.NCBI_LOCUSID % this_trait.geneid, Class="fs14 fwn", title="Info from NCBI Entrez Gene") - #tSpan.append(HT.Span(gurl, style=idStyle), " "*2) - if this_trait.omim: - gurl = HT.Href(text= 'OMIM', target='_blank', \ - url= webqtlConfig.OMIM_ID % this_trait.omim,Class="fs14 fwn", title="Summary from On Mendelian Inheritance in Man") - #tSpan.append(HT.Span(gurl, style=idStyle), " "*2) - if this_trait.unigeneid: - try: - gurl = HT.Href(text= 'UniGene',target='_blank',\ - url= webqtlConfig.UNIGEN_ID % tuple(string.split(this_trait.unigeneid,'.')[:2]),Class="fs14 fwn", title="UniGene ID") - #tSpan.append(HT.Span(gurl, style=idStyle), " "*2) - except: - pass - if this_trait.genbankid: - this_trait.genbankid = '|'.join(this_trait.genbankid.split('|')[0:10]) - if this_trait.genbankid[-1]=='|': - this_trait.genbankid=this_trait.genbankid[0:-1] - gurl = HT.Href(text= 'GenBank', target='_blank', \ - url= webqtlConfig.GENBANK_ID % this_trait.genbankid,Class="fs14 fwn", title="Find the original GenBank sequence used to design the probes") - #tSpan.append(HT.Span(gurl, style=idStyle), " "*2) - if this_trait.homologeneid: - hurl = HT.Href(text= 'HomoloGene', target='_blank',\ - url=webqtlConfig.HOMOLOGENE_ID % this_trait.homologeneid, Class="fs14 fwn", title="Find similar genes in other species") - #tSpan.append(HT.Span(hurl, style=idStyle), " "*2) - - #XZ: Resource Links: - if this_trait.symbol: - #XZ,12/26/2008: Gene symbol may contain single quotation mark. - #For example, Affymetrix, mouse430v2, 1440338_at, the symbol is 2'-Pde (geneid 211948) - #I debug this by using double quotation marks. - if self.species_name == "rat": - result = g.db.execute("SELECT kgID, chromosome,txStart,txEnd FROM GeneList_rn33 WHERE geneSymbol = %s", (this_trait.symbol)).fetchone() - if result != None: - kgId, chr, txst, txen = result[0], result[1], result[2], result[3] - if chr and txst and txen and kgId: - txst = int(txst*1000000) - txen = int(txen*1000000) - if self.species_name == "mouse": - logger.debug("this_trait.symbol:", this_trait.symbol) - result = g.db.execute("SELECT chromosome,txStart,txEnd FROM GeneList WHERE geneSymbol = %s", (this_trait.symbol)).fetchone() - if result != None: - this_chr, txst, txen = result[0], result[1], result[2] - if this_chr and txst and txen and this_trait.refseq_transcriptid : - txst = int(txst*1000000) - txen = int(txen*1000000) - ## NEEDED FOR UCSC GENOME BROWSER LINK - - #XZ, 7/16/2009: The url for SymAtlas (renamed as BioGPS) has changed. We don't need this any more - #tSpan.append(HT.Span(HT.Href(text= 'SymAtlas',target="mainFrame",\ - # url="http://symatlas.gnf.org/SymAtlas/bioentry?querytext=%s&query=14&species=%s&type=Expression" \ - # % (this_trait.symbol,symatlas_species),Class="fs14 fwn", \ - # title="Expression across many tissues and cell types"), style=linkStyle), " "*2) - if this_trait.geneid and (self.species_name == "mouse" or self.species_name == "rat" or self.species_name == "human"): - #tSpan.append(HT.Span(HT.Href(text= 'BioGPS',target="mainFrame",\ - # url="http://biogps.gnf.org/?org=%s#goto=genereport&id=%s" \ - # % (self.species_name, this_trait.geneid),Class="fs14 fwn", \ - # title="Expression across many tissues and cell types"), style=linkStyle), " "*2) - pass - #tSpan.append(HT.Span(HT.Href(text= 'STRING',target="mainFrame",\ - # url="http://string.embl.de/newstring_cgi/show_link_summary.pl?identifier=%s" \ - # % this_trait.symbol,Class="fs14 fwn", \ - # title="Protein interactions: known and inferred"), style=linkStyle), " "*2) - if this_trait.symbol: - #ZS: The "species scientific" converts the plain English species names we're using to their scientific names, which are needed for PANTHER's input - #We should probably use the scientific name along with the English name (if not instead of) elsewhere as well, given potential non-English speaking users - if self.species_name == "mouse": - species_scientific = "Mus%20musculus" - elif self.species_name == "rat": - species_scientific = "Rattus%20norvegicus" - elif self.species_name == "human": - species_scientific = "Homo%20sapiens" - elif self.species_name == "drosophila": - species_scientific = "Drosophila%20melanogaster" - else: - species_scientific = "all" - - species_scientific - #tSpan.append(HT.Span(HT.Href(text= 'PANTHER',target="mainFrame", \ - # url="http://www.pantherdb.org/genes/geneList.do?searchType=basic&fieldName=all&organism=%s&listType=1&fieldValue=%s" \ - # % (species_scientific, this_trait.symbol),Class="fs14 fwn", \ - # title="Gene and protein data resources from Celera-ABI"), style=linkStyle), " "*2) - else: - pass - #tSpan.append(HT.Span(HT.Href(text= 'BIND',target="mainFrame",\ - # url="http://bind.ca/?textquery=%s" \ - # % this_trait.symbol,Class="fs14 fwn", \ - # title="Protein interactions"), style=linkStyle), " "*2) - #if this_trait.geneid and (self.species_name == "mouse" or self.species_name == "rat" or self.species_name == "human"): - # tSpan.append(HT.Span(HT.Href(text= 'Gemma',target="mainFrame",\ - # url="http://www.chibi.ubc.ca/Gemma/gene/showGene.html?ncbiid=%s" \ - # % this_trait.geneid, Class="fs14 fwn", \ - # title="Meta-analysis of gene expression data"), style=linkStyle), " "*2) - #tSpan.append(HT.Span(HT.Href(text= 'SynDB',target="mainFrame",\ - # url="http://lily.uthsc.edu:8080/20091027_GNInterfaces/20091027_redirectSynDB.jsp?query=%s" \ - # % this_trait.symbol, Class="fs14 fwn", \ - # title="Brain synapse database"), style=linkStyle), " "*2) - #if self.species_name == "mouse": - # tSpan.append(HT.Span(HT.Href(text= 'ABA',target="mainFrame",\ - # url="http://mouse.brain-map.org/brain/%s.html" \ - # % this_trait.symbol, Class="fs14 fwn", \ - # title="Allen Brain Atlas"), style=linkStyle), " "*2) - - if this_trait.geneid: - #if self.species_name == "mouse": - # tSpan.append(HT.Span(HT.Href(text= 'ABA',target="mainFrame",\ - # url="http://www.brain-map.org/search.do?queryText=egeneid=%s" \ - # % this_trait.geneid, Class="fs14 fwn", \ - # title="Allen Brain Atlas"), style=linkStyle), " "*2) - if self.species_name == "human": - #tSpan.append(HT.Span(HT.Href(text= 'ABA',target="mainFrame",\ - # url="http://humancortex.alleninstitute.org/has/human/imageseries/search/1.html?searchSym=t&searchAlt=t&searchName=t&gene_term=&entrez_term=%s" \ - # % this_trait.geneid, Class="fs14 fwn", \ - # title="Allen Brain Atlas"), style=linkStyle), " "*2) - pass - - #for zhou mi's cliques, need to be removed - #if self.database[:6] == 'BXDMic' and self.ProbeSetID in cliqueID: - # Info2Disp.append(HT.Strong('Clique Search: '),HT.Href(text='Search',\ - # url ="http://compbio1.utmem.edu/clique_go/results.php?pid=%s&pval_1=0&pval_2=0.001" \ - # % self.ProbeSetID,target='_blank',Class="normalsize"),HT.BR()) - - elif this_trait and this_trait.dataset and this_trait.dataset.type =='Publish': #Check if trait is phenotype - - #if this_trait.confidential: - # pass - # #tbl.append(HT.TR( - # # HT.TD('Pre-publication Phenotype: ', Class="fs13 fwb", valign="top", nowrap="on", width=90), - # # HT.TD(width=10, valign="top"), - # # HT.TD(HT.Span(this_trait.pre_publication_description, Class="fs13"), valign="top", width=740) - # # )) - # if webqtlUtil.hasAccessToConfidentialPhenotypeTrait(privilege=self.privilege, userName=self.userName, authorized_users=this_trait.authorized_users): - # #tbl.append(HT.TR( - # # HT.TD('Post-publication Phenotype: ', Class="fs13 fwb", valign="top", nowrap="on", width=90), - # # HT.TD(width=10, valign="top"), - # # HT.TD(HT.Span(this_trait.post_publication_description, Class="fs13"), valign="top", width=740) - # # )) - # #tbl.append(HT.TR( - # # HT.TD('Pre-publication Abbreviation: ', Class="fs13 fwb", valign="top", nowrap="on", width=90), - # # HT.TD(width=10, valign="top"), - # # HT.TD(HT.Span(this_trait.pre_publication_abbreviation, Class="fs13"), valign="top", width=740) - # # )) - # #tbl.append(HT.TR( - # # HT.TD('Post-publication Abbreviation: ', Class="fs13 fwb", valign="top", nowrap="on", width=90), - # # HT.TD(width=10, valign="top"), - # # HT.TD(HT.Span(this_trait.post_publication_abbreviation, Class="fs13"), valign="top", width=740) - # # )) - # #tbl.append(HT.TR( - # # HT.TD('Lab code: ', Class="fs13 fwb", valign="top", nowrap="on", width=90), - # # HT.TD(width=10, valign="top"), - # # HT.TD(HT.Span(this_trait.lab_code, Class="fs13"), valign="top", width=740) - # # )) - # pass - # #tbl.append(HT.TR( - # # HT.TD('Owner: ', Class="fs13 fwb", valign="top", nowrap="on", width=90), - # # HT.TD(width=10, valign="top"), - # # HT.TD(HT.Span(this_trait.owner, Class="fs13"), valign="top", width=740) - # # )) - #else: - # pass - # #tbl.append(HT.TR( - # # HT.TD('Phenotype: ', Class="fs13 fwb", valign="top", nowrap="on", width=90), - # # HT.TD(width=10, valign="top"), - # # HT.TD(HT.Span(this_trait.post_publication_description, Class="fs13"), valign="top", width=740) - # # )) - ##tbl.append(HT.TR( - ## HT.TD('Authors: ', Class="fs13 fwb", - ## valign="top", nowrap="on", width=90), - ## HT.TD(width=10, valign="top"), - ## HT.TD(HT.Span(this_trait.authors, Class="fs13"), - ## valign="top", width=740) - ## )) - ##tbl.append(HT.TR( - ## HT.TD('Title: ', Class="fs13 fwb", - ## valign="top", nowrap="on", width=90), - ## HT.TD(width=10, valign="top"), - ## HT.TD(HT.Span(this_trait.title, Class="fs13"), - ## valign="top", width=740) - ## )) - if this_trait.journal: - journal = this_trait.journal - if this_trait.year: - journal = this_trait.journal + " (%s)" % this_trait.year - # - #tbl.append(HT.TR( - # HT.TD('Journal: ', Class="fs13 fwb", - # valign="top", nowrap="on", width=90), - # HT.TD(width=10, valign="top"), - # HT.TD(HT.Span(journal, Class="fs13"), - # valign="top", width=740) - # )) - PubMedLink = "" - if this_trait.pubmed_id: - PubMedLink = webqtlConfig.PUBMEDLINK_URL % this_trait.pubmed_id - if PubMedLink: - #tbl.append(HT.TR( - # HT.TD('Link: ', Class="fs13 fwb", - # valign="top", nowrap="on", width=90), - # HT.TD(width=10, valign="top"), - # HT.TD(HT.Span(HT.Href(url=PubMedLink, text="PubMed",target='_blank',Class="fs14 fwn"), - # style = "background:#cddcff;padding:2"), valign="top", width=740) - # )) - pass - - elif this_trait and this_trait.dataset and this_trait.dataset.type == 'Geno': #Check if trait is genotype - - if this_trait.chr and this_trait.mb: - location = ' Chr %s @ %s Mb' % (this_trait.chr,this_trait.mb) - else: - location = "not available" - - #if this_trait.sequence and len(this_trait.sequence) > 100: - # if self.species_name == "rat": - # UCSC_BLAT_URL = webqtlConfig.UCSC_BLAT % ('rat', 'rn3', this_trait.sequence) - # UTHSC_BLAT_URL = webqtlConfig.UTHSC_BLAT % ('rat', 'rn3', this_trait.sequence) - # elif self.species_name == "mouse": - # UCSC_BLAT_URL = webqtlConfig.UCSC_BLAT % ('mouse', 'mm9', this_trait.sequence) - # UTHSC_BLAT_URL = webqtlConfig.UTHSC_BLAT % ('mouse', 'mm9', this_trait.sequence) - # elif self.species_name == "human": - # UCSC_BLAT_URL = webqtlConfig.UCSC_BLAT % ('human', 'hg19', blatsequence) - # UTHSC_BLAT_URL = webqtlConfig.UTHSC_BLAT % ('human', 'hg19', this_trait.sequence) - # else: - # UCSC_BLAT_URL = "" - # UTHSC_BLAT_URL = "" - # if UCSC_BLAT_URL: - # #verifyButton = HT.Href(url="#", onClick="openNewWin('%s')" % UCSC_BLAT_URL) - # verifyButton = HT.Href(url="#") - # verifyButtonImg = HT.Image("/images/verify_icon.jpg", name="verify", alt=" Check probe locations at UCSC ", title=" Check probe locations at UCSC ", style="border:none;") - # verifyButton.append(verifyButtonImg) - # verifyText = "Verify" - # rnaseqButton = HT.Href(url="#", onClick="openNewWin('%s')" % UTHSC_BLAT_URL) - # rnaseqButtonImg = HT.Image("/images/rnaseq_icon.jpg", name="rnaseq", alt=" View probes, SNPs, and RNA-seq at UTHSC ", title=" View probes, SNPs, and RNA-seq at UTHSC ", style="border:none;") - # rnaseqButton.append(rnaseqButtonImg) - # rnaseqText = "RNA-seq" - - #tbl.append(HT.TR( - # HT.TD('Location: ', Class="fs13 fwb", - # valign="top", nowrap="on", width=90), - # HT.TD(width=10, valign="top"), - # HT.TD(HT.Span(location, Class="fs13"), valign="top", width=740) - # ), - # HT.TR( - # HT.TD('SNP Search: ', Class="fs13 fwb", - # valign="top", nowrap="on", width=90), - # HT.TD(width=10, valign="top"), - # HT.TD(HT.Href("http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?db=snp&cmd=search&term=%s" % this_trait.name, 'NCBI',Class="fs13"), - # valign="top", width=740) - # )) - - - def dispBasicStatistics(self, fd, this_trait): - - #XZ, June 22, 2011: The definition and usage of primary_samples, other_samples, specialStrains, all_samples are not clear and hard to understand. But since they are only used in this function for draw graph purpose, they will not hurt the business logic outside. As of June 21, 2011, this function seems work fine, so no hurry to clean up. These parameters and code in this function should be cleaned along with fd.f1list, fd.parlist, fd.samplelist later. - - # This should still be riset here - Sam - Nov. 2012 - if fd.genotype.type == "riset": - samplelist = fd.f1list + fd.samplelist + def build_correlation_tools(self): + if self.temp_trait == True: + this_group = self.temp_group else: - samplelist = fd.f1list + fd.parlist + fd.samplelist - - other_samples = [] #XZ: sample that is not of primary group - specialStrains = [] #XZ: This might be replaced by other_samples / ZS: It is just other samples without parent/f1 samples. - all_samples = [] - primary_samples = [] #XZ: sample of primary group, e.g., BXD, LXS - - #self.MDP_menu = HT.Select(name='stats_mdp', Class='stats_mdp') - self.MDP_menu = [] # We're going to use the same named data structure as in the old version - # but repurpose it for Jinja2 as an array - - for sample in this_trait.data.keys(): - sampleName = sample.replace("_2nd_", "") - if sample not in samplelist: - if this_trait.data[sampleName].value != None: - if sample.find('F1') < 0: - specialStrains.append(sample) - if (this_trait.data[sampleName].value != None) and (sample not in (fd.f1list + fd.parlist)): - other_samples.append(sample) #XZ: at current stage, other_samples doesn't include parent samples and F1 samples of primary group - else: - if (this_trait.data[sampleName].value != None) and (sample not in (fd.f1list + fd.parlist)): - primary_samples.append(sample) #XZ: at current stage, the primary_samples is the same as fd.samplelist / ZS: I tried defining primary_samples as fd.samplelist instead, but in some cases it ended up including the parent samples (1436869_at BXD) - - if len(other_samples) > 3: - other_samples.sort(key=webqtlUtil.natsort_key) - primary_samples.sort(key=webqtlUtil.natsort_key) - primary_samples = map(lambda X:"_2nd_"+X, fd.f1list + fd.parlist) + primary_samples #XZ: note that fd.f1list and fd.parlist are added. - all_samples = primary_samples + other_samples - other_samples = map(lambda X:"_2nd_"+X, fd.f1list + fd.parlist) + other_samples #XZ: note that fd.f1list and fd.parlist are added. - logger.debug("ac1") # This is the one used for first sall3 - self.MDP_menu.append(('All Cases','0')) - self.MDP_menu.append(('%s Only' % fd.group, '1')) - self.MDP_menu.append(('Non-%s Only' % fd.group, '2')) - - else: - if (len(other_samples) > 0) and (len(primary_samples) + len(other_samples) > 3): - logger.debug("ac2") - self.MDP_menu.append(('All Cases','0')) - self.MDP_menu.append(('%s Only' % fd.group,'1')) - self.MDP_menu.append(('Non-%s Only' % fd.group,'2')) - all_samples = primary_samples - all_samples.sort(key=webqtlUtil.natsort_key) - all_samples = map(lambda X:"_2nd_"+X, fd.f1list + fd.parlist) + all_samples - primary_samples = map(lambda X:"_2nd_"+X, fd.f1list + fd.parlist) + primary_samples - else: - logger.debug("ac3") - all_samples = samplelist - - other_samples.sort(key=webqtlUtil.natsort_key) - all_samples = all_samples + other_samples - - if (len(other_samples)) > 0 and (len(primary_samples) + len(other_samples) > 4): - #One set of vals for all, selected sample only, and non-selected only - vals1 = [] - vals2 = [] - vals3 = [] - - #Using all samples/cases for values - #for sample_type in (all_samples, primary_samples, other_samples): - for sampleNameOrig in all_samples: - sampleName = sampleNameOrig.replace("_2nd_", "") - - logger.debug("* type of this_trait:", type(this_trait)) - logger.debug(" name:", this_trait.__class__.__name__) - logger.debug(" this_trait:", this_trait) - logger.debug(" type of this_trait.data[sampleName]:", type(this_trait.data[sampleName])) - logger.debug(" name:", this_trait.data[sampleName].__class__.__name__) - logger.debug(" this_trait.data[sampleName]:", this_trait.data[sampleName]) - thisval = this_trait.data[sampleName].value - logger.debug(" thisval:", thisval) - thisvar = this_trait.data[sampleName].variance - logger.debug(" thisvar:", thisvar) - thisValFull = [sampleName, thisval, thisvar] - logger.debug(" thisValFull:", thisValFull) - - vals1.append(thisValFull) - - #Using just the group sample - for sampleNameOrig in primary_samples: - sampleName = sampleNameOrig.replace("_2nd_", "") - - thisval = this_trait.data[sampleName].value - thisvar = this_trait.data[sampleName].variance - thisValFull = [sampleName,thisval,thisvar] - - vals2.append(thisValFull) - - #Using all non-group samples only - for sampleNameOrig in other_samples: - sampleName = sampleNameOrig.replace("_2nd_", "") - - thisval = this_trait.data[sampleName].value - thisvar = this_trait.data[sampleName].variance - thisValFull = [sampleName,thisval,thisvar] - - vals3.append(thisValFull) - - vals_set = [vals1,vals2,vals3] - - else: - vals = [] - - #Using all samples/cases for values - for sampleNameOrig in all_samples: - sampleName = sampleNameOrig.replace("_2nd_", "") - - thisval = this_trait.data[sampleName].value - thisvar = this_trait.data[sampleName].variance - thisValFull = [sampleName,thisval,thisvar] - - vals.append(thisValFull) - - vals_set = [vals] - - self.stats_data = [] - for i, vals in enumerate(vals_set): - if i == 0 and len(vals) < 4: - stats_container = HT.Div(id="stats_tabs", style="padding:10px;", Class="ui-tabs") #Needed for tabs; notice the "stats_script_text" below referring to this element - stats_container.append(HT.Div(HT.Italic("Fewer than 4 case data were entered. No statistical analysis has been attempted."))) - break - elif (i == 1 and len(primary_samples) < 4): - stats_container = HT.Div(id="stats_tabs%s" % i, Class="ui-tabs") - #stats_container.append(HT.Div(HT.Italic("Fewer than 4 " + fd.group + " case data were entered. No statistical analysis has been attempted."))) - elif (i == 2 and len(other_samples) < 4): - stats_container = HT.Div(id="stats_tabs%s" % i, Class="ui-tabs") - stats_container.append(HT.Div(HT.Italic("Fewer than 4 non-" + fd.group + " case data were entered. No statistical analysis has been attempted."))) - else: - continue - if len(vals) > 4: - stats_tab_list = [HT.Href(text="Basic Table", url="#statstabs-1", Class="stats_tab"),HT.Href(text="Probability Plot", url="#statstabs-5", Class="stats_tab"), - HT.Href(text="Bar Graph (by name)", url="#statstabs-3", Class="stats_tab"), HT.Href(text="Bar Graph (by rank)", url="#statstabs-4", Class="stats_tab"), - HT.Href(text="Box Plot", url="#statstabs-2", Class="stats_tab")] - - if this_trait.dataset: - if this_trait.cellid: - self.stats_data.append(BasicStatisticsFunctions.basicStatsTable(vals=vals, trait_type=this_trait.dataset.type, cellid=this_trait.cellid)) - else: - self.stats_data.append(BasicStatisticsFunctions.basicStatsTable(vals=vals, trait_type=this_trait.dataset.type)) - else: - self.stats_data.append(BasicStatisticsFunctions.basicStatsTable(vals=vals)) - - #normalplot_div = HT.Div(id="statstabs-5") - #normalplot_container = HT.Paragraph() - #normalplot = HT.TableLite(cellspacing=0, cellpadding=0, width="100%") - - try: - plotTitle = this_trait.symbol - plotTitle += ": " - plotTitle += this_trait.name - except: - plotTitle = str(this_trait.name) - - #normalplot_img = BasicStatisticsFunctions.plotNormalProbability(vals=vals, group=fd.group, title=plotTitle, specialStrains=specialStrains) - #normalplot.append(HT.TR(HT.TD(normalplot_img))) - #normalplot.append(HT.TR(HT.TD(HT.BR(),HT.BR(),"This plot evaluates whether data are \ - #normally distributed. Different symbols represent different groups.",HT.BR(),HT.BR(), - #"More about ", HT.Href(url="http://en.wikipedia.org/wiki/Normal_probability_plot", - # target="_blank", text="Normal Probability Plots"), " and more about interpreting these plots from the ", HT.Href(url="/glossary.html#normal_probability", target="_blank", text="glossary")))) - - #boxplot_div = HT.Div(id="statstabs-2") - #boxplot_container = HT.Paragraph() - #boxplot = HT.TableLite(cellspacing=0, cellpadding=0, width="100%") - #boxplot_img, boxplot_link = BasicStatisticsFunctions.plotBoxPlot(vals) - #boxplot.append(HT.TR(HT.TD(boxplot_img, HT.P(), boxplot_link, align="left"))) - - #barName_div = HT.Div(id="statstabs-3") - #barName_container = HT.Paragraph() - #barName = HT.TableLite(cellspacing=0, cellpadding=0, width="100%") - #barName_img = BasicStatisticsFunctions.plotBarGraph(identification=fd.identification, group=fd.group, vals=vals, type="name") - - #barRank_div = HT.Div(id="statstabs-4") - #barRank_container = HT.Paragraph() - #barRank = HT.TableLite(cellspacing=0, cellpadding=0, width="100%") - #barRank_img = BasicStatisticsFunctions.plotBarGraph(identification=fd.identification, group=fd.group, vals=vals, type="rank") - - - def build_correlation_tools(self, this_trait): - - #species = webqtlDatabaseFunction.retrieveSpecies(cursor=self.cursor, group=fd.group) - - this_group = self.dataset.group.name + this_group = self.dataset.group.name # We're checking a string here! assert isinstance(this_group, basestring), "We need a string type thing here" @@ -916,11 +166,15 @@ class ShowTrait(object): this_group = 'BXD' if this_group: - dataset_menu = self.dataset.group.datasets() + #dataset_menu = self.dataset.group.datasets() + if self.temp_trait == True: + dataset_menu = data_set.datasets(this_group) + else: + dataset_menu = data_set.datasets(this_group, self.dataset.group) dataset_menu_selected = None if len(dataset_menu): - if this_trait and this_trait.dataset: - dataset_menu_selected = this_trait.dataset.name + if self.this_trait and self.this_trait.dataset: + dataset_menu_selected = self.this_trait.dataset.name return_results_menu = (100, 200, 500, 1000, 2000, 5000, 10000, 15000, 20000) return_results_menu_selected = 500 @@ -931,263 +185,9 @@ class ShowTrait(object): return_results_menu_selected = return_results_menu_selected,) - def build_mapping_tools(self, this_trait): - - - #_Species = webqtlDatabaseFunction.retrieveSpecies(cursor=self.cursor, group=fd.group) - - this_group = fd.group - if this_group[:3] == 'BXD': - this_group = 'BXD' - - #check boxes - one for regular interval mapping, the other for composite - permCheck1= HT.Input(type='checkbox', Class='checkbox', name='permCheck1',checked="on") - bootCheck1= HT.Input(type='checkbox', Class='checkbox', name='bootCheck1',checked=0) - permCheck2= HT.Input(type='checkbox', Class='checkbox', name='permCheck2',checked="on") - bootCheck2= HT.Input(type='checkbox', Class='checkbox', name='bootCheck2',checked=0) - optionbox1 = HT.Input(type='checkbox', Class='checkbox', name='parentsf14regression1',checked=0) - optionbox2 = HT.Input(type='checkbox', Class='checkbox', name='parentsf14regression2',checked=0) - optionbox3 = HT.Input(type='checkbox', Class='checkbox', name='parentsf14regression3',checked=0) - applyVariance1 = HT.Input(name='applyVarianceSE1',type='checkbox', Class='checkbox') - applyVariance2 = HT.Input(name='applyVarianceSE2',type='checkbox', Class='checkbox') - - IntervalMappingButton=HT.Input(type='button' ,name='interval',value=' Compute ', Class="button") - CompositeMappingButton=HT.Input(type='button' ,name='composite',value=' Compute ', Class="button") - MarkerRegressionButton=HT.Input(type='button',name='marker', value=' Compute ', Class="button") - - chrText = HT.Span("Chromosome:", Class="ffl fwb fs12") - - # updated by NL 5-28-2010 - # Interval Mapping - chrMenu = HT.Select(name='chromosomes1') - chrMenu.append(("All",-1)) - for i in range(len(fd.genotype)): - if len(fd.genotype[i]) > 1: - chrMenu.append((fd.genotype[i].name, i)) - - #Menu for Composite Interval Mapping - chrMenu2 = HT.Select(name='chromosomes2') - chrMenu2.append(("All",-1)) - for i in range(len(fd.genotype)): - if len(fd.genotype[i]) > 1: - chrMenu2.append((fd.genotype[i].name, i)) - - if fd.genotype.Mbmap: - scaleText = HT.Span("Mapping Scale:", Class="ffl fwb fs12") - scaleMenu1 = HT.Select(name='scale1', - onChange="checkUncheck(window.document.dataInput.scale1.value, window.document.dataInput.permCheck1, window.document.dataInput.bootCheck1)") - scaleMenu1.append(("Megabase",'physic')) - scaleMenu1.append(("Centimorgan",'morgan')) - scaleMenu2 = HT.Select(name='scale2', - onChange="checkUncheck(window.document.dataInput.scale2.value, window.document.dataInput.permCheck2, window.document.dataInput.bootCheck2)") - scaleMenu2.append(("Megabase",'physic')) - scaleMenu2.append(("Centimorgan",'morgan')) - - controlText = HT.Span("Control Locus:", Class="ffl fwb fs12") - controlMenu = HT.Input(type="text", name="controlLocus", Class="controlLocus") - - if fd.genotype.Mbmap: - intMappingMenu = HT.TableLite( - HT.TR(HT.TD(chrText), HT.TD(chrMenu, colspan="3")), - HT.TR(HT.TD(scaleText), HT.TD(scaleMenu1)), - cellspacing=0, width="263px", cellpadding=2) - compMappingMenu = HT.TableLite( - HT.TR(HT.TD(chrText), HT.TD(chrMenu2, colspan="3")), - HT.TR(HT.TD(scaleText), HT.TD(scaleMenu2)), - HT.TR(HT.TD(controlText), HT.TD(controlMenu)), - cellspacing=0, width="325px", cellpadding=2) - else: - intMappingMenu = HT.TableLite( - HT.TR(HT.TD(chrText), HT.TD(chrMenu, colspan="3")), - cellspacing=0, width="263px", cellpadding=2) - compMappingMenu = HT.TableLite( - HT.TR(HT.TD(chrText), HT.TD(chrMenu2, colspan="3")), - HT.TR(HT.TD(controlText), HT.TD(controlMenu)), - cellspacing=0, width="325px", cellpadding=2) - - directPlotButton = "" - directPlotButton = HT.Input(type='button',name='', value=' Compute ',\ - onClick="dataEditingFunc(this.form,'directPlot');",Class="button") - directPlotSortText = HT.Span(HT.Bold("Sort by: "), Class="ffl fwb fs12") - directPlotSortMenu = HT.Select(name='graphSort') - directPlotSortMenu.append(('LRS Full',0)) - directPlotSortMenu.append(('LRS Interact',1)) - directPlotPermuText = HT.Span("Permutation Test (n=500)", Class="ffl fs12") - directPlotPermu = HT.Input(type='checkbox', Class='checkbox',name='directPermuCheckbox', checked="on") - pairScanReturnText = HT.Span(HT.Bold("Return: "), Class="ffl fwb fs12") - pairScanReturnMenu = HT.Select(name='pairScanReturn') - pairScanReturnMenu.append(('top 50','50')) - pairScanReturnMenu.append(('top 100','100')) - pairScanReturnMenu.append(('top 200','200')) - pairScanReturnMenu.append(('top 500','500')) - - pairScanMenus = HT.TableLite( - HT.TR(HT.TD(directPlotSortText), HT.TD(directPlotSortMenu)), - HT.TR(HT.TD(pairScanReturnText), HT.TD(pairScanReturnMenu)), - cellspacing=0, width="232px", cellpadding=2) - - markerSuggestiveText = HT.Span(HT.Bold("Display LRS greater than:"), Class="ffl fwb fs12") - markerSuggestive = HT.Input(name='suggestive', size=5, maxlength=8) - displayAllText = HT.Span(" Display all LRS ", Class="ffl fs12") - displayAll = HT.Input(name='displayAllLRS', type="checkbox", Class='checkbox') - useParentsText = HT.Span(" Use Parents ", Class="ffl fs12") - useParents = optionbox2 - applyVarianceText = HT.Span(" Use Weighted ", Class="ffl fs12") - - markerMenu = HT.TableLite( - HT.TR(HT.TD(markerSuggestiveText), HT.TD(markerSuggestive)), - HT.TR(HT.TD(displayAll,displayAllText)), - HT.TR(HT.TD(useParents,useParentsText)), - HT.TR(HT.TD(applyVariance2,applyVarianceText)), - cellspacing=0, width="263px", cellpadding=2) - - - mapping_row = HT.TR() - mapping_container = HT.Div(id="mapping_tabs", Class="ui-tabs") - - mapping_tab_list = [HT.Href(text="Interval", url="#mappingtabs-1"), HT.Href(text="Marker Regression", url="#mappingtabs-2"), HT.Href(text="Composite", url="#mappingtabs-3"), HT.Href(text="Pair-Scan", url="#mappingtabs-4")] - mapping_tabs = HT.List(mapping_tab_list) - mapping_container.append(mapping_tabs) - - interval_div = HT.Div(id="mappingtabs-1") - interval_container = HT.Span() - - intervalTable = HT.TableLite(cellspacing=0, cellpadding=0, width="100%") - intTD = HT.TD(valign="top",NOWRAP='ON', Class="fs12 fwn") - intTD.append(intMappingMenu,HT.BR()) - - intTD.append(permCheck1,'Permutation Test (n=2000)',HT.BR(), - bootCheck1,'Bootstrap Test (n=2000)', HT.BR(), optionbox1, 'Use Parents', HT.BR(), - applyVariance1,'Use Weighted', HT.BR(), HT.BR(),IntervalMappingButton, HT.BR(), HT.BR()) - intervalTable.append(HT.TR(intTD), HT.TR(HT.TD(HT.Span(HT.Href(url='/glossary.html#intmap', target='_blank', text='Interval Mapping'), - ' computes linkage maps for the entire genome or single',HT.BR(),' chromosomes.', - ' The ',HT.Href(url='/glossary.html#permutation', target='_blank', text='Permutation Test'),' estimates suggestive and significant ',HT.BR(),' linkage scores. \ - The ',HT.Href(url='/glossary.html#bootstrap', target='_blank', text='Bootstrap Test'), ' estimates the precision of the QTL location.' - ,Class="fs12"), HT.BR(), valign="top"))) - - interval_container.append(intervalTable) - interval_div.append(interval_container) - mapping_container.append(interval_div) - - # Marker Regression - - marker_div = HT.Div(id="mappingtabs-2") - marker_container = HT.Span() - - markerTable = HT.TableLite(cellspacing=0, cellpadding=0, width="100%") - markerTD = HT.TD(valign="top",NOWRAP='ON', Class="fs12 fwn") - markerTD.append(markerMenu,HT.BR()) - - markerTD.append(MarkerRegressionButton,HT.BR(),HT.BR()) - - markerTable.append(HT.TR(markerTD),HT.TR(HT.TD(HT.Span(HT.Href(url='/glossary.html#',target='_blank',text='Marker regression'), - ' computes and displays LRS values for individual markers.',HT.BR(), - 'This function also lists additive effects (phenotype units per allele) and', HT.BR(), - 'dominance deviations for some datasets.', HT.BR(),Class="fs12"), HT.BR(), valign="top"))) - - marker_container.append(markerTable) - marker_div.append(marker_container) - mapping_container.append(marker_div) - - # Composite interval mapping - composite_div = HT.Div(id="mappingtabs-3") - composite_container = HT.Span() - - compositeTable = HT.TableLite(cellspacing=0, cellpadding=3, width="100%") - compTD = HT.TD(valign="top",NOWRAP='ON', Class="fs12 fwn") - compTD.append(compMappingMenu,HT.BR()) - - compTD.append(permCheck2, 'Permutation Test (n=2000)',HT.BR(), - bootCheck2,'Bootstrap Test (n=2000)', HT.BR(), - optionbox3, 'Use Parents', HT.BR(), HT.BR(), CompositeMappingButton, HT.BR(), HT.BR()) - compositeTable.append(HT.TR(compTD), HT.TR(HT.TD(HT.Span(HT.Href(url='/glossary.html#Composite',target='_blank',text='Composite Interval Mapping'), - " allows you to control for a single marker as",HT.BR()," a cofactor. ", - "To find a control marker, run the ",HT.Bold("Marker Regression")," function."), - HT.BR(), valign="top"))) - - composite_container.append(compositeTable) - composite_div.append(composite_container) - mapping_container.append(composite_div) - - # Pair Scan - - pairscan_div = HT.Div(id="mappingtabs-4") - pairscan_container = HT.Span() - - pairScanTable = HT.TableLite(cellspacing=0, cellpadding=0, width="100%") - pairScanTD = HT.TD(NOWRAP='ON', Class="fs12 fwn") - pairScanTD.append(pairScanMenus,HT.BR()) - pairScanTD.append(directPlotPermu, directPlotPermuText, HT.BR(), HT.BR(), - directPlotButton,HT.BR(),HT.BR()) - pairScanTable.append(HT.TR(pairScanTD), HT.TR(HT.TD(HT.Span(HT.Href(url='/glossary.html#Pair_Scan', target="_blank", text='Pair-Scan'), - ' searches for pairs of chromosomal regions that are',HT.BR(), - 'involved in two-locus epistatic interactions.'), HT.BR(), valign="top"))) - - pairscan_container.append(pairScanTable) - pairscan_div.append(pairscan_container) - mapping_container.append(pairscan_div) - - mapping_row.append(HT.TD(mapping_container)) - - # Treat Interval Mapping and Marker Regression and Pair Scan as a group for displaying - #disable Interval Mapping and Marker Regression and Pair Scan for human and the dataset doesn't have genotype file - mappingMethodId = webqtlDatabaseFunction.getMappingMethod(cursor=self.cursor, groupName=this_group) - - mapping_script = HT.Script(language="Javascript") - mapping_script_text = """$(function() { $("#mapping_tabs").tabs(); });""" - mapping_script.append(mapping_script_text) - - submitTable = HT.TableLite(cellspacing=0, cellpadding=0, width="100%", Class="target2") - - if not mappingMethodId: - if int(mappingMethodId) == 1: - submitTable.append(mapping_row) - submitTable.append(mapping_script) - elif int(mappingMethodId) == 4: - # NL; 09-26-2011 testing for Human Genome Association function - mapping_row=HT.TR() - mapping_container = HT.Div(id="mapping_tabs", Class="ui-tabs") - - mapping_tab_list = [HT.Href(text="Genome Association", url="#mappingtabs-1")] - mapping_tabs = HT.List(mapping_tab_list) - mapping_container.append(mapping_tabs) - - # Genome Association - markerSuggestiveText = HT.Span(HT.Bold("P Value:"), Class="ffl fwb fs12") - - markerSuggestive = HT.Input(name='pValue', value='0.001', size=10, maxlength=20,onClick="this.value='';",onBlur="if(this.value==''){this.value='0.001'};") - markerMenu = HT.TableLite(HT.TR(HT.TD(markerSuggestiveText), HT.TD(markerSuggestive),HT.TD(HT.Italic(' (e.g. 0.001 or 1e-3 or 1E-3 or 3)'))),cellspacing=0, width="400px", cellpadding=2) - MarkerRegressionButton=HT.Input(type='button',name='computePlink', value=' Compute Using PLINK ', onClick= "validatePvalue(this.form);", Class="button") - - marker_div = HT.Div(id="mappingtabs-1") - marker_container = HT.Span() - markerTable = HT.TableLite(cellspacing=0, cellpadding=0, width="100%") - markerTD = HT.TD(valign="top",NOWRAP='ON', Class="fs12 fwn") - markerTD.append(markerMenu,HT.BR()) - markerTD.append(MarkerRegressionButton,HT.BR(),HT.BR()) - markerTable.append(HT.TR(markerTD)) - - marker_container.append(markerTable) - marker_div.append(marker_container) - - mapping_container.append(marker_div) - mapping_row.append(HT.TD(mapping_container)) - submitTable.append(mapping_row) - submitTable.append(mapping_script) - else: - submitTable.append(HT.TR(HT.TD(HT.Div(HT.Italic("mappingMethodId %s has not been implemented for this dataset yet." % mappingMethodId), id="mapping_tabs", Class="ui-tabs")))) - submitTable.append(mapping_script) - - else: - submitTable.append(HT.TR(HT.TD(HT.Div(HT.Italic("Mapping options are disabled for data not matched with genotypes."), id="mapping_tabs", Class="ui-tabs")))) - submitTable.append(mapping_script) - - title4Body.append(submitTable) - - def make_sample_lists(self, this_trait): all_samples_ordered = self.dataset.group.all_samples_ordered() - + primary_sample_names = list(all_samples_ordered) other_sample_names = [] @@ -1210,7 +210,7 @@ class ShowTrait(object): logger.debug("primary_samples is: ", pf(primary_samples)) logger.debug("other_sample_names2:", other_sample_names) - if other_sample_names and self.dataset.group.species != "human": + if other_sample_names and self.dataset.group.species != "human" and self.dataset.group.name != "CFW": parent_f1_samples = None if self.dataset.group.parlist and self.dataset.group.f1list: parent_f1_samples = self.dataset.group.parlist + self.dataset.group.f1list @@ -1261,10 +261,19 @@ def get_nearest_marker(this_trait, this_db): return result[0][0] #return result[0][0], result[1][0] +def get_genofiles(this_trait): + jsonfile = "%s/%s.json" % (webqtlConfig.GENODIR, this_trait.dataset.group.name) + try: + f = open(jsonfile) + except: + return None + jsondata = json.load(f) + return jsondata['genofile'] + def get_trait_table_width(sample_groups): - table_width = 35 + table_width = 20 if sample_groups[0].se_exists(): - table_width += 10 + table_width += 15 if (table_width + len(sample_groups[0].attributes)*10) > 100: table_width = 100 else: diff --git a/wqflask/wqflask/static/new/css/main.css b/wqflask/wqflask/static/new/css/main.css index 017bbdb8..880395a7 100644 --- a/wqflask/wqflask/static/new/css/main.css +++ b/wqflask/wqflask/static/new/css/main.css @@ -2,3 +2,10 @@ padding-left: 30px; padding-right: 30px; } + +ol { + font-family: Arial; + font-weight: bold; + font-size: 16px; + color: #000082 +}
\ No newline at end of file diff --git a/wqflask/wqflask/static/new/javascript/biodalliance.js b/wqflask/wqflask/static/new/javascript/biodalliance.js new file mode 100644 index 00000000..3b9e3b7f --- /dev/null +++ b/wqflask/wqflask/static/new/javascript/biodalliance.js @@ -0,0 +1,72 @@ +"use strict"; + + +var BD = {}; +BD.browser = null; +BD.data = {}; +BD.sources = []; + +var getChrLen = function(chr) { + return js_data[chr * 1]; +}; + +BD.createBrowser = function(chr, start, end, speciesName, sources) { + console.log("creating BD browser"); + var b = new Browser({ + chr: chr, + viewStart: start, + viewEnd: end, + + coordSystem: { + speciesName: speciesName + }, + + sources: sources, + + maxHeight: 1400, + setDocumentTitle: false, + prefix: '/dalliance/', + workerPrefix: 'build/', + noPersist: true, + pageName: 'bd_container' + }); + + console.log("created BD browser"); + return b; +}; + +BD.showButton = function() { + $('#open_bd').show(); + $('#close_bd').hide(); +}; + +BD.hideButton = function() { + $('#close_bd').show(); + $('#open_bd').hide(); +}; + + +BD.putData = function(data) { + for (var key in data) { + BD.data[key] = data[key]; + } +}; + +BD.putSource = function(source) { + BD.sources.push(source); +}; + +BD.openBrowser = function() { + console.log("opening browser"); + if (!BD.browser) { + BD.browser = BD.createBrowser(BD.data.chr, + 0, + BD.data.length * 1000000, + BD.data.species, + BD.sources); + } else { + BD.browser.setLocation(BD.data.chr, 0, BD.data.length * 1000000); + } + + BD.browser.maxViewWidth = BD.data.length * 1000000; +}; diff --git a/wqflask/wqflask/static/new/javascript/chr_lod_chart.coffee b/wqflask/wqflask/static/new/javascript/chr_lod_chart.coffee index e00694be..8a5a3569 100644 --- a/wqflask/wqflask/static/new/javascript/chr_lod_chart.coffee +++ b/wqflask/wqflask/static/new/javascript/chr_lod_chart.coffee @@ -5,7 +5,7 @@ class Chr_Lod_Chart @qtl_results = js_data.qtl_results
console.log("qtl_results are:", @qtl_results)
console.log("chr is:", @chr)
-
+
@get_max_chr()
@filter_qtl_results()
@@ -21,16 +21,16 @@ class Chr_Lod_Chart console.log("@x_coords: ", @x_coords)
console.log("@y_coords: ", @y_coords)
console.timeEnd('Create coordinates')
-
+
# Buffer to allow for the ticks/labels to be drawn
@x_buffer = @plot_width/30
@y_buffer = @plot_height/20
-
+
@x_max = d3.max(@x_coords)
@y_max = d3.max(@y_coords) * 1.2
-
+
@y_threshold = @get_lod_threshold()
-
+
@svg = @create_svg()
@plot_coordinates = _.zip(@x_coords, @y_coords, @marker_names)
@@ -43,14 +43,14 @@ class Chr_Lod_Chart console.time('Create graph')
@create_graph()
console.timeEnd('Create graph')
-
+
get_max_chr: () ->
@max_chr = 0
for key of js_data.chromosomes
console.log("key is:", key)
if parseInt(key) > @max_chr
@max_chr = parseInt(key)
-
+
filter_qtl_results: () ->
@these_results = []
this_chr = 100
@@ -59,8 +59,8 @@ class Chr_Lod_Chart this_chr = @max_chr
else
this_chr = result.chr
- console.log("this_chr is:", this_chr)
- console.log("@chr[0] is:", parseInt(@chr[0]))
+ # console.log("this_chr is:", this_chr)
+ # console.log("@chr[0] is:", parseInt(@chr[0]))
if this_chr > parseInt(@chr[0])
break
if parseInt(this_chr) == parseInt(@chr[0])
@@ -72,7 +72,7 @@ class Chr_Lod_Chart if result.lod_score > 1
high_qtl_count += 1
console.log("high_qtl_count:", high_qtl_count)
-
+
#if high_qtl_count > 10000
@y_axis_filter = 2
#else if high_qtl_count > 1000
@@ -85,7 +85,7 @@ class Chr_Lod_Chart @x_coords.push(parseFloat(result.Mb))
@y_coords.push(result.lod_score)
@marker_names.push(result.name)
-
+
create_svg: () ->
svg = d3.select("#topchart")
.append("svg")
@@ -102,7 +102,7 @@ class Chr_Lod_Chart @y_scale = d3.scale.linear()
.domain([0, @y_max])
.range([@plot_height, @y_buffer])
-
+
get_lod_threshold: () ->
if @y_max/2 > 2
return @y_max/2
@@ -125,7 +125,7 @@ class Chr_Lod_Chart [@y_buffer, @plot_height, @plot_width, @plot_width],
[@y_buffer, @y_buffer, @x_buffer, @plot_width],
[@plot_height, @plot_height, @x_buffer, @plot_width]]
-
+
@svg.selectAll("line")
.data(border_coords)
.enter()
@@ -141,7 +141,7 @@ class Chr_Lod_Chart )
.attr("x2", (d) =>
return d[3]
- )
+ )
.style("stroke", "#000")
add_x_axis: () ->
@@ -166,13 +166,13 @@ class Chr_Lod_Chart .attr("transform", (d) =>
return "translate(-12,0) rotate(-90)"
)
-
+
add_y_axis: () ->
@yAxis = d3.svg.axis()
.scale(@y_scale)
.orient("left")
.ticks(5)
-
+
@svg.append("g")
.attr("class", "y_axis")
.attr("transform", "translate(" + @x_buffer + ",0)")
@@ -200,7 +200,7 @@ class Chr_Lod_Chart .x( (d) => return @x_scale(d[0]))
.y( (d) => return @y_scale(d[1]))
.interpolate("linear")
-
+
line_graph = @svg.append("path")
.attr("d", line_function(@plot_coordinates))
.attr("stroke", "blue")
@@ -273,6 +273,9 @@ class Chr_Lod_Chart $("#return_to_full_view").hide()
$('#topchart').remove()
$('#chart_container').append('<div class="qtlcharts" id="topchart"></div>')
+ BD.hideButton()
+ $('#close_bd').hide();
+ $('#bd_container').hide()
create_lod_chart()
show_marker_in_table: (marker_info) ->
diff --git a/wqflask/wqflask/static/new/javascript/chr_lod_chart.js b/wqflask/wqflask/static/new/javascript/chr_lod_chart.js index c6cbd01b..bae4565d 100644 --- a/wqflask/wqflask/static/new/javascript/chr_lod_chart.js +++ b/wqflask/wqflask/static/new/javascript/chr_lod_chart.js @@ -1,13 +1,12 @@ -// Generated by CoffeeScript 1.9.2 +// Generated by CoffeeScript 1.10.0 var Chr_Lod_Chart; Chr_Lod_Chart = (function() { - function Chr_Lod_Chart(plot_height, plot_width, chr, manhattanPlot, mappingScale) { + function Chr_Lod_Chart(plot_height, plot_width, chr, manhattanPlot) { this.plot_height = plot_height; this.plot_width = plot_width; this.chr = chr; this.manhattanPlot = manhattanPlot; - this.mappingScale = mappingScale; this.qtl_results = js_data.qtl_results; console.log("qtl_results are:", this.qtl_results); console.log("chr is:", this.chr); @@ -95,18 +94,11 @@ Chr_Lod_Chart = (function() { Chr_Lod_Chart.prototype.create_coordinates = function() { var i, len, ref, result, results; ref = this.these_results; - console.log("THESE_RESULTS:", ref) results = []; for (i = 0, len = ref.length; i < len; i++) { result = ref[i]; this.x_coords.push(parseFloat(result.Mb)); - if (js_data.result_score_type == "LOD") { - this.y_coords.push(result.lod_score); - } - else { - console.log("LRS VALUE:", result['lrs_value']) - this.y_coords.push(result['lrs_value']); - } + this.y_coords.push(result.lod_score); results.push(this.marker_names.push(result.name)); } return results; @@ -119,19 +111,7 @@ Chr_Lod_Chart = (function() { }; Chr_Lod_Chart.prototype.create_scales = function() { - if (this.mappingScale == "morgan") { - max_pos = 0 - for (i = 0, len = this.these_results.length; i < len; i++) { - marker = this.these_results[i] - if (parseFloat(marker['Mb']) > max_pos){ - max_pos = parseFloat(marker.Mb) - } - } - this.x_scale = d3.scale.linear().domain([0, max_pos]).range([this.x_buffer, this.plot_width]); - } - else { - this.x_scale = d3.scale.linear().domain([0, this.chr[1]]).range([this.x_buffer, this.plot_width]); - } + this.x_scale = d3.scale.linear().domain([0, this.chr[1]]).range([this.x_buffer, this.plot_width]); return this.y_scale = d3.scale.linear().domain([0, this.y_max]).range([this.plot_height, this.y_buffer]); }; @@ -278,6 +258,9 @@ Chr_Lod_Chart = (function() { $("#return_to_full_view").hide(); $('#topchart').remove(); $('#chart_container').append('<div class="qtlcharts" id="topchart"></div>'); + BD.hideButton(); + $('#close_bd').hide(); + $('#bd_container').hide(); return create_lod_chart(); }; diff --git a/wqflask/wqflask/static/new/javascript/create_corr_matrix.js b/wqflask/wqflask/static/new/javascript/create_corr_matrix.js index adb91295..44ed3c81 100644 --- a/wqflask/wqflask/static/new/javascript/create_corr_matrix.js +++ b/wqflask/wqflask/static/new/javascript/create_corr_matrix.js @@ -1,48 +1,47 @@ // Generated by CoffeeScript 1.8.0 -var get_data, get_options, root; +// var get_data, get_options, root; -root = typeof exports !== "undefined" && exports !== null ? exports : this; +// root = typeof exports !== "undefined" && exports !== null ? exports : this; -$(function() { - var chartOpts, data, mychart; - console.log("js_data:", js_data); - chartOpts = get_options(); - data = get_data(); - console.log(data); - return mychart = corr_matrix(data, chartOpts); -}); - -get_options = function() { - var chartOpts; - chartOpts = { - cortitle: "Correlation Matrix", - scattitle: "Scatterplot", - h: 450, - w: 450, - margin: { - left: 100, - top: 40, - right: 5, - bottom: 70, - inner: 5 - } - }; - return chartOpts; -}; +// $(function() { + // var chartOpts, data, mychart; + // console.log("js_data:", js_data); + // chartOpts = get_options(); + // data = get_data(); + // console.log(data); + // return mychart = corr_matrix(data, chartOpts); +// }); -get_data = function() { - var data; - data = {}; - data["var"] = js_data.traits; - data.group = js_data.groups; - data.indID = js_data.samples; - data.dat = js_data.sample_data; - data.corr = js_data.corr_results; - data.cols = js_data.cols; - data.rows = js_data.rows; - return data; -}; +// get_options = function() { + // var chartOpts; + // chartOpts = { + // cortitle: "Correlation Matrix", + // scattitle: "Scatterplot", + // h: 450, + // w: 450, + // margin: { + // left: 100, + // top: 40, + // right: 5, + // bottom: 70, + // inner: 5 + // } + // }; + // return chartOpts; +// }; +// get_data = function() { + // var data; + // data = {}; + // data["var"] = js_data.traits; + // data.group = js_data.groups; + // data.indID = js_data.samples; + // data.dat = js_data.sample_data; + // data.corr = js_data.corr_results; + // data.cols = js_data.cols; + // data.rows = js_data.rows; + // return data; +// }; var neg_color_scale = chroma.scale(['#FF0000', 'white']).domain([-1, -0.4]); var pos_color_scale = chroma.scale(['white', 'aqua']).domain([0.4, 1]) @@ -57,4 +56,26 @@ $('.corr_cell').each( function () { else { $(this).css('background-color', 'white') } +}); + +$('#short_labels').click( function (){ + $('.shortName').each( function() { + if ($(this).css("display") == "none"){ + $(this).css("display", "block"); + } + else { + $(this).css("display", "none"); + } + }); +}); + +$('#long_labels').click( function (){ + $('.verboseName').each( function() { + if ($(this).css("display") == "none"){ + $(this).css("display", "block"); + } + else { + $(this).css("display", "none"); + } + }); });
\ No newline at end of file diff --git a/wqflask/wqflask/static/new/javascript/create_lodchart.coffee b/wqflask/wqflask/static/new/javascript/create_lodchart.coffee index 88003f4e..f6dfd7a3 100644 --- a/wqflask/wqflask/static/new/javascript/create_lodchart.coffee +++ b/wqflask/wqflask/static/new/javascript/create_lodchart.coffee @@ -9,9 +9,9 @@ create_lod_chart = -> additive = js_data.additive else additive = false - + console.log("js_data:", js_data) - + # simplest use #d3.json "data.json", (data) -> mychart = lodchart().lodvarname("lod.hk") @@ -21,13 +21,13 @@ create_lod_chart = -> .ylab(js_data.result_score_type + " score") .manhattanPlot(js_data.manhattan_plot) #.additive(additive) - + data = js_data.json_data - + d3.select("div#topchart") .datum(data) .call(mychart) - + # grab chromosome rectangles; color pink on hover chrrect = mychart.chrSelect() chrrect.on "mouseover", -> @@ -36,7 +36,7 @@ create_lod_chart = -> d3.select(this).attr("fill", -> return "#F1F1F9" if i % 2 "#FBFBFF") - + # animate points at markers on click mychart.markerSelect() .on "click", (d) -> @@ -44,7 +44,3 @@ create_lod_chart = -> d3.select(this) .transition().duration(500).attr("r", r*3) .transition().duration(500).attr("r", r) - -$ -> - root.create_lod_chart = create_lod_chart - diff --git a/wqflask/wqflask/static/new/javascript/create_lodchart.js b/wqflask/wqflask/static/new/javascript/create_lodchart.js index 778eed3a..d2c531f9 100644 --- a/wqflask/wqflask/static/new/javascript/create_lodchart.js +++ b/wqflask/wqflask/static/new/javascript/create_lodchart.js @@ -1,4 +1,5 @@ -//var create_lod_chart; +// Generated by CoffeeScript 1.10.0 +var create_lod_chart; create_lod_chart = function() { var additive, chrrect, data, h, halfh, margin, mychart, totalh, totalw, w; @@ -40,11 +41,3 @@ create_lod_chart = function() { return d3.select(this).transition().duration(500).attr("r", r * 3).transition().duration(500).attr("r", r); }); }; - -create_lod_chart() - -/* -$(function() { - return root.create_lod_chart = create_lod_chart; -}); -*/
\ No newline at end of file diff --git a/wqflask/wqflask/static/new/javascript/ctl_graph.js b/wqflask/wqflask/static/new/javascript/ctl_graph.js new file mode 100644 index 00000000..94bd7e9d --- /dev/null +++ b/wqflask/wqflask/static/new/javascript/ctl_graph.js @@ -0,0 +1,199 @@ +window.onload=function() { + // id of Cytoscape Web container div + //var div_id = "cytoscapeweb"; + + var cy = cytoscape({ + container: $('#cytoscapeweb'), // container to render in + + elements: elements_list, + + style: [ // the stylesheet for the graph + { + selector: 'node', + style: { + 'background-color': '#666', + 'label': 'data(symbol)', + 'font-size': 10 + } + }, + + { + selector: 'edge', + style: { + 'width': 'data(width)', + 'line-color': 'data(color)', + 'target-arrow-color': '#ccc', + 'target-arrow-shape': 'none', + 'font-size': 8, + 'curve-style': 'bezier' + } + } + ], + + zoom: 12, + layout: { name: 'circle', + fit: true, // whether to fit the viewport to the graph + padding: 30 // the padding on fit + //idealEdgeLength: function( edge ){ return edge.data['correlation']*10; }, + }, + + + zoomingEnabled: true, + userZoomingEnabled: true, + panningEnabled: true, + userPanningEnabled: true, + boxSelectionEnabled: false, + selectionType: 'single', + + // rendering options: + styleEnabled: true + }); + + var eles = cy.$() // var containing all elements, so elements can be restored after being removed + + var defaults = { + zoomFactor: 0.05, // zoom factor per zoom tick + zoomDelay: 45, // how many ms between zoom ticks + minZoom: 0.1, // min zoom level + maxZoom: 10, // max zoom level + fitPadding: 30, // padding when fitting + panSpeed: 10, // how many ms in between pan ticks + panDistance: 10, // max pan distance per tick + panDragAreaSize: 75, // the length of the pan drag box in which the vector for panning is calculated (bigger = finer control of pan speed and direction) + panMinPercentSpeed: 0.25, // the slowest speed we can pan by (as a percent of panSpeed) + panInactiveArea: 8, // radius of inactive area in pan drag box + panIndicatorMinOpacity: 0.5, // min opacity of pan indicator (the draggable nib); scales from this to 1.0 + zoomOnly: false, // a minimal version of the ui only with zooming (useful on systems with bad mousewheel resolution) + fitSelector: undefined, // selector of elements to fit + animateOnFit: function(){ // whether to animate on fit + return false; + }, + fitAnimationDuration: 1000, // duration of animation on fit + + // icon class names + sliderHandleIcon: 'fa fa-minus', + zoomInIcon: 'fa fa-plus', + zoomOutIcon: 'fa fa-minus', + resetIcon: 'fa fa-expand' + }; + + cy.panzoom( defaults ); + + function create_qtips(cy){ + cy.nodes().qtip({ + content: function(){ + gn_link = '<b>'+'<a href="http://gn2.genenetwork.org/show_trait?trait_id=' + this.data().sid + '&dataset=' + this.data().dataset + '" >'+this.data().id +'</a>'+'</b><br>' + ncbi_link = '<a href="http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?db=gene&cmd=Retrieve&dopt=Graphics&list_uids=' + this.data().geneid + '" >NCBI<a>'+'<br>' + omim_link = '<a href="http://www.ncbi.nlm.nih.gov/omim/' + this.data().omim + '" >OMIM<a>'+'<br>' + qtip_content = gn_link + ncbi_link + omim_link + return qtip_content + //return '<b>'+'<a href="http://gn2.genenetwork.org/show_trait?trait_id=' + this.data().id + '&dataset=' + this.data().dataset + '" >'+this.data().id +'<a>'+'</b>' + }, + // content: { + // title: '<b>'+'<a href="http://gn2.genenetwork.org/show_trait?trait_id=' + this.target() + '&dataset=' + this.dataset() + '" >'+this.target() +'<a>'+'</b>', + // text: this.target, + // button: true + // }, + position: { + my: 'top center', + at: 'bottom center' + }, + style: { + classes: 'qtip-bootstrap', + tip: { + width: 16, + height: 8 + } + } + }); + + cy.edges().qtip({ + content: function(){ + edge_ID = '<b>Edge: ' + this.data().id + '</b><br>' + lod_score = 'LOD: ' + this.data().lod + '<br>' + return edge_ID + lod_score + }, + position: { + my: 'top center', + at: 'bottom center' + }, + style: { + classes: 'qtip-bootstrap', + tip: { + width: 16, + height: 8 + } + } + }); + } + + create_qtips(cy) + + $('#slide').change(function() { + eles.restore() + + console.log(eles) + + // nodes_to_restore = eles.filter("node[max_corr >= " + $(this).val() + "], edge[correlation >= " + $(this).val() + "][correlation <= -" + $(this).val() + "]") + // nodes_to_restore.restore() + + // edges_to_restore = eles.filter("edge[correlation >= " + $(this).val() + "][correlation <= -" + $(this).val() + "]") + // edges_to_restore.restore() + + //cy.$("node[max_corr >= " + $(this).val() + "]").restore(); + //cy.$("edge[correlation >= " + $(this).val() + "][correlation <= -" + $(this).val() + "]").restore(); + + cy.$("node[max_corr < " + $(this).val() + "]").remove(); + cy.$("edge[correlation < " + $(this).val() + "][correlation > -" + $(this).val() + "]").remove(); + + cy.layout({ name: $('select[name=layout_select]').val(), + fit: true, // whether to fit the viewport to the graph + padding: 25 // the padding on fit + }); + + }); + + $('#reset_graph').click(function() { + eles.restore() + $('#slide').val(0) + cy.layout({ name: $('select[name=layout_select]').val(), + fit: true, // whether to fit the viewport to the graph + padding: 25 // the padding on fit + }); + }); + + $('select[name=focus_select]').change(function() { + focus_trait = $(this).val() + + eles.restore() + cy.$('edge[source != "' + focus_trait + '"][target != "' + focus_trait + '"]').remove() + + cy.layout({ name: $('select[name=layout_select]').val(), + fit: true, // whether to fit the viewport to the graph + padding: 25 // the padding on fit + }); + }); + + $('select[name=layout_select]').change(function() { + layout_type = $(this).val() + console.log("LAYOUT:", layout_type) + cy.layout({ name: layout_type, + fit: true, // whether to fit the viewport to the graph + padding: 25 // the padding on fit + }); + }); + + $("a#image_link").click(function(e) { + var pngData = cy.png(); + + $(this).attr('href', pngData); + $(this).attr('download', 'network_graph.png'); + + console.log("TESTING:", image_link) + + }); + + +}; + + diff --git a/wqflask/wqflask/static/new/javascript/dataset_menu_structure.json b/wqflask/wqflask/static/new/javascript/dataset_menu_structure.json index d3db1853..861af3d6 100644 --- a/wqflask/wqflask/static/new/javascript/dataset_menu_structure.json +++ b/wqflask/wqflask/static/new/javascript/dataset_menu_structure.json @@ -117,14 +117,14 @@ "Barley1 Leaf MAS 5.0 SCRI (Dec06)" ], [ - "125", - "B30_K_1206_R", - "Barley1 Leaf gcRMA SCRI (Dec06)" - ], - [ "126", "B30_K_1206_Rn", "Barley1 Leaf gcRMAn SCRI (Dec06)" + ], + [ + "125", + "B30_K_1206_R", + "Barley1 Leaf gcRMA SCRI (Dec06)" ] ], "Phenotypes": [ @@ -1526,14 +1526,14 @@ "NCI Mammary LMT miRNA v2 (Apr09) RMA" ], [ - "36", - "MA_M_0704_M", - "NCI Mammary mRNA M430 (July04) MAS5" - ], - [ "37", "MA_M_0704_R", "NCI Mammary mRNA M430 (July04) RMA" + ], + [ + "36", + "MA_M_0704_M", + "NCI Mammary mRNA M430 (July04) MAS5" ] ] }, @@ -1591,14 +1591,14 @@ ], "Liver mRNA": [ [ - "38", - "LVF2_M_0704_M", - "(B6 x BTBR)F2-ob/ob Liver mRNA M430 (Jul04) MAS5" - ], - [ "39", "LVF2_M_0704_R", "(B6 x BTBR)F2-ob/ob Liver mRNA M430 (Jul04) RMA" + ], + [ + "38", + "LVF2_M_0704_M", + "(B6 x BTBR)F2-ob/ob Liver mRNA M430 (Jul04) MAS5" ] ], "Phenotypes": [ @@ -1616,23 +1616,11 @@ "B6D2Publish", "B6D2 Published Phenotypes" ] - ], - "Retina mRNA": [ - [ - "803", - "UTHSC_mm9_B6D2_Ret_0916", - "UTHSC B6D2 Retina Affy MoGene 1.0ST (Sep16) Gene Level RMA" - ] ] }, "B6D2F2": { "Brain mRNA": [ [ - "78", - "BRF2_M_0805_P", - "OHSU/VA B6D2F2 Brain mRNA M430 (Aug05) PDNN" - ], - [ "77", "BRF2_M_0805_R", "OHSU/VA B6D2F2 Brain mRNA M430 (Aug05) RMA" @@ -1643,19 +1631,24 @@ "OHSU/VA B6D2F2 Brain mRNA M430 (Aug05) MAS5" ], [ + "78", + "BRF2_M_0805_P", + "OHSU/VA B6D2F2 Brain mRNA M430 (Aug05) PDNN" + ], + [ "33", "BRF2_M_0304_P", "OHSU/VA B6D2F2 Brain mRNA M430A (Mar04) PDNN" ], [ - "31", - "BRF2_M_0304_M", - "OHSU/VA B6D2F2 Brain mRNA M430A (Mar04) MAS5" - ], - [ "32", "BRF2_M_0304_R", "OHSU/VA B6D2F2 Brain mRNA M430A (Mar04) RMA" + ], + [ + "31", + "BRF2_M_0304_M", + "OHSU/VA B6D2F2 Brain mRNA M430A (Mar04) MAS5" ] ], "Genotypes": [ @@ -1683,6 +1676,23 @@ ] }, "B6D2RI": { + "Hippocampus mRNA": [ + [ + "712", + "UTHSC_BXDAged_0615", + "UTHSC BXD Aged Hippocampus Affy Mouse Gene 1.0 ST (Jun15) RMA" + ], + [ + "805", + "UTHSC_BXDAgedEx_1116", + "UTHSC BXD Aged Hippocampus Affy Mouse Gene 1.0 ST (Jun15) Exon Level RMA" + ], + [ + "391", + "UTHSC_B6D2RI_H_0912", + "UTHSC B6D2RI Aged Hippocampus Affy Mouse Gene 1.0 ST (Sep12) RMA" + ] + ], "Phenotypes": [ [ "None", @@ -1717,11 +1727,6 @@ ], "Striatum mRNA": [ [ - "83", - "SA_M2_0905_M", - "OHSU/VA B6D2F2 Striatum M430v2 (Sep05) MAS5" - ], - [ "85", "SA_M2_0905_P", "OHSU/VA B6D2F2 Striatum M430v2 (Sep05) PDNN" @@ -1730,6 +1735,11 @@ "84", "SA_M2_0905_R", "OHSU/VA B6D2F2 Striatum M430v2 (Sep05) RMA" + ], + [ + "83", + "SA_M2_0905_M", + "OHSU/VA B6D2F2 Striatum M430v2 (Sep05) MAS5" ] ] }, @@ -2071,11 +2081,6 @@ "Eye M430v2 WT Gpnmb (Sep08) RMA" ], [ - "382", - "Eye_M2_0908_WTWT", - "Eye M430v2 WT WT (Sep08) RMA" - ], - [ "279", "Eye_M2_0908_R_WT", "Eye M430v2 WT Tyrp1 (Sep08) RMA" @@ -2086,6 +2091,11 @@ "Eye M430v2 Mutant Tyrp1 (Sep08) RMA" ], [ + "382", + "Eye_M2_0908_WTWT", + "Eye M430v2 WT WT (Sep08) RMA" + ], + [ "400", "DBA2J-ONH-1212", "Howell et al. 2011, DBA/2J Glaucoma Optic Nerve Head M430 2.0 (Dec12) RMA" @@ -2322,16 +2332,16 @@ ], "Kidney mRNA": [ [ - "240", - "MA_M2M_0706_R", - "Mouse kidney M430v2 Male (Aug06) RMA" - ], - [ "239", "MA_M2F_0706_R", "Mouse kidney M430v2 Female (Aug06) RMA" ], [ + "240", + "MA_M2M_0706_R", + "Mouse kidney M430v2 Male (Aug06) RMA" + ], + [ "118", "MA_M2_0806_R", "Mouse kidney M430v2 Sex Balanced (Aug06) RMA" @@ -2342,14 +2352,14 @@ "Mouse Kidney M430v2 Sex Balanced (Aug06) PDNN" ], [ - "115", - "MA_M2_0706_R", - "Mouse Kidney M430v2 (Jul06) RMA" - ], - [ "116", "MA_M2_0706_P", "Mouse Kidney M430v2 (Jul06) PDNN" + ], + [ + "115", + "MA_M2_0706_R", + "Mouse Kidney M430v2 (Jul06) RMA" ] ], "Liver Metabolome": [ @@ -2418,8 +2428,23 @@ ], "Liver mRNA": [ [ + "430", + "EPFLMouseLiverRMA0413", + "EPFL/LISP BXD CD+HFD Liver Affy Mouse Gene 1.0 ST (Apr13) RMA" + ], + [ + "431", + "EPFLMouseLiverHFDRMA0413", + "EPFL/LISP BXD HFD Liver Affy Mouse Gene 1.0 ST (Apr13) RMA" + ], + [ + "432", + "EPFLMouseLiverCDRMA0413", + "EPFL/LISP BXD CD Liver Affy Mouse Gene 1.0 ST (Apr13) RMA" + ], + [ "700", - "UT-VGX_HGL1014", + "UTHSC-VGX_MmBXDHepatocytesRMA1014", "UT-VGX Hepatocytes Affy Mouse Gene 1.0 ST Gene Level (Oct14) RMA" ], [ @@ -2441,21 +2466,6 @@ "702", "SUH_Liv_RMAEx_0611", "SUH BXD Liver CCl4-treated Affy Mouse Gene 1.0 ST Exon Level (Jun11) RMA" - ], - [ - "430", - "EPFLMouseLiverRMA0413", - "EPFL/LISP BXD CD+HFD Liver Affy Mouse Gene 1.0 ST (Apr13) RMA" - ], - [ - "431", - "EPFLMouseLiverHFDRMA0413", - "EPFL/LISP BXD HFD Liver Affy Mouse Gene 1.0 ST (Apr13) RMA" - ], - [ - "432", - "EPFLMouseLiverCDRMA0413", - "EPFL/LISP BXD CD Liver Affy Mouse Gene 1.0 ST (Apr13) RMA" ] ], "Lung mRNA": [ @@ -2479,21 +2489,6 @@ ], "Muscle mRNA": [ [ - "395", - "EPFLMouseMuscleRMA_Ex1112", - "EPFL/LISP BXD CD+HFD Muscle Affy Mouse Gene 1.0 ST (Nov12) RMA Exon Level" - ], - [ - "396", - "EPFLMouseMuscleHFDRMAEx1112", - "EPFL/LISP BXD HFD Muscle Affy Mouse Gene 1.0 ST (Nov12) RMA Exon Level" - ], - [ - "397", - "EPFLMouseMuscleCDRMAEx1112", - "EPFL/LISP BXD CD Muscle Affy Mouse Gene 1.0 ST (Nov12) RMA Exon Level" - ], - [ "378", "EPFLMouseMuscleRMA1211", "EPFL/LISP BXD CD+HFD Muscle Affy Mouse Gene 1.0 ST (Dec11) RMA" @@ -2507,20 +2502,35 @@ "379", "EPFLMouseMuscleCDRMA1211", "EPFL/LISP BXD CD Muscle Affy Mouse Gene 1.0 ST (Dec11) RMA" + ], + [ + "395", + "EPFLMouseMuscleRMA_Ex1112", + "EPFL/LISP BXD CD+HFD Muscle Affy Mouse Gene 1.0 ST (Nov12) RMA Exon Level" + ], + [ + "396", + "EPFLMouseMuscleHFDRMAEx1112", + "EPFL/LISP BXD HFD Muscle Affy Mouse Gene 1.0 ST (Nov12) RMA Exon Level" + ], + [ + "397", + "EPFLMouseMuscleCDRMAEx1112", + "EPFL/LISP BXD CD Muscle Affy Mouse Gene 1.0 ST (Nov12) RMA Exon Level" ] ], "Neocortex mRNA": [ [ - "374", - "DevNeocortex_ILM6.2P3RInv_1111", - "BIDMC/UTHSC Dev Neocortex P3 ILMv6.2 (Nov11) RankInv" - ], - [ "375", "DevNeocortex_ILM6.2P14RInv_1111", "BIDMC/UTHSC Dev Neocortex P14 ILMv6.2 (Nov11) RankInv" ], [ + "374", + "DevNeocortex_ILM6.2P3RInv_1111", + "BIDMC/UTHSC Dev Neocortex P3 ILMv6.2 (Nov11) RankInv" + ], + [ "284", "HQFNeoc_1210v2_RankInv", "HQF BXD Neocortex ILM6v1.1 (Dec10v2) RankInv" @@ -2751,11 +2761,6 @@ ], "Ventral Tegmental Area mRNA": [ [ - "228", - "VCUSal_0609_R", - "VCU BXD VTA Sal M430 2.0 (Jun09) RMA" - ], - [ "230", "VCUEtvsSal_0609_R", "VCU BXD VTA Et vs Sal M430 2.0 (Jun09) RMA" @@ -2764,6 +2769,20 @@ "229", "VCUEtOH_0609_R", "VCU BXD VTA EtOH M430 2.0 (Jun09) RMA" + ], + [ + "228", + "VCUSal_0609_R", + "VCU BXD VTA Sal M430 2.0 (Jun09) RMA" + ] + ] + }, + "BXD-Bone": { + "Phenotypes": [ + [ + "None", + "BXD-BonePublish", + "BXD-Bone Published Phenotypes" ] ] }, @@ -2830,6 +2849,51 @@ ] ] }, + "CFW": { + "Hippocampus mRNA": [ + [ + "811", + "UCSD_CFW_HIP_RNA-Seq_log2_0117", + "UCSD CFW Hippocampus (Jan17) RNA-Seq Log2 Z-score" + ], + [ + "808", + "UCSD_CFW_HIP_RNA-Seq_0117", + "UCSD CFW Hippocampus (Jan17) RNA-Seq" + ] + ], + "Phenotypes": [ + [ + "None", + "CFWPublish", + "CFW Published Phenotypes" + ] + ], + "Prefrontal Cortex mRNA": [ + [ + "813", + "UCSD_CFW_PFC_RNA-Seq_log2_0117", + "UCSD CFW Prefrontal Cortex (Jan17) RNA-Seq Log2 Z-score" + ], + [ + "810", + "UCSD_CFW_PFC_RNA-Seq_0117", + "UCSD CFW Prefrontal Cortex (Jan17) RNA-Seq" + ] + ], + "Striatum mRNA": [ + [ + "812", + "UCSD_CFW_STR_RNA-Seq_log2_0117", + "UCSD CFW Striatum (Jan17) RNA-Seq Log2 Z-score" + ], + [ + "809", + "UCSD_CFW_SPL_RNA-Seq_0117", + "UCSD CFW Striatum (Jan17) RNA-Seq" + ] + ] + }, "CIE-INIA": { "LCM Brain Regions mRNA": [ [ @@ -2959,14 +3023,14 @@ ], "Hippocampus mRNA": [ [ - "99", - "HC_M2CB_1205_P", - "Hippocampus Consortium M430v2 CXB (Dec05) PDNN" - ], - [ "100", "HC_M2CB_1205_R", "Hippocampus Consortium M430v2 CXB (Dec05) RMA" + ], + [ + "99", + "HC_M2CB_1205_P", + "Hippocampus Consortium M430v2 CXB (Dec05) PDNN" ] ], "Phenotypes": [ @@ -3033,16 +3097,6 @@ ], "Hippocampus mRNA": [ [ - "214", - "Illum_LXS_Hipp_NOE_1008", - "Hippocampus Illumina NOE (Oct08) RankInv beta" - ], - [ - "211", - "Illum_LXS_Hipp_RSS_1008", - "Hippocampus Illumina RSS (Oct08) RankInv beta" - ], - [ "213", "Illum_LXS_Hipp_NOS_1008", "Hippocampus Illumina NOS (Oct08) RankInv beta" @@ -3058,6 +3112,16 @@ "Hippocampus Illumina RSE (Oct08) RankInv beta" ], [ + "214", + "Illum_LXS_Hipp_NOE_1008", + "Hippocampus Illumina NOE (Oct08) RankInv beta" + ], + [ + "211", + "Illum_LXS_Hipp_RSS_1008", + "Hippocampus Illumina RSS (Oct08) RankInv beta" + ], + [ "143", "Illum_LXS_Hipp_loess0807", "Hippocampus Illumina (Aug07) LOESS" @@ -3148,14 +3212,14 @@ ], "Hippocampus mRNA": [ [ - "272", - "HC_M2_0606_MDP", - "Hippocampus Consortium M430v2 (Jun06) RMA MDP" - ], - [ "273", "UMUTAffyExon_0209_RMA_MDP", "UMUTAffy Hippocampus Exon (Feb09) RMA MDP" + ], + [ + "272", + "HC_M2_0606_MDP", + "Hippocampus Consortium M430v2 (Jun06) RMA MDP" ] ], "Liver mRNA": [ @@ -3227,6 +3291,17 @@ }, "Scripps-2013": {} }, + "poplar": { + "Poplar": { + "Phenotypes": [ + [ + "649", + "PoplarPublish", + "Poplar Published Phenotypes" + ] + ] + } + }, "rat": { "HSNIH-Palmer": { "Phenotypes": [ @@ -3524,6 +3599,10 @@ "BXD" ], [ + "BXD-Bone", + "BXD Bone" + ], + [ "BXH", "BXH" ], @@ -3532,6 +3611,10 @@ "Reduced Complexity Cross (B6JxB6N F2)" ], [ + "CFW", + "CFW Outbred GWAS" + ], + [ "CIE-INIA", "Chronic Intermittent Ethanol" ], @@ -3580,6 +3663,12 @@ "SOTNOT-OHSU" ] ], + "poplar": [ + [ + "Poplar", + "Poplar" + ] + ], "rat": [ [ "HSNIH-Palmer", @@ -3618,15 +3707,15 @@ "species": [ [ "human", - "Human" + "Human (hg19)" ], [ "mouse", - "Mouse" + "Mouse (mm10)" ], [ "rat", - "Rat" + "Rat (rn3)" ], [ "drosophila", @@ -3641,6 +3730,10 @@ "Barley" ], [ + "poplar", + "Poplar" + ], + [ "soybean", "Soybean" ], @@ -4387,10 +4480,6 @@ [ "Phenotypes", "Phenotypes" - ], - [ - "Retina mRNA", - "Retina mRNA" ] ], "B6D2F2": [ @@ -4417,6 +4506,10 @@ [ "Phenotypes", "Phenotypes" + ], + [ + "Hippocampus mRNA", + "Hippocampus mRNA" ] ], "BDF2-1999": [ @@ -4621,6 +4714,12 @@ "Ventral Tegmental Area mRNA" ] ], + "BXD-Bone": [ + [ + "Phenotypes", + "Phenotypes" + ] + ], "BXH": [ [ "Phenotypes", @@ -4653,6 +4752,24 @@ "Genotypes" ] ], + "CFW": [ + [ + "Phenotypes", + "Phenotypes" + ], + [ + "Hippocampus mRNA", + "Hippocampus mRNA" + ], + [ + "Prefrontal Cortex mRNA", + "Prefrontal Cortex mRNA" + ], + [ + "Striatum mRNA", + "Striatum mRNA" + ] + ], "CIE-INIA": [ [ "Phenotypes", @@ -4813,6 +4930,14 @@ ], "Scripps-2013": [] }, + "poplar": { + "Poplar": [ + [ + "Phenotypes", + "Phenotypes" + ] + ] + }, "rat": { "HSNIH-Palmer": [ [ diff --git a/wqflask/wqflask/static/new/javascript/dataset_select_menu.js b/wqflask/wqflask/static/new/javascript/dataset_select_menu.js index 43b0960c..9ad38102 100644 --- a/wqflask/wqflask/static/new/javascript/dataset_select_menu.js +++ b/wqflask/wqflask/static/new/javascript/dataset_select_menu.js @@ -1,10 +1,10 @@ $(function() { - var gndata; // loaded once for all to use - process_json = function(data) { - populate_species(); - return apply_default(); - }; - $.getJSON(gn_server_url+"/int/menu/main.json", + var gndata; // loaded once for all to use + process_json = function(data) { + populate_species(); + return apply_default(); + }; + $.getJSON(gn_server_url+"int/menu/main.json", function(data) { gndata = data; console.log("***** GOT DATA from GN_SERVER ****"); diff --git a/wqflask/wqflask/static/new/javascript/dataset_select_menu_orig.js b/wqflask/wqflask/static/new/javascript/dataset_select_menu_orig.js index 1fe4cf75..fd96eb78 100644 --- a/wqflask/wqflask/static/new/javascript/dataset_select_menu_orig.js +++ b/wqflask/wqflask/static/new/javascript/dataset_select_menu_orig.js @@ -4,7 +4,9 @@ $(function() { process_json = function(data) { window.jdata = data; populate_species(); - return apply_default(); + if ($('#type').length > 0) { //This is to determine if it's the index page or the submit_trait page (which only has species and group selection and no make default option) + return apply_default(); + } }; $.ajax('/static/new/javascript/dataset_menu_structure.json', { dataType: 'json', @@ -23,7 +25,9 @@ $(function() { species = $('#species').val(); group_list = this.jdata.groups[species]; redo_dropdown($('#group'), group_list); - return populate_type(); + if ($('#type').length > 0) { //This is to determine if it's the index page or the submit_trait page (which only has species and group selection and no make default option) + return populate_type(); + } }; window.populate_group = populate_group; populate_type = function() { @@ -70,7 +74,12 @@ $(function() { })(this)); $('#group').change((function(_this) { return function() { - return populate_type(); + if ($('#type').length > 0) { //This is to determine if it's the index page or the submit_trait page (which only has species and group selection and no make default option) + return populate_type(); + } + else { + return false + } }; })(this)); $('#type').change((function(_this) { diff --git a/wqflask/wqflask/static/new/javascript/draw_probability_plot.js b/wqflask/wqflask/static/new/javascript/draw_probability_plot.js index 1eeb6e73..e5787564 100644 --- a/wqflask/wqflask/static/new/javascript/draw_probability_plot.js +++ b/wqflask/wqflask/static/new/javascript/draw_probability_plot.js @@ -45,8 +45,7 @@ chart = nv.models.scatterChart().width(w).height(h).showLegend(true).color(d3.scale.category10().range()); chart.pointRange([50, 50]); chart.legend.updateState(false); - chart.xAxis.axisLabel("Theoretical quantiles").tickFormat(d3.format('.02f')); - //chart.yAxis.axisLabel("Sample quantiles").tickFormat(d3.format('.02f')); + chart.xAxis.axisLabel("Expected Z score").tickFormat(d3.format('.02f')); chart.tooltipContent(function(obj) { return '<b style="font-size: 20px">' + obj.point.name + '</b>'; }); @@ -79,7 +78,7 @@ } return results; })(); - chart.yAxis.axisLabel("Sample quantiles").tickFormat(d3.format('.0'+max_decimals.toString()+'f')); + chart.yAxis.axisLabel("Trait value").tickFormat(d3.format('.0'+max_decimals.toString()+'f')); sw_result = ShapiroWilkW(sorted_values); W = sw_result.w.toFixed(3); pvalue = sw_result.p.toFixed(3); @@ -115,7 +114,12 @@ data = [make_data('samples_primary'), make_data('samples_other')]; console.log("THE DATA IS:", data); d3.select("#prob_plot_container svg").datum(data).call(chart); - $("#prob_plot_title").html("<h3>Normal probability plot</h3>" + test_str); + if (js_data.trait_symbol != null) { + $("#prob_plot_title").html("<h3>" + js_data.trait_symbol + ": " + js_data.trait_id + "</h3>"); + } else { + $("#prob_plot_title").html("<h3>" + js_data.trait_id + "</h3>"); + } + $("#shapiro_wilk_text").html(test_str) $("#prob_plot_container .nv-legendWrap").toggle(sample_group === "samples_all"); return chart; }; diff --git a/wqflask/wqflask/static/new/javascript/get_traits_from_collection.js b/wqflask/wqflask/static/new/javascript/get_traits_from_collection.js index a73eafe4..bcd83889 100644 --- a/wqflask/wqflask/static/new/javascript/get_traits_from_collection.js +++ b/wqflask/wqflask/static/new/javascript/get_traits_from_collection.js @@ -226,10 +226,8 @@ back_to_collections = function() { return $('#collections_holder').colorbox.resize(); }; -$(function() { - console.log("inside get_traits_from_collection"); - $(document).on("click", ".collection_line", collection_click); - $(document).on("click", "#submit", submit_click); - $(document).on("click", ".trait", trait_click); - return $(document).on("click", "#back_to_collections", back_to_collections); -}); +console.log("inside get_traits_from_collection"); +$(".collection_line").on("click", collection_click); +$("#submit").on("click", submit_click); +$(".trait").on("click", trait_click); +$("#back_to_collections").on("click", back_to_collections);
\ No newline at end of file diff --git a/wqflask/wqflask/static/new/javascript/histogram.js b/wqflask/wqflask/static/new/javascript/histogram.js index d26d0c03..f71080e8 100644 --- a/wqflask/wqflask/static/new/javascript/histogram.js +++ b/wqflask/wqflask/static/new/javascript/histogram.js @@ -103,7 +103,6 @@ Histogram.prototype.add_bars = function() { var bar, rect_width; - console.log("bar_width:", this.x_scale(this.histogram_data[0].dx)); bar = this.svg.selectAll(".bar").data(this.histogram_data).enter().append("g").attr("class", "bar").attr("transform", (function(_this) { return function(d) { return "translate(" + _this.x_scale(d.x) + "," + _this.y_scale(d.y) + ")"; diff --git a/wqflask/wqflask/static/new/javascript/loadings_plot.js b/wqflask/wqflask/static/new/javascript/loadings_plot.js new file mode 100644 index 00000000..c44288c0 --- /dev/null +++ b/wqflask/wqflask/static/new/javascript/loadings_plot.js @@ -0,0 +1,109 @@ +var margin = {top: 20, right: 70, bottom: 60, left: 60} + , width = 960 - margin.left - margin.right + , height = 500 - margin.top - margin.bottom; + +var x = d3.scale.linear() + .domain([d3.min(loadings, function(d) { return d[0]; }) + 0.1*d3.min(loadings, function(d) { return d[0]; }), d3.max(loadings, function(d) { return d[0]; })]) + .range([ 0, width ]); + +var y = d3.scale.linear() + .domain([d3.min(loadings, function(d) { return d[1]; }) + 0.1*d3.min(loadings, function(d) { return d[1]; }), d3.max(loadings, function(d) { return d[1]; })]) + .range([ height, 0 ]); + +var chart = d3.select('#loadings_plot') + .append('svg:svg') + .attr('width', width + margin.right + margin.left) + .attr('height', height + margin.top + margin.bottom) + .attr('class', 'chart') + +var main = chart.append('g') + .attr('transform', 'translate(' + margin.left + ',' + margin.top + ')') + .attr('width', width) + .attr('height', height) + .attr('class', 'main') + +// draw the x axis +var xAxis = d3.svg.axis() + .scale(x) + .orient('bottom'); + +main.append('g') + .attr('transform', 'translate(0,' + height + ')') + .attr('class', 'x axis') + .call(xAxis); + +chart.append("text") + .attr("class", "x label") + .attr("text-anchor", "end") + .attr("x", 550) + .attr("y", 480) + .style("font-size", 14) + .style("fill", "blue") + .text("Factor (1)"); + +chart.append("text") + .attr("class", "y label") + .attr("text-anchor", "end") + .attr("x", -200) + .attr("y", 5) + .attr("dy", ".75em") + .attr("transform", "rotate(-90)") + .style("font-size", 14) + .style("fill", "blue") + .text("Factor (2)"); + +// draw the y axis +var yAxis = d3.svg.axis() + .scale(y) + .orient('left'); + +main.append('g') + .attr('transform', 'translate(0,0)') + .attr('class', 'y axis') + .call(yAxis); + +chart.select('.x.axis') + .selectAll("text") + .style("font-size","14px"); + +chart.select('.y.axis') + .selectAll("text") + .style("font-size","14px"); + +var g = main.append("svg:g"); + +g.selectAll("scatter-dots") + .data(loadings) + .enter().append("svg:circle") + .attr("cx", function (d,i) { return x(d[0]); } ) + .attr("cy", function (d) { return y(d[1]); } ) + .attr("r", 4) + .style("fill", "blue"); + +traits_and_loadings = [] +for (i = 0; i < js_data.traits.length; i++) { + this_trait_loadings = [] + this_trait_loadings[0] = js_data.traits[i] + this_trait_loadings[1] = [loadings[i][0], loadings[i][1]] + traits_and_loadings[i] = this_trait_loadings +} + +g.selectAll("scatter-dots") + .data(traits_and_loadings) + .enter().append("text") + .attr("x", function(d, i) { return x(d[1][0]); }) + .attr("y", function(d) { return y(d[1][1]); }) + .text(function(d) { return d[0]; }) + .style("font-size", 12) + .style("fill", "blue"); + +g.selectAll("scatter-lines") + .data(loadings) + .enter().append("svg:line") + .attr("x1", x(0)) + .attr("y1", y(0)) + .attr("x2", function (d,i) {return x(d[0]); } ) + .attr("y2", function (d) { return y(d[1]); } ) + .attr("stroke-width", 1) + .attr("stroke", "red"); +
\ No newline at end of file diff --git a/wqflask/wqflask/static/new/javascript/lod_chart.coffee b/wqflask/wqflask/static/new/javascript/lod_chart.coffee index 55ffdce0..a65df84f 100644 --- a/wqflask/wqflask/static/new/javascript/lod_chart.coffee +++ b/wqflask/wqflask/static/new/javascript/lod_chart.coffee @@ -123,6 +123,8 @@ lodchart = () -> .on("click", (d) -> console.log("d is:", d) redraw_plot(d) + BD.putData({chr: d[0], length: d[1]}); + BD.showButton() ) # x-axis labels diff --git a/wqflask/wqflask/static/new/javascript/lod_chart.js b/wqflask/wqflask/static/new/javascript/lod_chart.js index 014bf59b..f1df6bd8 100644 --- a/wqflask/wqflask/static/new/javascript/lod_chart.js +++ b/wqflask/wqflask/static/new/javascript/lod_chart.js @@ -1,8 +1,8 @@ -// Generated by CoffeeScript 1.9.2 +// Generated by CoffeeScript 1.10.0 var lodchart; lodchart = function() { - var additive, additive_ylab, additive_ylim, additive_yscale, additive_yticks, additivelinecolor, axispos, chart, chrGap, chrSelect, darkrect, height, lightrect, linewidth, lodcurve, lodlinecolor, lodvarname, manhattanPlot, mappingScale, margin, markerSelect, nyticks, pad4heatmap, pointcolor, pointsAtMarkers, pointsize, pointstroke, rotate_ylab, significantcolor, suggestivecolor, title, titlepos, width, xlab, xscale, ylab, ylim, yscale, yticks; + var additive, additive_ylab, additive_ylim, additive_yscale, additive_yticks, additivelinecolor, axispos, chart, chrGap, chrSelect, darkrect, height, lightrect, linewidth, lodcurve, lodlinecolor, lodvarname, manhattanPlot, margin, markerSelect, nyticks, pad4heatmap, pointcolor, pointsAtMarkers, pointsize, pointstroke, rotate_ylab, significantcolor, suggestivecolor, title, titlepos, width, xlab, xscale, ylab, ylim, yscale, yticks; width = 800; height = 500; margin = { @@ -20,6 +20,7 @@ lodchart = function() { }; titlepos = 20; manhattanPlot = false; + additive = false; ylim = null; additive_ylim = null; nyticks = 5; @@ -29,8 +30,7 @@ lodchart = function() { darkrect = "#F1F1F9"; lightrect = "#FBFBFF"; lodlinecolor = "darkslateblue"; - additivelinecolor_plus = "red"; - additivelinecolor_negative = "green"; + additivelinecolor = "red"; linewidth = 2; suggestivecolor = "gainsboro"; significantcolor = "#EBC7C7"; @@ -70,15 +70,14 @@ lodchart = function() { return results; })(); ylim = ylim != null ? ylim : [0, d3.max(data[lodvarname])]; - - if ('additive' in data) { + if (additive) { data['additive'] = (function() { var j, len, ref, results; ref = data['additive']; results = []; for (j = 0, len = ref.length; j < len; j++) { x = ref[j]; - results.push(x); + results.push(Math.abs(x)); } return results; })(); @@ -92,12 +91,12 @@ lodchart = function() { g.append("rect").attr("x", margin.left).attr("y", margin.top).attr("height", height).attr("width", width).attr("fill", darkrect).attr("stroke", "none"); yscale.domain(ylim).range([height + margin.top, margin.top + margin.inner]); yticks = yticks != null ? yticks : yscale.ticks(nyticks); - if ('additive' in data) { + if (additive) { additive_yscale.domain(additive_ylim).range([height + margin.top, margin.top + margin.inner + height / 2]); additive_yticks = additive_yticks != null ? additive_yticks : additive_yscale.ticks(nyticks); } reorgLodData(data, lodvarname); - data = chrscales(data, width, chrGap, margin.left, pad4heatmap, mappingScale); + data = chrscales(data, width, chrGap, margin.left, pad4heatmap); xscale = data.xscale; chrSelect = g.append("g").attr("class", "chrRect").selectAll("empty").data(data.chrnames).enter().append("rect").attr("id", function(d) { return "chrrect" + d[0]; @@ -118,7 +117,12 @@ lodchart = function() { return lightrect; }).attr("stroke", "none").on("click", function(d) { console.log("d is:", d); - return redraw_plot(d); + redraw_plot(d); + BD.putData({ + chr: d[0], + length: d[1] + }); + return BD.showButton(); }); xaxis = g.append("g").attr("class", "x axis"); xaxis.selectAll("empty").data(data.chrnames).enter().append("text").text(function(d) { @@ -133,7 +137,7 @@ lodchart = function() { var chr_plot; $('#topchart').remove(); $('#chart_container').append('<div class="qtlcharts" id="topchart"></div>'); - return chr_plot = new Chr_Lod_Chart(600, 1200, chr_ob, manhattanPlot, mappingScale); + return chr_plot = new Chr_Lod_Chart(600, 1200, chr_ob, manhattanPlot); }; rotate_ylab = rotate_ylab != null ? rotate_ylab : ylab.length > 1; yaxis = g.append("g").attr("class", "y axis"); @@ -148,7 +152,7 @@ lodchart = function() { return formatAxis(yticks)(d); }); yaxis.append("text").attr("class", "title").attr("y", margin.top + height / 2).attr("x", margin.left - axispos.ytitle).text(ylab).attr("transform", rotate_ylab ? "rotate(270," + (margin.left - axispos.ytitle) + "," + (margin.top + height / 2) + ")" : "").attr("text-anchor", "middle").attr("fill", "slateblue"); - if ('additive' in data) { + if (additive) { rotate_additive_ylab = rotate_additive_ylab != null ? rotate_additive_ylab : additive_ylab.length > 1; additive_yaxis = g.append("g").attr("class", "y axis"); additive_yaxis.selectAll("empty").data(additive_yticks).enter().append("line").attr("y1", function(d) { @@ -187,19 +191,13 @@ lodchart = function() { return yscale(data.lodByChr[chr][i][lodcolumn]); }); }; - if ('additive' in data) { + if (additive) { additivecurve = function(chr, lodcolumn) { - if (data.additiveByChr[chr][0] < 0) { - pos_neg = "negative" - } - else { - pos_neg = "positive" - } - return [pos_neg, d3.svg.line().x(function(d) { + return d3.svg.line().x(function(d) { return xscale[chr](d); }).y(function(d, i) { - return additive_yscale(Math.abs(data.additiveByChr[chr][i])); - })]; + return additive_yscale(data.additiveByChr[chr][i][lodcolumn]); + }); }; } curves = g.append("g").attr("id", "curves"); @@ -210,17 +208,12 @@ lodchart = function() { curves.append("path").datum(data.posByChr[chr[0]]).attr("d", lodcurve(chr[0], lodvarnum)).attr("stroke", lodlinecolor).attr("fill", "none").attr("stroke-width", linewidth).style("pointer-events", "none"); } } - if ('additive' in data) { + if (additive) { ref1 = data.chrnames; for (k = 0, len1 = ref1.length; k < len1; k++) { chr = ref1[k]; if (chr.indexOf(data['chr'])) { - if (additivecurve(chr[0], lodvarnum)[0] == "negative") { - curves.append("path").datum(data.posByChr[chr[0]]).attr("d", additivecurve(chr[0], lodvarnum)[1]).attr("stroke", additivelinecolor_negative).attr("fill", "none").attr("stroke-width", 1).style("pointer-events", "none"); - } - else { - curves.append("path").datum(data.posByChr[chr[0]]).attr("d", additivecurve(chr[0], lodvarnum)[1]).attr("stroke", additivelinecolor_plus).attr("fill", "none").attr("stroke-width", 1).style("pointer-events", "none"); - } + curves.append("path").datum(data.posByChr[chr[0]]).attr("d", additivecurve(chr[0], lodvarnum)).attr("stroke", additivelinecolor).attr("fill", "none").attr("stroke-width", 1).style("pointer-events", "none"); } } } @@ -305,13 +298,6 @@ lodchart = function() { manhattanPlot = value; return chart; }; - chart.mappingScale = function(value) { - if (!arguments.length) { - return mappingScale; - } - mappingScale = value; - return chart; - }; chart.ylim = function(value) { if (!arguments.length) { return ylim; @@ -449,6 +435,9 @@ lodchart = function() { chart.yscale = function() { return yscale; }; + chart.additive = function() { + return additive; + }; chart.additive_yscale = function() { return additive_yscale; }; @@ -470,4 +459,4 @@ lodchart = function() { return chrSelect; }; return chart; -};
\ No newline at end of file +}; diff --git a/wqflask/wqflask/static/new/javascript/search_results.js b/wqflask/wqflask/static/new/javascript/search_results.js index 746564fd..40fdff70 100644 --- a/wqflask/wqflask/static/new/javascript/search_results.js +++ b/wqflask/wqflask/static/new/javascript/search_results.js @@ -73,7 +73,6 @@ $(function() { }); $('.trait_checkbox:checkbox').change(function() { - console.log("CHANGED") change_buttons() if ($(this).is(":checked")) { @@ -108,7 +107,6 @@ $(function() { var button, buttons, item, num_checked, text, _i, _j, _k, _l, _len, _len2, _len3, _len4, _results, _results2; buttons = ["#add", "#remove"]; num_checked = $('.trait_checkbox:checked').length; - console.log("num_checked is:", num_checked); if (num_checked === 0) { for (_i = 0, _len = buttons.length; _i < _len; _i++) { button = buttons[_i]; @@ -155,10 +153,61 @@ $(function() { }); } }; + + export_traits = function() { + trait_data = get_traits_from_table("trait_table") + }; + + get_traits_from_table = function(table_name) { + trait_table = $('#'+table_name); + table_dict = {}; + + headers = []; + trait_table.find('th').each(function () { + if ($(this).data('export')){ + headers.push($(this).data('export')) + } + }); + table_dict['headers'] = headers; + + rows = []; + trait_table.find('tbody tr').each(function (i, tr) { + if (trait_table.find('input[name="searchResult"]:checked').length > 0) { + if ($(this).find('input[name="searchResult"]').is(':checked')){ + this_row = []; + $(tr).find('td').each(function(j, td){ + if ($(td).data('export')){ + this_row.push($(td).data('export')); + } + }); + rows.push(this_row); + } + } + else { + this_row = []; + $(tr).find('td').each(function(j, td){ + if ($(td).data('export')){ + this_row.push($(td).data('export')); + } + }); + rows.push(this_row); + } + }); + table_dict['rows'] = rows; + console.log("TABLEDICT:", table_dict); + + json_table_dict = JSON.stringify(table_dict); + $('input[name=export_data]').val(json_table_dict); + + $('#export_form').attr('action', '/export_traits_csv'); + $('#export_form').submit(); + }; + $("#select_all").click(select_all); $("#deselect_all").click(deselect_all); $("#invert").click(invert); $("#add").click(add); $("#remove").click(remove); + $("#export_traits").click(export_traits); $('.trait_checkbox, .btn').click(change_buttons); });
\ No newline at end of file diff --git a/wqflask/wqflask/static/new/javascript/show_trait.js b/wqflask/wqflask/static/new/javascript/show_trait.js index 19955b07..8223a38c 100644 --- a/wqflask/wqflask/static/new/javascript/show_trait.js +++ b/wqflask/wqflask/static/new/javascript/show_trait.js @@ -18,19 +18,19 @@ }, { vn: "mean", pretty: "Mean", - digits: 2 + digits: 3 }, { vn: "median", pretty: "Median", - digits: 2 + digits: 3 }, { vn: "std_error", pretty: "Standard Error (SE)", - digits: 2 + digits: 3 }, { vn: "std_dev", pretty: "Standard Deviation (SD)", - digits: 2 + digits: 3 }, { vn: "min", pretty: "Minimum", @@ -42,16 +42,16 @@ }, { vn: "range", pretty: "Range (log2)", - digits: 2 + digits: 3 }, { vn: "range_fold", pretty: "Range (fold)", - digits: 2 + digits: 3 }, { vn: "interquartile", pretty: "Interquartile Range", url: "http://www.genenetwork.org/glossary.html#Interquartile", - digits: 2 + digits: 3 } ]; @@ -179,8 +179,13 @@ if (!__hasProp.call(_ref, key)) continue; value = _ref[key]; the_id = process_id("column", key); - header += "<th id=\"" + the_id + "\" style=\"padding-left: 5px;\">" + value + "</th>"; + if (Object.keys(_ref).length > 1) { + header += "<th id=\"" + the_id + "\" style=\"padding-left: 5px;\">" + value + "</th>"; + } else { + header += "<th id=\"" + the_id + "\" style=\"padding-left: 5px;\">Value</th>"; + } } + header += "</thead>"; the_rows = "<tbody>"; for (_i = 0, _len = Stat_Table_Rows.length; _i < _len; _i++) { diff --git a/wqflask/wqflask/static/new/javascript/show_trait_mapping_tools.js b/wqflask/wqflask/static/new/javascript/show_trait_mapping_tools.js index a02fdb32..03602d07 100644 --- a/wqflask/wqflask/static/new/javascript/show_trait_mapping_tools.js +++ b/wqflask/wqflask/static/new/javascript/show_trait_mapping_tools.js @@ -166,8 +166,9 @@ return function() { var form_data, url; //$("#progress_bar_container").modal(); - url = "/marker_regression"; + url = "/loading"; $('input[name=method]').val("pylmm"); + $('input[name=genofile]').val($('#genofile_pylmm').val()); $('input[name=num_perm]').val($('input[name=num_perm_pylmm]').val()); $('input[name=manhattan_plot]').val($('input[name=manhattan_plot_pylmm]:checked').val()); form_data = $('#trait_data_form').serialize(); @@ -181,8 +182,9 @@ return function() { var form_data, url; //$("#progress_bar_container").modal(); - url = "/marker_regression"; + url = "/loading"; $('input[name=method]').val("rqtl_geno"); + $('input[name=genofile]').val($('#genofile_rqtl_geno').val()); $('input[name=num_perm]').val($('input[name=num_perm_rqtl_geno]').val()); $('input[name=manhattan_plot]').val($('input[name=manhattan_plot_rqtl]:checked').val()); $('input[name=control_marker]').val($('input[name=control_rqtl_geno]').val()); @@ -210,7 +212,7 @@ return function() { var form_data, url; //$("#static_progress_bar_container").modal(); - url = "/marker_regression"; + url = "/loading"; $('input[name=method]').val("plink"); $('input[name=maf]').val($('input[name=maf_plink]').val()); form_data = $('#trait_data_form').serialize(); @@ -244,7 +246,7 @@ var form_data, url; console.log("RUNNING GEMMA"); //$("#static_progress_bar_container").modal(); - url = "/marker_regression"; + url = "/loading"; $('input[name=method]').val("gemma"); $('input[name=maf]').val($('input[name=maf_gemma]').val()); form_data = $('#trait_data_form').serialize(); @@ -259,8 +261,9 @@ var form_data, url; console.log("In interval mapping"); //$("#progress_bar_container").modal(); - url = "/marker_regression"; + url = "/loading"; $('input[name=method]').val("reaper"); + $('input[name=genofile]').val($('#genofile_reaper').val()); $('input[name=num_perm]').val($('input[name=num_perm_reaper]').val()); $('input[name=control_marker]').val($('input[name=control_reaper]').val()); $('input[name=do_control]').val($('input[name=do_control_reaper]:checked').val()); diff --git a/wqflask/wqflask/static/new/packages/DataTables/css/jquery.dataTables.css b/wqflask/wqflask/static/new/packages/DataTables/css/jquery.dataTables.css index 6540d01f..40e58ac8 100644 --- a/wqflask/wqflask/static/new/packages/DataTables/css/jquery.dataTables.css +++ b/wqflask/wqflask/static/new/packages/DataTables/css/jquery.dataTables.css @@ -20,8 +20,14 @@ table.dataTable tfoot th { } table.dataTable thead th, table.dataTable thead td { - padding: 10px 18px 10px 0px; - border-bottom: 1px solid #111; + font: bold 12px/20px Arial, Sans-serif; + color: #000000; + background-color: #ffffff; + border-collapse: collapse; + border-bottom: #cccccc 2px solid; + padding: 0; + //padding: 10px 18px 10px 0px; + //border-bottom: 1px solid #111; } table.dataTable thead th:active, table.dataTable thead td:active { @@ -29,8 +35,13 @@ table.dataTable thead td:active { } table.dataTable tfoot th, table.dataTable tfoot td { - padding: 10px 18px 6px 18px; - border-top: 1px solid #111; + font: bold 12px/20px Arial, Sans-serif; + color: #000000; + background-color: #ffffff; + border-collapse: collapse; + padding: 0; + //padding: 10px 18px 6px 18px; + //border-top: 1px solid #111; } table.dataTable thead .sorting, table.dataTable thead .sorting_asc, @@ -69,7 +80,8 @@ table.dataTable tbody tr.selected { } table.dataTable tbody th, table.dataTable tbody td { - padding: 4px 5px; + font: 12px Arial, Sans-serif; + padding: 4px 16px 4px 0px; } table.dataTable.row-border tbody th, table.dataTable.row-border tbody td, table.dataTable.display tbody th, table.dataTable.display tbody td { border-top: 1px solid #ddd; diff --git a/wqflask/wqflask/static/new/packages/DataTables/extensions/buttons.colVis.min.js b/wqflask/wqflask/static/new/packages/DataTables/extensions/buttons.colVis.min.js new file mode 100644 index 00000000..072d6c9a --- /dev/null +++ b/wqflask/wqflask/static/new/packages/DataTables/extensions/buttons.colVis.min.js @@ -0,0 +1,5 @@ +(function(g){"function"===typeof define&&define.amd?define(["jquery","datatables.net","datatables.net-buttons"],function(d){return g(d,window,document)}):"object"===typeof exports?module.exports=function(d,e){d||(d=window);if(!e||!e.fn.dataTable)e=require("datatables.net")(d,e).$;e.fn.dataTable.Buttons||require("datatables.net-buttons")(d,e);return g(e,d,d.document)}:g(jQuery,window,document)})(function(g,d,e,h){d=g.fn.dataTable;g.extend(d.ext.buttons,{colvis:function(a,b){return{extend:"collection", +text:function(a){return a.i18n("buttons.colvis","Column visibility")},className:"buttons-colvis",buttons:[{extend:"columnsToggle",columns:b.columns}]}},columnsToggle:function(a,b){return a.columns(b.columns).indexes().map(function(a){return{extend:"columnToggle",columns:a}}).toArray()},columnToggle:function(a,b){return{extend:"columnVisibility",columns:b.columns}},columnsVisibility:function(a,b){return a.columns(b.columns).indexes().map(function(a){return{extend:"columnVisibility",columns:a,visibility:b.visibility}}).toArray()}, +columnVisibility:{columns:h,text:function(a,b,c){return c._columnText(a,c.columns)},className:"buttons-columnVisibility",action:function(a,b,c,f){a=b.columns(f.columns);b=a.visible();a.visible(f.visibility!==h?f.visibility:!(b.length&&b[0]))},init:function(a,b,c){var f=this;a.on("column-visibility.dt"+c.namespace,function(b,d){d.bDestroying||f.active(a.column(c.columns).visible())}).on("column-reorder.dt"+c.namespace,function(b,d,e){1===a.columns(c.columns).count()&&("number"===typeof c.columns&& +(c.columns=e.mapping[c.columns]),b=a.column(c.columns),f.text(c._columnText(a,c.columns)),f.active(b.visible()))});this.active(a.column(c.columns).visible())},destroy:function(a,b,c){a.off("column-visibility.dt"+c.namespace).off("column-reorder.dt"+c.namespace)},_columnText:function(a,b){var c=a.column(b).index();return a.settings()[0].aoColumns[c].sTitle.replace(/\n/g," ").replace(/<.*?>/g,"").replace(/^\s+|\s+$/g,"")}},colvisRestore:{className:"buttons-colvisRestore",text:function(a){return a.i18n("buttons.colvisRestore", +"Restore visibility")},init:function(a,b,c){c._visOriginal=a.columns().indexes().map(function(b){return a.column(b).visible()}).toArray()},action:function(a,b,c,d){b.columns().every(function(a){a=b.colReorder&&b.colReorder.transpose?b.colReorder.transpose(a,"toOriginal"):a;this.visible(d._visOriginal[a])})}},colvisGroup:{className:"buttons-colvisGroup",action:function(a,b,c,d){b.columns(d.show).visible(!0,!1);b.columns(d.hide).visible(!1,!1);b.columns.adjust()},show:[],hide:[]}});return d.Buttons});
\ No newline at end of file diff --git a/wqflask/wqflask/static/new/packages/DataTables/extensions/dataTables.buttons.min.js b/wqflask/wqflask/static/new/packages/DataTables/extensions/dataTables.buttons.min.js new file mode 100644 index 00000000..ae3fb9c8 --- /dev/null +++ b/wqflask/wqflask/static/new/packages/DataTables/extensions/dataTables.buttons.min.js @@ -0,0 +1,35 @@ +/*! + Buttons for DataTables 1.2.4 + Š2016 SpryMedia Ltd - datatables.net/license +*/ +(function(d){"function"===typeof define&&define.amd?define(["jquery","datatables.net"],function(n){return d(n,window,document)}):"object"===typeof exports?module.exports=function(n,o){n||(n=window);if(!o||!o.fn.dataTable)o=require("datatables.net")(n,o).$;return d(o,n,n.document)}:d(jQuery,window,document)})(function(d,n,o,m){var i=d.fn.dataTable,u=0,v=0,j=i.ext.buttons,l=function(a,b){!0===b&&(b={});d.isArray(b)&&(b={buttons:b});this.c=d.extend(!0,{},l.defaults,b);b.buttons&&(this.c.buttons=b.buttons); +this.s={dt:new i.Api(a),buttons:[],listenKeys:"",namespace:"dtb"+u++};this.dom={container:d("<"+this.c.dom.container.tag+"/>").addClass(this.c.dom.container.className)};this._constructor()};d.extend(l.prototype,{action:function(a,b){var c=this._nodeToButton(a);if(b===m)return c.conf.action;c.conf.action=b;return this},active:function(a,b){var c=this._nodeToButton(a),e=this.c.dom.button.active,c=d(c.node);if(b===m)return c.hasClass(e);c.toggleClass(e,b===m?!0:b);return this},add:function(a,b){var c= +this.s.buttons;if("string"===typeof b){for(var e=b.split("-"),c=this.s,d=0,h=e.length-1;d<h;d++)c=c.buttons[1*e[d]];c=c.buttons;b=1*e[e.length-1]}this._expandButton(c,a,!1,b);this._draw();return this},container:function(){return this.dom.container},disable:function(a){a=this._nodeToButton(a);d(a.node).addClass(this.c.dom.button.disabled);return this},destroy:function(){d("body").off("keyup."+this.s.namespace);var a=this.s.buttons.slice(),b,c;b=0;for(c=a.length;b<c;b++)this.remove(a[b].node);this.dom.container.remove(); +a=this.s.dt.settings()[0];b=0;for(c=a.length;b<c;b++)if(a.inst===this){a.splice(b,1);break}return this},enable:function(a,b){if(!1===b)return this.disable(a);var c=this._nodeToButton(a);d(c.node).removeClass(this.c.dom.button.disabled);return this},name:function(){return this.c.name},node:function(a){a=this._nodeToButton(a);return d(a.node)},remove:function(a){var b=this._nodeToButton(a),c=this._nodeToHost(a),e=this.s.dt;if(b.buttons.length)for(var g=b.buttons.length-1;0<=g;g--)this.remove(b.buttons[g].node); +b.conf.destroy&&b.conf.destroy.call(e.button(a),e,d(a),b.conf);this._removeKey(b.conf);d(b.node).remove();a=d.inArray(b,c);c.splice(a,1);return this},text:function(a,b){var c=this._nodeToButton(a),e=this.c.dom.collection.buttonLiner,e=c.inCollection&&e&&e.tag?e.tag:this.c.dom.buttonLiner.tag,g=this.s.dt,h=d(c.node),f=function(a){return"function"===typeof a?a(g,h,c.conf):a};if(b===m)return f(c.conf.text);c.conf.text=b;e?h.children(e).html(f(b)):h.html(f(b));return this},_constructor:function(){var a= +this,b=this.s.dt,c=b.settings()[0],e=this.c.buttons;c._buttons||(c._buttons=[]);c._buttons.push({inst:this,name:this.c.name});for(var c=0,g=e.length;c<g;c++)this.add(e[c]);b.on("destroy",function(){a.destroy()});d("body").on("keyup."+this.s.namespace,function(b){if(!o.activeElement||o.activeElement===o.body){var c=String.fromCharCode(b.keyCode).toLowerCase();a.s.listenKeys.toLowerCase().indexOf(c)!==-1&&a._keypress(c,b)}})},_addKey:function(a){a.key&&(this.s.listenKeys+=d.isPlainObject(a.key)?a.key.key: +a.key)},_draw:function(a,b){a||(a=this.dom.container,b=this.s.buttons);a.children().detach();for(var c=0,e=b.length;c<e;c++)a.append(b[c].inserter),b[c].buttons&&b[c].buttons.length&&this._draw(b[c].collection,b[c].buttons)},_expandButton:function(a,b,c,e){for(var g=this.s.dt,h=0,b=!d.isArray(b)?[b]:b,f=0,r=b.length;f<r;f++){var k=this._resolveExtends(b[f]);if(k)if(d.isArray(k))this._expandButton(a,k,c,e);else{var p=this._buildButton(k,c);if(p){e!==m?(a.splice(e,0,p),e++):a.push(p);if(p.conf.buttons){var s= +this.c.dom.collection;p.collection=d("<"+s.tag+"/>").addClass(s.className);p.conf._collection=p.collection;this._expandButton(p.buttons,p.conf.buttons,!0,e)}k.init&&k.init.call(g.button(p.node),g,d(p.node),k);h++}}}},_buildButton:function(a,b){var c=this.c.dom.button,e=this.c.dom.buttonLiner,g=this.c.dom.collection,h=this.s.dt,f=function(b){return"function"===typeof b?b(h,k,a):b};b&&g.button&&(c=g.button);b&&g.buttonLiner&&(e=g.buttonLiner);if(a.available&&!a.available(h,a))return!1;var r=function(a, +b,c,e){e.action.call(b.button(c),a,b,c,e);d(b.table().node()).triggerHandler("buttons-action.dt",[b.button(c),b,c,e])},k=d("<"+c.tag+"/>").addClass(c.className).attr("tabindex",this.s.dt.settings()[0].iTabIndex).attr("aria-controls",this.s.dt.table().node().id).on("click.dtb",function(b){b.preventDefault();!k.hasClass(c.disabled)&&a.action&&r(b,h,k,a);k.blur()}).on("keyup.dtb",function(b){b.keyCode===13&&!k.hasClass(c.disabled)&&a.action&&r(b,h,k,a)});"a"===c.tag.toLowerCase()&&k.attr("href","#"); +e.tag?(g=d("<"+e.tag+"/>").html(f(a.text)).addClass(e.className),"a"===e.tag.toLowerCase()&&g.attr("href","#"),k.append(g)):k.html(f(a.text));!1===a.enabled&&k.addClass(c.disabled);a.className&&k.addClass(a.className);a.titleAttr&&k.attr("title",a.titleAttr);a.namespace||(a.namespace=".dt-button-"+v++);e=(e=this.c.dom.buttonContainer)&&e.tag?d("<"+e.tag+"/>").addClass(e.className).append(k):k;this._addKey(a);return{conf:a,node:k.get(0),inserter:e,buttons:[],inCollection:b,collection:null}},_nodeToButton:function(a, +b){b||(b=this.s.buttons);for(var c=0,e=b.length;c<e;c++){if(b[c].node===a)return b[c];if(b[c].buttons.length){var d=this._nodeToButton(a,b[c].buttons);if(d)return d}}},_nodeToHost:function(a,b){b||(b=this.s.buttons);for(var c=0,e=b.length;c<e;c++){if(b[c].node===a)return b;if(b[c].buttons.length){var d=this._nodeToHost(a,b[c].buttons);if(d)return d}}},_keypress:function(a,b){var c=function(e){for(var g=0,h=e.length;g<h;g++){var f=e[g].conf,r=e[g].node;if(f.key)if(f.key===a)d(r).click();else if(d.isPlainObject(f.key)&& +f.key.key===a&&(!f.key.shiftKey||b.shiftKey))if(!f.key.altKey||b.altKey)if(!f.key.ctrlKey||b.ctrlKey)(!f.key.metaKey||b.metaKey)&&d(r).click();e[g].buttons.length&&c(e[g].buttons)}};c(this.s.buttons)},_removeKey:function(a){if(a.key){var b=d.isPlainObject(a.key)?a.key.key:a.key,a=this.s.listenKeys.split(""),b=d.inArray(b,a);a.splice(b,1);this.s.listenKeys=a.join("")}},_resolveExtends:function(a){for(var b=this.s.dt,c,e,g=function(c){for(var e=0;!d.isPlainObject(c)&&!d.isArray(c);){if(c===m)return; +if("function"===typeof c){if(c=c(b,a),!c)return!1}else if("string"===typeof c){if(!j[c])throw"Unknown button type: "+c;c=j[c]}e++;if(30<e)throw"Buttons: Too many iterations";}return d.isArray(c)?c:d.extend({},c)},a=g(a);a&&a.extend;){if(!j[a.extend])throw"Cannot extend unknown button type: "+a.extend;var h=g(j[a.extend]);if(d.isArray(h))return h;if(!h)return!1;c=h.className;a=d.extend({},h,a);c&&a.className!==c&&(a.className=c+" "+a.className);var f=a.postfixButtons;if(f){a.buttons||(a.buttons=[]); +c=0;for(e=f.length;c<e;c++)a.buttons.push(f[c]);a.postfixButtons=null}if(f=a.prefixButtons){a.buttons||(a.buttons=[]);c=0;for(e=f.length;c<e;c++)a.buttons.splice(c,0,f[c]);a.prefixButtons=null}a.extend=h.extend}return a}});l.background=function(a,b,c){c===m&&(c=400);a?d("<div/>").addClass(b).css("display","none").appendTo("body").fadeIn(c):d("body > div."+b).fadeOut(c,function(){d(this).removeClass(b).remove()})};l.instanceSelector=function(a,b){if(!a)return d.map(b,function(a){return a.inst});var c= +[],e=d.map(b,function(a){return a.name}),g=function(a){if(d.isArray(a))for(var f=0,r=a.length;f<r;f++)g(a[f]);else"string"===typeof a?-1!==a.indexOf(",")?g(a.split(",")):(a=d.inArray(d.trim(a),e),-1!==a&&c.push(b[a].inst)):"number"===typeof a&&c.push(b[a].inst)};g(a);return c};l.buttonSelector=function(a,b){for(var c=[],e=function(a,b,c){for(var d,g,f=0,h=b.length;f<h;f++)if(d=b[f])g=c!==m?c+f:f+"",a.push({node:d.node,name:d.conf.name,idx:g}),d.buttons&&e(a,d.buttons,g+"-")},g=function(a,b){var f, +h,i=[];e(i,b.s.buttons);f=d.map(i,function(a){return a.node});if(d.isArray(a)||a instanceof d){f=0;for(h=a.length;f<h;f++)g(a[f],b)}else if(null===a||a===m||"*"===a){f=0;for(h=i.length;f<h;f++)c.push({inst:b,node:i[f].node})}else if("number"===typeof a)c.push({inst:b,node:b.s.buttons[a].node});else if("string"===typeof a)if(-1!==a.indexOf(",")){i=a.split(",");f=0;for(h=i.length;f<h;f++)g(d.trim(i[f]),b)}else if(a.match(/^\d+(\-\d+)*$/))f=d.map(i,function(a){return a.idx}),c.push({inst:b,node:i[d.inArray(a, +f)].node});else if(-1!==a.indexOf(":name")){var j=a.replace(":name","");f=0;for(h=i.length;f<h;f++)i[f].name===j&&c.push({inst:b,node:i[f].node})}else d(f).filter(a).each(function(){c.push({inst:b,node:this})});else"object"===typeof a&&a.nodeName&&(i=d.inArray(a,f),-1!==i&&c.push({inst:b,node:f[i]}))},h=0,f=a.length;h<f;h++)g(b,a[h]);return c};l.defaults={buttons:["copy","excel","csv","pdf","print"],name:"main",tabIndex:0,dom:{container:{tag:"div",className:"dt-buttons"},collection:{tag:"div",className:"dt-button-collection"}, +button:{tag:"a",className:"dt-button",active:"active",disabled:"disabled"},buttonLiner:{tag:"span",className:""}}};l.version="1.2.4";d.extend(j,{collection:{text:function(a){return a.i18n("buttons.collection","Collection")},className:"buttons-collection",action:function(a,b,c,e){var a=c.offset(),g=d(b.table().container()),h=!1;d("div.dt-button-background").length&&(h=d(".dt-button-collection").offset(),d("body").trigger("click.dtb-collection"));e._collection.addClass(e.collectionLayout).css("display", +"none").appendTo("body").fadeIn(e.fade);var f=e._collection.css("position");h&&"absolute"===f?e._collection.css({top:h.top,left:h.left}):"absolute"===f?(e._collection.css({top:a.top+c.outerHeight(),left:a.left}),c=a.left+e._collection.outerWidth(),g=g.offset().left+g.width(),c>g&&e._collection.css("left",a.left-(c-g))):(a=e._collection.height()/2,a>d(n).height()/2&&(a=d(n).height()/2),e._collection.css("marginTop",-1*a));e.background&&l.background(!0,e.backgroundClassName,e.fade);setTimeout(function(){d("div.dt-button-background").on("click.dtb-collection", +function(){});d("body").on("click.dtb-collection",function(a){var c=d.fn.addBack?"addBack":"andSelf";if(!d(a.target).parents()[c]().filter(e._collection).length){e._collection.fadeOut(e.fade,function(){e._collection.detach()});d("div.dt-button-background").off("click.dtb-collection");l.background(false,e.backgroundClassName,e.fade);d("body").off("click.dtb-collection");b.off("buttons-action.b-internal")}})},10);if(e.autoClose)b.on("buttons-action.b-internal",function(){d("div.dt-button-background").click()})}, +background:!0,collectionLayout:"",backgroundClassName:"dt-button-background",autoClose:!1,fade:400},copy:function(a,b){if(j.copyHtml5)return"copyHtml5";if(j.copyFlash&&j.copyFlash.available(a,b))return"copyFlash"},csv:function(a,b){if(j.csvHtml5&&j.csvHtml5.available(a,b))return"csvHtml5";if(j.csvFlash&&j.csvFlash.available(a,b))return"csvFlash"},excel:function(a,b){if(j.excelHtml5&&j.excelHtml5.available(a,b))return"excelHtml5";if(j.excelFlash&&j.excelFlash.available(a,b))return"excelFlash"},pdf:function(a, +b){if(j.pdfHtml5&&j.pdfHtml5.available(a,b))return"pdfHtml5";if(j.pdfFlash&&j.pdfFlash.available(a,b))return"pdfFlash"},pageLength:function(a){var a=a.settings()[0].aLengthMenu,b=d.isArray(a[0])?a[0]:a,c=d.isArray(a[0])?a[1]:a,e=function(a){return a.i18n("buttons.pageLength",{"-1":"Show all rows",_:"Show %d rows"},a.page.len())};return{extend:"collection",text:e,className:"buttons-page-length",autoClose:!0,buttons:d.map(b,function(a,b){return{text:c[b],className:"button-page-length",action:function(b, +c){c.page.len(a).draw()},init:function(b,c,e){var d=this,c=function(){d.active(b.page.len()===a)};b.on("length.dt"+e.namespace,c);c()},destroy:function(a,b,c){a.off("length.dt"+c.namespace)}}}),init:function(a,b,c){var d=this;a.on("length.dt"+c.namespace,function(){d.text(e(a))})},destroy:function(a,b,c){a.off("length.dt"+c.namespace)}}}});i.Api.register("buttons()",function(a,b){b===m&&(b=a,a=m);this.selector.buttonGroup=a;var c=this.iterator(!0,"table",function(c){if(c._buttons)return l.buttonSelector(l.instanceSelector(a, +c._buttons),b)},!0);c._groupSelector=a;return c});i.Api.register("button()",function(a,b){var c=this.buttons(a,b);1<c.length&&c.splice(1,c.length);return c});i.Api.registerPlural("buttons().active()","button().active()",function(a){return a===m?this.map(function(a){return a.inst.active(a.node)}):this.each(function(b){b.inst.active(b.node,a)})});i.Api.registerPlural("buttons().action()","button().action()",function(a){return a===m?this.map(function(a){return a.inst.action(a.node)}):this.each(function(b){b.inst.action(b.node, +a)})});i.Api.register(["buttons().enable()","button().enable()"],function(a){return this.each(function(b){b.inst.enable(b.node,a)})});i.Api.register(["buttons().disable()","button().disable()"],function(){return this.each(function(a){a.inst.disable(a.node)})});i.Api.registerPlural("buttons().nodes()","button().node()",function(){var a=d();d(this.each(function(b){a=a.add(b.inst.node(b.node))}));return a});i.Api.registerPlural("buttons().text()","button().text()",function(a){return a===m?this.map(function(a){return a.inst.text(a.node)}): +this.each(function(b){b.inst.text(b.node,a)})});i.Api.registerPlural("buttons().trigger()","button().trigger()",function(){return this.each(function(a){a.inst.node(a.node).trigger("click")})});i.Api.registerPlural("buttons().containers()","buttons().container()",function(){var a=d(),b=this._groupSelector;this.iterator(!0,"table",function(c){if(c._buttons)for(var c=l.instanceSelector(b,c._buttons),d=0,g=c.length;d<g;d++)a=a.add(c[d].container())});return a});i.Api.register("button().add()",function(a, +b){var c=this.context;c.length&&(c=l.instanceSelector(this._groupSelector,c[0]._buttons),c.length&&c[0].add(b,a));return this.button(this._groupSelector,a)});i.Api.register("buttons().destroy()",function(){this.pluck("inst").unique().each(function(a){a.destroy()});return this});i.Api.registerPlural("buttons().remove()","buttons().remove()",function(){this.each(function(a){a.inst.remove(a.node)});return this});var q;i.Api.register("buttons.info()",function(a,b,c){var e=this;if(!1===a)return d("#datatables_buttons_info").fadeOut(function(){d(this).remove()}), +clearTimeout(q),q=null,this;q&&clearTimeout(q);d("#datatables_buttons_info").length&&d("#datatables_buttons_info").remove();d('<div id="datatables_buttons_info" class="dt-button-info"/>').html(a?"<h2>"+a+"</h2>":"").append(d("<div/>")["string"===typeof b?"html":"append"](b)).css("display","none").appendTo("body").fadeIn();c!==m&&0!==c&&(q=setTimeout(function(){e.buttons.info(!1)},c));return this});i.Api.register("buttons.exportData()",function(a){if(this.context.length){for(var b=new i.Api(this.context[0]), +c=d.extend(!0,{},{rows:null,columns:"",modifier:{search:"applied",order:"applied"},orthogonal:"display",stripHtml:!0,stripNewlines:!0,decodeEntities:!0,trim:!0,format:{header:function(a){return e(a)},footer:function(a){return e(a)},body:function(a){return e(a)}}},a),e=function(a){if("string"!==typeof a)return a;c.stripHtml&&(a=a.replace(/<[^>]*>/g,""));c.trim&&(a=a.replace(/^\s+|\s+$/g,""));c.stripNewlines&&(a=a.replace(/\n/g," "));c.decodeEntities&&(t.innerHTML=a,a=t.value);return a},a=b.columns(c.columns).indexes().map(function(a){var d= +b.column(a).header();return c.format.header(d.innerHTML,a,d)}).toArray(),g=b.table().footer()?b.columns(c.columns).indexes().map(function(a){var d=b.column(a).footer();return c.format.footer(d?d.innerHTML:"",a,d)}).toArray():null,h=b.rows(c.rows,c.modifier).indexes().toArray(),f=b.cells(h,c.columns),h=f.render(c.orthogonal).toArray(),f=f.nodes().toArray(),j=a.length,k=0<j?h.length/j:0,l=Array(k),m=0,n=0;n<k;n++){for(var o=Array(j),q=0;q<j;q++)o[q]=c.format.body(h[m],n,q,f[m]),m++;l[n]=o}return{header:a, +footer:g,body:l}}});var t=d("<textarea/>")[0];d.fn.dataTable.Buttons=l;d.fn.DataTable.Buttons=l;d(o).on("init.dt plugin-init.dt",function(a,b){if("dt"===a.namespace){var c=b.oInit.buttons||i.defaults.buttons;c&&!b._buttons&&(new l(b,c)).container()}});i.ext.feature.push({fnInit:function(a){var a=new i.Api(a),b=a.init().buttons||i.defaults.buttons;return(new l(a,b)).container()},cFeature:"B"});return l});
\ No newline at end of file diff --git a/wqflask/wqflask/static/new/packages/DataTables/extensions/scroller.dataTables.min.css b/wqflask/wqflask/static/new/packages/DataTables/extensions/scroller.dataTables.min.css new file mode 100644 index 00000000..284cb376 --- /dev/null +++ b/wqflask/wqflask/static/new/packages/DataTables/extensions/scroller.dataTables.min.css @@ -0,0 +1 @@ +div.DTS{display:block !important}div.DTS tbody th,div.DTS tbody td{white-space:nowrap}div.DTS div.DTS_Loading{z-index:1}div.DTS div.dataTables_scrollBody{background:repeating-linear-gradient(45deg, #edeeff, #edeeff 10px, #fff 10px, #fff 20px)}div.DTS div.dataTables_scrollBody table{z-index:2}div.DTS div.dataTables_paginate,div.DTS div.dataTables_length{display:none}
\ No newline at end of file diff --git a/wqflask/wqflask/static/packages/bootstrap/css/bootstrap.css b/wqflask/wqflask/static/packages/bootstrap/css/bootstrap.css index 2c20f635..91aaa98f 100644 --- a/wqflask/wqflask/static/packages/bootstrap/css/bootstrap.css +++ b/wqflask/wqflask/static/packages/bootstrap/css/bootstrap.css @@ -2088,7 +2088,7 @@ th { border-top: 1px solid #ddd; } .table > thead > tr > th { - vertical-align: bottom; + vertical-align: middle; border-bottom: 2px solid #ddd; } .table > caption + thead > tr:first-child > th, diff --git a/wqflask/wqflask/static/packages/bootstrap/css/non-responsive.css b/wqflask/wqflask/static/packages/bootstrap/css/non-responsive.css index 076b6dae..9da73a8f 100644 --- a/wqflask/wqflask/static/packages/bootstrap/css/non-responsive.css +++ b/wqflask/wqflask/static/packages/bootstrap/css/non-responsive.css @@ -28,7 +28,7 @@ body { /* Reset the container */ .container { - width: 1200px; + width: 1400px; max-width: none !important; } diff --git a/wqflask/wqflask/templates/base.html b/wqflask/wqflask/templates/base.html index c3826a90..ec55ebeb 100644 --- a/wqflask/wqflask/templates/base.html +++ b/wqflask/wqflask/templates/base.html @@ -81,10 +81,10 @@ </div> </div> - <div class="container-fluid" style="background-color: #d5d5d5; height: 95px;"> + <div class="container-fluid" style="position: relative; background-color: #d5d5d5; height: 95px;"> <form method="get" action="/gsearch"> - <div class="row"> + <div class="row" style="position: absolute; bottom: 0; top: 30px;"> <select class="form-control col-xs-2" style="width: 170px; margin-top: 15px; margin-left: 10px;" name="type"> <option value="gene">Genes / Molecules</option> <option value="phenotype" {% if type=="phenotype" %}selected{% endif %}>Phenotypes</option> @@ -95,29 +95,27 @@ </form> </div> - {% block content %}{% endblock %} + {% block content %} + {% endblock %} - <!-- Footer - ================================================== --> <footer class="footer"> <div class="container"> - - <p> - -GeneNetwork is a framework for web based genetics - launched in 1994 as + <p>GeneNetwork is a framework for web based genetics + launched in 1994 as <a href="http://www.ncbi.nlm.nih.gov/pubmed?term=8043953"> The Portable Dictionary of the Mouse Genome</a> (previously <a href="https://www.ncbi.nlm.nih.gov/pubmed/15043217">WebQTL</a>). </p> - <p>Operated by + <p> + Operated by <a href="mailto:rwilliams@uthsc.edu">Rob Williams</a>, <a href="mailto:lyan6@uthsc.edu">Lei Yan</a>, - <a href="mailto:zachary.a.sloan@gmail.com">Zachary Sloan</a>, and - <a href="mailto:acenteno@uthsc.edu">Arthur Centeno</a>. + <a href="mailto:zachary.a.sloan@gmail.com">Zachary Sloan</a>, + <a href="mailto:acenteno@uthsc.edu">Arthur Centeno</a> and + <a href="http://thebird.nl/">Pjotr Prins</a>. </p> <p>Published in <a href="http://joss.theoj.org/papers/10.21105/joss.00025"><img src="https://camo.githubusercontent.com/846b750f582ae8f1d0b4f7e8fee78bed705c88ba/687474703a2f2f6a6f73732e7468656f6a2e6f72672f7061706572732f31302e32313130352f6a6f73732e30303032352f7374617475732e737667" alt="JOSS" data-canonical-src="http://joss.theoj.org/papers/10.21105/joss.00025/status.svg" style="max-width:100%;"></a> - </p> + </p> <br /> <p>GeneNetwork is supported by:</p> <UL> @@ -143,8 +141,12 @@ GeneNetwork is a framework for web based genetics </li> </UL> <!--</p>--> + <p> + Development and source code on <a href="https://github.com/genenetwork/">github</a> with <a href="https://github.com/genenetwork/genenetwork2/issues">issue tracker</a> and <a href="https://github.com/genenetwork/genenetwork2/blob/master/README.md">documentation</a>. Join the <a href="http://listserv.uthsc.edu/mailman/listinfo/genenetwork-dev">mailing list</a> and find us on <a href="https://webchat.freenode.net/">IRC</a> (#genenetwork channel). + {% if version: %} + <p><small>GeneNetwork v{{ version }}</small></p> + {% endif %} - Join the <a href="http://listserv.uthsc.edu/mailman/listinfo/genenetwork-dev">mailing list</a> </div> </footer> diff --git a/wqflask/wqflask/templates/collections/list.html b/wqflask/wqflask/templates/collections/list.html index 23e976e9..6dc52c4d 100644 --- a/wqflask/wqflask/templates/collections/list.html +++ b/wqflask/wqflask/templates/collections/list.html @@ -26,7 +26,7 @@ {% endif %} </div> - <div id="collections_list" style="width:75%;"> + <div id="collections_list" style="width:50%;"> <table class="table table-hover table-striped" id='trait_table'> <thead> <tr> @@ -49,15 +49,11 @@ {% endif %} <td>{{ timeago(uc.created_timestamp.isoformat() + "Z") }}</td> <td>{{ timeago(uc.changed_timestamp.isoformat() + "Z") }}</td> - <td>{{ uc.num_members }}</td> + <td align="right">{{ uc.num_members }}</td> </tr> {% endfor %} </tbody> </table> - - {# if "color_by_trait" in params #} - <script type="text/javascript" src="/static/new/javascript/get_traits_from_collection.js"></script> - {# endif #} </div> </div> @@ -78,17 +74,23 @@ <script language="javascript" type="text/javascript" src="/static/new/packages/DataTables/extensions/dataTables.colReorder.js"></script> <script language="javascript" type="text/javascript" src="/static/packages/DT_bootstrap/DT_bootstrap.js"></script> <script language="javascript" type="text/javascript" src="/static/packages/TableTools/media/js/TableTools.min.js"></script> + {% if "color_by_trait" in params %} + <script type="text/javascript" src="/static/new/javascript/get_traits_from_collection.js"></script> + {% endif %} <script> $('#trait_table').dataTable( { - "buttons": [ - { - extend: 'csvHtml5', - text: 'Download CSV', - title: 'collection_list', - fieldBoundary: '"' - } + "columns": [ + { "type": "natural", + "width": "10%" }, + { "type": "natural" }, + { "type": "natural", + "width": "25%" }, + { "type": "natural", + "width": "25%" }, + { "type": "natural", + "width": "10%" } ], - "sDom": "RZBtir", + "sDom": "RZtr", "iDisplayLength": -1, "autoWidth": true, "bDeferRender": true, diff --git a/wqflask/wqflask/templates/collections/view.html b/wqflask/wqflask/templates/collections/view.html index 8fc5f120..9d03e6d7 100644 --- a/wqflask/wqflask/templates/collections/view.html +++ b/wqflask/wqflask/templates/collections/view.html @@ -4,7 +4,6 @@ <link rel="stylesheet" type="text/css" href="/static/new/packages/DataTables/css/jquery.dataTables.css" /> <link rel="stylesheet" type="text/css" href="/static/packages/DT_bootstrap/DT_bootstrap.css" /> <link rel="stylesheet" type="text/css" href="/static/packages/TableTools/media/css/TableTools.css" /> - <link rel="stylesheet" type="text/css" href="/static/new/packages/DataTables/extensions/buttons.bootstrap.css" /> {% endblock %} {% block content %} <!-- Start of body --> @@ -74,20 +73,26 @@ <button class="btn" id="remove" disabled="disabled"><i class="icon-minus-sign"></i> Remove Record</button> <br /> <br /> - <div style="background-color: #eeeeee; border: 1px solid black;"> - <table id="trait_table" class="table table-hover table-striped"> + <form id="export_form" method="POST" action="/export_traits_csv"> + <input type="hidden" name="database_name" id="database_name" value="None"> + <input type="hidden" name="export_data" id="export_data" value=""> + <button class="btn btn-default" id="export_traits">Download CSV</button> + </form> + <br /> + <div> + <table class="table table-hover table-striped nowrap" id='trait_table' style="float: left;"> <thead> <tr> - <th style="background-color: #eeeeee;"></th> - <th style="background-color: #eeeeee;">Index</th> - <th style="background-color: #eeeeee;">Dataset</th> - <th style="background-color: #eeeeee;">Record</th> - <th style="background-color: #eeeeee;">Description</th> - <th style="background-color: #eeeeee;">Location</th> - <th style="background-color: #eeeeee;">Mean</th> - <th style="background-color: #eeeeee;">Max LRS<a href="http://genenetwork.org//glossary.html#L" target="_blank"><sup style="color:#f00"> ?</sup></a></th> - <th style="background-color: #eeeeee;">Max LRS Location</th> - <th style="background-color: #eeeeee;">Additive Effect<a href="http://genenetwork.org//glossary.html#A" target="_blank"><sup style="color:#f00"> ?</sup></a></th> + <th></th> + <th data-export="Index">Index</th> + <th data-export="Dataset">Dataset</th> + <th data-export="Record">Record</th> + <th data-export="Description">Description</th> + <th data-export="Location">Location</th> + <th data-export="Mean">Mean</th> + <th data-export="Max LRS">Max LRS<a href="http://genenetwork.org//glossary.html#L" target="_blank"><sup style="color:#f00"> ?</sup></a></th> + <th data-export="Max LRS Location">Max LRS Location</th> + <th data-export="Additive Effect">Additive Effect<a href="http://genenetwork.org//glossary.html#A" target="_blank"><sup style="color:#f00"> ?</sup></a></th> </tr> </thead> @@ -98,9 +103,9 @@ <INPUT TYPE="checkbox" NAME="searchResult" class="checkbox trait_checkbox" VALUE="{{ data_hmac('{}:{}'.format(this_trait.name, this_trait.dataset.name)) }}"> </TD> - <TD>{{ loop.index }}</TD> - <TD>{{ this_trait.dataset.name }}</TD> - <TD> + <TD data-export="{{ loop.index }}" align="right">{{ loop.index }}</TD> + <TD data-export="{{ this_trait.dataset.name }}">{{ this_trait.dataset.name }}</TD> + <TD data-export="{{ this_trait.name }}"> <a href="{{ url_for('show_trait_page', trait_id = this_trait.name, dataset = this_trait.dataset.name @@ -108,12 +113,12 @@ {{ this_trait.name }} </a> </TD> - <TD>{{ this_trait.description_display }}</TD> - <TD>{{ this_trait.location_repr }}</TD> - <TD>{{ '%0.3f' % this_trait.mean|float }}</TD> - <TD>{{ '%0.3f' % this_trait.LRS_score_repr|float }}</TD> - <TD>{{ this_trait.LRS_location_repr }}</TD> - <TD>{{ '%0.3f' % this_trait.additive|float }}</TD> + <TD title="{{ this_trait.description_display }}" data-export="{{ this_trait.description_display }}">{{ this_trait.description_display }}</TD> + <TD data-export="{{ this_trait.location_repr }}">{{ this_trait.location_repr }}</TD> + <TD data-export="{{ this_trait.mean }}" align="right">{{ '%0.3f' % this_trait.mean|float }}</TD> + <TD data-export="{{ this_trait.LRS_score_repr }}" align="right">{{ '%0.3f' % this_trait.LRS_score_repr|float }}</TD> + <TD data-export="{{ this_trait.LRS_location_repr }}">{{ this_trait.LRS_location_repr }}</TD> + <TD data-export="{{ this_trait.additive }}" align="right">{{ '%0.3f' % this_trait.additive|float }}</TD> </TR> {% endfor %} @@ -132,9 +137,6 @@ {% block js %} <script type="text/javascript" src="/static/new/javascript/search_results.js"></script> <script language="javascript" type="text/javascript" src="/static/new/packages/DataTables/js/jquery.dataTables.min.js"></script> - <script language="javascript" type="text/javascript" src="https://cdn.datatables.net/buttons/1.0.0/js/dataTables.buttons.min.js"></script> - <script language="javascript" type="text/javascript" src="https://cdn.datatables.net/buttons/1.0.0/js/buttons.html5.min.js"></script> - <script language="javascript" type="text/javascript" src="https://cdn.datatables.net/buttons/1.0.0/js/buttons.bootstrap.min.js"></script> <script language="javascript" type="text/javascript" src="/static/new/js_external/jszip.min.js"></script> <script language="javascript" type="text/javascript" src="/static/new/packages/DataTables/js/dataTables.naturalSort.js"></script> <script language="javascript" type="text/javascript" src="/static/new/packages/DataTables/extensions/dataTables.colResize.js"></script> @@ -154,34 +156,34 @@ console.time("Creating table"); $('#trait_table').dataTable( { + "createdRow": function ( row, data, index ) { + if ($('td', row).eq(4).text().length > 50) { + $('td', row).eq(4).text($('td', row).eq(4).text().substring(0, 50)); + $('td', row).eq(4).text($('td', row).eq(4).text() + '...') + } + }, "columns": [ { "type": "natural" }, - { "type": "natural" }, + { "type": "natural", "width": "5%" }, { "type": "natural" }, { "type": "natural" }, { "type": "natural", - "width": "35%" }, + "width": "30%" }, { "type": "natural", - "width": "15%" }, + "width": "10%" }, { "type": "cust-txt" }, { "type": "natural", - "width": "9%" }, + "width": "6%" }, { "type": "natural", - "width": "15%" }, - { "type": "natural" } - ], - "buttons": [ - { - extend: 'csvHtml5', - text: 'Download CSV', - title: 'collection', - fieldBoundary: '"', - exportOptions: { - columns: [1, 2, 3, 4, 5, 6, 7, 8, 9] - } - } + "width": "10%" }, + { "type": "natural", + "width": "8%" } ], - "sDom": "ZRBtir", + "columnDefs": [ { + "targets": 0, + "orderable": false + } ], + "sDom": "ZRtr", "iDisplayLength": -1, "autoWidth": true, "bDeferRender": true, diff --git a/wqflask/wqflask/templates/correlation_matrix.html b/wqflask/wqflask/templates/correlation_matrix.html index 593c7bea..eb675568 100644 --- a/wqflask/wqflask/templates/correlation_matrix.html +++ b/wqflask/wqflask/templates/correlation_matrix.html @@ -12,11 +12,12 @@ {{ header("Correlation Matrix") }} +<div class="container"> {% if lowest_overlap < 8 %} <div style="margin: 20px;" >Caution: This matrix of correlations contains some cells with small sample sizes of fewer than 8.</div> {% endif %} -<table class="matrix" border="1" cellpadding="5" cellspacing="1" style="margin: 20px;" width="80%"> +<table class="matrix" border="1" cellpadding="5" cellspacing="1" width="80%"> <tbody> <tr> <td style="background-color: royalblue;" ></td> @@ -26,35 +27,53 @@ <td align="center" rowspan="{{traits|length + 1 }}" width="10" style="font-weight: Bold; border: 1px solid #999999; padding: 3px; color: #fff; background-color: royalblue;">P e a r s o n r</td> <td width="300"></td> {% for trait in traits %} - <td align="center"><a href="/show_trait?trait_id={{ trait.name }}&dataset={{ trait.dataset.name }}" style="font-weight: Bold;">Trait{{ loop.index }}</a></td> + <td align="center"> + <a href="/show_trait?trait_id={{ trait.name }}&dataset={{ trait.dataset.name }}" style="font-weight: Bold;">Trait{{ loop.index }}</a> + </td> {% endfor %} </tr> {% for trait in traits %} <tr> - <td><a href="/show_trait?trait_id={{ trait.name }}&dataset={{ trait.dataset.name }}" style="font-weight: Bold;">Trait {{ loop.index }}: {{ trait.dataset.name }}::{{ trait.name }}</a><div id="shortName_0" style="display:none">Symbol: {{ trait.symbol }} </div><div id="verboseName_0" style="display:none">{{ trait_symbol }} on Chr {{ trait.chr }} @ {{ trait.mb }} Mb</div><div id="verboseName2_0" style="display:none">{{ trait.description }}</div><div id="verboseName3_0" style="display:none">{{ trait.probe_target_description }}</div></td> + <td> + <a href="/show_trait?trait_id={{ trait.name }}&dataset={{ trait.dataset.name }}" style="font-weight: Bold;">Trait {{ loop.index }}: {{ trait.dataset.name }}::{{ trait.name }}</a> + <div class="shortName" style="display:none">{% if trait.dataset.type == "ProbeSet" %}Symbol: {{ trait.symbol }}{% elif trait.dataset.type == "Publish" %}Phenotype: {{ trait.post_publication_abbreviation }}{% else %}Genotype{% endif %} </div> + <div class="verboseName" style="display: none;"> + {% if trait.dataset.type == "ProbeSet" %} + <div>{{ trait.symbol }} on Chr {{ trait.chr }} @ {{ trait.mb }} Mb</div><div>{{ trait.description }}</div><div>{{ trait.probe_target_description }}</div> + {% elif trait.dataset.type == "Publish" %} + <div>PubMed {{ trait.pubmed_id }}: RecordID/{{ trait.name }}</div><div>Phenotype: {{ trait.description_display }}</div> + {% else %} + <div>Locus {{ trait.name }}</div><div>Chr {{ trait.chr }} @ {{ trait.mb }} Mb</div> + {% endif %} + </div> + </td> {% for result in corr_results[loop.index-1] %} {% if result[0].name == trait.name %} - <td nowrap="ON" align="center" bgcolor="#cccccc"><a href="/show_trait?trait_id={{ trait.name }}&dataset={{ trait.dataset.name }}"><font style="font-size: 11px; color: #000000;" ><em>n</em><br>{{ result[2] }}</font></a></td> + <td nowrap="ON" align="center" bgcolor="#cccccc" style="line-height: 1.1;"><a href="/show_trait?trait_id={{ trait.name }}&dataset={{ trait.dataset.name }}"><font style="font-size: 12px; color: #000000;" ><em>n</em><br>{{ result[2] }}</font></a></td> {% else %} - <td nowrap="ON" align="middle" class="corr_cell"><a href="/corr_scatter_plot?dataset_1={{ trait.dataset.name }}&dataset_2={{ result[0].dataset.name }}&trait_1={{ trait.name }}&trait_2={{ result[0].name }}"><font style="font-size: 11px; color: #000000;" ><span class="corr_value">{{ '%0.3f' % result[1] }}</span><br>{{ result[2] }}</font></a></td> + <td nowrap="ON" align="middle" class="corr_cell" style="line-height: 1.1;"><a href="/corr_scatter_plot?dataset_1={{ trait.dataset.name }}&dataset_2={{ result[0].dataset.name }}&trait_1={{ trait.name }}&trait_2={{ result[0].name }}"><font style="font-size: 12px; color: #000000;" ><span class="corr_value">{{ '%0.3f' % result[1] }}</span><br>{{ result[2] }}</font></a></td> {% endif %} {% endfor %} </tr> {% endfor %} </tbody> </table> - <br> - +<button class="btn btn-default" id="short_labels">Short Labels</button> +<button class="btn btn-default" id="long_labels">Long Labels</button> +<br> +<br> +<h2>Factor Loadings Plot</h2> <div id="loadings_plot"></div> +<h2>Factor Loadings Table</h2> <table class="table table-hover table-striped" border="1" id='trait_table' style="margin: 20px;" width="40%"> <thead> <tr> <th></th> <th align="right" >Factor 1</th> <th align="right" >Factor 2</th> - <th align="right" >Factor 2</th> + {% if trait_list|length > 2 %}<th align="right" >Factor 3</th>{% endif %} <!-- {% for row in loadings_array %} <th>Factor {{ loop.index }}</th> @@ -79,12 +98,14 @@ </tbody> </table> +</div> {% endblock %} {% block js %} <script> + js_data = {{ js_data | safe }} loadings = {{ loadings_array | safe }} </script> @@ -98,5 +119,6 @@ <script type="text/javascript" src="/static/new/javascript/panelutil.js"></script> <script language="javascript" type="text/javascript" src="/static/new/js_external/chroma.js"></script> <script language="javascript" type="text/javascript" src="/static/new/javascript/loadings_plot.js"></script> + <script type="text/javascript" src="/static/new/javascript/create_corr_matrix.js"></script> {% endblock %} diff --git a/wqflask/wqflask/templates/correlation_page.html b/wqflask/wqflask/templates/correlation_page.html index c5b4477b..cedb65a1 100644 --- a/wqflask/wqflask/templates/correlation_page.html +++ b/wqflask/wqflask/templates/correlation_page.html @@ -14,8 +14,8 @@ <h1>Correlation Table</h1> </div> - <p>Values of record {{ this_trait.name }} in the <a href="/static/dbdoc/{{dataset.fullname}}">{{ dataset.fullname }}</a> - dataset were compared to all records in the <a href="/static/dbdoc/{{target_dataset.fullname}}">{{ target_dataset.fullname }}</a> + <p>Values of record {{ this_trait.name }} in the <a href="http://genenetwork.org/webqtl/main.py?FormID=sharinginfo&GN_AccessionId={{ dataset.group.accession_id }}">{{ dataset.fullname }}</a> + dataset were compared to all records in the <a href="http://genenetwork.org/webqtl/main.py?FormID=sharinginfo&GN_AccessionId={{ target_dataset.group.accession_id }}">{{ target_dataset.fullname }}</a> dataset. The top {{ return_number }} correlations ranked by the {{ formatted_corr_type }} are displayed. You can resort this list by clicking the headers. Select the Record ID to open the trait data and analysis page. @@ -220,6 +220,20 @@ }; + jQuery.fn.dataTableExt.oSort['scientific-asc'] = function ( a, b ) { + var x = parseFloat(a); + var y = parseFloat(b); + return ((x < y) ? -1 : ((x > y) ? 1 : 0)); + }; + + jQuery.fn.dataTableExt.oSort['scientific-desc'] = function ( a, b ) { + var x = parseFloat(a); + var y = parseFloat(b); + return ((x < y) ? 1 : ((x > y) ? -1 : 0)); + }; + + + $(document).ready( function () { $('#trait_table tr').click(function(event) { @@ -258,13 +272,13 @@ { "type": "natural" }, { "type": "natural" }, { "type": "natural" }, - { "type": "numeric-html" }, { "type": "natural" }, { "type": "natural" }, + { "type": "scientific" }, { "type": "natural" }, { "type": "natural" } ], - "order": [[10, "desc" ]], + "order": [[12, "asc" ]], "sDom": "Btir", "autoWidth": false, "bDeferRender": true, @@ -304,9 +318,9 @@ { "type": "natural" }, { "type": "numeric-html" }, { "type": "natural" }, - { "type": "natural" } + { "type": "scientific" } ], - "order": [[9, "desc" ]], + "order": [[11, "asc" ]], "sDom": "Btir", "autoWidth": false, "bDeferRender": true, @@ -337,9 +351,9 @@ { "type": "natural" }, { "type": "numeric-html" }, { "type": "natural" }, - { "type": "natural" } + { "type": "scientific" } ], - "order": [[4, "desc" ]], + "order": [[6, "asc" ]], "sDom": "Btir", "autoWidth": false, "bDeferRender": true, diff --git a/wqflask/wqflask/templates/ctl_results.html b/wqflask/wqflask/templates/ctl_results.html index a5cb1c08..969ca18a 100644 --- a/wqflask/wqflask/templates/ctl_results.html +++ b/wqflask/wqflask/templates/ctl_results.html @@ -1,17 +1,30 @@ {% extends "base.html" %} +{% block css %} + <link rel="stylesheet" type="text/css" href="/static/new/css/network_graph.css" /> + <link rel="stylesheet" type="text/css" href="/static/packages/cytoscape/css/cytoscape.js-panzoom.css" /> + <link rel="stylesheet" type="text/css" href="http://cdnjs.cloudflare.com/ajax/libs/qtip2/2.2.0/jquery.qtip.css"> + <style> + /* The Cytoscape Web container must have its dimensions set. */ + html, body { height: 100%; width: 100%; padding: 0; margin: 0; } + #cytoscapeweb { width: 70%; height: 70%; } + </style> +{% endblock %} + {% block title %}CTL results{% endblock %} {% block content %} <!-- Start of body --> <div class="container"> <h1>CTL Results</h1> - {{(request.form['trait_list'].split(',')|length -1)}} phenotypes as input<br> - <h3>Network Figure</h3> + {{(request.form['trait_list'].split(',')|length)}} phenotypes as input<br> + + <!-- <a href="/tmp/{{ results['imgurl1'] }}"> <img alt="Embedded Image" src="data:image/png;base64, {% for elem in results['imgdata1'] -%} {% print("%c"|format(elem)) %} {%- endfor %} - " /></a> + " /></a> --> + <h3>CTL/QTL Plots for individual traits</h3> {% for r in range(2, (request.form['trait_list'].split(',')|length +1)) %} <a href="/tmp/{{ results['imgurl' + r|string] }}"> @@ -39,9 +52,26 @@ </tr> {% endfor %} </table> + <h3>Network Figure</h3> + <div id="cytoscapeweb" class="col-xs-9" style="min-height:700px !important;"></div> +</div> +{% endblock %} +{% block js %} + <script> + elements_list = {{ elements | safe }} + </script> + <script language="javascript" type="text/javascript" src="/static/new/packages/DataTables/js/jquery.js"></script> + <script language="javascript" type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/qtip2/2.2.0/jquery.qtip.js"></script> + <script language="javascript" type="text/javascript" src="/static/packages/underscore/underscore-min.js"></script> + <script language="javascript" type="text/javascript" src="/static/packages/cytoscape/js/min/cytoscape.min.js"></script> + <script language="javascript" type="text/javascript" src="/static/packages/cytoscape/js/min/AC_OETags.min.js"></script> + <script language="javascript" type="text/javascript" src="/static/packages/cytoscape/js/min/json2.min.js"></script> + <script language="javascript" type="text/javascript" src="/static/packages/cytoscape/js/src/cytoscape-panzoom.js"></script> + <script language="javascript" type="text/javascript" src="/static/packages/cytoscape/js/src/cytoscape-qtip.js"></script> -</div> + <script language="javascript" type="text/javascript" src="/static/new/javascript/ctl_graph.js"></script> {% endblock %} + diff --git a/wqflask/wqflask/templates/ctl_setup.html b/wqflask/wqflask/templates/ctl_setup.html index 51553322..a7ad5759 100644 --- a/wqflask/wqflask/templates/ctl_setup.html +++ b/wqflask/wqflask/templates/ctl_setup.html @@ -11,8 +11,14 @@ Please make sure you select enough traits to perform CTL. Your collection needs to contain at least 2 different traits. You provided {{request.form['trait_list'].split(',')|length}} traits as input. </div> {% else %} - <h1>CTL analysis parameters</h1> - {{(request.form['trait_list'].split(',')|length -1)}} traits as input + <h1>CTL analysis</h1> + CTL analysis is published as open source software, if you are using this method in your publications, please cite:<br><br> + Arends D, Li Y, Brockmann GA, Jansen RC, Williams RW, Prins P<br> + Correlation trait locus (CTL) mapping: Phenotype network inference subject to genotype.<br> + The Journal of Open Source Software (2016)<br> + Published in <a href="http://joss.theoj.org/papers/10.21105/joss.00087"><img src="http://joss.theoj.org/papers/10.21105/joss.00087/status.svg"></a> + <br><br> + {{(request.form['trait_list'].split(',')|length)}} traits as input <form action="/ctl_results" method="post" class="form-horizontal"> <input type="hidden" name="trait_list" id="trait_list" value= "{{request.form['trait_list']}}"> diff --git a/wqflask/wqflask/templates/data_sharing.html b/wqflask/wqflask/templates/data_sharing.html index 4e92106a..366e2075 100644 --- a/wqflask/wqflask/templates/data_sharing.html +++ b/wqflask/wqflask/templates/data_sharing.html @@ -1,5 +1,5 @@ {% extends "base.html" %} -{% block title %}Search Results{% endblock %} +{% block title %}Data Sharing{% endblock %} {% block content %} <!-- Start of body --> diff --git a/wqflask/wqflask/templates/error.html b/wqflask/wqflask/templates/error.html index 7ab2bf2f..c707a4fc 100644 --- a/wqflask/wqflask/templates/error.html +++ b/wqflask/wqflask/templates/error.html @@ -35,7 +35,7 @@ </p> <pre> - {{ stack[0] }} + GeneNetwork v{{ version }} {{ stack[0] }} {{ message }} (error) {{ stack[-3] }} {{ stack[-2] }} @@ -50,7 +50,7 @@ <a href="#Stack" class="btn btn-default" data-toggle="collapse">Toggle full stack trace</a> <div id="Stack" class="collapse"> <pre> - {% for line in stack %} {{ line }} + GeneNetwork v{{ version }} {% for line in stack %} {{ line }} {% endfor %} </pre> </div> diff --git a/wqflask/wqflask/templates/gsearch_gene.html b/wqflask/wqflask/templates/gsearch_gene.html index 2d970b36..e8bb6337 100644 --- a/wqflask/wqflask/templates/gsearch_gene.html +++ b/wqflask/wqflask/templates/gsearch_gene.html @@ -2,7 +2,6 @@ {% block title %}Search Results{% endblock %} {% block css %} <link rel="stylesheet" type="text/css" href="/static/new/packages/DataTables/css/jquery.dataTables.css" /> - <link rel="stylesheet" type="text/css" href="/static/new/packages/DataTables/extensions/buttons.bootstrap.css" /> {% endblock %} {% block content %} <!-- Start of body --> @@ -10,7 +9,7 @@ <div class="container"> <p>You searched for {{ terms }}.</p> - <p>To study a record, click on its ID below.<br />Check records below and click Add button to add to selection.</p> + <p>To study a record, click on its Record ID below.<br />Check records below and click Add button to add to selection.</p> <div> <br /> @@ -20,65 +19,70 @@ <button class="btn btn-default" id="add" disabled ><span class="glyphicon glyphicon-plus-sign"></span> Add</button> <input type="text" id="searchbox" class="form-control" style="width: 180px; display: inline;" placeholder="Search This Table For ..."> <input type="text" id="select_top" class="form-control" style="width: 120px; display: inline;" placeholder="Select Top ..."> - <br /> <br /> - <div style="width: 2000px; background-color: #eeeeee; border: 1px solid black;"> - <table width="2000px" id="trait_table" class="table table-hover table-striped" > + <form id="export_form" method="POST" action="/export_traits_csv"> + <input type="hidden" name="database_name" id="database_name" value="None"> + <input type="hidden" name="export_data" id="export_data" value=""> + <button class="btn btn-default" id="export_traits">Download CSV</button> + </form> + <br /> + <div style="width: 2000px;"> + <table width="2000px" id="trait_table" class="table table-hover table-striped nowrap" style="float: left;"> <thead> <tr> - <th style="background-color: #eeeeee;"></th> - <th style="background-color: #eeeeee;">Index</th> - <th style="background-color: #eeeeee;">Species</th> - <th style="background-color: #eeeeee;">Group</th> - <th style="background-color: #eeeeee;">Tissue</th> - <th style="background-color: #eeeeee;">Dataset</th> - <th style="background-color: #eeeeee;">Record</th> - <th style="background-color: #eeeeee;">Symbol</th> - <th style="background-color: #eeeeee;">Description</th> - <th style="background-color: #eeeeee;">Location</th> - <th style="background-color: #eeeeee;">Mean</th> - <th style="background-color: #eeeeee;">Max <br>LRS<a href="http://genenetwork.org/glossary.html#L" target="_blank"><sup style="color:#f00"> ?</sup></a></th> - <th style="background-color: #eeeeee;">Max LRS Location</th> - <th style="background-color: #eeeeee;">Additive<br>Effect<a href="http://genenetwork.org/glossary.html#A" target="_blank"><sup style="color:#f00"> ?</sup></a></th> + <th></th> + <th data-export="Index">Index</th> + <th data-export="Record">Record ID</th> + <th data-export="Species">Species</th> + <th data-export="Group">Group</th> + <th data-export="Tissue">Tissue</th> + <th data-export="Dataset">Dataset</th> + <th data-export="Symbol">Symbol</th> + <th data-export="Description">Description</th> + <th data-export="Location">Location</th> + <th data-export="Mean">Mean</th> + <th data-export="Max LRS">Max LRS<a href="http://genenetwork.org/glossary.html#L" target="_blank"><sup style="color:#f00"> ?</sup></a></th> + <th data-export="Max LRS Location">Max LRS Location</th> + <th data-export="Additive Effect">Additive <a href="http://genenetwork.org/glossary.html#A" target="_blank"><sup style="color:#f00"> ?</sup></a></th> </tr> </thead> <tbody> {% for this_trait in trait_list %} <tr id="trait:{{ this_trait.name }}:{{ this_trait.dataset.name }}"> - <td><input type="checkbox" name="searchResult" class="checkbox trait_checkbox" style="transform: scale(1.5);" value="{{ data_hmac('{}:{}'.format(this_trait.name, this_trait.dataset.name)) }}"></td> - <td>{{ loop.index }}</td> - <td>{{ this_trait.dataset.group.species }}</td> - <td>{{ this_trait.dataset.group.name }}</td> - <td>{{ this_trait.dataset.tissue }}</td> - <td>{{ this_trait.dataset.name }}</td> - <td><a href="{{ url_for('show_trait_page', trait_id = this_trait.name, dataset = this_trait.dataset.name)}}">{{ this_trait.name }}</a></td> - <td>{{ this_trait.symbol }}</td> - <td>{{ this_trait.description_display }}</td> - <td align="right">{{ this_trait.location_repr }}</td> - <td align="right">{{ '%0.3f' % this_trait.mean|float }}</td> - <td align="right">{% if this_trait.LRS_score_repr != "N/A" %}{{ '%0.1f' % this_trait.LRS_score_repr|float }}{% else %}N/A{% endif %}</td> - <td align="right">{{ this_trait.LRS_location_repr }}</td> - <td align="right">{% if this_trait.additive != "" %}{{ '%0.3f' % this_trait.additive|float }}{% else %}N/A{% endif %}</td> + <td align="center" style="padding-right: 0px; padding-left: 5px;"><input type="checkbox" name="searchResult" class="checkbox trait_checkbox" value="{{ data_hmac('{}:{}'.format(this_trait.name, this_trait.dataset.name)) }}"></td> + <td align="right" data-export="{{ loop.index }}">{{ loop.index }}</td> + <td data-export="{{ this_trait.name }}"><a href="{{ url_for('show_trait_page', trait_id = this_trait.name, dataset = this_trait.dataset.name)}}">{{ this_trait.name }}</a></td> + <td data-export="{{ this_trait.dataset.group.species }}">{{ this_trait.dataset.group.species }}</td> + <td data-export="{{ this_trait.dataset.group.name }}">{{ this_trait.dataset.group.name }}</td> + <td data-export="{{ this_trait.dataset.tissue }}">{{ this_trait.dataset.tissue }}</td> + <td data-export="{{ this_trait.dataset.name }}">{{ this_trait.dataset.name }}</td> + <td data-export="{{ this_trait.symbol }}">{{ this_trait.symbol }}</td> + <td data-export="{{ this_trait.description_display }}">{{ this_trait.description_display }}</td> + <td data-export="{{ this_trait.location_repr }}" align="right">{{ this_trait.location_repr }}</td> + <td data-export="{{ '%0.3f' % this_trait.mean|float }}" align="right">{{ '%0.3f' % this_trait.mean|float }}</td> + <td data-export="{% if this_trait.LRS_score_repr != "N/A" %}{{ '%0.1f' % this_trait.LRS_score_repr|float }}{% else %}N/A{% endif %}" align="right">{% if this_trait.LRS_score_repr != "N/A" %}{{ '%0.1f' % this_trait.LRS_score_repr|float }}{% else %}N/A{% endif %}</td> + <td data-export="{{ this_trait.LRS_location_repr }}" align="right">{{ this_trait.LRS_location_repr }}</td> + <td data-export="{% if this_trait.additive != "" %}{{ '%0.3f' % this_trait.additive|float }}{% else %}N/A{% endif %}" align="right">{% if this_trait.additive != "" %}{{ '%0.3f' % this_trait.additive|float }}{% else %}N/A{% endif %}</td> </tr> {% endfor %} </tbody> <tfoot> <tr> - <th style="background-color: #eeeeee;"></th> - <th style="background-color: #eeeeee;">Index</th> - <th style="background-color: #eeeeee;">Species</th> - <th style="background-color: #eeeeee;">Group</th> - <th style="background-color: #eeeeee;">Tissue</th> - <th style="background-color: #eeeeee;">Dataset</th> - <th style="background-color: #eeeeee;">Record</th> - <th style="background-color: #eeeeee;">Symbol</th> - <th style="background-color: #eeeeee;">Description</th> - <th style="background-color: #eeeeee;">Location</th> - <th style="background-color: #eeeeee;">Mean</th> - <th style="background-color: #eeeeee;">Max <br>LRS<a href="http://genenetwork.org/glossary.html#L" target="_blank"><sup style="color:#f00"> ?</sup></a></th> - <th style="background-color: #eeeeee;">Max LRS Location</th> - <th style="background-color: #eeeeee;">Additive<br>Effect<a href="http://genenetwork.org/glossary.html#A" target="_blank"><sup style="color:#f00"> ?</sup></a></th> + <th></th> + <th>Index</th> + <th>Record ID</th> + <th>Species</th> + <th>Group</th> + <th>Tissue</th> + <th>Dataset</th> + <th>Symbol</th> + <th>Description</th> + <th>Location</th> + <th>Mean</th> + <th>Max LRS<a href="http://genenetwork.org/glossary.html#L" target="_blank"><sup style="color:#f00"> ?</sup></a></th> + <th>Max LRS Location</th> + <th>Additive <a href="http://genenetwork.org/glossary.html#A" target="_blank"><sup style="color:#f00"> ?</sup></a></th> </tr> </tfoot> </table> @@ -94,9 +98,6 @@ <script language="javascript" type="text/javascript" src="/static/new/javascript/search_results.js"></script> <script language="javascript" type="text/javascript" src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script> - <script language="javascript" type="text/javascript" src="https://cdn.datatables.net/buttons/1.0.0/js/dataTables.buttons.min.js"></script> - <script language="javascript" type="text/javascript" src="https://cdn.datatables.net/buttons/1.0.0/js/buttons.html5.min.js"></script> - <script language="javascript" type="text/javascript" src="https://cdn.datatables.net/buttons/1.0.0/js/buttons.bootstrap.min.js"></script> <script language="javascript" type="text/javascript" src="/static/new/js_external/jszip.min.js"></script> <script language="javascript" type="text/javascript" src="/static/new/packages/DataTables/js/dataTables.naturalSort.js"></script> <script language="javascript" type="text/javascript" src="/static/new/packages/DataTables/extensions/dataTables.colReorder.js"></script> @@ -105,27 +106,12 @@ <script language="javascript" type="text/javascript" src="/static/packages/TableTools/media/js/TableTools.min.js"></script> <script type="text/javascript" charset="utf-8"> - function getValue(x) { - if (x.indexOf('input') >= 0) { - if ($(x).val() == 'x') { - return 0; - } - else { - return parseFloat($(x).val()); - } - } - else if (isNaN(x)) { - return x; - } - return parseFloat(x); - } - $.fn.dataTable.ext.order['dom-checkbox'] = function ( settings, col ) { return this.api().column( col, {order:'index'} ).nodes().map( function ( td, i ) { return $('input', td).prop('checked') ? '1' : '0'; } ); - } + }; $(document).ready( function () { @@ -137,36 +123,39 @@ console.time("Creating table"); $('#trait_table').DataTable( { - "paging": false, - "buttons": [ - { - extend: 'csvHtml5', - text: 'Download CSV', - title: 'search_results', - fieldBoundary: '"', - exportOptions: { - columns: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13] - } + "createdRow": function ( row, data, index ) { + $('td', row).eq(8).attr('title', $('td', row).eq(8).text()); + if ($('td', row).eq(8).text().length > 50) { + $('td', row).eq(8).text($('td', row).eq(8).text().substring(0, 50)); + $('td', row).eq(8).text($('td', row).eq(8).text() + '...') } - ], + }, + "paging": false, "columns": [ + { "orderDataType": "dom-checkbox" }, + { "type": "natural", "width": "3%" }, + { "type": "natural", "width": "6%" }, + { "type": "natural", "width": "8%" }, { "type": "natural" }, { "type": "natural" }, { "type": "natural" }, - { "type": "natural", "width": "8%" }, - { "type": "natural" }, - { "type": "natural" }, - { "type": "natural" }, - { "type": "natural" }, - { "type": "natural" }, - { "type": "natural", "width": "8%" }, { "type": "natural" }, { "type": "natural" }, - { "type": "natural", "width": "8%" }, - { "type": "natural" } + { "type": "natural", "width": "7%" }, + { "type": "natural", "width": "4%" }, + { "type": "natural", "width": "5%" }, + { "type": "natural", "width": "7%" }, + { "type": "natural", "width": "5%" } + ], + "columnDefs": [ + { + "targets": 0, + "orderable": false, + "orderDataType": "dom-checkbox" + } ], "order": [[1, "asc" ]], - "sDom": "Btir", + "sDom": "tir", "autoWidth": false, "bDeferRender": true, "scrollY": "800px", diff --git a/wqflask/wqflask/templates/gsearch_pheno.html b/wqflask/wqflask/templates/gsearch_pheno.html index be4981bb..2f7dcaf6 100644 --- a/wqflask/wqflask/templates/gsearch_pheno.html +++ b/wqflask/wqflask/templates/gsearch_pheno.html @@ -4,7 +4,6 @@ <link rel="stylesheet" type="text/css" href="/static/new/packages/DataTables/css/jquery.dataTables.css" /> <link rel="stylesheet" type="text/css" href="/static/packages/DT_bootstrap/DT_bootstrap.css" /> <link rel="stylesheet" type="text/css" href="/static/packages/TableTools/media/css/TableTools.css" /> - <link rel="stylesheet" type="text/css" href="/static/new/packages/DataTables/extensions/buttons.bootstrap.css" /> <link rel="stylesheet" type="text/css" href="/static/new/packages/DataTables/extensions/dataTables.fixedHeader.css" > <link rel="stylesheet" type="text/css" href="//cdn.datatables.net/fixedcolumns/3.0.4/css/dataTables.fixedColumns.css"> {% endblock %} @@ -25,37 +24,43 @@ <input type="text" id="select_top" class="form-control" style="width: 200px; display: inline;" placeholder="Select Top ..."> <br /> <br /> + <form id="export_form" method="POST" action="/export_traits_csv"> + <input type="hidden" name="database_name" id="database_name" value="None"> + <input type="hidden" name="export_data" id="export_data" value=""> + <button class="btn btn-default" id="export_traits">Download CSV</button> + </form> + <br /> <div style="width: 1500px; background-color: #eeeeee; border: 1px solid black;"> <table width="1500px" id="trait_table" class="table table-hover table-striped"> <thead> <tr> <th style="background-color: #eeeeee;"></th> - <th style="background-color: #eeeeee;">Index</th> - <th style="background-color: #eeeeee;">Species</th> - <th style="background-color: #eeeeee;">Group</th> - <th style="background-color: #eeeeee;">Record</th> - <th style="background-color: #eeeeee;">Description</th> - <th style="background-color: #eeeeee;">Authors</th> - <th style="background-color: #eeeeee;">Year</th> - <th style="background-color: #eeeeee; text-align: right;">Max <br>LRS<a href="http://genenetwork.org//glossary.html#L" target="_blank"><sup style="color:#f00"> ?</sup></a></th> - <th style="background-color: #eeeeee;">Max LRS Location</th> - <th style="background-color: #eeeeee; text-align: right;">Additive<br>Effect<a href="http://genenetwork.org//glossary.html#A" target="_blank"><sup style="color:#f00"> ?</sup></a></th> + <th data-export="Index" style="background-color: #eeeeee;">Index</th> + <th data-export="Species" style="background-color: #eeeeee;">Species</th> + <th data-export="Group" style="background-color: #eeeeee;">Group</th> + <th data-export="Record" style="background-color: #eeeeee;">Record</th> + <th data-export="Description" style="background-color: #eeeeee;">Description</th> + <th data-export="Authors" style="background-color: #eeeeee;">Authors</th> + <th data-export="Year" style="background-color: #eeeeee;">Year</th> + <th data-export="LRS" style="background-color: #eeeeee; text-align: right;">Max <br>LRS<a href="http://genenetwork.org//glossary.html#L" target="_blank"><sup style="color:#f00"> ?</sup></a></th> + <th data-export="LRS Location" style="background-color: #eeeeee;">Max LRS Location</th> + <th data-export="Additive Effect" style="background-color: #eeeeee; text-align: right;">Additive<br>Effect<a href="http://genenetwork.org//glossary.html#A" target="_blank"><sup style="color:#f00"> ?</sup></a></th> </tr> </thead> <tbody> {% for this_trait in trait_list %} <TR id="trait:{{ this_trait.name }}:{{ this_trait.dataset.name }}"> <td><INPUT TYPE="checkbox" NAME="searchResult" class="checkbox trait_checkbox" style="transform: scale(1.5);" VALUE="{{ data_hmac('{}:{}'.format(this_trait.name, this_trait.dataset.name)) }}"></td> - <td>{{ loop.index }}</td> - <td>{{ this_trait.dataset.group.species }}</td> - <td>{{ this_trait.dataset.group.name }}</td> - <td><a href="{{ url_for('show_trait_page', trait_id = this_trait.name, dataset = this_trait.dataset.name)}}">{{ this_trait.name }}</a></td> - <td>{{ this_trait.description_display }}</td> - <td>{{ this_trait.authors }}</td> - <td data-order="{{ this_trait.pubmed_text }}"><a href="{{ this_trait.pubmed_link }}">{{ this_trait.pubmed_text }}</a></td> - <td align="right">{% if this_trait.LRS_score_repr != "N/A" %}{{ '%0.1f' % this_trait.LRS_score_repr|float }}{% else %}N/A{% endif %}</td> - <td align="right">{{ this_trait.LRS_location_repr }}</td> - <td align="right">{% if this_trait.additive != "" %}{{ this_trait.additive }}{% else %}N/A{% endif %}</td> + <td data-export="{{ loop.index }}">{{ loop.index }}</td> + <td data-export="{{ this_trait.dataset.group.species }}">{{ this_trait.dataset.group.species }}</td> + <td data-export="{{ this_trait.dataset.group.name }}">{{ this_trait.dataset.group.name }}</td> + <td data-export="{{ this_trait.name }}"><a href="{{ url_for('show_trait_page', trait_id = this_trait.name, dataset = this_trait.dataset.name)}}">{{ this_trait.name }}</a></td> + <td data-export="{{ this_trait.description_display }}">{{ this_trait.description_display }}</td> + <td data-export="{{ this_trait.authors }}">{{ this_trait.authors }}</td> + <td data-export="{{ this_trait.pubmed_text }}" data-order="{{ this_trait.pubmed_text }}"><a href="{{ this_trait.pubmed_link }}">{{ this_trait.pubmed_text }}</a></td> + <td data-export="{% if this_trait.LRS_score_repr != "N/A" %}{{ '%0.1f' % this_trait.LRS_score_repr|float }}{% else %}N/A{% endif %}" align="right">{% if this_trait.LRS_score_repr != "N/A" %}{{ '%0.1f' % this_trait.LRS_score_repr|float }}{% else %}N/A{% endif %}</td> + <td data-export="{{ this_trait.LRS_location_repr }}" align="right">{{ this_trait.LRS_location_repr }}</td> + <td data-export="{% if this_trait.additive != "" %}{{ this_trait.additive }}{% else %}N/A{% endif %}" align="right">{% if this_trait.additive != "" %}{{ this_trait.additive }}{% else %}N/A{% endif %}</td> </TR> {% endfor %} </tbody> @@ -87,9 +92,6 @@ <script language="javascript" type="text/javascript" src="/static/new/javascript/search_results.js"></script> <script language="javascript" type="text/javascript" src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script> - <script language="javascript" type="text/javascript" src="https://cdn.datatables.net/buttons/1.0.0/js/dataTables.buttons.min.js"></script> - <script language="javascript" type="text/javascript" src="https://cdn.datatables.net/buttons/1.0.0/js/buttons.html5.min.js"></script> - <script language="javascript" type="text/javascript" src="https://cdn.datatables.net/buttons/1.0.0/js/buttons.bootstrap.min.js"></script> <script language="javascript" type="text/javascript" src="/static/new/js_external/jszip.min.js"></script> <script language="javascript" type="text/javascript" src="/static/new/packages/DataTables/js/dataTables.naturalSort.js"></script> <script language="javascript" type="text/javascript" src="/static/new/packages/DataTables/extensions/dataTables.colReorder.js"></script> @@ -98,40 +100,11 @@ <script language="javascript" type="text/javascript" src="/static/packages/TableTools/media/js/TableTools.min.js"></script> <script type="text/javascript" charset="utf-8"> - function getValue(x) { - if (x.indexOf('input') >= 0) { - if ($(x).val() == 'x') { - return 0; - } - else { - return parseFloat($(x).val()); - } - } - else if (isNaN(x)) { - return x; - } - return parseFloat(x); - } - - jQuery.fn.dataTableExt.oSort['cust-txt-asc'] = function (a, b) { - var x = getValue(a); - var y = getValue(b); - - if (x == 'N/A' || x == '') { - return 1; - } - else if (y == 'N/A' || y == '') { - return -1; - } - else { - return ((x < y) ? -1 : ((x > y) ? 1 : 0)); - } - }; - - jQuery.fn.dataTableExt.oSort['cust-txt-desc'] = function (a, b) { - var x = getValue(a); - var y = getValue(b); - return ((x < y) ? 1 : ((x > y) ? -1 : 0)); + $.fn.dataTable.ext.order['dom-checkbox'] = function ( settings, col ) + { + return this.api().column( col, {order:'index'} ).nodes().map( function ( td, i ) { + return $('input', td).prop('checked') ? '1' : '0'; + } ); }; $(document).ready( function () { @@ -145,19 +118,8 @@ console.time("Creating table"); $('#trait_table').DataTable( { "paging": false, - "buttons": [ - { - extend: 'csvHtml5', - text: 'Download CSV', - title: 'search_results', - fieldBoundary: '"', - exportOptions: { - columns: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] - } - } - ], "columns": [ - { "type": "natural" }, + { "orderDataType": "dom-checkbox" }, { "type": "natural" }, { "type": "natural" }, { "type": "natural" }, @@ -169,8 +131,14 @@ { "type": "natural", "width": "12%"}, { "type": "natural" } ], + "columnDefs": [ + { + "targets": 0, + "orderDataType": "dom-checkbox" + } + ], "order": [[1, "asc" ]], - "sDom": "Btir", + "sDom": "tir", "autoWidth": false, "bDeferRender": true, "scrollY": "800px", diff --git a/wqflask/wqflask/templates/index_page_orig.html b/wqflask/wqflask/templates/index_page_orig.html index 73d3e718..1694eae5 100755 --- a/wqflask/wqflask/templates/index_page_orig.html +++ b/wqflask/wqflask/templates/index_page_orig.html @@ -1,5 +1,10 @@ {% extends "base.html" %} {% block title %}GeneNetwork{% endblock %} +{% block css %} +<style TYPE="text/css"> + p.interact { display: none; } +</style> +{% endblock %} {% block content %} <!-- Start of body --> @@ -166,8 +171,17 @@ </ul> </section> </div> + <div style="padding-left:120px" class="col-xs-4" style="width: 600px !important;"> - <!-- + <section id="news-section"> + <div class="page-header"> + <h1>News</h1> + </div> + <div id="tweets"></div> + <div align="right"> + <a href="https://twitter.com/GeneNetwork2">more news items...</a> + </div> + <!-- <section id="tour-info"> <div class="page-header"> <h1>Tour and more info</h1> @@ -194,34 +208,37 @@ </section> --> + </section> <section id="websites"> <div class="page-header"> - <h1>Affiliates and mirrors</h1> + <h2>Links</h2> </div> - <h3>Websites affiliated with GeneNetwork</h3> + <h3>GeneNetwork v2:</h3> + <ul> + <li><a href="http://gn2.genenetwork.org/">Main website</a> at UTHSC</li> + <li><a href="http://test-gn2.genenetwork.org/">Testing website</a> at UTHSC</li> + </ul> + <h3>GeneNetwork v1:</h3> <ul> + <li><a href="http://www.genenetwork.org/">Main website</a> at UTHSC</li> + <li><a href="http://genenetwork.helmholtz-hzi.de/">Website</a> at the HZI (Germany)</li> + <li><a href="http://ec2.genenetwork.org/">Amazon + Cloud (EC2)</a></li> + </ul> + <h3>Affiliates</h3> + <ul> <li><a href="http://ucscbrowser.genenetwork.org/">Genome browser</a> at UTHSC</li> <li><a href="http://galaxy.genenetwork.org/">Galaxy</a> at UTHSC</li> - <li>GeneNetwork 1 at <a href="http://ec2.genenetwork.org/">Amazon - Cloud (EC2)</a></li> + </ul> - <li>GeneNetwork 1 Source Code at <a href="http://sourceforge.net/projects/genenetwork/">SourceForge</a></li> - <li>GeneNetwork 2 Source Code at <a href="https://github.com/genenetwork/genenetwork2">GitHub</a></li> - </ul> - <h3>GN1 Mirror and development sites</h3> - <ul> - <li><a href="http://www.genenetwork.org/">Main GN1 site at UTHSC</a> (main site)</li> - <li><a href="http://genenetwork.helmholtz-hzi.de/">Germany at the HZI</a></li> - <li><a href="http://gn2.genenetwork.org/">Memphis at the U of M</a></li> - </ul> - </section> + </section> <!--<section id="getting-started"> <div class="page-header"> @@ -282,4 +299,21 @@ } </script> + <script type="text/javascript" src="/twitter/js/twitterFetcher_min.js"></script> + + <script type="text/javascript"> + var configProfile = { + "profile": {"screenName": 'GeneNetwork2'}, + "domId": 'tweets', + "maxTweets": 5, + "enableLinks": true, + "showUser": false, + "showTime": true, + "showImages": false, + "lang": 'en' + }; + twitterFetcher.fetch(configProfile); + </script> + + {% endblock %} diff --git a/wqflask/wqflask/templates/links.html b/wqflask/wqflask/templates/links.html index 80d752e6..6ff7fc6c 100644 --- a/wqflask/wqflask/templates/links.html +++ b/wqflask/wqflask/templates/links.html @@ -1,5 +1,5 @@ {% extends "base.html" %} -{% block title %}Forgot Password{% endblock %} +{% block title %}Links{% endblock %} {% block content %} <Table width= "100%" cellSpacing=0 cellPadding=5><TR> diff --git a/wqflask/wqflask/templates/loading.html b/wqflask/wqflask/templates/loading.html new file mode 100644 index 00000000..cede0e86 --- /dev/null +++ b/wqflask/wqflask/templates/loading.html @@ -0,0 +1,26 @@ +<title>Loading Mapping Results</title> +<link REL="stylesheet" TYPE="text/css" href="/static/packages/bootstrap/css/bootstrap.css" /> +<link REL="stylesheet" TYPE="text/css" href="/static/packages/bootstrap/css/non-responsive.css" /> +<link REL="stylesheet" TYPE="text/css" href="/static/packages/bootstrap/css/docs.css" /> +<link rel="stylesheet" type="text/css" href="/static/packages/colorbox/example4/colorbox.css" /> +<link rel="stylesheet" type="text/css" href="/static/new/css/main.css" /> +<form method="post" action="/marker_regression" name="loading_form" id="loading_form" class="form-horizontal"> + {% for key, value in start_vars.iteritems() %} + <input type="hidden" name="{{ key }}" value="{{ value }}"> + {% endfor %} + <div class="container"> + <div class="row"> + <div style="margin-left: 46%; margin-right: 50%; min-height: 100vh; display: flex; align-items: center;"> + <h1>Loading Mapping Results...</h1> + </div> + <div class="progress center-block" style="margin-left: 25%; margin-right: 25%; position: absolute; height:50px; width:50%; top:50%;"> + <div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100" style="width:100%;"></div> + </div> + </div> + </div> +</form> +<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> +<script src="/static/packages/bootstrap/js/bootstrap.min.js"></script> +<script type="text/javascript"> +$("#loading_form").submit(); +</script>
\ No newline at end of file diff --git a/wqflask/wqflask/templates/marker_regression_gn1.html b/wqflask/wqflask/templates/marker_regression_gn1.html index 7454b650..31b8c595 100644 --- a/wqflask/wqflask/templates/marker_regression_gn1.html +++ b/wqflask/wqflask/templates/marker_regression_gn1.html @@ -14,6 +14,9 @@ <input type="hidden" name="temp_uuid" value="{{ temp_uuid }}"> <input type="hidden" name="trait_id" value="{{ this_trait.name }}"> <input type="hidden" name="dataset" value="{{ dataset.name }}"> + {% if mapping_method == "reaper" %} + <input type="hidden" name="genofile" value="{{ dataset.group.genofile }}"> + {% endif %} <input type="hidden" name="method" value="{{ mapping_method }}"> {% for sample in samples %} <input type="hidden" name="value:{{ sample }}" value="{{ vals[loop.index - 1] }}"> @@ -29,7 +32,7 @@ <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 }}"> - + <div class="container"> <div class="col-xs-5"> <h2>Map Viewer: Whole Genome</h2><br> @@ -68,7 +71,7 @@ <input type="radio" name="LRSCheck" value="LRS" {% if LRS_LOD == "LRS" %}checked{% endif %}>LRS </label> <label class="radio-inline"> - <input type="radio" name="LRSCheck" value="LOD" {% if LRS_LOD == "LOD" %}checked{% endif %}>LOD + <input type="radio" name="LRSCheck" value="{% if LRS_LOD == "-log(p)" %}-log(p){% else %}LOD{% endif %}" {% if LRS_LOD == "LOD" or LRS_LOD == "-log(p)" %}checked{% endif %}>{% if LRS_LOD == "-log(p)" %}-log(p){% else %}LOD{% endif %} </label> <a href="http://genenetwork.org/glossary.html#LOD" target="_blank"> <sup style="color:#f00"> ?</sup> @@ -78,7 +81,7 @@ <tr> <td></td> <td style="padding: 5px;"> - <input type="text" name="lrsMax" value="{{ '%0.1f' | format(lrsMax|float) }}" size="3"> <span style="font-size: 12px;">units on the y-axis (0 for default)</span> + <input type="text" name="lrsMax" value="{{ '%0.1f' | format(lrsMax|float) }}" size="3"> <span style="font-size: 12px;">units on the y-axis (0 for default)</span> </td> </tr> <tr> @@ -91,14 +94,14 @@ </div> <div class="col-xs-4" style="padding: 0px;"> {% if (mapping_method == "reaper" or mapping_method == "rqtl_geno") and nperm > 0 %} - <input type="checkbox" name="permCheck" class="checkbox" style="display: inline; margin-top: 0px;" {% if permChecked|upper == "ON" %}value="ON" checked{% endif %}> <span style="font-size: 12px;">Permutation Test + <input type="checkbox" name="permCheck" class="checkbox" style="display: inline; margin-top: 0px;" {% if permChecked|upper == "ON" %}value="ON" checked{% endif %}> <span style="font-size: 12px;">Permutation Test <a href="http://genenetwork.org/glossary.html#Permutation" target="_blank"> <sup style="color:#f00"> ?</sup> </a> <br> {% endif %} {% if mapping_method == "reaper" and nboot > 0 %} - <input type="checkbox" name="bootCheck" class="checkbox" style="display: inline; margin-top: 0px;" {% if bootChecked|upper == "ON" %}value="ON" checked{% endif %}> <span style="font-size: 12px;">Bootstrap Test + <input type="checkbox" name="bootCheck" class="checkbox" style="display: inline; margin-top: 0px;" {% if bootChecked|upper == "ON" %}value="ON" checked{% endif %}> <span style="font-size: 12px;">Bootstrap Test <a href="http://genenetwork.org/glossary.html#bootstrap" target="_blank"> <sup style="color:#f00"> ?</sup> </a> @@ -118,7 +121,7 @@ <span style="color:red;">*</span> <br> <input type="checkbox" name="showGenes" class="checkbox" style="display: inline; margin-top: 0px;" {% if geneChecked|upper == "ON" %}value="ON" checked{% endif %}> <span style="font-size: 12px;">Gene Track </span> <span style="color:red;">*</span><br> - {% if plotScale != "morgan" %} + {% if plotScale != "morgan" and mapping_method != "gemma" %} <input type="checkbox" name="haplotypeAnalystCheck" class="checkbox" style="display: inline; margin-top: 0px;" {% if haplotypeAnalystChecked|upper == "ON" %}value="ON" checked{% endif %}> <span style="font-size: 12px;">Haplotype Analyst </span> <span style="color:red;">*</span><br> {% endif %} <input type="checkbox" name="viewLegend" class="checkbox" style="display: inline; margin-top: 0px;" {% if legendChecked|upper == "ON" %}value="ON" checked{% endif %}> <span style="font-size: 12px;">Legend </span> @@ -128,7 +131,7 @@ </div> </div> </div> - + <div class="tabbable" style="margin: 10px;"> <ul class="nav nav-tabs"> <li id="gn1_map_tab"> @@ -160,8 +163,23 @@ </div> {% if mapping_method != "gemma" %} <div class="tab-pane {% if mapping_method == "gemma" %}active{% endif %}" id="vector_map"> - <div id="chart_container"> - <div class="qtlcharts" id="topchart"></div> + <div id="chart_container"> + <ul class="nav nav-tabs"> + <li id="return_to_full_view" class="btn btn-default buttons-html5" style="display:none"> + Return to full view + </li> + <li id="open_bd" class="btn btn-default buttons-html5" style="display:none"> + Open BioDalliance view + </li> + <li id="close_bd" class="btn btn-default buttons-html5" style="display:none"> + Return to vector map + </li> + </ul> + + <div class="qtlcharts" id="topchart"></div> + + <div id="bd_container" class="qtlcharts"> + </div> </div> </div> {% endif %} @@ -170,10 +188,10 @@ </form> {% if selectedChr == -1 %} - <div style="width:{% if 'additive' in trimmed_markers[0] %}50%{% else %}35%{% endif %};"> + <div style="width:{% if 'additive' in trimmed_markers[0] %}40%{% else %}30%{% endif %};"> <h2>Results</h2> - <div id="table_container" style="background-color: #eeeeee; border: 1px solid black;"> - <table id="qtl_results" class="table table-hover table-striped"> + <div id="table_container"> + <table id="qtl_results" class="table table-hover table-striped nowrap"> <thead> <tr> <th></th> @@ -189,7 +207,7 @@ {% if 'additive' in trimmed_markers[0] %} <th>Add Eff</th> {% endif %} - {% if 'dominance' in trimmed_markers[0] %} + {% if 'dominance' in trimmed_markers[0] and dataset.group.genetic_type != "riset" %} <th>Dom Eff</th> {% endif %} </tr> @@ -197,33 +215,33 @@ <tbody> {% for marker in trimmed_markers %} <tr> - <td> + <td align="center" style="padding-right: 0px;"> <input type="checkbox" name="selectCheck" class="checkbox edit_sample_checkbox" value="{{ marker.name }}" checked="checked"> </td> <td align="right">{{ loop.index }}</td> <td>{{ marker.name }}</td> - {% if LRS_LOD == "LOD" %} + {% if LRS_LOD == "LOD" or LRS_LOD == "-log(p)" %} {% if 'lod_score' in marker %} - <td>{{ '%0.2f' | format(marker.lod_score|float) }}</td> + <td align="right">{{ '%0.2f' | format(marker.lod_score|float) }}</td> {% else %} - <td>{{ '%0.2f' | format(marker.lrs_value|float / 4.16) }}</td> + <td align="right">{{ '%0.2f' | format(marker.lrs_value|float / 4.16) }}</td> {% endif %} {% else %} {% if 'lod_score' in marker %} - <td>{{ '%0.2f' | format(marker.lod_score|float * 4.16) }}</td> + <td align="right">{{ '%0.2f' | format(marker.lod_score|float * 4.16) }}</td> {% else %} - <td>{{ '%0.2f' | format(marker.lrs_value|float) }}</td> + <td align="right">{{ '%0.2f' | format(marker.lrs_value|float) }}</td> {% endif %} {% endif %} - <td>{{marker.chr}}</td> - <td>{{ '%0.6f' | format(marker.Mb|float) }}</td> + <td align="right">{{marker.chr}}</td> + <td align="right">{{ '%0.6f' | format(marker.Mb|float) }}</td> {% if 'additive' in marker %} - <td>{{ '%0.3f' | format(marker.additive|float) }}</td> + <td align="right">{{ '%0.3f' | format(marker.additive|float) }}</td> {% endif %} - {% if 'dominance' in marker %} - <td>{{ '%0.2f' | format(marker.dominance|float) }}</td> + {% if 'dominance' in marker and dataset.group.genetic_type != "riset" %} + <td align="right">{{ '%0.2f' | format(marker.dominance|float) }}</td> {% endif %} </tr> {% endfor %} @@ -234,8 +252,8 @@ {% else %} <div> <h2>Interval Analyst</h2> - <div id="table_container" style="background-color: #eeeeee; border: 1px solid black;"> - <table id="interval_analyst" class="table table-hover table-striped"> + <div id="table_container"> + <table id="interval_analyst" class="table table-hover table-striped nowrap"> <thead> <tr> {% for header in gene_table_header %} @@ -262,7 +280,37 @@ {% endblock %} -{% block js %} +{% block js %} + + <script> + /* This section checks for paths to JS libraries by + checking the headers */ + list = [ + /* check for static path */ + "/static/new/javascript/biodalliance.js", + "/static/new/js_external/underscore-min.js", + /* check for dalliance JS (see ./etc/default_settings.py) */ + "/dalliance/build/dalliance-all.js", + /* D3 path (FIXME) */ + "http://d3js.org/d3.v3.min.js", + /* datatables path (FIXME) */ + "https://cdn.datatables.net/buttons/1.0.0/js/dataTables.buttons.min.js" + ]; + for (var i = 0; i < list.length; i++) { + url = list[i]; + $.ajax({ + type: 'HEAD', + url: url, + success: function() { + // page exists + }, + error: function() { + // page does not exist + console.log("Failed to load "+this.url); + alert("Failed to load Javascript for "+this.url); + } + })}; + </script> <script type="text/javascript" src="http://d3js.org/d3.v3.min.js"></script> <script type="text/javascript" src="/static/new/js_external/underscore-min.js"></script> @@ -271,56 +319,68 @@ <script language="javascript" type="text/javascript" src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script> <script language="javascript" type="text/javascript" src="https://cdn.datatables.net/buttons/1.0.0/js/dataTables.buttons.min.js"></script> - <script language="javascript" type="text/javascript" src="https://cdn.datatables.net/buttons/1.0.0/js/buttons.html5.min.js"></script> - <script language="javascript" type="text/javascript" src="https://cdn.datatables.net/buttons/1.0.0/js/buttons.bootstrap.min.js"></script> <script language="javascript" type="text/javascript" src="/static/new/packages/DataTables/js/dataTables.scientific.js"></script> <script language="javascript" type="text/javascript" src="/static/new/packages/DataTables/js/dataTables.naturalSort.js"></script> - <script language="javascript" type="text/javascript" src="/static/new/packages/DataTables/extensions/dataTables.colResize.js"></script> - <script language="javascript" type="text/javascript" src="/static/new/packages/DataTables/extensions/dataTables.colReorder.js"></script> - <script> - js_data = {{ js_data | safe }} - </script> {% if mapping_method != "gemma" %} <script language="javascript" type="text/javascript" src="/static/new/javascript/panelutil.js"></script> - <script language="javascript" type="text/javascript" src="/static/new/javascript/chr_lod_chart.js"></script> + <script language="javascript" type="text/javascript" src="/static/new/javascript/chr_lod_chart.js"></script> <script language="javascript" type="text/javascript" src="/static/new/javascript/lod_chart.js"></script> <script language="javascript" type="text/javascript" src="/static/new/javascript/create_lodchart.js"></script> + + <script language="javascript" type="text/javascript" src="/dalliance/build/dalliance-all.js"></script> + <script language="javascript" type="text/javascript" src="/static/new/javascript/biodalliance.js"></script> {% endif %} - <script type="text/javascript" charset="utf-8"> - $(document).ready( function () { + <script> + createTable = function() { console.time("Creating table"); $('#qtl_results').DataTable( { + {% if mapping_method != "reaper" %} "columns": [ - { "type": "natural", "width": "5%", "bSortable": false }, - { "type": "natural", "width": "6%" }, - { "type": "natural" }, - { "type": "natural" }, - { "type": "natural" }, - { "type": "natural" }, - { "type": "natural" }, - { "type": "natural" } - ], - "order": [[1, "asc" ]], - "buttons": [ - { - extend: 'csvHtml5', - text: 'Download CSV', - title: 'search_results', - fieldBoundary: '"', - exportOptions: { - columns: [1, 2, 3, 4, 5, 6, 7, 8] - } - } + { "type": "natural", "width": "5%" }, + { "type": "natural", "width": "8%" }, + { "type": "natural", "width": "20%" }, + { "type": "natural", "width": "8%" }, + { "type": "natural", "width": "8%" }, + { "type": "natural", "width": "15%" } + ], + {% elif dataset.group.genetic_type == "riset" %} + "columns": [ + { "type": "natural", "width": "5%" }, + { "type": "natural", "width": "8%" }, + { "type": "natural", "width": "20%" }, + { "type": "natural", "width": "8%" }, + { "type": "natural", "width": "8%" }, + { "type": "natural", "width": "15%" }, + { "type": "natural", "width": "8%" } ], - "sDom": "RZBtir", + {% else %} + "columns": [ + { "type": "natural", "width": "5%" }, + { "type": "natural", "width": "8%" }, + { "type": "natural", "width": "20%" }, + { "type": "natural", "width": "8%" }, + { "type": "natural", "width": "8%" }, + { "type": "natural", "width": "15%" }, + { "type": "natural", "width": "8%" }, + { "type": "natural", "width": "8%" } + ], + {% endif %} + "columnDefs": [ { + "targets": 0, + "orderable": false + } ], + "order": [[1, "asc" ]], + "sDom": "RZtir", "iDisplayLength": -1, - "bDeferRender": true, + "autoWidth": false, + "deferRender": true, "bSortClasses": false, - "scrollY": true, + "scrollY": "600px", "scrollCollapse": false, + "scroller": true, "paging": false } ); @@ -330,18 +390,7 @@ "sortable": false }], "order": [[3, "asc" ]], - "buttons": [ - { - extend: 'csvHtml5', - text: 'Download CSV', - title: 'search_results', - fieldBoundary: '"', - exportOptions: { - columns: [1, 2, 3, 4, 5, 6, 7, 8, 9] - } - } - ], - "sDom": "RZBtir", + "sDom": "RZtir", "iDisplayLength": -1, "bDeferRender": true, "bSortClasses": false, @@ -349,15 +398,145 @@ "scrollCollapse": false, "paging": false } ); + }; + + filename = "{{json_filename}}"; + js_data = null; + $.ajax("/generated_text/{{json_filename}}", + {success: + function(data) { + js_data = data; + create_lod_chart(); + createTable(); + } + }); + + BD.putSource({name: 'Genome', + twoBitURI: 'http://www.biodalliance.org/datasets/GRCm38/mm10.2bit', + desc: 'Mouse reference genome build GRCm38', + tier_type: 'sequence', + provides_entrypoints: true + }); + BD.putSource({name: 'Genotype', + controlURI: "{{gn_server_url}}/api_pre1/genotype/mouse/BXD.json", + URIBase: "{{gn_server_url}}/api_pre1/genotype/mouse/", + tier_type: 'rqtl-genotype', + vOffset: 8, + pinned: true, + transposed: true, + hideSubpixelGlyphs: true, + style: [ + { type: "default", + method: "U", + style: { glyph: "BOX", + LINE: "0.5", + FGCOLOR: "black", + BGCOLOR: "white", + BGITEM: "true", + HEIGHT: "2", + BUMP: "true", + }}, + { type: "default", + method: "B", + style: { glyph: "BOX", + LINE: "0.5", + FGCOLOR: "blue", + BGCOLOR: "blue", + BGITEM: "true", + HEIGHT: "2", + BUMP: "true", + }}, + { type: "default", + method: "H", + style: { glyph: "BOX", + LINE: "0.5", + FGCOLOR: "green", + BGCOLOR: "green", + BGITEM: "true", + HEIGHT: "2", + BUMP: "true", + }}, + { type: "default", + method: "D", + style: { glyph: "BOX", + LINE: "0.5", + FGCOLOR: "red", + BGCOLOR: "red", + BGITEM: "true", + HEIGHT: "2", + BUMP: "true", + }}, + ] + }); + BD.putSource({name: 'QTL', + tier_type: 'qtl', + uri: '/generated_text/{{csv_filename}}', + style: [{ + type: 'default', + style: { + glyph: "LINEPLOT", + AUTOMAX: "true", + MIN: 0, + MAX: 3, + HEIGHT: 200, + STEPS: 500, + COLOR1: "blue", + } + }], + }); + BD.putSource({name: 'SNP density', + jbURI: "{{gn_server_url}}/api_pre1/snp", + jbQuery: "", + refetchOnZoom: true, + style: [{ + type: 'default', + style: { + glyph: "HISTOGRAM", + MIN: 0, + MAX: 5000, + AUTOMAX: "true", + HEIGHT: 60, + STEPS: 100, + COLOR1: "red", + COLOR2: "red", + COLOR3: "red", + AXISCENTER: "true", + } + }] + }); + </script> + + <script type="text/javascript" charset="utf-8"> + $(document).ready( function () { + BD.putData({species: "{{ dataset.group.species }}" }); + $('#vector_map_tab').click(function(){ $('div#gn1_map_options').hide(); }); $('#gn1_map_tab').click(function(){ - $('div#gn1_map_options').show(); + $('#gn1_map_options').show(); + $('div#bd_container').hide(); }); + $('#close_bd').click(function() { + $('#open_bd').show(); + $('#close_bd').hide(); + + $('#bd_container').hide(); + $('#topchart').show(); + }); + + $('#open_bd').click(function() { + $('#close_bd').show(); + $('#open_bd').hide() + + $('#topchart').hide(); + $('#bd_container').show(); + + BD.openBrowser(); + }) }); chrView = function(this_chr, chr_mb_list) { @@ -376,9 +555,9 @@ return $('#marker_regression_form').submit(); }; - remap = function() { + remap = function() { $('input[name=selected_chr]').val($('select[name=chromosomes]').val()); - return $('#marker_regression_form').submit(); + return $('#marker_regression_form').submit(); }; export_perm_data = function() { @@ -394,4 +573,3 @@ </script> {% endblock %} - diff --git a/wqflask/wqflask/templates/policies.html b/wqflask/wqflask/templates/policies.html index aa5c453d..83b6b3c0 100644 --- a/wqflask/wqflask/templates/policies.html +++ b/wqflask/wqflask/templates/policies.html @@ -1,5 +1,5 @@ {% extends "base.html" %} -{% block title %}GeneNetwork{% endblock %} +{% block title %}Policies{% endblock %} {% block content %} <Table width= "100%" cellSpacing=0 cellPadding=5><TR> diff --git a/wqflask/wqflask/templates/reference.html b/wqflask/wqflask/templates/reference.html index 4ad97522..cc4408e1 100644 --- a/wqflask/wqflask/templates/reference.html +++ b/wqflask/wqflask/templates/reference.html @@ -1,5 +1,5 @@ {% extends "base.html" %} -{% block title %}GeneNetwork{% endblock %} +{% block title %}References{% endblock %} {% block content %} <TABLE cellSpacing=5 cellPadding=4 width="100%" border=0> diff --git a/wqflask/wqflask/templates/search_result_page.html b/wqflask/wqflask/templates/search_result_page.html index 523037f8..718b31d3 100644 --- a/wqflask/wqflask/templates/search_result_page.html +++ b/wqflask/wqflask/templates/search_result_page.html @@ -2,18 +2,15 @@ {% block title %}Search Results{% endblock %} {% block css %} <link rel="stylesheet" type="text/css" href="/static/new/packages/DataTables/css/jquery.dataTables.css" /> - <link rel="stylesheet" type="text/css" href="//cdn.datatables.net/scroller/1.4.1/css/scroller.dataTables.min.css"> - <link rel="stylesheet" type="text/css" href="/static/new/packages/DataTables/extensions/dataTables.fixedHeader.css" > - <link rel="stylesheet" type="text/css" href="//cdn.datatables.net/fixedcolumns/3.0.4/css/dataTables.fixedColumns.css"> - <link rel="stylesheet" type="text/css" href="/static/new/packages/DataTables/extensions/buttons.bootstrap.css" /> + <link rel="stylesheet" type="text/css" href="/static/new/packages/DataTables/extensions/scroller.dataTables.min.css"> + <link rel="stylesheet" type="text/css" href="/static/new/packages/DataTables/extensions/buttons.dataTables.css"> {% endblock %} {% block content %} <!-- Start of body --> {{ header("Search Results", 'GeneNetwork found {}.'.format(numify(results|count, "record", "records"))) }} - <div class="container"> - + <div style="padding-left: 10px;"> <input type="hidden" name="uc_id" id="uc_id" value="{{ uc_id }}"> <!-- Need to customize text more for other types of searches --> @@ -41,12 +38,12 @@ {% elif word.key|lower == "position" %} with <u>target genes</u> on chromosome <strong>{% if word.search_term[0].split('chr')|length > 1 %}{{ word.search_term[0].split('chr')[1] }}{% elif word.search_term[0].split('CHR')|length > 1 %}{{ word.search_term[0].split('CHR')[1] }}{% else %}{{ word.search_term[0] }}{% endif %}</strong> between <strong>{{ word.search_term[1] }}</strong> and <strong>{{ word.search_term[2] }}</strong> Mb{% if loop.last %}.{% else %} and {% endif %} {% else %} - that match the term {{ word.search_term[0] }}. + that match the <u>TERM</u> <b>{{ word.search_term[0] }}</b>{% if loop.last %}.{% else %} and {% endif %} {% endif %} {% endfor %} </p> - <p>To study a record, click on its ID below. Check records below and click Add button to add to selection.</p> + <p>To study a record click on its ID below, and to view the whole description {% if dataset.type == "Publish" %}or list of authors {% endif %} hover over the table cell. Check records below and click Add button to add to selection.</p> <div> <br /> @@ -54,12 +51,17 @@ <button class="btn btn-default" id="deselect_all"><span class="glyphicon glyphicon-remove"></span> Deselect All</button> <button class="btn btn-default" id="invert"><span class="glyphicon glyphicon-resize-vertical"></span> Invert</button> <button class="btn btn-default" id="add" disabled><span class="glyphicon glyphicon-plus-sign"></span> Add</button> - <!--<button class="btn btn-default"><span class="glyphicon glyphicon-download"></span> Download Table</button>--> <button id="redraw" class="btn btn-default">Reset Columns</button> <input type="text" id="searchbox" class="form-control" style="width: 200px; display: inline;" placeholder="Search This Table For ..."> <input type="text" id="select_top" class="form-control" style="width: 200px; display: inline;" placeholder="Select Top ..."> <br /> <br /> + <form id="export_form" method="POST" action="/export_traits_csv"> + <input type="hidden" name="database_name" id="database_name" value="{{ dataset.fullname }}"> + <input type="hidden" name="export_data" id="export_data" value=""> + <button class="btn btn-default" id="export_traits">Download CSV</button> + </form> + <br /> <!-- Removing this until more options are added and work correctly {% if dataset.type == 'ProbeSet' %} @@ -75,73 +77,33 @@ {% endif %} --> - <div id="table_container" style="background-color: #eeeeee; border: 1px solid black;"> - <table class="table table-hover table-striped" id='trait_table' {% if dataset.type == 'Geno' %}width="400px"{% endif %} style="float: left;"> + <div id="table_container" style="width: {% if dataset.type == 'ProbeSet' %}1300{% elif dataset.type == 'Publish' %}1200{% elif dataset.type == 'Geno' %}500{% endif %}px;"> + <table class="table table-hover table-striped nowrap" id='trait_table' style="float: left;"> <thead> <tr> - <th style="background-color: #eeeeee;"></th> + <th></th> {% for header in header_fields %} {% if header == 'Max LRS' %} - <th style="background-color: #eeeeee; text-align: right;">Max<br>LRS</th> + <th data-export="Max LRS">Max LRS</th> {% elif header == 'Additive Effect' %} - <th style="background-color: #eeeeee; text-align: right;">Additive<br>Effect<a href="http://genenetwork.org//glossary.html#A" target="_blank"><sup style="color:#f00"> ?</sup></a></th> + <th data-export="Additive Effect">Additive <a href="http://genenetwork.org//glossary.html#A" target="_blank"><sup style="color:#f00"> ?</sup></a></th> {% else %} - <th style="background-color: #eeeeee;">{{header}}</th> + <th data-export="{{header}}">{{header}}</th> {% endif %} {% endfor %} </tr> </thead> - - <tbody> - {% for this_trait in trait_list %} - <TR id="trait:{{ this_trait.name }}:{{ this_trait.dataset.name }}"> - <TD><INPUT TYPE="checkbox" NAME="searchResult" class="checkbox trait_checkbox" style="transform: scale(1.5);" VALUE="{{ data_hmac('{}:{}'.format(this_trait.name, this_trait.dataset.name)) }}"> - </TD> - <TD align="right">{{ loop.index }}</TD> - <TD> - <a href="{{ url_for('show_trait_page', - trait_id = this_trait.name, - dataset = dataset.name - )}}"> - {{ this_trait.name }} - </a> - </TD> - {% if dataset.type == 'ProbeSet' %} - <TD>{{ this_trait.symbol }}</TD> - <TD>{{ this_trait.description_display }}</TD> - <TD>{{ this_trait.location_repr }}</TD> - <TD align="right">{{ '%0.3f' % this_trait.mean|float }}</TD> - <TD align="right">{{ '%0.3f' % this_trait.LRS_score_repr|float }}</TD> - <TD>{{ this_trait.LRS_location_repr }}</TD> - <TD align="right">{{ '%0.3f' % this_trait.additive|float }}</TD> - {% elif dataset.type == 'Publish' %} - <TD>{{ this_trait.description_display }}</TD> - <TD>{{ this_trait.authors }}</TD> - <TD data-sort="{{ this_trait.pubmed_text }}"> - <a href="{{ this_trait.pubmed_link }}"> - {{ this_trait.pubmed_text }} - </a> - </TD> - <TD>{{ '%0.3f' % this_trait.LRS_score_repr|float }}</TD> - <TD>{{ this_trait.LRS_location_repr }}</TD> - <TD>{{ '%0.3f' % this_trait.additive|float }}</TD> - {% elif dataset.type == 'Geno' %} - <TD>{{ this_trait.location_repr }}</TD> - {% endif %} - </TR> - {% endfor %} - </tbody> {% if trait_list|length > 20 %} <tfoot> <tr> - <th style="width: 30px;"></th> + <th></th> {% for header in header_fields %} {% if header == 'Max LRS' %} - <th style="text-align: right;">Max<br>LRS</th> + <th data-export="Max LRS">Max LRS</th> {% elif header == 'Additive Effect' %} - <th style="text-align: right;">Additive<br>Effect<a href="http://genenetwork.org//glossary.html#A" target="_blank"><sup style="color:#f00"> ?</sup></a></th> + <th data-export="Additive Effect">Additive Effect<a href="http://genenetwork.org//glossary.html#A" target="_blank"><sup style="color:#f00"> ?</sup></a></th> {% else %} - <th>{{header}}</th> + <th data-export="{{header}}">{{header}}</th> {% endif %} {% endfor %} </tr> @@ -159,57 +121,19 @@ {% endblock %} {% block js %} - <script type="text/javascript" src="/static/new/javascript/search_results.js"></script> + <script language="javascript" type="text/javascript" src="/static/new/javascript/search_results.js"></script> <script language="javascript" type="text/javascript" src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script> - <script language="javascript" type="text/javascript" src="https://cdn.datatables.net/buttons/1.0.0/js/dataTables.buttons.min.js"></script> - <script language="javascript" type="text/javascript" src="https://cdn.datatables.net/buttons/1.0.0/js/buttons.html5.min.js"></script> - <script language="javascript" type="text/javascript" src="https://cdn.datatables.net/buttons/1.0.0/js/buttons.bootstrap.min.js"></script> <script language="javascript" type="text/javascript" src="/static/new/js_external/jszip.min.js"></script> <script language="javascript" type="text/javascript" src="/static/new/packages/DataTables/js/dataTables.naturalSort.js"></script> - <script language="javascript" type="text/javascript" src="/static/new/packages/DataTables/extensions/dataTables.colResize.js"></script> - <script language="javascript" type="text/javascript" src="/static/new/packages/DataTables/extensions/dataTables.colReorder.js"></script> - <script language="javascript" type="text/javascript" src="/static/new/packages/DataTables/extensions/dataTables.fixedHeader.min.js"></script> + <script language="javascript" type="text/javascript" src="/static/new/packages/DataTables/extensions/dataTables.buttons.min.js"></script> + <script language="javascript" type="text/javascript" src="/static/new/packages/DataTables/extensions/buttons.colVis.min.js"></script> - <script type="text/javascript" charset="utf-8"> - function getValue(x) { - if (x.indexOf('input') >= 0) { - if ($(x).val() == 'x') { - return 0; - } - else { - return parseFloat($(x).val()); - } - } - else if (isNaN(x)) { - return x; - } - return parseFloat(x); - } - - - jQuery.fn.dataTableExt.oSort['cust-txt-asc'] = function (a, b) { - var x = getValue(a); - var y = getValue(b); - - if (x == 'N/A' || x == '') { - return 1; - } - else if (y == 'N/A' || y == '') { - return -1; - } - else { - return ((x < y) ? -1 : ((x > y) ? 1 : 0)); - } - }; - - jQuery.fn.dataTableExt.oSort['cust-txt-desc'] = function (a, b) { - var x = getValue(a); - var y = getValue(b); - return ((x < y) ? 1 : ((x > y) ? -1 : 0)); - }; - + <script type='text/javascript'> + var json_trait_list = {{ json_trait_list|safe }}; + </script> + <script type="text/javascript" charset="utf-8"> $(document).ready( function () { $('#trait_table tr').click(function(event) { @@ -218,104 +142,219 @@ } }); + function change_buttons() { + buttons = ["#add", "#remove"]; + num_checked = $('.trait_checkbox:checked').length; + if (num_checked === 0) { + for (_i = 0, _len = buttons.length; _i < _len; _i++) { + button = buttons[_i]; + $(button).prop("disabled", true); + } + } else { + for (_j = 0, _len2 = buttons.length; _j < _len2; _j++) { + button = buttons[_j]; + $(button).prop("disabled", false); + } + } + //}); + if ($(this).is(":checked")) { + if (!$(this).closest('tr').hasClass('selected')) { + $(this).closest('tr').addClass('selected') + } + } + else { + if ($(this).closest('tr').hasClass('selected')) { + $(this).closest('tr').removeClass('selected') + } + } + } + console.time("Creating table"); {% if dataset.type == 'ProbeSet' %} //ZS: Need to make sort by symbol, also need to make sure blank symbol fields at the bottom and symbols starting with numbers below letters $('#trait_table').DataTable( { + "drawCallback": function( settings ) { + $('#trait_table tr').click(function(event) { + if (event.target.type !== 'checkbox') { + $(':checkbox', this).trigger('click'); + } + }); + $('.trait_checkbox:checkbox').on("change", change_buttons); + }, + "createdRow": function ( row, data, index ) { + $('td', row).eq(0).attr('style', 'padding-right: 0px;'); + $('td', row).eq(0).attr('align', 'center'); + $('td', row).eq(1).attr('align', 'right'); + $('td', row).eq(1).attr('data-export', index+1); + $('td', row).eq(2).attr('data-export', $('td', row).eq(2).text()); + $('td', row).eq(3).attr('title', $('td', row).eq(3).text()); + $('td', row).eq(3).attr('data-export', $('td', row).eq(3).text()); + $('td', row).eq(4).attr('title', $('td', row).eq(4).text()); + $('td', row).eq(4).attr('data-export', $('td', row).eq(4).text()); + if ($('td', row).eq(4).text().length > 60) { + $('td', row).eq(4).text($('td', row).eq(4).text().substring(0, 60)); + $('td', row).eq(4).text($('td', row).eq(4).text() + '...') + } + $('td', row).eq(5).attr('data-export', $('td', row).eq(5).text()); + $('td', row).eq(6).attr('align', 'right'); + $('td', row).eq(6).attr('data-export', $('td', row).eq(6).text()); + $('td', row).eq(7).attr('align', 'right'); + $('td', row).eq(7).attr('data-export', $('td', row).eq(7).text()); + $('td', row).eq(8).attr('data-export', $('td', row).eq(8).text()); + $('td', row).eq(9).attr('align', 'right'); + $('td', row).eq(9).attr('data-export', $('td', row).eq(9).text()); + }, + "data": json_trait_list, "columns": [ - { "type": "natural" }, - { "type": "natural" }, - { "type": "natural" }, - { "type": "natural" }, - { "type": "natural", "width": "40%" }, - { "type": "natural", "width": "15%" }, - { "type": "natural" }, - { "type": "natural" }, - { "type": "natural", "width": "15%" }, - { "type": "natural" } + { "type": "natural", "width": "2%" }, + { "type": "natural", "width": "4%" }, + { "type": "natural", "width": "12%" }, + { "type": "natural", "width": "12%" }, + { "type": "natural", "width": "25%" }, + { "type": "natural", "width": "11%" }, + { "type": "natural", "width": "5%" }, + { "type": "natural", "width": "6%" }, + { "type": "natural", "width": "11%" }, + { "type": "natural", "width": "6%" } ], + "columnDefs": [ { + "targets": 0, + "orderable": false + } ], "order": [[1, "asc" ]], - "buttons": [ + buttons: [ { - extend: 'csvHtml5', - text: 'Download CSV', - title: 'search_results', - fieldBoundary: '"', - exportOptions: { - columns: [1, 2, 3, 4, 5, 6, 7, 8, 9] - } + extend: 'colvis', + text: 'Show or Hide Columns', + columns: ':not(:first-child)', + postfixButtons: [ 'colvisRestore' ] } ], - "sDom": "RZBtir", + "sDom": "BRZtir", "iDisplayLength": -1, - "bDeferRender": true, + "autoWidth": false, + "deferRender": true, "bSortClasses": false, - "scrollY": true, + "scrollY": "600px", "scrollCollapse": false, + "scroller": true, "paging": false } ); {% elif dataset.type == 'Publish' %} $('#trait_table').DataTable( { + "drawCallback": function( settings ) { + $('#trait_table tr').click(function(event) { + if (event.target.type !== 'checkbox') { + $(':checkbox', this).trigger('click'); + } + }); + $('.trait_checkbox:checkbox').on("change", change_buttons); + }, + "createdRow": function ( row, data, index ) { + $('td', row).eq(1).attr('align', 'right'); + $('td', row).eq(1).attr('data-export', index+1); + $('td', row).eq(2).attr('data-export', $('td', row).eq(2).text()); + $('td', row).eq(3).attr('title', $('td', row).eq(3).text()); + $('td', row).eq(3).attr('data-export', $('td', row).eq(3).text()); + if ($('td', row).eq(3).text().length > 50) { + $('td', row).eq(3).text($('td', row).eq(3).text().substring(0, 50)); + $('td', row).eq(3).text($('td', row).eq(3).text() + '...') + } + $('td', row).eq(4).attr('title', $('td', row).eq(4).text()); + $('td', row).eq(4).attr('data-export', $('td', row).eq(4).text()); + if ($('td', row).eq(4).text().length > 50) { + $('td', row).eq(4).text($('td', row).eq(4).text().substring(0, 50)); + $('td', row).eq(4).text($('td', row).eq(4).text() + '...') + } + $('td', row).eq(4).text($('td', row).eq(4).text().substring(0, 30)); + //$('td', row).eq(5).attr('align', 'right'); + $('td', row).eq(5).attr('data-export', $('td', row).eq(5).text()); + $('td', row).eq(6).attr('align', 'right'); + $('td', row).eq(6).attr('data-export', $('td', row).eq(6).text()); + $('td', row).eq(7).attr('data-export', $('td', row).eq(7).text()); + $('td', row).eq(8).attr('align', 'right'); + $('td', row).eq(8).attr('data-export', $('td', row).eq(8).text()); + }, + "data": json_trait_list, "columns": [ - { "type": "natural" }, - { "type": "natural" }, - { "type": "natural" }, - { "type": "natural" }, - { "type": "natural" }, - { "type": "natural" }, - { "type": "natural" }, - { "type": "natural", "width": "15%"}, - { "type": "natural" } + { "type": "natural", "width": "2%" }, + { "type": "natural", "width": "5%" }, + { "type": "natural", "width": "6%" }, + { "type": "natural", "width": "30%" }, + { "type": "natural", "width": "25%" }, + { "type": "natural", "width": "5%" }, + { "type": "natural", "width": "6%" }, + { "type": "natural", "width": "10%" }, + { "type": "natural", "width": "9%" } ], + "columnDefs": [ { + "targets": 0, + "orderable": false + } ], "order": [[1, "asc" ]], - "buttons": [ + buttons: [ { - extend: 'csvHtml5', - text: 'Download CSV', - title: 'search_results', - fieldBoundary: '"', - exportOptions: { - columns: [1, 2, 3, 4, 5, 6, 7] - } + extend: 'colvis', + text: 'Show or Hide Columns', + columns: ':not(:first-child)', + postfixButtons: [ 'colvisRestore' ] } ], - "sDom": "RZBtir", + "sDom": "BRZtir", "iDisplayLength": -1, "autoWidth": false, - "bDeferRender": true, + "deferRender": true, "bSortClasses": false, - "scrollY": "700px", - "scrollCollapse": false, + "scrollY": "600px", + "scrollCollapse": true, + "scroller": true, "paging": false } ); {% elif dataset.type == 'Geno' %} $('#trait_table').DataTable( { + "drawCallback": function( settings ) { + $('#trait_table tr').click(function(event) { + if (event.target.type !== 'checkbox') { + $(':checkbox', this).trigger('click'); + } + }); + $('.trait_checkbox:checkbox').on("change", change_buttons); + }, + "createdRow": function ( row, data, index ) { + $('td', row).eq(1).attr('align', 'right'); + $('td', row).eq(1).attr('data-export', index+1); + $('td', row).eq(2).attr('data-export', $('td', row).eq(2).text()); + $('td', row).eq(3).attr('data-export', $('td', row).eq(3).text()); + }, + "data": json_trait_list, "columns": [ - { "type": "natural" }, - { "type": "natural" }, - { "type": "natural" }, + { "type": "natural", "width": "8%" }, + { "type": "natural", "width": "12%" }, + { "type": "natural", "width": "40%" }, { "type": "natural", "width": "40%"} ], + "columnDefs": [ { + "targets": 0, + "orderable": false + } ], "order": [[1, "asc" ]], - "buttons": [ + buttons: [ { - extend: 'csvHtml5', - text: 'Download CSV', - title: 'search_results', - fieldBoundary: '"', - exportOptions: { - columns: [1, 2, 3] - } + extend: 'colvis', + text: 'Show or Hide Columns', + columns: ':not(:first-child)', + postfixButtons: [ 'colvisRestore' ] } ], - "sDom": "RZBtir", + "sDom": "BRZtir", "iDisplayLength": -1, - "autoWidth": true, - "bDeferRender": true, + "autoWidth": false, + "deferRender": true, "bSortClasses": false, - "scrollY": "700px", - "scrollCollapse": false, + "scrollY": "600px", + "scrollCollapse": true, + "scroller": true, "paging": false } ); {% endif %} diff --git a/wqflask/wqflask/templates/show_trait.html b/wqflask/wqflask/templates/show_trait.html index e5500a7e..d9566df1 100644 --- a/wqflask/wqflask/templates/show_trait.html +++ b/wqflask/wqflask/templates/show_trait.html @@ -39,6 +39,7 @@ </div> <input type="hidden" name="temp_uuid" id="temp_uuid" value="{{ temp_uuid }}"> + <input type="hidden" name="genofile" value=""> <div class="container"> <div class="panel-group" id="accordion"> @@ -225,7 +226,12 @@ {% for attribute in sample_groups[0].attributes %} { "type": "natural" }{% if loop.index < sample_groups[0].attributes|length %},{% endif %} {% endfor %} - ], + ], + "columnDefs": [ { + "targets": 0, + "orderable": false + } ], + "order": [[1, "asc" ]], "sDom": "RZtr", "iDisplayLength": -1, "autoWidth": false, @@ -244,14 +250,19 @@ $('#samples_primary, #samples_other').DataTable( { "columns": [ - { "bSortable": false }, - { "type": "natural" }, - null, - { "type": "cust-txt" }{% if sample_groups[0].attributes|length > 0 %},{% endif %} + { "bSortable": false, "width": "8%" }, + { "type": "natural", "width": "15%" }, + { "type": "natural", "width": "25%" }, + { "type": "cust-txt", "width": "25%" }{% if sample_groups[0].attributes|length > 0 %},{% endif %} {% for attribute in sample_groups[0].attributes %} { "type": "natural" }{% if loop.index < sample_groups[0].attributes|length %},{% endif %} {% endfor %} ], + "columnDefs": [ { + "targets": 0, + "orderable": false + } ], + "order": [[1, "asc" ]], "sDom": "RZtr", "iDisplayLength": -1, "autoWidth": false, diff --git a/wqflask/wqflask/templates/show_trait_details.html b/wqflask/wqflask/templates/show_trait_details.html index d5fb0cf2..547c3c27 100644 --- a/wqflask/wqflask/templates/show_trait_details.html +++ b/wqflask/wqflask/templates/show_trait_details.html @@ -1,17 +1,19 @@ <table class="table"> <tr> - <td>Species</td> - <td>{{ this_trait.dataset.group.species }}</td> - </tr> - <tr> - <td>Group</td> - <td>{{ this_trait.dataset.group.name }}</td> + <td>Species and Group</td> + <td>{{ this_trait.dataset.group.species }}, {{ this_trait.dataset.group.name }}</td> </tr> <tr> <td>Tissue</td> <td>{{ this_trait.dataset.tissue }}</td> </tr> {% if this_trait.dataset.type == 'ProbeSet' %} + {% if this_trait.symbol != None %} + <tr> + <td>Gene Symbol</td> + <td>{{ this_trait.symbol }}</td> + </tr> + {% endif %} <tr> <td>Aliases</td> <td>{{ this_trait.alias_fmt|replace(",",";") }}</td> @@ -51,7 +53,7 @@ <td> {% if this_trait.geneid != None %} <a href="http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?db=gene&cmd=Retrieve&dopt=Graphics&list_uids={{ this_trait.geneid }}" title="Info from NCBI Entrez Gene"> - Gene + NCBI </a> {% endif %} @@ -61,12 +63,6 @@ </a> {% endif %} - {% if this_trait.genbankid != None %} - <a href="http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?db=Nucleotide&cmd=search&doptcmdl=DocSum&term={{ this_trait.genbankid }}" title="Find the original GenBank sequence used to design the probes"> - GenBank - </a> - - {% endif %} {% if this_trait.symbol != None %} <a href="http://www.genotation.org/Getd2g.pl?gene_list={{ this_trait.symbol }}" title="Related descriptive, genomic, clinical, functional and drug-therapy information"> Genotation @@ -80,49 +76,35 @@ <div style="margin-bottom:15px;" class="btn-toolbar"> <div class="btn-group"> <a href="#redirect"> - <button type="button" id="add_to_collection" class="btn btn-primary" title="Add to collection"> - <i class="icon-plus-sign icon-white"></i> Add - </button> + <button type="button" id="add_to_collection" class="btn btn-primary" title="Add to collection">Add</button> </a> {% if this_trait.dataset.type == 'ProbeSet' %} {% if this_trait.symbol != None %} - <a href="http://www.genenetwork.org/webqtl/main.py?cmd=sch&gene={{ this_trait.symbol }}&alias=1&species={{ species_name }}"> - <button type="button" class="btn btn-default" title="Find similar expression data"> - <i class="icon-search"></i> Find - </button> + <a href="http://www.genenetwork.org/webqtl/main.py?cmd=sch&gene={{ this_trait.symbol }}&alias=1&species={{ dataset.group.species }}"> + <button type="button" class="btn btn-default" title="Find similar expression data">Find</button> </a> {% endif %} {% if UCSC_BLAT_URL != "" %} <a href="{{ UCSC_BLAT_URL }}"> - <button type="button" class="btn btn-default" title="Check probe locations at UCSC"> - <i class="icon-ok"></i> Verify - </button> + <button type="button" class="btn btn-default" title="Check probe locations at UCSC">Verify</button> </a> {% endif %} {% if this_trait.symbol != None %} <a href="http://genenetwork.org/webqtl/main.py?FormID=geneWiki&symbol={{ this_trait.symbol }}"> - <button type="button" class="btn btn-default" title="Write or review comments about this gene"> - <i class="icon-edit"></i> GeneWiki - </button> + <button type="button" class="btn btn-default" title="Write or review comments about this gene">GeneWiki</button> </a> <a href="http://genenetwork.org/webqtl/main.py?FormID=SnpBrowserResultPage&submitStatus=1&diffAlleles=True&customStrain=True&geneName={{ this_trait.symbol }}"> - <button type="button" class="btn btn-default" title="View SNPs and Indels"> - <i class="icon-road"></i> SNPs - </button> + <button type="button" class="btn btn-default" title="View SNPs and Indels">SNPs</button> </a> {% endif %} {% if UTHSC_BLAT_URL != "" %} <a href="{{ UTHSC_BLAT_URL }}"> - <button type="button" class="btn btn-default" title="View probes, SNPs, and RNA-seq at UTHSC"> - <i class="icon-eye-close"></i> RNA-seq - </button> + <button type="button" class="btn btn-default" title="View probes, SNPs, and RNA-seq at UTHSC">RNA-seq</button> </a> {% endif %} {% if show_probes == "True" %} <a href="http://genenetwork.org/webqtl/main.py?FormID=showProbeInfo&database={{ this_trait.dataset.name }}&ProbeSetID={{ this_trait.name }}&CellID={{ this_trait.cellid }}&RISet={{ dataset.group.name }}&incparentsf1=ON"> - <button type="button" class="btn btn-default" title="Check sequence of probes"> - <i class="icon-list"></i> Probes - </button> + <button type="button" class="btn btn-default" title="Check sequence of probes">Probes</button> </a> {% endif %} {% endif %} diff --git a/wqflask/wqflask/templates/show_trait_edit_data.html b/wqflask/wqflask/templates/show_trait_edit_data.html index ff5f0c87..a431821e 100644 --- a/wqflask/wqflask/templates/show_trait_edit_data.html +++ b/wqflask/wqflask/templates/show_trait_edit_data.html @@ -77,20 +77,21 @@ {% for sample_type in sample_groups %} <div class="sample_group" style="width:{{ trait_table_width }}%;"> <h3>{{ sample_type.header }}</h3> - <div id="table_container" style="background-color: #eeeeee; border: 1px solid black;"> + <hr> + <div id="table_container"> <table class="table-hover table-striped" id="samples_{{ sample_type.sample_group_type }}" style="float: left;"> <thead> <tr> - <th style="background-color: #eeeeee;"></th> - <th style="background-color: #eeeeee;">Index</th> - <th style="background-color: #eeeeee;">Sample</th> - <th style="background-color: #eeeeee;">Value</th> + <th></th> + <th>Index</th> + <th>Sample</th> + <th>Value</th> {% if sample_type.se_exists() %} - <th style="background-color: #eeeeee;"> </th> - <th style="background-color: #eeeeee;">SE</th> + <th> </th> + <th>SE</th> {% endif %} {% for attribute in sample_type.attributes|sort() %} - <th style="background-color: #eeeeee;"> + <th> {{ sample_type.attributes[attribute].name }} </th> {% endfor %} @@ -99,7 +100,7 @@ <tbody> {% for sample in sample_type.sample_list %} <tr class="{{ sample.class_outlier }} value_se" id="{{ sample.this_id }}"> - <td class="column_name-"><input type="checkbox" name="selectCheck" class="checkbox edit_sample_checkbox" style="transform: scale(1.5);" value="{{ sample.name }}" checked="checked"> + <td align="center" style="padding-right: 0px;" class="column_name-"><input type="checkbox" name="selectCheck" class="checkbox edit_sample_checkbox" value="{{ sample.name }}" checked="checked"> </td> <td class="column_name-Index" align="right">{{ loop.index }}</td> <td class="column_name-Sample"> @@ -109,12 +110,12 @@ </td> {# Todo: Add IDs #} - <td class="column_name-Value"> + <td class="column_name-Value" align="right"> <input type="text" data-value="{{ sample.display_value }}" name="{{ 'value:' + sample.name }}" style="text-align:right;" class="trait_value_input edit_sample_value" value="{{ sample.display_value }}" - size=8 maxlength=8 + size=6 maxlength=6 > </td> @@ -146,6 +147,7 @@ </table> </div> </div> + <br> {% endfor %} <!--</div>--> diff --git a/wqflask/wqflask/templates/show_trait_mapping_tools.html b/wqflask/wqflask/templates/show_trait_mapping_tools.html index 0f293942..12ba80b9 100644 --- a/wqflask/wqflask/templates/show_trait_mapping_tools.html +++ b/wqflask/wqflask/templates/show_trait_mapping_tools.html @@ -4,7 +4,8 @@ <div class="tabbable"> <!-- Only required for left/right tabs --> <ul class="nav nav-pills"> - {% if use_pylmm_rqtl and not use_plink_gemma and dataset.group.species != "human" %} + {# if use_pylmm_rqtl and not use_plink_gemma and dataset.group.species != "human" #} + {% if dataset.group.mapping_id == "1" %} <li class="active"> <a href="#interval_mapping" data-toggle="tab">Interval Mapping</a> </li> @@ -15,23 +16,39 @@ <a href="#rqtl_geno" data-toggle="tab">R/qtl</a> </li> {% endif %} - {% if use_plink_gemma %} - <li> - <a href="#plink" data-toggle="tab">PLINK</a> + {# if use_plink_gemma #} + {% if dataset.group.mapping_id == "2" or dataset.group.mapping_id == "4" %} + <li class="active"> + <a href="#gemma" data-toggle="tab">GEMMA</a> </li> + {% if dataset.group.mapping_id == "4" %} <li> - <a href="#gemma" data-toggle="tab">GEMMA</a> + <a href="#plink" data-toggle="tab">PLINK</a> </li> {% endif %} + {% endif %} <!--<li> <a href="#pair_scan" data-toggle="tab">Pair Scan</a> </li>--> </ul> <div class="tab-content"> - {% if use_pylmm_rqtl and not use_plink_gemma and dataset.group.species != "human" %} + {# if use_pylmm_rqtl and not use_plink_gemma and dataset.group.species != "human" #} + {% if dataset.group.mapping_id == "1" %} <div class="tab-pane active" id="interval_mapping"> <div style="margin-top: 20px" class="form-horizontal"> + {% if genofiles and genofiles|length>0 %} + <div class="mapping_method_fields form-group"> + <label for="genofiles" class="col-xs-3 control-label">Genotypes</label> + <div style="margin-left: 20px;" class="col-xs-8 controls"> + <select id="genofile_reaper" class="form-control"> + {% for item in genofiles %} + <option value="{{item['location']}}">{{item['title']}}</option> + {% endfor %} + </select> + </div> + </div> + {% endif %} <div class="mapping_method_fields form-group"> <label for="mapping_permutations" class="col-xs-3 control-label">Permutations</label> <div style="margin-left: 20px;" class="col-xs-4 controls"> @@ -114,6 +131,18 @@ </div> <div class="tab-pane" id="pylmm"> <div style="margin-top: 20px" class="form-horizontal"> + {% if genofiles and genofiles|length>0 %} + <div class="mapping_method_fields form-group"> + <label for="genofiles" class="col-xs-3 control-label">Genotypes</label> + <div style="margin-left: 20px;" class="col-xs-8 controls"> + <select id="genofile_pylmm" class="form-control"> + {% for item in genofiles %} + <option value="{{item['location']}}">{{item['title']}}</option> + {% endfor %} + </select> + </div> + </div> + {% endif %} <div class="mapping_method_fields form-group"> <label for="mapping_permutations" class="col-xs-3 control-label">Permutations</label> <div style="margin-left: 20px;" class="col-xs-4 controls"> @@ -169,6 +198,18 @@ <div class="tab-pane" id="rqtl_geno"> <div style="margin-top: 20px" class="form-horizontal"> + {% if genofiles and genofiles|length>0 %} + <div class="mapping_method_fields form-group"> + <label for="genofiles" class="col-xs-3 control-label">Genotypes</label> + <div style="margin-left: 20px;" class="col-xs-8 controls"> + <select id="genofile_rqtl_geno" class="form-control"> + {% for item in genofiles %} + <option value="{{item['location']}}">{{item['title']}}</option> + {% endfor %} + </select> + </div> + </div> + {% endif %} <div class="mapping_method_fields form-group"> <label for="mapping_permutations" class="col-xs-3 control-label">Permutations</label> <div style="margin-left: 20px;" class="col-xs-4 controls"> @@ -262,47 +303,49 @@ </div> </div> {% endif %} - {% if use_plink_gemma %} - <div class="tab-pane" id="plink"> + {# if use_plink_gemma #} + {% if dataset.group.mapping_id == "2" or dataset.group.mapping_id == "4" %} + <div class="tab-pane active" id="gemma"> <div style="padding: 20px" class="form-horizontal"> <div class="mapping_method_fields form-group"> - <label for="maf_plink" class="col-xs-3 control-label">Minor allele threshold</label> + <label for="maf_gemma" class="col-xs-3 control-label">Minor allele threshold</label> <div style="margin-left: 20px;" class="col-xs-3 controls"> - <input name="maf_plink" value="0.01" type="text" class="form-control"> + <input name="maf_gemma" value="0.01" type="text" class="form-control"> </div> </div> </div> <div class="form-group"> - <label for="plink_compute" class="col-xs-1 control-label"></label> + <label for="gemma_compute" class="col-xs-1 control-label"></label> <div style="margin-left:20px;" class="col-xs-4 controls"> - <button id="plink_compute" class="btn submit_special btn-primary" data-url="/marker_regression" title="Compute Marker Regression"> + <button id="gemma_compute" class="btn submit_special btn-primary" data-url="/marker_regression" title="Compute Marker Regression"> Compute </button> </div> </div> </div> - - <div class="tab-pane" id="gemma"> + {% if dataset.group.mapping_id == "4" %} + <div class="tab-pane" id="plink"> <div style="padding: 20px" class="form-horizontal"> <div class="mapping_method_fields form-group"> - <label for="maf_gemma" class="col-xs-3 control-label">Minor allele threshold</label> + <label for="maf_plink" class="col-xs-3 control-label">Minor allele threshold</label> <div style="margin-left: 20px;" class="col-xs-3 controls"> - <input name="maf_gemma" value="0.01" type="text" class="form-control"> + <input name="maf_plink" value="0.01" type="text" class="form-control"> </div> </div> </div> <div class="form-group"> - <label for="gemma_compute" class="col-xs-1 control-label"></label> + <label for="plink_compute" class="col-xs-1 control-label"></label> <div style="margin-left:20px;" class="col-xs-4 controls"> - <button id="gemma_compute" class="btn submit_special btn-primary" data-url="/marker_regression" title="Compute Marker Regression"> + <button id="plink_compute" class="btn submit_special btn-primary" data-url="/marker_regression" title="Compute Marker Regression"> Compute </button> </div> </div> </div> {% endif %} + {% endif %} </div> </div> </div> diff --git a/wqflask/wqflask/templates/show_trait_statistics.html b/wqflask/wqflask/templates/show_trait_statistics.html index 8e237868..0a0e9990 100644 --- a/wqflask/wqflask/templates/show_trait_statistics.html +++ b/wqflask/wqflask/templates/show_trait_statistics.html @@ -106,11 +106,11 @@ <div id="prob_plot_title"></div> <svg></svg> </div> - + <div id="shapiro_wilk_text"></div> <div> More about <a href="http://en.wikipedia.org/wiki/Normal_probability_plot">Normal Probability Plots</a> and more about interpreting these plots from the <a href="http://genenetwork.org/glossary.html#normal_probability">glossary</a> - </div> + </div> </div> diff --git a/wqflask/wqflask/templates/submit_trait.html b/wqflask/wqflask/templates/submit_trait.html new file mode 100644 index 00000000..2529a4f4 --- /dev/null +++ b/wqflask/wqflask/templates/submit_trait.html @@ -0,0 +1,103 @@ +{% extends "base.html" %} +{% block title %}Trait Submission{% endblock %} +{% block content %} +<!-- Start of body --> + <form method="post" action="/show_trait"> + <div class="container-fluid"> + + {{ flash_me() }} + + <div class="row" style="width: 1400px !important;"> + <div class="col-xs-5"> + <section id="description"> + <div> + <h2 style="color: #5a5a5a;">Introduction</h2> + <hr> + <p>The trait values that you enter are statistically compared with verified genotypes collected at a set of microsatellite markers in each RI set. The markers are drawn from a set of over 750, but for each set redundant markers have been removed, preferentially retaining those that are most informative.</p> + <p>These error-checked RI mapping data match theoretical expectations for RI strain sets. The cumulative adjusted length of the RI maps are approximately 1400 cM, a value that matches those of both MIT maps and Chromosome Committee Report maps. See our full description of the genetic data collected as part of the WebQTL project.</p> + </div> + </section> + <br> + <section id="description"> + <div> + <h2 style="color: #5a5a5a;">About Your Data</h2> + <hr> + <p>You can open a separate window giving the number of strains for each data set and sample data.</p> + <p>None of your submitted data is copied or stored by this system except during the actual processing of your submission. By the time the reply page displays in your browser, your submission has been cleared from this system.</p> + </div> + </section> + </div> + <div style="padding-left:20px" class="col-xs-6" style="width: 600px !important;"> + <section id="submission_form"> + <div class="form-group"> + <h2 style="color: #5a5a5a;">Trait Submission Form</h2> + <hr> + <div style="padding-bottom: 50px;" class="form-horizontal"> + <h3>1. Choose cross or RI set:</h3> + <br> + <div class="col-xs-2" style="min-height: 15vh; display: flex; align-items: center;"> + <img src="/static/new/images/step1.gif"> + </div> + <div class="col-xs-10"> + <div class="form-group"> + <label for="species" class="col-xs-2 control-label">Species: </label> + <div class="col-xs-4 controls"> + <select name="species" id="species" class="form-control span3" style="width: 280px !important;"></select> + </div> + </div> + <div class="form-group"> + <label for="group" class="col-xs-2 control-label">Group: </label> + <div class="col-xs-4 controls"> + <select name="group" id="group" class="form-control span3" style="width: 280px !important;"></select> + </div> + </div> + </div> + <div class="form-horizontal"><img src="/static/new/images/arrowdown.gif" style="display:block; margin-left: 50%; margin-right: 50%;"></div> + </div> + <div style="padding-bottom: 50px;" class="form-horizontal"> + <h3>2. Enter Trait Data:</h3> + <br> + <div class="col-xs-2" style="min-height: 100vh; display: flex; align-items: center;"> + <img src="/static/new/images/step2.gif"> + </div> + <div class="col-xs-10"> + <div class="form-group" style="padding-left: 15px;"> + <p> + <b>From a File:</b> You can enter data by entering a file name here. The file should contain a series of numbers representing trait values. + The values can be on one line separated by spaces or tabs, or they can be on separate lines. Include one value for each progeny individual + or recombinant inbred line. Represent missing values with a non-numeric character such as "x". If you have chosen a recombinant inbred set, + when you submit your data will be displayed in a form where you can confirm and/or edit them. If you enter a file name here, any data that + you paste into the next section will be ignored. + </p> + <input type="file" name="trait_file" style="border-width: 1px; border-style: solid; border-color: #999999;"> + </div> + <div class="form-group" style="padding-left: 15px;"> + <p> + <b>By Pasting or Typing Multiple Values:</b> You can enter data by pasting a series of numbers representing trait values into this area. + The values can be on one line separated by spaces or tabs, or they can be on separate lines. Include one value for each progeny individual + or recombinant inbredline. Represent missing values with a non-numeric character such as "x". If you have chosen a recombinant inbred set, + when you submit your data will be displayed in a form where you can confirm and/or edit them. If you enter a file name in the previous section, + any data that you paste here will be ignored. Check sample data for the correct format. + </p> + <textarea name="trait_paste" rows="6" cols="70"></textarea> + </div> + </div> + <div class="controls" style="display:block; margin-left: 40%; margin-right: 20%;"> + <input type="submit" style="width: 110px; margin-right: 25px;" class="btn btn-primary form-control col-xs-2" value="Submit Trait"> + <input type="reset" style="width: 110px;" class="btn btn-primary form-control col-xs-2" value="Reset"> + </div> + </div> + </section> + </div> + </div> + </div> + </form> + +{%endblock%} + +{% block js %} + <script src="/static/new/javascript/dataset_select_menu_orig.js"></script> + <script> + gn_server_url = "{{ gn_server_url }}"; + </script> +{% endblock %} diff --git a/wqflask/wqflask/user_manager.py b/wqflask/wqflask/user_manager.py index 598af0a6..1e831896 100644 --- a/wqflask/wqflask/user_manager.py +++ b/wqflask/wqflask/user_manager.py @@ -158,7 +158,6 @@ def verify_cookie(cookie): assert the_signature == actual_hmac_creation(the_uuid), "Uh-oh, someone tampering with the cookie?" return the_uuid - def create_signed_cookie(): the_uuid = str(uuid.uuid4()) signature = actual_hmac_creation(the_uuid) diff --git a/wqflask/wqflask/views.py b/wqflask/wqflask/views.py index b49f32d2..ee135d4c 100644 --- a/wqflask/wqflask/views.py +++ b/wqflask/wqflask/views.py @@ -21,6 +21,7 @@ import uuid import simplejson as json import yaml +import csv #Switching from Redis to StrictRedis; might cause some issues import redis @@ -33,6 +34,7 @@ import sqlalchemy from wqflask import app from flask import g, Response, request, make_response, render_template, send_from_directory, jsonify, redirect from wqflask import search_results +from wqflask import export_traits from wqflask import gsearch from wqflask import update_search_results from wqflask import docs @@ -52,11 +54,13 @@ from wqflask.ctl import ctl_analysis from wqflask.auwerx import phewas_analysis from wqflask.auwerx import ephewas_analysis +from utility import webqtlUtil from utility import temp_data -from utility.tools import SQL_URI,TEMPDIR,USE_REDIS,USE_GN_SERVER,GN_SERVER_URL +from utility.tools import SQL_URI,TEMPDIR,USE_REDIS,USE_GN_SERVER,GN_SERVER_URL,GN_VERSION +from utility.helper_functions import get_species_groups from base import webqtlFormData -from base.webqtlConfig import GENERATED_IMAGE_DIR +from base.webqtlConfig import GENERATED_IMAGE_DIR, GENERATED_TEXT_DIR from utility.benchmark import Bench from pprint import pformat as pf @@ -110,7 +114,7 @@ def handle_bad_request(e): list = [fn for fn in os.listdir("./wqflask/static/gif/error") if fn.endswith(".gif") ] animation = random.choice(list) - resp = make_response(render_template("error.html",message=err_msg,stack=formatted_lines,error_image=animation)) + resp = make_response(render_template("error.html",message=err_msg,stack=formatted_lines,error_image=animation,version=GN_VERSION)) # logger.error("Set cookie %s with %s" % (err_msg, animation)) resp.set_cookie(err_msg[:32],animation) @@ -126,10 +130,10 @@ def index_page(): g.cookie_session.import_traits_to_user() if USE_GN_SERVER: # The menu is generated using GN_SERVER - return render_template("index_page.html", gn_server_url = GN_SERVER_URL) + return render_template("index_page.html", gn_server_url = GN_SERVER_URL, version=GN_VERSION) else: # Old style static menu (OBSOLETE) - return render_template("index_page_orig.html") + return render_template("index_page_orig.html", version=GN_VERSION) @app.route("/tmp/<img_path>") @@ -145,6 +149,16 @@ def tmp_page(img_path): return render_template("show_image.html", img_base64 = bytesarray ) +@app.route("/twitter/<path:filename>") +def twitter_js(filename): + bd_path = app.config['JS_TWITTER_POST_FETCHER'] + return send_from_directory(bd_path, filename) + +@app.route("/dalliance/<path:filename>") +def biodalliance_js(filename): + bd_path = app.config['JS_BIODALLIANCE'] + return send_from_directory(bd_path, filename) + #@app.route("/data_sharing") #def data_sharing_page(): @@ -230,6 +244,10 @@ def docedit(): def generated_file(filename): return send_from_directory(GENERATED_IMAGE_DIR,filename) +@app.route('/generated_text/<filename>') +def generated_text(filename): + return send_from_directory(GENERATED_TEXT_DIR, filename) + @app.route("/help") def help(): doc = docs.Docs("help") @@ -310,6 +328,20 @@ def environments(): doc = docs.Docs("environments") return render_template("docs.html", **doc.__dict__) +@app.route("/submit_trait") +def submit_trait_form(): + species_and_groups = get_species_groups() + return render_template("submit_trait.html", **{'species_and_groups' : species_and_groups, 'gn_server_url' : GN_SERVER_URL, 'version' : GN_VERSION}) + +@app.route("/create_temp_trait", methods=('POST',)) +def create_temp_trait(): + print("REQUEST.FORM:", request.form) + #template_vars = submit_trait.SubmitTrait(request.form) + + doc = docs.Docs("links") + return render_template("links.html", **doc.__dict__) + #return render_template("show_trait.html", **template_vars.__dict__) + @app.route('/export_trait_excel', methods=('POST',)) def export_trait_excel(): """Excel file consisting of the sample data from the trait data and analysis page""" @@ -355,6 +387,17 @@ def export_trait_csv(): mimetype='text/csv', headers={"Content-Disposition":"attachment;filename=sample_data.csv"}) +@app.route('/export_traits_csv', methods=('POST',)) +def export_traits_csv(): + """CSV file consisting of the traits from the search result page""" + logger.info("In export_traits_csv") + logger.info("request.form:", request.form) + csv_data = export_traits.export_search_results_csv(request.form) + + return Response(csv_data, + mimetype='text/csv', + headers={"Content-Disposition":"attachment;filename=trait_list.csv"}) + @app.route('/export_perm_data', methods=('POST',)) def export_perm_data(): """CSV file consisting of the permutation data for the mapping results""" @@ -380,9 +423,6 @@ def export_perm_data(): @app.route("/show_trait") def show_trait_page(): - # Here it's currently too complicated not to use an fd that is a webqtlFormData - #fd = webqtlFormData.webqtlFormData(request.args) - #logger.info("stp y1:", pf(vars(fd))) template_vars = show_trait.ShowTrait(request.args) #logger.info("js_data before dump:", template_vars.js_data) template_vars.js_data = json.dumps(template_vars.js_data, @@ -445,6 +485,60 @@ def heatmap_page(): def mapping_results_container_page(): return render_template("mapping_results_container.html") +@app.route("/loading", methods=('POST',)) +def loading_page(): + initial_start_vars = request.form + logger.debug("Marker regression called with initial_start_vars:", initial_start_vars.items()) + #temp_uuid = initial_start_vars['temp_uuid'] + wanted = ( + 'temp_uuid', + 'trait_id', + 'dataset', + 'method', + 'trimmed_markers', + 'selected_chr', + 'chromosomes', + 'mapping_scale', + 'score_type', + 'suggestive', + 'significant', + 'num_perm', + 'permCheck', + 'perm_output', + 'num_bootstrap', + 'bootCheck', + 'bootstrap_results', + 'LRSCheck', + 'maf', + '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' + ) + start_vars_container = {} + start_vars = {} + for key, value in initial_start_vars.iteritems(): + if key in wanted or key.startswith(('value:')): + start_vars[key] = value + + start_vars_container['start_vars'] = start_vars + rendered_template = render_template("loading.html", **start_vars_container) + + return rendered_template + @app.route("/marker_regression", methods=('POST',)) def marker_regression_page(): initial_start_vars = request.form @@ -473,6 +567,7 @@ def marker_regression_page(): 'control_marker', 'control_marker_db', 'do_control', + 'genofile', 'pair_scan', 'startMb', 'endMb', @@ -512,10 +607,27 @@ def marker_regression_page(): with Bench("Total time in MarkerRegression"): template_vars = marker_regression.MarkerRegression(start_vars, temp_uuid) + + qtl_results = template_vars.js_data['qtl_results'] + template_vars.js_data = json.dumps(template_vars.js_data, default=json_default_handler, indent=" ") + + json_filename = webqtlUtil.genRandStr("") + ".json" + with open(GENERATED_TEXT_DIR + "/" + json_filename, "wb") as json_file: + json_file.write(template_vars.js_data) + + csv_filename = webqtlUtil.genRandStr("") + ".csv" + with open(GENERATED_TEXT_DIR + "/" + csv_filename, "wb") as csv_file: + writer = csv.writer(csv_file) + writer.writerow(("Locus", "Chr", "Mb", "LOD")) + for (row) in qtl_results: + score = row["lod_score"] if "lod_score" in row else row["lrs_value"] + writer.writerow((row["name"], row["chr"], row["Mb"], score)) + + result = template_vars.__dict__ if result['pair_scan']: @@ -535,6 +647,9 @@ def marker_regression_page(): # logger.info(" ---**--- {}: {}".format(type(template_vars.__dict__[item]), item)) gn1_template_vars = marker_regression_gn1.MarkerRegression(result).__dict__ + gn1_template_vars['json_filename'] = json_filename; + gn1_template_vars['csv_filename'] = csv_filename; + gn1_template_vars['gn_server_url'] = GN_SERVER_URL; pickled_result = pickle.dumps(result, pickle.HIGHEST_PROTOCOL) logger.info("pickled result length:", len(pickled_result)) @@ -544,22 +659,6 @@ def marker_regression_page(): with Bench("Rendering template"): rendered_template = render_template("marker_regression_gn1.html", **gn1_template_vars) - # with Bench("Rendering template"): - # if result['pair_scan'] == True: - # img_path = result['pair_scan_filename'] - # logger.info("img_path:", img_path) - # initial_start_vars = request.form - # logger.info("initial_start_vars:", initial_start_vars) - # imgfile = open(TEMPDIR + '/' + img_path, 'rb') - # imgdata = imgfile.read() - # imgB64 = imgdata.encode("base64") - # bytesarray = array.array('B', imgB64) - # result['pair_scan_array'] = bytesarray - # rendered_template = render_template("pair_scan_results.html", **result) - # else: - # rendered_template = render_template("marker_regression.html", **result) - # rendered_template = render_template("marker_regression_gn1.html", **gn1_template_vars) - return rendered_template |