diff --git a/tool_conf.xml.sample b/tool_conf.xml.sample
index d0cb733f330..e2d29234ce0 100644
--- a/tool_conf.xml.sample
+++ b/tool_conf.xml.sample
@@ -150,6 +150,12 @@
+
diff --git a/tools/multivariate_stats/cca.py b/tools/multivariate_stats/cca.py
new file mode 100644
index 00000000000..5ea69c6cb57
--- /dev/null
+++ b/tools/multivariate_stats/cca.py
@@ -0,0 +1,159 @@
+#!/usr/bin/env python
+
+from galaxy import eggs
+import sys, string
+from rpy import *
+import numpy
+
+def stop_err(msg):
+ sys.stderr.write(msg)
+ sys.exit()
+
+infile = sys.argv[1]
+x_cols = sys.argv[2].split(',')
+y_cols = sys.argv[3].split(',')
+
+x_scale = x_center = "FALSE"
+if sys.argv[4] == 'both':
+ x_scale = x_center = "TRUE"
+elif sys.argv[4] == 'center':
+ x_center = "TRUE"
+elif sys.argv[4] == 'scale':
+ x_scale = "TRUE"
+
+y_scale = y_center = "FALSE"
+if sys.argv[5] == 'both':
+ y_scale = y_center = "TRUE"
+elif sys.argv[5] == 'center':
+ y_center = "TRUE"
+elif sys.argv[5] == 'scale':
+ y_scale = "TRUE"
+
+std_scores = "FALSE"
+if sys.argv[6] == "yes":
+ std_scores = "TRUE"
+
+outfile = sys.argv[7]
+outfile2 = sys.argv[8]
+
+fout = open(outfile,'w')
+elems = []
+for i, line in enumerate( file ( infile )):
+ line = line.rstrip('\r\n')
+ if len( line )>0 and not line.startswith( '#' ):
+ elems = line.split( '\t' )
+ break
+ if i == 30:
+ break # Hopefully we'll never get here...
+
+if len( elems )<1:
+ stop_err( "The data in your input dataset is either missing or not formatted properly." )
+
+x_vals = []
+
+for k,col in enumerate(x_cols):
+ x_cols[k] = int(col)-1
+ x_vals.append([])
+
+y_vals = []
+
+for k,col in enumerate(y_cols):
+ y_cols[k] = int(col)-1
+ y_vals.append([])
+
+skipped = 0
+for ind,line in enumerate( file( infile )):
+ if line and not line.startswith( '#' ):
+ try:
+ fields = line.strip().split("\t")
+ valid_line = True
+ for col in x_cols+y_cols:
+ try:
+ assert float(fields[col])
+ except:
+ skipped += 1
+ valid_line = False
+ break
+ if valid_line:
+ for k,col in enumerate(x_cols):
+ try:
+ xval = float(fields[col])
+ except:
+ xval = NaN#
+ x_vals[k].append(xval)
+ for k,col in enumerate(y_cols):
+ try:
+ yval = float(fields[col])
+ except:
+ yval = NaN#
+ y_vals[k].append(yval)
+ except:
+ skipped += 1
+
+x_vals1 = numpy.asarray(x_vals).transpose()
+y_vals1 = numpy.asarray(y_vals).transpose()
+
+x_dat= r.list(array(x_vals1))
+y_dat= r.list(array(y_vals1))
+
+try:
+ r.suppressWarnings(r.library("yacca"))
+except:
+ stop_err("Missing R library yacca.")
+
+set_default_mode(NO_CONVERSION)
+try:
+ xcolnames = ["c%d" %(el+1) for el in x_cols]
+ ycolnames = ["c%d" %(el+1) for el in y_cols]
+ cc = r.cca(x=x_dat, y=y_dat, xlab=xcolnames, ylab=ycolnames, xcenter=r(x_center), ycenter=r(y_center), xscale=r(x_scale), yscale=r(y_scale), standardize_scores=r(std_scores))
+ ftest = r.F_test_cca(cc)
+except RException, rex:
+ stop_err("Encountered error while performing CCA on the input data: %s" %(rex))
+
+set_default_mode(BASIC_CONVERSION)
+summary = r.summary(cc)
+
+ncomps = len(summary['corr'])
+comps = summary['corr'].keys()
+corr = summary['corr'].values()
+xlab = summary['xlab']
+ylab = summary['ylab']
+
+for i in range(ncomps):
+ corr[comps.index('CV %s' %(i+1))] = summary['corr'].values()[i]
+
+ftest=ftest.as_py()
+print >>fout, "#Component\t%s" %("\t".join(["%s" % el for el in range(1,ncomps+1)]))
+print >>fout, "#Correlation\t%s" %("\t".join(["%s" % el for el in corr]))
+print >>fout, "#F-statistic\t%s" %("\t".join(["%s" % el for el in ftest['statistic']]))
+print >>fout, "#p-value\t%s" %("\t".join(["%s" % el for el in ftest['p.value']]))
+
+print >>fout, "#X-Coefficients\t%s" %("\t".join(["%s" % el for el in range(1,ncomps+1)]))
+for i,val in enumerate(summary['xcoef']):
+ print >>fout, "%s\t%s" %(xlab[i], "\t".join(["%s" % el for el in val]))
+
+print >>fout, "#Y-Coefficients\t%s" %("\t".join(["%s" % el for el in range(1,ncomps+1)]))
+for i,val in enumerate(summary['ycoef']):
+ print >>fout, "%s\t%s" %(ylab[i], "\t".join(["%s" % el for el in val]))
+
+print >>fout, "#X-Loadings\t%s" %("\t".join(["%s" % el for el in range(1,ncomps+1)]))
+for i,val in enumerate(summary['xstructcorr']):
+ print >>fout, "%s\t%s" %(xlab[i], "\t".join(["%s" % el for el in val]))
+
+print >>fout, "#Y-Loadings\t%s" %("\t".join(["%s" % el for el in range(1,ncomps+1)]))
+for i,val in enumerate(summary['ystructcorr']):
+ print >>fout, "%s\t%s" %(ylab[i], "\t".join(["%s" % el for el in val]))
+
+print >>fout, "#X-CrossLoadings\t%s" %("\t".join(["%s" % el for el in range(1,ncomps+1)]))
+for i,val in enumerate(summary['xcrosscorr']):
+ print >>fout, "%s\t%s" %(xlab[i], "\t".join(["%s" % el for el in val]))
+
+print >>fout, "#Y-CrossLoadings\t%s" %("\t".join(["%s" % el for el in range(1,ncomps+1)]))
+for i,val in enumerate(summary['ycrosscorr']):
+ print >>fout, "%s\t%s" %(ylab[i], "\t".join(["%s" % el for el in val]))
+
+r.pdf( outfile2, 8, 8 )
+#r.plot(cc)
+for i in range(ncomps):
+ r.helio_plot(cc, cv = i+1, main = r.paste("Explained Variance for CV",i+1), type = "variance")
+r.dev_off()
\ No newline at end of file
diff --git a/tools/multivariate_stats/cca.xml b/tools/multivariate_stats/cca.xml
new file mode 100644
index 00000000000..6bcdde2a725
--- /dev/null
+++ b/tools/multivariate_stats/cca.xml
@@ -0,0 +1,95 @@
+
+
+
+ cca.py
+ $input1
+ $x_cols
+ $y_cols
+ $x_scale
+ $y_scale
+ $std_scores
+ $out_file1
+ $out_file2
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ rpy
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+.. class:: infomark
+
+**TIP:** If your data is not TAB delimited, use *Edit Queries->Convert characters*
+
+-----
+
+.. class:: infomark
+
+**What it does**
+
+This tool uses functions from 'yacca' library from R statistical package to perform Canonical Correlation Analysis (CCA) on the input data. It outputs two files, one containing the summary statistics of the performed CCA, and the other containing helioplots, which display structural loadings of X and Y variables on different canonical components.
+
+*Carter T. Butts (2009). yacca: Yet Another Canonical Correlation Analysis Package. R package version 1.1.*
+
+-----
+
+.. class:: warningmark
+
+**Note**
+
+- This tool currently treats all predictor and response variables as continuous numeric variables. Running the tool on categorical variables might result in incorrect results.
+
+- Rows containing non-numeric (or missing) data in any of the chosen columns will be skipped from the analysis.
+
+- The summary statistics in the output are described below:
+
+ - correlation: Canonical correlation between the canonical variates (i.e. transformed variables)
+ - F-statistic: F-value obtained from F Test for Canonical Correlations Using Rao's Approximation
+ - p-value: denotes significance of canonical correlations
+ - Coefficients: represent the coefficients of X and Y variables on each canonical variate
+ - Loadings: represent the correlations between the original variables in each set and their respective canonical variates
+ - CrossLoadings: represent the correlations between the original variables in each set and the opposite canonical variates
+
+
+
diff --git a/tools/multivariate_stats/kcca.py b/tools/multivariate_stats/kcca.py
new file mode 100644
index 00000000000..620ba862ca9
--- /dev/null
+++ b/tools/multivariate_stats/kcca.py
@@ -0,0 +1,146 @@
+#!/usr/bin/env python
+
+"""
+Run kernel CCA using kcca() from R 'kernlab' package
+
+usage: %prog [options]
+ -i, --input=i: Input file
+ -o, --output1=o: Summary output
+ -x, --x_cols=x: X-Variable columns
+ -y, --y_cols=y: Y-Variable columns
+ -k, --kernel=k: Kernel function
+ -f, --features=f: Number of canonical components to return
+ -s, --sigma=s: sigma
+ -d, --degree=d: degree
+ -l, --scale=l: scale
+ -t, --offset=t: offset
+ -r, --order=r: order
+
+usage: %prog input output1 x_cols y_cols kernel features sigma(or_None) degree(or_None) scale(or_None) offset(or_None) order(or_None)
+"""
+
+from galaxy import eggs
+import sys, string
+from rpy import *
+import numpy
+import pkg_resources; pkg_resources.require( "bx-python" )
+from bx.cookbook import doc_optparse
+
+
+def stop_err(msg):
+ sys.stderr.write(msg)
+ sys.exit()
+
+#Parse Command Line
+options, args = doc_optparse.parse( __doc__ )
+#{'options= kernel': 'rbfdot', 'var_cols': '1,2,3,4', 'degree': 'None', 'output2': '/afs/bx.psu.edu/home/gua110/workspace/galaxy_bitbucket/database/files/000/dataset_260.dat', 'output1': '/afs/bx.psu.edu/home/gua110/workspace/galaxy_bitbucket/database/files/000/dataset_259.dat', 'scale': 'None', 'offset': 'None', 'input': '/afs/bx.psu.edu/home/gua110/workspace/galaxy_bitbucket/database/files/000/dataset_256.dat', 'sigma': '1.0', 'order': 'None'}
+
+infile = options.input
+x_cols = options.x_cols.split(',')
+y_cols = options.y_cols.split(',')
+kernel = options.kernel
+outfile = options.output1
+ncomps = int(options.features)
+fout = open(outfile,'w')
+
+if ncomps < 1:
+ print "You chose to return '0' canonical components. Please try rerunning the tool with number of components = 1 or more."
+ sys.exit()
+elems = []
+for i, line in enumerate( file ( infile )):
+ line = line.rstrip('\r\n')
+ if len( line )>0 and not line.startswith( '#' ):
+ elems = line.split( '\t' )
+ break
+ if i == 30:
+ break # Hopefully we'll never get here...
+
+if len( elems )<1:
+ stop_err( "The data in your input dataset is either missing or not formatted properly." )
+
+x_vals = []
+for k,col in enumerate(x_cols):
+ x_cols[k] = int(col)-1
+ x_vals.append([])
+y_vals = []
+for k,col in enumerate(y_cols):
+ y_cols[k] = int(col)-1
+ y_vals.append([])
+NA = 'NA'
+skipped = 0
+for ind,line in enumerate( file( infile )):
+ if line and not line.startswith( '#' ):
+ try:
+ fields = line.strip().split("\t")
+ valid_line = True
+ for col in x_cols+y_cols:
+ try:
+ assert float(fields[col])
+ except:
+ skipped += 1
+ valid_line = False
+ break
+ if valid_line:
+ for k,col in enumerate(x_cols):
+ try:
+ xval = float(fields[col])
+ except:
+ xval = NaN#
+ x_vals[k].append(xval)
+ for k,col in enumerate(y_cols):
+ try:
+ yval = float(fields[col])
+ except:
+ yval = NaN#
+ y_vals[k].append(yval)
+ except:
+ skipped += 1
+
+x_vals1 = numpy.asarray(x_vals).transpose()
+y_vals1 = numpy.asarray(y_vals).transpose()
+
+x_dat= r.list(array(x_vals1))
+y_dat= r.list(array(y_vals1))
+
+try:
+ r.suppressWarnings(r.library('kernlab'))
+except:
+ stop_err('Missing R library kernlab')
+
+set_default_mode(NO_CONVERSION)
+if kernel=="rbfdot" or kernel=="anovadot":
+ pars = r.list(sigma=float(options.sigma))
+elif kernel=="polydot":
+ pars = r.list(degree=float(options.degree),scale=float(options.scale),offset=float(options.offset))
+elif kernel=="tanhdot":
+ pars = r.list(scale=float(options.scale),offset=float(options.offset))
+elif kernel=="besseldot":
+ pars = r.list(degree=float(options.degree),sigma=float(options.sigma),order=float(options.order))
+elif kernel=="anovadot":
+ pars = r.list(degree=float(options.degree),sigma=float(options.sigma))
+else:
+ pars = rlist()
+
+try:
+ kcc = r.kcca(x=x_dat, y=y_dat, kernel=kernel, kpar=pars, ncomps=ncomps)
+except RException, rex:
+ stop_err("Encountered error while performing kCCA on the input data: %s" %(rex))
+
+set_default_mode(BASIC_CONVERSION)
+kcor = r.kcor(kcc)
+if ncomps == 1:
+ kcor = [kcor]
+xcoef = r.xcoef(kcc)
+ycoef = r.ycoef(kcc)
+
+print >>fout, "#Component\t%s" %("\t".join(["%s" % el for el in range(1,ncomps+1)]))
+
+print >>fout, "#Correlation\t%s" %("\t".join(["%s" % el for el in kcor]))
+
+print >>fout, "#Estimated X-coefficients\t%s" %("\t".join(["%s" % el for el in range(1,ncomps+1)]))
+for obs,val in enumerate(xcoef):
+ print >>fout, "%s\t%s" %(obs+1, "\t".join(["%s" % el for el in val]))
+
+print >>fout, "#Estimated Y-coefficients\t%s" %("\t".join(["%s" % el for el in range(1,ncomps+1)]))
+for obs,val in enumerate(ycoef):
+ print >>fout, "%s\t%s" %(obs+1, "\t".join(["%s" % el for el in val]))
diff --git a/tools/multivariate_stats/kcca.xml b/tools/multivariate_stats/kcca.xml
new file mode 100644
index 00000000000..7c5be10b7db
--- /dev/null
+++ b/tools/multivariate_stats/kcca.xml
@@ -0,0 +1,150 @@
+
+
+
+ kcca.py
+ --input=$input1
+ --output1=$out_file1
+ --x_cols=$x_cols
+ --y_cols=$y_cols
+ --kernel=$kernelChoice.kernel
+ --features=$features
+ #if $kernelChoice.kernel == "rbfdot" or $kernelChoice.kernel == "anovadot":
+ --sigma=$kernelChoice.sigma
+ --degree="None"
+ --scale="None"
+ --offset="None"
+ --order="None"
+ #elif $kernelChoice.kernel == "polydot":
+ --sigma="None"
+ --degree=$kernelChoice.degree
+ --scale=$kernelChoice.scale
+ --offset=$kernelChoice.offset
+ --order="None"
+ #elif $kernelChoice.kernel == "tanhdot":
+ --sigma="None"
+ --degree="None"
+ --scale=$kernelChoice.scale
+ --offset=$kernelChoice.offset
+ --order="None"
+ #elif $kernelChoice.kernel == "besseldot":
+ --sigma=$kernelChoice.sigma
+ --degree=$kernelChoice.degree
+ --scale="None"
+ --offset="None"
+ --order=$kernelChoice.order
+ #elif $kernelChoice.kernel == "anovadot":
+ --sigma=$kernelChoice.sigma
+ --degree=$kernelChoice.degree
+ --scale="None"
+ --offset="None"
+ --order="None"
+ #else:
+ --sigma="None"
+ --degree="None"
+ --scale="None"
+ --offset="None"
+ --order="None"
+ #end if
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ rpy
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+.. class:: infomark
+
+**TIP:** If your data is not TAB delimited, use *Edit Queries->Convert characters*
+
+-----
+
+.. class:: infomark
+
+**What it does**
+
+This tool uses functions from 'kernlab' library from R statistical package to perform Kernel Canonical Correlation Analysis (kCCA) on the input data.
+
+*Alexandros Karatzoglou, Alex Smola, Kurt Hornik, Achim Zeileis (2004). kernlab - An S4 Package for Kernel Methods in R. Journal of Statistical Software 11(9), 1-20. URL http://www.jstatsoft.org/v11/i09/*
+
+-----
+
+.. class:: warningmark
+
+**Note**
+
+This tool currently treats all variables as continuous numeric variables. Running the tool on categorical variables might result in incorrect results. Rows containing non-numeric (or missing) data in any of the chosen columns will be skipped from the analysis.
+
+
+
diff --git a/tools/multivariate_stats/kpca.py b/tools/multivariate_stats/kpca.py
new file mode 100644
index 00000000000..e9987c159a0
--- /dev/null
+++ b/tools/multivariate_stats/kpca.py
@@ -0,0 +1,134 @@
+#!/usr/bin/env python
+
+"""
+Run kernel PCA using kpca() from R 'kernlab' package
+
+usage: %prog [options]
+ -i, --input=i: Input file
+ -o, --output1=o: Summary output
+ -p, --output2=p: Figures output
+ -c, --var_cols=c: Variable columns
+ -k, --kernel=k: Kernel function
+ -f, --features=f: Number of principal components to return
+ -s, --sigma=s: sigma
+ -d, --degree=d: degree
+ -l, --scale=l: scale
+ -t, --offset=t: offset
+ -r, --order=r: order
+
+usage: %prog input output1 output2 var_cols kernel features sigma(or_None) degree(or_None) scale(or_None) offset(or_None) order(or_None)
+"""
+
+from galaxy import eggs
+import sys, string
+from rpy import *
+import numpy
+import pkg_resources; pkg_resources.require( "bx-python" )
+from bx.cookbook import doc_optparse
+
+
+def stop_err(msg):
+ sys.stderr.write(msg)
+ sys.exit()
+
+#Parse Command Line
+options, args = doc_optparse.parse( __doc__ )
+#{'options= kernel': 'rbfdot', 'var_cols': '1,2,3,4', 'degree': 'None', 'output2': '/afs/bx.psu.edu/home/gua110/workspace/galaxy_bitbucket/database/files/000/dataset_260.dat', 'output1': '/afs/bx.psu.edu/home/gua110/workspace/galaxy_bitbucket/database/files/000/dataset_259.dat', 'scale': 'None', 'offset': 'None', 'input': '/afs/bx.psu.edu/home/gua110/workspace/galaxy_bitbucket/database/files/000/dataset_256.dat', 'sigma': '1.0', 'order': 'None'}
+
+infile = options.input
+x_cols = options.var_cols.split(',')
+kernel = options.kernel
+outfile = options.output1
+outfile2 = options.output2
+ncomps = int(options.features)
+fout = open(outfile,'w')
+
+elems = []
+for i, line in enumerate( file ( infile )):
+ line = line.rstrip('\r\n')
+ if len( line )>0 and not line.startswith( '#' ):
+ elems = line.split( '\t' )
+ break
+ if i == 30:
+ break # Hopefully we'll never get here...
+
+if len( elems )<1:
+ stop_err( "The data in your input dataset is either missing or not formatted properly." )
+
+x_vals = []
+
+for k,col in enumerate(x_cols):
+ x_cols[k] = int(col)-1
+ x_vals.append([])
+
+NA = 'NA'
+skipped = 0
+for ind,line in enumerate( file( infile )):
+ if line and not line.startswith( '#' ):
+ try:
+ fields = line.strip().split("\t")
+ for k,col in enumerate(x_cols):
+ try:
+ xval = float(fields[col])
+ except:
+ #xval = r('NA')
+ xval = NaN#
+ x_vals[k].append(xval)
+ except:
+ skipped += 1
+
+x_vals1 = numpy.asarray(x_vals).transpose()
+dat= r.list(array(x_vals1))
+
+try:
+ r.suppressWarnings(r.library('kernlab'))
+except:
+ stop_err('Missing R library kernlab')
+
+set_default_mode(NO_CONVERSION)
+if kernel=="rbfdot" or kernel=="anovadot":
+ pars = r.list(sigma=float(options.sigma))
+elif kernel=="polydot":
+ pars = r.list(degree=float(options.degree),scale=float(options.scale),offset=float(options.offset))
+elif kernel=="tanhdot":
+ pars = r.list(scale=float(options.scale),offset=float(options.offset))
+elif kernel=="besseldot":
+ pars = r.list(degree=float(options.degree),sigma=float(options.sigma),order=float(options.order))
+elif kernel=="anovadot":
+ pars = r.list(degree=float(options.degree),sigma=float(options.sigma))
+else:
+ pars = rlist()
+
+try:
+ kpc = r.kpca(x=r.na_exclude(dat), kernel=kernel, kpar=pars, features=ncomps)
+except RException, rex:
+ stop_err("Encountered error while performing kPCA on the input data: %s" %(rex))
+set_default_mode(BASIC_CONVERSION)
+
+eig = r.eig(kpc)
+pcv = r.pcv(kpc)
+rotated = r.rotated(kpc)
+
+comps = eig.keys()
+eigv = eig.values()
+for i in range(ncomps):
+ eigv[comps.index('Comp.%s' %(i+1))] = eig.values()[i]
+
+print >>fout, "#Component\t%s" %("\t".join(["%s" % el for el in range(1,ncomps+1)]))
+
+print >>fout, "#Eigenvalue\t%s" %("\t".join(["%s" % el for el in eig.values()]))
+
+print >>fout, "#Principal component vectors\t%s" %("\t".join(["%s" % el for el in range(1,ncomps+1)]))
+for obs,val in enumerate(pcv):
+ print >>fout, "%s\t%s" %(obs+1, "\t".join(["%s" % el for el in val]))
+
+print >>fout, "#Rotated values\t%s" %("\t".join(["%s" % el for el in range(1,ncomps+1)]))
+for obs,val in enumerate(rotated):
+ print >>fout, "%s\t%s" %(obs+1, "\t".join(["%s" % el for el in val]))
+
+r.pdf( outfile2, 8, 8 )
+if ncomps != 1:
+ r.pairs(rotated,labels=r.list(range(1,ncomps+1)),main="Scatterplot of rotated values")
+else:
+ r.plot(rotated, ylab='Comp.1', main="Scatterplot of rotated values")
+r.dev_off()
\ No newline at end of file
diff --git a/tools/multivariate_stats/kpca.xml b/tools/multivariate_stats/kpca.xml
new file mode 100644
index 00000000000..42d178937e1
--- /dev/null
+++ b/tools/multivariate_stats/kpca.xml
@@ -0,0 +1,151 @@
+
+
+
+ kpca.py
+ --input=$input1
+ --output1=$out_file1
+ --output2=$out_file2
+ --var_cols=$var_cols
+ --kernel=$kernelChoice.kernel
+ --features=$features
+ #if $kernelChoice.kernel == "rbfdot" or $kernelChoice.kernel == "anovadot":
+ --sigma=$kernelChoice.sigma
+ --degree="None"
+ --scale="None"
+ --offset="None"
+ --order="None"
+ #elif $kernelChoice.kernel == "polydot":
+ --sigma="None"
+ --degree=$kernelChoice.degree
+ --scale=$kernelChoice.scale
+ --offset=$kernelChoice.offset
+ --order="None"
+ #elif $kernelChoice.kernel == "tanhdot":
+ --sigma="None"
+ --degree="None"
+ --scale=$kernelChoice.scale
+ --offset=$kernelChoice.offset
+ --order="None"
+ #elif $kernelChoice.kernel == "besseldot":
+ --sigma=$kernelChoice.sigma
+ --degree=$kernelChoice.degree
+ --scale="None"
+ --offset="None"
+ --order=$kernelChoice.order
+ #elif $kernelChoice.kernel == "anovadot":
+ --sigma=$kernelChoice.sigma
+ --degree=$kernelChoice.degree
+ --scale="None"
+ --offset="None"
+ --order="None"
+ #else:
+ --sigma="None"
+ --degree="None"
+ --scale="None"
+ --offset="None"
+ --order="None"
+ #end if
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ rpy
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+.. class:: infomark
+
+**TIP:** If your data is not TAB delimited, use *Edit Queries->Convert characters*
+
+-----
+
+.. class:: infomark
+
+**What it does**
+
+This tool uses functions from 'kernlab' library from R statistical package to perform Kernel Principal Component Analysis (kPCA) on the input data. It outputs two files, one containing the summary statistics of the performed kPCA, and the other containing a scatterplot matrix of rotated values reported by kPCA.
+
+*Alexandros Karatzoglou, Alex Smola, Kurt Hornik, Achim Zeileis (2004). kernlab - An S4 Package for Kernel Methods in R. Journal of Statistical Software 11(9), 1-20. URL http://www.jstatsoft.org/v11/i09/*
+
+-----
+
+.. class:: warningmark
+
+**Note**
+
+This tool currently treats all variables as continuous numeric variables. Running the tool on categorical variables might result in incorrect results. Rows containing non-numeric (or missing) data in any of the chosen columns will be skipped from the analysis.
+
+
+
diff --git a/tools/multivariate_stats/pca.py b/tools/multivariate_stats/pca.py
new file mode 100644
index 00000000000..7b1db8a6a85
--- /dev/null
+++ b/tools/multivariate_stats/pca.py
@@ -0,0 +1,98 @@
+#!/usr/bin/env python
+
+from galaxy import eggs
+import sys, string
+from rpy import *
+import numpy
+
+def stop_err(msg):
+ sys.stderr.write(msg)
+ sys.exit()
+
+infile = sys.argv[1]
+x_cols = sys.argv[2].split(',')
+method = sys.argv[3]
+outfile = sys.argv[4]
+outfile2 = sys.argv[5]
+
+fout = open(outfile,'w')
+elems = []
+for i, line in enumerate( file ( infile )):
+ line = line.rstrip('\r\n')
+ if len( line )>0 and not line.startswith( '#' ):
+ elems = line.split( '\t' )
+ break
+ if i == 30:
+ break # Hopefully we'll never get here...
+
+if len( elems )<1:
+ stop_err( "The data in your input dataset is either missing or not formatted properly." )
+
+x_vals = []
+
+for k,col in enumerate(x_cols):
+ x_cols[k] = int(col)-1
+ x_vals.append([])
+
+NA = 'NA'
+skipped = 0
+for ind,line in enumerate( file( infile )):
+ if line and not line.startswith( '#' ):
+ try:
+ fields = line.strip().split("\t")
+ for k,col in enumerate(x_cols):
+ try:
+ xval = float(fields[col])
+ except:
+ #xval = r('NA')
+ xval = NaN#
+ x_vals[k].append(xval)
+ except:
+ skipped += 1
+
+x_vals1 = numpy.asarray(x_vals).transpose()
+dat= r.list(array(x_vals1))
+
+set_default_mode(NO_CONVERSION)
+try:
+ if method == "cor":
+ pc = r.princomp(r.na_exclude(dat), cor = r("TRUE"))
+ else:
+ pc = r.princomp(r.na_exclude(dat), cor = r("FALSE"))
+except RException, rex:
+ stop_err("Encountered error while performing PCA on the input data: %s" %(rex))
+
+set_default_mode(BASIC_CONVERSION)
+summary = r.summary(pc, loadings="TRUE")
+ncomps = len(summary['sdev'])
+comps = summary['sdev'].keys()
+sd = summary['sdev'].values()
+for i in range(ncomps):
+ sd[comps.index('Comp.%s' %(i+1))] = summary['sdev'].values()[i]
+
+print >>fout, "#Component\t%s" %("\t".join(["%s" % el for el in range(1,ncomps+1)]))
+print >>fout, "#Std. deviation\t%s" %("\t".join(["%s" % el for el in sd]))
+total_var = 0
+vars = []
+for s in sd:
+ var = s*s
+ total_var += var
+ vars.append(var)
+for i,var in enumerate(vars):
+ vars[i] = vars[i]/total_var
+
+print >>fout, "#Proportion of variance explained\t%s" %("\t".join(["%s" % el for el in vars]))
+
+print >>fout, "#Loadings\t%s" %("\t".join(["%s" % el for el in range(1,ncomps+1)]))
+xcolnames = ["c%d" %(el+1) for el in x_cols]
+for i,val in enumerate(summary['loadings']):
+ print >>fout, "%s\t%s" %(xcolnames[i], "\t".join(["%s" % el for el in val]))
+
+print >>fout, "#Scores\t%s" %("\t".join(["%s" % el for el in range(1,ncomps+1)]))
+
+for obs,sc in enumerate(summary['scores']):
+ print >>fout, "%s\t%s" %(obs+1, "\t".join(["%s" % el for el in sc]))
+
+r.pdf( outfile2, 8, 8 )
+r.biplot(pc)
+r.dev_off()
\ No newline at end of file
diff --git a/tools/multivariate_stats/pca.xml b/tools/multivariate_stats/pca.xml
new file mode 100644
index 00000000000..b0bf49a48d1
--- /dev/null
+++ b/tools/multivariate_stats/pca.xml
@@ -0,0 +1,76 @@
+
+
+
+ pca.py
+ $input1
+ $var_cols
+ $method
+ $out_file1
+ $out_file2
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ rpy
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+.. class:: infomark
+
+**TIP:** If your data is not TAB delimited, use *Edit Queries->Convert characters*
+
+-----
+
+.. class:: infomark
+
+**What it does**
+
+This tool uses the 'princomp' function from R statistical package to perform Principal Component Analysis (PCA) on the given numeric input data. It outputs two files, one containing the summary statistics of PCA, and the other containing biplots of the observations and principal components.
+
+*R Development Core Team (2009). R: A language and environment for statistical computing. R Foundation for Statistical Computing, Vienna, Austria. ISBN 3-900051-07-0, URL http://www.R-project.org.*
+
+-----
+
+.. class:: warningmark
+
+**Note**
+
+- This tool currently treats all variables as continuous numeric variables. Running the tool on categorical variables might result in incorrect results. Rows containing non-numeric (or missing) data in any of the chosen columns will be skipped from the analysis.
+
+- The summary statistics in the output are described below:
+
+ - Std. deviation: Standard deviations of the principal components
+ - Loadings: a list of eigen-vectors
+ - Scores: Scores of the input data on the principal components
+
+
+
diff --git a/tools/regVariation/linear_regression.xml b/tools/regVariation/linear_regression.xml
index e337296b4cf..98703319a41 100644
--- a/tools/regVariation/linear_regression.xml
+++ b/tools/regVariation/linear_regression.xml
@@ -11,8 +11,8 @@
-
-
+
+
@@ -47,13 +47,15 @@
This tool uses the 'lm' function from R statistical package to perform linear regression on the input data. It outputs two files, one containing the summary statistics of the performed regression, and the other containing diagnostic plots to check whether model assumptions are satisfied.
+*R Development Core Team (2009). R: A language and environment for statistical computing. R Foundation for Statistical Computing, Vienna, Austria. ISBN 3-900051-07-0, URL http://www.R-project.org.*
+
-----
.. class:: warningmark
**Note**
-- This tool currently treats all predictor and response variables as continuous variables. Running the tool on categorical variables might result in incorrect results.
+- This tool currently treats all predictor and response variables as continuous numeric variables. Running the tool on categorical variables might result in incorrect results.
- Rows containing non-numeric (or missing) data in any of the chosen columns will be skipped from the analysis.