Browse code

- Article for registering new function written.

Dario Strbenac authored on 11/11/2022 05:00:17
Showing 4 changed files

... ...
@@ -1,6 +1,6 @@
1 1
 # ClassifyR: Performance evaluation for multi-view data sets and seamless integration with MultiAssayExperiment and Bioconductor
2 2
 
3
-<img src="inst/ClassifyRsticker.png" align="right">
3
+<img src="man/figures/ClassifyRsticker.png" align="right">
4 4
 
5 5
 ClassifyR's performance evaluation focuses on model stability and interpretability. Based on repeated cross-validation, it is possible to evaluate feature selection stability and also per-sample prediction accuracy. Also, multiple omics data assays on the same samples are becoming more popular and ClassifyR supports a range of multi-view methods to evaluate which data view is the most predictive and combine data views to evaluate if multiple views provide superior predictive performance to a single data view.
6 6
 
... ...
@@ -58,10 +58,12 @@
58 58
 
59 59
 
60 60
 
61
-<script src="incorporateNew_files/accessible-code-block-0.0.1/empty-anchor.js"></script><div class="row">
61
+
62
+<div class="row">
62 63
   <main id="main" class="col-md-9"><div class="page-header">
63 64
       <img src="" class="logo" alt=""><h1>Creating a Wrapper for New Functionality and Registering It</h1>
64
-                        <h4 data-toc-skip class="author">John Citizen <br> The University of Sydney, Australia.</h4>
65
+                        <h4 data-toc-skip class="author">Dario Strbenac
66
+<br> The University of Sydney, Australia.</h4>
65 67
             
66 68
       
67 69
       
... ...
@@ -73,7 +75,72 @@
73 75
 <div class="section level2">
74 76
 <h2 id="introduction">Introduction<a class="anchor" aria-label="anchor" href="#introduction"></a>
75 77
 </h2>
76
-<p>Placeholder.</p>
78
+<p>There might be a new transformation / selection / modelling algorithm
79
+that’s not a part of ClassifyR but might be useful to others. This guide
80
+explains the necessary steps to perform before making a pull request to
81
+get new functionality added.</p>
82
+<p>The core framework dispatches the data as a <code>DataFrame</code>
83
+object, so the new function should be able to accept such a variable
84
+type as its first argument.</p>
85
+</div>
86
+<div class="section level2">
87
+<h2 id="steps-to-add-a-new-function">Steps to Add a New Function<a class="anchor" aria-label="anchor" href="#steps-to-add-a-new-function"></a>
88
+</h2>
89
+<ol style="list-style-type: decimal">
90
+<li>Define an ordinary R function and attach a name to it. This will be
91
+useful in automated annotation of modelling results later. A basic
92
+outline is:</li>
93
+</ol>
94
+<div class="sourceCode" id="cb1"><pre class="downlit sourceCode r">
95
+<code class="sourceCode R"><span><span class="va">newFancyClassifier</span> <span class="op">&lt;-</span> <span class="kw">function</span><span class="op">(</span><span class="va">measurementsTrain</span>, <span class="va">classesTrain</span>, <span class="va">alpha</span>, <span class="va">...</span>, <span class="va">verbose</span> <span class="op">=</span> <span class="fl">3</span><span class="op">)</span></span>
96
+<span><span class="op">{</span></span>
97
+<span>  <span class="co"># Build a model.  </span></span>
98
+<span><span class="op">}</span></span>
99
+<span><span class="fu"><a href="https://rdrr.io/r/base/attr.html" class="external-link">attr</a></span><span class="op">(</span><span class="va">newFancyClassifier</span>, <span class="st">"name"</span><span class="op">)</span> <span class="op">&lt;-</span> <span class="st">"newFancyClassifier"</span></span></code></pre></div>
100
+<ol start="2" style="list-style-type: decimal">
101
+<li>Open the file constants.R. In the
102
+<code>.ClassifyRenvir[["functionsTable"]]</code> two-column matrix, add
103
+a row specifying the function name and a nice title to use for plot
104
+labelling. For example,</li>
105
+</ol>
106
+<div class="sourceCode" id="cb2"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a>.ClassifyRenvir[[<span class="st">"functionsTable"</span>]] <span class="ot">&lt;-</span> <span class="fu">matrix</span>(</span>
107
+<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a>    ...        ...</span>
108
+<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a><span class="st">"newFancyClassifier"</span>, <span class="st">"Fancy Classifier"</span>),</span>
109
+<span id="cb2-4"><a href="#cb2-4" aria-hidden="true" tabindex="-1"></a>    ...        ...</span></code></pre></div>
110
+<ol start="3" style="list-style-type: decimal">
111
+<li>Add a keyword that users will use when the want to use the function
112
+in cross-validation to one of the keywords two-column matrices along
113
+with a short one-sentence description. In the example, the new function
114
+is a classifier, so it is added to the end of the
115
+<code>"classifyKeywords"</code> matrix.</li>
116
+</ol>
117
+<div class="sourceCode" id="cb3"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a>.ClassifyRenvir[[<span class="st">"classifyKeywords"</span>]] <span class="ot">&lt;-</span> <span class="fu">matrix</span>(</span>
118
+<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a>    ...        ...</span>
119
+<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a><span class="st">"fancy"</span>, <span class="st">"Very good classifier that predicts amazingly well."</span>),</span>
120
+<span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a>    ...        ...</span></code></pre></div>
121
+<ol start="4" style="list-style-type: decimal">
122
+<li><p>Depending on what kind of functionality the new function
123
+provides, add an entry into either
124
+<code>.selectionKeywordToFunction</code> or
125
+<code>.classifierKeywordToParams</code> functions in utilities.R. The
126
+first function maps a feature selection keyword to a wrapper function
127
+and the second maps a classifier keyword into a pair of
128
+<code>TrainParams</code> and <code>PredictParams</code> objects, which
129
+specify the functions of training and prediction stages.</p></li>
130
+<li><p>If the function is a classifier, open simpleParams.R and define
131
+the <code>TrainParams</code> and <code>PredictParams</code> parameter
132
+sets there. If the classifier has any tuning parameters, it would be
133
+good to specify a small range of values to try, since crossValidate for
134
+simplicity doesn’t allow anything other than a keyword to be specified
135
+by the user.</p></li>
136
+<li><p>Open the vignette in vignettes/ClassifyR.Rmd and look for the
137
+section heading #### Provided Methods for Feature Selection and
138
+Classification. Add the new function to the appropriate table.</p></li>
139
+</ol>
140
+<p>Now that the new function is defined and described, users will be
141
+able to discover it using <code><a href="../reference/available.html">available()</a></code> at the R command line
142
+and results will automatically store nice names for the functions used
143
+and they will automatically be able to be shown in plots.</p>
77 144
 </div>
