galaxy-dev
Threads by month
- ----- 2025 -----
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- 10008 discussions
details: http://www.bx.psu.edu/hg/galaxy/rev/cdd8d520f3c7
changeset: 3635:cdd8d520f3c7
user: Anton Nekrutenko <anton(a)bx.psu.edu>
date: Tue Apr 13 11:23:19 2010 -0400
description:
merge
diffstat:
static/scripts/checkbox_and_radiobutton.js | 347 ++++
static/scripts/helper_functions.js | 817 ++++++++++
static/scripts/timer.js | 74 +
tools/rgenetics/rgGRR.py | 2241 ++++++++++++++-------------
tools/rgenetics/rgManQQ.py | 19 +-
5 files changed, 2396 insertions(+), 1102 deletions(-)
diffs (truncated from 3540 to 3000 lines):
diff -r a6e3f4cae4ce -r cdd8d520f3c7 static/scripts/checkbox_and_radiobutton.js
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/static/scripts/checkbox_and_radiobutton.js Tue Apr 13 11:23:19 2010 -0400
@@ -0,0 +1,347 @@
+/*
+Scripts to create interactive checkboxes and radio buttons in SVG using ECMA script
+Copyright (C) <2007> <Andreas Neumann>
+Version 1.1.3, 2007-08-09
+neumann(a)karto.baug.ethz.ch
+http://www.carto.net/
+http://www.carto.net/neumann/
+
+Credits:
+* Guy Morton for providing a fix to let users toggle checkboxes by clicking on text labels
+* Bruce Rindahl for providing the bugfix described in version 1.1.2
+* Simon Shutter for providing a fix for the ASV in IE crash when reloading the SVG file after calling the .remove() method on a checkbox
+
+----
+
+Documentation: http://www.carto.net/papers/svg/gui/checkbox_and_radiobutton/
+
+----
+
+current version: 1.1.3
+
+version history:
+1.0 (2006-03-13)
+initial version
+
+1.1 (2006-07-11)
+text labels are now clickable (thanks to Guy Morton)
+added method .moveTo() to move checkbox to a different location
+introduced new constructor parameter labelYOffset to allow more flexible placement of the text label
+
+1.1.1 (2007-02-06)
+added cursor pointer to the text label and use element representing the checkBox
+
+1.1.2 (2007-04-19)
+bug fix: this.selectedIndex was not correctly initialized in method addCheckBox of the radioButtonGroup object
+
+1.1.3 (2007-08-09)
+bug fix: the method .remove() was slightly modified (using removeEventListener) for avoiding a crash related to the method after reloading the SVG file
+
+-------
+
+
+This ECMA script library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library (lesser_gpl.txt); if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+----
+
+original document site: http://www.carto.net/papers/svg/gui/checkbox_and_radiobutton/
+Please contact the author in case you want to use code or ideas commercially.
+If you use this code, please include this copyright header, the included full
+LGPL 2.1 text and read the terms provided in the LGPL 2.1 license
+(http://www.gnu.org/copyleft/lesser.txt)
+
+-------------------------------
+
+Please report bugs and send improvements to neumann(a)karto.baug.ethz.ch
+If you use this control, please link to the original (http://www.carto.net/papers/svg/gui/checkbox_and_radiobutton/)
+somewhere in the source-code-comment or the "about" of your project and give credits, thanks!
+
+*/
+
+function checkBox(id,parentNode,x,y,checkboxId,checkcrossId,checkedStatus,labelText,textStyles,labelDistance,labelYOffset,radioButtonGroup,functionToCall) {
+ var nrArguments = 13;
+ var createCheckbox= true;
+ if (arguments.length == nrArguments) {
+ this.id = id; //an internal id, this id is not used in the SVG Dom tree
+ this.parentNode = parentNode; //the parentNode, string or nodeReference
+ this.x = x; //the center of the checkBox
+ this.y = y; //the center of the checkBox
+ this.checkboxId = checkboxId; //the id of the checkbox symbol (background)
+ this.checkcrossId = checkcrossId; //the id of the checkbox symbol (foreground), pointer-events should be set to "none"
+ this.checkedStatus = checkedStatus; //a status variable (true|false), indicates if checkbox is on or off
+ this.labelText = labelText; //the text of the checkbox label to be displayed, use undefined or empty string if you don't need a label text
+ this.textStyles = textStyles; //an array of literals containing the text settings
+ if (!this.textStyles["font-size"]) {
+ this.textStyles["font-size"] = 12;
+ }
+ this.labelDistance = labelDistance; //a distance defined from the center of the checkbox to the left of the text of the label
+ this.labelYOffset = labelYOffset; //a y offset value for the text label in relation to the checkbox symbol center
+ this.radioButtonGroup = radioButtonGroup; //a reference to a radio button group, if this is a standalone checkBox, just use the parameter undefined
+ this.functionToCall = functionToCall; //the function to call after triggering checkBox
+ this.exists = true; //status that indicates if checkbox exists or not, is set to false after method .remove() was called
+ this.label = undefined; //later a reference to the label text node
+ }
+ else {
+ createCheckbox = false;
+ alert("Error in checkbox ("+id+"): wrong nr of arguments! You have to pass over "+nrArguments+" parameters.");
+ }
+ if (createCheckbox) {
+ //timer stuff
+ this.timer = new Timer(this); //a Timer instance for calling the functionToCall
+ if (this.radioButtonGroup) {
+ this.timerMs = 0;
+ }
+ else {
+ this.timerMs = 200; //a constant of this object that is used in conjunction with the timer - functionToCall is called after 200 ms
+ }
+ //create checkbox
+ this.createCheckBox();
+ }
+ else {
+ alert("Could not create checkbox with id '"+id+"' due to errors in the constructor parameters");
+ }
+}
+
+//this method creates all necessary checkbox geometry
+checkBox.prototype.createCheckBox = function() {
+ if (typeof(this.parentNode) == "string") {
+ this.parentNode = document.getElementById(this.parentNode);
+ }
+ //create checkbox
+ this.checkBox = document.createElementNS(svgNS,"use");
+ this.checkBox.setAttributeNS(null,"x",this.x);
+ this.checkBox.setAttributeNS(null,"y",this.y);
+ this.checkBox.setAttributeNS(xlinkNS,"href","#"+this.checkboxId);
+ this.checkBox.addEventListener("click",this,false);
+ this.checkBox.setAttributeNS(null,"cursor","pointer");
+ this.parentNode.appendChild(this.checkBox);
+ //create checkcross
+ this.checkCross = document.createElementNS(svgNS,"use");
+ this.checkCross.setAttributeNS(null,"x",this.x);
+ this.checkCross.setAttributeNS(null,"y",this.y);
+ this.checkCross.setAttributeNS(xlinkNS,"href","#"+this.checkcrossId);
+ this.parentNode.appendChild(this.checkCross);
+ if (this.checkedStatus == false) {
+ this.checkCross.setAttributeNS(null,"display","none");
+ }
+ //create label, if any
+ if (this.labelText) {
+ if (this.labelText.length > 0) {
+ this.label = document.createElementNS(svgNS,"text");
+ for (var attrib in this.textStyles) {
+ var value = this.textStyles[attrib];
+ if (attrib == "font-size") {
+ value += "px";
+ }
+ this.label.setAttributeNS(null,attrib,value);
+ }
+ this.label.setAttributeNS(null,"x",(this.x + this.labelDistance));
+ this.label.setAttributeNS(null,"y",(this.y + this.labelYOffset));
+ this.label.setAttributeNS(null,"cursor","pointer");
+ var labelTextNode = document.createTextNode(this.labelText);
+ this.label.appendChild(labelTextNode);
+ this.label.setAttributeNS(null,"pointer-events","all");
+ this.label.addEventListener("click",this,false);
+ this.parentNode.appendChild(this.label);
+ }
+ }
+ if (this.radioButtonGroup) {
+ this.radioButtonGroup.addCheckBox(this);
+ }
+}
+
+checkBox.prototype.handleEvent = function(evt) {
+ if (evt.type == "click") {
+ if (this.checkedStatus == true) {
+ this.checkCross.setAttributeNS(null,"display","none");
+ this.checkedStatus = false;
+ }
+ else {
+ this.checkCross.setAttributeNS(null,"display","inline");
+ this.checkedStatus = true;
+ }
+ }
+ this.timer.setTimeout("fireFunction",this.timerMs);
+}
+
+checkBox.prototype.fireFunction = function() {
+ if (this.radioButtonGroup) {
+ this.radioButtonGroup.selectById(this.id,true);
+ }
+ else {
+ if (typeof(this.functionToCall) == "function") {
+ this.functionToCall(this.id,this.checkedStatus,this.labelText);
+ }
+ if (typeof(this.functionToCall) == "object") {
+ this.functionToCall.checkBoxChanged(this.id,this.checkedStatus,this.labelText);
+ }
+ if (typeof(this.functionToCall) == undefined) {
+ return;
+ }
+ }
+}
+
+checkBox.prototype.check = function(FireFunction) {
+ this.checkCross.setAttributeNS(null,"display","inherit");
+ this.checkedStatus = true;
+ if (FireFunction) {
+ this.timer.setTimeout("fireFunction",this.timerMs);
+ }
+}
+
+checkBox.prototype.uncheck = function(FireFunction) {
+ this.checkCross.setAttributeNS(null,"display","none");
+ this.checkedStatus = false;
+ if (FireFunction) {
+ this.timer.setTimeout("fireFunction",this.timerMs);
+ }
+}
+
+//move checkbox to a different position
+checkBox.prototype.moveTo = function(moveX,moveY) {
+ this.x = moveX;
+ this.y = moveY;
+ //move checkbox
+ this.checkBox.setAttributeNS(null,"x",this.x);
+ this.checkBox.setAttributeNS(null,"y",this.y);
+ //move checkcross
+ this.checkCross.setAttributeNS(null,"x",this.x);
+ this.checkCross.setAttributeNS(null,"y",this.y);
+ //move text label
+ if (this.labelText) {
+ this.label.setAttributeNS(null,"x",(this.x + this.labelDistance));
+ this.label.setAttributeNS(null,"y",(this.y + this.labelYOffset));
+ }
+}
+
+checkBox.prototype.remove = function(FireFunction) {
+ this.checkBox.removeEventListener("click",this,false);
+ this.parentNode.removeChild(this.checkBox);
+ this.parentNode.removeChild(this.checkCross);
+ if (this.label) {
+ this.parentNode.removeChild(this.label);
+ }
+ this.exists = false;
+}
+
+checkBox.prototype.setLabelText = function(labelText) {
+ this.labelText = labelText
+ if (this.label) {
+ this.label.firstChild.nodeValue = labelText;
+ }
+ else {
+ if (this.labelText.length > 0) {
+ this.label = document.createElementNS(svgNS,"text");
+ for (var attrib in this.textStyles) {
+ value = this.textStyles[attrib];
+ if (attrib == "font-size") {
+ value += "px";
+ }
+ this.label.setAttributeNS(null,attrib,value);
+ }
+ this.label.setAttributeNS(null,"x",(this.x + this.labelDistance));
+ this.label.setAttributeNS(null,"y",(this.y + this.textStyles["font-size"] * 0.3));
+ var labelTextNode = document.createTextNode(this.labelText);
+ this.label.appendChild(labelTextNode);
+ this.parentNode.appendChild(this.label);
+ }
+ }
+}
+
+/* start of the radioButtonGroup object */
+
+function radioButtonGroup(id,functionToCall) {
+ var nrArguments = 2;
+ if (arguments.length == nrArguments) {
+ this.id = id;
+ if (typeof(functionToCall) == "function" || typeof(functionToCall) == "object" || typeof(functionToCall) == undefined) {
+ this.functionToCall = functionToCall;
+ }
+ else {
+ alert("Error in radiobutton with ("+id+"): argument functionToCall is not of type 'function', 'object' or undefined!");
+ }
+ this.checkBoxes = new Array(); //this array will hold checkbox objects
+ this.selectedId = undefined; //holds the id of the active radio button
+ this.selectedIndex = undefined; //holds the index of the active radio button
+ //timer stuff
+ this.timer = new Timer(this); //a Timer instance for calling the functionToCall
+ this.timerMs = 200; //a constant of this object that is used in conjunction with the timer - functionToCall is called after 200 ms
+ }
+ else {
+ alert("Error in radiobutton with ("+id+"): wrong nr of arguments! You have to pass over "+nrArguments+" parameters.");
+ }
+}
+
+radioButtonGroup.prototype.addCheckBox = function(checkBoxObj) {
+ this.checkBoxes.push(checkBoxObj);
+ if (checkBoxObj.checkedStatus) {
+ this.selectedId = checkBoxObj.id;
+ this.selectedIndex = this.checkBoxes.length - 1;
+ }
+}
+
+//change radio button selection by id
+radioButtonGroup.prototype.selectById = function(cbId,fireFunction) {
+ var found = false;
+ for (var i=0;i<this.checkBoxes.length;i++) {
+ if (this.checkBoxes[i].id == cbId) {
+ this.selectedId = cbId;
+ this.selectedIndex = i;
+ if (this.checkBoxes[i].checkedStatus == false) {
+ this.checkBoxes[i].check(false);
+ }
+ found = true;
+ }
+ else {
+ this.checkBoxes[i].uncheck(false);
+ }
+ }
+ if (found) {
+ if (fireFunction) {
+ this.timer.setTimeout("fireFunction",this.timerMs);
+ }
+ }
+ else {
+ alert("Error in radiobutton with ("+this.id+"): could not find checkbox with id '"+cbId+"'");
+ }
+}
+
+//change radio button selection by label name
+radioButtonGroup.prototype.selectByLabelname = function(labelName,fireFunction) {
+ var id = -1;
+ for (var i=0;i<this.checkBoxes.length;i++) {
+ if (this.checkBoxes[i].labelText == labelName) {
+ id = this.checkBoxes[i].id;
+ }
+ }
+ if (id == -1) {
+ alert("Error in radiobutton with ("+this.id+"): could not find checkbox with label '"+labelName+"'");
+ }
+ else {
+ this.selectById(id,fireFunction);
+ }
+}
+
+radioButtonGroup.prototype.fireFunction = function() {
+ if (typeof(this.functionToCall) == "function") {
+ this.functionToCall(this.id,this.selectedId,this.checkBoxes[this.selectedIndex].labelText);
+ }
+ if (typeof(this.functionToCall) == "object") {
+ this.functionToCall.radioButtonChanged(this.id,this.selectedId,this.checkBoxes[this.selectedIndex].labelText);
+ }
+ if (typeof(this.functionToCall) == undefined) {
+ return;
+ }
+}
\ No newline at end of file
diff -r a6e3f4cae4ce -r cdd8d520f3c7 static/scripts/helper_functions.js
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/static/scripts/helper_functions.js Tue Apr 13 11:23:19 2010 -0400
@@ -0,0 +1,817 @@
+/**
+ * @fileoverview
+ *
+ * ECMAScript <a href="http://www.carto.net/papers/svg/resources/helper_functions.html">helper functions</a>, main purpose is to serve in SVG mapping or other SVG based web applications
+ *
+ * This ECMA script library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library (http://www.carto.net/papers/svg/resources/lesser_gpl.txt) if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Please report bugs and send improvements to neumann(a)karto.baug.ethz.ch
+ * If you use these scripts, please link to the original (http://www.carto.net/papers/svg/resources/helper_functions.html)
+ * somewhere in the source-code-comment or the "about" of your project and give credits, thanks!
+ *
+ * See <a href="js_docs_out/overview-summary-helper_functions.js.html">documentation</a>.
+ *
+ * @author Andreas Neumann a.neumann(a)carto.net
+ * @copyright LGPL 2.1 <a href="http://www.gnu.org/copyleft/lesser.txt">Gnu LGPL 2.1</a>
+ * @credits Bruce Rindahl, numerous people on svgdevelopers(a)yahoogroups.com
+ */
+
+//global variables necessary to create elements in these namespaces, do not delete them!!!!
+
+/**
+ * This variable is a shortcut to the full URL of the SVG namespace
+ * @final
+ * @type String
+ */
+var svgNS = "http://www.w3.org/2000/svg";
+
+/**
+ * This variable is a shortcut to the full URL of the XLink namespace
+ * @final
+ * @type String
+ */
+var xlinkNS = "http://www.w3.org/1999/xlink";
+
+/**
+ * This variable is a shortcut to the full URL of the attrib namespace
+ * @final
+ * @type String
+ */
+var cartoNS = "http://www.carto.net/attrib";
+
+/**
+ * This variable is a alias to the full URL of the attrib namespace
+ * @final
+ * @type String
+ */
+var attribNS = "http://www.carto.net/attrib";
+
+/**
+ * This variable is a alias to the full URL of the Batik extension namespace
+ * @final
+ * @type String
+ */
+var batikNS = "http://xml.apache.org/batik/ext";
+
+/**
+ * Returns the polar direction from a given vector
+ * @param {Number} xdiff the x-part of the vector
+ * @param {Number} ydiff the y-part of the vector
+ * @return direction the direction in radians
+ * @type Number
+ * @version 1.0 (2007-04-30)
+ * @see #toPolarDist
+ * @see #toRectX
+ * @see #toRectY
+ */
+function toPolarDir(xdiff,ydiff) {
+ var direction = (Math.atan2(ydiff,xdiff));
+ return(direction);
+}
+
+/**
+ * Returns the polar distance from a given vector
+ * @param {Number} xdiff the x-part of the vector
+ * @param {Number} ydiff the y-part of the vector
+ * @return distance the distance
+ * @type Number
+ * @version 1.0 (2007-04-30)
+ * @see #toPolarDir
+ * @see #toRectX
+ * @see #toRectY
+ */
+function toPolarDist(xdiff,ydiff) {
+ var distance = Math.sqrt(xdiff * xdiff + ydiff * ydiff);
+ return(distance);
+}
+
+/**
+ * Returns the x-part of a vector from a given direction and distance
+ * @param {Number} direction the direction (in radians)
+ * @param {Number} distance the distance
+ * @return x the x-part of the vector
+ * @type Number
+ * @version 1.0 (2007-04-30)
+ * @see #toPolarDist
+ * @see #toPolarDir
+ * @see #toRectY
+ */
+function toRectX(direction,distance) {
+ var x = distance * Math.cos(direction);
+ return(x);
+}
+
+/**
+ * Returns the y-part of the vector from a given direction and distance
+ * @param {Number} direction the direction (in radians)
+ * @param {Number} distance the distance
+ * @return y the y-part of the vector
+ * @type Number
+ * @version 1.0 (2007-04-30)
+ * @see #toPolarDist
+ * @see #toPolarDir
+ * @see #toRectX
+ */
+function toRectY(direction,distance) {
+ y = distance * Math.sin(direction);
+ return(y);
+}
+
+/**
+ * Converts degrees to radians
+ * @param {Number} deg the degree value
+ * @return rad the radians value
+ * @type Number
+ * @version 1.0 (2007-04-30)
+ * @see #RadToDeg
+ */
+function DegToRad(deg) {
+ return (deg / 180.0 * Math.PI);
+}
+
+/**
+ * Converts radians to degrees
+ * @param {Number} rad the radians value
+ * @return deg the degree value
+ * @type Number
+ * @version 1.0 (2007-04-30)
+ * @see #DegToRad
+ */
+function RadToDeg(rad) {
+ return (rad / Math.PI * 180.0);
+}
+
+/**
+ * Converts decimal degrees to degrees, minutes, seconds
+ * @param {Number} dd the decimal degree value
+ * @return degrees the degree values in the following notation: {deg:degrees,min:minutes,sec:seconds}
+ * @type literal
+ * @version 1.0 (2007-04-30)
+ * @see #dms2dd
+ */
+function dd2dms(dd) {
+ var minutes = (Math.abs(dd) - Math.floor(Math.abs(dd))) * 60;
+ var seconds = (minutes - Math.floor(minutes)) * 60;
+ var minutes = Math.floor(minutes);
+ if (dd >= 0) {
+ var degrees = Math.floor(dd);
+ }
+ else {
+ var degrees = Math.ceil(dd);
+ }
+ return {deg:degrees,min:minutes,sec:seconds};
+}
+
+/**
+ * Converts degrees, minutes and seconds to decimal degrees
+ * @param {Number} deg the degree value
+ * @param {Number} min the minute value
+ * @param {Number} sec the second value
+ * @return deg the decimal degree values
+ * @type Number
+ * @version 1.0 (2007-04-30)
+ * @see #dd2dms
+ */
+function dms2dd(deg,min,sec) {
+ if (deg < 0) {
+ return deg - (min / 60) - (sec / 3600);
+ }
+ else {
+ return deg + (min / 60) + (sec / 3600);
+ }
+}
+
+/**
+ * log function, missing in the standard Math object
+ * @param {Number} x the value where the log function should be applied to
+ * @param {Number} b the base value for the log function
+ * @return logResult the result of the log function
+ * @type Number
+ * @version 1.0 (2007-04-30)
+ */
+function log(x,b) {
+ if(b==null) b=Math.E;
+ return Math.log(x)/Math.log(b);
+}
+
+/**
+ * interpolates a value (e.g. elevation) bilinearly based on the position within a cell with 4 corner values
+ * @param {Number} za the value at the upper left corner of the cell
+ * @param {Number} zb the value at the upper right corner of the cell
+ * @param {Number} zc the value at the lower right corner of the cell
+ * @param {Number} zd the value at the lower left corner of the cell
+ * @param {Number} xpos the x position of the point where a new value should be interpolated
+ * @param {Number} ypos the y position of the point where a new value should be interpolated
+ * @param {Number} ax the x position of the lower left corner of the cell
+ * @param {Number} ay the y position of the lower left corner of the cell
+ * @param {Number} cellsize the size of the cell
+ * @return interpol_value the result of the bilinear interpolation function
+ * @type Number
+ * @version 1.0 (2007-04-30)
+ */
+function intBilinear(za,zb,zc,zd,xpos,ypos,ax,ay,cellsize) { //bilinear interpolation function
+ var e = (xpos - ax) / cellsize;
+ var f = (ypos - ay) / cellsize;
+
+ //calculation of weights
+ var wa = (1 - e) * (1 - f);
+ var wb = e * (1 - f);
+ var wc = e * f;
+ var wd = f * (1 - e);
+
+ var interpol_value = wa * zc + wb * zd + wc * za + wd * zb;
+ return interpol_value;
+}
+
+/**
+ * tests if a given point is left or right of a given line
+ * @param {Number} pointx the x position of the given point
+ * @param {Number} pointy the y position of the given point
+ * @param {Number} linex1 the x position of line's start point
+ * @param {Number} liney1 the y position of line's start point
+ * @param {Number} linex2 the x position of line's end point
+ * @param {Number} liney2 the y position of line's end point
+ * @return leftof the result of the leftOfTest, 1 means leftOf, 0 means rightOf
+ * @type Number (integer, 0|1)
+ * @version 1.0 (2007-04-30)
+ */
+function leftOfTest(pointx,pointy,linex1,liney1,linex2,liney2) {
+ var result = (liney1 - pointy) * (linex2 - linex1) - (linex1 - pointx) * (liney2 - liney1);
+ if (result < 0) {
+ var leftof = 1; //case left of
+ }
+ else {
+ var leftof = 0; //case left of
+ }
+ return leftof;
+}
+
+/**
+ * calculates the distance between a given point and a given line
+ * @param {Number} pointx the x position of the given point
+ * @param {Number} pointy the y position of the given point
+ * @param {Number} linex1 the x position of line's start point
+ * @param {Number} liney1 the y position of line's start point
+ * @param {Number} linex2 the x position of line's end point
+ * @param {Number} liney2 the y position of line's end point
+ * @return distance the result of the leftOfTest, 1 means leftOf, 0 means rightOf
+ * @type Number
+ * @version 1.0 (2007-04-30)
+ */
+function distFromLine(xpoint,ypoint,linex1,liney1,linex2,liney2) {
+ var dx = linex2 - linex1;
+ var dy = liney2 - liney1;
+ var distance = (dy * (xpoint - linex1) - dx * (ypoint - liney1)) / Math.sqrt(Math.pow(dx,2) + Math.pow(dy,2));
+ return distance;
+}
+
+/**
+ * calculates the angle between two vectors (lines)
+ * @param {Number} ax the x part of vector a
+ * @param {Number} ay the y part of vector a
+ * @param {Number} bx the x part of vector b
+ * @param {Number} by the y part of vector b
+ * @return angle the angle in radians
+ * @type Number
+ * @version 1.0 (2007-04-30)
+ * @credits <a href="http://www.mathe-online.at/mathint/vect2/i.html#Winkel">Mathe Online (Winkel)</a>
+ */
+function angleBetwTwoLines(ax,ay,bx,by) {
+ var angle = Math.acos((ax * bx + ay * by) / (Math.sqrt(Math.pow(ax,2) + Math.pow(ay,2)) * Math.sqrt(Math.pow(bx,2) + Math.pow(by,2))));
+ return angle;
+}
+
+/**
+ * calculates the bisector vector for two given vectors
+ * @param {Number} ax the x part of vector a
+ * @param {Number} ay the y part of vector a
+ * @param {Number} bx the x part of vector b
+ * @param {Number} by the y part of vector b
+ * @return c the resulting vector as an Array, c[0] is the x part of the vector, c[1] is the y part
+ * @type Array
+ * @version 1.0 (2007-04-30)
+ * @credits <a href="http://www.mathe-online.at/mathint/vect1/i.html#Winkelsymmetrale">Mathe Online (Winkelsymmetrale)</a>
+ * see #calcBisectorAngle
+ * */
+function calcBisectorVector(ax,ay,bx,by) {
+ var betraga = Math.sqrt(Math.pow(ax,2) + Math.pow(ay,2));
+ var betragb = Math.sqrt(Math.pow(bx,2) + Math.pow(by,2));
+ var c = new Array();
+ c[0] = ax / betraga + bx / betragb;
+ c[1] = ay / betraga + by / betragb;
+ return c;
+}
+
+/**
+ * calculates the bisector angle for two given vectors
+ * @param {Number} ax the x part of vector a
+ * @param {Number} ay the y part of vector a
+ * @param {Number} bx the x part of vector b
+ * @param {Number} by the y part of vector b
+ * @return angle the bisector angle in radians
+ * @type Number
+ * @version 1.0 (2007-04-30)
+ * @credits <a href="http://www.mathe-online.at/mathint/vect1/i.html#Winkelsymmetrale">Mathe Online (Winkelsymmetrale)</a>
+ * see #calcBisectorVector
+ * */
+function calcBisectorAngle(ax,ay,bx,by) {
+ var betraga = Math.sqrt(Math.pow(ax,2) + Math.pow(ay,2));
+ var betragb = Math.sqrt(Math.pow(bx,2) + Math.pow(by,2));
+ var c1 = ax / betraga + bx / betragb;
+ var c2 = ay / betraga + by / betragb;
+ var angle = toPolarDir(c1,c2);
+ return angle;
+}
+
+/**
+ * calculates the intersection point of two given lines
+ * @param {Number} line1x1 the x the start point of line 1
+ * @param {Number} line1y1 the y the start point of line 1
+ * @param {Number} line1x2 the x the end point of line 1
+ * @param {Number} line1y2 the y the end point of line 1
+ * @return interSectPoint the intersection point, interSectPoint.x contains x-part, interSectPoint.y the y-part of the resulting coordinate
+ * @type Object
+ * @version 1.0 (2007-04-30)
+ * @credits <a href="http://astronomy.swin.edu.au/~pbourke/geometry/lineline2d/">P. Bourke</a>
+ */
+function intersect2lines(line1x1,line1y1,line1x2,line1y2,line2x1,line2y1,line2x2,line2y2) {
+ var interSectPoint = new Object();
+ var denominator = (line2y2 - line2y1)*(line1x2 - line1x1) - (line2x2 - line2x1)*(line1y2 - line1y1);
+ if (denominator == 0) {
+ alert("lines are parallel");
+ }
+ else {
+ var ua = ((line2x2 - line2x1)*(line1y1 - line2y1) - (line2y2 - line2y1)*(line1x1 - line2x1)) / denominator;
+ var ub = ((line1x2 - line1x1)*(line1y1 - line2y1) - (line1y2 - line1y1)*(line1x1 - line2x1)) / denominator;
+ }
+ interSectPoint["x"] = line1x1 + ua * (line1x2 - line1x1);
+ interSectPoint["y"] = line1y1 + ua * (line1y2 - line1y1);
+ return interSectPoint;
+}
+
+/**
+ * reformats a given number to a string by adding separators at every third digit
+ * @param {String|Number} inputNumber the input number, can be of type number or string
+ * @param {String} separator the separator, e.g. ' or ,
+ * @return newString the intersection point, interSectPoint.x contains x-part, interSectPoint.y the y-part of the resulting coordinate
+ * @type String
+ * @version 1.0 (2007-04-30)
+ */
+function formatNumberString(inputNumber,separator) {
+ //check if of type string, if number, convert it to string
+ if (typeof(inputNumber) == "Number") {
+ var myTempString = inputNumber.toString();
+ }
+ else {
+ var myTempString = inputNumber;
+ }
+ var newString="";
+ //if it contains a comma, it will be split
+ var splitResults = myTempString.split(".");
+ var myCounter = splitResults[0].length;
+ if (myCounter > 3) {
+ while(myCounter > 0) {
+ if (myCounter > 3) {
+ newString = separator + splitResults[0].substr(myCounter - 3,3) + newString;
+ }
+ else {
+ newString = splitResults[0].substr(0,myCounter) + newString;
+ }
+ myCounter -= 3;
+ }
+ }
+ else {
+ newString = splitResults[0];
+ }
+ //concatenate if it contains a comma
+ if (splitResults[1]) {
+ newString = newString + "." + splitResults[1];
+ }
+ return newString;
+}
+
+/**
+ * writes a status text message out to a SVG text element's first child
+ * @param {String} statusText the text message to be displayed
+ * @version 1.0 (2007-04-30)
+ */
+ function statusChange(statusText) {
+ document.getElementById("statusText").firstChild.nodeValue = "Statusbar: " + statusText;
+}
+
+/**
+ * scales an SVG element, requires that the element has an x and y attribute (e.g. circle, ellipse, use element, etc.)
+ * @param {dom::Event} evt the evt object that triggered the scaling
+ * @param {Number} factor the scaling factor
+ * @version 1.0 (2007-04-30)
+ */
+function scaleObject(evt,factor) {
+ //reference to the currently selected object
+ var element = evt.currentTarget;
+ var myX = element.getAttributeNS(null,"x");
+ var myY = element.getAttributeNS(null,"y");
+ var newtransform = "scale(" + factor + ") translate(" + (myX * 1 / factor - myX) + " " + (myY * 1 / factor - myY) +")";
+ element.setAttributeNS(null,'transform', newtransform);
+}
+
+/**
+ * returns the transformation matrix (ctm) for the given node up to the root element
+ * the basic use case is to provide a wrapper function for the missing SVGLocatable.getTransformToElement method (missing in ASV3)
+ * @param {svg::SVGTransformable} node the node reference for the SVGElement the ctm is queried
+ * @return CTM the current transformation matrix from the given node to the root element
+ * @type svg::SVGMatrix
+ * @version 1.0 (2007-05-01)
+ * @credits <a href="http://www.kevlindev.com/tutorials/basics/transformations/toUserSpace/index…">Kevin Lindsey (toUserSpace)</a>
+ * @see #getTransformToElement
+ */
+function getTransformToRootElement(node) {
+ try {
+ //this part is for fully conformant players (like Opera, Batik, Firefox, Safari ...)
+ var CTM = node.getTransformToElement(document.documentElement);
+ }
+ catch (ex) {
+ //this part is for ASV3 or other non-conformant players
+ // Initialize our CTM the node's Current Transformation Matrix
+ var CTM = node.getCTM();
+ // Work our way through the ancestor nodes stopping at the SVG Document
+ while ( ( node = node.parentNode ) != document ) {
+ // Multiply the new CTM to the one with what we have accumulated so far
+ CTM = node.getCTM().multiply(CTM);
+ }
+ }
+ return CTM;
+}
+
+/**
+ * returns the transformation matrix (ctm) for the given dom::Node up to a different dom::Node
+ * the basic use case is to provide a wrapper function for the missing SVGLocatable.getTransformToElement method (missing in ASV3)
+ * @param {svg::SVGTransformable} node the node reference for the element the where the ctm should be calculated from
+ * @param {svg::SVGTransformable} targetNode the target node reference for the element the ctm should be calculated to
+ * @return CTM the current transformation matrix from the given node to the target element
+ * @type svg::SVGMatrix
+ * @version 1.0 (2007-05-01)
+ * @credits <a href="http://www.kevlindev.com/tutorials/basics/transformations/toUserSpace/index…">Kevin Lindsey (toUserSpace)</a>
+ * @see #getTransformToRootElement
+ */
+function getTransformToElement(node,targetNode) {
+ try {
+ //this part is for fully conformant players
+ var CTM = node.getTransformToElement(targetNode);
+ }
+ catch (ex) {
+ //this part is for ASV3 or other non-conformant players
+ // Initialize our CTM the node's Current Transformation Matrix
+ var CTM = node.getCTM();
+ // Work our way through the ancestor nodes stopping at the SVG Document
+ while ( ( node = node.parentNode ) != targetNode ) {
+ // Multiply the new CTM to the one with what we have accumulated so far
+ CTM = node.getCTM().multiply(CTM);
+ }
+ }
+ return CTM;
+}
+
+/**
+ * converts HSV to RGB values
+ * @param {Number} hue the hue value (between 0 and 360)
+ * @param {Number} sat the saturation value (between 0 and 1)
+ * @param {Number} val the value value (between 0 and 1)
+ * @return rgbArr the rgb values (associative array or object, the keys are: red,green,blue), all values are scaled between 0 and 255
+ * @type Object
+ * @version 1.0 (2007-05-01)
+ * @see #rgb2hsv
+ */
+function hsv2rgb(hue,sat,val) {
+ var rgbArr = new Object();
+ if ( sat == 0) {
+ rgbArr["red"] = Math.round(val * 255);
+ rgbArr["green"] = Math.round(val * 255);
+ rgbArr["blue"] = Math.round(val * 255);
+ }
+ else {
+ var h = hue / 60;
+ var i = Math.floor(h);
+ var f = h - i;
+ if (i % 2 == 0) {
+ f = 1 - f;
+ }
+ var m = val * (1 - sat);
+ var n = val * (1 - sat * f);
+ switch(i) {
+ case 0:
+ rgbArr["red"] = val;
+ rgbArr["green"] = n;
+ rgbArr["blue"] = m;
+ break;
+ case 1:
+ rgbArr["red"] = n;
+ rgbArr["green"] = val;
+ rgbArr["blue"] = m;
+ break;
+ case 2:
+ rgbArr["red"] = m;
+ rgbArr["green"] = val;
+ rgbArr["blue"] = n;
+ break;
+ case 3:
+ rgbArr["red"] = m;
+ rgbArr["green"] = n;
+ rgbArr["blue"] = val;
+ break;
+ case 4:
+ rgbArr["red"] = n;
+ rgbArr["green"] = m;
+ rgbArr["blue"] = val;
+ break;
+ case 5:
+ rgbArr["red"] = val;
+ rgbArr["green"] = m;
+ rgbArr["blue"] = n;
+ break;
+ case 6:
+ rgbArr["red"] = val;
+ rgbArr["green"] = n;
+ rgbArr["blue"] = m;
+ break;
+ }
+ rgbArr["red"] = Math.round(rgbArr["red"] * 255);
+ rgbArr["green"] = Math.round(rgbArr["green"] * 255);
+ rgbArr["blue"] = Math.round(rgbArr["blue"] * 255);
+ }
+ return rgbArr;
+}
+
+/**
+ * converts RGB to HSV values
+ * @param {Number} red the hue value (between 0 and 255)
+ * @param {Number} green the saturation value (between 0 and 255)
+ * @param {Number} blue the value value (between 0 and 255)
+ * @return hsvArr the hsv values (associative array or object, the keys are: hue (0-360),sat (0-1),val (0-1))
+ * @type Object
+ * @version 1.0 (2007-05-01)
+ * @see #hsv2rgb
+ */
+function rgb2hsv(red,green,blue) {
+ var hsvArr = new Object();
+ red = red / 255;
+ green = green / 255;
+ blue = blue / 255;
+ myMax = Math.max(red, Math.max(green,blue));
+ myMin = Math.min(red, Math.min(green,blue));
+ v = myMax;
+ if (myMax > 0) {
+ s = (myMax - myMin) / myMax;
+ }
+ else {
+ s = 0;
+ }
+ if (s > 0) {
+ myDiff = myMax - myMin;
+ rc = (myMax - red) / myDiff;
+ gc = (myMax - green) / myDiff;
+ bc = (myMax - blue) / myDiff;
+ if (red == myMax) {
+ h = (bc - gc) / 6;
+ }
+ if (green == myMax) {
+ h = (2 + rc - bc) / 6;
+ }
+ if (blue == myMax) {
+ h = (4 + gc - rc) / 6;
+ }
+ }
+ else {
+ h = 0;
+ }
+ if (h < 0) {
+ h += 1;
+ }
+ hsvArr["hue"] = Math.round(h * 360);
+ hsvArr["sat"] = s;
+ hsvArr["val"] = v;
+ return hsvArr;
+}
+
+/**
+ * populates an array such that it can be addressed by both a key or an index nr,
+ * note that both Arrays need to be of the same length
+ * @param {Array} arrayKeys the array containing the keys
+ * @param {Array} arrayValues the array containing the values
+ * @return returnArray the resulting array containing both associative values and also a regular indexed array
+ * @type Array
+ * @version 1.0 (2007-05-01)
+ */
+function arrayPopulate(arrayKeys,arrayValues) {
+ var returnArray = new Array();
+ if (arrayKeys.length != arrayValues.length) {
+ alert("error: arrays do not have the same length!");
+ }
+ else {
+ for (i=0;i<arrayKeys.length;i++) {
+ returnArray[arrayKeys[i]] = arrayValues[i];
+ }
+ }
+ return returnArray;
+}
+
+/**
+ * Wrapper object for network requests, uses getURL or XMLHttpRequest depending on availability
+ * The callBackFunction receives a XML or text node representing the rootElement
+ * of the fragment received or the return text, depending on the returnFormat.
+ * See also the following <a href="http://www.carto.net/papers/svg/network_requests/">documentation</a>.
+ * @class this is a wrapper object to provide network request functionality (get|post)
+ * @param {String} url the URL/IRI of the network resource to be called
+ * @param {Function|Object} callBackFunction the callBack function or object that is called after the data was received, in case of an object, the method 'receiveData' is called; both the function and the object's 'receiveData' method get 2 return parameters: 'node.firstChild'|text (the root element of the XML or text resource), this.additionalParams (if defined)
+ * @param {String} returnFormat the return format, either 'xml' or 'json' (or text)
+ * @param {String} method the method of the network request, either 'get' or 'post'
+ * @param {String|Undefined} postText the String containing the post text (optional) or Undefined (if not a 'post' request)
+ * @param {Object|Array|String|Number|Undefined} additionalParams additional parameters that will be passed to the callBackFunction or object (optional) or Undefined
+ * @return a new getData instance
+ * @type getData
+ * @constructor
+ * @version 1.0 (2007-02-23)
+ */
+function getData(url,callBackFunction,returnFormat,method,postText,additionalParams) {
+ this.url = url;
+ this.callBackFunction = callBackFunction;
+ this.returnFormat = returnFormat;
+ this.method = method;
+ this.additionalParams = additionalParams;
+ if (method != "get" && method != "post") {
+ alert("Error in network request: parameter 'method' must be 'get' or 'post'");
+ }
+ this.postText = postText;
+ this.xmlRequest = null; //@private reference to the XMLHttpRequest object
+}
+
+/**
+ * triggers the network request defined in the constructor
+ */
+getData.prototype.getData = function() {
+ //call getURL() if available
+ if (window.getURL) {
+ if (this.method == "get") {
+ getURL(this.url,this);
+ }
+ if (this.method == "post") {
+ postURL(this.url,this.postText,this);
+ }
+ }
+ //or call XMLHttpRequest() if available
+ else if (window.XMLHttpRequest) {
+ var _this = this;
+ this.xmlRequest = new XMLHttpRequest();
+ if (this.method == "get") {
+ if (this.returnFormat == "xml") {
+ this.xmlRequest.overrideMimeType("text/xml");
+ }
+ this.xmlRequest.open("GET",this.url,true);
+ }
+ if (this.method == "post") {
+ this.xmlRequest.open("POST",this.url,true);
+ }
+ this.xmlRequest.onreadystatechange = function() {_this.handleEvent()};
+ if (this.method == "get") {
+ this.xmlRequest.send(null);
+ }
+ if (this.method == "post") {
+ //test if postText exists and is of type string
+ var reallyPost = true;
+ if (!this.postText) {
+ reallyPost = false;
+ alert("Error in network post request: missing parameter 'postText'!");
+ }
+ if (typeof(this.postText) != "string") {
+ reallyPost = false;
+ alert("Error in network post request: parameter 'postText' has to be of type 'string')");
+ }
+ if (reallyPost) {
+ this.xmlRequest.send(this.postText);
+ }
+ }
+ }
+ //write an error message if neither method is available
+ else {
+ alert("your browser/svg viewer neither supports window.getURL nor window.XMLHttpRequest!");
+ }
+}
+
+/**
+ * this is the callback method for the getURL() or postURL() case
+ * @private
+ */
+getData.prototype.operationComplete = function(data) {
+ //check if data has a success property
+ if (data.success) {
+ //parse content of the XML format to the variable "node"
+ if (this.returnFormat == "xml") {
+ //convert the text information to an XML node and get the first child
+ var node = parseXML(data.content,document);
+ //distinguish between a callback function and an object
+ if (typeof(this.callBackFunction) == "function") {
+ this.callBackFunction(node.firstChild,this.additionalParams);
+ }
+ if (typeof(this.callBackFunction) == "object") {
+ this.callBackFunction.receiveData(node.firstChild,this.additionalParams);
+ }
+ }
+ if (this.returnFormat == "json") {
+ if (typeof(this.callBackFunction) == "function") {
+ this.callBackFunction(data.content,this.additionalParams);
+ }
+ if (typeof(this.callBackFunction) == "object") {
+ this.callBackFunction.receiveData(data.content,this.additionalParams);
+ }
+ }
+ }
+ else {
+ alert("something went wrong with dynamic loading of geometry!");
+ }
+}
+
+/**
+ * this is the callback method for the XMLHttpRequest case
+ * @private
+ */
+getData.prototype.handleEvent = function() {
+ if (this.xmlRequest.readyState == 4) {
+ if (this.returnFormat == "xml") {
+ //we need to import the XML node first
+ var importedNode = document.importNode(this.xmlRequest.responseXML.documentElement,true);
+ if (typeof(this.callBackFunction) == "function") {
+ this.callBackFunction(importedNode,this.additionalParams);
+ }
+ if (typeof(this.callBackFunction) == "object") {
+ this.callBackFunction.receiveData(importedNode,this.additionalParams);
+ }
+ }
+ if (this.returnFormat == "json") {
+ if (typeof(this.callBackFunction) == "function") {
+ this.callBackFunction(this.xmlRequest.responseText,this.additionalParams);
+ }
+ if (typeof(this.callBackFunction) == "object") {
+ this.callBackFunction.receiveData(this.xmlRequest.responseText,this.additionalParams);
+ }
+ }
+ }
+}
+
+/**
+ * Serializes an XML node and returns a string representation. Wrapper function to hide implementation differences.
+ * This can be used for debugging purposes or to post data to a server or network resource.
+ * @param {dom::Node} node the DOM node reference
+ * @return textRepresentation the String representation of the XML node
+ * @type String
+ * @version 1.0 (2007-05-01)
+ * @see getData
+ */
+function serializeNode(node) {
+ if (typeof XMLSerializer != 'undefined') {
+ return new XMLSerializer().serializeToString(node);
+ }
+ else if (typeof node.xml != 'undefined') {
+ return node.xml;
+ }
+ else if (typeof printNode != 'undefined') {
+ return printNode(node);
+ }
+ else if (typeof Packages != 'undefined') {
+ try {
+ var stringWriter = new java.io.StringWriter();
+ Packages.org.apache.batik.dom.util.DOMUtilities.writeNode(node,stringWriter);
+ return stringWriter.toString();
+ }
+ catch (e) {
+ alert("Sorry, your SVG viewer does not support the printNode/serialize function.");
+ return '';
+ }
+ }
+ else {
+ alert("Sorry, your SVG viewer does not support the printNode/serialize function.");
+ return '';
+ }
+}
+
+/**
+ * Starts a SMIL animation element with the given id by triggering the '.beginElement()' method.
+ * This is a convenience (shortcut) function.
+ * @param {String} id a valid id of a valid SMIL animation element
+ * @version 1.0 (2007-05-01)
+ */
+//starts an animtion with the given id
+//this function is useful in combination with window.setTimeout()
+function startAnimation(id) {
+ document.getElementById(id).beginElement();
+}
diff -r a6e3f4cae4ce -r cdd8d520f3c7 static/scripts/timer.js
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/static/scripts/timer.js Tue Apr 13 11:23:19 2010 -0400
@@ -0,0 +1,74 @@
+// source/credits: "Algorithm": http://www.codingforums.com/showthread.php?s=&threadid=10531
+// The constructor should be called with
+// the parent object (optional, defaults to window).
+
+function Timer(){
+ this.obj = (arguments.length)?arguments[0]:window;
+ return this;
+}
+
+// The set functions should be called with:
+// - The name of the object method (as a string) (required)
+// - The millisecond delay (required)
+// - Any number of extra arguments, which will all be
+// passed to the method when it is evaluated.
+
+Timer.prototype.setInterval = function(func, msec){
+ var i = Timer.getNew();
+ var t = Timer.buildCall(this.obj, i, arguments);
+ Timer.set[i].timer = window.setInterval(t,msec);
+ return i;
+}
+Timer.prototype.setTimeout = function(func, msec){
+ var i = Timer.getNew();
+ Timer.buildCall(this.obj, i, arguments);
+ Timer.set[i].timer = window.setTimeout("Timer.callOnce("+i+");",msec);
+ return i;
+}
+
+// The clear functions should be called with
+// the return value from the equivalent set function.
+
+Timer.prototype.clearInterval = function(i){
+ if(!Timer.set[i]) return;
+ window.clearInterval(Timer.set[i].timer);
+ Timer.set[i] = null;
+}
+Timer.prototype.clearTimeout = function(i){
+ if(!Timer.set[i]) return;
+ window.clearTimeout(Timer.set[i].timer);
+ Timer.set[i] = null;
+}
+
+// Private data
+
+Timer.set = new Array();
+Timer.buildCall = function(obj, i, args){
+ var t = "";
+ Timer.set[i] = new Array();
+ if(obj != window){
+ Timer.set[i].obj = obj;
+ t = "Timer.set["+i+"].obj.";
+ }
+ t += args[0]+"(";
+ if(args.length > 2){
+ Timer.set[i][0] = args[2];
+ t += "Timer.set["+i+"][0]";
+ for(var j=1; (j+2)<args.length; j++){
+ Timer.set[i][j] = args[j+2];
+ t += ", Timer.set["+i+"]["+j+"]";
+ }}
+ t += ");";
+ Timer.set[i].call = t;
+ return t;
+}
+Timer.callOnce = function(i){
+ if(!Timer.set[i]) return;
+ eval(Timer.set[i].call);
+ Timer.set[i] = null;
+}
+Timer.getNew = function(){
+ var i = 0;
+ while(Timer.set[i]) i++;
+ return i;
+}
\ No newline at end of file
diff -r a6e3f4cae4ce -r cdd8d520f3c7 tools/rgenetics/rgGRR.py
--- a/tools/rgenetics/rgGRR.py Tue Apr 13 11:17:30 2010 -0400
+++ b/tools/rgenetics/rgGRR.py Tue Apr 13 11:23:19 2010 -0400
@@ -1,1096 +1,1145 @@
-"""
-# july 2009: Need to see outliers so need to draw them last?
-# could use clustering on the zscores to guess real relationships for unrelateds
-# but definitely need to draw last
-# added MAX_SHOW_ROWS to limit the length of the main report page
-# Changes for Galaxy integration
-# added more robust knuth method for one pass mean and sd
-# no difference really - let's use scipy.mean() and scipy.std() instead...
-# fixed labels and changed to .xls for outlier reports so can open in excel
-# interesting - with a few hundred subjects, 5k gives good resolution
-# and 100k gives better but not by much
-# TODO remove non autosomal markers
-# TODO it would be best if label had the zmean and zsd as these are what matter for
-# outliers rather than the group mean/sd
-# mods to rgGRR.py from channing CVS which John Ziniti has rewritten to produce SVG plots
-# to make a Galaxy tool - we need the table of mean and SD for interesting pairs, the SVG and the log
-# so the result should be an HTML file
-
-# rgIBS.py
-# use a random subset of markers for a quick ibs
-# to identify sample dups and closely related subjects
-# try snpMatrix and plink and see which one works best for us?
-# abecasis grr plots mean*sd for every subject to show clusters
-# mods june 23 rml to avoid non-autosomal markers
-# we seem to be distinguishing parent-child by gender - 2 clouds!
-
-
-snpMatrix from David Clayton has:
-ibs.stats function to calculate the identity-by-state stats of a group of samples
-Description
-Given a snp.matrix-class or a X.snp.matrix-class object with N samples, calculates some statistics
-about the relatedness of every pair of samples within.
-
-Usage
-ibs.stats(x)
-8 ibs.stats
-Arguments
-x a snp.matrix-class or a X.snp.matrix-class object containing N samples
-Details
-No-calls are excluded from consideration here.
-Value
-A data.frame containing N(N - 1)/2 rows, where the row names are the sample name pairs separated
-by a comma, and the columns are:
-Count count of identical calls, exclusing no-calls
-Fraction fraction of identical calls comparied to actual calls being made in both samples
-Warning
-In some applications, it may be preferable to subset a (random) selection of SNPs first - the
-calculation
-time increases as N(N - 1)M/2 . Typically for N = 800 samples and M = 3000 SNPs, the
-calculation time is about 1 minute. A full GWA scan could take hours, and quite unnecessary for
-simple applications such as checking for duplicate or related samples.
-Note
-This is mostly written to find mislabelled and/or duplicate samples.
-Illumina indexes their SNPs in alphabetical order so the mitochondria SNPs comes first - for most
-purpose it is undesirable to use these SNPs for IBS purposes.
-TODO: Worst-case S4 subsetting seems to make 2 copies of a large object, so one might want to
-subset before rbind(), etc; a future version of this routine may contain a built-in subsetting facility
-"""
-import sys,os,time,random,string,copy,optparse
-
-try:
- set
-except NameError:
- from Sets import Set as set
-
-from rgutils import timenow
-import plinkbinJZ
-
-
-opts = None
-verbose = False
-
-showPolygons = False
-
-class NullDevice:
- def write(self, s):
- pass
-
-tempstderr = sys.stderr # save
-sys.stderr = NullDevice()
-# need to avoid blather about deprecation and other strange stuff from scipy
-# the current galaxy job runner assumes that
-# the job is in error if anything appears on sys.stderr
-# grrrrr. James wants to keep it that way instead of using the
-# status flag for some strange reason. Presumably he doesn't use R or (in this case, scipy)
-import numpy
-import scipy
-from scipy import weave
-
-
-sys.stderr=tempstderr
-
-
-PROGNAME = os.path.split(sys.argv[0])[-1]
-X_AXIS_LABEL = 'Mean Alleles Shared'
-Y_AXIS_LABEL = 'SD Alleles Shared'
-LEGEND_ALIGN = 'topleft'
-LEGEND_TITLE = 'Relationship'
-DEFAULT_SYMBOL_SIZE = 1.0 # default symbol size
-DEFAULT_SYMBOL_SIZE = 0.5 # default symbol size
-
-### Some colors for R/rpy
-R_BLACK = 1
-R_RED = 2
-R_GREEN = 3
-R_BLUE = 4
-R_CYAN = 5
-R_PURPLE = 6
-R_YELLOW = 7
-R_GRAY = 8
-
-### ... and some point-styles
-
-###
-PLOT_HEIGHT = 600
-PLOT_WIDTH = 1150
-
-
-#SVG_COLORS = ('black', 'darkblue', 'blue', 'deepskyblue', 'firebrick','maroon','crimson')
-#SVG_COLORS = ('cyan','dodgerblue','mediumpurple', 'fuchsia', 'red','gold','gray')
-SVG_COLORS = ('cyan','dodgerblue','mediumpurple','forestgreen', 'lightgreen','gold','gray')
-# dupe,parentchild,sibpair,halfsib,parents,unrel,unkn
-#('orange', 'red', 'green', 'chartreuse', 'blue', 'purple', 'gray')
-
-OUTLIERS_HEADER = 'Mean\tSdev\tZ(mean)\tZ(sdev)\tFID1\tIID1\tFID2\tIID2\tMean(Rel_Mean)\tSdev(Rel_Mean)\tMean(Rel_Sdev)\tSdev(Rel_Sdev)\n'
-OUTLIERS_HEADER_list = ['Mean','Sdev','ZMean','ZSdev','FID1','IID1','FID2','IID2',
-'RGMean_M','RGMean_SD','RGSD_M','RGSD_SD']
-TABLE_HEADER='fid1 iid1\tfid2 iid2\tmean\tsdev\tzmean\tzsdev\tgeno\trelcode\n'
-
-
-### Relationship codes, text, and lookups/mappings
-N_RELATIONSHIP_TYPES = 7
-REL_DUPE, REL_PARENTCHILD, REL_SIBS, REL_HALFSIBS, REL_RELATED, REL_UNRELATED, REL_UNKNOWN = range(N_RELATIONSHIP_TYPES)
-REL_LOOKUP = {
- REL_DUPE: ('dupe', R_BLUE, 1),
- REL_PARENTCHILD: ('parentchild', R_YELLOW, 1),
- REL_SIBS: ('sibpairs', R_RED, 1),
- REL_HALFSIBS: ('halfsibs', R_GREEN, 1),
- REL_RELATED: ('parents', R_PURPLE, 1),
- REL_UNRELATED: ('unrelated', R_CYAN, 1),
- REL_UNKNOWN: ('unknown', R_GRAY, 1),
- }
-OUTLIER_STDEVS = {
- REL_DUPE: 2,
- REL_PARENTCHILD: 2,
- REL_SIBS: 2,
- REL_HALFSIBS: 2,
- REL_RELATED: 2,
- REL_UNRELATED: 3,
- REL_UNKNOWN: 2,
- }
-# note now Z can be passed in
-
-REL_STATES = [REL_LOOKUP[r][0] for r in range(N_RELATIONSHIP_TYPES)]
-REL_COLORS = SVG_COLORS
-REL_POINTS = [REL_LOOKUP[r][2] for r in range(N_RELATIONSHIP_TYPES)]
-
-DEFAULT_MAX_SAMPLE_SIZE = 10000
-
-REF_COUNT_HOM1 = 3
-REF_COUNT_HET = 2
-REF_COUNT_HOM2 = 1
-MISSING = 0
-MAX_SHOW_ROWS = 100 # framingham has millions - delays showing output page - so truncate and explain
-MARKER_PAIRS_PER_SECOND_SLOW = 15000000.0
-MARKER_PAIRS_PER_SECOND_FAST = 70000000.0
-
-
-galhtmlprefix = """<?xml version="1.0" encoding="utf-8" ?>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta name="generator" content="Galaxy %s tool output - see http://g2.trac.bx.psu.edu/" />
-<title></title>
-<link rel="stylesheet" href="/static/style/base.css" type="text/css" />
-</head>
-<body>
-<div class="document">
-"""
-
-
-SVG_HEADER = '''<?xml version="1.0" standalone="no"?>
-<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.2//EN" "http://www.w3.org/Graphics/SVG/1.2/DTD/svg12.dtd">
-
-<svg width="1280" height="800"
- xmlns="http://www.w3.org/2000/svg" version="1.2"
- xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 1280 800" onload="init()">
-
- <script type="text/ecmascript" xlink:href="/static/scripts/tools/rgenetics/checkbox_and_radiobutton.js"/>
- <script type="text/ecmascript" xlink:href="/static/scripts/tools/rgenetics/helper_functions.js"/>
- <script type="text/ecmascript" xlink:href="/static/scripts/tools/rgenetics/timer.js"/>
- <script type="text/ecmascript">
- <![CDATA[
- var checkBoxes = new Array();
- var radioGroupBandwidth;
- var colours = ['%s','%s','%s','%s','%s','%s','%s'];
- function init() {
- var style = {"font-family":"Arial,Helvetica", "fill":"black", "font-size":12};
- var dist = 12;
- var yOffset = 4;
-
- //A checkBox for each relationship type dupe,parentchild,sibpair,halfsib,parents,unrel,unkn
- checkBoxes["dupe"] = new checkBox("dupe","checkboxes",20,40,"cbRect","cbCross",true,"Duplicate",style,dist,yOffset,undefined,hideShowLayer);
- checkBoxes["parentchild"] = new checkBox("parentchild","checkboxes",20,60,"cbRect","cbCross",true,"Parent-Child",style,dist,yOffset,undefined,hideShowLayer);
- checkBoxes["sibpairs"] = new checkBox("sibpairs","checkboxes",20,80,"cbRect","cbCross",true,"Sib-pairs",style,dist,yOffset,undefined,hideShowLayer);
- checkBoxes["halfsibs"] = new checkBox("halfsibs","checkboxes",20,100,"cbRect","cbCross",true,"Half-sibs",style,dist,yOffset,undefined,hideShowLayer);
- checkBoxes["parents"] = new checkBox("parents","checkboxes",20,120,"cbRect","cbCross",true,"Parents",style,dist,yOffset,undefined,hideShowLayer);
- checkBoxes["unrelated"] = new checkBox("unrelated","checkboxes",20,140,"cbRect","cbCross",true,"Unrelated",style,dist,yOffset,undefined,hideShowLayer);
- checkBoxes["unknown"] = new checkBox("unknown","checkboxes",20,160,"cbRect","cbCross",true,"Unknown",style,dist,yOffset,undefined,hideShowLayer);
-
- }
-
- function hideShowLayer(id, status, label) {
- var vis = "hidden";
- if (status) {
- vis = "visible";
- }
- document.getElementById(id).setAttributeNS(null, 'visibility', vis);
- }
-
- function showBTT(evt, rel, mm, dm, md, dd, n, mg, dg, lg, hg) {
- var x = parseInt(evt.pageX)-250;
- var y = parseInt(evt.pageY)-110;
- switch(rel) {
- case 0:
- fill = colours[rel];
- relt = "dupe";
- break;
- case 1:
- fill = colours[rel];
- relt = "parentchild";
- break;
- case 2:
- fill = colours[rel];
- relt = "sibpairs";
- break;
- case 3:
- fill = colours[rel];
- relt = "halfsibs";
- break;
- case 4:
- fill = colours[rel];
- relt = "parents";
- break;
- case 5:
- fill = colours[rel];
- relt = "unrelated";
- break;
- case 6:
- fill = colours[rel];
- relt = "unknown";
- break;
- default:
- fill = "cyan";
- relt = "ERROR_CODE: "+rel;
- }
-
- document.getElementById("btRel").textContent = "GROUP: "+relt;
- document.getElementById("btMean").textContent = "mean="+mm+" +/- "+dm;
- document.getElementById("btSdev").textContent = "sdev="+dm+" +/- "+dd;
- document.getElementById("btPair").textContent = "npairs="+n;
- document.getElementById("btGeno").textContent = "ngenos="+mg+" +/- "+dg+" (min="+lg+", max="+hg+")";
- document.getElementById("btHead").setAttribute('fill', fill);
-
- var tt = document.getElementById("btTip");
- tt.setAttribute("transform", "translate("+x+","+y+")");
- tt.setAttribute('visibility', 'visible');
- }
-
- function showOTT(evt, rel, s1, s2, mean, sdev, ngeno, rmean, rsdev) {
- var x = parseInt(evt.pageX)-150;
- var y = parseInt(evt.pageY)-180;
-
- switch(rel) {
- case 0:
- fill = colours[rel];
- relt = "dupe";
- break;
- case 1:
- fill = colours[rel];
- relt = "parentchild";
- break;
- case 2:
- fill = colours[rel];
- relt = "sibpairs";
- break;
- case 3:
- fill = colours[rel];
- relt = "halfsibs";
- break;
- case 4:
- fill = colours[rel];
- relt = "parents";
- break;
- case 5:
- fill = colours[rel];
- relt = "unrelated";
- break;
- case 6:
- fill = colours[rel];
- relt = "unknown";
- break;
- default:
- fill = "cyan";
- relt = "ERROR_CODE: "+rel;
- }
-
- document.getElementById("otRel").textContent = "PAIR: "+relt;
- document.getElementById("otS1").textContent = "s1="+s1;
- document.getElementById("otS2").textContent = "s2="+s2;
- document.getElementById("otMean").textContent = "mean="+mean;
- document.getElementById("otSdev").textContent = "sdev="+sdev;
- document.getElementById("otGeno").textContent = "ngenos="+ngeno;
- document.getElementById("otRmean").textContent = "relmean="+rmean;
- document.getElementById("otRsdev").textContent = "relsdev="+rsdev;
- document.getElementById("otHead").setAttribute('fill', fill);
-
- var tt = document.getElementById("otTip");
- tt.setAttribute("transform", "translate("+x+","+y+")");
- tt.setAttribute('visibility', 'visible');
- }
-
- function hideBTT(evt) {
- document.getElementById("btTip").setAttributeNS(null, 'visibility', 'hidden');
- }
-
- function hideOTT(evt) {
- document.getElementById("otTip").setAttributeNS(null, 'visibility', 'hidden');
- }
-
- ]]>
- </script>
- <defs>
- <!-- symbols for check boxes -->
- <symbol id="cbRect" overflow="visible">
- <rect x="-5" y="-5" width="10" height="10" fill="white" stroke="dimgray" stroke-width="1" cursor="pointer"/>
- </symbol>
- <symbol id="cbCross" overflow="visible">
- <g pointer-events="none" stroke="black" stroke-width="1">
- <line x1="-3" y1="-3" x2="3" y2="3"/>
- <line x1="3" y1="-3" x2="-3" y2="3"/>
- </g>
- </symbol>
- </defs>
-
-<desc>Developer Works Dynamic Scatter Graph Scaling Example</desc>
-
-<!-- Now Draw the main X and Y axis -->
-<g style="stroke-width:1.0; stroke:black; shape-rendering:crispEdges">
- <!-- X Axis top and bottom -->
- <path d="M 100 100 L 1250 100 Z"/>
- <path d="M 100 700 L 1250 700 Z"/>
-
- <!-- Y Axis left and right -->
- <path d="M 100 100 L 100 700 Z"/>
- <path d="M 1250 100 L 1250 700 Z"/>
-</g>
-
-<g transform="translate(100,100)">
-
- <!-- Grid Lines -->
- <g style="fill:none; stroke:#dddddd; stroke-width:1; stroke-dasharray:2,2; text-anchor:end; shape-rendering:crispEdges">
-
- <!-- Vertical grid lines -->
- <line x1="125" y1="0" x2="115" y2="600" />
- <line x1="230" y1="0" x2="230" y2="600" />
- <line x1="345" y1="0" x2="345" y2="600" />
- <line x1="460" y1="0" x2="460" y2="600" />
- <line x1="575" y1="0" x2="575" y2="600" style="stroke-dasharray:none;" />
- <line x1="690" y1="0" x2="690" y2="600" />
- <line x1="805" y1="0" x2="805" y2="600" />
- <line x1="920" y1="0" x2="920" y2="600" />
- <line x1="1035" y1="0" x2="1035" y2="600" />
-
- <!-- Horizontal grid lines -->
- <line x1="0" y1="60" x2="1150" y2="60" />
- <line x1="0" y1="120" x2="1150" y2="120" />
- <line x1="0" y1="180" x2="1150" y2="180" />
- <line x1="0" y1="240" x2="1150" y2="240" />
- <line x1="0" y1="300" x2="1150" y2="300" style="stroke-dasharray:none;" />
- <line x1="0" y1="360" x2="1150" y2="360" />
- <line x1="0" y1="420" x2="1150" y2="420" />
- <line x1="0" y1="480" x2="1150" y2="480" />
- <line x1="0" y1="540" x2="1150" y2="540" />
- </g>
-
- <!-- Legend -->
- <g style="fill:black; stroke:none" font-size="12" font-family="Arial" transform="translate(25,25)">
- <rect width="160" height="270" style="fill:none; stroke:black; shape-rendering:crispEdges" />
- <text x="5" y="20" style="fill:black; stroke:none;" font-size="13" font-weight="bold">Given Pair Relationship</text>
- <rect x="120" y="35" width="10" height="10" fill="%s" stroke="%s" stroke-width="1" cursor="pointer"/>
- <rect x="120" y="55" width="10" height="10" fill="%s" stroke="%s" stroke-width="1" cursor="pointer"/>
- <rect x="120" y="75" width="10" height="10" fill="%s" stroke="%s" stroke-width="1" cursor="pointer"/>
- <rect x="120" y="95" width="10" height="10" fill="%s" stroke="%s" stroke-width="1" cursor="pointer"/>
- <rect x="120" y="115" width="10" height="10" fill="%s" stroke="%s" stroke-width="1" cursor="pointer"/>
- <rect x="120" y="135" width="10" height="10" fill="%s" stroke="%s" stroke-width="1" cursor="pointer"/>
- <rect x="120" y="155" width="10" height="10" fill="%s" stroke="%s" stroke-width="1" cursor="pointer"/>
- <text x="15" y="195" style="fill:black; stroke:none" font-size="12" font-family="Arial" >Zscore gt 15</text>
- <circle cx="125" cy="192" r="6" style="stroke:red; fill:gold; fill-opacity:1.0; stroke-width:1;"/>
- <text x="15" y="215" style="fill:black; stroke:none" font-size="12" font-family="Arial" >Zscore 4 to 15</text>
- <circle cx="125" cy="212" r="3" style="stroke:gold; fill:gold; fill-opacity:1.0; stroke-width:1;"/>
- <text x="15" y="235" style="fill:black; stroke:none" font-size="12" font-family="Arial" >Zscore lt 4</text>
- <circle cx="125" cy="232" r="2" style="stroke:gold; fill:gold; fill-opacity:1.0; stroke-width:1;"/>
- <g id="checkboxes">
- </g>
- </g>
-
-
- <g style='fill:black; stroke:none' font-size="17" font-family="Arial">
- <!-- X Axis Labels -->
- <text x="480" y="660">Mean Alleles Shared</text>
- <text x="0" y="630" >1.0</text>
- <text x="277" y="630" >1.25</text>
- <text x="564" y="630" >1.5</text>
- <text x="842" y="630" >1.75</text>
- <text x="1140" y="630" >2.0</text>
- </g>
-
- <g transform="rotate(270)" style="fill:black; stroke:none" font-size="17" font-family="Arial">
- <!-- Y Axis Labels -->
- <text x="-350" y="-40">SD Alleles Shared</text>
- <text x="-20" y="-10" >1.0</text>
- <text x="-165" y="-10" >0.75</text>
- <text x="-310" y="-10" >0.5</text>
- <text x="-455" y="-10" >0.25</text>
- <text x="-600" y="-10" >0.0</text>
- </g>
-
-<!-- Plot Title -->
-<g style="fill:black; stroke:none" font-size="18" font-family="Arial">
- <text x="425" y="-30">%s</text>
-</g>
-
-<!-- One group/layer of points for each relationship type -->
-'''
-
-SVG_FOOTER = '''
-<!-- End of Data -->
-</g>
-<g id="btTip" visibility="hidden" style="stroke-width:1.0; fill:black; stroke:none;" font-size="10" font-family="Arial">
- <rect width="250" height="110" style="fill:silver" rx="2" ry="2"/>
- <rect id="btHead" width="250" height="20" rx="2" ry="2" />
- <text id="btRel" y="14" x="85">unrelated</text>
- <text id="btMean" y="40" x="4">mean=1.5 +/- 0.04</text>
- <text id="btSdev" y="60" x="4">sdev=0.7 +/- 0.03</text>
- <text id="btPair" y="80" x="4">npairs=1152</text>
- <text id="btGeno" y="100" x="4">ngenos=4783 +/- 24 (min=1000, max=5000)</text>
-</g>
-
-<g id="otTip" visibility="hidden" style="stroke-width:1.0; fill:black; stroke:none;" font-size="10" font-family="Arial">
- <rect width="150" height="180" style="fill:silver" rx="2" ry="2"/>
- <rect id="otHead" width="150" height="20" rx="2" ry="2" />
- <text id="otRel" y="14" x="40">sibpairs</text>
- <text id="otS1" y="40" x="4">s1=fid1,iid1</text>
- <text id="otS2" y="60" x="4">s2=fid2,iid2</text>
- <text id="otMean" y="80" x="4">mean=1.82</text>
- <text id="otSdev" y="100" x="4">sdev=0.7</text>
- <text id="otGeno" y="120" x="4">ngeno=4487</text>
- <text id="otRmean" y="140" x="4">relmean=1.85</text>
- <text id="otRsdev" y="160" x="4">relsdev=0.65</text>
-</g>
-</svg>
-'''
-
-OUTLIERS_HEADER = 'Mean\tSdev\tZ(mean)\tZ(sdev)\tFID1\tIID1\tFID2\tIID2\tMean(Mean)\tSdev(Mean)\tMean(Sdev)\tSdev(Sdev)\n'
-
-DEFAULT_MAX_SAMPLE_SIZE = 5000
-
-REF_COUNT_HOM1 = 3
-REF_COUNT_HET = 2
-REF_COUNT_HOM2 = 1
-MISSING = 0
-
-MARKER_PAIRS_PER_SECOND_SLOW = 15000000
-MARKER_PAIRS_PER_SECOND_FAST = 70000000
-
-POLYGONS = {
- REL_UNRELATED: ((1.360, 0.655), (1.385, 0.730), (1.620, 0.575), (1.610, 0.505)),
- REL_HALFSIBS: ((1.630, 0.500), (1.630, 0.550), (1.648, 0.540), (1.648, 0.490)),
- REL_SIBS: ((1.660, 0.510), (1.665, 0.560), (1.820, 0.410), (1.820, 0.390)),
- REL_PARENTCHILD: ((1.650, 0.470), (1.650, 0.490), (1.750, 0.440), (1.750, 0.420)),
- REL_DUPE: ((1.970, 0.000), (1.970, 0.150), (2.000, 0.150), (2.000, 0.000)),
- }
-
-def distance(point1, point2):
- """ Calculate the distance between two points
- """
- (x1,y1) = [float(d) for d in point1]
- (x2,y2) = [float(d) for d in point2]
- dx = abs(x1 - x2)
- dy = abs(y1 - y2)
- return math.sqrt(dx**2 + dy**2)
-
-def point_inside_polygon(x, y, poly):
- """ Determine if a point (x,y) is inside a given polygon or not
- poly is a list of (x,y) pairs.
-
- Taken from: http://www.ariel.com.au/a/python-point-int-poly.html
- """
-
- n = len(poly)
- inside = False
-
- p1x,p1y = poly[0]
- for i in range(n+1):
- p2x,p2y = poly[i % n]
- if y > min(p1y,p2y):
- if y <= max(p1y,p2y):
- if x <= max(p1x,p2x):
- if p1y != p2y:
- xinters = (y-p1y)*(p2x-p1x)/(p2y-p1y)+p1x
- if p1x == p2x or x <= xinters:
- inside = not inside
- p1x,p1y = p2x,p2y
- return inside
-
-def readMap(pedfile):
- """
- """
- mapfile = pedfile.replace('.ped', '.map')
- marker_list = []
- if os.path.exists(mapfile):
- print 'readMap: %s' % (mapfile)
- fh = file(mapfile, 'r')
- for line in fh:
- marker_list.append(line.strip().split())
- fh.close()
- print 'readMap: %s markers' % (len(marker_list))
- return marker_list
-
-def calcMeanSD(useme):
- """
- A numerically stable algorithm is given below. It also computes the mean.
- This algorithm is due to Knuth,[1] who cites Welford.[2]
- n = 0
- mean = 0
- M2 = 0
-
- foreach x in data:
- n = n + 1
- delta = x - mean
- mean = mean + delta/n
- M2 = M2 + delta*(x - mean) // This expression uses the new value of mean
- end for
-
- variance_n = M2/n
- variance = M2/(n - 1)
- """
- mean = 0.0
- M2 = 0.0
- sd = 0.0
- n = len(useme)
- if n > 1:
- for i,x in enumerate(useme):
- delta = x - mean
- mean = mean + delta/(i+1) # knuth uses n+=1 at start
- M2 = M2 + delta*(x - mean) # This expression uses the new value of mean
- variance = M2/(n-1) # assume is sample so lose 1 DOF
- sd = pow(variance,0.5)
- return mean,sd
-
-
-def doIBSpy(inpath='',basename='',outdir=None,logf=None,
- nrsSamples=10000,title='title',pdftoo=0,Zcutoff=2.0):
- #def doIBS(pedName, title, nrsSamples=None, pdftoo=False):
- """ started with snpmatrix but GRR uses actual IBS counts and sd's
- """
- repOut = [] # text strings to add to the html display
- refallele = {}
- tblf = '%s_table.xls' % (title)
- tbl = file(os.path.join(outdir,tblf), 'w')
- tbl.write(TABLE_HEADER)
- svgf = '%s.svg' % (title)
- svg = file(os.path.join(outdir,svgf), 'w')
-
- bedname = '%s.bed' % (inpath)
- pedname = '%s.ped' % (inpath)
- print 'pedname',pedname
- if os.path.exists(bedname):
- ped = plinkbinJZ.BPed(inpath)
- ped.parse(quick=True)
- elif os.path.exists(pedname):
- ped = plinkbinJZ.LPed(inpath)
- ped.parse()
- else:
- print >> sys.stdout, '## doIBSpy problem - cannot open %s or %s - cannot run' % (bedname,pedname)
- nMarkers = len(ped._markers)
- if nMarkers < 5:
- print sys.stderr, '### ERROR - %d is too few markers for reliable estimation in %s - terminating' % (nMarkers,PROGNAME)
- sys.exit(1)
- nSubjects = len(ped._subjects)
- nrsSamples = min(nMarkers, nrsSamples)
- if opts and opts.use_mito:
- markers = range(nMarkers)
- nrsSamples = min(len(markers), nrsSamples)
- sampleIndexes = sorted(random.sample(markers, nrsSamples))
- else:
- autosomals = ped.autosomal_indices()
- nrsSamples = min(len(autosomals), nrsSamples)
- sampleIndexes = sorted(random.sample(autosomals, nrsSamples))
-
- print ''
- print 'Getting random.sample of %s from %s total' % (nrsSamples, nMarkers)
- npairs = (nSubjects*(nSubjects-1))/2 # total rows in table
- newfiles=[svgf,tblf]
- explanations = ['rgGRR Plot (requires SVG)','Mean by SD alleles shared - %d rows' % npairs]
- # these go with the output file links in the html file
- s = 'Reading genotypes for %s subjects and %s markers\n' % (nSubjects, nrsSamples)
- logf.write(s)
- minUsegenos = nrsSamples/2 # must have half?
- nGenotypes = nSubjects*nrsSamples
- stime = time.time()
- emptyRows = set()
- genos = numpy.zeros((nSubjects, nrsSamples), dtype=int)
- for s in xrange(nSubjects):
- nValid = 0
- #getGenotypesByIndices(self, s, mlist, format)
- genos[s] = ped.getGenotypesByIndices(s, sampleIndexes, format='ref')
- nValid = sum([1 for g in genos[s] if g])
- if not nValid:
- emptyRows.add(s)
- sub = ped.getSubject(s)
- print 'All missing for row %d (%s)' % (s, sub)
- logf.write('All missing for row %d (%s)\n' % (s, sub))
- rtime = time.time() - stime
- if verbose:
- print '@@Read %s genotypes in %s seconds' % (nGenotypes, rtime)
-
-
- ### Now the expensive part. For each pair of subjects, we get the mean number
- ### and standard deviation of shared alleles over all of the markers where both
- ### subjects have a known genotype. Identical subjects should have mean shared
- ### alleles very close to 2.0 with a standard deviation very close to 0.0.
- tot = nSubjects*(nSubjects-1)/2
- nprog = tot/10
- nMarkerpairs = tot * nrsSamples
- estimatedTimeSlow = nMarkerpairs/MARKER_PAIRS_PER_SECOND_SLOW
- estimatedTimeFast = nMarkerpairs/MARKER_PAIRS_PER_SECOND_FAST
-
- pairs = []
- pair_data = {}
- means = [] ## Mean IBS for each pair
- ngenoL = [] ## Count of comparable genotypes for each pair
- sdevs = [] ## Standard dev for each pair
- rels = [] ## A relationship code for each pair
- zmeans = [0.0 for x in xrange(tot)] ## zmean score for each pair for the relgroup
- zstds = [0.0 for x in xrange(tot)] ## zstd score for each pair for the relgrp
- skip = set()
- ndone = 0 ## How many have been done so far
-
- logf.write('Calculating %d pairs, updating every %d pairs...\n' % (tot, nprog))
- logf.write('Estimated time is %2.2f to %2.2f seconds ...\n' % (estimatedTimeFast, estimatedTimeSlow))
-
- t1sum = 0
- t2sum = 0
- t3sum = 0
- now = time.time()
- scache = {}
- _founder_cache = {}
- C_CODE = """
- #include "math.h"
- int i;
- int sumibs = 0;
- int ssqibs = 0;
- int ngeno = 0;
- float mean = 0;
- float M2 = 0;
- float delta = 0;
- float sdev=0;
- float variance=0;
- for (i=0; i<nrsSamples; i++) {
- int a1 = g1[i];
- int a2 = g2[i];
- if (a1 != 0 && a2 != 0) {
- ngeno += 1;
- int shared = 2-abs(a1-a2);
- delta = shared - mean;
- mean = mean + delta/ngeno;
- M2 += delta*(shared-mean);
- // yes that second time, the updated mean is used see calcmeansd above;
- //printf("%d %d %d %d %d %d\\n", i, a1, a2, ngeno, shared, squared);
- }
- }
- if (ngeno > 1) {
- variance = M2/(ngeno-1);
- sdev = sqrt(variance);
- //printf("OK: %d %3.2f %3.2f\\n", ngeno, mean, sdev);
- }
- //printf("%d %d %d %1.2f %1.2f\\n", ngeno, sumibs, ssqibs, mean, sdev);
- result[0] = ngeno;
- result[1] = mean;
- result[2] = sdev;
- return_val = ngeno;
- """
- started = time.time()
- for s1 in xrange(nSubjects):
- if s1 in emptyRows:
- continue
- (fid1,iid1,did1,mid1,sex1,phe1,iid1,d_sid1,m_sid1) = scache.setdefault(s1, ped.getSubject(s1))
-
- isFounder1 = _founder_cache.setdefault(s1, (did1==mid1))
- g1 = genos[s1]
-
- for s2 in xrange(s1+1, nSubjects):
- if s2 in emptyRows:
- continue
- if nprog and ndone % nprog == 0 and ndone > 1:
- dur = time.time() - started
- pct = float(ndone)/tot*100.0
- logf.write('%f sec at pair %d of %d (%3.2f%%): %f marker*pairs/sec\n' % (dur, ndone, tot, pct, ndone/dur*nrsSamples))
- t1s = time.time()
-
- (fid2,iid2,did2,mid2,sex2,phe2,iid2,d_sid2,m_sid2) = scache.setdefault(s2, ped.getSubject(s2))
-
- g2 = genos[s2]
- isFounder2 = _founder_cache.setdefault(s2, (did2==mid2))
-
- # Determine the relationship for this pair
- relcode = REL_UNKNOWN
- if (fid2 == fid1):
- if iid1 == iid2:
- relcode = REL_DUPE
- elif (did2 == did1) and (mid2 == mid1) and did1 != mid1:
- relcode = REL_SIBS
- elif (iid1 == mid2) or (iid1 == did2) or (iid2 == mid1) or (iid2 == did1):
- relcode = REL_PARENTCHILD
- elif (str(did1) != '0' and (did2 == did1)) or (str(mid1) != '0' and (mid2 == mid1)):
- relcode = REL_HALFSIBS
- else:
- # People in the same family should be marked as some other
- # form of related. In general, these people will have a
- # pretty random spread of similarity. This distinction is
- # probably not very useful most of the time
- relcode = REL_RELATED
- else:
- ### Different families
- relcode = REL_UNRELATED
-
- t1e = time.time()
- t1sum += t1e-t1s
-
-
- ### Calculate sum(2-abs(a1-a2)) and sum((2-abs(a1-a2))**2) and count
- ### the number of contributing genotypes. These values are not actually
- ### calculated here, but instead are looked up in a table for speed.
- ### FIXME: This is still too slow ...
- result = [0.0, 0.0, 0.0]
- ngeno = weave.inline(C_CODE, ['g1', 'g2', 'nrsSamples', 'result'])
- if ngeno >= minUsegenos:
- _, mean, sdev = result
- means.append(mean)
- sdevs.append(sdev)
- ngenoL.append(ngeno)
- pairs.append((s1, s2))
- rels.append(relcode)
- else:
- skip.add(ndone) # signal no comparable genotypes for this pair
- ndone += 1
- t2e = time.time()
- t2sum += t2e-t1e
- t3e = time.time()
- t3sum += t3e-t2e
-
- logme = [ 'T1: %s' % (t1sum), 'T2: %s' % (t2sum), 'T3: %s' % (t3sum),'TOT: %s' % (t3e-now),
- '%s pairs with no (or not enough) comparable genotypes (%3.1f%%)' % (len(skip),
- float(len(skip))/float(tot)*100)]
- logf.write('%s\n' % '\t'.join(logme))
- ### Calculate mean and standard deviation of scores on a per relationship
- ### type basis, allowing us to flag outliers for each particular relationship
- ### type
- relstats = {}
- relCounts = {}
- outlierFiles = {}
- for relCode, relInfo in REL_LOOKUP.items():
- relName, relColor, relStyle = relInfo
- useme = [means[x] for x in xrange(len(means)) if rels[x] == relCode]
- relCounts[relCode] = len(useme)
- mm = scipy.mean(useme)
- ms = scipy.std(useme)
- useme = [sdevs[x] for x in xrange(len(sdevs)) if rels[x] == relCode]
- sm = scipy.mean(useme)
- ss = scipy.std(useme)
- relstats[relCode] = {'sd':(sm,ss), 'mean':(mm,ms)}
- logf.write('Relstate %s: mean(mean)=%3.2f sdev(mean)=%3.2f, mean(sdev)=%3.2f sdev(sdev)=%3.2f\n' % (relName, mm, ms, sm, ss))
-
- ### now fake z scores for each subject like abecasis recommends max(|zmu|,|zsd|)
- ### within each group, for each pair, z=(groupmean-pairmean)/groupsd
- available = len(means)
- logf.write('%d pairs are available of %d\n' % (available, tot))
- ### s = '\nOutliers:\nrelationship\tzmean\tzsd\tped1\tped2\tmean\tsd\trmeanmean\trmeansd\trsdmean\trsdsd\n'
- ### logf.write(s)
- pairnum = 0
- offset = 0
- nOutliers = 0
- cexs = []
- outlierRecords = dict([(r, []) for r in range(N_RELATIONSHIP_TYPES)])
- zsdmax = 0
- for s1 in range(nSubjects):
- if s1 in emptyRows:
- continue
- (fid1,iid1,did1,mid1,sex1,aff1,ok1,d_sid1,m_sid1) = scache[s1]
- for s2 in range(s1+1, nSubjects):
- if s2 in emptyRows:
- continue
- if pairnum not in skip:
- ### Get group stats for this relationship
- (fid2,iid2,did2,mid2,sex2,aff2,ok2,d_sid2,m_sid2) = scache[s2]
- try:
- r = rels[offset]
- except IndexError:
- logf.write('###OOPS offset %d available %d pairnum %d len(rels) %d', offset, available, pairnum, len(rels))
- rmm,rmd = relstats[r]['mean'] # group mean, group meansd alleles shared
- rdm,rdd = relstats[r]['sd'] # group sdmean, group sdsd alleles shared
-
- try:
- zsd = (sdevs[offset] - rdm)/rdd # distance from group mean in group sd units
- except:
- zsd = 1
- if abs(zsd) > zsdmax:
- zsdmax = zsd # keep for sort scaling
- try:
- zmean = (means[offset] - rmm)/rmd # distance from group mean
- except:
- zmean = 1
- zmeans[offset] = zmean
- zstds[offset] = zsd
- pid=(s1,s2)
- zrad = max(zsd,zmean)
- if zrad < 4:
- zrad = 2
- elif 4 < zrad < 15:
- zrad = 3 # to 9
- else: # > 15 6=24+
- zrad=zrad/4
- zrad = min(zrad,6) # scale limit
- zrad = max(2,max(zsd,zmean)) # as > 2, z grows
- pair_data[pid] = (zmean,zsd,r,zrad)
- if max(zsd,zmean) > Zcutoff: # is potentially interesting
- mean = means[offset]
- sdev = sdevs[offset]
- outlierRecords[r].append((mean, sdev, zmean, zsd, fid1, iid1, fid2, iid2, rmm, rmd, rdm, rdd))
- nOutliers += 1
- tbl.write('%s_%s\t%s_%s\t%f\t%f\t%f\t%f\t%d\t%s\n' % \
- (fid1, iid1, fid2, iid2, mean, sdev, zmean,zsd, ngeno, relcode))
- offset += 1
- pairnum += 1
- logf.write( 'Outliers: %s\n' % (nOutliers))
-
- ### Write outlier files for each relationship type
- repOut.append('<h2>Outliers in tab delimited files linked above are also listed below</h2>')
- lzsd = round(numpy.log10(zsdmax)) + 1
- scalefactor = 10**lzsd
- for relCode, relInfo in REL_LOOKUP.items():
- relName, _, _ = relInfo
- outliers = outlierRecords[relCode]
- if not outliers:
- continue
- outliers = [(scalefactor*int(abs(x[3]))+ int(abs(x[2])),x) for x in outliers] # decorate
- outliers.sort()
- logf.write('### outliers after decorated sort=%s' % outliers)
- outliers.reverse() # largest deviation first
- logf.write('### outliers after decorated sort=%s' % outliers)
- outliers = [x[1] for x in outliers] # undecorate
- nrows = len(outliers)
- truncated = 0
- if nrows > MAX_SHOW_ROWS:
- s = '<h3>%s outlying pairs (top %d of %d) from %s</h3><table border="0" cellpadding="3">' % (relName,
- MAX_SHOW_ROWS,nrows,title)
- truncated = nrows - MAX_SHOW_ROWS
- else:
- s = '<h3>%s outlying pairs (n=%d) from %s</h3><table border="0" cellpadding="3">' % (relName,nrows,title)
- repOut.append(s)
- fhname = '%s_rgGRR_%s_outliers.xls' % (title, relName)
- fhpath = os.path.join(outdir,fhname)
- fh = open(fhpath, 'w')
- newfiles.append(fhname)
- explanations.append('%s Outlier Pairs %s, N=%d, Cutoff SD=%f' % (relName,title,len(outliers),Zcutoff))
- fh.write(OUTLIERS_HEADER)
- s = ''.join(['<th>%s</th>' % x for x in OUTLIERS_HEADER_list])
- repOut.append('<tr align="center">%s</tr>' % s)
- for n,rec in enumerate(outliers):
- #(mean, sdev, zmean, zsd, fid1, iid1, fid2, iid2, rmm, rmd, rdm, rdd) = rec
- fh.write('%f\t%f\t%f\t%f\t%s\t%s\t%s\t%s\t%f\t%f\t%f\t%f\n' % tuple(rec))
- # (mean, sdev, zmean, zsd, fid1, iid1, fid2, iid2, rmm, rmd, rdm, rdd))
- s = '''<td>%f</td><td>%f</td><td>%f</td><td>%f</td><td>%s</td><td>%s</td>
- <td>%s</td><td>%s</td><td>%f</td><td>%f</td><td>%f</td><td>%f</td>''' % tuple(rec)
- if n < MAX_SHOW_ROWS:
- repOut.append('<tr align="center">%s</tr>' % s)
- if truncated > 0:
- repOut.append('<H2>WARNING: %d rows truncated - see outlier file for all %d rows</H2>' % (truncated,
- nrows))
- fh.close()
- repOut.append('</table><p>')
-
- ### Now, draw the plot in jpeg and svg formats, and optionally in the PDF format
- ### if requested
- logf.write('Plotting ...')
- pointColors = [REL_COLORS[rel] for rel in rels]
- pointStyles = [REL_POINTS[rel] for rel in rels]
-
- mainTitle = '%s (%s subjects, %d snp)' % (title, nSubjects, nrsSamples)
- svg.write(SVG_HEADER % (SVG_COLORS[0],SVG_COLORS[1],SVG_COLORS[2],SVG_COLORS[3],SVG_COLORS[4],
- SVG_COLORS[5],SVG_COLORS[6],SVG_COLORS[0],SVG_COLORS[0],SVG_COLORS[1],SVG_COLORS[1],
- SVG_COLORS[2],SVG_COLORS[2],SVG_COLORS[3],SVG_COLORS[3],SVG_COLORS[4],SVG_COLORS[4],
- SVG_COLORS[5],SVG_COLORS[5],SVG_COLORS[6],SVG_COLORS[6],mainTitle))
- #rpy.r.jpeg(filename='%s.jpg' % (title), width=1600, height=1200, pointsize=12, quality=100, bg='white')
- #rpy.r.par(mai=(1,1,1,0.5))
- #rpy.r('par(xaxs="i",yaxs="i")')
- #rpy.r.plot(means, sdevs, main=mainTitle, ylab=Y_AXIS_LABEL, xlab=X_AXIS_LABEL, cex=cexs, col=pointColors, pch=pointStyles, xlim=(0,2), ylim=(0,2))
- #rpy.r.legend(LEGEND_ALIGN, legend=REL_STATES, pch=REL_POINTS, col=REL_COLORS, title=LEGEND_TITLE)
- #rpy.r.grid(nx=10, ny=10, col='lightgray', lty='dotted')
- #rpy.r.dev_off()
-
- ### We will now go through each relationship type to partition plot points
- ### into "bulk" and "outlier" groups. Bulk points will represent common
- ### mean/sdev pairs and will cover the majority of the points in the plot --
- ### they will use generic tooltip informtion about all of the pairs
- ### represented by that point. "Outlier" points will be uncommon pairs,
- ### with very specific information in their tooltips. It would be nice to
- ### keep hte total number of plotted points in the SVG representation to
- ### ~10000 (certainly less than 100000?)
- pointMap = {}
- orderedRels = [y[1] for y in reversed(sorted([(relCounts.get(x, 0),x) for x in REL_LOOKUP.keys()]))]
- # do we really want this? I want out of zone points last and big
- for relCode in orderedRels:
- svgColor = SVG_COLORS[relCode]
- relName, relColor, relStyle = REL_LOOKUP[relCode]
- svg.write('<g id="%s" style="stroke:%s; fill:%s; fill-opacity:1.0; stroke-width:1;" cursor="pointer">\n' % (relName, svgColor, svgColor))
- pMap = pointMap.setdefault(relCode, {})
- nPoints = 0
- rpairs=[]
- rgenos=[]
- rmeans=[]
- rsdevs=[]
- rz = []
- for x,rel in enumerate(rels): # all pairs
- if rel == relCode:
- s1,s2 = pairs[x]
- pid=(s1,s2)
- zmean,zsd,r,zrad = pair_data[pid][:4]
- rpairs.append(pairs[x])
- rgenos.append(ngenoL[x])
- rmeans.append(means[x])
- rsdevs.append(sdevs[x])
- rz.append(zrad)
- ### Now add the svg point group for this relationship to the svg file
- for x in range(len(rmeans)):
- svgX = '%d' % ((rmeans[x] - 1.0) * PLOT_WIDTH) # changed so mean scale is 1-2
- svgY = '%d' % (PLOT_HEIGHT - (rsdevs[x] * PLOT_HEIGHT)) # changed so sd scale is 0-1
- s1, s2 = rpairs[x]
- (fid1,uid1,did1,mid1,sex1,phe1,iid1,d_sid1,m_sid1) = scache[s1]
- (fid2,uid2,did2,mid2,sex2,phe2,iid2,d_sid2,m_sid2) = scache[s2]
- ngenos = rgenos[x]
- nPoints += 1
- point = pMap.setdefault((svgX, svgY), [])
- point.append((rmeans[x], rsdevs[x], fid1, iid1, did1, mid1, fid2, iid2, did2, mid2, ngenos,rz[x]))
- for (svgX, svgY) in pMap:
- points = pMap[(svgX, svgY)]
- svgX = int(svgX)
- svgY = int(svgY)
- if len(points) > 1:
- mmean,dmean = calcMeanSD([p[0] for p in points])
- msdev,dsdev = calcMeanSD([p[1] for p in points])
- mgeno,dgeno = calcMeanSD([p[-1] for p in points])
- mingeno = min([p[-1] for p in points])
- maxgeno = max([p[-1] for p in points])
- svg.write("""<circle cx="%d" cy="%d" r="2"
- onmouseover="showBTT(evt, %d, %1.2f, %1.2f, %1.2f, %1.2f, %d, %d, %d, %d, %d)"
- onmouseout="hideBTT(evt)" />\n""" % (svgX, svgY, relCode, mmean, dmean, msdev, dsdev, len(points), mgeno, dgeno, mingeno, maxgeno))
- else:
- mean, sdev, fid1, iid1, did1, mid1, fid2, iid2, did2, mid2, ngenos, zrad = points[0][:12]
- rmean = float(relstats[relCode]['mean'][0])
- rsdev = float(relstats[relCode]['sd'][0])
- if zrad < 4:
- zrad = 2
- elif 4 < zrad < 9:
- zrad = 3 # to 9
- else: # > 9 5=15+
- zrad=zrad/3
- zrad = min(zrad,5) # scale limit
- if zrad <= 3:
- svg.write('<circle cx="%d" cy="%d" r="%s" onmouseover="showOTT(evt, %d, \'%s,%s,%s,%s\', \'%s,%s,%s,%s\', %1.2f, %1.2f, %s, %1.2f, %1.2f)" onmouseout="hideOTT(evt)" />\n' % (svgX, svgY, zrad, relCode, fid1, iid1, did1, mid1, fid2, iid2, did2, mid2, mean, sdev, ngenos, rmean, rsdev))
- else: # highlight pairs a long way from expectation by outlining circle in red
- svg.write("""<circle cx="%d" cy="%d" r="%s" style="stroke:red; fill:%s; fill-opacity:1.0; stroke-width:1;"
- onmouseover="showOTT(evt, %d, \'%s,%s,%s,%s\', \'%s,%s,%s,%s\', %1.2f, %1.2f, %s, %1.2f, %1.2f)"
- onmouseout="hideOTT(evt)" />\n""" % \
- (svgX, svgY, zrad, svgColor, relCode, fid1, iid1, did1, mid1, fid2, iid2, did2, mid2, mean, sdev, ngenos, rmean, rsdev))
- svg.write('</g>\n')
-
- ### Create a pdf as well if indicated on the command line
- ### WARNING! for framingham share, with about 50M pairs, this is a 5.5GB pdf!
-## if pdftoo:
-## pdfname = '%s.pdf' % (title)
-## rpy.r.pdf(pdfname, 6, 6)
-## rpy.r.par(mai=(1,1,1,0.5))
-## rpy.r('par(xaxs="i",yaxs="i")')
-## rpy.r.plot(means, sdevs, main='%s, %d snp' % (title, nSamples), ylab=Y_AXIS_LABEL, xlab=X_AXIS_LABEL, cex=cexs, col=pointColors, pch=pointStyles, xlim=(0,2), ylim=(0,2))
-## rpy.r.legend(LEGEND_ALIGN, legend=REL_STATES, pch=REL_POINTS, col=REL_COLORS, title=LEGEND_TITLE)
-## rpy.r.grid(nx=10, ny=10, col='lightgray', lty='dotted')
-## rpy.r.dev_off()
-
- ### Draw polygons
- if showPolygons:
- svg.write('<g id="polygons" cursor="pointer">\n')
- for rel, poly in POLYGONS.items():
- points = ' '.join(['%s,%s' % ((p[0]-1.0)*float(PLOT_WIDTH), (PLOT_HEIGHT - p[1]*PLOT_HEIGHT)) for p in poly])
- svg.write('<polygon points="%s" fill="transparent" style="stroke:%s; stroke-width:1"/>\n' % (points, SVG_COLORS[rel]))
- svg.write('</g>\n')
-
-
- svg.write(SVG_FOOTER)
- svg.close()
- return newfiles,explanations,repOut
-
-def doIBS(n=100):
- """parse parameters from galaxy
- expect 'input pbed path' 'basename' 'outpath' 'title' 'logpath' 'n'
- <command interpreter="python">
- rgGRR.py $i.extra_files_path/$i.metadata.base_name "$i.metadata.base_name"
- '$out_file1' '$out_file1.files_path' "$title" '$n' '$Z'
- </command>
-
- """
- u="""<command interpreter="python">
- rgGRR.py $i.extra_files_path/$i.metadata.base_name "$i.metadata.base_name"
- '$out_file1' '$out_file1.files_path' "$title" '$n' '$Z'
- </command>"""
-
- if len(sys.argv) < 8:
- print >> sys.stdout, 'Need pbed inpath, basename, out_htmlname, outpath, title, logpath, nSNP, Zcutoff on command line please'
- print >> sys.stdout, u
- sys.exit(1)
- ts = '%s%s' % (string.punctuation,string.whitespace)
- ptran = string.maketrans(ts,'_'*len(ts))
- inpath = sys.argv[1]
- basename = sys.argv[2]
- outhtml = sys.argv[3]
- newfilepath = sys.argv[4]
- try:
- os.makedirs(newfilepath)
- except:
- pass
- title = sys.argv[5].translate(ptran)
- logfname = 'Log_%s.txt' % title
- logpath = os.path.join(newfilepath,logfname) # log was a child - make part of html extra_files_path zoo
- n = int(sys.argv[6])
- try:
- Zcutoff = float(sys.argv[7])
- except:
- Zcutoff = 2.0
- try:
- os.makedirs(newfilepath)
- except:
- pass
- logf = file(logpath,'w')
- newfiles,explanations,repOut = doIBSpy(inpath=inpath,basename=basename,outdir=newfilepath,
- logf=logf,nrsSamples=n,title=title,pdftoo=0,Zcutoff=Zcutoff)
- logf.close()
- logfs = file(logpath,'r').readlines()
- lf = file(outhtml,'w')
- lf.write(galhtmlprefix % PROGNAME)
- # this is a mess. todo clean up - should each datatype have it's own directory? Yes
- # probably. Then titles are universal - but userId libraries are separate.
- s = '<div>Output from %s run at %s<br>\n' % (PROGNAME,timenow())
- lf.write('<h4>%s</h4>\n' % s)
- fixed = ["'%s'" % x for x in sys.argv] # add quotes just in case
- s = 'If you need to rerun this analysis, the command line was\n<pre>%s</pre>\n</div>' % (' '.join(fixed))
- lf.write(s)
- #s = """<object data="%s" type="image/svg+xml" width="%d" height="%d">
- # <embed src="%s" type="image/svg+xml" width="%d" height="%d" />
- # </object>""" % (newfiles[0],PLOT_WIDTH,PLOT_HEIGHT,newfiles[0],PLOT_WIDTH,PLOT_HEIGHT)
- s = """ <embed src="%s" type="image/svg+xml" width="%d" height="%d" />""" % (newfiles[0],PLOT_WIDTH,PLOT_HEIGHT)
- #s = """ <iframe src="%s" type="image/svg+xml" width="%d" height="%d" />""" % (newfiles[0],PLOT_WIDTH,PLOT_HEIGHT)
- lf.write(s)
- lf.write('<div><h4>Click the links below to save output files and plots</h4><br><ol>\n')
- for i in range(len(newfiles)):
- if i == 0:
- lf.write('<li><a href="%s" type="image/svg+xml" >%s</a></li>\n' % (newfiles[i],explanations[i]))
- else:
- lf.write('<li><a href="%s">%s</a></li>\n' % (newfiles[i],explanations[i]))
- flist = os.listdir(newfilepath)
- for fname in flist:
- if not fname in newfiles:
- lf.write('<li><a href="%s">%s</a></li>\n' % (fname,fname))
- lf.write('</ol></div>')
- lf.write('<div>%s</div>' % ('\n'.join(repOut))) # repOut is a list of tables
- lf.write('<div><hr><h3>Log from this job (also stored in %s)</h3><pre>%s</pre><hr></div>' % (logfname,'\n'.join(logfs)))
- lf.write('</body></html>\n')
- lf.close()
- logf.close()
-
-if __name__ == '__main__':
- doIBS()
-
-
+"""
+# july 2009: Need to see outliers so need to draw them last?
+# could use clustering on the zscores to guess real relationships for unrelateds
+# but definitely need to draw last
+# added MAX_SHOW_ROWS to limit the length of the main report page
+# Changes for Galaxy integration
+# added more robust knuth method for one pass mean and sd
+# no difference really - let's use scipy.mean() and scipy.std() instead...
+# fixed labels and changed to .xls for outlier reports so can open in excel
+# interesting - with a few hundred subjects, 5k gives good resolution
+# and 100k gives better but not by much
+# TODO remove non autosomal markers
+# TODO it would be best if label had the zmean and zsd as these are what matter for
+# outliers rather than the group mean/sd
+# mods to rgGRR.py from channing CVS which John Ziniti has rewritten to produce SVG plots
+# to make a Galaxy tool - we need the table of mean and SD for interesting pairs, the SVG and the log
+# so the result should be an HTML file
+
+# rgIBS.py
+# use a random subset of markers for a quick ibs
+# to identify sample dups and closely related subjects
+# try snpMatrix and plink and see which one works best for us?
+# abecasis grr plots mean*sd for every subject to show clusters
+# mods june 23 rml to avoid non-autosomal markers
+# we seem to be distinguishing parent-child by gender - 2 clouds!
+
+
+snpMatrix from David Clayton has:
+ibs.stats function to calculate the identity-by-state stats of a group of samples
+Description
+Given a snp.matrix-class or a X.snp.matrix-class object with N samples, calculates some statistics
+about the relatedness of every pair of samples within.
+
+Usage
+ibs.stats(x)
+8 ibs.stats
+Arguments
+x a snp.matrix-class or a X.snp.matrix-class object containing N samples
+Details
+No-calls are excluded from consideration here.
+Value
+A data.frame containing N(N - 1)/2 rows, where the row names are the sample name pairs separated
+by a comma, and the columns are:
+Count count of identical calls, exclusing no-calls
+Fraction fraction of identical calls comparied to actual calls being made in both samples
+Warning
+In some applications, it may be preferable to subset a (random) selection of SNPs first - the
+calculation
+time increases as N(N - 1)M/2 . Typically for N = 800 samples and M = 3000 SNPs, the
+calculation time is about 1 minute. A full GWA scan could take hours, and quite unnecessary for
+simple applications such as checking for duplicate or related samples.
+Note
+This is mostly written to find mislabelled and/or duplicate samples.
+Illumina indexes their SNPs in alphabetical order so the mitochondria SNPs comes first - for most
+purpose it is undesirable to use these SNPs for IBS purposes.
+TODO: Worst-case S4 subsetting seems to make 2 copies of a large object, so one might want to
+subset before rbind(), etc; a future version of this routine may contain a built-in subsetting facility
+"""
+import sys,os,time,random,string,copy,optparse
+
+try:
+ set
+except NameError:
+ from Sets import Set as set
+
+from rgutils import timenow,pruneLD,plinke
+import plinkbinJZ
+
+
+opts = None
+verbose = False
+
+showPolygons = False
+
+class NullDevice:
+ def write(self, s):
+ pass
+
+tempstderr = sys.stderr # save
+sys.stderr = NullDevice()
+# need to avoid blather about deprecation and other strange stuff from scipy
+# the current galaxy job runner assumes that
+# the job is in error if anything appears on sys.stderr
+# grrrrr. James wants to keep it that way instead of using the
+# status flag for some strange reason. Presumably he doesn't use R or (in this case, scipy)
+import numpy
+import scipy
+from scipy import weave
+
+
+sys.stderr=tempstderr
+
+
+PROGNAME = os.path.split(sys.argv[0])[-1]
+X_AXIS_LABEL = 'Mean Alleles Shared'
+Y_AXIS_LABEL = 'SD Alleles Shared'
+LEGEND_ALIGN = 'topleft'
+LEGEND_TITLE = 'Relationship'
+DEFAULT_SYMBOL_SIZE = 1.0 # default symbol size
+DEFAULT_SYMBOL_SIZE = 0.5 # default symbol size
+
+### Some colors for R/rpy
+R_BLACK = 1
+R_RED = 2
+R_GREEN = 3
+R_BLUE = 4
+R_CYAN = 5
+R_PURPLE = 6
+R_YELLOW = 7
+R_GRAY = 8
+
+### ... and some point-styles
+
+###
+PLOT_HEIGHT = 600
+PLOT_WIDTH = 1150
+
+
+#SVG_COLORS = ('black', 'darkblue', 'blue', 'deepskyblue', 'firebrick','maroon','crimson')
+#SVG_COLORS = ('cyan','dodgerblue','mediumpurple', 'fuchsia', 'red','gold','gray')
+SVG_COLORS = ('cyan','dodgerblue','mediumpurple','forestgreen', 'lightgreen','gold','gray')
+# dupe,parentchild,sibpair,halfsib,parents,unrel,unkn
+#('orange', 'red', 'green', 'chartreuse', 'blue', 'purple', 'gray')
+
+OUTLIERS_HEADER = 'Mean\tSdev\tZ(mean)\tZ(sdev)\tFID1\tIID1\tFID2\tIID2\tMean(Rel_Mean)\tSdev(Rel_Mean)\tMean(Rel_Sdev)\tSdev(Rel_Sdev)\n'
+OUTLIERS_HEADER_list = ['Mean','Sdev','ZMean','ZSdev','FID1','IID1','FID2','IID2',
+'RGMean_M','RGMean_SD','RGSD_M','RGSD_SD']
+TABLE_HEADER='fid1 iid1\tfid2 iid2\tmean\tsdev\tzmean\tzsdev\tgeno\trelcode\n'
+
+
+### Relationship codes, text, and lookups/mappings
+N_RELATIONSHIP_TYPES = 7
+REL_DUPE, REL_PARENTCHILD, REL_SIBS, REL_HALFSIBS, REL_RELATED, REL_UNRELATED, REL_UNKNOWN = range(N_RELATIONSHIP_TYPES)
+REL_LOOKUP = {
+ REL_DUPE: ('dupe', R_BLUE, 1),
+ REL_PARENTCHILD: ('parentchild', R_YELLOW, 1),
+ REL_SIBS: ('sibpairs', R_RED, 1),
+ REL_HALFSIBS: ('halfsibs', R_GREEN, 1),
+ REL_RELATED: ('parents', R_PURPLE, 1),
+ REL_UNRELATED: ('unrelated', R_CYAN, 1),
+ REL_UNKNOWN: ('unknown', R_GRAY, 1),
+ }
+OUTLIER_STDEVS = {
+ REL_DUPE: 2,
+ REL_PARENTCHILD: 2,
+ REL_SIBS: 2,
+ REL_HALFSIBS: 2,
+ REL_RELATED: 2,
+ REL_UNRELATED: 3,
+ REL_UNKNOWN: 2,
+ }
+# note now Z can be passed in
+
+REL_STATES = [REL_LOOKUP[r][0] for r in range(N_RELATIONSHIP_TYPES)]
+REL_COLORS = SVG_COLORS
+REL_POINTS = [REL_LOOKUP[r][2] for r in range(N_RELATIONSHIP_TYPES)]
+
+DEFAULT_MAX_SAMPLE_SIZE = 10000
+
+REF_COUNT_HOM1 = 3
+REF_COUNT_HET = 2
+REF_COUNT_HOM2 = 1
+MISSING = 0
+MAX_SHOW_ROWS = 100 # framingham has millions - delays showing output page - so truncate and explain
+MARKER_PAIRS_PER_SECOND_SLOW = 15000000.0
+MARKER_PAIRS_PER_SECOND_FAST = 70000000.0
+
+
+galhtmlprefix = """<?xml version="1.0" encoding="utf-8" ?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+<meta name="generator" content="Galaxy %s tool output - see http://g2.trac.bx.psu.edu/" />
+<title></title>
+<link rel="stylesheet" href="/static/style/base.css" type="text/css" />
+</head>
+<body>
+<div class="document">
+"""
+
+
+SVG_HEADER = '''<?xml version="1.0" standalone="no"?>
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.2//EN" "http://www.w3.org/Graphics/SVG/1.2/DTD/svg12.dtd">
+
+<svg width="1280" height="800"
+ xmlns="http://www.w3.org/2000/svg" version="1.2"
+ xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 1280 800" onload="init()">
+
+ <script type="text/ecmascript" xlink:href="/static/scripts/checkbox_and_radiobutton.js"/>
+ <script type="text/ecmascript" xlink:href="/static/scripts/helper_functions.js"/>
+ <script type="text/ecmascript" xlink:href="/static/scripts/timer.js"/>
+ <script type="text/ecmascript">
+ <![CDATA[
+ var checkBoxes = new Array();
+ var radioGroupBandwidth;
+ var colours = ['%s','%s','%s','%s','%s','%s','%s'];
+ function init() {
+ var style = {"font-family":"Arial,Helvetica", "fill":"black", "font-size":12};
+ var dist = 12;
+ var yOffset = 4;
+
+ //A checkBox for each relationship type dupe,parentchild,sibpair,halfsib,parents,unrel,unkn
+ checkBoxes["dupe"] = new checkBox("dupe","checkboxes",20,40,"cbRect","cbCross",true,"Duplicate",style,dist,yOffset,undefined,hideShowLayer);
+ checkBoxes["parentchild"] = new checkBox("parentchild","checkboxes",20,60,"cbRect","cbCross",true,"Parent-Child",style,dist,yOffset,undefined,hideShowLayer);
+ checkBoxes["sibpairs"] = new checkBox("sibpairs","checkboxes",20,80,"cbRect","cbCross",true,"Sib-pairs",style,dist,yOffset,undefined,hideShowLayer);
+ checkBoxes["halfsibs"] = new checkBox("halfsibs","checkboxes",20,100,"cbRect","cbCross",true,"Half-sibs",style,dist,yOffset,undefined,hideShowLayer);
+ checkBoxes["parents"] = new checkBox("parents","checkboxes",20,120,"cbRect","cbCross",true,"Parents",style,dist,yOffset,undefined,hideShowLayer);
+ checkBoxes["unrelated"] = new checkBox("unrelated","checkboxes",20,140,"cbRect","cbCross",true,"Unrelated",style,dist,yOffset,undefined,hideShowLayer);
+ checkBoxes["unknown"] = new checkBox("unknown","checkboxes",20,160,"cbRect","cbCross",true,"Unknown",style,dist,yOffset,undefined,hideShowLayer);
+
+ }
+
+ function hideShowLayer(id, status, label) {
+ var vis = "hidden";
+ if (status) {
+ vis = "visible";
+ }
+ document.getElementById(id).setAttributeNS(null, 'visibility', vis);
+ }
+
+ function showBTT(evt, rel, mm, dm, md, dd, n, mg, dg, lg, hg) {
+ var x = parseInt(evt.pageX)-250;
+ var y = parseInt(evt.pageY)-110;
+ switch(rel) {
+ case 0:
+ fill = colours[rel];
+ relt = "dupe";
+ break;
+ case 1:
+ fill = colours[rel];
+ relt = "parentchild";
+ break;
+ case 2:
+ fill = colours[rel];
+ relt = "sibpairs";
+ break;
+ case 3:
+ fill = colours[rel];
+ relt = "halfsibs";
+ break;
+ case 4:
+ fill = colours[rel];
+ relt = "parents";
+ break;
+ case 5:
+ fill = colours[rel];
+ relt = "unrelated";
+ break;
+ case 6:
+ fill = colours[rel];
+ relt = "unknown";
+ break;
+ default:
+ fill = "cyan";
+ relt = "ERROR_CODE: "+rel;
+ }
+
+ document.getElementById("btRel").textContent = "GROUP: "+relt;
+ document.getElementById("btMean").textContent = "mean="+mm+" +/- "+dm;
+ document.getElementById("btSdev").textContent = "sdev="+dm+" +/- "+dd;
+ document.getElementById("btPair").textContent = "npairs="+n;
+ document.getElementById("btGeno").textContent = "ngenos="+mg+" +/- "+dg+" (min="+lg+", max="+hg+")";
+ document.getElementById("btHead").setAttribute('fill', fill);
+
+ var tt = document.getElementById("btTip");
+ tt.setAttribute("transform", "translate("+x+","+y+")");
+ tt.setAttribute('visibility', 'visible');
+ }
+
+ function showOTT(evt, rel, s1, s2, mean, sdev, ngeno, rmean, rsdev) {
+ var x = parseInt(evt.pageX)-150;
+ var y = parseInt(evt.pageY)-180;
+
+ switch(rel) {
+ case 0:
+ fill = colours[rel];
+ relt = "dupe";
+ break;
+ case 1:
+ fill = colours[rel];
+ relt = "parentchild";
+ break;
+ case 2:
+ fill = colours[rel];
+ relt = "sibpairs";
+ break;
+ case 3:
+ fill = colours[rel];
+ relt = "halfsibs";
+ break;
+ case 4:
+ fill = colours[rel];
+ relt = "parents";
+ break;
+ case 5:
+ fill = colours[rel];
+ relt = "unrelated";
+ break;
+ case 6:
+ fill = colours[rel];
+ relt = "unknown";
+ break;
+ default:
+ fill = "cyan";
+ relt = "ERROR_CODE: "+rel;
+ }
+
+ document.getElementById("otRel").textContent = "PAIR: "+relt;
+ document.getElementById("otS1").textContent = "s1="+s1;
+ document.getElementById("otS2").textContent = "s2="+s2;
+ document.getElementById("otMean").textContent = "mean="+mean;
+ document.getElementById("otSdev").textContent = "sdev="+sdev;
+ document.getElementById("otGeno").textContent = "ngenos="+ngeno;
+ document.getElementById("otRmean").textContent = "relmean="+rmean;
+ document.getElementById("otRsdev").textContent = "relsdev="+rsdev;
+ document.getElementById("otHead").setAttribute('fill', fill);
+
+ var tt = document.getElementById("otTip");
+ tt.setAttribute("transform", "translate("+x+","+y+")");
+ tt.setAttribute('visibility', 'visible');
+ }
+
+ function hideBTT(evt) {
+ document.getElementById("btTip").setAttributeNS(null, 'visibility', 'hidden');
+ }
+
+ function hideOTT(evt) {
+ document.getElementById("otTip").setAttributeNS(null, 'visibility', 'hidden');
+ }
+
+ ]]>
+ </script>
+ <defs>
+ <!-- symbols for check boxes -->
+ <symbol id="cbRect" overflow="visible">
+ <rect x="-5" y="-5" width="10" height="10" fill="white" stroke="dimgray" stroke-width="1" cursor="pointer"/>
+ </symbol>
+ <symbol id="cbCross" overflow="visible">
+ <g pointer-events="none" stroke="black" stroke-width="1">
+ <line x1="-3" y1="-3" x2="3" y2="3"/>
+ <line x1="3" y1="-3" x2="-3" y2="3"/>
+ </g>
+ </symbol>
+ </defs>
+
+<desc>Developer Works Dynamic Scatter Graph Scaling Example</desc>
+
+<!-- Now Draw the main X and Y axis -->
+<g style="stroke-width:1.0; stroke:black; shape-rendering:crispEdges">
+ <!-- X Axis top and bottom -->
+ <path d="M 100 100 L 1250 100 Z"/>
+ <path d="M 100 700 L 1250 700 Z"/>
+
+ <!-- Y Axis left and right -->
+ <path d="M 100 100 L 100 700 Z"/>
+ <path d="M 1250 100 L 1250 700 Z"/>
+</g>
+
+<g transform="translate(100,100)">
+
+ <!-- Grid Lines -->
+ <g style="fill:none; stroke:#dddddd; stroke-width:1; stroke-dasharray:2,2; text-anchor:end; shape-rendering:crispEdges">
+
+ <!-- Vertical grid lines -->
+ <line x1="125" y1="0" x2="115" y2="600" />
+ <line x1="230" y1="0" x2="230" y2="600" />
+ <line x1="345" y1="0" x2="345" y2="600" />
+ <line x1="460" y1="0" x2="460" y2="600" />
+ <line x1="575" y1="0" x2="575" y2="600" style="stroke-dasharray:none;" />
+ <line x1="690" y1="0" x2="690" y2="600" />
+ <line x1="805" y1="0" x2="805" y2="600" />
+ <line x1="920" y1="0" x2="920" y2="600" />
+ <line x1="1035" y1="0" x2="1035" y2="600" />
+
+ <!-- Horizontal grid lines -->
+ <line x1="0" y1="60" x2="1150" y2="60" />
+ <line x1="0" y1="120" x2="1150" y2="120" />
+ <line x1="0" y1="180" x2="1150" y2="180" />
+ <line x1="0" y1="240" x2="1150" y2="240" />
+ <line x1="0" y1="300" x2="1150" y2="300" style="stroke-dasharray:none;" />
+ <line x1="0" y1="360" x2="1150" y2="360" />
+ <line x1="0" y1="420" x2="1150" y2="420" />
+ <line x1="0" y1="480" x2="1150" y2="480" />
+ <line x1="0" y1="540" x2="1150" y2="540" />
+ </g>
+
+ <!-- Legend -->
+ <g style="fill:black; stroke:none" font-size="12" font-family="Arial" transform="translate(25,25)">
+ <rect width="160" height="270" style="fill:none; stroke:black; shape-rendering:crispEdges" />
+ <text x="5" y="20" style="fill:black; stroke:none;" font-size="13" font-weight="bold">Given Pair Relationship</text>
+ <rect x="120" y="35" width="10" height="10" fill="%s" stroke="%s" stroke-width="1" cursor="pointer"/>
+ <rect x="120" y="55" width="10" height="10" fill="%s" stroke="%s" stroke-width="1" cursor="pointer"/>
+ <rect x="120" y="75" width="10" height="10" fill="%s" stroke="%s" stroke-width="1" cursor="pointer"/>
+ <rect x="120" y="95" width="10" height="10" fill="%s" stroke="%s" stroke-width="1" cursor="pointer"/>
+ <rect x="120" y="115" width="10" height="10" fill="%s" stroke="%s" stroke-width="1" cursor="pointer"/>
+ <rect x="120" y="135" width="10" height="10" fill="%s" stroke="%s" stroke-width="1" cursor="pointer"/>
+ <rect x="120" y="155" width="10" height="10" fill="%s" stroke="%s" stroke-width="1" cursor="pointer"/>
+ <text x="15" y="195" style="fill:black; stroke:none" font-size="12" font-family="Arial" >Zscore gt 15</text>
+ <circle cx="125" cy="192" r="6" style="stroke:red; fill:gold; fill-opacity:1.0; stroke-width:1;"/>
+ <text x="15" y="215" style="fill:black; stroke:none" font-size="12" font-family="Arial" >Zscore 4 to 15</text>
+ <circle cx="125" cy="212" r="3" style="stroke:gold; fill:gold; fill-opacity:1.0; stroke-width:1;"/>
+ <text x="15" y="235" style="fill:black; stroke:none" font-size="12" font-family="Arial" >Zscore lt 4</text>
+ <circle cx="125" cy="232" r="2" style="stroke:gold; fill:gold; fill-opacity:1.0; stroke-width:1;"/>
+ <g id="checkboxes">
+ </g>
+ </g>
+
+
+ <g style='fill:black; stroke:none' font-size="17" font-family="Arial">
+ <!-- X Axis Labels -->
+ <text x="480" y="660">Mean Alleles Shared</text>
+ <text x="0" y="630" >1.0</text>
+ <text x="277" y="630" >1.25</text>
+ <text x="564" y="630" >1.5</text>
+ <text x="842" y="630" >1.75</text>
+ <text x="1140" y="630" >2.0</text>
+ </g>
+
+ <g transform="rotate(270)" style="fill:black; stroke:none" font-size="17" font-family="Arial">
+ <!-- Y Axis Labels -->
+ <text x="-350" y="-40">SD Alleles Shared</text>
+ <text x="-20" y="-10" >1.0</text>
+ <text x="-165" y="-10" >0.75</text>
+ <text x="-310" y="-10" >0.5</text>
+ <text x="-455" y="-10" >0.25</text>
+ <text x="-600" y="-10" >0.0</text>
+ </g>
+
+<!-- Plot Title -->
+<g style="fill:black; stroke:none" font-size="18" font-family="Arial">
+ <text x="425" y="-30">%s</text>
+</g>
+
+<!-- One group/layer of points for each relationship type -->
+'''
+
+SVG_FOOTER = '''
+<!-- End of Data -->
+</g>
+<g id="btTip" visibility="hidden" style="stroke-width:1.0; fill:black; stroke:none;" font-size="10" font-family="Arial">
+ <rect width="250" height="110" style="fill:silver" rx="2" ry="2"/>
+ <rect id="btHead" width="250" height="20" rx="2" ry="2" />
+ <text id="btRel" y="14" x="85">unrelated</text>
+ <text id="btMean" y="40" x="4">mean=1.5 +/- 0.04</text>
+ <text id="btSdev" y="60" x="4">sdev=0.7 +/- 0.03</text>
+ <text id="btPair" y="80" x="4">npairs=1152</text>
+ <text id="btGeno" y="100" x="4">ngenos=4783 +/- 24 (min=1000, max=5000)</text>
+</g>
+
+<g id="otTip" visibility="hidden" style="stroke-width:1.0; fill:black; stroke:none;" font-size="10" font-family="Arial">
+ <rect width="150" height="180" style="fill:silver" rx="2" ry="2"/>
+ <rect id="otHead" width="150" height="20" rx="2" ry="2" />
+ <text id="otRel" y="14" x="40">sibpairs</text>
+ <text id="otS1" y="40" x="4">s1=fid1,iid1</text>
+ <text id="otS2" y="60" x="4">s2=fid2,iid2</text>
+ <text id="otMean" y="80" x="4">mean=1.82</text>
+ <text id="otSdev" y="100" x="4">sdev=0.7</text>
+ <text id="otGeno" y="120" x="4">ngeno=4487</text>
+ <text id="otRmean" y="140" x="4">relmean=1.85</text>
+ <text id="otRsdev" y="160" x="4">relsdev=0.65</text>
+</g>
+</svg>
+'''
+
+OUTLIERS_HEADER = 'Mean\tSdev\tZ(mean)\tZ(sdev)\tFID1\tIID1\tFID2\tIID2\tMean(Mean)\tSdev(Mean)\tMean(Sdev)\tSdev(Sdev)\n'
+
+DEFAULT_MAX_SAMPLE_SIZE = 5000
+
+REF_COUNT_HOM1 = 3
+REF_COUNT_HET = 2
+REF_COUNT_HOM2 = 1
+MISSING = 0
+
+MARKER_PAIRS_PER_SECOND_SLOW = 15000000
+MARKER_PAIRS_PER_SECOND_FAST = 70000000
+
+POLYGONS = {
+ REL_UNRELATED: ((1.360, 0.655), (1.385, 0.730), (1.620, 0.575), (1.610, 0.505)),
+ REL_HALFSIBS: ((1.630, 0.500), (1.630, 0.550), (1.648, 0.540), (1.648, 0.490)),
+ REL_SIBS: ((1.660, 0.510), (1.665, 0.560), (1.820, 0.410), (1.820, 0.390)),
+ REL_PARENTCHILD: ((1.650, 0.470), (1.650, 0.490), (1.750, 0.440), (1.750, 0.420)),
+ REL_DUPE: ((1.970, 0.000), (1.970, 0.150), (2.000, 0.150), (2.000, 0.000)),
+ }
+
+def distance(point1, point2):
+ """ Calculate the distance between two points
+ """
+ (x1,y1) = [float(d) for d in point1]
+ (x2,y2) = [float(d) for d in point2]
+ dx = abs(x1 - x2)
+ dy = abs(y1 - y2)
+ return math.sqrt(dx**2 + dy**2)
+
+def point_inside_polygon(x, y, poly):
+ """ Determine if a point (x,y) is inside a given polygon or not
+ poly is a list of (x,y) pairs.
+
+ Taken from: http://www.ariel.com.au/a/python-point-int-poly.html
+ """
+
+ n = len(poly)
+ inside = False
+
+ p1x,p1y = poly[0]
+ for i in range(n+1):
+ p2x,p2y = poly[i % n]
+ if y > min(p1y,p2y):
+ if y <= max(p1y,p2y):
+ if x <= max(p1x,p2x):
+ if p1y != p2y:
+ xinters = (y-p1y)*(p2x-p1x)/(p2y-p1y)+p1x
+ if p1x == p2x or x <= xinters:
+ inside = not inside
+ p1x,p1y = p2x,p2y
+ return inside
+
+def readMap(pedfile):
+ """
+ """
+ mapfile = pedfile.replace('.ped', '.map')
+ marker_list = []
+ if os.path.exists(mapfile):
+ print 'readMap: %s' % (mapfile)
+ fh = file(mapfile, 'r')
+ for line in fh:
+ marker_list.append(line.strip().split())
+ fh.close()
+ print 'readMap: %s markers' % (len(marker_list))
+ return marker_list
+
+def calcMeanSD(useme):
+ """
+ A numerically stable algorithm is given below. It also computes the mean.
+ This algorithm is due to Knuth,[1] who cites Welford.[2]
+ n = 0
+ mean = 0
+ M2 = 0
+
+ foreach x in data:
+ n = n + 1
+ delta = x - mean
+ mean = mean + delta/n
+ M2 = M2 + delta*(x - mean) // This expression uses the new value of mean
+ end for
+
+ variance_n = M2/n
+ variance = M2/(n - 1)
+ """
+ mean = 0.0
+ M2 = 0.0
+ sd = 0.0
+ n = len(useme)
+ if n > 1:
+ for i,x in enumerate(useme):
+ delta = x - mean
+ mean = mean + delta/(i+1) # knuth uses n+=1 at start
+ M2 = M2 + delta*(x - mean) # This expression uses the new value of mean
+ variance = M2/(n-1) # assume is sample so lose 1 DOF
+ sd = pow(variance,0.5)
+ return mean,sd
+
+
+def doIBSpy(ped=None,basename='',outdir=None,logf=None,
+ nrsSamples=10000,title='title',pdftoo=0,Zcutoff=2.0):
+ #def doIBS(pedName, title, nrsSamples=None, pdftoo=False):
+ """ started with snpmatrix but GRR uses actual IBS counts and sd's
+ """
+ repOut = [] # text strings to add to the html display
+ refallele = {}
+ tblf = '%s_table.xls' % (title)
+ tbl = file(os.path.join(outdir,tblf), 'w')
+ tbl.write(TABLE_HEADER)
+ svgf = '%s.svg' % (title)
+ svg = file(os.path.join(outdir,svgf), 'w')
+
+ nMarkers = len(ped._markers)
+ if nMarkers < 5:
+ print sys.stderr, '### ERROR - %d is too few markers for reliable estimation in %s - terminating' % (nMarkers,PROGNAME)
+ sys.exit(1)
+ nSubjects = len(ped._subjects)
+ nrsSamples = min(nMarkers, nrsSamples)
+ if opts and opts.use_mito:
+ markers = range(nMarkers)
+ nrsSamples = min(len(markers), nrsSamples)
+ sampleIndexes = sorted(random.sample(markers, nrsSamples))
+ else:
+ autosomals = ped.autosomal_indices()
+ nrsSamples = min(len(autosomals), nrsSamples)
+ sampleIndexes = sorted(random.sample(autosomals, nrsSamples))
+
+ print ''
+ print 'Getting random.sample of %s from %s total' % (nrsSamples, nMarkers)
+ npairs = (nSubjects*(nSubjects-1))/2 # total rows in table
+ newfiles=[svgf,tblf]
+ explanations = ['rgGRR Plot (requires SVG)','Mean by SD alleles shared - %d rows' % npairs]
+ # these go with the output file links in the html file
+ s = 'Reading genotypes for %s subjects and %s markers\n' % (nSubjects, nrsSamples)
+ logf.write(s)
+ minUsegenos = nrsSamples/2 # must have half?
+ nGenotypes = nSubjects*nrsSamples
+ stime = time.time()
+ emptyRows = set()
+ genos = numpy.zeros((nSubjects, nrsSamples), dtype=int)
+ for s in xrange(nSubjects):
+ nValid = 0
+ #getGenotypesByIndices(self, s, mlist, format)
+ genos[s] = ped.getGenotypesByIndices(s, sampleIndexes, format='ref')
+ nValid = sum([1 for g in genos[s] if g])
+ if not nValid:
+ emptyRows.add(s)
+ sub = ped.getSubject(s)
+ print 'All missing for row %d (%s)' % (s, sub)
+ logf.write('All missing for row %d (%s)\n' % (s, sub))
+ rtime = time.time() - stime
+ if verbose:
+ print '@@Read %s genotypes in %s seconds' % (nGenotypes, rtime)
+
+
+ ### Now the expensive part. For each pair of subjects, we get the mean number
+ ### and standard deviation of shared alleles over all of the markers where both
+ ### subjects have a known genotype. Identical subjects should have mean shared
+ ### alleles very close to 2.0 with a standard deviation very close to 0.0.
+ tot = nSubjects*(nSubjects-1)/2
+ nprog = tot/10
+ nMarkerpairs = tot * nrsSamples
+ estimatedTimeSlow = nMarkerpairs/MARKER_PAIRS_PER_SECOND_SLOW
+ estimatedTimeFast = nMarkerpairs/MARKER_PAIRS_PER_SECOND_FAST
+
+ pairs = []
+ pair_data = {}
+ means = [] ## Mean IBS for each pair
+ ngenoL = [] ## Count of comparable genotypes for each pair
+ sdevs = [] ## Standard dev for each pair
+ rels = [] ## A relationship code for each pair
+ zmeans = [0.0 for x in xrange(tot)] ## zmean score for each pair for the relgroup
+ zstds = [0.0 for x in xrange(tot)] ## zstd score for each pair for the relgrp
+ skip = set()
+ ndone = 0 ## How many have been done so far
+
+ logf.write('Calculating %d pairs, updating every %d pairs...\n' % (tot, nprog))
+ logf.write('Estimated time is %2.2f to %2.2f seconds ...\n' % (estimatedTimeFast, estimatedTimeSlow))
+
+ t1sum = 0
+ t2sum = 0
+ t3sum = 0
+ now = time.time()
+ scache = {}
1
0
details: http://www.bx.psu.edu/hg/galaxy/rev/a6e3f4cae4ce
changeset: 3634:a6e3f4cae4ce
user: Anton Nekrutenko <anton(a)bx.psu.edu>
date: Tue Apr 13 11:17:30 2010 -0400
description:
Added pound to trimmer list
diffstat:
tools/filters/trimmer.xml | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diffs (11 lines):
diff -r 0dc1fc63c945 -r a6e3f4cae4ce tools/filters/trimmer.xml
--- a/tools/filters/trimmer.xml Tue Apr 13 10:22:27 2010 -0400
+++ b/tools/filters/trimmer.xml Tue Apr 13 11:17:30 2010 -0400
@@ -28,6 +28,7 @@
<option value="38">&</option>
<option value="37">%</option>
<option value="94">^</option>
+ <option value="35">#</option>
</param>
</inputs>
<outputs>
1
0

16 Apr '10
details: http://www.bx.psu.edu/hg/galaxy/rev/0b682d3dd01b
changeset: 3633:0b682d3dd01b
user: fubar: ross Lazarus at gmail period com
date: Tue Apr 13 11:15:35 2010 -0400
description:
Add the raw uncompressed .js files needed for rgGRR svg display - the packed ones were already there
Fix rgManQQ so the manhattan plot is not called for data without chromosome and offset
Use LD reduced data for IBD/GRR for faster performance and better resolution of close relationships
Add an LD pruning and thinning step to rgGRR - the target composite pbed or lped has the thinned files permanently added for reuse.
This is skipped for small numbers of markers since the plink --thin 0.1 option applied to tinywga.pbed will return an empty file
which is not really ideal.
diffstat:
static/scripts/checkbox_and_radiobutton.js | 347 ++++
static/scripts/helper_functions.js | 817 ++++++++++
static/scripts/timer.js | 74 +
tools/rgenetics/rgGRR.py | 2241 ++++++++++++++-------------
tools/rgenetics/rgManQQ.py | 19 +-
5 files changed, 2396 insertions(+), 1102 deletions(-)
diffs (truncated from 3540 to 3000 lines):
diff -r 0dc1fc63c945 -r 0b682d3dd01b static/scripts/checkbox_and_radiobutton.js
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/static/scripts/checkbox_and_radiobutton.js Tue Apr 13 11:15:35 2010 -0400
@@ -0,0 +1,347 @@
+/*
+Scripts to create interactive checkboxes and radio buttons in SVG using ECMA script
+Copyright (C) <2007> <Andreas Neumann>
+Version 1.1.3, 2007-08-09
+neumann(a)karto.baug.ethz.ch
+http://www.carto.net/
+http://www.carto.net/neumann/
+
+Credits:
+* Guy Morton for providing a fix to let users toggle checkboxes by clicking on text labels
+* Bruce Rindahl for providing the bugfix described in version 1.1.2
+* Simon Shutter for providing a fix for the ASV in IE crash when reloading the SVG file after calling the .remove() method on a checkbox
+
+----
+
+Documentation: http://www.carto.net/papers/svg/gui/checkbox_and_radiobutton/
+
+----
+
+current version: 1.1.3
+
+version history:
+1.0 (2006-03-13)
+initial version
+
+1.1 (2006-07-11)
+text labels are now clickable (thanks to Guy Morton)
+added method .moveTo() to move checkbox to a different location
+introduced new constructor parameter labelYOffset to allow more flexible placement of the text label
+
+1.1.1 (2007-02-06)
+added cursor pointer to the text label and use element representing the checkBox
+
+1.1.2 (2007-04-19)
+bug fix: this.selectedIndex was not correctly initialized in method addCheckBox of the radioButtonGroup object
+
+1.1.3 (2007-08-09)
+bug fix: the method .remove() was slightly modified (using removeEventListener) for avoiding a crash related to the method after reloading the SVG file
+
+-------
+
+
+This ECMA script library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library (lesser_gpl.txt); if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+----
+
+original document site: http://www.carto.net/papers/svg/gui/checkbox_and_radiobutton/
+Please contact the author in case you want to use code or ideas commercially.
+If you use this code, please include this copyright header, the included full
+LGPL 2.1 text and read the terms provided in the LGPL 2.1 license
+(http://www.gnu.org/copyleft/lesser.txt)
+
+-------------------------------
+
+Please report bugs and send improvements to neumann(a)karto.baug.ethz.ch
+If you use this control, please link to the original (http://www.carto.net/papers/svg/gui/checkbox_and_radiobutton/)
+somewhere in the source-code-comment or the "about" of your project and give credits, thanks!
+
+*/
+
+function checkBox(id,parentNode,x,y,checkboxId,checkcrossId,checkedStatus,labelText,textStyles,labelDistance,labelYOffset,radioButtonGroup,functionToCall) {
+ var nrArguments = 13;
+ var createCheckbox= true;
+ if (arguments.length == nrArguments) {
+ this.id = id; //an internal id, this id is not used in the SVG Dom tree
+ this.parentNode = parentNode; //the parentNode, string or nodeReference
+ this.x = x; //the center of the checkBox
+ this.y = y; //the center of the checkBox
+ this.checkboxId = checkboxId; //the id of the checkbox symbol (background)
+ this.checkcrossId = checkcrossId; //the id of the checkbox symbol (foreground), pointer-events should be set to "none"
+ this.checkedStatus = checkedStatus; //a status variable (true|false), indicates if checkbox is on or off
+ this.labelText = labelText; //the text of the checkbox label to be displayed, use undefined or empty string if you don't need a label text
+ this.textStyles = textStyles; //an array of literals containing the text settings
+ if (!this.textStyles["font-size"]) {
+ this.textStyles["font-size"] = 12;
+ }
+ this.labelDistance = labelDistance; //a distance defined from the center of the checkbox to the left of the text of the label
+ this.labelYOffset = labelYOffset; //a y offset value for the text label in relation to the checkbox symbol center
+ this.radioButtonGroup = radioButtonGroup; //a reference to a radio button group, if this is a standalone checkBox, just use the parameter undefined
+ this.functionToCall = functionToCall; //the function to call after triggering checkBox
+ this.exists = true; //status that indicates if checkbox exists or not, is set to false after method .remove() was called
+ this.label = undefined; //later a reference to the label text node
+ }
+ else {
+ createCheckbox = false;
+ alert("Error in checkbox ("+id+"): wrong nr of arguments! You have to pass over "+nrArguments+" parameters.");
+ }
+ if (createCheckbox) {
+ //timer stuff
+ this.timer = new Timer(this); //a Timer instance for calling the functionToCall
+ if (this.radioButtonGroup) {
+ this.timerMs = 0;
+ }
+ else {
+ this.timerMs = 200; //a constant of this object that is used in conjunction with the timer - functionToCall is called after 200 ms
+ }
+ //create checkbox
+ this.createCheckBox();
+ }
+ else {
+ alert("Could not create checkbox with id '"+id+"' due to errors in the constructor parameters");
+ }
+}
+
+//this method creates all necessary checkbox geometry
+checkBox.prototype.createCheckBox = function() {
+ if (typeof(this.parentNode) == "string") {
+ this.parentNode = document.getElementById(this.parentNode);
+ }
+ //create checkbox
+ this.checkBox = document.createElementNS(svgNS,"use");
+ this.checkBox.setAttributeNS(null,"x",this.x);
+ this.checkBox.setAttributeNS(null,"y",this.y);
+ this.checkBox.setAttributeNS(xlinkNS,"href","#"+this.checkboxId);
+ this.checkBox.addEventListener("click",this,false);
+ this.checkBox.setAttributeNS(null,"cursor","pointer");
+ this.parentNode.appendChild(this.checkBox);
+ //create checkcross
+ this.checkCross = document.createElementNS(svgNS,"use");
+ this.checkCross.setAttributeNS(null,"x",this.x);
+ this.checkCross.setAttributeNS(null,"y",this.y);
+ this.checkCross.setAttributeNS(xlinkNS,"href","#"+this.checkcrossId);
+ this.parentNode.appendChild(this.checkCross);
+ if (this.checkedStatus == false) {
+ this.checkCross.setAttributeNS(null,"display","none");
+ }
+ //create label, if any
+ if (this.labelText) {
+ if (this.labelText.length > 0) {
+ this.label = document.createElementNS(svgNS,"text");
+ for (var attrib in this.textStyles) {
+ var value = this.textStyles[attrib];
+ if (attrib == "font-size") {
+ value += "px";
+ }
+ this.label.setAttributeNS(null,attrib,value);
+ }
+ this.label.setAttributeNS(null,"x",(this.x + this.labelDistance));
+ this.label.setAttributeNS(null,"y",(this.y + this.labelYOffset));
+ this.label.setAttributeNS(null,"cursor","pointer");
+ var labelTextNode = document.createTextNode(this.labelText);
+ this.label.appendChild(labelTextNode);
+ this.label.setAttributeNS(null,"pointer-events","all");
+ this.label.addEventListener("click",this,false);
+ this.parentNode.appendChild(this.label);
+ }
+ }
+ if (this.radioButtonGroup) {
+ this.radioButtonGroup.addCheckBox(this);
+ }
+}
+
+checkBox.prototype.handleEvent = function(evt) {
+ if (evt.type == "click") {
+ if (this.checkedStatus == true) {
+ this.checkCross.setAttributeNS(null,"display","none");
+ this.checkedStatus = false;
+ }
+ else {
+ this.checkCross.setAttributeNS(null,"display","inline");
+ this.checkedStatus = true;
+ }
+ }
+ this.timer.setTimeout("fireFunction",this.timerMs);
+}
+
+checkBox.prototype.fireFunction = function() {
+ if (this.radioButtonGroup) {
+ this.radioButtonGroup.selectById(this.id,true);
+ }
+ else {
+ if (typeof(this.functionToCall) == "function") {
+ this.functionToCall(this.id,this.checkedStatus,this.labelText);
+ }
+ if (typeof(this.functionToCall) == "object") {
+ this.functionToCall.checkBoxChanged(this.id,this.checkedStatus,this.labelText);
+ }
+ if (typeof(this.functionToCall) == undefined) {
+ return;
+ }
+ }
+}
+
+checkBox.prototype.check = function(FireFunction) {
+ this.checkCross.setAttributeNS(null,"display","inherit");
+ this.checkedStatus = true;
+ if (FireFunction) {
+ this.timer.setTimeout("fireFunction",this.timerMs);
+ }
+}
+
+checkBox.prototype.uncheck = function(FireFunction) {
+ this.checkCross.setAttributeNS(null,"display","none");
+ this.checkedStatus = false;
+ if (FireFunction) {
+ this.timer.setTimeout("fireFunction",this.timerMs);
+ }
+}
+
+//move checkbox to a different position
+checkBox.prototype.moveTo = function(moveX,moveY) {
+ this.x = moveX;
+ this.y = moveY;
+ //move checkbox
+ this.checkBox.setAttributeNS(null,"x",this.x);
+ this.checkBox.setAttributeNS(null,"y",this.y);
+ //move checkcross
+ this.checkCross.setAttributeNS(null,"x",this.x);
+ this.checkCross.setAttributeNS(null,"y",this.y);
+ //move text label
+ if (this.labelText) {
+ this.label.setAttributeNS(null,"x",(this.x + this.labelDistance));
+ this.label.setAttributeNS(null,"y",(this.y + this.labelYOffset));
+ }
+}
+
+checkBox.prototype.remove = function(FireFunction) {
+ this.checkBox.removeEventListener("click",this,false);
+ this.parentNode.removeChild(this.checkBox);
+ this.parentNode.removeChild(this.checkCross);
+ if (this.label) {
+ this.parentNode.removeChild(this.label);
+ }
+ this.exists = false;
+}
+
+checkBox.prototype.setLabelText = function(labelText) {
+ this.labelText = labelText
+ if (this.label) {
+ this.label.firstChild.nodeValue = labelText;
+ }
+ else {
+ if (this.labelText.length > 0) {
+ this.label = document.createElementNS(svgNS,"text");
+ for (var attrib in this.textStyles) {
+ value = this.textStyles[attrib];
+ if (attrib == "font-size") {
+ value += "px";
+ }
+ this.label.setAttributeNS(null,attrib,value);
+ }
+ this.label.setAttributeNS(null,"x",(this.x + this.labelDistance));
+ this.label.setAttributeNS(null,"y",(this.y + this.textStyles["font-size"] * 0.3));
+ var labelTextNode = document.createTextNode(this.labelText);
+ this.label.appendChild(labelTextNode);
+ this.parentNode.appendChild(this.label);
+ }
+ }
+}
+
+/* start of the radioButtonGroup object */
+
+function radioButtonGroup(id,functionToCall) {
+ var nrArguments = 2;
+ if (arguments.length == nrArguments) {
+ this.id = id;
+ if (typeof(functionToCall) == "function" || typeof(functionToCall) == "object" || typeof(functionToCall) == undefined) {
+ this.functionToCall = functionToCall;
+ }
+ else {
+ alert("Error in radiobutton with ("+id+"): argument functionToCall is not of type 'function', 'object' or undefined!");
+ }
+ this.checkBoxes = new Array(); //this array will hold checkbox objects
+ this.selectedId = undefined; //holds the id of the active radio button
+ this.selectedIndex = undefined; //holds the index of the active radio button
+ //timer stuff
+ this.timer = new Timer(this); //a Timer instance for calling the functionToCall
+ this.timerMs = 200; //a constant of this object that is used in conjunction with the timer - functionToCall is called after 200 ms
+ }
+ else {
+ alert("Error in radiobutton with ("+id+"): wrong nr of arguments! You have to pass over "+nrArguments+" parameters.");
+ }
+}
+
+radioButtonGroup.prototype.addCheckBox = function(checkBoxObj) {
+ this.checkBoxes.push(checkBoxObj);
+ if (checkBoxObj.checkedStatus) {
+ this.selectedId = checkBoxObj.id;
+ this.selectedIndex = this.checkBoxes.length - 1;
+ }
+}
+
+//change radio button selection by id
+radioButtonGroup.prototype.selectById = function(cbId,fireFunction) {
+ var found = false;
+ for (var i=0;i<this.checkBoxes.length;i++) {
+ if (this.checkBoxes[i].id == cbId) {
+ this.selectedId = cbId;
+ this.selectedIndex = i;
+ if (this.checkBoxes[i].checkedStatus == false) {
+ this.checkBoxes[i].check(false);
+ }
+ found = true;
+ }
+ else {
+ this.checkBoxes[i].uncheck(false);
+ }
+ }
+ if (found) {
+ if (fireFunction) {
+ this.timer.setTimeout("fireFunction",this.timerMs);
+ }
+ }
+ else {
+ alert("Error in radiobutton with ("+this.id+"): could not find checkbox with id '"+cbId+"'");
+ }
+}
+
+//change radio button selection by label name
+radioButtonGroup.prototype.selectByLabelname = function(labelName,fireFunction) {
+ var id = -1;
+ for (var i=0;i<this.checkBoxes.length;i++) {
+ if (this.checkBoxes[i].labelText == labelName) {
+ id = this.checkBoxes[i].id;
+ }
+ }
+ if (id == -1) {
+ alert("Error in radiobutton with ("+this.id+"): could not find checkbox with label '"+labelName+"'");
+ }
+ else {
+ this.selectById(id,fireFunction);
+ }
+}
+
+radioButtonGroup.prototype.fireFunction = function() {
+ if (typeof(this.functionToCall) == "function") {
+ this.functionToCall(this.id,this.selectedId,this.checkBoxes[this.selectedIndex].labelText);
+ }
+ if (typeof(this.functionToCall) == "object") {
+ this.functionToCall.radioButtonChanged(this.id,this.selectedId,this.checkBoxes[this.selectedIndex].labelText);
+ }
+ if (typeof(this.functionToCall) == undefined) {
+ return;
+ }
+}
\ No newline at end of file
diff -r 0dc1fc63c945 -r 0b682d3dd01b static/scripts/helper_functions.js
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/static/scripts/helper_functions.js Tue Apr 13 11:15:35 2010 -0400
@@ -0,0 +1,817 @@
+/**
+ * @fileoverview
+ *
+ * ECMAScript <a href="http://www.carto.net/papers/svg/resources/helper_functions.html">helper functions</a>, main purpose is to serve in SVG mapping or other SVG based web applications
+ *
+ * This ECMA script library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library (http://www.carto.net/papers/svg/resources/lesser_gpl.txt) if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Please report bugs and send improvements to neumann(a)karto.baug.ethz.ch
+ * If you use these scripts, please link to the original (http://www.carto.net/papers/svg/resources/helper_functions.html)
+ * somewhere in the source-code-comment or the "about" of your project and give credits, thanks!
+ *
+ * See <a href="js_docs_out/overview-summary-helper_functions.js.html">documentation</a>.
+ *
+ * @author Andreas Neumann a.neumann(a)carto.net
+ * @copyright LGPL 2.1 <a href="http://www.gnu.org/copyleft/lesser.txt">Gnu LGPL 2.1</a>
+ * @credits Bruce Rindahl, numerous people on svgdevelopers(a)yahoogroups.com
+ */
+
+//global variables necessary to create elements in these namespaces, do not delete them!!!!
+
+/**
+ * This variable is a shortcut to the full URL of the SVG namespace
+ * @final
+ * @type String
+ */
+var svgNS = "http://www.w3.org/2000/svg";
+
+/**
+ * This variable is a shortcut to the full URL of the XLink namespace
+ * @final
+ * @type String
+ */
+var xlinkNS = "http://www.w3.org/1999/xlink";
+
+/**
+ * This variable is a shortcut to the full URL of the attrib namespace
+ * @final
+ * @type String
+ */
+var cartoNS = "http://www.carto.net/attrib";
+
+/**
+ * This variable is a alias to the full URL of the attrib namespace
+ * @final
+ * @type String
+ */
+var attribNS = "http://www.carto.net/attrib";
+
+/**
+ * This variable is a alias to the full URL of the Batik extension namespace
+ * @final
+ * @type String
+ */
+var batikNS = "http://xml.apache.org/batik/ext";
+
+/**
+ * Returns the polar direction from a given vector
+ * @param {Number} xdiff the x-part of the vector
+ * @param {Number} ydiff the y-part of the vector
+ * @return direction the direction in radians
+ * @type Number
+ * @version 1.0 (2007-04-30)
+ * @see #toPolarDist
+ * @see #toRectX
+ * @see #toRectY
+ */
+function toPolarDir(xdiff,ydiff) {
+ var direction = (Math.atan2(ydiff,xdiff));
+ return(direction);
+}
+
+/**
+ * Returns the polar distance from a given vector
+ * @param {Number} xdiff the x-part of the vector
+ * @param {Number} ydiff the y-part of the vector
+ * @return distance the distance
+ * @type Number
+ * @version 1.0 (2007-04-30)
+ * @see #toPolarDir
+ * @see #toRectX
+ * @see #toRectY
+ */
+function toPolarDist(xdiff,ydiff) {
+ var distance = Math.sqrt(xdiff * xdiff + ydiff * ydiff);
+ return(distance);
+}
+
+/**
+ * Returns the x-part of a vector from a given direction and distance
+ * @param {Number} direction the direction (in radians)
+ * @param {Number} distance the distance
+ * @return x the x-part of the vector
+ * @type Number
+ * @version 1.0 (2007-04-30)
+ * @see #toPolarDist
+ * @see #toPolarDir
+ * @see #toRectY
+ */
+function toRectX(direction,distance) {
+ var x = distance * Math.cos(direction);
+ return(x);
+}
+
+/**
+ * Returns the y-part of the vector from a given direction and distance
+ * @param {Number} direction the direction (in radians)
+ * @param {Number} distance the distance
+ * @return y the y-part of the vector
+ * @type Number
+ * @version 1.0 (2007-04-30)
+ * @see #toPolarDist
+ * @see #toPolarDir
+ * @see #toRectX
+ */
+function toRectY(direction,distance) {
+ y = distance * Math.sin(direction);
+ return(y);
+}
+
+/**
+ * Converts degrees to radians
+ * @param {Number} deg the degree value
+ * @return rad the radians value
+ * @type Number
+ * @version 1.0 (2007-04-30)
+ * @see #RadToDeg
+ */
+function DegToRad(deg) {
+ return (deg / 180.0 * Math.PI);
+}
+
+/**
+ * Converts radians to degrees
+ * @param {Number} rad the radians value
+ * @return deg the degree value
+ * @type Number
+ * @version 1.0 (2007-04-30)
+ * @see #DegToRad
+ */
+function RadToDeg(rad) {
+ return (rad / Math.PI * 180.0);
+}
+
+/**
+ * Converts decimal degrees to degrees, minutes, seconds
+ * @param {Number} dd the decimal degree value
+ * @return degrees the degree values in the following notation: {deg:degrees,min:minutes,sec:seconds}
+ * @type literal
+ * @version 1.0 (2007-04-30)
+ * @see #dms2dd
+ */
+function dd2dms(dd) {
+ var minutes = (Math.abs(dd) - Math.floor(Math.abs(dd))) * 60;
+ var seconds = (minutes - Math.floor(minutes)) * 60;
+ var minutes = Math.floor(minutes);
+ if (dd >= 0) {
+ var degrees = Math.floor(dd);
+ }
+ else {
+ var degrees = Math.ceil(dd);
+ }
+ return {deg:degrees,min:minutes,sec:seconds};
+}
+
+/**
+ * Converts degrees, minutes and seconds to decimal degrees
+ * @param {Number} deg the degree value
+ * @param {Number} min the minute value
+ * @param {Number} sec the second value
+ * @return deg the decimal degree values
+ * @type Number
+ * @version 1.0 (2007-04-30)
+ * @see #dd2dms
+ */
+function dms2dd(deg,min,sec) {
+ if (deg < 0) {
+ return deg - (min / 60) - (sec / 3600);
+ }
+ else {
+ return deg + (min / 60) + (sec / 3600);
+ }
+}
+
+/**
+ * log function, missing in the standard Math object
+ * @param {Number} x the value where the log function should be applied to
+ * @param {Number} b the base value for the log function
+ * @return logResult the result of the log function
+ * @type Number
+ * @version 1.0 (2007-04-30)
+ */
+function log(x,b) {
+ if(b==null) b=Math.E;
+ return Math.log(x)/Math.log(b);
+}
+
+/**
+ * interpolates a value (e.g. elevation) bilinearly based on the position within a cell with 4 corner values
+ * @param {Number} za the value at the upper left corner of the cell
+ * @param {Number} zb the value at the upper right corner of the cell
+ * @param {Number} zc the value at the lower right corner of the cell
+ * @param {Number} zd the value at the lower left corner of the cell
+ * @param {Number} xpos the x position of the point where a new value should be interpolated
+ * @param {Number} ypos the y position of the point where a new value should be interpolated
+ * @param {Number} ax the x position of the lower left corner of the cell
+ * @param {Number} ay the y position of the lower left corner of the cell
+ * @param {Number} cellsize the size of the cell
+ * @return interpol_value the result of the bilinear interpolation function
+ * @type Number
+ * @version 1.0 (2007-04-30)
+ */
+function intBilinear(za,zb,zc,zd,xpos,ypos,ax,ay,cellsize) { //bilinear interpolation function
+ var e = (xpos - ax) / cellsize;
+ var f = (ypos - ay) / cellsize;
+
+ //calculation of weights
+ var wa = (1 - e) * (1 - f);
+ var wb = e * (1 - f);
+ var wc = e * f;
+ var wd = f * (1 - e);
+
+ var interpol_value = wa * zc + wb * zd + wc * za + wd * zb;
+ return interpol_value;
+}
+
+/**
+ * tests if a given point is left or right of a given line
+ * @param {Number} pointx the x position of the given point
+ * @param {Number} pointy the y position of the given point
+ * @param {Number} linex1 the x position of line's start point
+ * @param {Number} liney1 the y position of line's start point
+ * @param {Number} linex2 the x position of line's end point
+ * @param {Number} liney2 the y position of line's end point
+ * @return leftof the result of the leftOfTest, 1 means leftOf, 0 means rightOf
+ * @type Number (integer, 0|1)
+ * @version 1.0 (2007-04-30)
+ */
+function leftOfTest(pointx,pointy,linex1,liney1,linex2,liney2) {
+ var result = (liney1 - pointy) * (linex2 - linex1) - (linex1 - pointx) * (liney2 - liney1);
+ if (result < 0) {
+ var leftof = 1; //case left of
+ }
+ else {
+ var leftof = 0; //case left of
+ }
+ return leftof;
+}
+
+/**
+ * calculates the distance between a given point and a given line
+ * @param {Number} pointx the x position of the given point
+ * @param {Number} pointy the y position of the given point
+ * @param {Number} linex1 the x position of line's start point
+ * @param {Number} liney1 the y position of line's start point
+ * @param {Number} linex2 the x position of line's end point
+ * @param {Number} liney2 the y position of line's end point
+ * @return distance the result of the leftOfTest, 1 means leftOf, 0 means rightOf
+ * @type Number
+ * @version 1.0 (2007-04-30)
+ */
+function distFromLine(xpoint,ypoint,linex1,liney1,linex2,liney2) {
+ var dx = linex2 - linex1;
+ var dy = liney2 - liney1;
+ var distance = (dy * (xpoint - linex1) - dx * (ypoint - liney1)) / Math.sqrt(Math.pow(dx,2) + Math.pow(dy,2));
+ return distance;
+}
+
+/**
+ * calculates the angle between two vectors (lines)
+ * @param {Number} ax the x part of vector a
+ * @param {Number} ay the y part of vector a
+ * @param {Number} bx the x part of vector b
+ * @param {Number} by the y part of vector b
+ * @return angle the angle in radians
+ * @type Number
+ * @version 1.0 (2007-04-30)
+ * @credits <a href="http://www.mathe-online.at/mathint/vect2/i.html#Winkel">Mathe Online (Winkel)</a>
+ */
+function angleBetwTwoLines(ax,ay,bx,by) {
+ var angle = Math.acos((ax * bx + ay * by) / (Math.sqrt(Math.pow(ax,2) + Math.pow(ay,2)) * Math.sqrt(Math.pow(bx,2) + Math.pow(by,2))));
+ return angle;
+}
+
+/**
+ * calculates the bisector vector for two given vectors
+ * @param {Number} ax the x part of vector a
+ * @param {Number} ay the y part of vector a
+ * @param {Number} bx the x part of vector b
+ * @param {Number} by the y part of vector b
+ * @return c the resulting vector as an Array, c[0] is the x part of the vector, c[1] is the y part
+ * @type Array
+ * @version 1.0 (2007-04-30)
+ * @credits <a href="http://www.mathe-online.at/mathint/vect1/i.html#Winkelsymmetrale">Mathe Online (Winkelsymmetrale)</a>
+ * see #calcBisectorAngle
+ * */
+function calcBisectorVector(ax,ay,bx,by) {
+ var betraga = Math.sqrt(Math.pow(ax,2) + Math.pow(ay,2));
+ var betragb = Math.sqrt(Math.pow(bx,2) + Math.pow(by,2));
+ var c = new Array();
+ c[0] = ax / betraga + bx / betragb;
+ c[1] = ay / betraga + by / betragb;
+ return c;
+}
+
+/**
+ * calculates the bisector angle for two given vectors
+ * @param {Number} ax the x part of vector a
+ * @param {Number} ay the y part of vector a
+ * @param {Number} bx the x part of vector b
+ * @param {Number} by the y part of vector b
+ * @return angle the bisector angle in radians
+ * @type Number
+ * @version 1.0 (2007-04-30)
+ * @credits <a href="http://www.mathe-online.at/mathint/vect1/i.html#Winkelsymmetrale">Mathe Online (Winkelsymmetrale)</a>
+ * see #calcBisectorVector
+ * */
+function calcBisectorAngle(ax,ay,bx,by) {
+ var betraga = Math.sqrt(Math.pow(ax,2) + Math.pow(ay,2));
+ var betragb = Math.sqrt(Math.pow(bx,2) + Math.pow(by,2));
+ var c1 = ax / betraga + bx / betragb;
+ var c2 = ay / betraga + by / betragb;
+ var angle = toPolarDir(c1,c2);
+ return angle;
+}
+
+/**
+ * calculates the intersection point of two given lines
+ * @param {Number} line1x1 the x the start point of line 1
+ * @param {Number} line1y1 the y the start point of line 1
+ * @param {Number} line1x2 the x the end point of line 1
+ * @param {Number} line1y2 the y the end point of line 1
+ * @return interSectPoint the intersection point, interSectPoint.x contains x-part, interSectPoint.y the y-part of the resulting coordinate
+ * @type Object
+ * @version 1.0 (2007-04-30)
+ * @credits <a href="http://astronomy.swin.edu.au/~pbourke/geometry/lineline2d/">P. Bourke</a>
+ */
+function intersect2lines(line1x1,line1y1,line1x2,line1y2,line2x1,line2y1,line2x2,line2y2) {
+ var interSectPoint = new Object();
+ var denominator = (line2y2 - line2y1)*(line1x2 - line1x1) - (line2x2 - line2x1)*(line1y2 - line1y1);
+ if (denominator == 0) {
+ alert("lines are parallel");
+ }
+ else {
+ var ua = ((line2x2 - line2x1)*(line1y1 - line2y1) - (line2y2 - line2y1)*(line1x1 - line2x1)) / denominator;
+ var ub = ((line1x2 - line1x1)*(line1y1 - line2y1) - (line1y2 - line1y1)*(line1x1 - line2x1)) / denominator;
+ }
+ interSectPoint["x"] = line1x1 + ua * (line1x2 - line1x1);
+ interSectPoint["y"] = line1y1 + ua * (line1y2 - line1y1);
+ return interSectPoint;
+}
+
+/**
+ * reformats a given number to a string by adding separators at every third digit
+ * @param {String|Number} inputNumber the input number, can be of type number or string
+ * @param {String} separator the separator, e.g. ' or ,
+ * @return newString the intersection point, interSectPoint.x contains x-part, interSectPoint.y the y-part of the resulting coordinate
+ * @type String
+ * @version 1.0 (2007-04-30)
+ */
+function formatNumberString(inputNumber,separator) {
+ //check if of type string, if number, convert it to string
+ if (typeof(inputNumber) == "Number") {
+ var myTempString = inputNumber.toString();
+ }
+ else {
+ var myTempString = inputNumber;
+ }
+ var newString="";
+ //if it contains a comma, it will be split
+ var splitResults = myTempString.split(".");
+ var myCounter = splitResults[0].length;
+ if (myCounter > 3) {
+ while(myCounter > 0) {
+ if (myCounter > 3) {
+ newString = separator + splitResults[0].substr(myCounter - 3,3) + newString;
+ }
+ else {
+ newString = splitResults[0].substr(0,myCounter) + newString;
+ }
+ myCounter -= 3;
+ }
+ }
+ else {
+ newString = splitResults[0];
+ }
+ //concatenate if it contains a comma
+ if (splitResults[1]) {
+ newString = newString + "." + splitResults[1];
+ }
+ return newString;
+}
+
+/**
+ * writes a status text message out to a SVG text element's first child
+ * @param {String} statusText the text message to be displayed
+ * @version 1.0 (2007-04-30)
+ */
+ function statusChange(statusText) {
+ document.getElementById("statusText").firstChild.nodeValue = "Statusbar: " + statusText;
+}
+
+/**
+ * scales an SVG element, requires that the element has an x and y attribute (e.g. circle, ellipse, use element, etc.)
+ * @param {dom::Event} evt the evt object that triggered the scaling
+ * @param {Number} factor the scaling factor
+ * @version 1.0 (2007-04-30)
+ */
+function scaleObject(evt,factor) {
+ //reference to the currently selected object
+ var element = evt.currentTarget;
+ var myX = element.getAttributeNS(null,"x");
+ var myY = element.getAttributeNS(null,"y");
+ var newtransform = "scale(" + factor + ") translate(" + (myX * 1 / factor - myX) + " " + (myY * 1 / factor - myY) +")";
+ element.setAttributeNS(null,'transform', newtransform);
+}
+
+/**
+ * returns the transformation matrix (ctm) for the given node up to the root element
+ * the basic use case is to provide a wrapper function for the missing SVGLocatable.getTransformToElement method (missing in ASV3)
+ * @param {svg::SVGTransformable} node the node reference for the SVGElement the ctm is queried
+ * @return CTM the current transformation matrix from the given node to the root element
+ * @type svg::SVGMatrix
+ * @version 1.0 (2007-05-01)
+ * @credits <a href="http://www.kevlindev.com/tutorials/basics/transformations/toUserSpace/index…">Kevin Lindsey (toUserSpace)</a>
+ * @see #getTransformToElement
+ */
+function getTransformToRootElement(node) {
+ try {
+ //this part is for fully conformant players (like Opera, Batik, Firefox, Safari ...)
+ var CTM = node.getTransformToElement(document.documentElement);
+ }
+ catch (ex) {
+ //this part is for ASV3 or other non-conformant players
+ // Initialize our CTM the node's Current Transformation Matrix
+ var CTM = node.getCTM();
+ // Work our way through the ancestor nodes stopping at the SVG Document
+ while ( ( node = node.parentNode ) != document ) {
+ // Multiply the new CTM to the one with what we have accumulated so far
+ CTM = node.getCTM().multiply(CTM);
+ }
+ }
+ return CTM;
+}
+
+/**
+ * returns the transformation matrix (ctm) for the given dom::Node up to a different dom::Node
+ * the basic use case is to provide a wrapper function for the missing SVGLocatable.getTransformToElement method (missing in ASV3)
+ * @param {svg::SVGTransformable} node the node reference for the element the where the ctm should be calculated from
+ * @param {svg::SVGTransformable} targetNode the target node reference for the element the ctm should be calculated to
+ * @return CTM the current transformation matrix from the given node to the target element
+ * @type svg::SVGMatrix
+ * @version 1.0 (2007-05-01)
+ * @credits <a href="http://www.kevlindev.com/tutorials/basics/transformations/toUserSpace/index…">Kevin Lindsey (toUserSpace)</a>
+ * @see #getTransformToRootElement
+ */
+function getTransformToElement(node,targetNode) {
+ try {
+ //this part is for fully conformant players
+ var CTM = node.getTransformToElement(targetNode);
+ }
+ catch (ex) {
+ //this part is for ASV3 or other non-conformant players
+ // Initialize our CTM the node's Current Transformation Matrix
+ var CTM = node.getCTM();
+ // Work our way through the ancestor nodes stopping at the SVG Document
+ while ( ( node = node.parentNode ) != targetNode ) {
+ // Multiply the new CTM to the one with what we have accumulated so far
+ CTM = node.getCTM().multiply(CTM);
+ }
+ }
+ return CTM;
+}
+
+/**
+ * converts HSV to RGB values
+ * @param {Number} hue the hue value (between 0 and 360)
+ * @param {Number} sat the saturation value (between 0 and 1)
+ * @param {Number} val the value value (between 0 and 1)
+ * @return rgbArr the rgb values (associative array or object, the keys are: red,green,blue), all values are scaled between 0 and 255
+ * @type Object
+ * @version 1.0 (2007-05-01)
+ * @see #rgb2hsv
+ */
+function hsv2rgb(hue,sat,val) {
+ var rgbArr = new Object();
+ if ( sat == 0) {
+ rgbArr["red"] = Math.round(val * 255);
+ rgbArr["green"] = Math.round(val * 255);
+ rgbArr["blue"] = Math.round(val * 255);
+ }
+ else {
+ var h = hue / 60;
+ var i = Math.floor(h);
+ var f = h - i;
+ if (i % 2 == 0) {
+ f = 1 - f;
+ }
+ var m = val * (1 - sat);
+ var n = val * (1 - sat * f);
+ switch(i) {
+ case 0:
+ rgbArr["red"] = val;
+ rgbArr["green"] = n;
+ rgbArr["blue"] = m;
+ break;
+ case 1:
+ rgbArr["red"] = n;
+ rgbArr["green"] = val;
+ rgbArr["blue"] = m;
+ break;
+ case 2:
+ rgbArr["red"] = m;
+ rgbArr["green"] = val;
+ rgbArr["blue"] = n;
+ break;
+ case 3:
+ rgbArr["red"] = m;
+ rgbArr["green"] = n;
+ rgbArr["blue"] = val;
+ break;
+ case 4:
+ rgbArr["red"] = n;
+ rgbArr["green"] = m;
+ rgbArr["blue"] = val;
+ break;
+ case 5:
+ rgbArr["red"] = val;
+ rgbArr["green"] = m;
+ rgbArr["blue"] = n;
+ break;
+ case 6:
+ rgbArr["red"] = val;
+ rgbArr["green"] = n;
+ rgbArr["blue"] = m;
+ break;
+ }
+ rgbArr["red"] = Math.round(rgbArr["red"] * 255);
+ rgbArr["green"] = Math.round(rgbArr["green"] * 255);
+ rgbArr["blue"] = Math.round(rgbArr["blue"] * 255);
+ }
+ return rgbArr;
+}
+
+/**
+ * converts RGB to HSV values
+ * @param {Number} red the hue value (between 0 and 255)
+ * @param {Number} green the saturation value (between 0 and 255)
+ * @param {Number} blue the value value (between 0 and 255)
+ * @return hsvArr the hsv values (associative array or object, the keys are: hue (0-360),sat (0-1),val (0-1))
+ * @type Object
+ * @version 1.0 (2007-05-01)
+ * @see #hsv2rgb
+ */
+function rgb2hsv(red,green,blue) {
+ var hsvArr = new Object();
+ red = red / 255;
+ green = green / 255;
+ blue = blue / 255;
+ myMax = Math.max(red, Math.max(green,blue));
+ myMin = Math.min(red, Math.min(green,blue));
+ v = myMax;
+ if (myMax > 0) {
+ s = (myMax - myMin) / myMax;
+ }
+ else {
+ s = 0;
+ }
+ if (s > 0) {
+ myDiff = myMax - myMin;
+ rc = (myMax - red) / myDiff;
+ gc = (myMax - green) / myDiff;
+ bc = (myMax - blue) / myDiff;
+ if (red == myMax) {
+ h = (bc - gc) / 6;
+ }
+ if (green == myMax) {
+ h = (2 + rc - bc) / 6;
+ }
+ if (blue == myMax) {
+ h = (4 + gc - rc) / 6;
+ }
+ }
+ else {
+ h = 0;
+ }
+ if (h < 0) {
+ h += 1;
+ }
+ hsvArr["hue"] = Math.round(h * 360);
+ hsvArr["sat"] = s;
+ hsvArr["val"] = v;
+ return hsvArr;
+}
+
+/**
+ * populates an array such that it can be addressed by both a key or an index nr,
+ * note that both Arrays need to be of the same length
+ * @param {Array} arrayKeys the array containing the keys
+ * @param {Array} arrayValues the array containing the values
+ * @return returnArray the resulting array containing both associative values and also a regular indexed array
+ * @type Array
+ * @version 1.0 (2007-05-01)
+ */
+function arrayPopulate(arrayKeys,arrayValues) {
+ var returnArray = new Array();
+ if (arrayKeys.length != arrayValues.length) {
+ alert("error: arrays do not have the same length!");
+ }
+ else {
+ for (i=0;i<arrayKeys.length;i++) {
+ returnArray[arrayKeys[i]] = arrayValues[i];
+ }
+ }
+ return returnArray;
+}
+
+/**
+ * Wrapper object for network requests, uses getURL or XMLHttpRequest depending on availability
+ * The callBackFunction receives a XML or text node representing the rootElement
+ * of the fragment received or the return text, depending on the returnFormat.
+ * See also the following <a href="http://www.carto.net/papers/svg/network_requests/">documentation</a>.
+ * @class this is a wrapper object to provide network request functionality (get|post)
+ * @param {String} url the URL/IRI of the network resource to be called
+ * @param {Function|Object} callBackFunction the callBack function or object that is called after the data was received, in case of an object, the method 'receiveData' is called; both the function and the object's 'receiveData' method get 2 return parameters: 'node.firstChild'|text (the root element of the XML or text resource), this.additionalParams (if defined)
+ * @param {String} returnFormat the return format, either 'xml' or 'json' (or text)
+ * @param {String} method the method of the network request, either 'get' or 'post'
+ * @param {String|Undefined} postText the String containing the post text (optional) or Undefined (if not a 'post' request)
+ * @param {Object|Array|String|Number|Undefined} additionalParams additional parameters that will be passed to the callBackFunction or object (optional) or Undefined
+ * @return a new getData instance
+ * @type getData
+ * @constructor
+ * @version 1.0 (2007-02-23)
+ */
+function getData(url,callBackFunction,returnFormat,method,postText,additionalParams) {
+ this.url = url;
+ this.callBackFunction = callBackFunction;
+ this.returnFormat = returnFormat;
+ this.method = method;
+ this.additionalParams = additionalParams;
+ if (method != "get" && method != "post") {
+ alert("Error in network request: parameter 'method' must be 'get' or 'post'");
+ }
+ this.postText = postText;
+ this.xmlRequest = null; //@private reference to the XMLHttpRequest object
+}
+
+/**
+ * triggers the network request defined in the constructor
+ */
+getData.prototype.getData = function() {
+ //call getURL() if available
+ if (window.getURL) {
+ if (this.method == "get") {
+ getURL(this.url,this);
+ }
+ if (this.method == "post") {
+ postURL(this.url,this.postText,this);
+ }
+ }
+ //or call XMLHttpRequest() if available
+ else if (window.XMLHttpRequest) {
+ var _this = this;
+ this.xmlRequest = new XMLHttpRequest();
+ if (this.method == "get") {
+ if (this.returnFormat == "xml") {
+ this.xmlRequest.overrideMimeType("text/xml");
+ }
+ this.xmlRequest.open("GET",this.url,true);
+ }
+ if (this.method == "post") {
+ this.xmlRequest.open("POST",this.url,true);
+ }
+ this.xmlRequest.onreadystatechange = function() {_this.handleEvent()};
+ if (this.method == "get") {
+ this.xmlRequest.send(null);
+ }
+ if (this.method == "post") {
+ //test if postText exists and is of type string
+ var reallyPost = true;
+ if (!this.postText) {
+ reallyPost = false;
+ alert("Error in network post request: missing parameter 'postText'!");
+ }
+ if (typeof(this.postText) != "string") {
+ reallyPost = false;
+ alert("Error in network post request: parameter 'postText' has to be of type 'string')");
+ }
+ if (reallyPost) {
+ this.xmlRequest.send(this.postText);
+ }
+ }
+ }
+ //write an error message if neither method is available
+ else {
+ alert("your browser/svg viewer neither supports window.getURL nor window.XMLHttpRequest!");
+ }
+}
+
+/**
+ * this is the callback method for the getURL() or postURL() case
+ * @private
+ */
+getData.prototype.operationComplete = function(data) {
+ //check if data has a success property
+ if (data.success) {
+ //parse content of the XML format to the variable "node"
+ if (this.returnFormat == "xml") {
+ //convert the text information to an XML node and get the first child
+ var node = parseXML(data.content,document);
+ //distinguish between a callback function and an object
+ if (typeof(this.callBackFunction) == "function") {
+ this.callBackFunction(node.firstChild,this.additionalParams);
+ }
+ if (typeof(this.callBackFunction) == "object") {
+ this.callBackFunction.receiveData(node.firstChild,this.additionalParams);
+ }
+ }
+ if (this.returnFormat == "json") {
+ if (typeof(this.callBackFunction) == "function") {
+ this.callBackFunction(data.content,this.additionalParams);
+ }
+ if (typeof(this.callBackFunction) == "object") {
+ this.callBackFunction.receiveData(data.content,this.additionalParams);
+ }
+ }
+ }
+ else {
+ alert("something went wrong with dynamic loading of geometry!");
+ }
+}
+
+/**
+ * this is the callback method for the XMLHttpRequest case
+ * @private
+ */
+getData.prototype.handleEvent = function() {
+ if (this.xmlRequest.readyState == 4) {
+ if (this.returnFormat == "xml") {
+ //we need to import the XML node first
+ var importedNode = document.importNode(this.xmlRequest.responseXML.documentElement,true);
+ if (typeof(this.callBackFunction) == "function") {
+ this.callBackFunction(importedNode,this.additionalParams);
+ }
+ if (typeof(this.callBackFunction) == "object") {
+ this.callBackFunction.receiveData(importedNode,this.additionalParams);
+ }
+ }
+ if (this.returnFormat == "json") {
+ if (typeof(this.callBackFunction) == "function") {
+ this.callBackFunction(this.xmlRequest.responseText,this.additionalParams);
+ }
+ if (typeof(this.callBackFunction) == "object") {
+ this.callBackFunction.receiveData(this.xmlRequest.responseText,this.additionalParams);
+ }
+ }
+ }
+}
+
+/**
+ * Serializes an XML node and returns a string representation. Wrapper function to hide implementation differences.
+ * This can be used for debugging purposes or to post data to a server or network resource.
+ * @param {dom::Node} node the DOM node reference
+ * @return textRepresentation the String representation of the XML node
+ * @type String
+ * @version 1.0 (2007-05-01)
+ * @see getData
+ */
+function serializeNode(node) {
+ if (typeof XMLSerializer != 'undefined') {
+ return new XMLSerializer().serializeToString(node);
+ }
+ else if (typeof node.xml != 'undefined') {
+ return node.xml;
+ }
+ else if (typeof printNode != 'undefined') {
+ return printNode(node);
+ }
+ else if (typeof Packages != 'undefined') {
+ try {
+ var stringWriter = new java.io.StringWriter();
+ Packages.org.apache.batik.dom.util.DOMUtilities.writeNode(node,stringWriter);
+ return stringWriter.toString();
+ }
+ catch (e) {
+ alert("Sorry, your SVG viewer does not support the printNode/serialize function.");
+ return '';
+ }
+ }
+ else {
+ alert("Sorry, your SVG viewer does not support the printNode/serialize function.");
+ return '';
+ }
+}
+
+/**
+ * Starts a SMIL animation element with the given id by triggering the '.beginElement()' method.
+ * This is a convenience (shortcut) function.
+ * @param {String} id a valid id of a valid SMIL animation element
+ * @version 1.0 (2007-05-01)
+ */
+//starts an animtion with the given id
+//this function is useful in combination with window.setTimeout()
+function startAnimation(id) {
+ document.getElementById(id).beginElement();
+}
diff -r 0dc1fc63c945 -r 0b682d3dd01b static/scripts/timer.js
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/static/scripts/timer.js Tue Apr 13 11:15:35 2010 -0400
@@ -0,0 +1,74 @@
+// source/credits: "Algorithm": http://www.codingforums.com/showthread.php?s=&threadid=10531
+// The constructor should be called with
+// the parent object (optional, defaults to window).
+
+function Timer(){
+ this.obj = (arguments.length)?arguments[0]:window;
+ return this;
+}
+
+// The set functions should be called with:
+// - The name of the object method (as a string) (required)
+// - The millisecond delay (required)
+// - Any number of extra arguments, which will all be
+// passed to the method when it is evaluated.
+
+Timer.prototype.setInterval = function(func, msec){
+ var i = Timer.getNew();
+ var t = Timer.buildCall(this.obj, i, arguments);
+ Timer.set[i].timer = window.setInterval(t,msec);
+ return i;
+}
+Timer.prototype.setTimeout = function(func, msec){
+ var i = Timer.getNew();
+ Timer.buildCall(this.obj, i, arguments);
+ Timer.set[i].timer = window.setTimeout("Timer.callOnce("+i+");",msec);
+ return i;
+}
+
+// The clear functions should be called with
+// the return value from the equivalent set function.
+
+Timer.prototype.clearInterval = function(i){
+ if(!Timer.set[i]) return;
+ window.clearInterval(Timer.set[i].timer);
+ Timer.set[i] = null;
+}
+Timer.prototype.clearTimeout = function(i){
+ if(!Timer.set[i]) return;
+ window.clearTimeout(Timer.set[i].timer);
+ Timer.set[i] = null;
+}
+
+// Private data
+
+Timer.set = new Array();
+Timer.buildCall = function(obj, i, args){
+ var t = "";
+ Timer.set[i] = new Array();
+ if(obj != window){
+ Timer.set[i].obj = obj;
+ t = "Timer.set["+i+"].obj.";
+ }
+ t += args[0]+"(";
+ if(args.length > 2){
+ Timer.set[i][0] = args[2];
+ t += "Timer.set["+i+"][0]";
+ for(var j=1; (j+2)<args.length; j++){
+ Timer.set[i][j] = args[j+2];
+ t += ", Timer.set["+i+"]["+j+"]";
+ }}
+ t += ");";
+ Timer.set[i].call = t;
+ return t;
+}
+Timer.callOnce = function(i){
+ if(!Timer.set[i]) return;
+ eval(Timer.set[i].call);
+ Timer.set[i] = null;
+}
+Timer.getNew = function(){
+ var i = 0;
+ while(Timer.set[i]) i++;
+ return i;
+}
\ No newline at end of file
diff -r 0dc1fc63c945 -r 0b682d3dd01b tools/rgenetics/rgGRR.py
--- a/tools/rgenetics/rgGRR.py Tue Apr 13 10:22:27 2010 -0400
+++ b/tools/rgenetics/rgGRR.py Tue Apr 13 11:15:35 2010 -0400
@@ -1,1096 +1,1145 @@
-"""
-# july 2009: Need to see outliers so need to draw them last?
-# could use clustering on the zscores to guess real relationships for unrelateds
-# but definitely need to draw last
-# added MAX_SHOW_ROWS to limit the length of the main report page
-# Changes for Galaxy integration
-# added more robust knuth method for one pass mean and sd
-# no difference really - let's use scipy.mean() and scipy.std() instead...
-# fixed labels and changed to .xls for outlier reports so can open in excel
-# interesting - with a few hundred subjects, 5k gives good resolution
-# and 100k gives better but not by much
-# TODO remove non autosomal markers
-# TODO it would be best if label had the zmean and zsd as these are what matter for
-# outliers rather than the group mean/sd
-# mods to rgGRR.py from channing CVS which John Ziniti has rewritten to produce SVG plots
-# to make a Galaxy tool - we need the table of mean and SD for interesting pairs, the SVG and the log
-# so the result should be an HTML file
-
-# rgIBS.py
-# use a random subset of markers for a quick ibs
-# to identify sample dups and closely related subjects
-# try snpMatrix and plink and see which one works best for us?
-# abecasis grr plots mean*sd for every subject to show clusters
-# mods june 23 rml to avoid non-autosomal markers
-# we seem to be distinguishing parent-child by gender - 2 clouds!
-
-
-snpMatrix from David Clayton has:
-ibs.stats function to calculate the identity-by-state stats of a group of samples
-Description
-Given a snp.matrix-class or a X.snp.matrix-class object with N samples, calculates some statistics
-about the relatedness of every pair of samples within.
-
-Usage
-ibs.stats(x)
-8 ibs.stats
-Arguments
-x a snp.matrix-class or a X.snp.matrix-class object containing N samples
-Details
-No-calls are excluded from consideration here.
-Value
-A data.frame containing N(N - 1)/2 rows, where the row names are the sample name pairs separated
-by a comma, and the columns are:
-Count count of identical calls, exclusing no-calls
-Fraction fraction of identical calls comparied to actual calls being made in both samples
-Warning
-In some applications, it may be preferable to subset a (random) selection of SNPs first - the
-calculation
-time increases as N(N - 1)M/2 . Typically for N = 800 samples and M = 3000 SNPs, the
-calculation time is about 1 minute. A full GWA scan could take hours, and quite unnecessary for
-simple applications such as checking for duplicate or related samples.
-Note
-This is mostly written to find mislabelled and/or duplicate samples.
-Illumina indexes their SNPs in alphabetical order so the mitochondria SNPs comes first - for most
-purpose it is undesirable to use these SNPs for IBS purposes.
-TODO: Worst-case S4 subsetting seems to make 2 copies of a large object, so one might want to
-subset before rbind(), etc; a future version of this routine may contain a built-in subsetting facility
-"""
-import sys,os,time,random,string,copy,optparse
-
-try:
- set
-except NameError:
- from Sets import Set as set
-
-from rgutils import timenow
-import plinkbinJZ
-
-
-opts = None
-verbose = False
-
-showPolygons = False
-
-class NullDevice:
- def write(self, s):
- pass
-
-tempstderr = sys.stderr # save
-sys.stderr = NullDevice()
-# need to avoid blather about deprecation and other strange stuff from scipy
-# the current galaxy job runner assumes that
-# the job is in error if anything appears on sys.stderr
-# grrrrr. James wants to keep it that way instead of using the
-# status flag for some strange reason. Presumably he doesn't use R or (in this case, scipy)
-import numpy
-import scipy
-from scipy import weave
-
-
-sys.stderr=tempstderr
-
-
-PROGNAME = os.path.split(sys.argv[0])[-1]
-X_AXIS_LABEL = 'Mean Alleles Shared'
-Y_AXIS_LABEL = 'SD Alleles Shared'
-LEGEND_ALIGN = 'topleft'
-LEGEND_TITLE = 'Relationship'
-DEFAULT_SYMBOL_SIZE = 1.0 # default symbol size
-DEFAULT_SYMBOL_SIZE = 0.5 # default symbol size
-
-### Some colors for R/rpy
-R_BLACK = 1
-R_RED = 2
-R_GREEN = 3
-R_BLUE = 4
-R_CYAN = 5
-R_PURPLE = 6
-R_YELLOW = 7
-R_GRAY = 8
-
-### ... and some point-styles
-
-###
-PLOT_HEIGHT = 600
-PLOT_WIDTH = 1150
-
-
-#SVG_COLORS = ('black', 'darkblue', 'blue', 'deepskyblue', 'firebrick','maroon','crimson')
-#SVG_COLORS = ('cyan','dodgerblue','mediumpurple', 'fuchsia', 'red','gold','gray')
-SVG_COLORS = ('cyan','dodgerblue','mediumpurple','forestgreen', 'lightgreen','gold','gray')
-# dupe,parentchild,sibpair,halfsib,parents,unrel,unkn
-#('orange', 'red', 'green', 'chartreuse', 'blue', 'purple', 'gray')
-
-OUTLIERS_HEADER = 'Mean\tSdev\tZ(mean)\tZ(sdev)\tFID1\tIID1\tFID2\tIID2\tMean(Rel_Mean)\tSdev(Rel_Mean)\tMean(Rel_Sdev)\tSdev(Rel_Sdev)\n'
-OUTLIERS_HEADER_list = ['Mean','Sdev','ZMean','ZSdev','FID1','IID1','FID2','IID2',
-'RGMean_M','RGMean_SD','RGSD_M','RGSD_SD']
-TABLE_HEADER='fid1 iid1\tfid2 iid2\tmean\tsdev\tzmean\tzsdev\tgeno\trelcode\n'
-
-
-### Relationship codes, text, and lookups/mappings
-N_RELATIONSHIP_TYPES = 7
-REL_DUPE, REL_PARENTCHILD, REL_SIBS, REL_HALFSIBS, REL_RELATED, REL_UNRELATED, REL_UNKNOWN = range(N_RELATIONSHIP_TYPES)
-REL_LOOKUP = {
- REL_DUPE: ('dupe', R_BLUE, 1),
- REL_PARENTCHILD: ('parentchild', R_YELLOW, 1),
- REL_SIBS: ('sibpairs', R_RED, 1),
- REL_HALFSIBS: ('halfsibs', R_GREEN, 1),
- REL_RELATED: ('parents', R_PURPLE, 1),
- REL_UNRELATED: ('unrelated', R_CYAN, 1),
- REL_UNKNOWN: ('unknown', R_GRAY, 1),
- }
-OUTLIER_STDEVS = {
- REL_DUPE: 2,
- REL_PARENTCHILD: 2,
- REL_SIBS: 2,
- REL_HALFSIBS: 2,
- REL_RELATED: 2,
- REL_UNRELATED: 3,
- REL_UNKNOWN: 2,
- }
-# note now Z can be passed in
-
-REL_STATES = [REL_LOOKUP[r][0] for r in range(N_RELATIONSHIP_TYPES)]
-REL_COLORS = SVG_COLORS
-REL_POINTS = [REL_LOOKUP[r][2] for r in range(N_RELATIONSHIP_TYPES)]
-
-DEFAULT_MAX_SAMPLE_SIZE = 10000
-
-REF_COUNT_HOM1 = 3
-REF_COUNT_HET = 2
-REF_COUNT_HOM2 = 1
-MISSING = 0
-MAX_SHOW_ROWS = 100 # framingham has millions - delays showing output page - so truncate and explain
-MARKER_PAIRS_PER_SECOND_SLOW = 15000000.0
-MARKER_PAIRS_PER_SECOND_FAST = 70000000.0
-
-
-galhtmlprefix = """<?xml version="1.0" encoding="utf-8" ?>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta name="generator" content="Galaxy %s tool output - see http://g2.trac.bx.psu.edu/" />
-<title></title>
-<link rel="stylesheet" href="/static/style/base.css" type="text/css" />
-</head>
-<body>
-<div class="document">
-"""
-
-
-SVG_HEADER = '''<?xml version="1.0" standalone="no"?>
-<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.2//EN" "http://www.w3.org/Graphics/SVG/1.2/DTD/svg12.dtd">
-
-<svg width="1280" height="800"
- xmlns="http://www.w3.org/2000/svg" version="1.2"
- xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 1280 800" onload="init()">
-
- <script type="text/ecmascript" xlink:href="/static/scripts/tools/rgenetics/checkbox_and_radiobutton.js"/>
- <script type="text/ecmascript" xlink:href="/static/scripts/tools/rgenetics/helper_functions.js"/>
- <script type="text/ecmascript" xlink:href="/static/scripts/tools/rgenetics/timer.js"/>
- <script type="text/ecmascript">
- <![CDATA[
- var checkBoxes = new Array();
- var radioGroupBandwidth;
- var colours = ['%s','%s','%s','%s','%s','%s','%s'];
- function init() {
- var style = {"font-family":"Arial,Helvetica", "fill":"black", "font-size":12};
- var dist = 12;
- var yOffset = 4;
-
- //A checkBox for each relationship type dupe,parentchild,sibpair,halfsib,parents,unrel,unkn
- checkBoxes["dupe"] = new checkBox("dupe","checkboxes",20,40,"cbRect","cbCross",true,"Duplicate",style,dist,yOffset,undefined,hideShowLayer);
- checkBoxes["parentchild"] = new checkBox("parentchild","checkboxes",20,60,"cbRect","cbCross",true,"Parent-Child",style,dist,yOffset,undefined,hideShowLayer);
- checkBoxes["sibpairs"] = new checkBox("sibpairs","checkboxes",20,80,"cbRect","cbCross",true,"Sib-pairs",style,dist,yOffset,undefined,hideShowLayer);
- checkBoxes["halfsibs"] = new checkBox("halfsibs","checkboxes",20,100,"cbRect","cbCross",true,"Half-sibs",style,dist,yOffset,undefined,hideShowLayer);
- checkBoxes["parents"] = new checkBox("parents","checkboxes",20,120,"cbRect","cbCross",true,"Parents",style,dist,yOffset,undefined,hideShowLayer);
- checkBoxes["unrelated"] = new checkBox("unrelated","checkboxes",20,140,"cbRect","cbCross",true,"Unrelated",style,dist,yOffset,undefined,hideShowLayer);
- checkBoxes["unknown"] = new checkBox("unknown","checkboxes",20,160,"cbRect","cbCross",true,"Unknown",style,dist,yOffset,undefined,hideShowLayer);
-
- }
-
- function hideShowLayer(id, status, label) {
- var vis = "hidden";
- if (status) {
- vis = "visible";
- }
- document.getElementById(id).setAttributeNS(null, 'visibility', vis);
- }
-
- function showBTT(evt, rel, mm, dm, md, dd, n, mg, dg, lg, hg) {
- var x = parseInt(evt.pageX)-250;
- var y = parseInt(evt.pageY)-110;
- switch(rel) {
- case 0:
- fill = colours[rel];
- relt = "dupe";
- break;
- case 1:
- fill = colours[rel];
- relt = "parentchild";
- break;
- case 2:
- fill = colours[rel];
- relt = "sibpairs";
- break;
- case 3:
- fill = colours[rel];
- relt = "halfsibs";
- break;
- case 4:
- fill = colours[rel];
- relt = "parents";
- break;
- case 5:
- fill = colours[rel];
- relt = "unrelated";
- break;
- case 6:
- fill = colours[rel];
- relt = "unknown";
- break;
- default:
- fill = "cyan";
- relt = "ERROR_CODE: "+rel;
- }
-
- document.getElementById("btRel").textContent = "GROUP: "+relt;
- document.getElementById("btMean").textContent = "mean="+mm+" +/- "+dm;
- document.getElementById("btSdev").textContent = "sdev="+dm+" +/- "+dd;
- document.getElementById("btPair").textContent = "npairs="+n;
- document.getElementById("btGeno").textContent = "ngenos="+mg+" +/- "+dg+" (min="+lg+", max="+hg+")";
- document.getElementById("btHead").setAttribute('fill', fill);
-
- var tt = document.getElementById("btTip");
- tt.setAttribute("transform", "translate("+x+","+y+")");
- tt.setAttribute('visibility', 'visible');
- }
-
- function showOTT(evt, rel, s1, s2, mean, sdev, ngeno, rmean, rsdev) {
- var x = parseInt(evt.pageX)-150;
- var y = parseInt(evt.pageY)-180;
-
- switch(rel) {
- case 0:
- fill = colours[rel];
- relt = "dupe";
- break;
- case 1:
- fill = colours[rel];
- relt = "parentchild";
- break;
- case 2:
- fill = colours[rel];
- relt = "sibpairs";
- break;
- case 3:
- fill = colours[rel];
- relt = "halfsibs";
- break;
- case 4:
- fill = colours[rel];
- relt = "parents";
- break;
- case 5:
- fill = colours[rel];
- relt = "unrelated";
- break;
- case 6:
- fill = colours[rel];
- relt = "unknown";
- break;
- default:
- fill = "cyan";
- relt = "ERROR_CODE: "+rel;
- }
-
- document.getElementById("otRel").textContent = "PAIR: "+relt;
- document.getElementById("otS1").textContent = "s1="+s1;
- document.getElementById("otS2").textContent = "s2="+s2;
- document.getElementById("otMean").textContent = "mean="+mean;
- document.getElementById("otSdev").textContent = "sdev="+sdev;
- document.getElementById("otGeno").textContent = "ngenos="+ngeno;
- document.getElementById("otRmean").textContent = "relmean="+rmean;
- document.getElementById("otRsdev").textContent = "relsdev="+rsdev;
- document.getElementById("otHead").setAttribute('fill', fill);
-
- var tt = document.getElementById("otTip");
- tt.setAttribute("transform", "translate("+x+","+y+")");
- tt.setAttribute('visibility', 'visible');
- }
-
- function hideBTT(evt) {
- document.getElementById("btTip").setAttributeNS(null, 'visibility', 'hidden');
- }
-
- function hideOTT(evt) {
- document.getElementById("otTip").setAttributeNS(null, 'visibility', 'hidden');
- }
-
- ]]>
- </script>
- <defs>
- <!-- symbols for check boxes -->
- <symbol id="cbRect" overflow="visible">
- <rect x="-5" y="-5" width="10" height="10" fill="white" stroke="dimgray" stroke-width="1" cursor="pointer"/>
- </symbol>
- <symbol id="cbCross" overflow="visible">
- <g pointer-events="none" stroke="black" stroke-width="1">
- <line x1="-3" y1="-3" x2="3" y2="3"/>
- <line x1="3" y1="-3" x2="-3" y2="3"/>
- </g>
- </symbol>
- </defs>
-
-<desc>Developer Works Dynamic Scatter Graph Scaling Example</desc>
-
-<!-- Now Draw the main X and Y axis -->
-<g style="stroke-width:1.0; stroke:black; shape-rendering:crispEdges">
- <!-- X Axis top and bottom -->
- <path d="M 100 100 L 1250 100 Z"/>
- <path d="M 100 700 L 1250 700 Z"/>
-
- <!-- Y Axis left and right -->
- <path d="M 100 100 L 100 700 Z"/>
- <path d="M 1250 100 L 1250 700 Z"/>
-</g>
-
-<g transform="translate(100,100)">
-
- <!-- Grid Lines -->
- <g style="fill:none; stroke:#dddddd; stroke-width:1; stroke-dasharray:2,2; text-anchor:end; shape-rendering:crispEdges">
-
- <!-- Vertical grid lines -->
- <line x1="125" y1="0" x2="115" y2="600" />
- <line x1="230" y1="0" x2="230" y2="600" />
- <line x1="345" y1="0" x2="345" y2="600" />
- <line x1="460" y1="0" x2="460" y2="600" />
- <line x1="575" y1="0" x2="575" y2="600" style="stroke-dasharray:none;" />
- <line x1="690" y1="0" x2="690" y2="600" />
- <line x1="805" y1="0" x2="805" y2="600" />
- <line x1="920" y1="0" x2="920" y2="600" />
- <line x1="1035" y1="0" x2="1035" y2="600" />
-
- <!-- Horizontal grid lines -->
- <line x1="0" y1="60" x2="1150" y2="60" />
- <line x1="0" y1="120" x2="1150" y2="120" />
- <line x1="0" y1="180" x2="1150" y2="180" />
- <line x1="0" y1="240" x2="1150" y2="240" />
- <line x1="0" y1="300" x2="1150" y2="300" style="stroke-dasharray:none;" />
- <line x1="0" y1="360" x2="1150" y2="360" />
- <line x1="0" y1="420" x2="1150" y2="420" />
- <line x1="0" y1="480" x2="1150" y2="480" />
- <line x1="0" y1="540" x2="1150" y2="540" />
- </g>
-
- <!-- Legend -->
- <g style="fill:black; stroke:none" font-size="12" font-family="Arial" transform="translate(25,25)">
- <rect width="160" height="270" style="fill:none; stroke:black; shape-rendering:crispEdges" />
- <text x="5" y="20" style="fill:black; stroke:none;" font-size="13" font-weight="bold">Given Pair Relationship</text>
- <rect x="120" y="35" width="10" height="10" fill="%s" stroke="%s" stroke-width="1" cursor="pointer"/>
- <rect x="120" y="55" width="10" height="10" fill="%s" stroke="%s" stroke-width="1" cursor="pointer"/>
- <rect x="120" y="75" width="10" height="10" fill="%s" stroke="%s" stroke-width="1" cursor="pointer"/>
- <rect x="120" y="95" width="10" height="10" fill="%s" stroke="%s" stroke-width="1" cursor="pointer"/>
- <rect x="120" y="115" width="10" height="10" fill="%s" stroke="%s" stroke-width="1" cursor="pointer"/>
- <rect x="120" y="135" width="10" height="10" fill="%s" stroke="%s" stroke-width="1" cursor="pointer"/>
- <rect x="120" y="155" width="10" height="10" fill="%s" stroke="%s" stroke-width="1" cursor="pointer"/>
- <text x="15" y="195" style="fill:black; stroke:none" font-size="12" font-family="Arial" >Zscore gt 15</text>
- <circle cx="125" cy="192" r="6" style="stroke:red; fill:gold; fill-opacity:1.0; stroke-width:1;"/>
- <text x="15" y="215" style="fill:black; stroke:none" font-size="12" font-family="Arial" >Zscore 4 to 15</text>
- <circle cx="125" cy="212" r="3" style="stroke:gold; fill:gold; fill-opacity:1.0; stroke-width:1;"/>
- <text x="15" y="235" style="fill:black; stroke:none" font-size="12" font-family="Arial" >Zscore lt 4</text>
- <circle cx="125" cy="232" r="2" style="stroke:gold; fill:gold; fill-opacity:1.0; stroke-width:1;"/>
- <g id="checkboxes">
- </g>
- </g>
-
-
- <g style='fill:black; stroke:none' font-size="17" font-family="Arial">
- <!-- X Axis Labels -->
- <text x="480" y="660">Mean Alleles Shared</text>
- <text x="0" y="630" >1.0</text>
- <text x="277" y="630" >1.25</text>
- <text x="564" y="630" >1.5</text>
- <text x="842" y="630" >1.75</text>
- <text x="1140" y="630" >2.0</text>
- </g>
-
- <g transform="rotate(270)" style="fill:black; stroke:none" font-size="17" font-family="Arial">
- <!-- Y Axis Labels -->
- <text x="-350" y="-40">SD Alleles Shared</text>
- <text x="-20" y="-10" >1.0</text>
- <text x="-165" y="-10" >0.75</text>
- <text x="-310" y="-10" >0.5</text>
- <text x="-455" y="-10" >0.25</text>
- <text x="-600" y="-10" >0.0</text>
- </g>
-
-<!-- Plot Title -->
-<g style="fill:black; stroke:none" font-size="18" font-family="Arial">
- <text x="425" y="-30">%s</text>
-</g>
-
-<!-- One group/layer of points for each relationship type -->
-'''
-
-SVG_FOOTER = '''
-<!-- End of Data -->
-</g>
-<g id="btTip" visibility="hidden" style="stroke-width:1.0; fill:black; stroke:none;" font-size="10" font-family="Arial">
- <rect width="250" height="110" style="fill:silver" rx="2" ry="2"/>
- <rect id="btHead" width="250" height="20" rx="2" ry="2" />
- <text id="btRel" y="14" x="85">unrelated</text>
- <text id="btMean" y="40" x="4">mean=1.5 +/- 0.04</text>
- <text id="btSdev" y="60" x="4">sdev=0.7 +/- 0.03</text>
- <text id="btPair" y="80" x="4">npairs=1152</text>
- <text id="btGeno" y="100" x="4">ngenos=4783 +/- 24 (min=1000, max=5000)</text>
-</g>
-
-<g id="otTip" visibility="hidden" style="stroke-width:1.0; fill:black; stroke:none;" font-size="10" font-family="Arial">
- <rect width="150" height="180" style="fill:silver" rx="2" ry="2"/>
- <rect id="otHead" width="150" height="20" rx="2" ry="2" />
- <text id="otRel" y="14" x="40">sibpairs</text>
- <text id="otS1" y="40" x="4">s1=fid1,iid1</text>
- <text id="otS2" y="60" x="4">s2=fid2,iid2</text>
- <text id="otMean" y="80" x="4">mean=1.82</text>
- <text id="otSdev" y="100" x="4">sdev=0.7</text>
- <text id="otGeno" y="120" x="4">ngeno=4487</text>
- <text id="otRmean" y="140" x="4">relmean=1.85</text>
- <text id="otRsdev" y="160" x="4">relsdev=0.65</text>
-</g>
-</svg>
-'''
-
-OUTLIERS_HEADER = 'Mean\tSdev\tZ(mean)\tZ(sdev)\tFID1\tIID1\tFID2\tIID2\tMean(Mean)\tSdev(Mean)\tMean(Sdev)\tSdev(Sdev)\n'
-
-DEFAULT_MAX_SAMPLE_SIZE = 5000
-
-REF_COUNT_HOM1 = 3
-REF_COUNT_HET = 2
-REF_COUNT_HOM2 = 1
-MISSING = 0
-
-MARKER_PAIRS_PER_SECOND_SLOW = 15000000
-MARKER_PAIRS_PER_SECOND_FAST = 70000000
-
-POLYGONS = {
- REL_UNRELATED: ((1.360, 0.655), (1.385, 0.730), (1.620, 0.575), (1.610, 0.505)),
- REL_HALFSIBS: ((1.630, 0.500), (1.630, 0.550), (1.648, 0.540), (1.648, 0.490)),
- REL_SIBS: ((1.660, 0.510), (1.665, 0.560), (1.820, 0.410), (1.820, 0.390)),
- REL_PARENTCHILD: ((1.650, 0.470), (1.650, 0.490), (1.750, 0.440), (1.750, 0.420)),
- REL_DUPE: ((1.970, 0.000), (1.970, 0.150), (2.000, 0.150), (2.000, 0.000)),
- }
-
-def distance(point1, point2):
- """ Calculate the distance between two points
- """
- (x1,y1) = [float(d) for d in point1]
- (x2,y2) = [float(d) for d in point2]
- dx = abs(x1 - x2)
- dy = abs(y1 - y2)
- return math.sqrt(dx**2 + dy**2)
-
-def point_inside_polygon(x, y, poly):
- """ Determine if a point (x,y) is inside a given polygon or not
- poly is a list of (x,y) pairs.
-
- Taken from: http://www.ariel.com.au/a/python-point-int-poly.html
- """
-
- n = len(poly)
- inside = False
-
- p1x,p1y = poly[0]
- for i in range(n+1):
- p2x,p2y = poly[i % n]
- if y > min(p1y,p2y):
- if y <= max(p1y,p2y):
- if x <= max(p1x,p2x):
- if p1y != p2y:
- xinters = (y-p1y)*(p2x-p1x)/(p2y-p1y)+p1x
- if p1x == p2x or x <= xinters:
- inside = not inside
- p1x,p1y = p2x,p2y
- return inside
-
-def readMap(pedfile):
- """
- """
- mapfile = pedfile.replace('.ped', '.map')
- marker_list = []
- if os.path.exists(mapfile):
- print 'readMap: %s' % (mapfile)
- fh = file(mapfile, 'r')
- for line in fh:
- marker_list.append(line.strip().split())
- fh.close()
- print 'readMap: %s markers' % (len(marker_list))
- return marker_list
-
-def calcMeanSD(useme):
- """
- A numerically stable algorithm is given below. It also computes the mean.
- This algorithm is due to Knuth,[1] who cites Welford.[2]
- n = 0
- mean = 0
- M2 = 0
-
- foreach x in data:
- n = n + 1
- delta = x - mean
- mean = mean + delta/n
- M2 = M2 + delta*(x - mean) // This expression uses the new value of mean
- end for
-
- variance_n = M2/n
- variance = M2/(n - 1)
- """
- mean = 0.0
- M2 = 0.0
- sd = 0.0
- n = len(useme)
- if n > 1:
- for i,x in enumerate(useme):
- delta = x - mean
- mean = mean + delta/(i+1) # knuth uses n+=1 at start
- M2 = M2 + delta*(x - mean) # This expression uses the new value of mean
- variance = M2/(n-1) # assume is sample so lose 1 DOF
- sd = pow(variance,0.5)
- return mean,sd
-
-
-def doIBSpy(inpath='',basename='',outdir=None,logf=None,
- nrsSamples=10000,title='title',pdftoo=0,Zcutoff=2.0):
- #def doIBS(pedName, title, nrsSamples=None, pdftoo=False):
- """ started with snpmatrix but GRR uses actual IBS counts and sd's
- """
- repOut = [] # text strings to add to the html display
- refallele = {}
- tblf = '%s_table.xls' % (title)
- tbl = file(os.path.join(outdir,tblf), 'w')
- tbl.write(TABLE_HEADER)
- svgf = '%s.svg' % (title)
- svg = file(os.path.join(outdir,svgf), 'w')
-
- bedname = '%s.bed' % (inpath)
- pedname = '%s.ped' % (inpath)
- print 'pedname',pedname
- if os.path.exists(bedname):
- ped = plinkbinJZ.BPed(inpath)
- ped.parse(quick=True)
- elif os.path.exists(pedname):
- ped = plinkbinJZ.LPed(inpath)
- ped.parse()
- else:
- print >> sys.stdout, '## doIBSpy problem - cannot open %s or %s - cannot run' % (bedname,pedname)
- nMarkers = len(ped._markers)
- if nMarkers < 5:
- print sys.stderr, '### ERROR - %d is too few markers for reliable estimation in %s - terminating' % (nMarkers,PROGNAME)
- sys.exit(1)
- nSubjects = len(ped._subjects)
- nrsSamples = min(nMarkers, nrsSamples)
- if opts and opts.use_mito:
- markers = range(nMarkers)
- nrsSamples = min(len(markers), nrsSamples)
- sampleIndexes = sorted(random.sample(markers, nrsSamples))
- else:
- autosomals = ped.autosomal_indices()
- nrsSamples = min(len(autosomals), nrsSamples)
- sampleIndexes = sorted(random.sample(autosomals, nrsSamples))
-
- print ''
- print 'Getting random.sample of %s from %s total' % (nrsSamples, nMarkers)
- npairs = (nSubjects*(nSubjects-1))/2 # total rows in table
- newfiles=[svgf,tblf]
- explanations = ['rgGRR Plot (requires SVG)','Mean by SD alleles shared - %d rows' % npairs]
- # these go with the output file links in the html file
- s = 'Reading genotypes for %s subjects and %s markers\n' % (nSubjects, nrsSamples)
- logf.write(s)
- minUsegenos = nrsSamples/2 # must have half?
- nGenotypes = nSubjects*nrsSamples
- stime = time.time()
- emptyRows = set()
- genos = numpy.zeros((nSubjects, nrsSamples), dtype=int)
- for s in xrange(nSubjects):
- nValid = 0
- #getGenotypesByIndices(self, s, mlist, format)
- genos[s] = ped.getGenotypesByIndices(s, sampleIndexes, format='ref')
- nValid = sum([1 for g in genos[s] if g])
- if not nValid:
- emptyRows.add(s)
- sub = ped.getSubject(s)
- print 'All missing for row %d (%s)' % (s, sub)
- logf.write('All missing for row %d (%s)\n' % (s, sub))
- rtime = time.time() - stime
- if verbose:
- print '@@Read %s genotypes in %s seconds' % (nGenotypes, rtime)
-
-
- ### Now the expensive part. For each pair of subjects, we get the mean number
- ### and standard deviation of shared alleles over all of the markers where both
- ### subjects have a known genotype. Identical subjects should have mean shared
- ### alleles very close to 2.0 with a standard deviation very close to 0.0.
- tot = nSubjects*(nSubjects-1)/2
- nprog = tot/10
- nMarkerpairs = tot * nrsSamples
- estimatedTimeSlow = nMarkerpairs/MARKER_PAIRS_PER_SECOND_SLOW
- estimatedTimeFast = nMarkerpairs/MARKER_PAIRS_PER_SECOND_FAST
-
- pairs = []
- pair_data = {}
- means = [] ## Mean IBS for each pair
- ngenoL = [] ## Count of comparable genotypes for each pair
- sdevs = [] ## Standard dev for each pair
- rels = [] ## A relationship code for each pair
- zmeans = [0.0 for x in xrange(tot)] ## zmean score for each pair for the relgroup
- zstds = [0.0 for x in xrange(tot)] ## zstd score for each pair for the relgrp
- skip = set()
- ndone = 0 ## How many have been done so far
-
- logf.write('Calculating %d pairs, updating every %d pairs...\n' % (tot, nprog))
- logf.write('Estimated time is %2.2f to %2.2f seconds ...\n' % (estimatedTimeFast, estimatedTimeSlow))
-
- t1sum = 0
- t2sum = 0
- t3sum = 0
- now = time.time()
- scache = {}
- _founder_cache = {}
- C_CODE = """
- #include "math.h"
- int i;
- int sumibs = 0;
- int ssqibs = 0;
- int ngeno = 0;
- float mean = 0;
- float M2 = 0;
- float delta = 0;
- float sdev=0;
- float variance=0;
- for (i=0; i<nrsSamples; i++) {
- int a1 = g1[i];
- int a2 = g2[i];
- if (a1 != 0 && a2 != 0) {
- ngeno += 1;
- int shared = 2-abs(a1-a2);
- delta = shared - mean;
- mean = mean + delta/ngeno;
- M2 += delta*(shared-mean);
- // yes that second time, the updated mean is used see calcmeansd above;
- //printf("%d %d %d %d %d %d\\n", i, a1, a2, ngeno, shared, squared);
- }
- }
- if (ngeno > 1) {
- variance = M2/(ngeno-1);
- sdev = sqrt(variance);
- //printf("OK: %d %3.2f %3.2f\\n", ngeno, mean, sdev);
- }
- //printf("%d %d %d %1.2f %1.2f\\n", ngeno, sumibs, ssqibs, mean, sdev);
- result[0] = ngeno;
- result[1] = mean;
- result[2] = sdev;
- return_val = ngeno;
- """
- started = time.time()
- for s1 in xrange(nSubjects):
- if s1 in emptyRows:
- continue
- (fid1,iid1,did1,mid1,sex1,phe1,iid1,d_sid1,m_sid1) = scache.setdefault(s1, ped.getSubject(s1))
-
- isFounder1 = _founder_cache.setdefault(s1, (did1==mid1))
- g1 = genos[s1]
-
- for s2 in xrange(s1+1, nSubjects):
- if s2 in emptyRows:
- continue
- if nprog and ndone % nprog == 0 and ndone > 1:
- dur = time.time() - started
- pct = float(ndone)/tot*100.0
- logf.write('%f sec at pair %d of %d (%3.2f%%): %f marker*pairs/sec\n' % (dur, ndone, tot, pct, ndone/dur*nrsSamples))
- t1s = time.time()
-
- (fid2,iid2,did2,mid2,sex2,phe2,iid2,d_sid2,m_sid2) = scache.setdefault(s2, ped.getSubject(s2))
-
- g2 = genos[s2]
- isFounder2 = _founder_cache.setdefault(s2, (did2==mid2))
-
- # Determine the relationship for this pair
- relcode = REL_UNKNOWN
- if (fid2 == fid1):
- if iid1 == iid2:
- relcode = REL_DUPE
- elif (did2 == did1) and (mid2 == mid1) and did1 != mid1:
- relcode = REL_SIBS
- elif (iid1 == mid2) or (iid1 == did2) or (iid2 == mid1) or (iid2 == did1):
- relcode = REL_PARENTCHILD
- elif (str(did1) != '0' and (did2 == did1)) or (str(mid1) != '0' and (mid2 == mid1)):
- relcode = REL_HALFSIBS
- else:
- # People in the same family should be marked as some other
- # form of related. In general, these people will have a
- # pretty random spread of similarity. This distinction is
- # probably not very useful most of the time
- relcode = REL_RELATED
- else:
- ### Different families
- relcode = REL_UNRELATED
-
- t1e = time.time()
- t1sum += t1e-t1s
-
-
- ### Calculate sum(2-abs(a1-a2)) and sum((2-abs(a1-a2))**2) and count
- ### the number of contributing genotypes. These values are not actually
- ### calculated here, but instead are looked up in a table for speed.
- ### FIXME: This is still too slow ...
- result = [0.0, 0.0, 0.0]
- ngeno = weave.inline(C_CODE, ['g1', 'g2', 'nrsSamples', 'result'])
- if ngeno >= minUsegenos:
- _, mean, sdev = result
- means.append(mean)
- sdevs.append(sdev)
- ngenoL.append(ngeno)
- pairs.append((s1, s2))
- rels.append(relcode)
- else:
- skip.add(ndone) # signal no comparable genotypes for this pair
- ndone += 1
- t2e = time.time()
- t2sum += t2e-t1e
- t3e = time.time()
- t3sum += t3e-t2e
-
- logme = [ 'T1: %s' % (t1sum), 'T2: %s' % (t2sum), 'T3: %s' % (t3sum),'TOT: %s' % (t3e-now),
- '%s pairs with no (or not enough) comparable genotypes (%3.1f%%)' % (len(skip),
- float(len(skip))/float(tot)*100)]
- logf.write('%s\n' % '\t'.join(logme))
- ### Calculate mean and standard deviation of scores on a per relationship
- ### type basis, allowing us to flag outliers for each particular relationship
- ### type
- relstats = {}
- relCounts = {}
- outlierFiles = {}
- for relCode, relInfo in REL_LOOKUP.items():
- relName, relColor, relStyle = relInfo
- useme = [means[x] for x in xrange(len(means)) if rels[x] == relCode]
- relCounts[relCode] = len(useme)
- mm = scipy.mean(useme)
- ms = scipy.std(useme)
- useme = [sdevs[x] for x in xrange(len(sdevs)) if rels[x] == relCode]
- sm = scipy.mean(useme)
- ss = scipy.std(useme)
- relstats[relCode] = {'sd':(sm,ss), 'mean':(mm,ms)}
- logf.write('Relstate %s: mean(mean)=%3.2f sdev(mean)=%3.2f, mean(sdev)=%3.2f sdev(sdev)=%3.2f\n' % (relName, mm, ms, sm, ss))
-
- ### now fake z scores for each subject like abecasis recommends max(|zmu|,|zsd|)
- ### within each group, for each pair, z=(groupmean-pairmean)/groupsd
- available = len(means)
- logf.write('%d pairs are available of %d\n' % (available, tot))
- ### s = '\nOutliers:\nrelationship\tzmean\tzsd\tped1\tped2\tmean\tsd\trmeanmean\trmeansd\trsdmean\trsdsd\n'
- ### logf.write(s)
- pairnum = 0
- offset = 0
- nOutliers = 0
- cexs = []
- outlierRecords = dict([(r, []) for r in range(N_RELATIONSHIP_TYPES)])
- zsdmax = 0
- for s1 in range(nSubjects):
- if s1 in emptyRows:
- continue
- (fid1,iid1,did1,mid1,sex1,aff1,ok1,d_sid1,m_sid1) = scache[s1]
- for s2 in range(s1+1, nSubjects):
- if s2 in emptyRows:
- continue
- if pairnum not in skip:
- ### Get group stats for this relationship
- (fid2,iid2,did2,mid2,sex2,aff2,ok2,d_sid2,m_sid2) = scache[s2]
- try:
- r = rels[offset]
- except IndexError:
- logf.write('###OOPS offset %d available %d pairnum %d len(rels) %d', offset, available, pairnum, len(rels))
- rmm,rmd = relstats[r]['mean'] # group mean, group meansd alleles shared
- rdm,rdd = relstats[r]['sd'] # group sdmean, group sdsd alleles shared
-
- try:
- zsd = (sdevs[offset] - rdm)/rdd # distance from group mean in group sd units
- except:
- zsd = 1
- if abs(zsd) > zsdmax:
- zsdmax = zsd # keep for sort scaling
- try:
- zmean = (means[offset] - rmm)/rmd # distance from group mean
- except:
- zmean = 1
- zmeans[offset] = zmean
- zstds[offset] = zsd
- pid=(s1,s2)
- zrad = max(zsd,zmean)
- if zrad < 4:
- zrad = 2
- elif 4 < zrad < 15:
- zrad = 3 # to 9
- else: # > 15 6=24+
- zrad=zrad/4
- zrad = min(zrad,6) # scale limit
- zrad = max(2,max(zsd,zmean)) # as > 2, z grows
- pair_data[pid] = (zmean,zsd,r,zrad)
- if max(zsd,zmean) > Zcutoff: # is potentially interesting
- mean = means[offset]
- sdev = sdevs[offset]
- outlierRecords[r].append((mean, sdev, zmean, zsd, fid1, iid1, fid2, iid2, rmm, rmd, rdm, rdd))
- nOutliers += 1
- tbl.write('%s_%s\t%s_%s\t%f\t%f\t%f\t%f\t%d\t%s\n' % \
- (fid1, iid1, fid2, iid2, mean, sdev, zmean,zsd, ngeno, relcode))
- offset += 1
- pairnum += 1
- logf.write( 'Outliers: %s\n' % (nOutliers))
-
- ### Write outlier files for each relationship type
- repOut.append('<h2>Outliers in tab delimited files linked above are also listed below</h2>')
- lzsd = round(numpy.log10(zsdmax)) + 1
- scalefactor = 10**lzsd
- for relCode, relInfo in REL_LOOKUP.items():
- relName, _, _ = relInfo
- outliers = outlierRecords[relCode]
- if not outliers:
- continue
- outliers = [(scalefactor*int(abs(x[3]))+ int(abs(x[2])),x) for x in outliers] # decorate
- outliers.sort()
- logf.write('### outliers after decorated sort=%s' % outliers)
- outliers.reverse() # largest deviation first
- logf.write('### outliers after decorated sort=%s' % outliers)
- outliers = [x[1] for x in outliers] # undecorate
- nrows = len(outliers)
- truncated = 0
- if nrows > MAX_SHOW_ROWS:
- s = '<h3>%s outlying pairs (top %d of %d) from %s</h3><table border="0" cellpadding="3">' % (relName,
- MAX_SHOW_ROWS,nrows,title)
- truncated = nrows - MAX_SHOW_ROWS
- else:
- s = '<h3>%s outlying pairs (n=%d) from %s</h3><table border="0" cellpadding="3">' % (relName,nrows,title)
- repOut.append(s)
- fhname = '%s_rgGRR_%s_outliers.xls' % (title, relName)
- fhpath = os.path.join(outdir,fhname)
- fh = open(fhpath, 'w')
- newfiles.append(fhname)
- explanations.append('%s Outlier Pairs %s, N=%d, Cutoff SD=%f' % (relName,title,len(outliers),Zcutoff))
- fh.write(OUTLIERS_HEADER)
- s = ''.join(['<th>%s</th>' % x for x in OUTLIERS_HEADER_list])
- repOut.append('<tr align="center">%s</tr>' % s)
- for n,rec in enumerate(outliers):
- #(mean, sdev, zmean, zsd, fid1, iid1, fid2, iid2, rmm, rmd, rdm, rdd) = rec
- fh.write('%f\t%f\t%f\t%f\t%s\t%s\t%s\t%s\t%f\t%f\t%f\t%f\n' % tuple(rec))
- # (mean, sdev, zmean, zsd, fid1, iid1, fid2, iid2, rmm, rmd, rdm, rdd))
- s = '''<td>%f</td><td>%f</td><td>%f</td><td>%f</td><td>%s</td><td>%s</td>
- <td>%s</td><td>%s</td><td>%f</td><td>%f</td><td>%f</td><td>%f</td>''' % tuple(rec)
- if n < MAX_SHOW_ROWS:
- repOut.append('<tr align="center">%s</tr>' % s)
- if truncated > 0:
- repOut.append('<H2>WARNING: %d rows truncated - see outlier file for all %d rows</H2>' % (truncated,
- nrows))
- fh.close()
- repOut.append('</table><p>')
-
- ### Now, draw the plot in jpeg and svg formats, and optionally in the PDF format
- ### if requested
- logf.write('Plotting ...')
- pointColors = [REL_COLORS[rel] for rel in rels]
- pointStyles = [REL_POINTS[rel] for rel in rels]
-
- mainTitle = '%s (%s subjects, %d snp)' % (title, nSubjects, nrsSamples)
- svg.write(SVG_HEADER % (SVG_COLORS[0],SVG_COLORS[1],SVG_COLORS[2],SVG_COLORS[3],SVG_COLORS[4],
- SVG_COLORS[5],SVG_COLORS[6],SVG_COLORS[0],SVG_COLORS[0],SVG_COLORS[1],SVG_COLORS[1],
- SVG_COLORS[2],SVG_COLORS[2],SVG_COLORS[3],SVG_COLORS[3],SVG_COLORS[4],SVG_COLORS[4],
- SVG_COLORS[5],SVG_COLORS[5],SVG_COLORS[6],SVG_COLORS[6],mainTitle))
- #rpy.r.jpeg(filename='%s.jpg' % (title), width=1600, height=1200, pointsize=12, quality=100, bg='white')
- #rpy.r.par(mai=(1,1,1,0.5))
- #rpy.r('par(xaxs="i",yaxs="i")')
- #rpy.r.plot(means, sdevs, main=mainTitle, ylab=Y_AXIS_LABEL, xlab=X_AXIS_LABEL, cex=cexs, col=pointColors, pch=pointStyles, xlim=(0,2), ylim=(0,2))
- #rpy.r.legend(LEGEND_ALIGN, legend=REL_STATES, pch=REL_POINTS, col=REL_COLORS, title=LEGEND_TITLE)
- #rpy.r.grid(nx=10, ny=10, col='lightgray', lty='dotted')
- #rpy.r.dev_off()
-
- ### We will now go through each relationship type to partition plot points
- ### into "bulk" and "outlier" groups. Bulk points will represent common
- ### mean/sdev pairs and will cover the majority of the points in the plot --
- ### they will use generic tooltip informtion about all of the pairs
- ### represented by that point. "Outlier" points will be uncommon pairs,
- ### with very specific information in their tooltips. It would be nice to
- ### keep hte total number of plotted points in the SVG representation to
- ### ~10000 (certainly less than 100000?)
- pointMap = {}
- orderedRels = [y[1] for y in reversed(sorted([(relCounts.get(x, 0),x) for x in REL_LOOKUP.keys()]))]
- # do we really want this? I want out of zone points last and big
- for relCode in orderedRels:
- svgColor = SVG_COLORS[relCode]
- relName, relColor, relStyle = REL_LOOKUP[relCode]
- svg.write('<g id="%s" style="stroke:%s; fill:%s; fill-opacity:1.0; stroke-width:1;" cursor="pointer">\n' % (relName, svgColor, svgColor))
- pMap = pointMap.setdefault(relCode, {})
- nPoints = 0
- rpairs=[]
- rgenos=[]
- rmeans=[]
- rsdevs=[]
- rz = []
- for x,rel in enumerate(rels): # all pairs
- if rel == relCode:
- s1,s2 = pairs[x]
- pid=(s1,s2)
- zmean,zsd,r,zrad = pair_data[pid][:4]
- rpairs.append(pairs[x])
- rgenos.append(ngenoL[x])
- rmeans.append(means[x])
- rsdevs.append(sdevs[x])
- rz.append(zrad)
- ### Now add the svg point group for this relationship to the svg file
- for x in range(len(rmeans)):
- svgX = '%d' % ((rmeans[x] - 1.0) * PLOT_WIDTH) # changed so mean scale is 1-2
- svgY = '%d' % (PLOT_HEIGHT - (rsdevs[x] * PLOT_HEIGHT)) # changed so sd scale is 0-1
- s1, s2 = rpairs[x]
- (fid1,uid1,did1,mid1,sex1,phe1,iid1,d_sid1,m_sid1) = scache[s1]
- (fid2,uid2,did2,mid2,sex2,phe2,iid2,d_sid2,m_sid2) = scache[s2]
- ngenos = rgenos[x]
- nPoints += 1
- point = pMap.setdefault((svgX, svgY), [])
- point.append((rmeans[x], rsdevs[x], fid1, iid1, did1, mid1, fid2, iid2, did2, mid2, ngenos,rz[x]))
- for (svgX, svgY) in pMap:
- points = pMap[(svgX, svgY)]
- svgX = int(svgX)
- svgY = int(svgY)
- if len(points) > 1:
- mmean,dmean = calcMeanSD([p[0] for p in points])
- msdev,dsdev = calcMeanSD([p[1] for p in points])
- mgeno,dgeno = calcMeanSD([p[-1] for p in points])
- mingeno = min([p[-1] for p in points])
- maxgeno = max([p[-1] for p in points])
- svg.write("""<circle cx="%d" cy="%d" r="2"
- onmouseover="showBTT(evt, %d, %1.2f, %1.2f, %1.2f, %1.2f, %d, %d, %d, %d, %d)"
- onmouseout="hideBTT(evt)" />\n""" % (svgX, svgY, relCode, mmean, dmean, msdev, dsdev, len(points), mgeno, dgeno, mingeno, maxgeno))
- else:
- mean, sdev, fid1, iid1, did1, mid1, fid2, iid2, did2, mid2, ngenos, zrad = points[0][:12]
- rmean = float(relstats[relCode]['mean'][0])
- rsdev = float(relstats[relCode]['sd'][0])
- if zrad < 4:
- zrad = 2
- elif 4 < zrad < 9:
- zrad = 3 # to 9
- else: # > 9 5=15+
- zrad=zrad/3
- zrad = min(zrad,5) # scale limit
- if zrad <= 3:
- svg.write('<circle cx="%d" cy="%d" r="%s" onmouseover="showOTT(evt, %d, \'%s,%s,%s,%s\', \'%s,%s,%s,%s\', %1.2f, %1.2f, %s, %1.2f, %1.2f)" onmouseout="hideOTT(evt)" />\n' % (svgX, svgY, zrad, relCode, fid1, iid1, did1, mid1, fid2, iid2, did2, mid2, mean, sdev, ngenos, rmean, rsdev))
- else: # highlight pairs a long way from expectation by outlining circle in red
- svg.write("""<circle cx="%d" cy="%d" r="%s" style="stroke:red; fill:%s; fill-opacity:1.0; stroke-width:1;"
- onmouseover="showOTT(evt, %d, \'%s,%s,%s,%s\', \'%s,%s,%s,%s\', %1.2f, %1.2f, %s, %1.2f, %1.2f)"
- onmouseout="hideOTT(evt)" />\n""" % \
- (svgX, svgY, zrad, svgColor, relCode, fid1, iid1, did1, mid1, fid2, iid2, did2, mid2, mean, sdev, ngenos, rmean, rsdev))
- svg.write('</g>\n')
-
- ### Create a pdf as well if indicated on the command line
- ### WARNING! for framingham share, with about 50M pairs, this is a 5.5GB pdf!
-## if pdftoo:
-## pdfname = '%s.pdf' % (title)
-## rpy.r.pdf(pdfname, 6, 6)
-## rpy.r.par(mai=(1,1,1,0.5))
-## rpy.r('par(xaxs="i",yaxs="i")')
-## rpy.r.plot(means, sdevs, main='%s, %d snp' % (title, nSamples), ylab=Y_AXIS_LABEL, xlab=X_AXIS_LABEL, cex=cexs, col=pointColors, pch=pointStyles, xlim=(0,2), ylim=(0,2))
-## rpy.r.legend(LEGEND_ALIGN, legend=REL_STATES, pch=REL_POINTS, col=REL_COLORS, title=LEGEND_TITLE)
-## rpy.r.grid(nx=10, ny=10, col='lightgray', lty='dotted')
-## rpy.r.dev_off()
-
- ### Draw polygons
- if showPolygons:
- svg.write('<g id="polygons" cursor="pointer">\n')
- for rel, poly in POLYGONS.items():
- points = ' '.join(['%s,%s' % ((p[0]-1.0)*float(PLOT_WIDTH), (PLOT_HEIGHT - p[1]*PLOT_HEIGHT)) for p in poly])
- svg.write('<polygon points="%s" fill="transparent" style="stroke:%s; stroke-width:1"/>\n' % (points, SVG_COLORS[rel]))
- svg.write('</g>\n')
-
-
- svg.write(SVG_FOOTER)
- svg.close()
- return newfiles,explanations,repOut
-
-def doIBS(n=100):
- """parse parameters from galaxy
- expect 'input pbed path' 'basename' 'outpath' 'title' 'logpath' 'n'
- <command interpreter="python">
- rgGRR.py $i.extra_files_path/$i.metadata.base_name "$i.metadata.base_name"
- '$out_file1' '$out_file1.files_path' "$title" '$n' '$Z'
- </command>
-
- """
- u="""<command interpreter="python">
- rgGRR.py $i.extra_files_path/$i.metadata.base_name "$i.metadata.base_name"
- '$out_file1' '$out_file1.files_path' "$title" '$n' '$Z'
- </command>"""
-
- if len(sys.argv) < 8:
- print >> sys.stdout, 'Need pbed inpath, basename, out_htmlname, outpath, title, logpath, nSNP, Zcutoff on command line please'
- print >> sys.stdout, u
- sys.exit(1)
- ts = '%s%s' % (string.punctuation,string.whitespace)
- ptran = string.maketrans(ts,'_'*len(ts))
- inpath = sys.argv[1]
- basename = sys.argv[2]
- outhtml = sys.argv[3]
- newfilepath = sys.argv[4]
- try:
- os.makedirs(newfilepath)
- except:
- pass
- title = sys.argv[5].translate(ptran)
- logfname = 'Log_%s.txt' % title
- logpath = os.path.join(newfilepath,logfname) # log was a child - make part of html extra_files_path zoo
- n = int(sys.argv[6])
- try:
- Zcutoff = float(sys.argv[7])
- except:
- Zcutoff = 2.0
- try:
- os.makedirs(newfilepath)
- except:
- pass
- logf = file(logpath,'w')
- newfiles,explanations,repOut = doIBSpy(inpath=inpath,basename=basename,outdir=newfilepath,
- logf=logf,nrsSamples=n,title=title,pdftoo=0,Zcutoff=Zcutoff)
- logf.close()
- logfs = file(logpath,'r').readlines()
- lf = file(outhtml,'w')
- lf.write(galhtmlprefix % PROGNAME)
- # this is a mess. todo clean up - should each datatype have it's own directory? Yes
- # probably. Then titles are universal - but userId libraries are separate.
- s = '<div>Output from %s run at %s<br>\n' % (PROGNAME,timenow())
- lf.write('<h4>%s</h4>\n' % s)
- fixed = ["'%s'" % x for x in sys.argv] # add quotes just in case
- s = 'If you need to rerun this analysis, the command line was\n<pre>%s</pre>\n</div>' % (' '.join(fixed))
- lf.write(s)
- #s = """<object data="%s" type="image/svg+xml" width="%d" height="%d">
- # <embed src="%s" type="image/svg+xml" width="%d" height="%d" />
- # </object>""" % (newfiles[0],PLOT_WIDTH,PLOT_HEIGHT,newfiles[0],PLOT_WIDTH,PLOT_HEIGHT)
- s = """ <embed src="%s" type="image/svg+xml" width="%d" height="%d" />""" % (newfiles[0],PLOT_WIDTH,PLOT_HEIGHT)
- #s = """ <iframe src="%s" type="image/svg+xml" width="%d" height="%d" />""" % (newfiles[0],PLOT_WIDTH,PLOT_HEIGHT)
- lf.write(s)
- lf.write('<div><h4>Click the links below to save output files and plots</h4><br><ol>\n')
- for i in range(len(newfiles)):
- if i == 0:
- lf.write('<li><a href="%s" type="image/svg+xml" >%s</a></li>\n' % (newfiles[i],explanations[i]))
- else:
- lf.write('<li><a href="%s">%s</a></li>\n' % (newfiles[i],explanations[i]))
- flist = os.listdir(newfilepath)
- for fname in flist:
- if not fname in newfiles:
- lf.write('<li><a href="%s">%s</a></li>\n' % (fname,fname))
- lf.write('</ol></div>')
- lf.write('<div>%s</div>' % ('\n'.join(repOut))) # repOut is a list of tables
- lf.write('<div><hr><h3>Log from this job (also stored in %s)</h3><pre>%s</pre><hr></div>' % (logfname,'\n'.join(logfs)))
- lf.write('</body></html>\n')
- lf.close()
- logf.close()
-
-if __name__ == '__main__':
- doIBS()
-
-
+"""
+# july 2009: Need to see outliers so need to draw them last?
+# could use clustering on the zscores to guess real relationships for unrelateds
+# but definitely need to draw last
+# added MAX_SHOW_ROWS to limit the length of the main report page
+# Changes for Galaxy integration
+# added more robust knuth method for one pass mean and sd
+# no difference really - let's use scipy.mean() and scipy.std() instead...
+# fixed labels and changed to .xls for outlier reports so can open in excel
+# interesting - with a few hundred subjects, 5k gives good resolution
+# and 100k gives better but not by much
+# TODO remove non autosomal markers
+# TODO it would be best if label had the zmean and zsd as these are what matter for
+# outliers rather than the group mean/sd
+# mods to rgGRR.py from channing CVS which John Ziniti has rewritten to produce SVG plots
+# to make a Galaxy tool - we need the table of mean and SD for interesting pairs, the SVG and the log
+# so the result should be an HTML file
+
+# rgIBS.py
+# use a random subset of markers for a quick ibs
+# to identify sample dups and closely related subjects
+# try snpMatrix and plink and see which one works best for us?
+# abecasis grr plots mean*sd for every subject to show clusters
+# mods june 23 rml to avoid non-autosomal markers
+# we seem to be distinguishing parent-child by gender - 2 clouds!
+
+
+snpMatrix from David Clayton has:
+ibs.stats function to calculate the identity-by-state stats of a group of samples
+Description
+Given a snp.matrix-class or a X.snp.matrix-class object with N samples, calculates some statistics
+about the relatedness of every pair of samples within.
+
+Usage
+ibs.stats(x)
+8 ibs.stats
+Arguments
+x a snp.matrix-class or a X.snp.matrix-class object containing N samples
+Details
+No-calls are excluded from consideration here.
+Value
+A data.frame containing N(N - 1)/2 rows, where the row names are the sample name pairs separated
+by a comma, and the columns are:
+Count count of identical calls, exclusing no-calls
+Fraction fraction of identical calls comparied to actual calls being made in both samples
+Warning
+In some applications, it may be preferable to subset a (random) selection of SNPs first - the
+calculation
+time increases as N(N - 1)M/2 . Typically for N = 800 samples and M = 3000 SNPs, the
+calculation time is about 1 minute. A full GWA scan could take hours, and quite unnecessary for
+simple applications such as checking for duplicate or related samples.
+Note
+This is mostly written to find mislabelled and/or duplicate samples.
+Illumina indexes their SNPs in alphabetical order so the mitochondria SNPs comes first - for most
+purpose it is undesirable to use these SNPs for IBS purposes.
+TODO: Worst-case S4 subsetting seems to make 2 copies of a large object, so one might want to
+subset before rbind(), etc; a future version of this routine may contain a built-in subsetting facility
+"""
+import sys,os,time,random,string,copy,optparse
+
+try:
+ set
+except NameError:
+ from Sets import Set as set
+
+from rgutils import timenow,pruneLD,plinke
+import plinkbinJZ
+
+
+opts = None
+verbose = False
+
+showPolygons = False
+
+class NullDevice:
+ def write(self, s):
+ pass
+
+tempstderr = sys.stderr # save
+sys.stderr = NullDevice()
+# need to avoid blather about deprecation and other strange stuff from scipy
+# the current galaxy job runner assumes that
+# the job is in error if anything appears on sys.stderr
+# grrrrr. James wants to keep it that way instead of using the
+# status flag for some strange reason. Presumably he doesn't use R or (in this case, scipy)
+import numpy
+import scipy
+from scipy import weave
+
+
+sys.stderr=tempstderr
+
+
+PROGNAME = os.path.split(sys.argv[0])[-1]
+X_AXIS_LABEL = 'Mean Alleles Shared'
+Y_AXIS_LABEL = 'SD Alleles Shared'
+LEGEND_ALIGN = 'topleft'
+LEGEND_TITLE = 'Relationship'
+DEFAULT_SYMBOL_SIZE = 1.0 # default symbol size
+DEFAULT_SYMBOL_SIZE = 0.5 # default symbol size
+
+### Some colors for R/rpy
+R_BLACK = 1
+R_RED = 2
+R_GREEN = 3
+R_BLUE = 4
+R_CYAN = 5
+R_PURPLE = 6
+R_YELLOW = 7
+R_GRAY = 8
+
+### ... and some point-styles
+
+###
+PLOT_HEIGHT = 600
+PLOT_WIDTH = 1150
+
+
+#SVG_COLORS = ('black', 'darkblue', 'blue', 'deepskyblue', 'firebrick','maroon','crimson')
+#SVG_COLORS = ('cyan','dodgerblue','mediumpurple', 'fuchsia', 'red','gold','gray')
+SVG_COLORS = ('cyan','dodgerblue','mediumpurple','forestgreen', 'lightgreen','gold','gray')
+# dupe,parentchild,sibpair,halfsib,parents,unrel,unkn
+#('orange', 'red', 'green', 'chartreuse', 'blue', 'purple', 'gray')
+
+OUTLIERS_HEADER = 'Mean\tSdev\tZ(mean)\tZ(sdev)\tFID1\tIID1\tFID2\tIID2\tMean(Rel_Mean)\tSdev(Rel_Mean)\tMean(Rel_Sdev)\tSdev(Rel_Sdev)\n'
+OUTLIERS_HEADER_list = ['Mean','Sdev','ZMean','ZSdev','FID1','IID1','FID2','IID2',
+'RGMean_M','RGMean_SD','RGSD_M','RGSD_SD']
+TABLE_HEADER='fid1 iid1\tfid2 iid2\tmean\tsdev\tzmean\tzsdev\tgeno\trelcode\n'
+
+
+### Relationship codes, text, and lookups/mappings
+N_RELATIONSHIP_TYPES = 7
+REL_DUPE, REL_PARENTCHILD, REL_SIBS, REL_HALFSIBS, REL_RELATED, REL_UNRELATED, REL_UNKNOWN = range(N_RELATIONSHIP_TYPES)
+REL_LOOKUP = {
+ REL_DUPE: ('dupe', R_BLUE, 1),
+ REL_PARENTCHILD: ('parentchild', R_YELLOW, 1),
+ REL_SIBS: ('sibpairs', R_RED, 1),
+ REL_HALFSIBS: ('halfsibs', R_GREEN, 1),
+ REL_RELATED: ('parents', R_PURPLE, 1),
+ REL_UNRELATED: ('unrelated', R_CYAN, 1),
+ REL_UNKNOWN: ('unknown', R_GRAY, 1),
+ }
+OUTLIER_STDEVS = {
+ REL_DUPE: 2,
+ REL_PARENTCHILD: 2,
+ REL_SIBS: 2,
+ REL_HALFSIBS: 2,
+ REL_RELATED: 2,
+ REL_UNRELATED: 3,
+ REL_UNKNOWN: 2,
+ }
+# note now Z can be passed in
+
+REL_STATES = [REL_LOOKUP[r][0] for r in range(N_RELATIONSHIP_TYPES)]
+REL_COLORS = SVG_COLORS
+REL_POINTS = [REL_LOOKUP[r][2] for r in range(N_RELATIONSHIP_TYPES)]
+
+DEFAULT_MAX_SAMPLE_SIZE = 10000
+
+REF_COUNT_HOM1 = 3
+REF_COUNT_HET = 2
+REF_COUNT_HOM2 = 1
+MISSING = 0
+MAX_SHOW_ROWS = 100 # framingham has millions - delays showing output page - so truncate and explain
+MARKER_PAIRS_PER_SECOND_SLOW = 15000000.0
+MARKER_PAIRS_PER_SECOND_FAST = 70000000.0
+
+
+galhtmlprefix = """<?xml version="1.0" encoding="utf-8" ?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+<meta name="generator" content="Galaxy %s tool output - see http://g2.trac.bx.psu.edu/" />
+<title></title>
+<link rel="stylesheet" href="/static/style/base.css" type="text/css" />
+</head>
+<body>
+<div class="document">
+"""
+
+
+SVG_HEADER = '''<?xml version="1.0" standalone="no"?>
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.2//EN" "http://www.w3.org/Graphics/SVG/1.2/DTD/svg12.dtd">
+
+<svg width="1280" height="800"
+ xmlns="http://www.w3.org/2000/svg" version="1.2"
+ xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 1280 800" onload="init()">
+
+ <script type="text/ecmascript" xlink:href="/static/scripts/checkbox_and_radiobutton.js"/>
+ <script type="text/ecmascript" xlink:href="/static/scripts/helper_functions.js"/>
+ <script type="text/ecmascript" xlink:href="/static/scripts/timer.js"/>
+ <script type="text/ecmascript">
+ <![CDATA[
+ var checkBoxes = new Array();
+ var radioGroupBandwidth;
+ var colours = ['%s','%s','%s','%s','%s','%s','%s'];
+ function init() {
+ var style = {"font-family":"Arial,Helvetica", "fill":"black", "font-size":12};
+ var dist = 12;
+ var yOffset = 4;
+
+ //A checkBox for each relationship type dupe,parentchild,sibpair,halfsib,parents,unrel,unkn
+ checkBoxes["dupe"] = new checkBox("dupe","checkboxes",20,40,"cbRect","cbCross",true,"Duplicate",style,dist,yOffset,undefined,hideShowLayer);
+ checkBoxes["parentchild"] = new checkBox("parentchild","checkboxes",20,60,"cbRect","cbCross",true,"Parent-Child",style,dist,yOffset,undefined,hideShowLayer);
+ checkBoxes["sibpairs"] = new checkBox("sibpairs","checkboxes",20,80,"cbRect","cbCross",true,"Sib-pairs",style,dist,yOffset,undefined,hideShowLayer);
+ checkBoxes["halfsibs"] = new checkBox("halfsibs","checkboxes",20,100,"cbRect","cbCross",true,"Half-sibs",style,dist,yOffset,undefined,hideShowLayer);
+ checkBoxes["parents"] = new checkBox("parents","checkboxes",20,120,"cbRect","cbCross",true,"Parents",style,dist,yOffset,undefined,hideShowLayer);
+ checkBoxes["unrelated"] = new checkBox("unrelated","checkboxes",20,140,"cbRect","cbCross",true,"Unrelated",style,dist,yOffset,undefined,hideShowLayer);
+ checkBoxes["unknown"] = new checkBox("unknown","checkboxes",20,160,"cbRect","cbCross",true,"Unknown",style,dist,yOffset,undefined,hideShowLayer);
+
+ }
+
+ function hideShowLayer(id, status, label) {
+ var vis = "hidden";
+ if (status) {
+ vis = "visible";
+ }
+ document.getElementById(id).setAttributeNS(null, 'visibility', vis);
+ }
+
+ function showBTT(evt, rel, mm, dm, md, dd, n, mg, dg, lg, hg) {
+ var x = parseInt(evt.pageX)-250;
+ var y = parseInt(evt.pageY)-110;
+ switch(rel) {
+ case 0:
+ fill = colours[rel];
+ relt = "dupe";
+ break;
+ case 1:
+ fill = colours[rel];
+ relt = "parentchild";
+ break;
+ case 2:
+ fill = colours[rel];
+ relt = "sibpairs";
+ break;
+ case 3:
+ fill = colours[rel];
+ relt = "halfsibs";
+ break;
+ case 4:
+ fill = colours[rel];
+ relt = "parents";
+ break;
+ case 5:
+ fill = colours[rel];
+ relt = "unrelated";
+ break;
+ case 6:
+ fill = colours[rel];
+ relt = "unknown";
+ break;
+ default:
+ fill = "cyan";
+ relt = "ERROR_CODE: "+rel;
+ }
+
+ document.getElementById("btRel").textContent = "GROUP: "+relt;
+ document.getElementById("btMean").textContent = "mean="+mm+" +/- "+dm;
+ document.getElementById("btSdev").textContent = "sdev="+dm+" +/- "+dd;
+ document.getElementById("btPair").textContent = "npairs="+n;
+ document.getElementById("btGeno").textContent = "ngenos="+mg+" +/- "+dg+" (min="+lg+", max="+hg+")";
+ document.getElementById("btHead").setAttribute('fill', fill);
+
+ var tt = document.getElementById("btTip");
+ tt.setAttribute("transform", "translate("+x+","+y+")");
+ tt.setAttribute('visibility', 'visible');
+ }
+
+ function showOTT(evt, rel, s1, s2, mean, sdev, ngeno, rmean, rsdev) {
+ var x = parseInt(evt.pageX)-150;
+ var y = parseInt(evt.pageY)-180;
+
+ switch(rel) {
+ case 0:
+ fill = colours[rel];
+ relt = "dupe";
+ break;
+ case 1:
+ fill = colours[rel];
+ relt = "parentchild";
+ break;
+ case 2:
+ fill = colours[rel];
+ relt = "sibpairs";
+ break;
+ case 3:
+ fill = colours[rel];
+ relt = "halfsibs";
+ break;
+ case 4:
+ fill = colours[rel];
+ relt = "parents";
+ break;
+ case 5:
+ fill = colours[rel];
+ relt = "unrelated";
+ break;
+ case 6:
+ fill = colours[rel];
+ relt = "unknown";
+ break;
+ default:
+ fill = "cyan";
+ relt = "ERROR_CODE: "+rel;
+ }
+
+ document.getElementById("otRel").textContent = "PAIR: "+relt;
+ document.getElementById("otS1").textContent = "s1="+s1;
+ document.getElementById("otS2").textContent = "s2="+s2;
+ document.getElementById("otMean").textContent = "mean="+mean;
+ document.getElementById("otSdev").textContent = "sdev="+sdev;
+ document.getElementById("otGeno").textContent = "ngenos="+ngeno;
+ document.getElementById("otRmean").textContent = "relmean="+rmean;
+ document.getElementById("otRsdev").textContent = "relsdev="+rsdev;
+ document.getElementById("otHead").setAttribute('fill', fill);
+
+ var tt = document.getElementById("otTip");
+ tt.setAttribute("transform", "translate("+x+","+y+")");
+ tt.setAttribute('visibility', 'visible');
+ }
+
+ function hideBTT(evt) {
+ document.getElementById("btTip").setAttributeNS(null, 'visibility', 'hidden');
+ }
+
+ function hideOTT(evt) {
+ document.getElementById("otTip").setAttributeNS(null, 'visibility', 'hidden');
+ }
+
+ ]]>
+ </script>
+ <defs>
+ <!-- symbols for check boxes -->
+ <symbol id="cbRect" overflow="visible">
+ <rect x="-5" y="-5" width="10" height="10" fill="white" stroke="dimgray" stroke-width="1" cursor="pointer"/>
+ </symbol>
+ <symbol id="cbCross" overflow="visible">
+ <g pointer-events="none" stroke="black" stroke-width="1">
+ <line x1="-3" y1="-3" x2="3" y2="3"/>
+ <line x1="3" y1="-3" x2="-3" y2="3"/>
+ </g>
+ </symbol>
+ </defs>
+
+<desc>Developer Works Dynamic Scatter Graph Scaling Example</desc>
+
+<!-- Now Draw the main X and Y axis -->
+<g style="stroke-width:1.0; stroke:black; shape-rendering:crispEdges">
+ <!-- X Axis top and bottom -->
+ <path d="M 100 100 L 1250 100 Z"/>
+ <path d="M 100 700 L 1250 700 Z"/>
+
+ <!-- Y Axis left and right -->
+ <path d="M 100 100 L 100 700 Z"/>
+ <path d="M 1250 100 L 1250 700 Z"/>
+</g>
+
+<g transform="translate(100,100)">
+
+ <!-- Grid Lines -->
+ <g style="fill:none; stroke:#dddddd; stroke-width:1; stroke-dasharray:2,2; text-anchor:end; shape-rendering:crispEdges">
+
+ <!-- Vertical grid lines -->
+ <line x1="125" y1="0" x2="115" y2="600" />
+ <line x1="230" y1="0" x2="230" y2="600" />
+ <line x1="345" y1="0" x2="345" y2="600" />
+ <line x1="460" y1="0" x2="460" y2="600" />
+ <line x1="575" y1="0" x2="575" y2="600" style="stroke-dasharray:none;" />
+ <line x1="690" y1="0" x2="690" y2="600" />
+ <line x1="805" y1="0" x2="805" y2="600" />
+ <line x1="920" y1="0" x2="920" y2="600" />
+ <line x1="1035" y1="0" x2="1035" y2="600" />
+
+ <!-- Horizontal grid lines -->
+ <line x1="0" y1="60" x2="1150" y2="60" />
+ <line x1="0" y1="120" x2="1150" y2="120" />
+ <line x1="0" y1="180" x2="1150" y2="180" />
+ <line x1="0" y1="240" x2="1150" y2="240" />
+ <line x1="0" y1="300" x2="1150" y2="300" style="stroke-dasharray:none;" />
+ <line x1="0" y1="360" x2="1150" y2="360" />
+ <line x1="0" y1="420" x2="1150" y2="420" />
+ <line x1="0" y1="480" x2="1150" y2="480" />
+ <line x1="0" y1="540" x2="1150" y2="540" />
+ </g>
+
+ <!-- Legend -->
+ <g style="fill:black; stroke:none" font-size="12" font-family="Arial" transform="translate(25,25)">
+ <rect width="160" height="270" style="fill:none; stroke:black; shape-rendering:crispEdges" />
+ <text x="5" y="20" style="fill:black; stroke:none;" font-size="13" font-weight="bold">Given Pair Relationship</text>
+ <rect x="120" y="35" width="10" height="10" fill="%s" stroke="%s" stroke-width="1" cursor="pointer"/>
+ <rect x="120" y="55" width="10" height="10" fill="%s" stroke="%s" stroke-width="1" cursor="pointer"/>
+ <rect x="120" y="75" width="10" height="10" fill="%s" stroke="%s" stroke-width="1" cursor="pointer"/>
+ <rect x="120" y="95" width="10" height="10" fill="%s" stroke="%s" stroke-width="1" cursor="pointer"/>
+ <rect x="120" y="115" width="10" height="10" fill="%s" stroke="%s" stroke-width="1" cursor="pointer"/>
+ <rect x="120" y="135" width="10" height="10" fill="%s" stroke="%s" stroke-width="1" cursor="pointer"/>
+ <rect x="120" y="155" width="10" height="10" fill="%s" stroke="%s" stroke-width="1" cursor="pointer"/>
+ <text x="15" y="195" style="fill:black; stroke:none" font-size="12" font-family="Arial" >Zscore gt 15</text>
+ <circle cx="125" cy="192" r="6" style="stroke:red; fill:gold; fill-opacity:1.0; stroke-width:1;"/>
+ <text x="15" y="215" style="fill:black; stroke:none" font-size="12" font-family="Arial" >Zscore 4 to 15</text>
+ <circle cx="125" cy="212" r="3" style="stroke:gold; fill:gold; fill-opacity:1.0; stroke-width:1;"/>
+ <text x="15" y="235" style="fill:black; stroke:none" font-size="12" font-family="Arial" >Zscore lt 4</text>
+ <circle cx="125" cy="232" r="2" style="stroke:gold; fill:gold; fill-opacity:1.0; stroke-width:1;"/>
+ <g id="checkboxes">
+ </g>
+ </g>
+
+
+ <g style='fill:black; stroke:none' font-size="17" font-family="Arial">
+ <!-- X Axis Labels -->
+ <text x="480" y="660">Mean Alleles Shared</text>
+ <text x="0" y="630" >1.0</text>
+ <text x="277" y="630" >1.25</text>
+ <text x="564" y="630" >1.5</text>
+ <text x="842" y="630" >1.75</text>
+ <text x="1140" y="630" >2.0</text>
+ </g>
+
+ <g transform="rotate(270)" style="fill:black; stroke:none" font-size="17" font-family="Arial">
+ <!-- Y Axis Labels -->
+ <text x="-350" y="-40">SD Alleles Shared</text>
+ <text x="-20" y="-10" >1.0</text>
+ <text x="-165" y="-10" >0.75</text>
+ <text x="-310" y="-10" >0.5</text>
+ <text x="-455" y="-10" >0.25</text>
+ <text x="-600" y="-10" >0.0</text>
+ </g>
+
+<!-- Plot Title -->
+<g style="fill:black; stroke:none" font-size="18" font-family="Arial">
+ <text x="425" y="-30">%s</text>
+</g>
+
+<!-- One group/layer of points for each relationship type -->
+'''
+
+SVG_FOOTER = '''
+<!-- End of Data -->
+</g>
+<g id="btTip" visibility="hidden" style="stroke-width:1.0; fill:black; stroke:none;" font-size="10" font-family="Arial">
+ <rect width="250" height="110" style="fill:silver" rx="2" ry="2"/>
+ <rect id="btHead" width="250" height="20" rx="2" ry="2" />
+ <text id="btRel" y="14" x="85">unrelated</text>
+ <text id="btMean" y="40" x="4">mean=1.5 +/- 0.04</text>
+ <text id="btSdev" y="60" x="4">sdev=0.7 +/- 0.03</text>
+ <text id="btPair" y="80" x="4">npairs=1152</text>
+ <text id="btGeno" y="100" x="4">ngenos=4783 +/- 24 (min=1000, max=5000)</text>
+</g>
+
+<g id="otTip" visibility="hidden" style="stroke-width:1.0; fill:black; stroke:none;" font-size="10" font-family="Arial">
+ <rect width="150" height="180" style="fill:silver" rx="2" ry="2"/>
+ <rect id="otHead" width="150" height="20" rx="2" ry="2" />
+ <text id="otRel" y="14" x="40">sibpairs</text>
+ <text id="otS1" y="40" x="4">s1=fid1,iid1</text>
+ <text id="otS2" y="60" x="4">s2=fid2,iid2</text>
+ <text id="otMean" y="80" x="4">mean=1.82</text>
+ <text id="otSdev" y="100" x="4">sdev=0.7</text>
+ <text id="otGeno" y="120" x="4">ngeno=4487</text>
+ <text id="otRmean" y="140" x="4">relmean=1.85</text>
+ <text id="otRsdev" y="160" x="4">relsdev=0.65</text>
+</g>
+</svg>
+'''
+
+OUTLIERS_HEADER = 'Mean\tSdev\tZ(mean)\tZ(sdev)\tFID1\tIID1\tFID2\tIID2\tMean(Mean)\tSdev(Mean)\tMean(Sdev)\tSdev(Sdev)\n'
+
+DEFAULT_MAX_SAMPLE_SIZE = 5000
+
+REF_COUNT_HOM1 = 3
+REF_COUNT_HET = 2
+REF_COUNT_HOM2 = 1
+MISSING = 0
+
+MARKER_PAIRS_PER_SECOND_SLOW = 15000000
+MARKER_PAIRS_PER_SECOND_FAST = 70000000
+
+POLYGONS = {
+ REL_UNRELATED: ((1.360, 0.655), (1.385, 0.730), (1.620, 0.575), (1.610, 0.505)),
+ REL_HALFSIBS: ((1.630, 0.500), (1.630, 0.550), (1.648, 0.540), (1.648, 0.490)),
+ REL_SIBS: ((1.660, 0.510), (1.665, 0.560), (1.820, 0.410), (1.820, 0.390)),
+ REL_PARENTCHILD: ((1.650, 0.470), (1.650, 0.490), (1.750, 0.440), (1.750, 0.420)),
+ REL_DUPE: ((1.970, 0.000), (1.970, 0.150), (2.000, 0.150), (2.000, 0.000)),
+ }
+
+def distance(point1, point2):
+ """ Calculate the distance between two points
+ """
+ (x1,y1) = [float(d) for d in point1]
+ (x2,y2) = [float(d) for d in point2]
+ dx = abs(x1 - x2)
+ dy = abs(y1 - y2)
+ return math.sqrt(dx**2 + dy**2)
+
+def point_inside_polygon(x, y, poly):
+ """ Determine if a point (x,y) is inside a given polygon or not
+ poly is a list of (x,y) pairs.
+
+ Taken from: http://www.ariel.com.au/a/python-point-int-poly.html
+ """
+
+ n = len(poly)
+ inside = False
+
+ p1x,p1y = poly[0]
+ for i in range(n+1):
+ p2x,p2y = poly[i % n]
+ if y > min(p1y,p2y):
+ if y <= max(p1y,p2y):
+ if x <= max(p1x,p2x):
+ if p1y != p2y:
+ xinters = (y-p1y)*(p2x-p1x)/(p2y-p1y)+p1x
+ if p1x == p2x or x <= xinters:
+ inside = not inside
+ p1x,p1y = p2x,p2y
+ return inside
+
+def readMap(pedfile):
+ """
+ """
+ mapfile = pedfile.replace('.ped', '.map')
+ marker_list = []
+ if os.path.exists(mapfile):
+ print 'readMap: %s' % (mapfile)
+ fh = file(mapfile, 'r')
+ for line in fh:
+ marker_list.append(line.strip().split())
+ fh.close()
+ print 'readMap: %s markers' % (len(marker_list))
+ return marker_list
+
+def calcMeanSD(useme):
+ """
+ A numerically stable algorithm is given below. It also computes the mean.
+ This algorithm is due to Knuth,[1] who cites Welford.[2]
+ n = 0
+ mean = 0
+ M2 = 0
+
+ foreach x in data:
+ n = n + 1
+ delta = x - mean
+ mean = mean + delta/n
+ M2 = M2 + delta*(x - mean) // This expression uses the new value of mean
+ end for
+
+ variance_n = M2/n
+ variance = M2/(n - 1)
+ """
+ mean = 0.0
+ M2 = 0.0
+ sd = 0.0
+ n = len(useme)
+ if n > 1:
+ for i,x in enumerate(useme):
+ delta = x - mean
+ mean = mean + delta/(i+1) # knuth uses n+=1 at start
+ M2 = M2 + delta*(x - mean) # This expression uses the new value of mean
+ variance = M2/(n-1) # assume is sample so lose 1 DOF
+ sd = pow(variance,0.5)
+ return mean,sd
+
+
+def doIBSpy(ped=None,basename='',outdir=None,logf=None,
+ nrsSamples=10000,title='title',pdftoo=0,Zcutoff=2.0):
+ #def doIBS(pedName, title, nrsSamples=None, pdftoo=False):
+ """ started with snpmatrix but GRR uses actual IBS counts and sd's
+ """
+ repOut = [] # text strings to add to the html display
+ refallele = {}
+ tblf = '%s_table.xls' % (title)
+ tbl = file(os.path.join(outdir,tblf), 'w')
+ tbl.write(TABLE_HEADER)
+ svgf = '%s.svg' % (title)
+ svg = file(os.path.join(outdir,svgf), 'w')
+
+ nMarkers = len(ped._markers)
+ if nMarkers < 5:
+ print sys.stderr, '### ERROR - %d is too few markers for reliable estimation in %s - terminating' % (nMarkers,PROGNAME)
+ sys.exit(1)
+ nSubjects = len(ped._subjects)
+ nrsSamples = min(nMarkers, nrsSamples)
+ if opts and opts.use_mito:
+ markers = range(nMarkers)
+ nrsSamples = min(len(markers), nrsSamples)
+ sampleIndexes = sorted(random.sample(markers, nrsSamples))
+ else:
+ autosomals = ped.autosomal_indices()
+ nrsSamples = min(len(autosomals), nrsSamples)
+ sampleIndexes = sorted(random.sample(autosomals, nrsSamples))
+
+ print ''
+ print 'Getting random.sample of %s from %s total' % (nrsSamples, nMarkers)
+ npairs = (nSubjects*(nSubjects-1))/2 # total rows in table
+ newfiles=[svgf,tblf]
+ explanations = ['rgGRR Plot (requires SVG)','Mean by SD alleles shared - %d rows' % npairs]
+ # these go with the output file links in the html file
+ s = 'Reading genotypes for %s subjects and %s markers\n' % (nSubjects, nrsSamples)
+ logf.write(s)
+ minUsegenos = nrsSamples/2 # must have half?
+ nGenotypes = nSubjects*nrsSamples
+ stime = time.time()
+ emptyRows = set()
+ genos = numpy.zeros((nSubjects, nrsSamples), dtype=int)
+ for s in xrange(nSubjects):
+ nValid = 0
+ #getGenotypesByIndices(self, s, mlist, format)
+ genos[s] = ped.getGenotypesByIndices(s, sampleIndexes, format='ref')
+ nValid = sum([1 for g in genos[s] if g])
+ if not nValid:
+ emptyRows.add(s)
+ sub = ped.getSubject(s)
+ print 'All missing for row %d (%s)' % (s, sub)
+ logf.write('All missing for row %d (%s)\n' % (s, sub))
+ rtime = time.time() - stime
+ if verbose:
+ print '@@Read %s genotypes in %s seconds' % (nGenotypes, rtime)
+
+
+ ### Now the expensive part. For each pair of subjects, we get the mean number
+ ### and standard deviation of shared alleles over all of the markers where both
+ ### subjects have a known genotype. Identical subjects should have mean shared
+ ### alleles very close to 2.0 with a standard deviation very close to 0.0.
+ tot = nSubjects*(nSubjects-1)/2
+ nprog = tot/10
+ nMarkerpairs = tot * nrsSamples
+ estimatedTimeSlow = nMarkerpairs/MARKER_PAIRS_PER_SECOND_SLOW
+ estimatedTimeFast = nMarkerpairs/MARKER_PAIRS_PER_SECOND_FAST
+
+ pairs = []
+ pair_data = {}
+ means = [] ## Mean IBS for each pair
+ ngenoL = [] ## Count of comparable genotypes for each pair
+ sdevs = [] ## Standard dev for each pair
+ rels = [] ## A relationship code for each pair
+ zmeans = [0.0 for x in xrange(tot)] ## zmean score for each pair for the relgroup
+ zstds = [0.0 for x in xrange(tot)] ## zstd score for each pair for the relgrp
+ skip = set()
+ ndone = 0 ## How many have been done so far
+
+ logf.write('Calculating %d pairs, updating every %d pairs...\n' % (tot, nprog))
+ logf.write('Estimated time is %2.2f to %2.2f seconds ...\n' % (estimatedTimeFast, estimatedTimeSlow))
+
+ t1sum = 0
+ t2sum = 0
+ t3sum = 0
+ now = time.time()
+ scache = {}
1
0

16 Apr '10
details: http://www.bx.psu.edu/hg/galaxy/rev/0dc1fc63c945
changeset: 3632:0dc1fc63c945
user: jeremy goecks <jeremy.goecks(a)emory.edu>
date: Tue Apr 13 10:22:27 2010 -0400
description:
Enable user to change dbkey from a known key back to unspecified. This is a hack, but there's no straightforward way to accomplish this without modifying the jquery autocomplete script.
diffstat:
static/scripts/galaxy.base.js | 11 +++++++++--
1 files changed, 9 insertions(+), 2 deletions(-)
diffs (30 lines):
diff -r 968161f35d50 -r 0dc1fc63c945 static/scripts/galaxy.base.js
--- a/static/scripts/galaxy.base.js Tue Apr 13 10:16:46 2010 -0400
+++ b/static/scripts/galaxy.base.js Tue Apr 13 10:22:27 2010 -0400
@@ -149,10 +149,10 @@
var select_mapping = {};
select_elt.children('option').each( function() {
// Get text, value for option.
- var text = $(this).text();
+ var text = $(this).text();
var value = $(this).attr('value');
- // Ignore values that are '?'
+ // HACK: dbkey-specific: ignore values that are '?'
if (value == '?') {
return;
}
@@ -169,6 +169,13 @@
}
});
+ // HACK: dbkey-specific: add an unspecified option. We need to add this at the end b/c adding it first mucks
+ // up the autocomplete sorting for some reason. (I.e. All options that start with the first character of the
+ // first option are listed before the other, alphabetized options.)
+ select_options.push( "unspecified (?)" );
+ select_mapping[ "unspecified (?)" ] = "?";
+ select_mapping[ "?" ] = "?";
+
// Set initial text if it's empty.
if ( text_input_elt.attr('value') == '' ) {
text_input_elt.attr('value', 'Click to Search or Select');
1
0

16 Apr '10
details: http://www.bx.psu.edu/hg/galaxy/rev/968161f35d50
changeset: 3631:968161f35d50
user: rc
date: Tue Apr 13 10:16:46 2010 -0400
description:
fixed forms and user_info functional tests
removed a debugging print stmt
diffstat:
lib/galaxy/model/__init__.py | 2 +-
lib/galaxy/web/controllers/forms.py | 1 -
test/functional/test_forms_and_requests.py | 8 ++++----
test/functional/test_user_info.py | 2 +-
4 files changed, 6 insertions(+), 7 deletions(-)
diffs (74 lines):
diff -r fdf5c92e7fae -r 968161f35d50 lib/galaxy/model/__init__.py
--- a/lib/galaxy/model/__init__.py Mon Apr 12 19:11:36 2010 -0400
+++ b/lib/galaxy/model/__init__.py Tue Apr 13 10:16:46 2010 -0400
@@ -1326,7 +1326,7 @@
# the user had already filled out this field and the same form is re-rendered
# due to some reason like required fields have been left out.
if field[ 'type' ] == 'CheckboxField':
- value = CheckboxField.is_checked( util.restore_text( params.get( field_name, False ) ) )
+ value = CheckboxField.is_checked( params.get( field_name, False ) )
else:
value = util.restore_text( params.get( field_name, '' ) )
elif contents:
diff -r fdf5c92e7fae -r 968161f35d50 lib/galaxy/web/controllers/forms.py
--- a/lib/galaxy/web/controllers/forms.py Mon Apr 12 19:11:36 2010 -0400
+++ b/lib/galaxy/web/controllers/forms.py Tue Apr 13 10:16:46 2010 -0400
@@ -541,7 +541,6 @@
self.selectbox_options = []
# if the form is for defining samples, then use the sample field types
# which does not include TextArea & AddressField
- print >> sys.stderr, 'form_type', form_type
if form_type == trans.app.model.FormDefinition.types.SAMPLE:
for ft in BaseField.sample_field_types():
self.fieldtype.add_option(ft, ft)
diff -r fdf5c92e7fae -r 968161f35d50 test/functional/test_forms_and_requests.py
--- a/test/functional/test_forms_and_requests.py Mon Apr 12 19:11:36 2010 -0400
+++ b/test/functional/test_forms_and_requests.py Tue Apr 13 10:16:46 2010 -0400
@@ -106,7 +106,7 @@
"""Testing address & library creation"""
# first create a regular user
self.logout()
- self.login( email='test1(a)bx.psu.edu' )
+ self.login( email='test1(a)bx.psu.edu', username='regular-user1' )
self.logout()
self.login( email='test(a)bx.psu.edu' )
# first create a library for the request so that it can be submitted later
@@ -191,7 +191,7 @@
self.check_page_for_string( name )
# create address
self.logout()
- self.login( email='test1(a)bx.psu.edu' )
+ self.login( email='test1(a)bx.psu.edu', username='regular-user1' )
self.add_user_address( regular_user1.id, address1 )
global regular_user
regular_user = sa_session.query( galaxy.model.User ) \
@@ -206,7 +206,7 @@
"""Testing creating, editing and submitting a request as a regular user"""
# login as a regular user
self.logout()
- self.login( email='test1(a)bx.psu.edu' )
+ self.login( email='test1(a)bx.psu.edu', username='regular-user1' )
# set field values
fields = ['option1', str(user_address.id), 'field three value']
# create the request
@@ -259,7 +259,7 @@
self.home()
sa_session.refresh( request_one )
self.logout()
- self.login( email='test1(a)bx.psu.edu' )
+ self.login( email='test1(a)bx.psu.edu', username='regular-user1' )
# check if the request's state is now set to 'complete'
self.check_request_grid(state='Complete', request_name=request_one.name)
assert request_one.state is not request_one.states.COMPLETE, "The state of the request '%s' should be set to '%s'" \
diff -r fdf5c92e7fae -r 968161f35d50 test/functional/test_user_info.py
--- a/test/functional/test_user_info.py Mon Apr 12 19:11:36 2010 -0400
+++ b/test/functional/test_user_info.py Tue Apr 13 10:16:46 2010 -0400
@@ -162,7 +162,7 @@
# Test changing email and user name - first try an invalid user name
self.edit_login_info( new_email='test12_new(a)bx.psu.edu',
new_username='test12_new',
- check_str1='User name must contain only letters, numbers and' )
+ check_str1="User name must contain only lower-case letters, numbers and '-'" )
# Now try a valid user name
self.edit_login_info( new_email='test12_new(a)bx.psu.edu',
new_username='test12-new',
1
0
details: http://www.bx.psu.edu/hg/galaxy/rev/fdf5c92e7fae
changeset: 3630:fdf5c92e7fae
user: Kelly Vincent <kpvincent(a)bx.psu.edu>
date: Mon Apr 12 19:11:36 2010 -0400
description:
Fixed a bug in the new joiner tool
diffstat:
tools/new_operations/column_join.py | 97 +++++++++++++++++++++++------------
tools/new_operations/column_join.xml | 8 +-
2 files changed, 68 insertions(+), 37 deletions(-)
diffs (213 lines):
diff -r 6b93e705c8a4 -r fdf5c92e7fae tools/new_operations/column_join.py
--- a/tools/new_operations/column_join.py Mon Apr 12 17:24:17 2010 -0400
+++ b/tools/new_operations/column_join.py Mon Apr 12 19:11:36 2010 -0400
@@ -19,6 +19,32 @@
sys.stderr.write( msg )
sys.exit()
+def hinge_compare( hinge1, hinge2 ):
+ """
+ Compares items like 'chr10' and 'chrM' or 'scaffold2' and scaffold10' so that
+ first part handled as text but last part as number
+ """
+ pat = re.compile( '(?P<text>\D*)(?P<number>\d+)?' )
+ split_hinge1 = hinge1.split( '\t' )
+ split_hinge2 = hinge2.split( '\t' )
+ for i in range( len( split_hinge1 ) ):
+ if split_hinge1[ i ] == split_hinge2[ i ]:
+ continue
+ try:
+ if int( split_hinge1[ i ] ) > int( split_hinge2[ i ] ):
+ return 1
+ else:
+ return -1
+ except ValueError:
+ try:
+ if float( split_hinge1[ i ] ) > float( split_hinge2[ i ] ):
+ return 1
+ else:
+ return -1
+ except ValueError:
+ return ref_compare( split_hinge1[ i ], split_hinge2[ i ])
+ return 0
+
def ref_compare( ref1, ref2 ):
"""
Compares items like 'chr10' and 'chrM' or 'scaffold2' and scaffold10' so that
@@ -52,35 +78,31 @@
elif text1 < text2:
return -1
-def ref_pos_sort( infile, outfile ):
+def hinge_sort( infile, outfile, hinge ):
"""Given input file name, sorts logically (text vs. numeric) into provided output file name."""
- ref_locs = {}
+ hinge_locs = {}
bad_lines = []
fin = open( infile, 'rb' )
line = fin.readline()
while line.strip():
- if True:
+ try:
+ hinge_parts = line.split( '\t' )[ :hinge ]
try:
- ref_seq, ref_loc = line.split( '\t' )[:2]
- try:
- ref_locs[ ref_seq ][ long( ref_loc ) ] = fin.tell() - len( line.strip() ) - 1
- except KeyError:
- ref_locs[ ref_seq ] = { long( ref_loc ): fin.tell() - len( line.strip() ) - 1 }
- except ValueError:
- bad_lines.append( line )
- except ValueError:
- bad_line.append( line )
+ hinge_locs[ '\t'.join( hinge_parts ) ].append( fin.tell() - len( line.strip() ) - 1 )
+ except KeyError:
+ hinge_locs[ '\t'.join( hinge_parts ) ] = [ fin.tell() - len( line.strip() ) - 1 ]
+ except ValueError:
+ bad_line.append( line )
line = fin.readline()
fin.close()
- refs = ref_locs.keys()
- refs.sort( ref_compare )
fin = open( infile, 'rb' )
fout = open( outfile, 'wb' )
- for ref in refs:
- locs = ref_locs[ ref ].keys()
- locs.sort()
+ hinge_locs_sorted = hinge_locs.keys()
+ hinge_locs_sorted.sort( hinge_compare )
+ for hinge_loc in hinge_locs_sorted:
+ locs = hinge_locs[ hinge_loc ]
for loc in locs:
- fin.seek( ref_locs[ ref ][ loc ] )
+ fin.seek( loc )
fout.write( fin.readline() )
fout.close()
fin.close()
@@ -90,14 +112,17 @@
if len( chr_pos ) == 0 and ''.join( chr_pos ):
return ''
min_loc = len( chr_pos )
- min_ref_pos = []
+ min_hinge = []
loc = 0
for c_pos in chr_pos:
if c_pos.strip():
+ split_c = c_pos.split( '\t' )
+
+
ref, pos = c_pos.split( '\t' )[:2]
pos = int( pos )
- if not min_ref_pos:
- min_ref_pos = [ ref, pos ]
+ if not min_hinge:
+ min_hinge = split_c
min_loc = loc
else:
ref_comp = ref_compare( ref, min_ref_pos[0] )
@@ -126,25 +151,33 @@
tmp_file = tempfile.NamedTemporaryFile()
tmp_file_name = tmp_file.name
tmp_file.close()
- ref_pos_sort( in_file, tmp_file_name )
+ hinge_sort( in_file, tmp_file_name, hinge )
tmp_file = open( tmp_file_name, 'rb' )
tmp_input_files.append( tmp_file )
# cycle through files, getting smallest line of all files one at a time
# also have to keep track of vertical position of extra columns
fout = file( output, 'w' )
- old_current_chr_pos = ''
+ old_current = ''
first_line = True
current_lines = [ f.readline() for f in tmp_input_files ]
last_lines = ''.join( current_lines ).strip()
last_loc = -1
+ i = 0
while last_lines:
# get the "minimum" hinge, which should come first, and the file location in list
- current_chr_pos, loc = min_chr_pos( [ '\t'.join( line.split( '\t' )[ :hinge ] ) for line in current_lines ] )
+ hinges = [ '\t'.join( line.split( '\t' )[ :hinge ] ) for line in current_lines ]
+ hinge_dict = {}
+ for i in range( len( hinges ) ):
+ if not hinge_dict.has_key( hinges[ i ] ):
+ hinge_dict[ hinges[ i ] ] = i
+ hinges.sort( hinge_compare )
+ hinges = [ h for h in hinges if h ]
+ current, loc = hinges[0], hinge_dict[ hinges[0] ]
# first output empty columns for vertical alignment (account for "missing" files)
- if current_chr_pos != old_current_chr_pos:
+ if current != old_current:
last_loc = -1
if loc - last_loc > 1:
- current_data = [ '' for col in range( ( loc - last_loc - 1 ) * len( cols[ hinge: ] ) ) ]
+ current_data = [ '' for col in range( ( loc - last_loc - 1 ) * len( [ col for col in cols if col > hinge ] ) ) ]
else:
current_data = []
# now output actual data
@@ -154,22 +187,20 @@
if col > hinge:
current_data.append( split_line[ col - 1 ] )
current_lines[ loc ] = tmp_input_files[ loc ].readline()
- if current_chr_pos == old_current_chr_pos:
- fout.write( '\t%s' % '\t'.join( current_data ) )
+ if current == old_current:
+ if current_data:
+ fout.write( '\t%s' % '\t'.join( current_data ) )
else:
if not first_line:
fout.write( '\n' )
- fout.write( '%s\t%s' % ( current_chr_pos, '\t'.join( current_data ) ) )
+ fout.write( '%s\t%s' % ( current, '\t'.join( current_data ) ) )
first_line = False
- old_current_chr_pos = current_chr_pos
- if last_lines == ''.join( current_lines ).strip():
- break
+ old_current = current
last_lines = ''.join( current_lines ).strip()
last_loc = loc
fout.write( '\n' )
for f in tmp_input_files:
os.unlink( f.name )
fout.close()
-# sys.stderr.write('******************\n'+file(fout.name, 'r').read()+'\n******************\n')
if __name__ == "__main__" : __main__()
diff -r 6b93e705c8a4 -r fdf5c92e7fae tools/new_operations/column_join.xml
--- a/tools/new_operations/column_join.xml Mon Apr 12 17:24:17 2010 -0400
+++ b/tools/new_operations/column_join.xml Mon Apr 12 19:11:36 2010 -0400
@@ -21,7 +21,7 @@
</repeat>
</inputs>
<outputs>
- <data name="output" format="pileup" />
+ <data name="output" format="tabular" />
</outputs>
<tests>
<test>
@@ -30,7 +30,7 @@
<param name="hinge" value="1,2" />
<param name="input2" value="column_join_in2.pileup" ftype="pileup" />
<param name="input" value="column_join_in3.pileup" ftype="pileup" />
- <output name="output" file="column_join_out1.pileup" ftype="pileup" />
+ <output name="output" file="column_join_out1.pileup" ftype="tabular" />
</test>
<test>
<param name="input1" value="column_join_in4.pileup" ftype="pileup" />
@@ -38,7 +38,7 @@
<param name="hinge" value="1,2" />
<param name="input2" value="column_join_in5.pileup" ftype="pileup" />
<param name="input" value="column_join_in6.pileup" ftype="pileup" />
- <output name="output" file="column_join_out2.pileup" ftype="pileup" />
+ <output name="output" file="column_join_out2.pileup" ftype="tabular" />
</test>
<test>
<param name="input1" value="column_join_in7.pileup" ftype="pileup" />
@@ -46,7 +46,7 @@
<param name="hinge" value="1,2" />
<param name="input2" value="column_join_in8.pileup" ftype="pileup" />
<param name="input" value="column_join_in9.pileup" ftype="pileup" />
- <output name="output" file="column_join_out3.pileup" ftype="pileup" />
+ <output name="output" file="column_join_out3.pileup" ftype="tabular" />
</test>
</tests>
<help>
1
0

16 Apr '10
details: http://www.bx.psu.edu/hg/galaxy/rev/6b93e705c8a4
changeset: 3629:6b93e705c8a4
user: Nate Coraor <nate(a)bx.psu.edu>
date: Mon Apr 12 17:24:17 2010 -0400
description:
If a subdir of the library import dir is a symlink and we are linking instead of copying data on import, dereference that symlink
diffstat:
lib/galaxy/web/controllers/library_common.py | 15 +++++++++++++--
1 files changed, 13 insertions(+), 2 deletions(-)
diffs (25 lines):
diff -r c19605dca27d -r 6b93e705c8a4 lib/galaxy/web/controllers/library_common.py
--- a/lib/galaxy/web/controllers/library_common.py Mon Apr 12 15:56:13 2010 -0400
+++ b/lib/galaxy/web/controllers/library_common.py Mon Apr 12 17:24:17 2010 -0400
@@ -915,8 +915,19 @@
for entry in os.listdir( full_dir ):
# Only import regular files
path = os.path.join( full_dir, entry )
- if os.path.islink( path ) and os.path.isfile( path ) and params.get( 'link_data_only', False ):
- # If we're linking instead of copying, link the file the link points to, not the link itself.
+ if os.path.islink( full_dir ) and params.get( 'link_data_only', False ):
+ # If we're linking instead of copying and the
+ # sub-"directory" in the import dir is actually a symlink,
+ # dereference the symlink, but not any of its contents.
+ link_path = os.readlink( full_dir )
+ if os.path.isabs( link_path ):
+ path = os.path.join( link_path, entry )
+ else:
+ path = os.path.abspath( os.path.join( link_path, entry ) )
+ elif os.path.islink( path ) and os.path.isfile( path ) and params.get( 'link_data_only', False ):
+ # If we're linking instead of copying and the "file" in the
+ # sub-directory of the import dir is actually a symlink,
+ # dereference the symlink (one dereference only, Vasili).
link_path = os.readlink( path )
if os.path.isabs( link_path ):
path = link_path
1
0

16 Apr '10
details: http://www.bx.psu.edu/hg/galaxy/rev/c19605dca27d
changeset: 3628:c19605dca27d
user: Kelly Vincent <kpvincent(a)bx.psu.edu>
date: Mon Apr 12 15:56:13 2010 -0400
description:
Updated NGS tools' stderr handling to use file rather than pipe to allow for large stderr output
diffstat:
tools/metag_tools/megablast_wrapper.py | 13 +++++++++-
tools/samtools/sam_merge.py | 15 ++++++++++--
tools/samtools/sam_pileup.py | 18 ++++++++++++---
tools/samtools/sam_to_bam.py | 27 ++++++++++++++++++-----
tools/sr_mapping/bowtie_wrapper.py | 26 +++++++++++++++++-----
tools/sr_mapping/bowtie_wrapper.xml | 4 +-
tools/sr_mapping/bwa_wrapper.py | 38 +++++++++++++++++++++++++--------
7 files changed, 109 insertions(+), 32 deletions(-)
diffs (406 lines):
diff -r f32497f2e001 -r c19605dca27d tools/metag_tools/megablast_wrapper.py
--- a/tools/metag_tools/megablast_wrapper.py Mon Apr 12 10:30:25 2010 -0400
+++ b/tools/metag_tools/megablast_wrapper.py Mon Apr 12 15:56:13 2010 -0400
@@ -74,24 +74,33 @@
print megablast_command
+ tmp = tempfile.NamedTemporaryFile().name
try:
- proc = subprocess.Popen( args=megablast_command, shell=True, stderr=subprocess.PIPE )
+ tmp_stderr = open( tmp, 'wb' )
+ proc = subprocess.Popen( args=megablast_command, shell=True, stderr=tmp_stderr.fileno() )
returncode = proc.wait()
+ tmp_stderr.close()
# get stderr, allowing for case where it's very large
+ tmp_stderr = open( tmp, 'rb' )
stderr = ''
buffsize = 1048576
try:
while True:
- stderr += proc.stderr.read( buffsize )
+ stderr += tmp_stderr.read( buffsize )
if not stderr or len( stderr ) % buffsize != 0:
break
except OverflowError:
pass
+ tmp_stderr.close()
if returncode != 0:
raise Exception, stderr
+ if os.path.exists( tmp ):
+ os.unlink( tmp )
except Exception, e:
if os.path.exists( mega_temp_output ):
os.unlink( mega_temp_output )
+ if os.path.exists( tmp ):
+ os.unlink( tmp )
stop_err( 'Error indexing reference sequence. ' + str( e ) )
output = open( output_filename, 'w' )
diff -r f32497f2e001 -r c19605dca27d tools/samtools/sam_merge.py
--- a/tools/samtools/sam_merge.py Mon Apr 12 10:30:25 2010 -0400
+++ b/tools/samtools/sam_merge.py Mon Apr 12 15:56:13 2010 -0400
@@ -9,7 +9,7 @@
[input3[,input4[,input5[,...]]]]
"""
-import os, subprocess, sys
+import os, subprocess, sys, tempfile
def stop_err( msg ):
sys.stderr.write( '%s\n' % msg )
@@ -22,22 +22,31 @@
stop_err( 'There are not enough files to merge' )
filenames = sys.argv[3:]
cmd = 'samtools merge %s %s %s' % ( outfile, infile, ' '.join( filenames ) )
+ tmp = tempfile.NamedTemporaryFile().name
try:
- proc = subprocess.Popen( args=cmd, shell=True, stderr=subprocess.PIPE )
+ tmp_stderr = open( tmp, 'wb' )
+ proc = subprocess.Popen( args=cmd, shell=True, stderr=tmp_stderr.fileno() )
returncode = proc.wait()
+ tmp_stderr.close()
# get stderr, allowing for case where it's very large
+ tmp_stderr = open( tmp, 'rb' )
stderr = ''
buffsize = 1048576
try:
while True:
- stderr += proc.stderr.read( buffsize )
+ stderr += tmp_stderr.read( buffsize )
if not stderr or len( stderr ) % buffsize != 0:
break
except OverflowError:
pass
+ tmp_stderr.close()
if returncode != 0:
raise Exception, stderr
+ if os.path.exists( tmp ):
+ os.unlink( tmp )
except Exception, e:
+ if os.path.exists( tmp ):
+ os.unlink( tmp )
stop_err( 'Error running SAMtools merge tool\n' + str( e ) )
if os.path.getsize( outfile ) > 0:
sys.stdout.write( '%s files merged.' % ( len( sys.argv ) - 2 ) )
diff -r f32497f2e001 -r c19605dca27d tools/samtools/sam_pileup.py
--- a/tools/samtools/sam_pileup.py Mon Apr 12 10:30:25 2010 -0400
+++ b/tools/samtools/sam_pileup.py Mon Apr 12 15:56:13 2010 -0400
@@ -88,36 +88,46 @@
elif options.ref == 'history':
os.symlink( options.ownFile, tmpf1_name )
cmdIndex = 'samtools faidx %s' % ( tmpf1_name )
- proc = subprocess.Popen( args=cmdIndex, shell=True, cwd=tmpDir, stderr=subprocess.PIPE )
+ tmp = tempfile.NamedTemporaryFile( dir=tmpDir ).name
+ tmp_stderr = open( tmp, 'wb' )
+ proc = subprocess.Popen( args=cmdIndex, shell=True, cwd=tmpDir, stderr=tmp_stderr.fileno() )
returncode = proc.wait()
+ tmp_stderr.close()
# get stderr, allowing for case where it's very large
+ tmp_stderr = open( tmp, 'rb' )
stderr = ''
buffsize = 1048576
try:
while True:
- stderr += proc.stderr.read( buffsize )
+ stderr += tmp_stderr.read( buffsize )
if not stderr or len( stderr ) % buffsize != 0:
break
except OverflowError:
pass
+ tmp_stderr.close()
#did index succeed?
if returncode != 0:
raise Exception, 'Error creating index file\n' + stderr
cmd = cmd % ( opts, tmpf1_name, tmpf0bam_name, options.output1 )
#perform pileup command
- proc = subprocess.Popen( args=cmd, shell=True, cwd=tmpDir, stderr=subprocess.PIPE )
+ tmp = tempfile.NamedTemporaryFile( dir=tmpDir ).name
+ tmp_stderr = open( tmp, 'wb' )
+ proc = subprocess.Popen( args=cmd, shell=True, cwd=tmpDir, stderr=tmp_stderr.fileno() )
returncode = proc.wait()
+ tmp_stderr.close()
#did it succeed?
# get stderr, allowing for case where it's very large
+ tmp_stderr = open( tmp, 'rb' )
stderr = ''
buffsize = 1048576
try:
while True:
- stderr += proc.stderr.read( buffsize )
+ stderr += tmp_stderr.read( buffsize )
if not stderr or len( stderr ) % buffsize != 0:
break
except OverflowError:
pass
+ tmp_stderr.close()
if returncode != 0:
raise Exception, stderr
except Exception, e:
diff -r f32497f2e001 -r c19605dca27d tools/samtools/sam_to_bam.py
--- a/tools/samtools/sam_to_bam.py Mon Apr 12 10:30:25 2010 -0400
+++ b/tools/samtools/sam_to_bam.py Mon Apr 12 15:56:13 2010 -0400
@@ -75,18 +75,23 @@
os.symlink( options.ref_file, fai_index_file_base )
fai_index_file_path = '%s.fai' % fai_index_file_base
command = 'samtools faidx %s' % fai_index_file_base
- proc = subprocess.Popen( args=command, shell=True, cwd=tmp_dir, stderr=subprocess.PIPE )
+ tmp = tempfile.NamedTemporaryFile( dir=tmp_dir ).name
+ tmp_stderr = open( tmp, 'wb' )
+ proc = subprocess.Popen( args=command, shell=True, cwd=tmp_dir, stderr=tmp_stderr.fileno() )
returncode = proc.wait()
+ tmp_stderr.close()
# get stderr, allowing for case where it's very large
+ tmp_stderr = open( tmp, 'rb' )
stderr = ''
buffsize = 1048576
try:
while True:
- stderr += proc.stderr.read( buffsize )
+ stderr += tmp_stderr.read( buffsize )
if not stderr or len( stderr ) % buffsize != 0:
break
except OverflowError:
pass
+ tmp_stderr.close()
if returncode != 0:
raise Exception, stderr
if len( open( fai_index_file_path ).read().strip() ) == 0:
@@ -104,18 +109,23 @@
# IMPORTANT NOTE: for some reason the samtools view command gzips the resulting bam file without warning,
# and the docs do not currently state that this occurs ( very bad ).
command = 'samtools view -bt %s -o %s %s' % ( fai_index_file_path, tmp_aligns_file_name, options.input1 )
- proc = subprocess.Popen( args=command, shell=True, cwd=tmp_dir, stderr=subprocess.PIPE )
+ tmp = tempfile.NamedTemporaryFile( dir=tmp_dir ).name
+ tmp_stderr = open( tmp, 'wb' )
+ proc = subprocess.Popen( args=command, shell=True, cwd=tmp_dir, stderr=tmp_stderr.fileno() )
returncode = proc.wait()
+ tmp_stderr.close()
# get stderr, allowing for case where it's very large
+ tmp_stderr = open( tmp, 'rb' )
stderr = ''
buffsize = 1048576
try:
while True:
- stderr += proc.stderr.read( buffsize )
+ stderr += tmp_stderr.read( buffsize )
if not stderr or len( stderr ) % buffsize != 0:
break
except OverflowError:
pass
+ tmp_stderr.close()
if returncode != 0:
raise Exception, stderr
if len( open( tmp_aligns_file_name ).read() ) == 0:
@@ -133,18 +143,23 @@
tmp_sorted_aligns_file_name = tmp_sorted_aligns_file.name
tmp_sorted_aligns_file.close()
command = 'samtools sort %s %s' % ( tmp_aligns_file_name, tmp_sorted_aligns_file_name )
- proc = subprocess.Popen( args=command, shell=True, cwd=tmp_dir, stderr=subprocess.PIPE )
+ tmp = tempfile.NamedTemporaryFile( dir=tmp_dir ).name
+ tmp_stderr = open( tmp, 'wb' )
+ proc = subprocess.Popen( args=command, shell=True, cwd=tmp_dir, stderr=tmp_stderr.fileno() )
returncode = proc.wait()
+ tmp_stderr.close()
# get stderr, allowing for case where it's very large
+ tmp_stderr = open( tmp, 'rb' )
stderr = ''
buffsize = 1048576
try:
while True:
- stderr += proc.stderr.read( buffsize )
+ stderr += tmp_stderr.read( buffsize )
if not stderr or len( stderr ) % buffsize != 0:
break
except OverflowError:
pass
+ tmp_stderr.close()
if returncode != 0:
raise Exception, stderr
except Exception, e:
diff -r f32497f2e001 -r c19605dca27d tools/sr_mapping/bowtie_wrapper.py
--- a/tools/sr_mapping/bowtie_wrapper.py Mon Apr 12 10:30:25 2010 -0400
+++ b/tools/sr_mapping/bowtie_wrapper.py Mon Apr 12 15:56:13 2010 -0400
@@ -186,25 +186,34 @@
( iautoB, ipacked, ibmax, ibmaxdivn, idcv, inodc,
inoref, options.ioffrate, iftab, intoa, iendian,
iseed, icutoff, colorspace )
- except ValueError:
- indexing_cmds = '%s' % colorspace
+ except ValueError, e:
+ # clean up temp dir
+ if os.path.exists( tmp_index_dir ):
+ shutil.rmtree( tmp_index_dir )
+ stop_err( 'Something is wrong with the indexing parameters and the indexing and alignment could not be run\n' + str( e ) )
ref_file = tempfile.NamedTemporaryFile( dir=tmp_index_dir )
ref_file_name = ref_file.name
ref_file.close()
os.symlink( options.ref, ref_file_name )
cmd1 = 'bowtie-build %s -f %s %s' % ( indexing_cmds, ref_file_name, ref_file_name )
try:
- proc = subprocess.Popen( args=cmd1, shell=True, cwd=tmp_index_dir, stderr=subprocess.PIPE, stdout=subprocess.PIPE )
+ tmp = tempfile.NamedTemporaryFile( dir=tmp_index_dir ).name
+ tmp_stderr = open( tmp, 'wb' )
+ proc = subprocess.Popen( args=cmd1, shell=True, cwd=tmp_index_dir, stderr=tmp_stderr.fileno() )
returncode = proc.wait()
+ tmp_stderr.close()
+ # get stderr, allowing for case where it's very large
+ tmp_stderr = open( tmp, 'rb' )
stderr = ''
buffsize = 1048576
try:
while True:
- stderr += proc.stderr.read( buffsize )
+ stderr += tmp_stderr.read( buffsize )
if not stderr or len( stderr ) % buffsize != 0:
break
except OverflowError:
pass
+ tmp_stderr.close()
if returncode != 0:
raise Exception, stderr
except Exception, e:
@@ -358,18 +367,23 @@
else:
cmd2 = 'bowtie %s %s %s > %s' % ( aligning_cmds, ref_file_name, options.input1, options.output )
# align
- proc = subprocess.Popen( args=cmd2, shell=True, cwd=tmp_index_dir, stderr=subprocess.PIPE )
+ tmp = tempfile.NamedTemporaryFile( dir=tmp_index_dir ).name
+ tmp_stderr = open( tmp, 'wb' )
+ proc = subprocess.Popen( args=cmd2, shell=True, cwd=tmp_index_dir, stderr=tmp_stderr.fileno() )
returncode = proc.wait()
+ tmp_stderr.close()
# get stderr, allowing for case where it's very large
+ tmp_stderr = open( tmp, 'rb' )
stderr = ''
buffsize = 1048576
try:
while True:
- stderr += proc.stderr.read( buffsize )
+ stderr += tmp_stderr.read( buffsize )
if not stderr or len( stderr ) % buffsize != 0:
break
except OverflowError:
pass
+ tmp_stderr.close()
if returncode != 0:
raise Exception, stderr
# check that there are results in the output file
diff -r f32497f2e001 -r c19605dca27d tools/sr_mapping/bowtie_wrapper.xml
--- a/tools/sr_mapping/bowtie_wrapper.xml Mon Apr 12 10:30:25 2010 -0400
+++ b/tools/sr_mapping/bowtie_wrapper.xml Mon Apr 12 15:56:13 2010 -0400
@@ -181,8 +181,8 @@
--maxAlignAttempt="None"
--forwardAlign="None"
--reverseAlign="None"
- #end if
- #end if
+ #end if
+ #end if
</command>
<inputs>
<conditional name="refGenomeSource">
diff -r f32497f2e001 -r c19605dca27d tools/sr_mapping/bwa_wrapper.py
--- a/tools/sr_mapping/bwa_wrapper.py Mon Apr 12 10:30:25 2010 -0400
+++ b/tools/sr_mapping/bwa_wrapper.py Mon Apr 12 15:56:13 2010 -0400
@@ -91,18 +91,23 @@
indexing_cmds = '-a %s' % indexingAlg
cmd1 = 'bwa index %s %s' % ( indexing_cmds, ref_file_name )
try:
- proc = subprocess.Popen( args=cmd1, shell=True, cwd=tmp_index_dir, stderr=subprocess.PIPE )
+ tmp = tempfile.NamedTemporaryFile( dir=tmp_index_dir ).name
+ tmp_stderr = open( tmp, 'wb' )
+ proc = subprocess.Popen( args=cmd1, shell=True, cwd=tmp_index_dir, stderr=tmp_stderr.fileno() )
returncode = proc.wait()
+ tmp_stderr.close()
# get stderr, allowing for case where it's very large
+ tmp_stderr = open( tmp, 'rb' )
stderr = ''
buffsize = 1048576
try:
while True:
- stderr += proc.stderr.read( buffsize )
+ stderr += tmp_stderr.read( buffsize )
if not stderr or len( stderr ) % buffsize != 0:
break
except OverflowError:
pass
+ tmp_stderr.close()
if returncode != 0:
raise Exception, stderr
except Exception, e:
@@ -166,52 +171,67 @@
try:
# align
try:
- proc = subprocess.Popen( args=cmd2, shell=True, cwd=tmp_dir, stderr=subprocess.PIPE )
+ tmp = tempfile.NamedTemporaryFile( dir=tmp_dir ).name
+ tmp_stderr = open( tmp, 'wb' )
+ proc = subprocess.Popen( args=cmd2, shell=True, cwd=tmp_dir, stderr=tmp_stderr.fileno() )
returncode = proc.wait()
+ tmp_stderr.close()
# get stderr, allowing for case where it's very large
+ tmp_stderr = open( tmp, 'rb' )
stderr = ''
try:
while True:
- stderr += proc.stderr.read( buffsize )
+ stderr += tmp_stderr.read( buffsize )
if not stderr or len( stderr ) % buffsize != 0:
break
except OverflowError:
pass
+ tmp_stderr.close()
if returncode != 0:
raise Exception, stderr
except Exception, e:
raise Exception, 'Error aligning sequence. ' + str( e )
# and again if paired data
try:
- if cmd2b:
- proc = subprocess.Popen( args=cmd2b, shell=True, cwd=tmp_dir, stderr=subprocess.PIPE )
+ if cmd2b:
+ tmp = tempfile.NamedTemporaryFile( dir=tmp_dir ).name
+ tmp_stderr = open( tmp, 'wb' )
+ proc = subprocess.Popen( args=cmd2b, shell=True, cwd=tmp_dir, stderr=tmp_stderr.fileno() )
returncode = proc.wait()
+ tmp_stderr.close()
# get stderr, allowing for case where it's very large
+ tmp_stderr = open( tmp, 'rb' )
stderr = ''
try:
while True:
- stderr += proc.stderr.read( buffsize )
+ stderr += tmp_stderr.read( buffsize )
if not stderr or len( stderr ) % buffsize != 0:
break
except OverflowError:
pass
+ tmp_stderr.close()
if returncode != 0:
raise Exception, stderr
except Exception, e:
raise Exception, 'Error aligning second sequence. ' + str( e )
# generate align
try:
- proc = subprocess.Popen( args=cmd3, shell=True, cwd=tmp_dir, stderr=subprocess.PIPE )
+ tmp = tempfile.NamedTemporaryFile( dir=tmp_dir ).name
+ tmp_stderr = open( tmp, 'wb' )
+ proc = subprocess.Popen( args=cmd3, shell=True, cwd=tmp_dir, stderr=tmp_stderr.fileno() )
returncode = proc.wait()
+ tmp_stderr.close()
# get stderr, allowing for case where it's very large
+ tmp_stderr = open( tmp, 'rb' )
stderr = ''
try:
while True:
- stderr += proc.stderr.read( buffsize )
+ stderr += tmp_stderr.read( buffsize )
if not stderr or len( stderr ) % buffsize != 0:
break
except OverflowError:
pass
+ tmp_stderr.close()
if returncode != 0:
raise Exception, stderr
except Exception, e:
1
0

16 Apr '10
details: http://www.bx.psu.edu/hg/galaxy/rev/f32497f2e001
changeset: 3627:f32497f2e001
user: Dan Blankenberg <dan(a)bx.psu.edu>
date: Mon Apr 12 10:30:25 2010 -0400
description:
Allow FASTQ parser to handle extra space padded decimal scores, e.g. '0 '
diffstat:
lib/galaxy_utils/sequence/fastq.py | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diffs (12 lines):
diff -r 5536d57237a3 -r f32497f2e001 lib/galaxy_utils/sequence/fastq.py
--- a/lib/galaxy_utils/sequence/fastq.py Fri Apr 09 18:09:54 2010 -0400
+++ b/lib/galaxy_utils/sequence/fastq.py Mon Apr 12 10:30:25 2010 -0400
@@ -60,7 +60,7 @@
else:
quality = self.quality.rstrip() #decimal scores should have a trailing space
if quality:
- return map( int, quality.split( ' ' ) )
+ return [ int( val ) for val in quality.split( ' ' ) if val.strip() ]
else:
return []
def convert_read_to_format( self, format, force_quality_encoding = None ):
1
0
details: http://www.bx.psu.edu/hg/galaxy/rev/5536d57237a3
changeset: 3626:5536d57237a3
user: Kanwei Li <kanwei(a)gmail.com>
date: Fri Apr 09 18:09:54 2010 -0400
description:
- Update jQuery.jStore, JSON2
- Fix issue with all local prefs being deleted on "collapse all"
- Refactored history display code into galaxy.base
diffstat:
static/jStore.Flash.html | 19 -
static/jStore.swf | 0
static/scripts/class.js | 80 +
static/scripts/galaxy.base.js | 87 +
static/scripts/jquery.jstore-all.js | 748 -----------
static/scripts/jquery.jstore.js | 1810 ++++++++++++++++++++++++++++
static/scripts/json2.js | 26 +-
static/scripts/packed/class.js | 7 +
static/scripts/packed/galaxy.base.js | 2 +-
static/scripts/packed/jquery.jstore-all.js | 1 -
static/scripts/packed/jquery.jstore.js | 17 +
static/scripts/packed/json2.js | 2 +-
templates/display_base.mako | 29 +-
templates/history/display.mako | 264 +---
templates/history/view.mako | 259 +---
templates/page/display.mako | 272 +---
templates/root/history.mako | 222 +--
templates/workflow/editor.mako | 42 +-
18 files changed, 2216 insertions(+), 1671 deletions(-)
diffs (truncated from 4199 to 3000 lines):
diff -r a9402fc7ce1b -r 5536d57237a3 static/jStore.Flash.html
--- a/static/jStore.Flash.html Fri Apr 09 13:02:15 2010 -0400
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,19 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
- <head>
- <title>Flash External Object</title>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <script type="text/javascript">
- /**
- * This function captures the flash_ready event. We need to relay this
- * back to the parent so it knows flash is ready.
- */
- function flash_ready(){
- parent.flash_ready();
- }
- </script>
- </head>
- <body>
- <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#versi…" width="1" height="1" id="jStoreFlash"><param name="allowScriptAccess" value="always" /><param name="movie" value="jStore.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffcc00" /><embed src="jStore.swf" quality="high" bgcolor="#ffcc00" width="1" height="1" name="jStoreFlash" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>
- </body>
-</html>
\ No newline at end of file
diff -r a9402fc7ce1b -r 5536d57237a3 static/jStore.swf
Binary file static/jStore.swf has changed
diff -r a9402fc7ce1b -r 5536d57237a3 static/scripts/class.js
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/static/scripts/class.js Fri Apr 09 18:09:54 2010 -0400
@@ -0,0 +1,80 @@
+/*!
+ * Class definition
+ *
+ * Copyright (c) 2008 John Resig (http://ejohn.org/blog/simple-javascript-inheritance/)
+ * Inspired by base2 and Prototype
+ */
+
+"use strict";
+
+(function () {
+
+ var initializing = false,
+
+ fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/;
+
+ // The base Class implementation (does nothing)
+ this.Class = function(){};
+
+ // Create a new Class that inherits from this class
+ Class.extend = function (prop)
+ {
+ var _super = this.prototype;
+
+ // Instantiate a base class (but only create the instance, don't run the init constructor)
+ initializing = true;
+
+ var prototype = new this();
+
+ initializing = false;
+
+ // Copy the properties over onto the new prototype
+ for (var name in prop)
+ {
+
+ // Check if we're overwriting an existing function
+ prototype[name] = (typeof prop[name] === "function" && typeof _super[name] === "function" && fnTest.test(prop[name]) ?
+
+ (function(name, fn)
+ {
+ return function()
+ {
+ var tmp = this._super;
+
+ // Add a new ._super() method that is the same method
+ // but on the super-class
+ this._super = _super[name];
+
+ // The method only need to be bound temporarily, so we
+ // remove it when we're done executing
+ var ret = fn.apply(this, arguments);
+ this._super = tmp;
+
+ return ret;
+ };
+ }(name, prop[name])) : prop[name]);
+ }
+
+ // The dummy class constructor
+ function Class()
+ {
+ // All construction is actually done in the init method
+ if (!initializing && this.init)
+ {
+ this.init.apply(this, arguments);
+ }
+ }
+
+ // Populate our constructed prototype object
+ Class.prototype = prototype;
+
+ // Enforce the constructor to be what we expect
+ Class.constructor = Class;
+
+ // And make this class extendable
+ Class.extend = arguments.callee;
+
+ return Class;
+ };
+
+}());
diff -r a9402fc7ce1b -r 5536d57237a3 static/scripts/galaxy.base.js
--- a/static/scripts/galaxy.base.js Fri Apr 09 13:02:15 2010 -0400
+++ b/static/scripts/galaxy.base.js Fri Apr 09 18:09:54 2010 -0400
@@ -275,6 +275,93 @@
});
}
+function init_history_items(historywrapper, noinit) {
+
+ var action = function() {
+ // Load saved state and show as necessary
+ try {
+ var stored = $.jStore.store("history_expand_state");
+ if (stored) {
+ for (var id in stored) {
+ $("#" + id + " div.historyItemBody" ).show();
+ }
+ }
+ } catch(err) {
+ // Something was wrong with values in storage, so clear storage
+ $.jStore.remove("history_expand_state");
+ }
+
+ // If Mozilla, hide scrollbars in hidden items since they cause animation bugs
+ if ( $.browser.mozilla ) {
+ $( "div.historyItemBody" ).each( function() {
+ if ( ! $(this).is( ":visible" ) ) $(this).find( "pre.peek" ).css( "overflow", "hidden" );
+ })
+ }
+
+ historywrapper.each( function() {
+ var id = this.id;
+ var body = $(this).children( "div.historyItemBody" );
+ var peek = body.find( "pre.peek" )
+ $(this).children( ".historyItemTitleBar" ).find( ".historyItemTitle" ).wrap( "<a href='#'></a>" ).click( function() {
+ if ( body.is(":visible") ) {
+ // Hiding stuff here
+ if ( $.browser.mozilla ) { peek.css( "overflow", "hidden" ) }
+ body.slideUp( "fast" );
+
+ if (!noinit) { // Ignore embedded item actions
+ // Save setting
+ var prefs = $.jStore.store("history_expand_state");
+ if (prefs) {
+ delete prefs[id];
+ $.jStore.store("history_expand_state", prefs);
+ }
+ }
+ } else {
+ // Showing stuff here
+ body.slideDown( "fast", function() {
+ if ( $.browser.mozilla ) { peek.css( "overflow", "auto" ); }
+ });
+
+ if (!noinit) {
+ // Save setting
+ var prefs = $.jStore.store("history_expand_state");
+ if (prefs === undefined) { prefs = {}; }
+ prefs[id] = true;
+ $.jStore.store("history_expand_state", prefs);
+ }
+ }
+ return false;
+ });
+ });
+
+ // Generate 'collapse all' link
+ $("#top-links > a.toggle").click( function() {
+ var prefs = $.jStore.store("history_expand_state");
+ if (prefs === undefined) { prefs = {}; }
+ $( "div.historyItemBody:visible" ).each( function() {
+ if ( $.browser.mozilla ) {
+ $(this).find( "pre.peek" ).css( "overflow", "hidden" );
+ }
+ $(this).slideUp( "fast" );
+ if (prefs) {
+ delete prefs[$(this).parent().attr("id")];
+ }
+ });
+ $.jStore.store("history_expand_state", prefs);
+ }).show();
+ }
+
+ if (noinit) {
+ action();
+ } else {
+ // Load jStore for local storage
+ $.jStore.init("galaxy"); // Auto-select best storage
+ $.jStore.engineReady(function() {
+ action();
+ });
+ }
+}
+
$(document).ready( function() {
// Links with confirmation
$( "a[confirm]" ).click( function() {
diff -r a9402fc7ce1b -r 5536d57237a3 static/scripts/jquery.jstore-all.js
--- a/static/scripts/jquery.jstore-all.js Fri Apr 09 13:02:15 2010 -0400
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,748 +0,0 @@
-/*
- * jStore - Persistent Client-Side Storage
- *
- * Copyright (c) 2009 Eric Garside (http://eric.garside.name)
- *
- * Dual licensed under:
- * MIT: http://www.opensource.org/licenses/mit-license.php
- * GPLv3: http://www.opensource.org/licenses/gpl-3.0.html
- *//**
- * Javascript Class Framework
- *
- * Copyright (c) 2008 John Resig (http://ejohn.org/blog/simple-javascript-inheritance/)
- * Inspired by base2 and Prototype
- */
-(function(){
- var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/;
-
- // The base Class implementation (does nothing)
- this.Class = function(){};
-
- // Create a new Class that inherits from this class
- Class.extend = function(prop) {
- var _super = this.prototype;
-
- // Instantiate a base class (but only create the instance,
- // don't run the init constructor)
- initializing = true;
- var prototype = new this();
- initializing = false;
-
- // Copy the properties over onto the new prototype
- for (var name in prop) {
- // Check if we're overwriting an existing function
- prototype[name] = typeof prop[name] == "function" &&
- typeof _super[name] == "function" && fnTest.test(prop[name]) ?
- (function(name, fn){
- return function() {
- var tmp = this._super;
-
- // Add a new ._super() method that is the same method
- // but on the super-class
- this._super = _super[name];
-
- // The method only need to be bound temporarily, so we
- // remove it when we're done executing
- var ret = fn.apply(this, arguments);
- this._super = tmp;
-
- return ret;
- };
- })(name, prop[name]) :
- prop[name];
- }
-
- // The dummy class constructor
- function Class() {
- // All construction is actually done in the init method
- if ( !initializing && this.init )
- this.init.apply(this, arguments);
- }
-
- // Populate our constructed prototype object
- Class.prototype = prototype;
-
- // Enforce the constructor to be what we expect
- Class.constructor = Class;
-
- // And make this class extendable
- Class.extend = arguments.callee;
-
- return Class;
- };
-})();
-/*
- * jStore Delegate Framework
- * Copyright (c) 2009 Eric Garside (http://eric.garside.name)
- */
-(function($){
-
- this.jStoreDelegate = Class.extend({
- init: function(parent){
- // The Object this delgate operates for
- this.parent = parent;
- // Container for callbacks to dispatch.
- // eventType => [ callback, callback, ... ]
- this.callbacks = {};
- },
- bind: function(event, callback){
- if ( !$.isFunction(callback) ) return this;
- if ( !this.callbacks[ event ] ) this.callbacks[ event ] = [];
-
- this.callbacks[ event ].push(callback);
-
- return this;
- },
- trigger: function(){
- var parent = this.parent,
- args = [].slice.call(arguments),
- event = args.shift(),
- handlers = this.callbacks[ event ];
-
- if ( !handlers ) return false;
-
- $.each(handlers, function(){ this.apply(parent, args) });
- return this;
- }
- });
-
-})(jQuery);/**
- * jStore-jQuery Interface
- * Copyright (c) 2009 Eric Garside (http://eric.garside.name)
- */
-(function($){
-
- // Setup the jStore namespace in jQuery for options storage
- $.jStore = {};
-
- // Seed the options in
- $.extend($.jStore, {
- EngineOrder: [],
- // Engines should put their availability tests within jStore.Availability
- Availability: {},
- // Defined engines should enter themselves into the jStore.Engines
- Engines: {},
- // Instanciated engines should exist within jStore.Instances
- Instances: {},
- // The current engine to use for storage
- CurrentEngine: null,
- // Provide global settings for overwriting
- defaults: {
- project: null,
- engine: null,
- autoload: true,
- flash: 'jStore.Flash.html'
- },
- // Boolean for ready state handling
- isReady: false,
- // Boolean for flash ready state handling
- isFlashReady: false,
- // An event delegate
- delegate: new jStoreDelegate($.jStore)
- .bind('jStore-ready', function(engine){
- $.jStore.isReady = true;
- if ($.jStore.defaults.autoload) engine.connect();
- })
- .bind('flash-ready', function(){
- $.jStore.isFlashReady = true;
- })
- });
-
- // Enable ready callback for jStore
- $.jStore.ready = function(callback){
- if ($.jStore.isReady) callback.apply($.jStore, [$.jStore.CurrentEngine]);
- else $.jStore.delegate.bind('jStore-ready', callback);
- }
-
- // Enable failure callback registration for jStore
- $.jStore.fail = function(callback){
- $.jStore.delegate.bind('jStore-failure', callback);
- }
-
- // Enable ready callback for Flash
- $.jStore.flashReady = function(callback){
- if ($.jStore.isFlashReady) callback.apply($.jStore, [$.jStore.CurrentEngine]);
- else $.jStore.delegate.bind('flash-ready', callback);
- }
-
- // Enable and test an engine
- $.jStore.use = function(engine, project, identifier){
- project = project || $.jStore.defaults.project || location.hostname.replace(/\./g, '-') || 'unknown';
-
- var e = $.jStore.Engines[engine.toLowerCase()] || null,
- name = (identifier ? identifier + '.' : '') + project + '.' + engine;
-
- if ( !e ) throw 'JSTORE_ENGINE_UNDEFINED';
-
- // Instanciate the engine
- e = new e(project, name);
-
- // Prevent against naming conflicts
- if ($.jStore.Instances[name]) throw 'JSTORE_JRI_CONFLICT';
-
- // Test the engine
- if (e.isAvailable()){
- $.jStore.Instances[name] = e; // The Easy Way
- if (!$.jStore.CurrentEngine){
- $.jStore.CurrentEngine = e;
- }
- $.jStore.delegate.trigger('jStore-ready', e);
- } else {
- if (!e.autoload) // Not available
- throw 'JSTORE_ENGINE_UNAVILABLE';
- else { // The hard way
- e.included(function(){
- if (this.isAvailable()) { // Worked out
- $.jStore.Instances[name] = this;
- // If there is no current engine, use this one
- if (!$.jStore.CurrentEngine){
- $.jStore.CurrentEngine = this;
- }
- $.jStore.delegate.trigger('jStore-ready', this);
- }
- else $.jStore.delegate.trigger('jStore-failure', this);
- }).include();
- }
- }
- }
-
- // Set the current storage engine
- $.jStore.setCurrentEngine = function(name){
- if (!$.jStore.Instances.length ) // If no instances exist, attempt to load one
- return $.jStore.FindEngine();
-
- if (!name && $.jStore.Instances.length >= 1) { // If no name is specified, use the first engine
- $.jStore.delegate.trigger('jStore-ready', $.jStore.Instances[0]);
- return $.jStore.CurrentEngine = $.jStore.Instances[0];
- }
-
- if (name && $.jStore.Instances[name]) { // If a name is specified and exists, use it
- $.jStore.delegate.trigger('jStore-ready', $.jStore.Instances[name]);
- return $.jStore.CurrentEngine = $.jStore.Instances[name];
- }
-
- throw 'JSTORE_JRI_NO_MATCH';
- }
-
- // Test all possible engines for straightforward useability
- $.jStore.FindEngine = function(){
- $.each($.jStore.EngineOrder, function(k){
- if ($.jStore.Availability[this]()){ // Find the first, easiest option and use it.
- $.jStore.use(this, $.jStore.defaults.project, 'default');
- return false;
- }
- })
- }
-
- // Provide a simple interface for storing/getting values
- $.jStore.store = function(key, value){
- if (!$.jStore.CurrentEngine) return false;
-
- if ( !value ) // Executing a get command
- return $.jStore.CurrentEngine.get(key);
- // Executing a set command
- return $.jStore.CurrentEngine.set(key, value);
- }
- // Provide a simple interface for storing/getting values
- $.jStore.remove = function(key){
- if (!$.jStore.CurrentEngine) return false;
-
- return $.jStore.CurrentEngine.rem(key);
- }
-
- // Provide a chainable interface for storing values/getting a value at the end of a chain
- $.fn.store = function(key, value){
- if (!$.jStore.CurrentEngine) return this;
-
- var result = $.jStore.store(key, value);
-
- return !value ? result : this;
- }
-
- // Provide a chainable interface for removing values
- $.fn.removeStore = function(key){
- $.jStore.remove(key);
-
- return this;
- }
-
- // Provide a way for users to call for auto-loading
- $.jStore.load = function(){
- if ($.jStore.defaults.engine)
- return $.jStore.use($.jStore.defaults.engine, $.jStore.defaults.project, 'default');
-
- // Attempt to find a valid engine, and catch any exceptions if we can't
- try {
- $.jStore.FindEngine();
- } catch (e) {}
- }
-
-})(jQuery);
-/**
- * jStore Engine Core
- * Copyright (c) 2009 Eric Garside (http://eric.garside.name)
- */
-(function($){
-
- this.StorageEngine = Class.extend({
- init: function(project, name){
- // Configure the project name
- this.project = project;
- // The JRI name given by the manager
- this.jri = name;
- // Cache the data so we can work synchronously
- this.data = {};
- // The maximum limit of the storage engine
- this.limit = -1;
- // Third party script includes
- this.includes = [];
- // Create an event delegate for users to subscribe to event triggers
- this.delegate = new jStoreDelegate(this)
- .bind('engine-ready', function(){
- this.isReady = true;
- })
- .bind('engine-included', function(){
- this.hasIncluded = true;
- });
- // If enabled, the manager will check availability, then run include(), then check again
- this.autoload = false; // This should be changed by the engines, if they have required includes
- // When set, we're ready to transact data
- this.isReady = false;
- // When the includer is finished, it will set this to true
- this.hasIncluded = false;
- },
- // Performs all necessary script includes
- include: function(){
- var self = this,
- total = this.includes.length,
- count = 0;
-
- $.each(this.includes, function(){
- $.ajax({type: 'get', url: this, dataType: 'script', cache: true,
- success: function(){
- count++;
- if (count == total) self.delegate.trigger('engine-included');
- }
- })
- });
- },
- // This should be overloaded with an actual functionality presence check
- isAvailable: function(){
- return false;
- },
- /** Event Subscription Shortcuts **/
- ready: function(callback){
- if (this.isReady) callback.apply(this);
- else this.delegate.bind('engine-ready', callback);
- return this;
- },
- included: function(callback){
- if (this.hasIncluded) callback.apply(this);
- else this.delegate.bind('engine-included', callback);
- return this;
- },
- /** Cache Data Access **/
- get: function(key){
- return this.data[key] || null;
- },
- set: function(key, value){
- this.data[key] = value;
- return value;
- },
- rem: function(key){
- var beforeDelete = this.data[key];
- this.data[key] = null;
- return beforeDelete;
- }
- });
-
-})(jQuery);
-/*
- * jStore DOM Storage Engine
- * Copyright (c) 2009 Eric Garside (http://eric.garside.name)
- */
-(function($){
-
- // Set up a static test function for this instance
- var sessionAvailability = $.jStore.Availability.session = function(){
- return !!window.sessionStorage;
- },
- localAvailability = $.jStore.Availability.local = function(){
- return !!(window.localStorage || window.globalStorage);
- };
-
- this.jStoreDom = StorageEngine.extend({
- init: function(project, name){
- // Call the parental init object
- this._super(project, name);
-
- // The type of storage engine
- this.type = 'DOM';
-
- // Set the Database limit
- this.limit = 5 * 1024 * 1024;
- },
- connect: function(){
- // Fire our delegate to indicate we're ready for data transactions
- this.delegate.trigger('engine-ready');
- },
- get: function(key){
- var out = this.db.getItem(key);
- // Gecko's getItem returns {value: 'the value'}, WebKit returns 'the value'
- return out && out.value ? out.value : out
- },
- set: function(key, value){
- this.db.setItem(key,value);
- return value;
- },
- rem: function(key){
- var out = this.get(key);
- this.db.removeItem(key);
- return out
- }
- })
-
- this.jStoreLocal = jStoreDom.extend({
- connect: function(){
- // Gecko uses a non-standard globalStorage[ www.example.com ] DOM access object for persistant storage.
- this.db = !window.globalStorage ? window.localStorage : window.globalStorage[location.hostname];
- this._super();
- },
- isAvailable: localAvailability
- })
-
- this.jStoreSession = jStoreDom.extend({
- connect: function(){
- this.db = sessionStorage;
- this._super();
- },
- isAvailable: sessionAvailability
- })
-
- $.jStore.Engines.local = jStoreLocal;
- $.jStore.Engines.session = jStoreSession;
-
- // Store the ordering preference
- $.jStore.EngineOrder[ 1 ] = 'local';
-
-})(jQuery);
-/*
- * jStore Flash Storage Engine
- * Copyright (c) 2009 Eric Garside (http://eric.garside.name)
- * jStore.swf Copyright (c) 2008 Daniel Bulli (http://www.nuff-respec.com)
- */
-(function($){
-
- // Set up a static test function for this instance
- var avilability = $.jStore.Availability.flash = function(){
- return !!($.jStore.hasFlash('8.0.0'));
- }
-
- this.jStoreFlash = StorageEngine.extend({
- init: function(project, name){
- // Call the parental init object
- this._super(project, name);
-
- // The type of storage engine
- this.type = 'Flash';
-
- // Bind our flashReady function to the jStore Delegate
- var self = this;
- $.jStore.flashReady(function(){ self.flashReady() });
- },
- connect: function(){
- var name = 'jstore-flash-embed-' + this.project;
-
- // To make Flash Storage work on IE, we have to load up an iFrame
- // which contains an HTML page that embeds the object using an
- // object tag wrapping an embed tag. Of course, this is unnecessary for
- // all browsers except for IE, which, to my knowledge, is the only browser
- // in existance where you need to complicate your code to fix bugs. Goddamnit. :(
- $(document.body)
- .append('<iframe style="height:1px;width:1px;position:absolute;left:0;top:0;margin-left:-100px;" ' +
- 'id="jStoreFlashFrame" src="' +$.jStore.defaults.flash + '"></iframe>');
- },
- flashReady: function(e){
- var iFrame = $('#jStoreFlashFrame')[0];
-
- // IE
- if (iFrame.Document && $.isFunction(iFrame.Document['jStoreFlash'].f_get_cookie)) this.db = iFrame.Document['jStoreFlash'];
- // Safari && Firefox
- else if (iFrame.contentWindow && iFrame.contentWindow.document){
- var doc = iFrame.contentWindow.document;
- // Safari
- if ($.isFunction($('object', $(doc))[0].f_get_cookie)) this.db = $('object', $(doc))[0];
- // Firefox
- else if ($.isFunction($('embed', $(doc))[0].f_get_cookie)) this.db = $('embed', $(doc))[0];
- }
-
- // We're ready to process data
- if (this.db) this.delegate.trigger('engine-ready');
- },
- isAvailable: avilability,
- get: function(key){
- var out = this.db.f_get_cookie(key);
- return out == 'null' ? null : out;
- },
- set: function(key, value){
- this.db.f_set_cookie(key, value);
- return value;
- },
- rem: function(key){
- var beforeDelete = this.get(key);
- this.db.f_delete_cookie(key);
- return beforeDelete;
- }
- })
-
- $.jStore.Engines.flash = jStoreFlash;
-
- // Store the ordering preference
- $.jStore.EngineOrder[ 2 ] = 'flash';
-
- /**
- * Flash Detection functions copied from the jQuery Flash Plugin
- * Copyright (c) 2006 Luke Lutman (http://jquery.lukelutman.com/plugins/flash)
- * Dual licensed under the MIT and GPL licenses.
- * http://www.opensource.org/licenses/mit-license.php
- * http://www.opensource.org/licenses/gpl-license.php
- */
- $.jStore.hasFlash = function(version){
- var pv = $.jStore.flashVersion().match(/\d+/g),
- rv = version.match(/\d+/g);
-
- for(var i = 0; i < 3; i++) {
- pv[i] = parseInt(pv[i] || 0);
- rv[i] = parseInt(rv[i] || 0);
- // player is less than required
- if(pv[i] < rv[i]) return false;
- // player is greater than required
- if(pv[i] > rv[i]) return true;
- }
- // major version, minor version and revision match exactly
- return true;
- }
-
- $.jStore.flashVersion = function(){
- // ie
- try {
- try {
- // avoid fp6 minor version lookup issues
- // see: http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet…
- var axo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.6');
- try { axo.AllowScriptAccess = 'always'; }
- catch(e) { return '6,0,0'; }
- } catch(e) {}
- return new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version').replace(/\D+/g, ',').match(/^,?(.+),?$/)[1];
- // other browsers
- } catch(e) {
- try {
- if(navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin){
- return (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]).description.replace(/\D+/g, ",").match(/^,?(.+),?$/)[1];
- }
- } catch(e) {}
- }
- return '0,0,0';
- }
-
-})(jQuery);
-
-// Callback fired when ExternalInterface is established
-function flash_ready(){
- $.jStore.delegate.trigger('flash-ready');
-}
-/*
- * jStore Google Gears Storage Engine
- * Copyright (c) 2009 Eric Garside (http://eric.garside.name)
- */
-(function($){
-
- // Set up a static test function for this instance
- var avilability = $.jStore.Availability.gears = function(){
- return !!(window.google && window.google.gears)
- }
-
- this.jStoreGears = StorageEngine.extend({
- init: function(project, name){
- // Call the parental init object
- this._super(project, name);
-
- // The type of storage engine
- this.type = 'Google Gears';
-
- // Add required third-party scripts
- this.includes.push('http://code.google.com/apis/gears/gears_init.js');
-
- // Allow Autoloading on fail
- this.autoload = true;
- },
- connect: function(){
- // Create our database connection
- var db = this.db = google.gears.factory.create('beta.database');
- db.open( 'jstore-' + this.project );
- db.execute( 'CREATE TABLE IF NOT EXISTS jstore (k TEXT UNIQUE NOT NULL PRIMARY KEY, v TEXT NOT NULL)' );
-
- // Cache the data from the table
- this.updateCache();
- },
- updateCache: function(){
- // Read the database into our cache object
- var result = this.db.execute( 'SELECT k,v FROM jstore' );
- while (result.isValidRow()){
- this.data[result.field(0)] = result.field(1);
- result.next();
- } result.close();
-
- // Fire our delegate to indicate we're ready for data transactions
- this.delegate.trigger('engine-ready');
- },
- isAvailable: avilability,
- set: function(key, value){
- // Update the database
- var db = this.db;
- db.execute( 'BEGIN' );
- db.execute( 'INSERT OR REPLACE INTO jstore(k, v) VALUES (?, ?)', [key,value] );
- db.execute( 'COMMIT' );
- return this._super(key, value);
- },
- rem: function(key){
- // Update the database
- var db = this.db;
- db.execute( 'BEGIN' );
- db.execute( 'DELETE FROM jstore WHERE k = ?', [key] );
- db.execute( 'COMMIT' );
- return this._super(key);
- }
- })
-
- $.jStore.Engines.gears = jStoreGears;
-
- // Store the ordering preference
- $.jStore.EngineOrder[ 3 ] = 'gears';
-
-})(jQuery);
-/*
- * jStore HTML5 Specification Storage Engine
- * Copyright (c) 2009 Eric Garside (http://eric.garside.name)
- */
-(function($){
-
- // Set up a static test function for this instance
- var avilability = $.jStore.Availability.html5 = function(){
- return !!window.openDatabase
- }
-
- this.jStoreHtml5 = StorageEngine.extend({
- init: function(project, name){
- // Call the parental init object
- this._super(project, name);
-
- // The type of storage engine
- this.type = 'HTML5';
-
- // Set the Database limit
- this.limit = 1024 * 200;
- },
- connect: function(){
- // Create our database connection
- var db = this.db = openDatabase('jstore-' + this.project, '1.0', this.project, this.limit);
- if (!db) throw 'JSTORE_ENGINE_HTML5_NODB';
- db.transaction(function(db){
- db.executeSql( 'CREATE TABLE IF NOT EXISTS jstore (k TEXT UNIQUE NOT NULL PRIMARY KEY, v TEXT NOT NULL)' );
- });
-
- // Cache the data from the table
- this.updateCache();
- },
- updateCache: function(){
- var self = this;
- // Read the database into our cache object
- this.db.transaction(function(db){
- db.executeSql( 'SELECT k,v FROM jstore', [], function(db, result){
- var rows = result.rows, i = 0, row;
- for (; i < rows.length; ++i){
- row = rows.item(i);
- self.data[row.k] = row.v;
- }
-
- // Fire our delegate to indicate we're ready for data transactions
- self.delegate.trigger('engine-ready');
- });
- });
- },
- isAvailable: avilability,
- set: function(key, value){
- // Update the database
- this.db.transaction(function(db){
- db.executeSql( 'INSERT OR REPLACE INTO jstore(k, v) VALUES (?, ?)', [key,value]);
- });
- return this._super(key, value);
- },
- rem: function(key){
- // Update the database
- this.db.transaction(function(db){
- db.executeSql( 'DELETE FROM jstore WHERE k = ?', [key] )
- })
- return this._super(key);
- }
- })
-
- $.jStore.Engines.html5 = jStoreHtml5;
-
- // Store the ordering preference
- $.jStore.EngineOrder[ 0 ] = 'html5';
-
-})(jQuery);
-/*
- * jStore IE Storage Engine
- * Copyright (c) 2009 Eric Garside (http://eric.garside.name)
- */
-(function($){
-
- // Set up a static test function for this instance
- var avilability = $.jStore.Availability.ie = function(){
- return !!window.ActiveXObject;
- }
-
- this.jStoreIE = StorageEngine.extend({
- init: function(project, name){
- // Call the parental init object
- this._super(project, name);
-
- // The type of storage engine
- this.type = 'IE';
-
- // Allow Autoloading on fail
- this.limit = 64 * 1024;
- },
- connect: function(){
- // Create a hidden div to store attributes in
- this.db = $('<div style="display:none;behavior:url(\'#default#userData\')" id="jstore-' + this.project + '"></div>')
- .appendTo(document.body).get(0);
- // Fire our delegate to indicate we're ready for data transactions
- this.delegate.trigger('engine-ready');
- },
- isAvailable: avilability,
- get: function(key){
- this.db.load(this.project);
- return this.db.getAttribute(key);
- },
- set: function(key, value){
- this.db.setAttribute(key, value);
- this.db.save(this.project);
- return value;
- },
- rem: function(key){
- var beforeDelete = this.get(key);
- this.db.removeAttribute(key);
- this.db.save(this.project);
- return beforeDelete;
- }
- })
-
- $.jStore.Engines.ie = jStoreIE;
-
- // Store the ordering preference
- $.jStore.EngineOrder[ 4 ] = 'ie';
-
-})(jQuery);
diff -r a9402fc7ce1b -r 5536d57237a3 static/scripts/jquery.jstore.js
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/static/scripts/jquery.jstore.js Fri Apr 09 18:09:54 2010 -0400
@@ -0,0 +1,1810 @@
+/*!
+ * jStore 2.0 - Persistent Client Side Storage
+ *
+ * Copyright (c) 2010 Eric Garside (http://eric.garside.name/)
+ * Dual licensed under:
+ * MIT: http://www.opensource.org/licenses/mit-license.php
+ * GPLv3: http://www.opensource.org/licenses/gpl-3.0.html
+ *
+ * ---------------------------
+ *
+ * jStore Flash Storage Component
+ *
+ * Copyright (c) 2006 Jeff Lerman (jeff(a)blip.tv)
+ * Licensed under the Creative Commons Attribution 3.0 United States License:
+ * http://creativecommons.org/licenses/by/3.0/us
+ */
+
+"use strict";
+
+/*global Class, window, jQuery, ActiveXObject, google */
+
+/*jslint white: true, browser: true, onevar: true, undef: true, eqeqeq: true, bitwise: true, regexp: false, strict: true, newcap: true, immed: true, maxerr: 50, indent: 4 */
+
+(function ($, window) {
+
+ //------------------------------
+ //
+ // Constants
+ //
+ //------------------------------
+
+ //------------------------------
+ // Exceptions
+ //------------------------------
+
+ /**
+ * An exception thrown by the StorageEngine class whenever its data accessor methods
+ * are called before the engine is ready to transact data.
+ */
+ var EX_UNSTABLE = 'JSTORE_ENGINE_UNSTABLE',
+
+ /**
+ * An exception thrown by jStore whenever an undefined storage engine is referenced for
+ * some task by an invalid JRI (jStore Resource Identifier).
+ */
+ EX_UNKNOWN = 'JSTORE_UNKNOWN_ENGINE_REQUESTED',
+
+ /**
+ * An exception thrown by jStore whenever a given flavor of storage is double defined.
+ */
+ EX_COLLISION = 'JSTORE_ENGINE_NAMESPACE_COLLISION',
+
+ /**
+ * An exception thrown by jStore whenever a jri is double applied to a resource.
+ */
+ EX_DUPLICATE = 'JSTORE_RESOURCE_NAMESPACE_COLLISION',
+
+ /**
+ * An exception thrown by jStore whenever a given flavor of storage has no defined engine.
+ */
+ EX_UNAVAILABLE = 'JSTORE_ENGINE_UNAVAILABLE',
+
+ /**
+ * An exception thrown by jStore whenever an invalid flavor type is used.
+ */
+ EX_INVALID = 'JSTORE_INVALID_FLAVOR',
+
+ //------------------------------
+ // Regular Expressions
+ //------------------------------
+
+ /**
+ * Regular expression to test property values for being JSON.
+ */
+ RX_JSON = (function ()
+ {
+ try
+ {
+ return new RegExp('^("(\\\\.|[^"\\\\\\n\\r])*?"|[,:{}\\[\\]0-9.\\-+Eaeflnr-u \\n\\r\\t])+?$');
+ }
+ catch (e)
+ {
+ return (/^(true|false|null|\[.*\]|\{.*\}|".*"|\d+|\d+\.\d+)$/);
+ }
+ }()),
+
+ //------------------------------
+ // Storage Flavors
+ //------------------------------
+
+ /**
+ * The storage flavor identifier for HTML5 local storage.
+ */
+ FLAVOR_LOCAL = 'jstore-html5-local',
+
+ /**
+ * The storage flavor identifier for HTML5 database storage.
+ */
+ FLAVOR_SQL = 'jstore-html5-sql',
+
+ /**
+ * The storage flavor identifier for Adobe Flash SharedObject storage.
+ */
+ FLAVOR_FLASH = 'jstore-flash',
+
+ /**
+ * The storage flavor identifier for Google Gears storage.
+ */
+ FLAVOR_GEARS = 'jstore-google-gears',
+
+ /**
+ * The storage flavor identifier for Internet Explorer storage, available to IE7 and IE6.
+ */
+ FLAVOR_MSIE = 'jstore-msie',
+
+ //------------------------------
+ //
+ // Property Declaration
+ //
+ //------------------------------
+
+ /**
+ * The base StorageEngine class which each "storage flavor" will extend to meet the
+ * requirements for its specific implementation.
+ */
+ StorageEngine,
+
+ /**
+ * The jStore object. Internal to this closure, jStore is referenced by "_". It is
+ * exposed to jQuery below, and made publicly accessible through jQuery.jStore
+ */
+ _ = {},
+
+ /**
+ * The engines available to jStore for use. These are the class definitions for flavored
+ * storage engines.
+ *
+ * Signature:
+ * {
+ * <storageFlavor>: <flavoredStorageEngineDefinition>,
+ *
+ * ...
+ * }
+ */
+ definitions = {},
+
+ /**
+ * Active engines instantiated by jStore, indexed by their JRI.
+ *
+ * Signature:
+ * {
+ * <engineJRI>: <engineInstance>,
+ *
+ * ...
+ * }
+ */
+ engines = {},
+
+ /**
+ * If we are going to be using the flash storage engine, we want to postpone the jStore ready event until the jStore
+ * isFlashReady flag is also true. This property is set whenever flash is determined to be the storage engine.
+ */
+ waitForFlash = false,
+
+ /**
+ * Storage for listeners, indexed by content and event type.
+ *
+ * Signature:
+ * {
+ * <context>:
+ * {
+ * <eventType>: [<listener>, ...],
+ *
+ * ...
+ * },
+ *
+ * ...
+ * }
+ */
+ events = {},
+
+ /**
+ * The configuration for this implementation.
+ *
+ * Signature:
+ * {
+ * project: <defaultProjectName>,
+ *
+ * flash: <pathToFlashBootloader>,
+ *
+ * json: <pathToJSONFile>,
+ *
+ * errorCallback: <listenerToNotifyOnError>
+ * }
+ */
+ configurations =
+ {
+ project: undefined,
+
+ flash: 'jStore.Flash.html',
+
+ json: 'browser.json.js'
+ },
+
+ /**
+ * The active storage engine, being used to satisfy the get/set/remove functions on the jStore and jQuery
+ * objects.
+ */
+ active;
+
+ //------------------------------
+ //
+ // Internal Methods
+ //
+ //------------------------------
+
+ /**
+ * Determine if the given flavor is valid.
+ *
+ * @param flavor The flavor to test.
+ *
+ * @return True if the flavor is valid, false otherwise.
+ */
+ function validFlavor(flavor)
+ {
+ switch (flavor)
+ {
+
+ case FLAVOR_LOCAL:
+ case FLAVOR_SQL:
+ case FLAVOR_FLASH:
+ case FLAVOR_GEARS:
+ case FLAVOR_MSIE:
+ return true;
+
+ default:
+ return false;
+
+ }
+ }
+
+ /**
+ * Performs enhanced type comparison on an object. This is more reliable method
+ * of type checking a variable than a simple typeof comparison. The reason is that,
+ * typeof will reduce to the lowest common type.
+ *
+ * "typeof []" returns Object, and not Array.
+ * "typeof {}" returns Object as well.
+ *
+ * typecheck( [], 'Array' ) : returns true;
+ * typecheck( [], 'Object' ) : returns false;
+ *
+ * @param type The variable type to check.
+ *
+ * @param compare A string representing the literal type to check.
+ *
+ * @return True if the variable "type" matches the compare literal.
+ */
+ function typecheck(type, compare)
+ {
+ return !type ? false : type.constructor.toString().match(new RegExp(compare + '\\(\\)', 'i')) !== null;
+ }
+
+ /**
+ * If the provided listener is a valid function, it will be triggered with the provided context
+ * and parameters.
+ *
+ * @param listener The listener being triggered.
+ *
+ * @param context The context to provide to the listener.
+ *
+ * @param parameters The parameters to pass to the listener as arguments.
+ *
+ * @return The response of the notified listener.
+ */
+ function notify(listener, context, parameters)
+ {
+ if (typecheck(listener, 'Function'))
+ {
+ return listener.apply(context || _, typecheck(parameters, 'Array') ? parameters : [parameters]);
+ }
+ }
+
+ /**
+ * Load the given script.
+ *
+ * @param path The path to the file to include.
+ *
+ * @param listener The listener to notify when the file finishes loading.
+ */
+ function loadScript(path, listener)
+ {
+ $.ajax(
+ {
+ url: path,
+ complete: listener || $.noop(),
+ type: 'GET',
+ dataType: 'script',
+ cache: false
+ });
+ }
+
+ /**
+ * Checks the type of the value, and returns a value safe to persist in any client-side mechanism.
+ *
+ * @param value The value which should be prepared for storage.
+ *
+ * @return A value safe for storage.
+ */
+ function prepareForStorage(value)
+ {
+ if (value === undefined)
+ {
+ return '';
+ }
+
+ if (typecheck(value, 'Object') ||
+ typecheck(value, 'Array') ||
+ typecheck(value, 'Function'))
+ {
+ return JSON.stringify(value);
+ }
+
+ return value;
+ }
+
+ /**
+ * Checks the type of the value, and returns a value safe for access in any client-side mechanism.
+ *
+ * @param value The value which should be prepared for use.
+ *
+ * @return A value safe for use.
+ */
+ function prepareForRevival(value)
+ {
+ return RX_JSON.test(value) ? JSON.parse(value) : value;
+ }
+
+ /**
+ * Normalize a key before using it, to ensure it's valid.
+ *
+ * @param key The key to normalize.
+ *
+ * @return A normalized key, safe for storage.
+ */
+ function normalizeKey(key)
+ {
+ return key.replace(/^\s+|\s+$/g, "");
+ }
+
+ /**
+ * Define a flavored storage engine.
+ *
+ * @throws EX_COLLISION, EX_INVALID
+ *
+ * @param flavor The flavor of engine being defined.
+ *
+ * @param definition An object containing the new properties and methods for the engine extension.
+ *
+ * @param availability A function to invoke which must return a boolean value indicating the
+ * availability of the storage flavor on this browser.
+ */
+ function define(flavor, definition, availability)
+ {
+ if (!validFlavor(flavor))
+ {
+ throw EX_INVALID;
+ }
+
+ if (availability[flavor] !== undefined)
+ {
+ throw EX_COLLISION;
+ }
+
+ /**
+ * The logic here has been reworked so unavailable flavors are discarded, so we don't needlessly
+ * bloat the runtime size of jStore.
+ */
+ if (notify(availability) === true)
+ {
+ _.available[flavor] = true;
+
+ definition.flavor = flavor;
+
+ definitions[flavor] = StorageEngine.extend(definition);
+ }
+ else
+ {
+ _.available[flavor] = false;
+
+ // Filter the invalid flavor out of the priority list.
+ _.enginePriority = $.map(_.enginePriority, function (engine)
+ {
+ if (engine === flavor)
+ {
+ return null;
+ }
+ else
+ {
+ return engine;
+ }
+ });
+ }
+ }
+
+ /**
+ * Make the jStore library ready.
+ */
+ function makeReady()
+ {
+ if (_.isReady)
+ {
+ return;
+ }
+
+ if ((waitForFlash && _.isFlashReady) || !waitForFlash)
+ {
+ _.isReady = true;
+ _.trigger('jstore-ready', [engines[active]]);
+ }
+ }
+
+ /**
+ * Create a best-fit engine.
+ */
+ function createBestFitEngine()
+ {
+ _.create(_.enginePriority[0], undefined, 'best-fit');
+ }
+
+ /**
+ * Get the flash version currently supported in this browser.
+ *
+ * @return The flash version.
+ */
+ function flashVersion()
+ {
+ // MSIE
+ try
+ {
+ // avoid fp6 minor version lookup issues
+ // see: http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet…
+ var axo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.6');
+
+ try
+ {
+ axo.AllowScriptAccess = 'always';
+ }
+ catch (axo_e)
+ {
+ return '6,0,0';
+ }
+
+ return new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version').replace(/\D+/g, ',').match(/^,?(.+),?$/)[1];
+ }
+
+ // Real browsers
+ catch (e)
+ {
+ try
+ {
+ if (navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin)
+ {
+ return (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]).description.replace(/\D+/g, ",").match(/^,?(.+),?$/)[1];
+ }
+ }
+ catch (flash_e)
+ {}
+ }
+
+ return '0,0,0';
+ }
+
+ /**
+ * Flash Detection functions copied from the jQuery Flash Plugin
+ *
+ * Copyright (c) 2006 Luke Lutman (http://jquery.lukelutman.com/plugins/flash)
+ *
+ * Dual licensed under the MIT and GPL licenses.
+ * http://www.opensource.org/licenses/mit-license.php
+ * http://www.opensource.org/licenses/gpl-license.php
+ *
+ * @param version The version to compare to.
+ *
+ * @return True if the version is greater than or equal to the required version, false otherwise.
+ */
+ function hasFlashVersion(version)
+ {
+ var playerVersion = flashVersion().match(/\d+/g),
+ requiredVersion = version.match(/\d+/g),
+ index = 0,
+ player,
+ required;
+
+ for (; index < 3; index++)
+ {
+ player = parseInt(playerVersion[index], 10);
+ required = parseInt(requiredVersion[index], 10);
+
+ // Player version is less than what is required.
+ if (player < required)
+ {
+ return false;
+ }
+
+ // Player version is greater than what is required.
+ else if (player > required)
+ {
+ return true;
+ }
+ }
+
+ // Player and required version match exactly.
+ return true;
+ }
+
+ //------------------------------
+ //
+ // Plugin Definition
+ //
+ //------------------------------
+
+ //------------------------------
+ // Error Declaration
+ //------------------------------
+
+ //------------------------------
+ // Plugin Creation
+ //------------------------------
+
+ /**
+ * The jStore object. Manages a collection of StorageEngines for particular "storage flavors", or the types
+ * of storage solutions available to each browser.
+ *
+ * 2.0 Version Notes:
+ *
+ * - The user is now responsible for third-party script includes, with the exception of flash.
+ *
+ * - jStore has been given sole responsibility for testing engine availability.
+ *
+ * - For the sake of naming conventions, all property names now start with a lowercase, and are camel-cased.
+ *
+ * The following properties have been changed since the 1.2.x release:
+ *
+ * - EngineOrder: For the sake of naming conventions, renamed to enginePriority.
+ *
+ * The following properties and methods have been removed since the 1.2.x release:
+ *
+ * - Availability: jStore's engines would add their availability tests to this object, so jStore could test
+ * them. With the changes to how availability testing works, this property has been removed.
+ * A new property, "available" on jStore contains a set of available engines.
+ *
+ * - Engines: Formerly contained the definitions of storage engines. This property has been removed, and
+ * storage of these definitions has been moved internal to the closure.
+ *
+ * - Instances: Formerly contained instantiated storage engines. This property has been removed, and storage
+ * of instantiated engines has been moved internal to the closure.
+ *
+ * - CurrentEngine: Formerly contained the active storage engine being used for transacting data through the jStore
+ * and/or jQuery objects. This property has been removed, and storage of the current engine has
+ * been moved internal to the closure. A new method, "activeEngine" has been added to jQuery to
+ * get and set the active engine to use.
+ *
+ * - defaults: Formerly used to set the implementation options for jStore. This property has been removed and
+ * replaced with a new configuration metho on the jStore object.
+ *
+ * - delegate: The delegate class has been removed in favor of a much simpler bind/trigger accessor system, which
+ * is accessible contextually through storage engines, or generically through jStore.
+ *
+ * + fail: This registration class bound events on the delegate for jstore-fail events. Instead, use:
+ * jStore.bind('jstore-failure', listener);
+ *
+ * + flashReady: This registration class bound events on the delegate for flash-ready events. The jstore-ready method
+ * now accounts for waiting for flash readyness, if and only if the flash engine is being used. Simply
+ * call to jStore.ready().
+ *
+ * + load: Replaced with the init() method, which performs the same basic functions as the old load() method. Also,
+ * the init function is now domready safe, meaning it wraps itself in a domready listener, so the end user
+ * doesn't have to.
+ *
+ * + FindEngine: Removed entirely. The functionality provided by this method now implicitly occurs with the new define()
+ * system implemented for engine flavors.
+ *
+ * + setCurrentEngine: Replaced by activeEngine(). Set the current active engine by passing in the JRI.
+ *
+ * + safeStore: Replaced by a method internal to this closure, "prepareForStorage".
+ *
+ * + safeResurrect: Replaced by a method internal to this closure, "prepareForRevival".
+ *
+ * + use: Replaced by "create".
+ */
+ $.extend(_, {
+
+ //------------------------------
+ // Properties
+ //------------------------------
+
+ /**
+ * The priority order in which engines should be tested for use. The lower their index in the array, the higher
+ * their priority for use.
+ *
+ * Be weary when reconfiguring the priority order of engines! jStore will use the first available engine it finds
+ * based on its priority when autoloading.
+ *
+ * This array is filtered out as engines are defined, with invalid engines being removed.
+ *
+ * Signature:
+ * [FLAVOR_<storageFlavor>, ...]
+ */
+ enginePriority: [FLAVOR_LOCAL, FLAVOR_SQL, FLAVOR_FLASH, FLAVOR_MSIE],
+
+ /**
+ * A collection of the availability states of engines, indexed by their flavor.
+ *
+ * Signature:
+ * {
+ * <storageFlavor>: true|false,
+ *
+ * ...
+ * }
+ */
+ available: {},
+
+ /**
+ * Flag to determine if the jStore library is ready. jStore becomes ready once the dom is ready and all necessary
+ * startup procedures required by jStore to function properly are completed.
+ */
+ isReady: false,
+
+ /**
+ * With the flash storage engine, we have to jump through a couple of hoops before the flash engine is ready to work.
+ * This flag tracks whether or not the flash storage is available.
+ */
+ isFlashReady: false,
+
+ /**
+ * The available engine flavors.
+ */
+ flavors:
+ {
+ local: FLAVOR_LOCAL,
+
+ sql: FLAVOR_SQL,
+
+ flash: FLAVOR_FLASH,
+
+ gears: FLAVOR_GEARS,
+
+ msie: FLAVOR_MSIE
+ },
+
+ //------------------------------
+ // Constructor
+ //------------------------------
+
+ /**
+ * Constructor.
+ *
+ * @throws EX_INVALID
+ *
+ * @param project The name of the jStore project. Used to generate a JRI for the engine we create.
+ *
+ * @param configuration Optionally, an object containing configuration options for this implementation.
+ *
+ * @param flavor Optionally, the flavor of storage to use. If not provided, jStore will pick the
+ * best flavor, based on the current browser.
+ *
+ * @return jStore
+ */
+ init: function (project, configuration, flavor)
+ {
+ // Extend our plugin configurations
+ $.extend(configurations, {project: project}, configuration);
+
+ $(function ()
+ {
+ // If JSON parsing isn't defined in this browser, include it.
+ if (window.JSON === undefined)
+ {
+ loadScript(configurations.json);
+ }
+
+ // If we have an explicit flavor to use, use it.
+ if (flavor !== undefined)
+ {
+ _.create(flavor, project, 'default');
+ }
+
+ // Otherwise, attempt to create a best-fit engine.
+ else
+ {
+ createBestFitEngine();
+ }
+ });
+
+ return _;
+ },
+
+ //------------------------------
+ // Methods
+ //------------------------------
+
+ /**
+ * Create an instance of a flavored engine.
+ *
+ * @throws EX_INVALID, EX_UNAVAILABLE, EX_DUPLICATE
+ *
+ * @param flavor The flavor to create the engine with.
+ *
+ * @param project The project identifier for this instance.
+ *
+ * @param identifier Some arbitrary identifier for this project instance of the engine.
+ *
+ * @return The created instance.
+ */
+ create: function (flavor, project, identifier)
+ {
+ project = project || configurations.project || location.hostname.replace(/\./g, '-') || 'unknown';
+
+ if (!validFlavor(flavor))
+ {
+ throw EX_INVALID;
+ }
+
+ if (definitions[flavor] === undefined)
+ {
+ throw EX_UNAVAILABLE;
+ }
+
+ var jri = (identifier !== undefined ? identifier + '.' : '') + project + '.' + flavor,
+ engine;
+
+ if (engines[jri] !== undefined)
+ {
+ throw EX_DUPLICATE;
+ }
+
+ // Create our engine instance.
+ engine = engines[jri] = new definitions[flavor](project, jri);
+
+ // Set up a listener for our jstore-engine-ready event.
+ engine.ready(function ()
+ {
+ _.trigger('jstore-engine-ready', [engine]);
+ });
+
+ if (flavor === FLAVOR_FLASH && !_.isFlashReady)
+ {
+ if (active === undefined)
+ {
+ waitForFlash = true;
+ }
+
+ // Define a window-accessible function for flash to call via ExternalInterface
+ window.jstore_ready = function ()
+ {
+ _.isFlashReady = true;
+ _.trigger('flash-ready');
+
+ if (active === undefined)
+ {
+ makeReady();
+ }
+
+ // Remove the callback from the window scope, as it is no longer necessary
+ window.flash_ready = undefined;
+ };
+
+ window.jstore_error = function (message)
+ {
+ _.trigger('jstore-error', ['JSTORE_FLASH_EXCEPTION', null, message]);
+ };
+
+ $('<iframe style="height:1px;width:1px;position:absolute;left:0;top:0;margin-left:-100px;" id="jStoreFlashFrame" src="' +
+ configurations.flash + '"></iframe>').appendTo('body');
+ }
+ else if (active === undefined)
+ {
+ active = jri;
+ makeReady();
+ }
+
+ return engine;
+ },
+
+ /**
+ * Fetch an engine by it's JRI.
+ *
+ * @param jri The JRI of the engine to retrieve.
+ *
+ * @return The requested engine.
+ */
+ engine: function (jri)
+ {
+ return engines[jri];
+ },
+
+ /**
+ * Returns the active storage engine being used. If a value is passed, sets that engine as the active engine.
+ *
+ * @throws EX_UNKNOWN
+ *
+ * @param jri Optionally, the JRI of the engine to make active, if it should be changed.
+ *
+ * @return The active storage engine.
+ */
+ activeEngine: function (jri)
+ {
+ if (jri !== undefined)
+ {
+ if (engines[jri] === undefined)
+ {
+ throw EX_UNKNOWN;
+ }
+ else
+ {
+ active = jri;
+ }
+ }
+
+ return engines[active];
+ },
+
+ /**
+ * Bind an event listener.
+ *
+ * @param event The event to bind a listener on.
+ *
+ * @param listener The listener to notify when the event occurs.
+ *
+ * @param context The context of the binding. A string representing the engine flavor
+ * binding the event, or undefined to indicate it's a jStore event.
+ *
+ * @return jStore
+ */
+ bind: function (event, listener, context)
+ {
+ context = context || 'jstore';
+
+ if (events[context] === undefined)
+ {
+ events[context] = {};
+ }
+
+ if (events[context][event] === undefined)
+ {
+ events[context][event] = [listener];
+ }
+ else
+ {
+ events[context][event].push(listener);
+ }
+
+ return _;
+ },
+
+ /**
+ * Trigger an event, notifying any bound listeners.
+ *
+ * @param event The event to trigger.
+ *
+ * @param parameters Any additional parameters to pass to the listeners being notified.
+ *
+ * @param context The context of the binding. A string representing the engine flavor
+ * binding the event, or undefined to indicate it's a jStore event.
+ *
+ * @return jStore
+ */
+ trigger: function (event, parameters, context)
+ {
+ context = context || 'jstore';
+
+ if (events[context] !== undefined)
+ {
+ if (events[context][event] !== undefined)
+ {
+ $.each(events[context][event], function ()
+ {
+ notify(this, _, parameters);
+ });
+ }
+ }
+
+ return _;
+ },
+
+ /**
+ * Bind a listener to be notified when jStore causes a non-fatal exception.
+ *
+ * @param listener The listener to notify when a failure occurs.
+ */
+ error: function (listener)
+ {
+ _.bind('jstore-error', listener);
+ },
+
+ /**
+ * Bind a listener to be notified when jStore is ready.
+ *
+ * @param listener The listener to notify when jStore is ready.
+ *
+ * @return jStore
+ */
+ ready: function (listener)
+ {
+ if (_.isReady)
+ {
+ notify(listener);
+ }
+ else
+ {
+ _.bind('jstore-ready', listener);
+ }
+
+ return _;
+ },
+
+ /**
+ * Bind a listener to be notified when jStore and the default engine are ready.
+ *
+ * @param listener The listener to notify when jStore and it's default engine are ready.
+ *
+ * @return jStore
+ */
+ engineReady: function (listener)
+ {
+ if (_.isReady)
+ {
+ notify(listener);
+ }
+ else
+ {
+ _.bind('jstore-engine-ready', listener);
+ }
+
+ return _;
+ },
+
+ /**
+ * A combined getter/setter for the active engine.
+ *
+ * @param key The key of the property to get, or set.
+ *
+ * @param value If a valid value is provided, sets the engine.
+ *
+ * @return The requested property value.
+ */
+ store: function (key, value)
+ {
+ return value === undefined ? _.get(key) : _.set(key, value);
+ },
+
+ /**
+ * Remove a property from the active engine.
+ *
+ * @param key The key of the property to remove.
+ *
+ * @return The value of the property before removal.
+ */
+ remove: function (key)
+ {
+ return _.activeEngine().remove(key);
+ },
+
+ /**
+ * Get a property from the active engine.
+ *
+ * @param key The key of the property to get.
+ *
+ * @return The value of the property.
+ */
+ get: function (key)
+ {
+ return _.activeEngine().get(key);
+ },
+
+ /**
+ * Set a property on the active engine.
+ *
+ * @param key The key of the property to set.
+ *
+ * @param value The value to set the property to.
+ *
+ * @return The new value of the property.
+ */
+ set: function (key, value)
+ {
+ return _.activeEngine().set(key, value);
+ }
+
+ });
+
+ //------------------------------
+ // Core Extension
+ //------------------------------
+
+ //------------------------------
+ //
+ // Class Definition
+ //
+ //------------------------------
+
+ /**
+ * The StorageEngine class is the unified API through which jStore accesses and manipulates
+ * the various storage flavors available.
+ *
+ * 2.0 Version Notes:
+ *
+ * - All third-party loading is now the responsibility of the developer.
+ *
+ * - The delegate class has been removed entirely. Engines have been given "bind" and "trigger" methods
+ * to interact directly with the delegate like-replacement that has been added to jStore.
+ *
+ * - Engine availability has been moved out of the engines themselves, and elevated to a jStore
+ * responsibility.
+ *
+ * The following methods have changed since the 1.2.x release:
+ *
+ * - get: When "get"ting a non-stored property, the get function will now return "undefined"
+ * instead of "null". "null" can now be used as a valid property value.
+ *
+ * - rem: Renamed to "remove". I always felt dirty about "rem" being vaguely explicit.
+ *
+ * The following properties have been removed since the 1.2.x release:
+ *
+ * - autoload: Part of the third-party loading logic.
+ *
+ * - hasIncluded: Part of the third-party loading logic.
+ *
+ * - includes: Part of the third-party loading logic.
+ *
+ * - isAvailable: Part of the availability logic elevated to jStore.
+ *
+ * @throws EX_UNSTABLE
+ */
+ StorageEngine = Class.extend({
+
+ //------------------------------
+ // Properties
+ //------------------------------
+
+ /**
+ * The project which owns this storage engine.
+ */
+ project: undefined,
+
+ /**
+ * The JRI (jStore Resource Identifier) acts as a uuid for this specific instance
+ * of the storage engine.
+ */
+ jri: undefined,
+
+ /**
+ * The flavor of this engine.
+ */
+ flavor: undefined,
+
+ /**
+ * The actual database object which data is transacted through.
+ */
+ database: undefined,
+
+ /**
+ * A StorageEngine should always respond to fetch requests synchronously. However, some
+ * of the storage flavors require callback-based asynchronous access. To get around this,
+ * we simlpy require all engines to function off a primary data cache, to allow for
+ * synchronous access across all implementations.
+ *
+ * Signature:
+ * {
+ * <propertyKey>: <propertyValue>,
+ *
+ * ...
+ * }
+ */
+ data: undefined,
+
+ /**
+ * A number of storage engines enforce a size limit as to what they will persist for a given site.
+ * This limit is not monitored or computed by jStore currently, and this property will merely give
+ * a static indication of the total size alloted to the engine, as defined by the storage flavor.
+ */
+ limit: undefined,
+
+ /**
+ * Each storage flavor has a different process to go through before it's "ready" to transact data. This
+ * property stores the state of the engine's readyness, and uses it to notify listeners whenever jStore
+ * is ready to function.
+ */
+ isReady: undefined,
+
+ //------------------------------
+ // Constructor
+ //------------------------------
+
+ /**
+ * Constructor.
+ *
+ * @param project The project which instantiated this engine.
+ *
+ * @param jri The uuid assigned to this instance by jStore.
+ */
+ init: function (project, jri)
+ {
+ this.project = project;
+ this.jri = jri;
+ this.data = {};
+ this.isReady = false;
+ this.updateCache();
+ },
+
+ //------------------------------
+ // Methods
+ //------------------------------
+
+ /**
+ * Update the cache.
+ */
+ updateCache: function ()
+ {
+ this.isReady = true;
+ this.trigger('engine-ready', [this]);
+ },
+
+ /**
+ * Bind a listener to an event dispatched by this engine.
+ *
+ * @param event The event to bind on.
+ *
+ * @param listener The listener to notify when the event occurs.
+ */
+ bind: function (event, listener)
+ {
+ _.bind(event, listener, this.jri);
+ },
+
+ /**
+ * Trigger an event, notifying all bound listeners.
+ *
+ * @param event The event to trigger.
+ *
+ * @param parameters An optional Array of parameters to pass to the listeners.
+ */
+ trigger: function (event, parameters)
+ {
+ _.trigger(event, parameters, this.jri);
+ },
+
+ /**
+ * Bind a listener to the StorageEngine's ready event.
+ *
+ * @param listener The listener to notify whenever this engine is ready to transact data.
+ */
+ ready: function (listener)
+ {
+ if (this.isReady)
+ {
+ notify(listener, this);
+ }
+ else
+ {
+ this.bind('engine-ready', listener);
+ }
+ },
+
+ /**
+ * Get a property from the StorageEngine.
+ *
+ * @param key The property key of the data to retrieve.
+ *
+ * @return The property value, or "undefined" if the property isn't stored.
+ */
+ get: function (key)
+ {
+ this.__interruptAccess();
+
+ return this.data[key];
+ },
+
+ /**
+ * Sets a property in the StorageEngine.
+ *
+ * @param key The key of the property.
+ *
+ * @param value The value of the property.
+ *
+ * @return The new value of the property.
+ */
+ set: function (key, value)
+ {
+ this.__interruptAccess();
+
+ key = normalizeKey(key);
+
+ try
+ {
+ this.__set(key, value);
+ }
+ catch (e)
+ {
+ _.trigger('jstore-error', ['JSTORE_STORAGE_FAILURE', this.jri, e]);
+ }
+
+ this.data[key] = value;
+
+ return value;
+ },
+
+ /**
+ * Removes a property from the StorageEngine.
+ *
+ * @param key The property key of the data to remove.
+ *
+ * @return The value of the property, before it was removed.
+ */
+ remove: function (key)
+ {
+ this.__interruptAccess();
+
+ key = normalizeKey(key);
+
+ try
+ {
+ this.__remove(key);
+ }
+ catch (e)
+ {
+ _.trigger('jstore-error', ['JSTORE_REMOVE_FAILURE', this.jri, e]);
+ }
+
+ var buffer = this.data[key];
+
+ this.data[key] = undefined;
+
+ return buffer;
+ },
+
+ //------------------------------
+ // Internal Methods
+ //------------------------------
+
+ /**
+ * Ensures the engine is in a stable state for transacting data.
+ *
+ * @throws EX_UNSTABLE
+ */
+ __interruptAccess: function ()
+ {
+ if (!this.isReady)
+ {
+ throw EX_UNSTABLE;
+ }
+ },
+
+ /**
+ * Sets a property in the StorageEngine. This method should be overloaded to provide actual
+ * storage flavor integration.
+ *
+ * @param key The key of the property.
+ *
+ * @param value The value of the property.
+ *
+ * @return The new value of the property.
+ */
+ __set: function (key, value)
+ {
+ return;
+ },
+
+ /**
+ * Removes a property from the StorageEngine. This method should be overloaded to provide actual
+ * storage flavor integration.
+ *
+ * @param key The property key of the data to remove.
+ *
+ * @return The value of the property, before it was removed.
+ */
+ __remove: function (key)
+ {
+ return;
+ }
+
+ });
+
+ //------------------------------
+ //
+ // jQuery Hooks
+ //
+ //------------------------------
+
+ $.extend($.fn, {
+
+ //------------------------------
+ // Methods
+ //------------------------------
+
+ /**
+ * A combined getter/setter for the active engine.
+ *
+ * @param key The key of the property to get, or set.
+ *
+ * @param value If a valid value is provided, sets the engine.
+ *
+ * @return jQuery
+ */
+ store: function (key, value)
+ {
+ if (value === undefined)
+ {
+ _.get(key);
+ }
+ else
+ {
+ _.set(key, value);
+ }
+
+ return this;
+ },
+
+ /**
+ * Remove a property from the active engine.
+ *
+ * @param key The key of the property to remove.
+ *
+ * @return jQuery
+ */
+ removeStore: function (key)
+ {
+ _.activeEngine().remove(key);
+
+ return this;
+ },
+
+ /**
+ * Get a property from the active engine.
+ *
+ * @param key The key of the property to get.
+ *
+ * @return The value of the property.
+ */
+ getStore: function (key)
+ {
+ return _.activeEngine().get(key);
+ },
+
+ /**
+ * Set a property on the active engine.
+ *
+ * @param key The key of the property to set.
+ *
+ * @param value The value to set the property to.
+ *
+ * @return jQuery
+ */
+ setStore: function (key, value)
+ {
+ _.activeEngine().set(key, value);
+
+ return this;
+ }
+
+ });
+
+ //------------------------------
+ //
+ // Event Bindings
+ //
+ //------------------------------
+
+ //------------------------------
+ //
+ // Startup Code
+ //
+ //------------------------------
+
+ //------------------------------
+ // Expose jStore through jQuery
+ //------------------------------
+
+ window.jStore = $.jStore = _;
+
+ //------------------------------
+ //
+ // Engine Definitions
+ //
+ //------------------------------
+
+ //------------------------------
+ // Local
+ //------------------------------
+
+ define(FLAVOR_LOCAL,
+ {
+ //------------------------------
+ // Properties
+ //------------------------------
+
+ limit: parseInt(5e5, 16),
+
+ //------------------------------
+ // Constructor
+ //------------------------------
+
+ init: function (project, name)
+ {
+ this.database = window.globalStorage === undefined ? window.localStorage : window.globalStorage[location.hostname];
+
+ this._super(project, name);
+ },
+
+ //------------------------------
+ // Methods
+ //------------------------------
+
+ updateCache: function ()
+ {
+ var key, value;
+
+ for (key in this.database)
+ {
+ var has_key = false;
+ if (this.database.hasOwnProperty) {
+ if (this.database.hasOwnProperty(key)) {
+ has_key = true;
+ }
+ } else { // IE 8
+ if (this.database.getItem(key) !== null) {
+ has_key = true;
+ }
+ }
+
+ if (has_key) {
+ value = this.database.getItem(key);
+
+ // Gecko's getItem returns {value: 'the value'}, WebKit returns 'the value'
+ this.data[key] = prepareForRevival(value && value.value ? value.value : value);
+ }
+ }
+
+ this._super();
+ },
+
+ //------------------------------
+ // Internal methods
+ //------------------------------
+
+ __set: function (key, value)
+ {
+ this.database.setItem(key, prepareForStorage(value));
+ },
+
+ __remove: function (key)
+ {
+ this.database.removeItem(key);
+ }
+ },
+
+ function ()
+ {
+ return window.localStorage !== undefined || window.globalStorage !== undefined;
+ });
+
+ //------------------------------
+ // SQL
+ //------------------------------
+
+ define(FLAVOR_SQL,
+ {
+ //------------------------------
+ // Properties
+ //------------------------------
+
+ limit: parseInt(32e3, 16),
+
+ //------------------------------
+ // Constructor
+ //------------------------------
+
+ init: function (project, name)
+ {
+ this.database = window.openDatabase('jstore-' + project, '1.0', project, this.limit);
+
+ if (!this.database)
+ {
+ throw 'JSTORE_SQL_NO_DB';
+ }
+
+ this.database.transaction(function (database)
+ {
+ database.executeSql('CREATE TABLE IF NOT EXISTS jstore (k TEXT UNIQUE NOT NULL PRIMARY KEY, v TEXT NOT NULL)');
+ });
+
+ this._super(project, name);
+ },
+
+ //------------------------------
+ // Methods
+ //------------------------------
+
+ updateCache: function ()
+ {
+ var self = this,
+ _super = this._super;
+
+ this.database.transaction(function (database)
+ {
+ database.executeSql('SELECT k,v FROM jstore', [], function (database, result)
+ {
+ var rows = result.rows,
+ index = 0,
+ row;
+
+ for (; index < rows.length; ++index)
+ {
+ row = rows.item(index);
+ self.data[row.k] = prepareForRevival(row.v);
+ }
+
+ _super.apply(self);
+ });
+ });
+ },
+
+ //------------------------------
+ // Internal methods
+ //------------------------------
+
+ __set: function (key, value)
+ {
+ this.database.transaction(function (database)
+ {
+ database.executeSql('INSERT OR REPLACE INTO jstore(k, v) VALUES (?, ?)', [key, prepareForStorage(value)]);
+ });
+ },
+
+ __remove: function (key)
+ {
+ this.database.transaction(function (database)
+ {
+ database.executeSql('DELETE FROM jstore WHERE k = ?', [key]);
+ });
+ }
+ },
+
+ function ()
+ {
+ return window.openDatabase !== undefined;
+ });
+
+ //------------------------------
+ // Flash
+ //------------------------------
+
+ define(FLAVOR_FLASH,
+ {
+ //------------------------------
+ // Properties
+ //------------------------------
+
+ limit: -1,
+
+ //------------------------------
+ // Constructor
+ //------------------------------
+
+ init: function (project, name)
+ {
+ var self = this;
+
+ _.bind('flash-ready', function ()
+ {
+ self.__flashReadyListener();
+ });
+
+ this._super(project, name);
+ },
+
+ //------------------------------
+ // Methods
+ //------------------------------
+
+ updateCache: function (enable)
+ {
+ /**
+ * The default call to updateCache passes no variable, so we can short circuit the
+ * ready state until we explictly call this after flash ready.
+ */
+ if (enable === true)
+ {
+ var key,
+ dataset = this.database.jstore_get_all();
+
+ for (key in dataset)
+ {
+ if (dataset.hasOwnProperty(key))
+ {
+ this.data[key] = prepareForRevival(this.database.jstore_get(key));
+ }
+ }
+
+ this._super();
+ }
+ },
+
+ //------------------------------
+ // Internal methods
+ //------------------------------
+
+ __set: function (key, value)
+ {
+ if (!this.database.jstore_set(key, prepareForStorage(value)))
+ {
+ _.trigger('jstore-error', ['JSTORE_STORAGE_FAILURE', this.jri, 'Flash Exception']);
+ }
+ },
+
+ __remove: function (key)
+ {
+ this.database.jstore_remove(key);
+ },
+
+ /**
+ * Triggered whenever flash is ready.
+ */
+ __flashReadyListener: function ()
+ {
+ var iFrame = $('#jStoreFlashFrame')[0],
+ frameDocument;
+
+ // MSIE
+ if (iFrame.Document !== undefined && typecheck(iFrame.Document.jStoreFlash.jstore_get, 'Function'))
+ {
+ this.database = iFrame.Document.jStoreFlash;
+ }
+
+ // Real Browsers
+ else if (iFrame.contentWindow && iFrame.contentWindow.document)
+ {
+ frameDocument = $(iFrame.contentWindow.document);
+
+ // Webkit
+ if (typecheck($('object', frameDocument)[0].jstore_get, 'Function'))
+ {
+ this.database = $('object', frameDocument)[0];
+ }
+
+ // Gecko
+ else if (typecheck($('embed', frameDocument)[0].jstore_get, 'Function'))
+ {
+ this.database = $('embed', frameDocument)[0];
+ }
+ }
+
+ if (this.database === undefined)
+ {
+ throw 'JSTORE_FLASH_REFERENCE_ISSUE';
+ }
+ else
+ {
+ this.updateCache(true);
+ }
+ }
+ },
+
+ function ()
+ {
+ return hasFlashVersion('9.0.0');
+ });
+
+ //------------------------------
+ // Gears
+ //------------------------------
+
+ define(FLAVOR_GEARS,
+ {
+ //------------------------------
+ // Properties
+ //------------------------------
+
+ limit: -1,
+
+ //------------------------------
+ // Constructor
+ //------------------------------
+
+ init: function (project, name)
+ {
+ this.database = google.gears.factory.create('beta.database');
+ this.database.open('jstore-' + project);
+ this.database.execute('CREATE TABLE IF NOT EXISTS jstore (k TEXT UNIQUE NOT NULL PRIMARY KEY, v TEXT NOT NULL)');
+
+ this._super(project, name);
+ },
+
+ //------------------------------
+ // Methods
+ //------------------------------
+
+ updateCache: function ()
+ {
+ var result = this.database.execute('SELECT k,v FROM jstore');
+
+ while (result.isValidRow())
+ {
+ this.data[result.field(0)] = prepareForRevival(result.field(1));
+ result.next();
+ }
+
+ result.close();
+
+ this._super();
+ },
+
+ //------------------------------
+ // Internal methods
+ //------------------------------
+
+ __set: function (key, value)
+ {
+ this.database.execute('BEGIN');
+ this.database.execute('INSERT OR REPLACE INTO jstore(k, v) VALUES (?, ?)', [key, prepareForStorage(value)]);
+ this.database.execute('COMMIT');
+ },
+
+ __remove: function (key)
+ {
+ this.database.execute('BEGIN');
+ this.database.execute('DELETE FROM jstore WHERE k = ?', [key]);
+ this.database.execute('COMMIT');
+ }
+ },
+
+ function ()
+ {
+ return window.google !== undefined && window.google.gears !== undefined;
+ });
+
+ //------------------------------
+ // MSIE
+ //------------------------------
+
+ define(FLAVOR_MSIE,
+ {
+ //------------------------------
+ // Properties
+ //------------------------------
+
+ limit: parseInt(1e4, 16),
+
+ //------------------------------
+ // Constructor
+ //------------------------------
+
+ init: function (project, name)
+ {
+ this.database = $('<div style="display:none;behavior:url(\'#default#userData\')" id="jstore-' + project + '"></div>')
+ .appendTo(document.body).get(0);
+
+ this._super(project, name);
+ },
+
+ //------------------------------
+ // Methods
+ //------------------------------
+
+ updateCache: function ()
+ {
+ this.database.load(this.project);
+
+ var node = document.getElementById('jstore-' + this.project),
+ xmlDoc = node.XMLDocument,
+ root,
+ index = 0;
+
+ if (xmlDoc && xmlDoc.documentElement && xmlDoc.documentElement.attributes)
+ {
+ root = xmlDoc.documentElement;
+
+ for (; index < root.attributes.length; ++index)
+ {
+ this.data[root.attributes.item(index).nodeName] = prepareForRevival(root.attributes.item(index).nodeValue);
+ }
+ }
+
+ this._super();
+ },
+
+ //------------------------------
+ // Internal methods
+ //------------------------------
+
+ __set: function (key, value)
+ {
+ this.database.setAttribute(key, prepareForStorage(value));
+ this.database.save(this.project);
+ },
+
+ __remove: function (key)
+ {
+ this.database.removeAttribute(key);
+ this.database.save(this.project);
+ }
+ },
+
+ function ()
+ {
+ return window.ActiveXObject !== undefined;
+ });
+
+}(jQuery, window));
diff -r a9402fc7ce1b -r 5536d57237a3 static/scripts/json2.js
--- a/static/scripts/json2.js Fri Apr 09 13:02:15 2010 -0400
+++ b/static/scripts/json2.js Fri Apr 09 18:09:54 2010 -0400
@@ -1,6 +1,6 @@
/*
http://www.JSON.org/json2.js
- 2009-06-29
+ 2010-03-20
Public Domain.
@@ -8,6 +8,14 @@
See http://www.JSON.org/js.html
+
+ This code should be minified before deployment.
+ See http://javascript.crockford.com/jsmin.html
+
+ USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO
+ NOT CONTROL.
+
+
This file creates a global JSON object containing two methods: stringify
and parse.
@@ -33,7 +41,7 @@
value represented by the name/value pair that should be serialized,
or undefined if nothing should be serialized. The toJSON method
will be passed the key associated with the value, and this will be
- bound to the object holding the key.
+ bound to the value
For example, this would serialize Dates as ISO strings.
@@ -136,15 +144,9 @@
This is a reference implementation. You are free to copy, modify, or
redistribute.
-
- This code should be minified before deployment.
- See http://javascript.crockford.com/jsmin.html
-
- USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO
- NOT CONTROL.
*/
-/*jslint evil: true */
+/*jslint evil: true, strict: false */
/*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply,
call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours,
@@ -153,10 +155,13 @@
test, toJSON, toString, valueOf
*/
+
// Create a JSON object only if one does not already exist. We create the
// methods in a closure to avoid creating global variables.
-var JSON = JSON || {};
+if (!this.JSON) {
+ this.JSON = {};
+}
(function () {
@@ -428,6 +433,7 @@
// Unicode characters with escape sequences. JavaScript handles many characters
// incorrectly, either silently deleting them, or treating them as line endings.
+ text = String(text);
cx.lastIndex = 0;
if (cx.test(text)) {
text = text.replace(cx, function (a) {
diff -r a9402fc7ce1b -r 5536d57237a3 static/scripts/packed/class.js
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/static/scripts/packed/class.js Fri Apr 09 18:09:54 2010 -0400
@@ -0,0 +1,7 @@
+/*
+ * Class definition
+ *
+ * Copyright (c) 2008 John Resig (http://ejohn.org/blog/simple-javascript-inheritance/)
+ * Inspired by base2 and Prototype
+ */
+"use strict";(function(){var a=false,b=/xyz/.test(function(){xyz})?/\b_super\b/:/.*/;this.Class=function(){};Class.extend=function(g){var f=this.prototype;a=true;var e=new this();a=false;for(var d in g){e[d]=(typeof g[d]==="function"&&typeof f[d]==="function"&&b.test(g[d])?(function(h,i){return function(){var k=this._super;this._super=f[h];var j=i.apply(this,arguments);this._super=k;return j}}(d,g[d])):g[d])}function c(){if(!a&&this.init){this.init.apply(this,arguments)}}c.prototype=e;c.constructor=c;c.extend=arguments.callee;return c}}());
\ No newline at end of file
diff -r a9402fc7ce1b -r 5536d57237a3 static/scripts/packed/galaxy.base.js
--- a/static/scripts/packed/galaxy.base.js Fri Apr 09 13:02:15 2010 -0400
+++ b/static/scripts/packed/galaxy.base.js Fri Apr 09 18:09:54 2010 -0400
@@ -1,1 +1,1 @@
-$(document).ready(function(){replace_big_select_inputs()});$.fn.makeAbsolute=function(a){return this.each(function(){var b=$(this);var c=b.position();b.css({position:"absolute",marginLeft:0,marginTop:0,top:c.top,left:c.left,right:$(window).width()-(c.left+b.width())});if(a){b.remove().appendTo("body")}})};function ensure_popup_helper(){if($("#popup-helper").length===0){$("<div id='popup-helper'/>").css({background:"white",opacity:0,zIndex:15000,position:"absolute",top:0,left:0,width:"100%",height:"100%"}).appendTo("body").hide()}}function attach_popupmenu(b,d){var a=function(){d.unbind().hide();$("#popup-helper").unbind("click.popupmenu").hide()};var c=function(g){$("#popup-helper").bind("click.popupmenu",a).show();d.click(a).css({left:0,top:-1000}).show();var f=g.pageX-d.width()/2;f=Math.min(f,$(document).scrollLeft()+$(window).width()-$(d).width()-20);f=Math.max(f,$(document).scrollLeft()+20);d.css({top:g.pageY-5,left:f});return false};$(b).click(c)}function make_popupmen!
u(c,b){ensure_popup_helper();var a=$("<ul id='"+c.attr("id")+"-menu'></ul>");$.each(b,function(f,e){if(e){$("<li/>").html(f).click(e).appendTo(a)}else{$("<li class='head'/>").html(f).appendTo(a)}});var d=$("<div class='popmenu-wrapper'>");d.append(a).append("<div class='overlay-border'>").css("position","absolute").appendTo("body").hide();attach_popupmenu(c,d)}function make_popup_menus(){jQuery("div[popupmenu]").each(function(){var c={};$(this).find("a").each(function(){var b=$(this).attr("confirm"),d=$(this).attr("href"),e=$(this).attr("target");c[$(this).text()]=function(){if(!b||confirm(b)){var g=window;if(e=="_parent"){g=window.parent}else{if(e=="_top"){g=window.top}}g.location=d}}});var a=$("#"+$(this).attr("popupmenu"));make_popupmenu(a,c);$(this).remove();a.addClass("popup").show()})}function array_length(b){if(b.length){return b.length}var c=0;for(var a in b){c++}return c}function replace_big_select_inputs(){$("select[name=dbkey]").each(function(){var a=$(this);if(a!
.find("option").length<20){return}var b=a.attr("value");var c=$("<inpu
t type='text' class='text-and-autocomplete-select'></input>");c.attr("size",40);c.attr("name",a.attr("name"));c.click(function(){var g=$(this).attr("value");$(this).attr("value","Loading...");$(this).showAllInCache();$(this).attr("value",g);$(this).select()});var f=[];var e={};a.children("option").each(function(){var h=$(this).text();var g=$(this).attr("value");if(g=="?"){return}f.push(h);e[h]=g;e[g]=g;if(g==b){c.attr("value",h)}});if(c.attr("value")==""){c.attr("value","Click to Search or Select")}var d={selectFirst:false,autoFill:false,mustMatch:false,matchContains:true,max:1000,minChars:0,hideForLessThanMinChars:false};c.autocomplete(f,d);a.replaceWith(c);c.parents("form").submit(function(){var h=c.attr("value");var g=e[h];if(g!==null&&g!==undefined){c.attr("value",g)}else{if(b!=""){c.attr("value",b)}else{c.attr("value","?")}}})})}function async_save_text(d,f,e,a,c,h,i,g,b){if(c===undefined){c=30}if(i===undefined){i=4}$("#"+d).live("click",function(){if($("#renaming-activ!
e").length>0){return}var l=$("#"+f),k=l.text(),j;if(h){j=$("<textarea></textarea>").attr({rows:i,cols:c}).text(k)}else{j=$("<input type='text'></input>").attr({value:k,size:c})}j.attr("id","renaming-active");j.blur(function(){$(this).remove();l.show();if(b){b(j)}});j.keyup(function(n){if(n.keyCode===27){$(this).trigger("blur")}else{if(n.keyCode===13){var m={};m[a]=$(this).val();$(this).trigger("blur");$.ajax({url:e,data:m,error:function(){alert("Text editing for elt "+f+" failed")},success:function(o){l.text(o);if(b){b(j)}}})}}});if(g){g(j)}l.hide();j.insertAfter(l);j.focus();j.select();return})}$(document).ready(function(){$("a[confirm]").click(function(){return confirm($(this).attr("confirm"))});if($.fn.tipsy){$(".tooltip").tipsy({gravity:"s"})}make_popup_menus()});
\ No newline at end of file
+$(document).ready(function(){replace_big_select_inputs()});$.fn.makeAbsolute=function(a){return this.each(function(){var b=$(this);var c=b.position();b.css({position:"absolute",marginLeft:0,marginTop:0,top:c.top,left:c.left,right:$(window).width()-(c.left+b.width())});if(a){b.remove().appendTo("body")}})};function ensure_popup_helper(){if($("#popup-helper").length===0){$("<div id='popup-helper'/>").css({background:"white",opacity:0,zIndex:15000,position:"absolute",top:0,left:0,width:"100%",height:"100%"}).appendTo("body").hide()}}function attach_popupmenu(b,d){var a=function(){d.unbind().hide();$("#popup-helper").unbind("click.popupmenu").hide()};var c=function(g){$("#popup-helper").bind("click.popupmenu",a).show();d.click(a).css({left:0,top:-1000}).show();var f=g.pageX-d.width()/2;f=Math.min(f,$(document).scrollLeft()+$(window).width()-$(d).width()-20);f=Math.max(f,$(document).scrollLeft()+20);d.css({top:g.pageY-5,left:f});return false};$(b).click(c)}function make_popupmen!
u(c,b){ensure_popup_helper();var a=$("<ul id='"+c.attr("id")+"-menu'></ul>");$.each(b,function(f,e){if(e){$("<li/>").html(f).click(e).appendTo(a)}else{$("<li class='head'/>").html(f).appendTo(a)}});var d=$("<div class='popmenu-wrapper'>");d.append(a).append("<div class='overlay-border'>").css("position","absolute").appendTo("body").hide();attach_popupmenu(c,d)}function make_popup_menus(){jQuery("div[popupmenu]").each(function(){var c={};$(this).find("a").each(function(){var b=$(this).attr("confirm"),d=$(this).attr("href"),e=$(this).attr("target");c[$(this).text()]=function(){if(!b||confirm(b)){var g=window;if(e=="_parent"){g=window.parent}else{if(e=="_top"){g=window.top}}g.location=d}}});var a=$("#"+$(this).attr("popupmenu"));make_popupmenu(a,c);$(this).remove();a.addClass("popup").show()})}function array_length(b){if(b.length){return b.length}var c=0;for(var a in b){c++}return c}function replace_big_select_inputs(){$("select[name=dbkey]").each(function(){var a=$(this);if(a!
.find("option").length<20){return}var b=a.attr("value");var c=$("<inpu
t type='text' class='text-and-autocomplete-select'></input>");c.attr("size",40);c.attr("name",a.attr("name"));c.click(function(){var g=$(this).attr("value");$(this).attr("value","Loading...");$(this).showAllInCache();$(this).attr("value",g);$(this).select()});var f=[];var e={};a.children("option").each(function(){var h=$(this).text();var g=$(this).attr("value");if(g=="?"){return}f.push(h);e[h]=g;e[g]=g;if(g==b){c.attr("value",h)}});if(c.attr("value")==""){c.attr("value","Click to Search or Select")}var d={selectFirst:false,autoFill:false,mustMatch:false,matchContains:true,max:1000,minChars:0,hideForLessThanMinChars:false};c.autocomplete(f,d);a.replaceWith(c);c.parents("form").submit(function(){var h=c.attr("value");var g=e[h];if(g!==null&&g!==undefined){c.attr("value",g)}else{if(b!=""){c.attr("value",b)}else{c.attr("value","?")}}})})}function async_save_text(d,f,e,a,c,h,i,g,b){if(c===undefined){c=30}if(i===undefined){i=4}$("#"+d).live("click",function(){if($("#renaming-activ!
e").length>0){return}var l=$("#"+f),k=l.text(),j;if(h){j=$("<textarea></textarea>").attr({rows:i,cols:c}).text(k)}else{j=$("<input type='text'></input>").attr({value:k,size:c})}j.attr("id","renaming-active");j.blur(function(){$(this).remove();l.show();if(b){b(j)}});j.keyup(function(n){if(n.keyCode===27){$(this).trigger("blur")}else{if(n.keyCode===13){var m={};m[a]=$(this).val();$(this).trigger("blur");$.ajax({url:e,data:m,error:function(){alert("Text editing for elt "+f+" failed")},success:function(o){l.text(o);if(b){b(j)}}})}}});if(g){g(j)}l.hide();j.insertAfter(l);j.focus();j.select();return})}function init_history_items(c,a){var b=function(){try{var d=$.jStore.store("history_expand_state");if(d){for(var f in d){$("#"+f+" div.historyItemBody").show()}}}catch(e){$.jStore.remove("history_expand_state")}if($.browser.mozilla){$("div.historyItemBody").each(function(){if(!$(this).is(":visible")){$(this).find("pre.peek").css("overflow","hidden")}})}c.each(function(){var i=this.i!
d;var g=$(this).children("div.historyItemBody");var h=g.find("pre.peek
");$(this).children(".historyItemTitleBar").find(".historyItemTitle").wrap("<a href='#'></a>").click(function(){if(g.is(":visible")){if($.browser.mozilla){h.css("overflow","hidden")}g.slideUp("fast");if(!a){var j=$.jStore.store("history_expand_state");if(j){delete j[i];$.jStore.store("history_expand_state",j)}}}else{g.slideDown("fast",function(){if($.browser.mozilla){h.css("overflow","auto")}});if(!a){var j=$.jStore.store("history_expand_state");if(j===undefined){j={}}j[i]=true;$.jStore.store("history_expand_state",j)}}return false})});$("#top-links > a.toggle").click(function(){var g=$.jStore.store("history_expand_state");if(g===undefined){g={}}$("div.historyItemBody:visible").each(function(){if($.browser.mozilla){$(this).find("pre.peek").css("overflow","hidden")}$(this).slideUp("fast");if(g){delete g[$(this).parent().attr("id")]}});$.jStore.store("history_expand_state",g)}).show()};if(a){b()}else{$.jStore.init("galaxy");$.jStore.engineReady(function(){b()})}}$(document).re!
ady(function(){$("a[confirm]").click(function(){return confirm($(this).attr("confirm"))});if($.fn.tipsy){$(".tooltip").tipsy({gravity:"s"})}make_popup_menus()});
\ No newline at end of file
diff -r a9402fc7ce1b -r 5536d57237a3 static/scripts/packed/jquery.jstore-all.js
--- a/static/scripts/packed/jquery.jstore-all.js Fri Apr 09 13:02:15 2010 -0400
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-(function(){var a=false,b=/xyz/.test(function(){xyz})?/\b_super\b/:/.*/;this.Class=function(){};Class.extend=function(g){var f=this.prototype;a=true;var e=new this();a=false;for(var d in g){e[d]=typeof g[d]=="function"&&typeof f[d]=="function"&&b.test(g[d])?(function(h,i){return function(){var k=this._super;this._super=f[h];var j=i.apply(this,arguments);this._super=k;return j}})(d,g[d]):g[d]}function c(){if(!a&&this.init){this.init.apply(this,arguments)}}c.prototype=e;c.constructor=c;c.extend=arguments.callee;return c}})();(function(a){this.jStoreDelegate=Class.extend({init:function(b){this.parent=b;this.callbacks={}},bind:function(b,c){if(!a.isFunction(c)){return this}if(!this.callbacks[b]){this.callbacks[b]=[]}this.callbacks[b].push(c);return this},trigger:function(){var d=this.parent,c=[].slice.call(arguments),e=c.shift(),b=this.callbacks[e];if(!b){return false}a.each(b,function(){this.apply(d,c)});return this}})})(jQuery);(function(a){a.jStore={};a.extend(a.jStore,{Engi!
neOrder:[],Availability:{},Engines:{},Instances:{},CurrentEngine:null,defaults:{project:null,engine:null,autoload:true,flash:"jStore.Flash.html"},isReady:false,isFlashReady:false,delegate:new jStoreDelegate(a.jStore).bind("jStore-ready",function(b){a.jStore.isReady=true;if(a.jStore.defaults.autoload){b.connect()}}).bind("flash-ready",function(){a.jStore.isFlashReady=true})});a.jStore.ready=function(b){if(a.jStore.isReady){b.apply(a.jStore,[a.jStore.CurrentEngine])}else{a.jStore.delegate.bind("jStore-ready",b)}};a.jStore.fail=function(b){a.jStore.delegate.bind("jStore-failure",b)};a.jStore.flashReady=function(b){if(a.jStore.isFlashReady){b.apply(a.jStore,[a.jStore.CurrentEngine])}else{a.jStore.delegate.bind("flash-ready",b)}};a.jStore.use=function(d,g,c){g=g||a.jStore.defaults.project||location.hostname.replace(/\./g,"-")||"unknown";var f=a.jStore.Engines[d.toLowerCase()]||null,b=(c?c+".":"")+g+"."+d;if(!f){throw"JSTORE_ENGINE_UNDEFINED"}f=new f(g,b);if(a.jStore.Instances[b]!
){throw"JSTORE_JRI_CONFLICT"}if(f.isAvailable()){a.jStore.Instances[b]
=f;if(!a.jStore.CurrentEngine){a.jStore.CurrentEngine=f}a.jStore.delegate.trigger("jStore-ready",f)}else{if(!f.autoload){throw"JSTORE_ENGINE_UNAVILABLE"}else{f.included(function(){if(this.isAvailable()){a.jStore.Instances[b]=this;if(!a.jStore.CurrentEngine){a.jStore.CurrentEngine=this}a.jStore.delegate.trigger("jStore-ready",this)}else{a.jStore.delegate.trigger("jStore-failure",this)}}).include()}}};a.jStore.setCurrentEngine=function(b){if(!a.jStore.Instances.length){return a.jStore.FindEngine()}if(!b&&a.jStore.Instances.length>=1){a.jStore.delegate.trigger("jStore-ready",a.jStore.Instances[0]);return a.jStore.CurrentEngine=a.jStore.Instances[0]}if(b&&a.jStore.Instances[b]){a.jStore.delegate.trigger("jStore-ready",a.jStore.Instances[b]);return a.jStore.CurrentEngine=a.jStore.Instances[b]}throw"JSTORE_JRI_NO_MATCH"};a.jStore.FindEngine=function(){a.each(a.jStore.EngineOrder,function(b){if(a.jStore.Availability[this]()){a.jStore.use(this,a.jStore.defaults.project,"default");re!
turn false}})};a.jStore.store=function(b,c){if(!a.jStore.CurrentEngine){return false}if(!c){return a.jStore.CurrentEngine.get(b)}return a.jStore.CurrentEngine.set(b,c)};a.jStore.remove=function(b){if(!a.jStore.CurrentEngine){return false}return a.jStore.CurrentEngine.rem(b)};a.fn.store=function(c,d){if(!a.jStore.CurrentEngine){return this}var b=a.jStore.store(c,d);return !d?b:this};a.fn.removeStore=function(b){a.jStore.remove(b);return this};a.jStore.load=function(){if(a.jStore.defaults.engine){return a.jStore.use(a.jStore.defaults.engine,a.jStore.defaults.project,"default")}try{a.jStore.FindEngine()}catch(b){}}})(jQuery);(function(a){this.StorageEngine=Class.extend({init:function(c,b){this.project=c;this.jri=b;this.data={};this.limit=-1;this.includes=[];this.delegate=new jStoreDelegate(this).bind("engine-ready",function(){this.isReady=true}).bind("engine-included",function(){this.hasIncluded=true});this.autoload=false;this.isReady=false;this.hasIncluded=false},include:func!
tion(){var b=this,d=this.includes.length,c=0;a.each(this.includes,func
tion(){a.ajax({type:"get",url:this,dataType:"script",cache:true,success:function(){c++;if(c==d){b.delegate.trigger("engine-included")}}})})},isAvailable:function(){return false},ready:function(b){if(this.isReady){b.apply(this)}else{this.delegate.bind("engine-ready",b)}return this},included:function(b){if(this.hasIncluded){b.apply(this)}else{this.delegate.bind("engine-included",b)}return this},get:function(b){return this.data[b]||null},set:function(b,c){this.data[b]=c;return c},rem:function(b){var c=this.data[b];this.data[b]=null;return c}})})(jQuery);(function(c){var b=c.jStore.Availability.session=function(){return !!window.sessionStorage},a=c.jStore.Availability.local=function(){return !!(window.localStorage||window.globalStorage)};this.jStoreDom=StorageEngine.extend({init:function(e,d){this._super(e,d);this.type="DOM";this.limit=5*1024*1024},connect:function(){this.delegate.trigger("engine-ready")},get:function(e){var d=this.db.getItem(e);return d&&d.value?d.value:d},set:!
function(d,e){this.db.setItem(d,e);return e},rem:function(e){var d=this.get(e);this.db.removeItem(e);return d}});this.jStoreLocal=jStoreDom.extend({connect:function(){this.db=!window.globalStorage?window.localStorage:window.globalStorage[location.hostname];this._super()},isAvailable:a});this.jStoreSession=jStoreDom.extend({connect:function(){this.db=sessionStorage;this._super()},isAvailable:b});c.jStore.Engines.local=jStoreLocal;c.jStore.Engines.session=jStoreSession;c.jStore.EngineOrder[1]="local"})(jQuery);(function(b){var a=b.jStore.Availability.flash=function(){return !!(b.jStore.hasFlash("8.0.0"))};this.jStoreFlash=StorageEngine.extend({init:function(e,d){this._super(e,d);this.type="Flash";var c=this;b.jStore.flashReady(function(){c.flashReady()})},connect:function(){var c="jstore-flash-embed-"+this.project;b(document.body).append('<iframe style="height:1px;width:1px;position:absolute;left:0;top:0;margin-left:-100px;" id="jStoreFlashFrame" src="'+b.jStore.defaults.flas!
h+'"></iframe>')},flashReady:function(f){var c=b("#jStoreFlashFrame")[
0];if(c.Document&&b.isFunction(c.Document.jStoreFlash.f_get_cookie)){this.db=c.Document.jStoreFlash}else{if(c.contentWindow&&c.contentWindow.document){var d=c.contentWindow.document;if(b.isFunction(b("object",b(d))[0].f_get_cookie)){this.db=b("object",b(d))[0]}else{if(b.isFunction(b("embed",b(d))[0].f_get_cookie)){this.db=b("embed",b(d))[0]}}}}if(this.db){this.delegate.trigger("engine-ready")}},isAvailable:a,get:function(d){var c=this.db.f_get_cookie(d);return c=="null"?null:c},set:function(c,d){this.db.f_set_cookie(c,d);return d},rem:function(c){var d=this.get(c);this.db.f_delete_cookie(c);return d}});b.jStore.Engines.flash=jStoreFlash;b.jStore.EngineOrder[2]="flash";b.jStore.hasFlash=function(c){var e=b.jStore.flashVersion().match(/\d+/g),f=c.match(/\d+/g);for(var d=0;d<3;d++){e[d]=parseInt(e[d]||0);f[d]=parseInt(f[d]||0);if(e[d]<f[d]){return false}if(e[d]>f[d]){return true}}return true};b.jStore.flashVersion=function(){try{try{var c=new ActiveXObject("ShockwaveFlash.Shock!
waveFlash.6");try{c.AllowScriptAccess="always"}catch(d){return"6,0,0"}}catch(d){}return new ActiveXObject("ShockwaveFlash.ShockwaveFlash").GetVariable("$version").replace(/\D+/g,",").match(/^,?(.+),?$/)[1]}catch(d){try{if(navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin){return(navigator.plugins["Shockwave Flash 2.0"]||navigator.plugins["Shockwave Flash"]).description.replace(/\D+/g,",").match(/^,?(.+),?$/)[1]}}catch(d){}}return"0,0,0"}})(jQuery);function flash_ready(){$.jStore.delegate.trigger("flash-ready")}(function(b){var a=b.jStore.Availability.gears=function(){return !!(window.google&&window.google.gears)};this.jStoreGears=StorageEngine.extend({init:function(d,c){this._super(d,c);this.type="Google Gears";this.includes.push("http://code.google.com/apis/gears/gears_init.js");this.autoload=true},connect:function(){var c=this.db=google.gears.factory.create("beta.database");c.open("jstore-"+this.project);c.execute("CREATE TABLE IF NOT EXISTS jstore (k TEX!
T UNIQUE NOT NULL PRIMARY KEY, v TEXT NOT NULL)");this.updateCache()},
updateCache:function(){var c=this.db.execute("SELECT k,v FROM jstore");while(c.isValidRow()){this.data[c.field(0)]=c.field(1);c.next()}c.close();this.delegate.trigger("engine-ready")},isAvailable:a,set:function(d,e){var c=this.db;c.execute("BEGIN");c.execute("INSERT OR REPLACE INTO jstore(k, v) VALUES (?, ?)",[d,e]);c.execute("COMMIT");return this._super(d,e)},rem:function(d){var c=this.db;c.execute("BEGIN");c.execute("DELETE FROM jstore WHERE k = ?",[d]);c.execute("COMMIT");return this._super(d)}});b.jStore.Engines.gears=jStoreGears;b.jStore.EngineOrder[3]="gears"})(jQuery);(function(b){var a=b.jStore.Availability.html5=function(){return !!window.openDatabase};this.jStoreHtml5=StorageEngine.extend({init:function(d,c){this._super(d,c);this.type="HTML5";this.limit=1024*200},connect:function(){var c=this.db=openDatabase("jstore-"+this.project,"1.0",this.project,this.limit);if(!c){throw"JSTORE_ENGINE_HTML5_NODB"}c.transaction(function(d){d.executeSql("CREATE TABLE IF NOT EXISTS!
jstore (k TEXT UNIQUE NOT NULL PRIMARY KEY, v TEXT NOT NULL)")});this.updateCache()},updateCache:function(){var c=this;this.db.transaction(function(d){d.executeSql("SELECT k,v FROM jstore",[],function(f,e){var h=e.rows,g=0,j;for(;g<h.length;++g){j=h.item(g);c.data[j.k]=j.v}c.delegate.trigger("engine-ready")})})},isAvailable:a,set:function(c,d){this.db.transaction(function(e){e.executeSql("INSERT OR REPLACE INTO jstore(k, v) VALUES (?, ?)",[c,d])});return this._super(c,d)},rem:function(c){this.db.transaction(function(d){d.executeSql("DELETE FROM jstore WHERE k = ?",[c])});return this._super(c)}});b.jStore.Engines.html5=jStoreHtml5;b.jStore.EngineOrder[0]="html5"})(jQuery);(function(b){var a=b.jStore.Availability.ie=function(){return !!window.ActiveXObject};this.jStoreIE=StorageEngine.extend({init:function(d,c){this._super(d,c);this.type="IE";this.limit=64*1024},connect:function(){this.db=b('<div style="display:none;behavior:url(\'#default#userData\')" id="jstore-'+this.proj!
ect+'"></div>').appendTo(document.body).get(0);this.delegate.trigger("
engine-ready")},isAvailable:a,get:function(c){this.db.load(this.project);return this.db.getAttribute(c)},set:function(c,d){this.db.setAttribute(c,d);this.db.save(this.project);return d},rem:function(c){var d=this.get(c);this.db.removeAttribute(c);this.db.save(this.project);return d}});b.jStore.Engines.ie=jStoreIE;b.jStore.EngineOrder[4]="ie"})(jQuery);
\ No newline at end of file
diff -r a9402fc7ce1b -r 5536d57237a3 static/scripts/packed/jquery.jstore.js
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/static/scripts/packed/jquery.jstore.js Fri Apr 09 18:09:54 2010 -0400
@@ -0,0 +1,17 @@
+/*
+ * jStore 2.0 - Persistent Client Side Storage
+ *
+ * Copyright (c) 2010 Eric Garside (http://eric.garside.name/)
+ * Dual licensed under:
+ * MIT: http://www.opensource.org/licenses/mit-license.php
+ * GPLv3: http://www.opensource.org/licenses/gpl-3.0.html
+ *
+ * ---------------------------
+ *
+ * jStore Flash Storage Component
+ *
+ * Copyright (c) 2006 Jeff Lerman (jeff(a)blip.tv)
+ * Licensed under the Creative Commons Attribution 3.0 United States License:
+ * http://creativecommons.org/licenses/by/3.0/us
+ */
+"use strict";(function(i,n){var h="JSTORE_ENGINE_UNSTABLE",t="JSTORE_UNKNOWN_ENGINE_REQUESTED",r="JSTORE_ENGINE_NAMESPACE_COLLISION",j="JSTORE_RESOURCE_NAMESPACE_COLLISION",m="JSTORE_ENGINE_UNAVAILABLE",o="JSTORE_INVALID_FLAVOR",f=(function(){try{return new RegExp('^("(\\\\.|[^"\\\\\\n\\r])*?"|[,:{}\\[\\]0-9.\\-+Eaeflnr-u \\n\\r\\t])+?$')}catch(I){return(/^(true|false|null|\[.*\]|\{.*\}|".*"|\d+|\d+\.\d+)$/)}}()),b="jstore-html5-local",y="jstore-html5-sql",F="jstore-flash",G="jstore-google-gears",A="jstore-msie",u,E={},D={},C={},c=false,d={},q={project:undefined,flash:"jStore.Flash.html",json:"browser.json.js"},l;function z(I){switch(I){case b:case y:case F:case G:case A:return true;default:return false}}function g(I,J){return !I?false:I.constructor.toString().match(new RegExp(J+"\\(\\)","i"))!==null}function s(K,I,J){if(g(K,"Function")){return K.apply(I||E,g(J,"Array")?J:[J])}}function p(J,I){i.ajax({url:J,complete:I||i.noop(),type:"GET",dataType:"script",cache:false})}fun!
ction x(I){if(I===undefined){return""}if(g(I,"Object")||g(I,"Array")||g(I,"Function")){return JSON.stringify(I)}return I}function k(I){return f.test(I)?JSON.parse(I):I}function w(I){return I.replace(/^\s+|\s+$/g,"")}function e(I,J,K){if(!z(I)){throw o}if(K[I]!==undefined){throw r}if(s(K)===true){E.available[I]=true;J.flavor=I;D[I]=u.extend(J)}else{E.available[I]=false;E.enginePriority=i.map(E.enginePriority,function(L){if(L===I){return null}else{return L}})}}function v(){if(E.isReady){return}if((c&&E.isFlashReady)||!c){E.isReady=true;E.trigger("jstore-ready",[C[l]])}}function a(){E.create(E.enginePriority[0],undefined,"best-fit")}function H(){try{var J=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");try{J.AllowScriptAccess="always"}catch(L){return"6,0,0"}return new ActiveXObject("ShockwaveFlash.ShockwaveFlash").GetVariable("$version").replace(/\D+/g,",").match(/^,?(.+),?$/)[1]}catch(K){try{if(navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin){return(na!
vigator.plugins["Shockwave Flash 2.0"]||navigator.plugins["Shockwave F
lash"]).description.replace(/\D+/g,",").match(/^,?(.+),?$/)[1]}}catch(I){}}return"0,0,0"}function B(I){var N=H().match(/\d+/g),L=I.match(/\d+/g),J=0,K,M;for(;J<3;J++){K=parseInt(N[J],10);M=parseInt(L[J],10);if(K<M){return false}else{if(K>M){return true}}}return true}i.extend(E,{enginePriority:[b,y,F,A],available:{},isReady:false,isFlashReady:false,flavors:{local:b,sql:y,flash:F,gears:G,msie:A},init:function(J,K,I){i.extend(q,{project:J},K);i(function(){if(n.JSON===undefined){p(q.json)}if(I!==undefined){E.create(I,J,"default")}else{a()}});return E},create:function(I,M,J){M=M||q.project||location.hostname.replace(/\./g,"-")||"unknown";if(!z(I)){throw o}if(D[I]===undefined){throw m}var L=(J!==undefined?J+".":"")+M+"."+I,K;if(C[L]!==undefined){throw j}K=C[L]=new D[I](M,L);K.ready(function(){E.trigger("jstore-engine-ready",[K])});if(I===F&&!E.isFlashReady){if(l===undefined){c=true}n.jstore_ready=function(){E.isFlashReady=true;E.trigger("flash-ready");if(l===undefined){v()}n.flash!
_ready=undefined};n.jstore_error=function(N){E.trigger("jstore-error",["JSTORE_FLASH_EXCEPTION",null,N])};i('<iframe style="height:1px;width:1px;position:absolute;left:0;top:0;margin-left:-100px;" id="jStoreFlashFrame" src="'+q.flash+'"></iframe>').appendTo("body")}else{if(l===undefined){l=L;v()}}return K},engine:function(I){return C[I]},activeEngine:function(I){if(I!==undefined){if(C[I]===undefined){throw t}else{l=I}}return C[l]},bind:function(J,K,I){I=I||"jstore";if(d[I]===undefined){d[I]={}}if(d[I][J]===undefined){d[I][J]=[K]}else{d[I][J].push(K)}return E},trigger:function(K,J,I){I=I||"jstore";if(d[I]!==undefined){if(d[I][K]!==undefined){i.each(d[I][K],function(){s(this,E,J)})}}return E},error:function(I){E.bind("jstore-error",I)},ready:function(I){if(E.isReady){s(I)}else{E.bind("jstore-ready",I)}return E},engineReady:function(I){if(E.isReady){s(I)}else{E.bind("jstore-engine-ready",I)}return E},store:function(I,J){return J===undefined?E.get(I):E.set(I,J)},remove:function!
(I){return E.activeEngine().remove(I)},get:function(I){return E.active
Engine().get(I)},set:function(I,J){return E.activeEngine().set(I,J)}});u=Class.extend({project:undefined,jri:undefined,flavor:undefined,database:undefined,data:undefined,limit:undefined,isReady:undefined,init:function(J,I){this.project=J;this.jri=I;this.data={};this.isReady=false;this.updateCache()},updateCache:function(){this.isReady=true;this.trigger("engine-ready",[this])},bind:function(I,J){E.bind(I,J,this.jri)},trigger:function(J,I){E.trigger(J,I,this.jri)},ready:function(I){if(this.isReady){s(I,this)}else{this.bind("engine-ready",I)}},get:function(I){this.__interruptAccess();return this.data[I]},set:function(I,J){this.__interruptAccess();I=w(I);try{this.__set(I,J)}catch(K){E.trigger("jstore-error",["JSTORE_STORAGE_FAILURE",this.jri,K])}this.data[I]=J;return J},remove:function(J){this.__interruptAccess();J=w(J);try{this.__remove(J)}catch(K){E.trigger("jstore-error",["JSTORE_REMOVE_FAILURE",this.jri,K])}var I=this.data[J];this.data[J]=undefined;return I},__interruptAcces!
s:function(){if(!this.isReady){throw h}},__set:function(I,J){return},__remove:function(I){return}});i.extend(i.fn,{store:function(I,J){if(J===undefined){E.get(I)}else{E.set(I,J)}return this},removeStore:function(I){E.activeEngine().remove(I);return this},getStore:function(I){return E.activeEngine().get(I)},setStore:function(I,J){E.activeEngine().set(I,J);return this}});n.jStore=i.jStore=E;e(b,{limit:parseInt(500000,16),init:function(J,I){this.database=n.globalStorage===undefined?n.localStorage:n.globalStorage[location.hostname];this._super(J,I)},updateCache:function(){var J,K;for(J in this.database){var I=false;if(this.database.hasOwnProperty){if(this.database.hasOwnProperty(J)){I=true}}else{if(this.database.getItem(J)!==null){I=true}}if(I){K=this.database.getItem(J);this.data[J]=k(K&&K.value?K.value:K)}}this._super()},__set:function(I,J){this.database.setItem(I,x(J))},__remove:function(I){this.database.removeItem(I)}},function(){return n.localStorage!==undefined||n.globalS!
torage!==undefined});e(y,{limit:parseInt(32000,16),init:function(J,I){
this.database=n.openDatabase("jstore-"+J,"1.0",J,this.limit);if(!this.database){throw"JSTORE_SQL_NO_DB"}this.database.transaction(function(K){K.executeSql("CREATE TABLE IF NOT EXISTS jstore (k TEXT UNIQUE NOT NULL PRIMARY KEY, v TEXT NOT NULL)")});this._super(J,I)},updateCache:function(){var I=this,J=this._super;this.database.transaction(function(K){K.executeSql("SELECT k,v FROM jstore",[],function(O,L){var N=L.rows,M=0,P;for(;M<N.length;++M){P=N.item(M);I.data[P.k]=k(P.v)}J.apply(I)})})},__set:function(I,J){this.database.transaction(function(K){K.executeSql("INSERT OR REPLACE INTO jstore(k, v) VALUES (?, ?)",[I,x(J)])})},__remove:function(I){this.database.transaction(function(J){J.executeSql("DELETE FROM jstore WHERE k = ?",[I])})}},function(){return n.openDatabase!==undefined});e(F,{limit:-1,init:function(K,J){var I=this;E.bind("flash-ready",function(){I.__flashReadyListener()});this._super(K,J)},updateCache:function(I){if(I===true){var J,K=this.database.jstore_get_all();f!
or(J in K){if(K.hasOwnProperty(J)){this.data[J]=k(this.database.jstore_get(J))}}this._super()}},__set:function(I,J){if(!this.database.jstore_set(I,x(J))){E.trigger("jstore-error",["JSTORE_STORAGE_FAILURE",this.jri,"Flash Exception"])}},__remove:function(I){this.database.jstore_remove(I)},__flashReadyListener:function(){var I=i("#jStoreFlashFrame")[0],J;if(I.Document!==undefined&&g(I.Document.jStoreFlash.jstore_get,"Function")){this.database=I.Document.jStoreFlash}else{if(I.contentWindow&&I.contentWindow.document){J=i(I.contentWindow.document);if(g(i("object",J)[0].jstore_get,"Function")){this.database=i("object",J)[0]}else{if(g(i("embed",J)[0].jstore_get,"Function")){this.database=i("embed",J)[0]}}}}if(this.database===undefined){throw"JSTORE_FLASH_REFERENCE_ISSUE"}else{this.updateCache(true)}}},function(){return B("9.0.0")});e(G,{limit:-1,init:function(J,I){this.database=google.gears.factory.create("beta.database");this.database.open("jstore-"+J);this.database.execute("CREA!
TE TABLE IF NOT EXISTS jstore (k TEXT UNIQUE NOT NULL PRIMARY KEY, v T
EXT NOT NULL)");this._super(J,I)},updateCache:function(){var I=this.database.execute("SELECT k,v FROM jstore");while(I.isValidRow()){this.data[I.field(0)]=k(I.field(1));I.next()}I.close();this._super()},__set:function(I,J){this.database.execute("BEGIN");this.database.execute("INSERT OR REPLACE INTO jstore(k, v) VALUES (?, ?)",[I,x(J)]);this.database.execute("COMMIT")},__remove:function(I){this.database.execute("BEGIN");this.database.execute("DELETE FROM jstore WHERE k = ?",[I]);this.database.execute("COMMIT")}},function(){return n.google!==undefined&&n.google.gears!==undefined});e(A,{limit:parseInt(10000,16),init:function(J,I){this.database=i('<div style="display:none;behavior:url(\'#default#userData\')" id="jstore-'+J+'"></div>').appendTo(document.body).get(0);this._super(J,I)},updateCache:function(){this.database.load(this.project);var K=document.getElementById("jstore-"+this.project),L=K.XMLDocument,I,J=0;if(L&&L.documentElement&&L.documentElement.attributes){I=L.document!
Element;for(;J<I.attributes.length;++J){this.data[I.attributes.item(J).nodeName]=k(I.attributes.item(J).nodeValue)}}this._super()},__set:function(I,J){this.database.setAttribute(I,x(J));this.database.save(this.project)},__remove:function(I){this.database.removeAttribute(I);this.database.save(this.project)}},function(){return n.ActiveXObject!==undefined})}(jQuery,window));
\ No newline at end of file
diff -r a9402fc7ce1b -r 5536d57237a3 static/scripts/packed/json2.js
--- a/static/scripts/packed/json2.js Fri Apr 09 13:02:15 2010 -0400
+++ b/static/scripts/packed/json2.js Fri Apr 09 18:09:54 2010 -0400
@@ -1,1 +1,1 @@
-var JSON=JSON||{};(function(){function f(n){return n<10?"0"+n:n}if(typeof Date.prototype.toJSON!=="function"){Date.prototype.toJSON=function(key){return isFinite(this.valueOf())?this.getUTCFullYear()+"-"+f(this.getUTCMonth()+1)+"-"+f(this.getUTCDate())+"T"+f(this.getUTCHours())+":"+f(this.getUTCMinutes())+":"+f(this.getUTCSeconds())+"Z":null};String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(key){return this.valueOf()}}var cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,escapable=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,gap,indent,meta={"\b":"\\b","\t":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},rep;function quote(string){escapable.lastIndex=0;return escapable.test(string)?'"'+string.replace(escapable,function(a){var c=meta[a];return typeof c==="string"?c:"\\u"+("0000"+a.charCodeAt(0!
).toString(16)).slice(-4)})+'"':'"'+string+'"'}function str(key,holder){var i,k,v,length,mind=gap,partial,value=holder[key];if(value&&typeof value==="object"&&typeof value.toJSON==="function"){value=value.toJSON(key)}if(typeof rep==="function"){value=rep.call(holder,key,value)}switch(typeof value){case"string":return quote(value);case"number":return isFinite(value)?String(value):"null";case"boolean":case"null":return String(value);case"object":if(!value){return"null"}gap+=indent;partial=[];if(Object.prototype.toString.apply(value)==="[object Array]"){length=value.length;for(i=0;i<length;i+=1){partial[i]=str(i,value)||"null"}v=partial.length===0?"[]":gap?"[\n"+gap+partial.join(",\n"+gap)+"\n"+mind+"]":"["+partial.join(",")+"]";gap=mind;return v}if(rep&&typeof rep==="object"){length=rep.length;for(i=0;i<length;i+=1){k=rep[i];if(typeof k==="string"){v=str(k,value);if(v){partial.push(quote(k)+(gap?": ":":")+v)}}}}else{for(k in value){if(Object.hasOwnProperty.call(value,k)){v=st!
r(k,value);if(v){partial.push(quote(k)+(gap?": ":":")+v)}}}}v=partial.
length===0?"{}":gap?"{\n"+gap+partial.join(",\n"+gap)+"\n"+mind+"}":"{"+partial.join(",")+"}";gap=mind;return v}}if(typeof JSON.stringify!=="function"){JSON.stringify=function(value,replacer,space){var i;gap="";indent="";if(typeof space==="number"){for(i=0;i<space;i+=1){indent+=" "}}else{if(typeof space==="string"){indent=space}}rep=replacer;if(replacer&&typeof replacer!=="function"&&(typeof replacer!=="object"||typeof replacer.length!=="number")){throw new Error("JSON.stringify")}return str("",{"":value})}}if(typeof JSON.parse!=="function"){JSON.parse=function(text,reviver){var j;function walk(holder,key){var k,v,value=holder[key];if(value&&typeof value==="object"){for(k in value){if(Object.hasOwnProperty.call(value,k)){v=walk(value,k);if(v!==undefined){value[k]=v}else{delete value[k]}}}}return reviver.call(holder,key,value)}cx.lastIndex=0;if(cx.test(text)){text=text.replace(cx,function(a){return"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})}if(/^[\],:{}\s]*$/.test!
(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,"@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,"]").replace(/(?:^|:|,)(?:\s*\[)+/g,""))){j=eval("("+text+")");return typeof reviver==="function"?walk({"":j},""):j}throw new SyntaxError("JSON.parse")}}}());
\ No newline at end of file
+if(!this.JSON){this.JSON={}}(function(){function f(n){return n<10?"0"+n:n}if(typeof Date.prototype.toJSON!=="function"){Date.prototype.toJSON=function(key){return isFinite(this.valueOf())?this.getUTCFullYear()+"-"+f(this.getUTCMonth()+1)+"-"+f(this.getUTCDate())+"T"+f(this.getUTCHours())+":"+f(this.getUTCMinutes())+":"+f(this.getUTCSeconds())+"Z":null};String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(key){return this.valueOf()}}var cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,escapable=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,gap,indent,meta={"\b":"\\b","\t":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},rep;function quote(string){escapable.lastIndex=0;return escapable.test(string)?'"'+string.replace(escapable,function(a){var c=meta[a];return typeof c==="string"?c:"\\u"+("0000"+a.ch!
arCodeAt(0).toString(16)).slice(-4)})+'"':'"'+string+'"'}function str(key,holder){var i,k,v,length,mind=gap,partial,value=holder[key];if(value&&typeof value==="object"&&typeof value.toJSON==="function"){value=value.toJSON(key)}if(typeof rep==="function"){value=rep.call(holder,key,value)}switch(typeof value){case"string":return quote(value);case"number":return isFinite(value)?String(value):"null";case"boolean":case"null":return String(value);case"object":if(!value){return"null"}gap+=indent;partial=[];if(Object.prototype.toString.apply(value)==="[object Array]"){length=value.length;for(i=0;i<length;i+=1){partial[i]=str(i,value)||"null"}v=partial.length===0?"[]":gap?"[\n"+gap+partial.join(",\n"+gap)+"\n"+mind+"]":"["+partial.join(",")+"]";gap=mind;return v}if(rep&&typeof rep==="object"){length=rep.length;for(i=0;i<length;i+=1){k=rep[i];if(typeof k==="string"){v=str(k,value);if(v){partial.push(quote(k)+(gap?": ":":")+v)}}}}else{for(k in value){if(Object.hasOwnProperty.call(valu!
e,k)){v=str(k,value);if(v){partial.push(quote(k)+(gap?": ":":")+v)}}}}
v=partial.length===0?"{}":gap?"{\n"+gap+partial.join(",\n"+gap)+"\n"+mind+"}":"{"+partial.join(",")+"}";gap=mind;return v}}if(typeof JSON.stringify!=="function"){JSON.stringify=function(value,replacer,space){var i;gap="";indent="";if(typeof space==="number"){for(i=0;i<space;i+=1){indent+=" "}}else{if(typeof space==="string"){indent=space}}rep=replacer;if(replacer&&typeof replacer!=="function"&&(typeof replacer!=="object"||typeof replacer.length!=="number")){throw new Error("JSON.stringify")}return str("",{"":value})}}if(typeof JSON.parse!=="function"){JSON.parse=function(text,reviver){var j;function walk(holder,key){var k,v,value=holder[key];if(value&&typeof value==="object"){for(k in value){if(Object.hasOwnProperty.call(value,k)){v=walk(value,k);if(v!==undefined){value[k]=v}else{delete value[k]}}}}return reviver.call(holder,key,value)}text=String(text);cx.lastIndex=0;if(cx.test(text)){text=text.replace(cx,function(a){return"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-!
4)})}if(/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,"@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,"]").replace(/(?:^|:|,)(?:\s*\[)+/g,""))){j=eval("("+text+")");return typeof reviver==="function"?walk({"":j},""):j}throw new SyntaxError("JSON.parse")}}}());
\ No newline at end of file
diff -r a9402fc7ce1b -r 5536d57237a3 templates/display_base.mako
--- a/templates/display_base.mako Fri Apr 09 13:02:15 2010 -0400
+++ b/templates/display_base.mako Fri Apr 09 18:09:54 2010 -0400
@@ -32,29 +32,25 @@
<%def name="javascripts()">
${parent.javascripts()}
- ${h.js( "jquery", "jquery.tipsy", "galaxy.base", "json2", "jquery.autocomplete", "jquery.jstore-all", "autocomplete_tagging" )}
+ ${h.js( "jquery", "jquery.tipsy", "galaxy.base", "json2", "class", "jquery.jstore", "jquery.autocomplete", "autocomplete_tagging" )}
<script type="text/javascript">
- //
+
// Handle click on community tag.
- //
- function community_tag_click(tag_name, tag_value)
- {
+ function community_tag_click(tag_name, tag_value) {
<% controller_name = get_controller_name( item ) %>
var href = '${h.url_for ( controller='/' + controller_name , action='list_published')}';
href = href + "?f-tags=" + tag_name;
- if (tag_value != undefined && tag_value != "")
+ if (tag_value != undefined && tag_value != "") {
href = href + ":" + tag_value;
+ }
self.location = href;
}
- $(document).ready( function()
- {
+ $(function() {
// Set links to Galaxy screencasts to open in overlay.
- $(this).find("a[href^='http://screencast.g2.bx.psu.edu/']").each( function()
- {
- $(this).click( function()
- {
+ $(this).find("a[href^='http://screencast.g2.bx.psu.edu/']").each( function() {
+ $(this).click( function() {
var href = $(this).attr('href');
show_in_overlay(
{
@@ -67,7 +63,8 @@
return false;
});
});
-
+ // Init history boxes
+ init_history_items( $("div.historyItemWrapper") );
});
</script>
</%def>
@@ -76,14 +73,12 @@
${parent.stylesheets()}
${h.css( "autocomplete_tagging", "embed_item" )}
<style type="text/css">
- .page-body
- {
+ .page-body {
padding: 10px;
## float: left;
## width: 65%;
}
- .page-meta
- {
+ .page-meta {
float: right;
width: 27%;
padding: 0.5em;
diff -r a9402fc7ce1b -r 5536d57237a3 templates/history/display.mako
--- a/templates/history/display.mako Fri Apr 09 13:02:15 2010 -0400
+++ b/templates/history/display.mako Fri Apr 09 18:09:54 2010 -0400
@@ -1,207 +1,14 @@
<%inherit file="/display_base.mako"/>
<%namespace file="/root/history_common.mako" import="render_dataset" />
+## Set vars so that there's no need to change the code below.
+<%
+ history = published_item
+ datasets = published_item_data
+%>
+
<%def name="javascripts()">
${parent.javascripts()}
- ${h.js( "jquery.jstore-all" )}
-
- ## Set vars so that there's no need to change the code below.
- <%
- history = published_item
- datasets = published_item_data
- %>
-
- <script type="text/javascript">
- $(function() {
- // Load jStore for local storage
- $.extend(jQuery.jStore.defaults, { project: 'galaxy', flash: '/static/jStore.Flash.html' })
- $.jStore.load(); // Auto-select best storage
1
0