/
helminthR_vignette.Rmd
191 lines (115 loc) · 5.15 KB
/
helminthR_vignette.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
---
title: "Introduction to the helminthR package"
author: "Tad Dallas"
date: ""
output:
html_document:
toc: true
toc_float: true
theme: readable
vignette: >
%\VignetteIndexEntry{Introduction to the helminthR package}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r echo=FALSE}
library(knitr)
hook_output <- knitr::knit_hooks$get("output")
knitr::knit_hooks$set(output = function(x, options) {
lines <- options$output.lines
if (is.null(lines)) {
return(hook_output(x, options)) # pass to default hook
}
x <- unlist(strsplit(x, "\n"))
more <- "..."
if (length(lines)==1) { # first n lines
if (length(x) > lines) {
# truncate the output, but add ....
x <- c(head(x, lines), more)
}
} else {
x <- c(if (abs(lines[1])>1) more else NULL,
x[lines],
if (length(x)>lines[abs(length(lines))]) more else NULL
)
}
# paste these lines together
x <- paste(c(x, ""), collapse = "\n")
hook_output(x, options)
})
knitr::opts_chunk$set(
comment = "#>",
collapse = TRUE,
warning = FALSE,
message = FALSE
)
library(helminthR)
```
This is an introduction to the `helminthR` package, whicih allows for the programmatic access to the London Natural History Museum's helminth parasite database ([available here](https://www.nhm.ac.uk/research-curation/scientific-resources/taxonomy-systematics/host-parasites/index.html)). This database represents the largest known database of host-helminth interactions, containing host-helminth occurrence records for over 350 locations, including aquatic, marine, and terrestrial locations.
See software note in _Ecography_ ([available here](https://onlinelibrary.wiley.com/doi/10.1111/ecog.02131))
### Installation
From GitHub
```{r eval=FALSE}
# install.packages("devtools")
devtools::install_github("rOpenSci/helminthR")
library("helminthR")
```
From CRAN
```{r eval=FALSE}
install.packages("helminthR")
```
## Package functionality
The package allows for the acquisition of host-helminth interaction records based on host name (genus or species), parasite name (genus, species, or group), and/or location (accepted region name as provided in `data(locations)`. Parasite groups include "Acanthocephalans", "Cestodes", "Monogeans", "Nematodes", "Trematodes", or "Turbs" (short for Turbellarians). The user can further define host species as occuring
1. "In the wild"
2. "Zoo captivity"
3. "Domesticated"
4. "Experimental"
5. "Commercial source"
6. "Accidental infestation"
by inputting the corresponding number above in the `hostState` argument.
The package itself has three main functions; `findHost`, `findParasite`, and `findLocation`.
### Find all helminth parasites of a given host species
Given a host genus and (optionally) species and location, this function returns all host-parasite associations of a given host species. The example below determines all parasite records for helminth infections of _Gorilla gorilla_. We also use the `citation` argument here to obtain information on the citations which the host-helminth occurrences are based on.
```{r eval=FALSE}
gorillaParasites <- findHost(genus='Gorilla', species='gorilla',
hostState=1, speciesOnly=TRUE, citation=TRUE)
```
The above function will query the database for helminth parasites of _Gorilla gorilla_ that were captured in the wild, and will remove helminth parasites not identified to species. If the user wishes to query multiple host species at the same time, the user can do the following
```{r eval=FALSE}
hosts <- c('Gorilla gorilla', 'Peromyscus leucopus')
plyr::ldply(hosts,
function(x){
findHost(unlist(strsplit(x, ' '))[1],
unlist(strsplit(x,' '))[2])
}
)
```
### Find all hosts of a given helminth parasite
Given a helminth parasite genus (and optionally species, and location), this function returns a list of host-parasite records for that parasite. In the example below, I query the database for occurrences of the genus _Strongyloides_.
```{r eval=FALSE}
strongHosts <- findParasite(genus='Strongyloides')
dim(strongHosts)
```
```{r eval=FALSE}
head(strongHosts)
```
### `data(locations)` and `findLocation()`
A data file containing all the location names that can be queried, along with putative latitude and longitude coordinates for the centroid of each location can be found in `data(locations)`. Note that this will replace any object in the global environment named `locations`. These names can be given to the `findLocation()` function, which finds all host-parasite associations that have occurred in the given location. Below, I look at host-parasite associations recorded in France.
```{r eval=FALSE}
montanaOcc <- findLocation(location='Montana')
dim(montanaOcc)
```
```{r eval=FALSE}
head(montanaOcc)
```
### plotting host-helminth networks
Below, I provide an example of code for plotting the bipartite network of host-helminth interactions found in the state of Montana.
```{r eval=FALSE}
g <- igraph::graph.incidence(table(montanaOcc[,1:2]))
igraph::V(g)$name <- NA
igraph::E(g)$color <- 'black'
plot(g,
vertex.color=c("black","dodgerblue")[igraph::V(g)$type+1],
vertex.size=5
)
```