Skip to content

Commit

Permalink
Merge pull request #9 from kbroman/main
Browse files Browse the repository at this point in the history
Fix get_geno() + remove things that don't work
  • Loading branch information
kbroman authored Oct 25, 2022
2 parents a0ff43d + 074d7bf commit 173e7d3
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 65 deletions.
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: GNapi
Version: 0.3-4
Date: 2021-11-17
Version: 0.3-6
Date: 2022-09-26
Title: Connection to the GeneNetwork API
Description: Tools for connecting to the GeneNetwork API.
Author: Karl W Broman [aut, cre] (<https://orcid.org/0000-0002-4914-6671>)
Expand All @@ -26,5 +26,5 @@ LazyData: true
Encoding: UTF-8
ByteCompile: true
VignetteBuilder: knitr
RoxygenNote: 7.2.0
RoxygenNote: 7.2.1
Roxygen: list(markdown=TRUE)
5 changes: 3 additions & 2 deletions R/get_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ get_pheno <-
#'
#' @param group Name of group
#' @param url The URL for the GeneNetwork API
#' @param format The group's genotypes format
#'
#' @return A data frame
#'
Expand All @@ -72,11 +73,11 @@ get_pheno <-
#' @examples
#' g <- get_geno("QSM")
get_geno <-
function(group, url=gnapi_url())
function(group, url=gnapi_url(), format = "geno")
{
stopifnot(length(group) == 1)

result <- query_gn(paste0("genotypes/", group), url=url, output="text")
result <- query_gn(paste0("genotypes/", group, ".", format), url=url, output="text")

# replace @ with #
result <- gsub("@", "#", result, fixed=TRUE)
Expand Down
14 changes: 3 additions & 11 deletions R/get_info.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#'
#' @param group Name of a group of datasets
#' @param trait Trait identifier (can be a vector)
#' @param limit Limit on number of traits to return (if `trait` is `NULL`)
#' @param url The URL for the GeneNetwork API
#'
#' @return A data frame
Expand All @@ -13,20 +12,13 @@
#'
#' @examples
#' info_pheno("BXD", "10002")
#' info_pheno("HC_M2_0606_P", limit=10)
#' info_pheno("HC_M2_0606_P", "1436869_at")
#' info_pheno("HXBBXH", limit=10)
info_pheno <-
function(group, trait=NULL, limit=NULL, url=gnapi_url())
function(group, trait, url=gnapi_url())
{
stopifnot(length(group)==1)
if(is.null(trait) || trait == "") {
query <- paste0("traits/", group)
if(!is.null(limit)) {
query <- paste0(query, "?limit_to=", limit)
}
result <- query_gn(query, url)
return(list2df(result))
if(is.null(trait) || (length(trait)==1 && trait == "")) {
stop("trait must be provided; can be a vector")
}

if(length(trait) > 1) {
Expand Down
16 changes: 2 additions & 14 deletions R/get_lists.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ list_species <-
#' Get list of available groups
#'
#' @param species Optional species name, for just the groups for that species.
#' @param group Optional name for a specific group
#' @param url URL for GeneNetwork API
#'
#' @return Data frame with columns `FullName`, `Id`, `Name`, and `TaxonomyId`.
Expand All @@ -45,21 +44,10 @@ list_species <-
#' @examples
#' list_groups()
#' list_groups("barley")
#' list_groups("rat", "HSNIH-Palmer")
#' list_groups(group="HSNIH-Palmer")
list_groups <-
function(species=NULL, group=NULL, url=gnapi_url())
function(species=NULL, url=gnapi_url())
{
if(!is.null(group) && group != "") { # note this uses group/ rather than groups/
query <- "group/"
if(!is.null(species) && species != "") {
query <- paste0(query, "/", species)
}
result <- query_gn(paste0(query, "/", group), url=url)
if(is.null(result)) return(NULL)
return(as.data.frame(result))
}
else if(!is.null(species) && species != "") {
if(!is.null(species) && species != "") {
stopifnot(length(species)==1)
result <- query_gn(paste0("groups/", species), url=url)
} else {
Expand Down
2 changes: 1 addition & 1 deletion R/run_stuff.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#' @export
#'
#' @examples
#' out <- run_gemma("BXDPublish", "10015")
#' \dontrun{out <- run_gemma("BXDPublish", "10015")}
run_gemma <-
function(dataset, trait, use_loco=FALSE, maf=0.01, url=gnapi_url())
{
Expand Down
31 changes: 18 additions & 13 deletions docs/GNapi.html
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,20 @@
for (var i = 0; i < sheets.length; i++) {
if (sheets[i].ownerNode.dataset["origin"] !== "pandoc") continue;
try { var rules = sheets[i].cssRules; } catch (e) { continue; }
for (var j = 0; j < rules.length; j++) {
var j = 0;
while (j < rules.length) {
var rule = rules[j];
// check if there is a div.sourceCode rule
if (rule.type !== rule.STYLE_RULE || rule.selectorText !== "div.sourceCode") continue;
if (rule.type !== rule.STYLE_RULE || rule.selectorText !== "div.sourceCode") {
j++;
continue;
}
var style = rule.style.cssText;
// check if color or background-color is set
if (rule.style.color === '' && rule.style.backgroundColor === '') continue;
if (rule.style.color === '' && rule.style.backgroundColor === '') {
j++;
continue;
}
// replace div.sourceCode by a pre.sourceCode rule
sheets[i].deleteRule(j);
sheets[i].insertRule('pre.sourceCode{' + style + '}', j);
Expand Down Expand Up @@ -384,16 +391,14 @@ <h3>Fetch individual phenotype info</h3>
</div>
<div id="fetch-trait-information" class="section level2">
<h2>Fetch trait information</h2>
<p>This is mostly information about QTL location (LRS score and
marker).</p>
<p>You can get all traits within a microarray dataset, possibly limiting
the results to some number.</p>
<div class="sourceCode" id="cb13"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a><span class="fu">info_pheno</span>(<span class="st">&quot;HC_M2_0606_P&quot;</span>, <span class="at">limit=</span><span class="dv">10</span>)</span></code></pre></div>
<p>Or you can use a group name, again possibly limiting the results to
some number.</p>
<div class="sourceCode" id="cb14"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true" tabindex="-1"></a><span class="fu">info_pheno</span>(<span class="st">&quot;HXBBXH&quot;</span>, <span class="at">limit=</span><span class="dv">10</span>)</span></code></pre></div>
<p>Or you can get the information for a single trait.</p>
<div class="sourceCode" id="cb15"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true" tabindex="-1"></a><span class="fu">info_pheno</span>(<span class="st">&quot;HC_M2_0606_P&quot;</span>, <span class="st">&quot;1436869_at&quot;</span>)</span></code></pre></div>
<p>This is mostly information about QTL location (LRS score and marker).
You need to provide a group and a trait, such as a probeset on a
microarray:</p>
<div class="sourceCode" id="cb13"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a><span class="fu">info_pheno</span>(<span class="st">&quot;HC_M2_0606_P&quot;</span>, <span class="st">&quot;1436869_at&quot;</span>)</span></code></pre></div>
<p>Or a traditional phenotype:</p>
<div class="sourceCode" id="cb14"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true" tabindex="-1"></a><span class="fu">info_pheno</span>(<span class="st">&quot;BXD&quot;</span>, <span class="st">&quot;10002&quot;</span>)</span></code></pre></div>
<p>You can provide a vector of trait identifiers:</p>
<div class="sourceCode" id="cb15"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true" tabindex="-1"></a><span class="fu">info_pheno</span>(<span class="st">&quot;BXD&quot;</span>, <span class="fu">c</span>(<span class="st">&quot;10002&quot;</span>, <span class="st">&quot;10010&quot;</span>, <span class="st">&quot;10100&quot;</span>))</span></code></pre></div>
</div>
<div id="fetch-sample-data-for-a-single-trait" class="section level2">
<h2>Fetch sample data for a single trait</h2>
Expand Down
4 changes: 3 additions & 1 deletion man/get_geno.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions man/info_pheno.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions man/list_groups.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/run_gemma.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 6 additions & 9 deletions vignettes/GNapi.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -105,25 +105,22 @@ list_datasets("bxd", "10001")
## Fetch trait information

This is mostly information about QTL location (LRS score and marker).

You can get all traits within a microarray dataset, possibly limiting the results
to some number.
You need to provide a group and a trait, such as a probeset on a microarray:

```r
info_pheno("HC_M2_0606_P", limit=10)
info_pheno("HC_M2_0606_P", "1436869_at")
```

Or you can use a group name, again possibly limiting the results to
some number.
Or a traditional phenotype:

```r
info_pheno("HXBBXH", limit=10)
info_pheno("BXD", "10002")
```

Or you can get the information for a single trait.
You can provide a vector of trait identifiers:

```r
info_pheno("HC_M2_0606_P", "1436869_at")
info_pheno("BXD", c("10002", "10010", "10100"))
```


Expand Down

0 comments on commit 173e7d3

Please sign in to comment.