78 145
   </main><aside class="col-md-3"><nav id="toc"><h2>On this page</h2>
79 146
     </nav></aside>
... ...
@@ -52,9 +52,9 @@
52 52
         <dd>
53 53
         </dd><dt><a href="incorporateNew.html">Creating a Wrapper for New Functionality and Registering It</a></dt>
54 54
         <dd>
55
-        </dd><dt><a href="ClassifyR.html">An Introduction to ClassifyR</a></dt>
55
+        </dd><dt><a href="ClassifyR.html">An Introduction to **ClassifyR**</a></dt>
56 56
         <dd>
57
-        </dd><dt><a href="DevelopersGuide.html">ClassifyR Developer's Guide</a></dt>
57
+        </dd><dt><a href="DevelopersGuide.html">**ClassifyR** Developer's Guide</a></dt>
58 58
         <dd>
59 59
       </dd></dl></div>
60 60
   </main></div>
... ...
@@ -1,6 +1,6 @@
1 1
 ---
2 2
 title: "Creating a Wrapper for New Functionality and Registering It"
3
-author: John Citizen <br>
3
+author: Dario Strbenac <br>
4 4
         The University of Sydney, Australia.
5 5
 output: 
6 6
     BiocStyle::html_document:
... ...
@@ -10,4 +10,44 @@ output:
10 10
 
11 11
 ## Introduction
12 12
 
13
-Placeholder.
14 13
\ No newline at end of file
14
+There might be a new transformation / selection / modelling algorithm that's not a part of ClassifyR but might be useful to others. This guide explains the necessary steps to perform before making a pull request to get new functionality added.
15
+
16
+The core framework dispatches the data as a `DataFrame` object, so the new function should be able to accept such a variable type as its first argument.
17
+
18
+## Steps to Add a New Function
19
+
20
+1. Define an ordinary R function and attach a name to it. This will be useful in automated annotation of modelling results later. A basic outline is:
21
+
22
+```{r}
23
+newFancyClassifier <- function(measurementsTrain, classesTrain, alpha, ..., verbose = 3)
24
+{
25
+  # Build a model.  
26
+}
27
+attr(newFancyClassifier, "name") <- "newFancyClassifier"
28
+```
29
+
30
+2. Open the file constants.R. In the `.ClassifyRenvir[["functionsTable"]]` two-column matrix, add a row specifying the function name and a nice title to use for plot labelling. For example,
31
+
32
+```{r, eval = FALSE}
33
+.ClassifyRenvir[["functionsTable"]] <- matrix(
34
+    ...        ...
35
+"newFancyClassifier", "Fancy Classifier"),
36
+    ...        ...
37
+```
38
+
39
+3. Add a keyword that users will use when the want to use the function in cross-validation to one of the keywords two-column matrices along with a short one-sentence description. In the example, the new function is a classifier, so it is added to the end of the `"classifyKeywords"` matrix.
40
+
41
+```{r, eval = FALSE}
42
+.ClassifyRenvir[["classifyKeywords"]] <- matrix(
43
+    ...        ...
44
+"fancy", "Very good classifier that predicts amazingly well."),
45
+    ...        ...
46
+```
47
+
48
+4. Depending on what kind of functionality the new function provides, add an entry into either `.selectionKeywordToFunction` or `.classifierKeywordToParams` functions in utilities.R. The first function maps a feature selection keyword to a wrapper function and the second maps a classifier keyword into a pair of `TrainParams` and `PredictParams` objects, which specify the functions of training and prediction stages.
49
+
50
+5. If the function is a classifier, open simpleParams.R and define the `TrainParams` and `PredictParams` parameter sets there. If the classifier has any tuning parameters, it would be good to specify a small range of values to try, since crossValidate for simplicity doesn't allow anything other than a keyword to be specified by the user.
51
+
52
+6. Open the vignette in vignettes/ClassifyR.Rmd and look for the section heading #### Provided Methods for Feature Selection and Classification. Add the new function to the appropriate table.
53
+
54
+Now that the new function is defined and described, users will be able to discover it using `available()` at the R command line and results will automatically store nice names for the functions used and they will automatically be able to be shown in plots.
15 55
\ No newline at end of file