Skip to content

Commit b6c78b5

Browse files
authored
Merge pull request #28 from mrc-ide/develop
Develop
2 parents 2224360 + 9aecb35 commit b6c78b5

6 files changed

Lines changed: 72 additions & 24 deletions

File tree

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: variantstring
22
Type: Package
33
Title: Functions for working with variant string format
4-
Version: 1.8.5
4+
Version: 1.8.6
55
Authors@R: c(
66
person("Bob", "Verity", email = "r.verity@imperial.ac.uk", role = c("aut", "cre"))
77
)

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export(long_to_position)
1414
export(long_to_variant)
1515
export(order_position_string)
1616
export(order_variant_string)
17+
export(overlay_variant)
1718
export(position_from_variant_string)
1819
export(position_to_long)
1920
export(subset_position)

R/main.R

Lines changed: 48 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,14 @@
22
# avoids "no visible bindings" warnings
33
if (getRversion() >= "2.15.1") {
44
utils::globalVariables(c("gene", "pos", "aa", "het", "phased", "read_count",
5-
"combo", "variant"))
5+
"combo", "variant", "n_aa.x", "n_aa.y",
6+
"het.x", "het.y",
7+
"phased.x", "phased.y",
8+
"aa.x", "aa.y",
9+
"read_count.x", "read_count.y",
10+
"n_aa"))
611
}
712

8-
# --- FUNCTION LIST ---
9-
# check_variant_string
10-
# check_position_string
11-
# variant_to_long
12-
# long_to_variant
13-
# position_to_long
14-
# long_to_position
15-
# position_from_variant_string
16-
# subset_position
17-
# order_variant_string
18-
# order_position_string
19-
# count_unphased_hets
20-
# count_phased_hets
21-
# drop_read_counts
22-
# compare_variant_string
23-
# compare_position_string
24-
# extract_single_locus_variants
25-
# get_component_variants
26-
# allowed_amino_acids
27-
2813
#------------------------------------------------
2914
#' @title Check for a valid variant string
3015
#'
@@ -1330,6 +1315,48 @@ get_component_variants <- function(x) {
13301315
return(ret)
13311316
}
13321317

1318+
#------------------------------------------------
1319+
#' @title Overlay one variant string onto another
1320+
#'
1321+
#' @description
1322+
#' All the positions and amino-acids from the first variant are combined with
1323+
#' the second, overwriting where positions are the same.
1324+
#'
1325+
#' @details
1326+
#' Note, inputs are not internally checked for being valid variant strings, it is up to the user to ensure this (see \code{?check_variant_string}).
1327+
#'
1328+
#' @param var1 the first variant string, which overwrites in the case of shared positions.
1329+
#' @param var2 the second variant string, which is overwritten in the case of shared positions.
1330+
#'
1331+
#' @import dplyr
1332+
#'
1333+
#' @export
1334+
1335+
overlay_variant <- function(var1, var2) {
1336+
1337+
mapply(function(x, y) {
1338+
if (is.na(x) & is.na(y)) {
1339+
return(NA)
1340+
}
1341+
if (is.na(x)) {
1342+
return(y)
1343+
}
1344+
if (is.na(y)) {
1345+
return(x)
1346+
}
1347+
full_join(variant_to_long(x)[[1]], variant_to_long(y)[[1]], by = join_by(gene, pos)) |>
1348+
mutate(n_aa = coalesce(n_aa.x, n_aa.y),
1349+
het = coalesce(het.x, het.y),
1350+
phased = coalesce(phased.x, phased.y),
1351+
aa = coalesce(aa.x, aa.y),
1352+
read_count = coalesce(read_count.x, read_count.y)) |>
1353+
select(gene, pos, n_aa, het, phased, aa, read_count) |>
1354+
list() |>
1355+
long_to_variant()
1356+
}, var1, var2)
1357+
1358+
}
1359+
13331360
#------------------------------------------------
13341361
#' @title List allowed amino acids
13351362
#'

README.Rmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Tools for working with *variant string format*, a convenient format for encoding
2727
You can install directly from Github:
2828

2929
```{r, eval=FALSE}
30-
devtools::install_github(repo = "mrc-ide/variantstring@v1.8.5")
30+
devtools::install_github(repo = "mrc-ide/variantstring@v1.8.6")
3131
```
3232

3333
Note the use of the @ symbol to reference a specific tagged version. This is highly recommended as the package is still in development and backwards compatibility is not guaranteed.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ other.
1919
You can install directly from Github:
2020

2121
``` r
22-
devtools::install_github(repo = "mrc-ide/variantstring@v1.8.5")
22+
devtools::install_github(repo = "mrc-ide/variantstring@v1.8.6")
2323
```
2424

2525
Note the use of the @ symbol to reference a specific tagged version.

man/overlay_variant.Rd

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)