annotate helperFunctions.R @ 3:3d0adeee3f2b draft default tip

"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit c062eb1cd00ce9d565f3e2f3b042b3dd90d78ce4"
author iuc
date Wed, 06 Jan 2021 10:55:53 +0000
parents dc51db22310c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
1 #!/usr/bin/env R
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
2
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
3 ## Helper functions for processing variant data, especially for
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
4 ## data which contains duplicate variants differing only on
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
5 ## annotation.
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
6
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
7 difference_in_group <- function(lines) {
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
8 #' Find the columns containing the differences between a
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
9 #' group of lines sharing the same POS and ALT.
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
10 #' e.g.
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
11 #' CHROM POS REF ALT IMPACT FUNCLASS AA GENE
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
12 #' 1 NC_045512.2 3037 C T LOW SILENT F924 ORF1ab
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
13 #' 2 NC_045512.2 3037 C T LOW SILENT F106 ORF1ab
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
14 #' 3 NC_045512.2 3037 C T MEDIUM SILENT F106 ORF1ab
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
15 #'
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
16 #' should yield:
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
17 #'
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
18 #' unique.name
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
19 #' 1 3037 T (LOW|F924)
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
20 #' 2 3037 T (LOW|F106)
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
21 #' 3 3037 T (MEDIUM|F106)
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
22 #'
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
23 #' i.e. it identifies that IMPACT and AA are the differing
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
24 #' columns for each of the rows
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
25 #'
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
26 #' Ideally this function should just be used as
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
27 #' ``tab %>% group_by(POS, ALT) %>% difference_in_group()``
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
28 #'
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
29 diff.colnames <- c()
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
30 nlines <- nrow(lines)
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
31 if (nlines > 1) {
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
32 for (i in 1:(nlines - 1)) {
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
33 test1 <- lines[i, ]
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
34 for (j in i:nlines) {
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
35 test2 <- lines[j, ]
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
36 diff.colnames <- c(diff.colnames,
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
37 names(test1[!(test1 %in% test2)]))
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
38 }
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
39 }
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
40 }
1
e362b3143cde "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1bde09fccd1a5412240ebd5c1f34a45ad73cebe2"
iuc
parents: 0
diff changeset
41 group_select <- c("POS", "REF", "ALT", diff.colnames)
e362b3143cde "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1bde09fccd1a5412240ebd5c1f34a45ad73cebe2"
iuc
parents: 0
diff changeset
42 return(lines[, group_select] %>% unite(group_select, sep = " ")) # nolint
0
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
43 }
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
44
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
45 split_table_and_process <- function(tab) {
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
46 #' Split TAB into groups sharing the same POS and ALT
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
47 #' and create distinguishing labels.
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
48 #'
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
49 #' Calls the above ``difference_in_group`` for each
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
50 #' discovered group.
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
51 #'
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
52 #' This function is necessary because tidyr is difficult
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
53 #' to write custom group binding functions.
1
e362b3143cde "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1bde09fccd1a5412240ebd5c1f34a45ad73cebe2"
iuc
parents: 0
diff changeset
54 group_ind <- tab %>% group_by(POS, REF, ALT) %>% select(POS, REF, ALT) # nolint
0
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
55 nlines <- nrow(tab)
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
56 groups <- list()
2
dc51db22310c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit d1c54d077cfc0eeb9699719760e668948cb9bbbc"
iuc
parents: 1
diff changeset
57 if (nlines) {
dc51db22310c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit d1c54d077cfc0eeb9699719760e668948cb9bbbc"
iuc
parents: 1
diff changeset
58 groups[[1]] <- c(1, 1)
dc51db22310c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit d1c54d077cfc0eeb9699719760e668948cb9bbbc"
iuc
parents: 1
diff changeset
59 } else {
dc51db22310c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit d1c54d077cfc0eeb9699719760e668948cb9bbbc"
iuc
parents: 1
diff changeset
60 groups[[1]] <- c(0, 0)
dc51db22310c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit d1c54d077cfc0eeb9699719760e668948cb9bbbc"
iuc
parents: 1
diff changeset
61 }
dc51db22310c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit d1c54d077cfc0eeb9699719760e668948cb9bbbc"
iuc
parents: 1
diff changeset
62 if (nlines >= 2) {
dc51db22310c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit d1c54d077cfc0eeb9699719760e668948cb9bbbc"
iuc
parents: 1
diff changeset
63 last_pa <- paste(group_ind[1, ])
dc51db22310c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit d1c54d077cfc0eeb9699719760e668948cb9bbbc"
iuc
parents: 1
diff changeset
64 for (r in 2:nlines) {
dc51db22310c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit d1c54d077cfc0eeb9699719760e668948cb9bbbc"
iuc
parents: 1
diff changeset
65 curr_pa <- paste(group_ind[r, ])
dc51db22310c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit d1c54d077cfc0eeb9699719760e668948cb9bbbc"
iuc
parents: 1
diff changeset
66 group_ind_diff_between_lines <- !all(last_pa == curr_pa)
dc51db22310c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit d1c54d077cfc0eeb9699719760e668948cb9bbbc"
iuc
parents: 1
diff changeset
67 if (group_ind_diff_between_lines) {
dc51db22310c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit d1c54d077cfc0eeb9699719760e668948cb9bbbc"
iuc
parents: 1
diff changeset
68 ## end of current group, start of new
dc51db22310c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit d1c54d077cfc0eeb9699719760e668948cb9bbbc"
iuc
parents: 1
diff changeset
69 groups[[length(groups)]][2] <- r - 1 ## change prev end
dc51db22310c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit d1c54d077cfc0eeb9699719760e668948cb9bbbc"
iuc
parents: 1
diff changeset
70 groups[[length(groups) + 1]] <- c(r, r) ## set (start, end)
dc51db22310c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit d1c54d077cfc0eeb9699719760e668948cb9bbbc"
iuc
parents: 1
diff changeset
71 } else if (r == nlines) {
dc51db22310c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit d1c54d077cfc0eeb9699719760e668948cb9bbbc"
iuc
parents: 1
diff changeset
72 ## i.e. if the very last line shares
dc51db22310c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit d1c54d077cfc0eeb9699719760e668948cb9bbbc"
iuc
parents: 1
diff changeset
73 ## the same POS REF ALT as the one before,
dc51db22310c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit d1c54d077cfc0eeb9699719760e668948cb9bbbc"
iuc
parents: 1
diff changeset
74 ## close current group.
dc51db22310c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit d1c54d077cfc0eeb9699719760e668948cb9bbbc"
iuc
parents: 1
diff changeset
75 groups[[length(groups)]][2] <- r
dc51db22310c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit d1c54d077cfc0eeb9699719760e668948cb9bbbc"
iuc
parents: 1
diff changeset
76 }
dc51db22310c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit d1c54d077cfc0eeb9699719760e668948cb9bbbc"
iuc
parents: 1
diff changeset
77 last_pa <- curr_pa
0
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
78 }
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
79 }
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
80 as_tibble(do.call(
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
81 "rbind",
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
82 lapply(groups, function(grange) {
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
83 expand_range <- grange[1]:grange[2]
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
84 difference_in_group(tab[expand_range, ])
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
85 })
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
86 ))
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
87 }
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
88
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
89 read_and_process <- function(id) {
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
90 file <- (samples %>% filter(ids == id))$files # nolint
2
dc51db22310c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit d1c54d077cfc0eeb9699719760e668948cb9bbbc"
iuc
parents: 1
diff changeset
91 variants <- read.table(file, header = T, sep = "\t", colClasses = "character")
dc51db22310c "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit d1c54d077cfc0eeb9699719760e668948cb9bbbc"
iuc
parents: 1
diff changeset
92 variants["AF"] <- lapply(variants["AF"], as.numeric)
0
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
93 uniq_ids <- split_table_and_process(variants)
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
94 if (nrow(variants) != nrow(uniq_ids)) {
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
95 stop(paste0(id, " '", file, "' failed: ", file, "\"",
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
96 "nrow(variants)=", nrow(variants),
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
97 " but nrow(uniq_ids)=", nrow(uniq_ids)))
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
98 }
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
99 variants <- as_tibble(cbind(variants, uniq_ids)) # nolint
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
100 return(variants)
1062d6ad6503 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/snpfreqplot/ commit 1f35303af979c16d9a3126dbc882a59f686ace5d"
iuc
parents:
diff changeset
101 }