diff rg_nri.xml @ 20:bb725f6d6d38 draft default tip

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/rglasso commit 344140b8df53b8b7024618bb04594607a045c03a
author iuc
date Mon, 04 May 2015 22:47:29 -0400
parents 0e87f636bdd8
children
line wrap: on
line diff
--- a/rg_nri.xml	Wed Apr 29 12:07:11 2015 -0400
+++ b/rg_nri.xml	Mon May 04 22:47:29 2015 -0400
@@ -7,145 +7,12 @@
       <requirement type="package" version="2.14">glmnet_lars_2_14</requirement>
   </requirements>
   <command interpreter="python">
-     rgToolFactory.py --script_path "$runme" --interpreter "Rscript" --tool_name "rg_NRI" 
+     rgToolFactory.py --script_path "$runme" --interpreter "Rscript" --tool_name "rg_NRI"
     --output_dir "$html_file.files_path" --output_html "$html_file" --make_HTML "yes"
   </command>
-  <inputs>
-     <param name="title" type="text" value="NRI test" size="80" label="Plot Title" help="Will appear as the title for the comparison plot"/>
-    <param name="input1"  type="data" format="tabular" label="Select a tabular file from the baseline model with predicted and observed outcome column for each subject"
-    multiple='False' help="Observed and predicted status columns must be selected from this file below - NOTE both models must be in same order with exact matches in all observed outcomes" optional="False"/>
-    <param name="input1_observed" label="Select column containing observed outcome (0 for no event, 1 for an event)" type="data_column" data_ref="input1" numerical="True" 
-         multiple="False" use_header_names="True" optional="False" help = "Observed outcomes are compared in the two files to check that the datasets are from the same data"/>
-    <param name="input1_predicted" label="Select column containing predicted event probabilies from baseline model" type="data_column" data_ref="input1" numerical="True" 
-         multiple="False" use_header_names="True" optional="False"  help="Must be in range 0-1"/>
-    <param name="input1_id" label="Select column containing subject ID from baseline model" type="data_column" data_ref="input1" numerical="True" 
-         multiple="False" use_header_names="True" optional="False" help="Subect IDs are needed to match subjects to compare predictions in the two inputs"/>
-    <param name="input2"  type="data" format="tabular" label="Select a tabular file from the new model with predicted and observed outcome columns for each subject"
-    multiple='False' help="Observed and predicted status columns must be selected from this file below" />
-    <param name="input2_observed" label="Select column containing observed outcome (0 for no event, 1 for an event)" type="data_column" data_ref="input2" numerical="True" 
-         multiple="False" use_header_names="True" optional="False" help = "Observed outcomes are compared in the two files to check that the datasets are from the same data"/>
-    <param name="input2_predicted" label="Select column containing predicted event probabilities from the new model" type="data_column" data_ref="input2" numerical="True" 
-         multiple="False" use_header_names="True" optional="False" help="Must be in range 0-1"/>
-    <param name="input2_id" label="Select column containing subject ID from the new model" type="data_column" data_ref="input2" numerical="True" 
-         multiple="False" use_header_names="True" optional="False"  help="Subect IDs are needed to match subjects to compare predictions in the two inputs"/>
-    <conditional name="CImeth">
-        <param name="cis" type="select" label="CI calculation method" 
-             help="Bootstrap will take time - a long time for thousands - asymptotic is quick and informative">
-                <option value="asymptotic" selected="true">Asymptotic estimate</option>
-                <option value="boot">Bootstrap for empirical CIs</option>
-        </param>
-        <when value="boot">
-            <param name="nboot" type="integer" value="1000" label="Number of bootstrap replicates"/>
-        </when>
-        <when value="asymptotic">
-            <param name="nboot" type="hidden" value="1000"/>
-        </when>
-    </conditional>
-  </inputs>    
-  <outputs>
-    <data format="html" name="html_file" label="${title}.html"/>
-    <data format="tabular" name="nri_file" label="${title}_nrires.xls"/>
-  </outputs>
- <tests>
-    <test>
-     <param name='title' value='nri_test1' />
-     <param name='input1' value='nri_test1.xls' ftype='tabular' />
-     <param name='input2' value='nri_test1.xls' ftype='tabular' />
-     <param name='input1_id' value="1" />
-     <param name='input1_observed' value="2" />
-     <param name='input1_predicted' value="3" />
-     <param name='input2_observed' value="2" />
-     <param name='input2_predicted' value="4" />
-     <output name='html_file' file='nri_test1_out.html'  compare='diff' lines_diff='10' />
-     <output name='nri_file' file='nri_test1_out.xls' />
-    </test>
-</tests>
-<help>
-
-**Before you start**
-
-This is a simple tool to calculate various measures of improvement in prediction between two models described in pickering_paper_
-It is based on an R script pickering_code_ written by Dr John W Pickering and Dr David Cairns from sunny Otago University which
-has been debugged and slightly adjusted to fit a Galaxy tool wrapper.
-
-
-**What it does**
-
-Copied from the documentation in pickering_code_ ::
-
-    
-    Functions to create risk assessment plots and associated summary statistics
-    
-    
-      (c) 2012 Dr John W Pickering, john.pickering@otago.ac.nz, and Dr David Cairns
-       Last modified August 2014
-     
-      Redistribution and use in source and binary forms, with or without 
-       modification, are permitted provided that the following conditions are met:
-       * Redistributions of source code must retain the above copyright 
-         notice, this list of conditions and the following disclaimer.
-       * Redistributions in binary form must reproduce the above copyright 
-         notice, this list of conditions and the following disclaimer in 
-         the documentation and/or other materials provided with the distribution
-
-     FUNCTIONS
-     raplot
-           Produces a Risk Assessment Plot and outputs the coordinates of the four curves
-           Based on: Pickering, J. W. and Endre, Z. H. (2012). New Metrics for Assessing Diagnostic Potential of
-           Candidate Biomarkers. Clinical Journal of the American Society of Nephrology, 7, 1355–1364. doi:10.2215/CJN.09590911
-    
-     statistics.raplot 
-           Produces the NRIs, IDIs, IS, IP, AUCs.
-           Based on: Pencina, M. J., D'Agostino, R. B. and Steyerberg, E. W. (2011). Extensions of net reclassification improvement calculations to
-           measure usefulness of new biomarkers. Statistics in Medicine, 30(1), 11–21. doi:10.1002/sim.4085
-           Pencina, M. J., D'Agostino, R. B. and Vasan, R. S. (2008). Evaluating the added predictive ability of a new marker: From area under the
-           ROC curve to reclassification and beyond.
-           Statistics in Medicine, 27(2), 157–172. doi:10.1002/sim.2929
-           DeLong, E., DeLong, D. and Clarke-Pearson, D. (1988). Comparing the areas under 2 or more correlated receiver operating characteristic curves - a nonparametric approach.
-           Biometrics, 44(3), 837–845.
-    
-     summary.raplot 
-           Produces the NRIs, IDIs, IS, IP, AUCs with confidence intervals using a bootstrap or asymptotic procedure. (I prefer bootstrap which is chosed by cis=c("boot"))
-
-
-     Required arguments for all functions:
-       x1 is calculated risk (eg from a glm) for the null model, i.e. predict(,type="response") on a glm object
-       x2 is calculated risk (eg from a glm) for the alternative model
-       y is the case-control indicator (0 for controls, 1 for cases)
-     Optional argument
-       t are the boundaries of the risks for each group (ie 0, 1 and the thresholds beteween.  eg c(0,0,3,0,7,1)). If missing, defaults to c(0, the incidence, 1)
-
-
-**Input**
-
-The observed and predicted outcomes from two models to be compared.
-
-**Output**
-
-Lots'o'measures (TM) see pickering_paper_ for details
-
-**Attributions**
-
-pickering_paper_ is the paper the caclulations performed by this tool is based on
-
-pickering_code_ is the R function from John Pickering exposed by this Galaxy tool with minor modifications and hacks by Ross Lazarus.
-
-Galaxy_ (that's what you are using right now!) for gluing everything together 
-
-Otherwise, all code and documentation comprising this tool was written by Ross Lazarus and is 
-licensed to you under the LGPL_ like other rgenetics artefacts
-
-.. _LGPL: http://www.gnu.org/copyleft/lesser.html
-.. _pickering_code: http://www.researchgate.net/publication/264672640_R_function_for_Risk_Assessment_Plot__reclassification_metrics_NRI_IDI_cfNRI 
-.. _pickering_paper: http://cjasn.asnjournals.org/content/early/2012/05/24/CJN.09590911.full 
-.. _Galaxy: http://getgalaxy.org
-
-
-</help>
-
 <configfiles>
 <configfile name="runme">
-    
+
 <![CDATA[
 
 ### http://www.researchgate.net/publication/264672640_R_function_for_Risk_Assessment_Plot__reclassification_metrics_NRI_IDI_cfNRI code
@@ -159,13 +26,13 @@
 ###
 ###  (c) 2012 Dr John W Pickering, john.pickering@otago.ac.nz, and Dr David Cairns
 ###   Last modified August 2014
-### 
-###  Redistribution and use in source and binary forms, with or without 
+###
+###  Redistribution and use in source and binary forms, with or without
 ###   modification, are permitted provided that the following conditions are met:
-###   * Redistributions of source code must retain the above copyright 
+###   * Redistributions of source code must retain the above copyright
 ###     notice, this list of conditions and the following disclaimer.
-###   * Redistributions in binary form must reproduce the above copyright 
-###     notice, this list of conditions and the following disclaimer in 
+###   * Redistributions in binary form must reproduce the above copyright
+###     notice, this list of conditions and the following disclaimer in
 ###     the documentation and/or other materials provided with the distribution
 
 ### FUNCTIONS
@@ -174,7 +41,7 @@
 ###       Based on: Pickering, J. W. and Endre, Z. H. (2012). New Metrics for Assessing Diagnostic Potential of
 ###       Candidate Biomarkers. Clinical Journal of the American Society of Nephrology, 7, 1355–1364. doi:10.2215/CJN.09590911
 ###
-### statistics.raplot 
+### statistics.raplot
 ###       Produces the NRIs, IDIs, IS, IP, AUCs.
 ###       Based on: Pencina, M. J., D'Agostino, R. B. and Steyerberg, E. W. (2011).
 ### Extensions of net reclassification improvement calculations to measure usefulness of new biomarkers. Statistics in Medicine, 30(1), 11–21. doi:10.1002/sim.4085
@@ -183,7 +50,7 @@
 ###       DeLong, E., DeLong, D. and Clarke-Pearson, D. (1988). Comparing the areas under 2 or more correlated receiver operating characteristic curves - a nonparametric approach.
 ### Biometrics, 44(3), 837–845.
 ###
-### summary.raplot 
+### summary.raplot
 ###       Produces the NRIs, IDIs, IS, IP, AUCs with confidence intervals using a bootstrap or asymptotic procedure. (I prefer bootstrap which is chosed by cis=c("boot"))
 
 
@@ -229,13 +96,13 @@
 
     ### actual plotting
     pdf(outplot)
-    plot(thresh.model1, sens.model1, xlim = c(0, 1), ylim = c(0, 1), type = "n", 
+    plot(thresh.model1, sens.model1, xlim = c(0, 1), ylim = c(0, 1), type = "n",
          lty = 2, lwd = 2, xlab = "Risk of Event", ylab = "", col = "black", main=title)
     grid()
 
-    polygon(x = c(thresh.model1, thresh.model2[n.model2:1]), 
+    polygon(x = c(thresh.model1, thresh.model2[n.model2:1]),
             y = c(sens.model1, sens.model2[n.model2:1]), border = NA, col = gray(0.8))
-    polygon(x = c(thresh.model1, thresh.model2[n.model2:1]), 
+    polygon(x = c(thresh.model1, thresh.model2[n.model2:1]),
             y = c(spec.model1, spec.model2[n.model2:1]), border = NA, col = gray(0.8))
 
     lines(thresh.model1, sens.model1, type = "l", lty = 2, lwd = 2, col = "black")
@@ -246,9 +113,9 @@
 
     text(x = -0.15, y = 0.4, labels = "Sensitivity, ", col = "black", xpd = TRUE, srt = 90)
     text(x = -0.15, y = 0.4 + 0.175, labels = "1-Specificity", col = "red", xpd = TRUE, srt = 90)
-    legend("topleft", c("Event: New model", "Event: Baseline model", 
-                         "No Event: New model", "No Event: Baseline model"), 
-                          col = c("black", "black", "red", "red"), 
+    legend("topleft", c("Event: New model", "Event: Baseline model",
+                         "No Event: New model", "No Event: Baseline model"),
+                          col = c("black", "black", "red", "red"),
                           lty = c(1,2, 1, 2), lwd = 2, bty = "n")
     dev.off()
     return(data.frame("Null.p.sens"=thresh.model1,
@@ -267,8 +134,8 @@
 ### statistics from a raplot (is an adaptation of improveProb() from Hmisc)
 
 statistics.raplot = function(x1, x2, y, threshvec)
-{   
- 
+{
+
     s = is.na(x1 + x2 + y)  ###Remove rows with missing data
     if (any(s)) {
         smiss = sum(s)
@@ -302,7 +169,7 @@
     na = sum(a)
     nb = sum(b)
     d = x2 - x1
-    ### NRI 
+    ### NRI
     n.thresh=length(threshvec)-1
     risk.class.x1.ev=cut2(x1[a],threshvec)
     risk.class.x2.ev=cut2(x2[a],threshvec)
@@ -317,18 +184,18 @@
     pup.ev=0
     pdown.ev=0
     for (i in 1:(n.thresh-1)) { pup.ev = pup.ev + sum(cM.ev\$table[(i+1):n.thresh,i])}
-    for (i in 2:n.thresh) { pdown.ev = pdown.ev + sum(cM.ev\$table[1:(i-1),i])} 
-    pup.ev=pup.ev/na 
+    for (i in 2:n.thresh) { pdown.ev = pdown.ev + sum(cM.ev\$table[1:(i-1),i])}
+    pup.ev=pup.ev/na
     pdown.ev=pdown.ev/na
     risk.class.x1.ne=cut2(x1[b],threshvec)
-    risk.class.x2.ne=cut2(x2[b],threshvec)  
+    risk.class.x2.ne=cut2(x2[b],threshvec)
     levels(risk.class.x1.ne)=thresh
     levels(risk.class.x2.ne)=thresh
     cM.ne=confusionMatrix(risk.class.x2.ne,risk.class.x1.ne)
     pup.ne=0
     pdown.ne=0
     for (i in 1:(n.thresh-1)){pup.ne=pup.ev+sum(cM.ne\$table[(i+1):n.thresh,i])}
-    for (i in 2:n.thresh){pdown.ne=pdown.ne+sum(cM.ne\$table[1:(i-1),i])} 
+    for (i in 2:n.thresh){pdown.ne=pdown.ne+sum(cM.ne\$table[1:(i-1),i])}
     pdown.ne=pdown.ne/nb
     pup.ne=pup.ne/nb
     nri = pup.ev - pdown.ev - (pup.ne - pdown.ne)
@@ -339,7 +206,7 @@
     z.nri.ev = nri.ev/se.nri.ev
     nri.ne = pdown.ne - pup.ne
     se.nri.ne = sqrt((pdown.ne + pup.ne)/nb)
-    z.nri.ne = nri.ne/se.nri.ne 
+    z.nri.ne = nri.ne/se.nri.ne
     ### Category Free NRI calculations
     cfpup.ev = mean(d[a] > 0)
     cfpup.ne = mean(d[b] > 0)
@@ -400,31 +267,31 @@
 
     ### Output
     output = c(n, na, nb, pup.ev, pup.ne, pdown.ev, pdown.ne, nri, se.nri, z.nri,
-                nri.ev, se.nri.ev, z.nri.ev, nri.ne, se.nri.ne, z.nri.ne, 
+                nri.ev, se.nri.ev, z.nri.ev, nri.ne, se.nri.ne, z.nri.ne,
                 cfpup.ev, cfpup.ne, cfpdown.ev, cfpdown.ne, cfnri, se.cfnri, z.cfnri,
-                cfnri.ev, se.cfnri.ev, z.cfnri.ev, cfnri.ne, se.cfnri.ne, z.cfnri.ne, 
-                improveSens, improveSpec, idi.ev, se.idi.ev, z.idi.ev, idi.ne, 
-                se.idi.ne, z.idi.ne, idi, se.idi, z.idi, is.x1, NA, is.x2, NA, 
-                ip.x1, NA, ip.x2, NA, auc.x1, se.auc.x1, auc.x2, se.auc.x2, 
+                cfnri.ev, se.cfnri.ev, z.cfnri.ev, cfnri.ne, se.cfnri.ne, z.cfnri.ne,
+                improveSens, improveSpec, idi.ev, se.idi.ev, z.idi.ev, idi.ne,
+                se.idi.ne, z.idi.ne, idi, se.idi, z.idi, is.x1, NA, is.x2, NA,
+                ip.x1, NA, ip.x2, NA, auc.x1, se.auc.x1, auc.x2, se.auc.x2,
                 roc.test.x1.x2\$p.value,incidence)
-    names(output) = c("n", "na", "nb", "pup.ev", "pup.ne", "pdown.ev", "pdown.ne", 
+    names(output) = c("n", "na", "nb", "pup.ev", "pup.ne", "pdown.ev", "pdown.ne",
                        "nri", "se.nri", "z.nri", "nri.ev", "se.nri.ev", "z.nri.ev",
                        "nri.ne", "se.nri.ne", "z.nri.ne",
-                       "cfpup.ev", "cfpup.ne", "cfpdown.ev", "cfpdown.ne", 
+                       "cfpup.ev", "cfpup.ne", "cfpdown.ev", "cfpdown.ne",
                        "cfnri", "se.cfnri", "z.cfnri", "cfnri.ev", "se.cfnri.ev", "z.cfnri.ev",
                        "cfnri.ne", "se.cfnri.ne", "z.cfnri.ne", "improveSens", "improveSpec",
-                       "idi.ev", "se.idi.ev", "z.idi.ev", "idi.ne", "se.idi.ne", 
-                       "z.idi.ne", "idi", "se.idi", "z.idi", "is.x1", "se.is.x1", 
-                       "is.x2", "se.is.x2", "ip.x1", "se.ip.x1", "ip.x2", "se.ip.x2", 
-                       "auc.x1", "se.auc.x1", "auc.x2", "se.auc.x2", 
+                       "idi.ev", "se.idi.ev", "z.idi.ev", "idi.ne", "se.idi.ne",
+                       "z.idi.ne", "idi", "se.idi", "z.idi", "is.x1", "se.is.x1",
+                       "is.x2", "se.is.x2", "ip.x1", "se.ip.x1", "ip.x2", "se.ip.x2",
+                       "auc.x1", "se.auc.x1", "auc.x2", "se.auc.x2",
                        "roc.test.x1.x2.pvalue","incidence")
     resdf = data.frame(N=n, Na=na, Nb=nb, pup.ev=pup.ev, pup.ne=pup.ne, pdown.ev=pdown.ev, pdown.ne=pdown.ne, NRI=nri, NRI.se=se.nri, NRI.z=z.nri,
-                NRI.ev=nri.ev, NRI.ev.se=se.nri.ev, NRI.ev.z=z.nri.ev, NRI.ne=nri.ne, NRI.ne.se=se.nri.ne, NRI.ne.z=z.nri.ne, 
+                NRI.ev=nri.ev, NRI.ev.se=se.nri.ev, NRI.ev.z=z.nri.ev, NRI.ne=nri.ne, NRI.ne.se=se.nri.ne, NRI.ne.z=z.nri.ne,
                 cfpup.ev=cfpup.ev, cfpup.ne=cfpup.ne, cfpdown.ev=cfpdown.ev, cfpdown.ne=cfpdown.ne, CFNRI=cfnri, CFNRI.se=se.cfnri, CFNRI.z=z.cfnri,
-                CFNRI.ev=cfnri.ev, CFNRI.ev.se=se.cfnri.ev, CFNRI.ev.z=z.cfnri.ev, CFNRI.ne=cfnri.ne, CFNRI.ne.se=se.cfnri.ne, CFNRI.ne.z=z.cfnri.ne, 
-                improvSens=improveSens, improvSpec=improveSpec, IDI.ev=idi.ev, IDI.ev.se=se.idi.ev, IDI.ev.z=z.idi.ev, IDI.ne=idi.ne, 
-                IDI.ne.se=se.idi.ne, IDI.ne.z=z.idi.ne, IDI=idi, IDI.se=se.idi, IDI.z=z.idi, isx1=is.x1, isx2=is.x2, 
-                ipxi=ip.x1, ipx2=ip.x2, AUC.x1=auc.x1, AUC.x1.se=se.auc.x1, AUC.x2=auc.x2, AUC.x2.se=se.auc.x2, 
+                CFNRI.ev=cfnri.ev, CFNRI.ev.se=se.cfnri.ev, CFNRI.ev.z=z.cfnri.ev, CFNRI.ne=cfnri.ne, CFNRI.ne.se=se.cfnri.ne, CFNRI.ne.z=z.cfnri.ne,
+                improvSens=improveSens, improvSpec=improveSpec, IDI.ev=idi.ev, IDI.ev.se=se.idi.ev, IDI.ev.z=z.idi.ev, IDI.ne=idi.ne,
+                IDI.ne.se=se.idi.ne, IDI.ne.z=z.idi.ne, IDI=idi, IDI.se=se.idi, IDI.z=z.idi, isx1=is.x1, isx2=is.x2,
+                ipxi=ip.x1, ipx2=ip.x2, AUC.x1=auc.x1, AUC.x1.se=se.auc.x1, AUC.x2=auc.x2, AUC.x2.se=se.auc.x2,
                 roctestpval=roc.test.x1.x2\$p.value,incidence=incidence)
     tr = t(resdf)
     tresdf = data.frame(measure=colnames(resdf),value=tr[,1])
@@ -453,7 +320,7 @@
                 boot.index = sample(length(y), replace = TRUE)
                 risk.model1.boot = x1[boot.index]
                 risk.model2.boot = x2[boot.index]
-                cc.status.boot = y[boot.index]           
+                cc.status.boot = y[boot.index]
                 r = statistics.raplot(x1 = risk.model1.boot, x2 = risk.model2.boot, y = cc.status.boot)
                 results.boot[i, ] = r\$output
             }
@@ -478,87 +345,87 @@
     results.matrix[2, ] = c("Events (n)", results["na"])
     results.matrix[3, ] = c("Non-events (n)", results["nb"])
     results.matrix[4, ] = c("Category free NRI and summary statistics","-------------------------")
-    results.matrix[5, ] = c("cfNRI events (%)", 
-                             paste(round(100*results["cfnri.ev"], dp-2), " (", 
+    results.matrix[5, ] = c("cfNRI events (%)",
+                             paste(round(100*results["cfnri.ev"], dp-2), " (",
                                    round(100*results["cfnri.ev"] - z * 100*results["se.cfnri.ev"], dp-2),
-                                    " to ", round(100*results["cfnri.ev"] + 
+                                    " to ", round(100*results["cfnri.ev"] +
                                       z * 100*results["se.cfnri.ev"], dp-2), ")", sep = ""))
-    results.matrix[6, ] = c("cfNRI non-events (%)", 
+    results.matrix[6, ] = c("cfNRI non-events (%)",
                              paste(round(100*results["cfnri.ne"], dp-2), " (",
                              round(100*results["cfnri.ne"] - z * 100*results["se.cfnri.ne"], dp)-2,
-                             " to ", round(100*results["cfnri.ne"] +  z * 100*results["se.cfnri.ne"], 
-                                           dp-2), ")", sep = "")) 
-    results.matrix[7, ] = c("cfNRI (%)", 
-                             paste(round(100*results["cfnri"], dp-2), " (", 
-                             round(100*results["cfnri"] - z * 100*results["se.cfnri"], dp-2), 
-                             " to ", round(100*results["cfnri"] + z * 100*results["se.cfnri"], 
+                             " to ", round(100*results["cfnri.ne"] +  z * 100*results["se.cfnri.ne"],
+                                           dp-2), ")", sep = ""))
+    results.matrix[7, ] = c("cfNRI (%)",
+                             paste(round(100*results["cfnri"], dp-2), " (",
+                             round(100*results["cfnri"] - z * 100*results["se.cfnri"], dp-2),
+                             " to ", round(100*results["cfnri"] + z * 100*results["se.cfnri"],
                                            dp-2), ")", sep = ""))
     results.matrix[8, ] = c("NRI and summary statistics","-------------------------")
-    results.matrix[9, ] = c("NRI events (%)", 
-                             paste(round(100*results["nri.ev"], dp-2), " (", 
+    results.matrix[9, ] = c("NRI events (%)",
+                             paste(round(100*results["nri.ev"], dp-2), " (",
                                    round(100*results["nri.ev"] - z * 100*results["se.nri.ev"], dp-2),
-                                   " to ", round(100*results["nri.ev"] + 
+                                   " to ", round(100*results["nri.ev"] +
                                                    z * 100*results["se.nri.ev"], dp-2), ")", sep = ""))
-    results.matrix[10, ] = c("NRI non-events (%)", 
+    results.matrix[10, ] = c("NRI non-events (%)",
                              paste(round(100*results["nri.ne"], dp-2), " (",
                                    round(100*results["nri.ne"] - z * 100*results["se.nri.ne"], dp-2),
-                                   " to ", round(100*results["nri.ne"] +  z * 100*results["se.nri.ne"], 
-                                                 dp-2), ")", sep = "")) 
-    results.matrix[11, ] = c("NRI (%)", 
-                             paste(round(100*results["nri"], dp-2), " (", 
-                                   round(100*results["nri"] - z * 100*results["se.nri"], dp-2), 
-                                   " to ", round(100*results["nri"] + z * 100*results["se.nri"], 
+                                   " to ", round(100*results["nri.ne"] +  z * 100*results["se.nri.ne"],
+                                                 dp-2), ")", sep = ""))
+    results.matrix[11, ] = c("NRI (%)",
+                             paste(round(100*results["nri"], dp-2), " (",
+                                   round(100*results["nri"] - z * 100*results["se.nri"], dp-2),
+                                   " to ", round(100*results["nri"] + z * 100*results["se.nri"],
                                                  dp-2), ")", sep = ""))
     results.matrix[12, ] = c("IDI and summary statistics","-------------------------")
-    results.matrix[13, ] = c("IDI events", 
-                             paste(round(results["idi.ev"], dp), " (", 
-                              round(results["idi.ev"] - z * results["se.idi.ev"], dp), 
-                              " to ", round(results["idi.ev"] + z * results["se.idi.ev"], 
+    results.matrix[13, ] = c("IDI events",
+                             paste(round(results["idi.ev"], dp), " (",
+                              round(results["idi.ev"] - z * results["se.idi.ev"], dp),
+                              " to ", round(results["idi.ev"] + z * results["se.idi.ev"],
                                             dp), ")", sep = ""))
-    results.matrix[14, ] = c("IDI non-events", 
-                              paste(round(results["idi.ne"], dp), " (", 
-                              round(results["idi.ne"] - z * results["se.idi.ne"], dp), 
-                              " to ", round(results["idi.ne"] + z * results["se.idi.ne"], 
+    results.matrix[14, ] = c("IDI non-events",
+                              paste(round(results["idi.ne"], dp), " (",
+                              round(results["idi.ne"] - z * results["se.idi.ne"], dp),
+                              " to ", round(results["idi.ne"] + z * results["se.idi.ne"],
                                             dp), ")", sep = ""))
-    results.matrix[15, ] = c("IDI", 
-                              paste(round(results["idi"], dp), " (", 
-                              round(results["idi"] - z * results["se.idi"], dp), 
-                              " to ", round(results["idi"] + z * results["se.idi"], 
+    results.matrix[15, ] = c("IDI",
+                              paste(round(results["idi"], dp), " (",
+                              round(results["idi"] - z * results["se.idi"], dp),
+                              " to ", round(results["idi"] + z * results["se.idi"],
                               dp), ")", sep = ""))
-    results.matrix[16, ] = c("IS (null model)", 
-                              paste(round(results["is.x1"], dp), " (", 
-                              round(results["is.x1"] - z * results["se.is.x1"], dp), 
-                              " to ", round(results["is.x1"] + z * results["se.is.x1"], 
+    results.matrix[16, ] = c("IS (null model)",
+                              paste(round(results["is.x1"], dp), " (",
+                              round(results["is.x1"] - z * results["se.is.x1"], dp),
+                              " to ", round(results["is.x1"] + z * results["se.is.x1"],
                                             dp), ")", sep = ""))
-    results.matrix[17, ] = c("IS (alt model)", 
-                              paste(round(results["is.x2"], dp), " (", 
-                              round(results["is.x2"] - z * results["se.is.x2"], dp), 
-                              " to ", round(results["is.x2"] + z * results["se.is.x2"], 
+    results.matrix[17, ] = c("IS (alt model)",
+                              paste(round(results["is.x2"], dp), " (",
+                              round(results["is.x2"] - z * results["se.is.x2"], dp),
+                              " to ", round(results["is.x2"] + z * results["se.is.x2"],
                                             dp), ")", sep = ""))
-    results.matrix[18, ] = c("IP (null model)", 
-                              paste(round(results["ip.x1"], dp), " (", 
-                              round(results["ip.x1"] - z * results["se.ip.x1"], dp), 
-                              " to ", round(results["ip.x1"] + z *  results["se.ip.x1"], 
+    results.matrix[18, ] = c("IP (null model)",
+                              paste(round(results["ip.x1"], dp), " (",
+                              round(results["ip.x1"] - z * results["se.ip.x1"], dp),
+                              " to ", round(results["ip.x1"] + z *  results["se.ip.x1"],
                                             dp), ")", sep = ""))
-    results.matrix[19, ] = c("IP (alt model)", 
-                              paste(round(results["ip.x2"], dp), " (", 
-                              round(results["ip.x2"] - z * results["se.ip.x2"], dp), 
-                              " to ", round(results["ip.x2"] + z * results["se.ip.x2"], 
+    results.matrix[19, ] = c("IP (alt model)",
+                              paste(round(results["ip.x2"], dp), " (",
+                              round(results["ip.x2"] - z * results["se.ip.x2"], dp),
+                              " to ", round(results["ip.x2"] + z * results["se.ip.x2"],
                                             dp), ")", sep = ""))
     results.matrix[20, ] = c("AUC","-------------------------")
-    results.matrix[21, ] = c("AUC (null model)", 
-                              paste(round(results["auc.x1"], dp), " (", 
-                              round(results["auc.x1"] - z * results["se.auc.x1"], dp), 
-                              " to ", round(results["auc.x1"] + z * results["se.auc.x1"], 
+    results.matrix[21, ] = c("AUC (null model)",
+                              paste(round(results["auc.x1"], dp), " (",
+                              round(results["auc.x1"] - z * results["se.auc.x1"], dp),
+                              " to ", round(results["auc.x1"] + z * results["se.auc.x1"],
                                             dp), ")", sep = ""))
-    results.matrix[22, ] = c("AUC (alt model)", 
-                              paste(round(results["auc.x2"], dp), " (", 
-                              round(results["auc.x2"] - z * results["se.auc.x2"], dp), 
-                              " to ", round(results["auc.x2"] +  z * results["se.auc.x2"], 
+    results.matrix[22, ] = c("AUC (alt model)",
+                              paste(round(results["auc.x2"], dp), " (",
+                              round(results["auc.x2"] - z * results["se.auc.x2"], dp),
+                              " to ", round(results["auc.x2"] +  z * results["se.auc.x2"],
                                             dp), ")", sep = ""))
     results.matrix[23, ] = c("difference (P)", round(results["roc.test.x1.x2.pvalue"], dp))
     results.matrix[24, ] = c("Incidence", round(results["incidence"], dp))
-    
+
     return(results.matrix)
 }
 
@@ -624,6 +491,139 @@
 sink()
 </configfile>
 </configfiles>
+  <inputs>
+     <param name="title" type="text" value="NRI test" size="80" label="Plot Title" help="Will appear as the title for the comparison plot"/>
+    <param name="input1"  type="data" format="tabular" label="Select a tabular file from the baseline model with predicted and observed outcome column for each subject"
+    multiple='False' help="Observed and predicted status columns must be selected from this file below - NOTE both models must be in same order with exact matches in all observed outcomes" optional="False"/>
+    <param name="input1_observed" label="Select column containing observed outcome (0 for no event, 1 for an event)" type="data_column" data_ref="input1" numerical="True"
+         multiple="False" use_header_names="True" optional="False" help = "Observed outcomes are compared in the two files to check that the datasets are from the same data"/>
+    <param name="input1_predicted" label="Select column containing predicted event probabilies from baseline model" type="data_column" data_ref="input1" numerical="True"
+         multiple="False" use_header_names="True" optional="False"  help="Must be in range 0-1"/>
+    <param name="input1_id" label="Select column containing subject ID from baseline model" type="data_column" data_ref="input1" numerical="True"
+         multiple="False" use_header_names="True" optional="False" help="Subect IDs are needed to match subjects to compare predictions in the two inputs"/>
+    <param name="input2"  type="data" format="tabular" label="Select a tabular file from the new model with predicted and observed outcome columns for each subject"
+    multiple='False' help="Observed and predicted status columns must be selected from this file below" />
+    <param name="input2_observed" label="Select column containing observed outcome (0 for no event, 1 for an event)" type="data_column" data_ref="input2" numerical="True"
+         multiple="False" use_header_names="True" optional="False" help = "Observed outcomes are compared in the two files to check that the datasets are from the same data"/>
+    <param name="input2_predicted" label="Select column containing predicted event probabilities from the new model" type="data_column" data_ref="input2" numerical="True"
+         multiple="False" use_header_names="True" optional="False" help="Must be in range 0-1"/>
+    <param name="input2_id" label="Select column containing subject ID from the new model" type="data_column" data_ref="input2" numerical="True"
+         multiple="False" use_header_names="True" optional="False"  help="Subect IDs are needed to match subjects to compare predictions in the two inputs"/>
+    <conditional name="CImeth">
+        <param name="cis" type="select" label="CI calculation method"
+             help="Bootstrap will take time - a long time for thousands - asymptotic is quick and informative">
+                <option value="asymptotic" selected="true">Asymptotic estimate</option>
+                <option value="boot">Bootstrap for empirical CIs</option>
+        </param>
+        <when value="boot">
+            <param name="nboot" type="integer" value="1000" label="Number of bootstrap replicates"/>
+        </when>
+        <when value="asymptotic">
+            <param name="nboot" type="hidden" value="1000"/>
+        </when>
+    </conditional>
+  </inputs>
+  <outputs>
+    <data format="html" name="html_file" label="${title}.html"/>
+    <data format="tabular" name="nri_file" label="${title}_nrires.xls"/>
+  </outputs>
+ <tests>
+    <test>
+     <param name='title' value='nri_test1' />
+     <param name='input1' value='nri_test1.xls' ftype='tabular' />
+     <param name='input2' value='nri_test1.xls' ftype='tabular' />
+     <param name='input1_id' value="1" />
+     <param name='input1_observed' value="2" />
+     <param name='input1_predicted' value="3" />
+     <param name='input2_observed' value="2" />
+     <param name='input2_predicted' value="4" />
+     <output name='html_file' file='nri_test1_out.html'  compare='diff' lines_diff='10' />
+     <output name='nri_file' file='nri_test1_out.xls' />
+    </test>
+</tests>
+<help>
+
+**Before you start**
+
+This is a simple tool to calculate various measures of improvement in prediction between two models described in pickering_paper_
+It is based on an R script pickering_code_ written by Dr John W Pickering and Dr David Cairns from sunny Otago University which
+has been debugged and slightly adjusted to fit a Galaxy tool wrapper.
+
+
+**What it does**
+
+Copied from the documentation in pickering_code_ ::
+
+
+    Functions to create risk assessment plots and associated summary statistics
+
+
+      (c) 2012 Dr John W Pickering, john.pickering@otago.ac.nz, and Dr David Cairns
+       Last modified August 2014
+
+      Redistribution and use in source and binary forms, with or without
+       modification, are permitted provided that the following conditions are met:
+       * Redistributions of source code must retain the above copyright
+         notice, this list of conditions and the following disclaimer.
+       * Redistributions in binary form must reproduce the above copyright
+         notice, this list of conditions and the following disclaimer in
+         the documentation and/or other materials provided with the distribution
+
+     FUNCTIONS
+     raplot
+           Produces a Risk Assessment Plot and outputs the coordinates of the four curves
+           Based on: Pickering, J. W. and Endre, Z. H. (2012). New Metrics for Assessing Diagnostic Potential of
+           Candidate Biomarkers. Clinical Journal of the American Society of Nephrology, 7, 1355–1364. doi:10.2215/CJN.09590911
+
+     statistics.raplot
+           Produces the NRIs, IDIs, IS, IP, AUCs.
+           Based on: Pencina, M. J., D'Agostino, R. B. and Steyerberg, E. W. (2011). Extensions of net reclassification improvement calculations to
+           measure usefulness of new biomarkers. Statistics in Medicine, 30(1), 11–21. doi:10.1002/sim.4085
+           Pencina, M. J., D'Agostino, R. B. and Vasan, R. S. (2008). Evaluating the added predictive ability of a new marker: From area under the
+           ROC curve to reclassification and beyond.
+           Statistics in Medicine, 27(2), 157–172. doi:10.1002/sim.2929
+           DeLong, E., DeLong, D. and Clarke-Pearson, D. (1988). Comparing the areas under 2 or more correlated receiver operating characteristic curves - a nonparametric approach.
+           Biometrics, 44(3), 837–845.
+
+     summary.raplot
+           Produces the NRIs, IDIs, IS, IP, AUCs with confidence intervals using a bootstrap or asymptotic procedure. (I prefer bootstrap which is chosed by cis=c("boot"))
+
+
+     Required arguments for all functions:
+       x1 is calculated risk (eg from a glm) for the null model, i.e. predict(,type="response") on a glm object
+       x2 is calculated risk (eg from a glm) for the alternative model
+       y is the case-control indicator (0 for controls, 1 for cases)
+     Optional argument
+       t are the boundaries of the risks for each group (ie 0, 1 and the thresholds beteween.  eg c(0,0,3,0,7,1)). If missing, defaults to c(0, the incidence, 1)
+
+
+**Input**
+
+The observed and predicted outcomes from two models to be compared.
+
+**Output**
+
+Lots'o'measures (TM) see pickering_paper_ for details
+
+**Attributions**
+
+pickering_paper_ is the paper the caclulations performed by this tool is based on
+
+pickering_code_ is the R function from John Pickering exposed by this Galaxy tool with minor modifications and hacks by Ross Lazarus.
+
+Galaxy_ (that's what you are using right now!) for gluing everything together
+
+Otherwise, all code and documentation comprising this tool was written by Ross Lazarus and is
+licensed to you under the LGPL_ like other rgenetics artefacts
+
+.. _LGPL: http://www.gnu.org/copyleft/lesser.html
+.. _pickering_code: http://www.researchgate.net/publication/264672640_R_function_for_Risk_Assessment_Plot__reclassification_metrics_NRI_IDI_cfNRI
+.. _pickering_paper: http://cjasn.asnjournals.org/content/early/2012/05/24/CJN.09590911.full
+.. _Galaxy: http://getgalaxy.org
+
+
+</help>
+
 <citations>
     <citation type="doi">doi: 10.2215/​CJN.09590911</citation>
 </citations>