bodkan / admixr
1
# Generate a parameter file.
2
create_par_file <- function(files, data, params) {
3 2
  geno <- data$geno
4 2
  snp <- data$snp
5 2
  ind <- ifelse(is.null(data$group), data$ind, data$group)
6 2
  exclude <- data$exclude
7

8 2
  sprintf("genotypename: %s\nsnpname: %s\nindivname: %s\n", geno, snp, ind) %>%
9 2
    writeLines(con = files$par_file)
10

11 2
  if (!is.null(files[["pop_file"]])) {
12 2
    write(sprintf("popfilename: %s\n", files$pop_file), file = files$par_file, append = TRUE)
13 2
  } else if (!is.null(files$popleft) & !is.null(files$popright)) {
14 2
    write(sprintf("popleft: %s", files$popleft), file = files$par_file, append = TRUE)
15 2
    write(sprintf("popright: %s", files$popright), file = files$par_file, append = TRUE)
16
  }
17

18 2
  if (!is.null(exclude)) {
19 2
    write(sprintf("badsnpname: %s", exclude), file = files$par_file, append = TRUE)
20
  }
21

22
  # write user-specified parameters
23 2
  for (par in names(params)) {
24 2
    write(sprintf("%s: %s\n", par, params[[par]]), file = files$par_file, append = TRUE)
25
  }
26
}
27

28

29
# Generate a file with populations for a qpF4ratio run.
30
create_qpF4ratio_pop_file <- function(X, A, B, C, O, file) {
31 2
  lines <- sprintf("%s %s : %s %s :: %s %s : %s %s", A, O, X, C, A, O, B, C)
32 2
  writeLines(lines, file)
33
}
34

35

36
# Generate a file with populations for a qpDstat run.
37
create_qpDstat_pop_file <- function(W = NULL, X = NULL, Y = NULL, Z = NULL, file) {
38 2
  lines <- c()
39 2
  for (w in W) for (x in X) for (y in Y) for (z in Z) {
40 2
    lines <- c(lines, sprintf("%s %s %s %s", w, x, y, z))
41
  }
42 2
  writeLines(lines, file)
43
}
44

45

46
# Generate a file with populations for a qpDstat run based on given
47
# list of quartets.
48
create_qpDstat_pop_file_quartets <- function(quartets, file) {
49 0
  lines <- c()
50 0
  for (q in quartets) {
51 0
    lines <- c(lines, sprintf("%s %s %s %s", q[1], q[2], q[3], q[4]))
52
  }
53 0
  writeLines(lines, file)
54
}
55

56

57
# Generate a file with populations for a qp3Pop run.
58
create_qp3Pop_pop_file <- function(A, B, C, file) {
59 2
  lines <- c()
60 2
  for (a in A) for (b in B) for (c in C) {
61 2
    lines <- c(lines, sprintf("%s %s %s", a, b, c))
62
  }
63 2
  writeLines(lines, file)
64
}
65

66
# Generate a file with populations for a qpDstat run.
67
create_leftright_pop_files <- function(left, right, files) {
68 2
  writeLines(left, files$popleft)
69 2
  writeLines(right, files$popright)
70
}
71

Read our documentation on viewing source code .

Loading