Showing 5 of 62 files from the diff.
Other files ignored by Codecov
docs/LICENSE.html has changed.
docs/index.html has changed.
docs/pkgdown.yml has changed.
man/loginfo.Rd has changed.
_pkgdown.yml has changed.
man/reset.Rd has changed.
docs/404.html has changed.
man/filter_bed.Rd has changed.
man/eigenstrat.Rd has changed.
docs/authors.html has changed.
man/relabel.Rd has changed.
man/count_snps.Rd has changed.
man/qpAdm.Rd has changed.
man/qpWave.Rd has changed.
man/f4ratio.Rd has changed.
DESCRIPTION has changed.
R/log.R has changed.
NEWS.md has changed.
cran-comments.md has changed.

@@ -4,6 +4,36 @@
Loading
4 4
#'
5 5
#' @inheritParams qpAdm
6 6
#'
7 +
#' @return Data frame object with calculated statistics
8 +
#'
9 +
#' @examples
10 +
#' \dontrun{# download an example genomic data set and prepare it for analysis
11 +
#' snps <- eigenstrat(download_data())
12 +
#'
13 +
#' # define a set of populations to analyze
14 +
#' pops <- c("French", "Sardinian", "Han", "Papuan", "Dinka")
15 +
#'
16 +
#' result_f4ratio <- f4ratio(
17 +
#'     X = pops, A = "Altai", B = "Vindija", C = "Yoruba", O = "Chimp",
18 +
#'     data = snps
19 +
#' )
20 +
#'
21 +
#' result_d <- d(
22 +
#'     W = pops, X = "Yoruba", Y = "Vindija", Z = "Chimp",
23 +
#'     data = snps
24 +
#' )
25 +
#'
26 +
#' result_f4 <- f4(
27 +
#'     W = pops, X = "Yoruba", Y = "Vindija", Z = "Chimp",
28 +
#'     data = snps
29 +
#' )
30 +
#'
31 +
#' result_f3 <- f3(
32 +
#'     A = pops, B = "Mbuti", C = "Khomani_San",
33 +
#'     data = snps
34 +
#' )
35 +
#' }
36 +
#'
7 37
#' @export
8 38
f4ratio <- function(data, X, A, B, C, O, outdir = NULL, params = NULL) {
9 39
  check_presence(c(X, A, B, C, O), data)
@@ -105,6 +135,26 @@
Loading
105 135
#' @param outdir Where to put all generated files (temporary directory by default).
106 136
#' @param params Named list of parameters and their values.
107 137
#'
138 +
#' @return List of three components:
139 +
#'     1. estimated ancestry proportions
140 +
#'     2. ranks statistics
141 +
#'     3. analysis of patterns (all possible subsets of ancestry sources).
142 +
#'
143 +
#' @examples
144 +
#' \dontrun{# download example data set and prepare it for analysis
145 +
#' snps <- eigenstrat(download_data())
146 +
#'
147 +
#' # estimate the proportion of Neandertal ancestry in a French
148 +
#' # individual and other associated qpAdm statistics (see detailed
149 +
#' # description in the tutorial vignette)
150 +
#' result <- qpAdm(
151 +
#'     target = "French",
152 +
#'     sources = c("Vindija", "Yoruba"),
153 +
#'     outgroups = c("Chimp", "Denisova", "Altai"),
154 +
#'     data = snps
155 +
#' )
156 +
#' }
157 +
#'
108 158
#' @export
109 159
qpAdm <- function(data, target, sources, outgroups, outdir = NULL,
110 160
                  params = list(allsnps = "YES", summary = "YES", details = "YES")) {
@@ -185,6 +235,20 @@
Loading
185 235
#' @param details Return the A, B matrices used in rank calculations?
186 236
#' @inheritParams qpAdm
187 237
#'
238 +
#' @return Table of rank test results.
239 +
#'
240 +
#' @examples
241 +
#' \dontrun{# download example data set and prepare it for analysis
242 +
#' snps <- eigenstrat(download_data())
243 +
#'
244 +
#' # run the qpWave wrapper (detailed description in the tutorial vignette)
245 +
#' result <- qpWave(
246 +
#'      left = c("French", "Sardinian", "Han"),
247 +
#'      right = c("Altai", "Yoruba", "Mbuti"),
248 +
#'      data = snps
249 +
#' )
250 +
#' }
251 +
#'
188 252
#' @export
189 253
qpWave <- function(data, left, right, maxrank = NULL, details = FALSE, outdir = NULL, params = NULL) {
190 254
  check_presence(c(left, right), data)

@@ -14,11 +14,11 @@
Loading
14 14
  # which only confuse the user. Let's make sure that the log file is
15 15
  # complete, informing the user to inspect it in case we see a problem.
16 16
  if (!any(stringr::str_detect(log_lines, "end of"))) {
17 -
    cat("BEGINNING OF OUTPUT FILE\n")
18 -
    cat("==================================================\n\n")
19 -
    cat(paste(log_lines, collapse = "\n"))
20 -
    cat("\n\n==================================================\n")
21 -
    cat("END OF OUTPUT FILE\n\n")
17 +
    message("BEGINNING OF OUTPUT FILE\n",
18 +
            "==================================================\n\n",
19 +
            paste(log_lines, collapse = "\n"),
20 +
            "\n\n==================================================\n",
21 +
            "END OF OUTPUT FILE\n\n")
22 22
    stop("The output file we got from ADMIXTOOLS is truncated.
23 23
       Please examine the full output above and check for errors.",
24 24
         call. = FALSE)

@@ -1,6 +1,5 @@
Loading
1 1
#' EIGENSTRAT data constructor
2 2
#'
3 -
#'
4 3
#' This function creates an instance of the EIGENSTRAT S3 class, which
5 4
#' encapsulates all paths to data files required for an ADMIXTOOLS analysis.
6 5
#'
@@ -10,6 +9,16 @@
Loading
10 9
#'
11 10
#' @return S3 object of the EIGENSTRAT class.
12 11
#'
12 +
#' @examples
13 +
#' \dontrun{# download an example genomic data and get the path prefix to the
14 +
#' # trio of snp/geno/ind files in an EIGENSTRAT format
15 +
#' prefix <- download_data()
16 +
#'
17 +
#' # wrap the trio of snp/geno/ind files in an object of the class
18 +
#' # EIGENSTRAT
19 +
#' snps <- eigenstrat(prefix)
20 +
#' }
21 +
#'
13 22
#' @export
14 23
eigenstrat <- function(prefix = NULL, ind = NULL, snp = NULL, geno = NULL, exclude = NULL) {
15 24
  if (is.null(prefix) & any(is.null(c(ind, snp, geno))))
@@ -75,6 +84,14 @@
Loading
75 84
#' @param a,b Two EIGENSTRAT datasets to merge.
76 85
#' @param strandcheck Deal with potential strand issues? Mostly for historic reasons. For details see the README of ADMIXTOOLS convertf.
77 86
#'
87 +
#' @examples
88 +
#' \dontrun{# merged <- merge_eigenstrat(
89 +
#' #    merged = <"path prefix of the merged snp/geno/ind data">
90 +
#' #    a = first_EIGENSTRAT_object,
91 +
#' #    b = second_EIGENSTRAT_object
92 +
#' #)
93 +
#' }
94 +
#'
78 95
#' @export
79 96
merge_eigenstrat <- function(merged, a, b, strandcheck = "NO") {
80 97
  parfile <- tempfile()
@@ -93,7 +110,7 @@
Loading
93 110
  ) %>% writeLines(text = ., con = parfile)
94 111
95 112
  return_value <- run_cmd("mergeit", parfile, "/dev/null")
96 -
  if (return_value) cat("\nMerge command ended with an error -- see above.\n")
113 +
  if (return_value) stop("\nMerge command ended with an error -- see above.\n")
97 114
98 115
  eigenstrat(merged)
99 116
}
@@ -106,8 +123,10 @@
Loading
106 123
#' BED file.
107 124
#'
108 125
#' This function requires a functioning bedtools installation! See:
109 -
#'   - https://github.com/arq5x/bedtools2
110 -
#'   - https://bedtools.readthedocs.io/en/latest/content/installation.html
126 +
#'
127 +
#' - https://github.com/arq5x/bedtools2
128 +
#'
129 +
#' - https://bedtools.readthedocs.io/
111 130
#'
112 131
#' @param data EIGENSTRAT data object.
113 132
#' @param bed Path to a BED file.
@@ -117,6 +136,20 @@
Loading
117 136
#'
118 137
#' @return Updated S3 EIGENSTRAT data object.
119 138
#'
139 +
#' @examples
140 +
#' \dontrun{# download an example genomic data set
141 +
#' prefix <- download_data()
142 +
#' # create an EIGENSTRAT R object from the downloaded data
143 +
#' snps <- eigenstrat(prefix)
144 +
#'
145 +
#' # get the path to an example BED file
146 +
#' bed <- file.path(dirname(prefix), "regions.bed")
147 +
#'
148 +
#' # BED file contains regions to keep in an analysis
149 +
#' snps_kept <- filter_bed(snps, bed)
150 +
#' # BED file contains regions to remove from an analysis
151 +
#' snps_removed <- filter_bed(snps, bed, remove = TRUE)
152 +
#' }
120 153
#' @export
121 154
filter_bed <- function(data, bed, remove = FALSE, outfile = tempfile(fileext = ".snp")) {
122 155
  if (file.exists(outfile)) {
@@ -171,8 +204,7 @@
Loading
171 204
#' @param outfile Path to an output snp file with coordinates of excluded sites.
172 205
#'
173 206
#' @return Updated S3 EIGENSTRAT data object with an additional 'exclude' slot
174 -
#'     specifying the path to the set of SNPs to be removed from a downstream
175 -
#'     analysis.
207 +
#'     specifying the path to the set of SNPs to be removed.
176 208
#'
177 209
#' @export
178 210
keep_transitions <- function(data, outfile = tempfile(fileext = ".snp")) {
@@ -192,6 +224,15 @@
Loading
192 224
#'     specifying the path to the set of SNPs to be removed from a downstream
193 225
#'     analysis.
194 226
#'
227 +
#' @examples
228 +
#' \dontrun{# download an example genomic data set and prepare it for analysis
229 +
#' snps <- eigenstrat(download_data())
230 +
#'
231 +
#' # perform the calculation only on transversions
232 +
#' snps_tv <- transversions_only(snps)
233 +
#' results_d <- d(W = "French", X = "Dinka", Y = "Altai", Z = "Chimp", data = snps_tv)
234 +
#' }
235 +
#'
195 236
#' @export
196 237
transversions_only <- function(data, outfile = tempfile(fileext = ".snp")) {
197 238
  if (file.exists(outfile)) {
@@ -223,8 +264,25 @@
Loading
223 264
#' @param outfile Path to an output snp file with coordinates of excluded sites.
224 265
#'
225 266
#' @return Updated S3 EIGENSTRAT data object with an additional 'group' slot
226 -
#'     specifying the path to a new ind file that will be used in downstream
227 -
#'     analysis.
267 +
#'     specifying the path to a new ind file.
268 +
#'#'
269 +
#' @examples
270 +
#' \dontrun{# download an example genomic data set and prepare it for analysis
271 +
#' snps <- eigenstrat(download_data())
272 +
#'
273 +
#' # group individual samples into larger populations, creating a new
274 +
#' # EIGENSTRAT R object
275 +
#' new_snps <- relabel(
276 +
#'     snps,
277 +
#'     European = c("French", "Sardinian"),
278 +
#'     African = c("Dinka", "Yoruba", "Mbuti", "Khomani_San"),
279 +
#'     Archaic = c("Vindija", "Altai", "Denisova")
280 +
#' )
281 +
#'
282 +
#' # use the newly created EIGENSTRAT object to run a D statistic with
283 +
#' # the new population groups
284 +
#' result_d  <- d(W = "European", X = "African", Y = "Archaic", Z = "Chimp", data = new_snps)
285 +
#' }
228 286
#'
229 287
#' @export
230 288
relabel <- function(data, ..., outfile = tempfile(fileext = ".ind")) {
@@ -257,6 +315,25 @@
Loading
257 315
#' @param data EIGENSTRAT data object.
258 316
#' @return EIGENSTRAT data S3 object.
259 317
#'
318 +
#'
319 +
#' @examples
320 +
#' \dontrun{# download an example genomic data set and prepare it for analysis
321 +
#' snps <- eigenstrat(download_data())
322 +
#'
323 +
#' # group individual samples into larger populations, creating a new
324 +
#' # EIGENSTRAT R object
325 +
#' new_snps <- relabel(
326 +
#'     snps,
327 +
#'     European = c("French", "Sardinian"),
328 +
#'     African = c("Dinka", "Yoruba", "Mbuti", "Khomani_San"),
329 +
#'     Archaic = c("Vindija", "Altai", "Denisova")
330 +
#' )
331 +
#'
332 +
#' # remove the population grouping in the previous step - this
333 +
#' # results in the same EIGENSTRAT object tht we started with
334 +
#' original_snps <- reset(new_snps)
335 +
#' }
336 +
#'
260 337
#' @export
261 338
reset <- function(data) {
262 339
  data$group <- NULL

@@ -14,6 +14,25 @@
Loading
14 14
#'     with a traditional qpAdm run) or just the proportions
15 15
#'     (determined by the value of the 'fulloutput' argument)
16 16
#'
17 +
#' @examples
18 +
#' \dontrun{# download an example genomic data set and prepare it for analysis
19 +
#' snps <- eigenstrat(download_data())
20 +
#'
21 +
#' # find the set of most likely two-source qpAdm models of
22 +
#' # a French individual - produce only the 'proportions'
23 +
#' # qpAdm summary
24 +
#' models <- qpAdm_rotation(
25 +
#'     data = snps,
26 +
#'     target = "French",
27 +
#'     candidates = c("Dinka", "Mbuti", "Yoruba", "Vindija",
28 +
#'                    "Altai", "Denisova", "Chimp"),
29 +
#'     minimize = TRUE,
30 +
#'     nsources = 2,
31 +
#'     ncores = 2,
32 +
#'     fulloutput = FALSE
33 +
#' )
34 +
#' }
35 +
#'
17 36
#' @importFrom utils combn
18 37
#' @export
19 38
qpAdm_rotation <- function(data, target, candidates, minimize = TRUE, nsources = 2, ncores = 1, fulloutput = FALSE) {
@@ -117,6 +136,30 @@
Loading
117 136
#'
118 137
#' @return qpAdm_rotation object filtered down based on p-value
119 138
#'
139 +
#' 
140 +
#'
141 +
#' @examples
142 +
#' \dontrun{# download an example genomic data set and prepare it for analysis
143 +
#' snps <- eigenstrat(download_data())
144 +
#'
145 +
#' # find the set of most likely two-source qpAdm models of
146 +
#' # a French individual - produce only the 'proportions'
147 +
#' # qpAdm summary
148 +
#' models <- qpAdm_rotation(
149 +
#'     data = snps,
150 +
#'     target = "French",
151 +
#'     candidates = c("Dinka", "Mbuti", "Yoruba", "Vindija",
152 +
#'                    "Altai", "Denisova", "Chimp"),
153 +
#'     minimize = TRUE,
154 +
#'     nsources = 2,
155 +
#'     ncores = 2,
156 +
#'     fulloutput = FALSE
157 +
#' )
158 +
#'
159 +
#' # filter out models which can clearly be rejected
160 +
#' fits <- qpAdm_filter(models, p = 0.05)
161 +
#' }
162 +
#'
120 163
#' @export
121 164
qpAdm_filter <- function(x, p = 0.05) {
122 165
    check_type(x, "admixr_result")

@@ -6,6 +6,16 @@
Loading
6 6
#'
7 7
#' @return A data.frame object with SNP counts/proportions.
8 8
#'
9 +
#' @examples
10 +
#' \dontrun{snps <- eigenstrat(download_data())
11 +
#' 
12 +
#' present_count <- count_snps(snps)
13 +
#' missing_count <- count_snps(snps, missing = TRUE)
14 +
#'
15 +
#' present_proportion <- count_snps(snps, prop = TRUE)
16 +
#' missing_proportion <- count_snps(snps, missing = TRUE, prop = TRUE)
17 +
#' }
18 +
#'
9 19
#' @export
10 20
#' @import rlang
11 21
count_snps <- function(data, missing = FALSE, prop = FALSE) {
Files Coverage
R 86.49%
Project Totals (7 files) 86.49%
1
comment: false
2

3
coverage:
4
  status:
5
    project:
6
      default:
7
        target: auto
8
        threshold: 1%
9
    patch:
10
      default:
11
        target: auto
12
        threshold: 1%
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading