-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from kbroman/main
Add MUGA maps + cross2_to_grcm39()
- Loading branch information
Showing
19 changed files
with
379 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,5 @@ Makefile$ | |
\.Rout$ | ||
^\.github$ | ||
^README\.Rmd$ | ||
\.csv$ | ||
^\.here$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
inst/scripts/*.csv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,21 @@ | ||
Package: mmconvert | ||
Version: 0.1-5 | ||
Date: 2021-09-28 | ||
Version: 0.2-3 | ||
Date: 2021-10-12 | ||
Title: Mouse Map Converter | ||
Description: Function to convert mouse genome positions between the build 39 physical map and the Cox genetic map <doi:10.1534/genetics.109.105486>. | ||
Author: Karl W Broman [aut, cre] (<https://orcid.org/0000-0002-4914-6671>) | ||
Maintainer: Karl W Broman <[email protected]> | ||
Authors@R: person("Karl W", "Broman", role=c("aut", "cre"), | ||
email="[email protected]", comment=c(ORCID = "0000-0002-4914-6671")) | ||
email="[email protected]", comment=c(ORCID = "0000-0002-4914-6671")) | ||
Depends: | ||
R (>= 3.5.0) | ||
Imports: | ||
Rcpp (>= 0.12.12), | ||
utils, | ||
stats | ||
Rcpp (>= 0.12.12) | ||
Suggests: | ||
testthat, | ||
devtools, | ||
roxygen2 | ||
roxygen2, | ||
qtl2 | ||
License: GPL-3 | ||
URL: https://github.com/rqtl/mmconvert | ||
BugReports: https://github.com/rqtl/mmconvert/issues | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
# Generated by roxygen2: do not edit by hand | ||
|
||
export(cross2_to_grcm39) | ||
export(mmconvert) | ||
importFrom(Rcpp,sourceCpp) | ||
useDynLib(mmconvert, .registration=TRUE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,14 @@ | ||
## mmconvert 0.2-3 (2021-10-12) | ||
|
||
- Added a dataset with the MUGA array annotations for markers on the | ||
autosomes or X chromosome, with mouse build GRCm39 positions and | ||
the revised Cox Map genetic map locations. | ||
|
||
- Add function `cross2_to_grcm39()` for converting an R/qtl2 cross2 | ||
object to use the new GRCm39 mouse build and the revised Cox genetic | ||
map. | ||
|
||
|
||
## mmconvert 0.1-5 (2021-09-28) | ||
|
||
- New package |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#' @name MUGAmaps | ||
#' @aliases MUGAmaps | ||
#' | ||
#' @title Array annotation information for the mouse MUGA arrays | ||
#' in mouse genome build 39. | ||
#' | ||
#' @description A list of four data frames with annotation information for the four MUGA arrays, | ||
#' GigaMUGA ("gm"), MegaMUGA ("mm"), MiniMUGA ("mini") and the original MUGA ("muga"). | ||
#' Each has columns marker, chromosome, build 39 basepair position, and sex-averaged cM position (in Cox Map v3). | ||
#' | ||
#' @details | ||
#' SNP probes for the MUGA arrays were blasted against mouse genome | ||
#' build GRCm39 and locations interpolated using theRevised Cox maps. | ||
#' See <https://github.com/kbroman/MUGAarrays> for the array | ||
#' annotations and <https://github.com/kbroman/CoxMapV3> for the | ||
#' genetic maps. Note that for the genetic map locations, markers were | ||
#' shifted so that 0 cM corresponds to 3 Mbp, using the chromosome- | ||
#' and sex-specific recombination rate. | ||
#' | ||
#' @source <https://github.com/kbroman/MUGAarrays> | ||
#' | ||
#' @keywords datasets | ||
#' | ||
#' @examples | ||
#' data(MUGAmaps) | ||
NULL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
#' Convert a cross2 object to use mouse build GRCm39 | ||
#' | ||
#' Convert a cross2 object (with genotypes from one of the MUGA | ||
#' arrays) to use mouse build GRCm39 and the revised Cox map | ||
#' positions, revising marker order and omitting markers that are not | ||
#' found. | ||
#' | ||
#' @param cross Object of class `"cross2"`, as produced by | ||
#' [qtl2::read_cross2()]. Must have markers from just one of the MUGA arrays. | ||
#' | ||
#' @param array Character string indicating which of the MUGA arrays | ||
#' was used ("gm" for GigaMUGA, "mm" for MegaMUGA, "mini" for | ||
#' MiniMUGA, or "muga" for the original MUGA), or "guess" (the | ||
#' default) to pick the array with the most matching marker names. | ||
#' | ||
#' @export | ||
#' | ||
#' @return The input `cross` object with markers subset to those in build GRCm39 | ||
#' and with `pmap` and `gmap` replaced with the GRCm39 physical map and | ||
#' revised Cox genetic map, respectively. | ||
#' | ||
#' @seealso [MUGAmaps] | ||
#' | ||
#' @examples | ||
#' \dontrun{ | ||
#' file <- paste0("https://raw.githubusercontent.com/rqtl/", | ||
#' "qtl2data/master/DOex/DOex.zip") | ||
#' DOex <- read_cross2(file) | ||
#' DOex_rev <- cross2_to_grcm39(DOex) | ||
#' } | ||
|
||
cross2_to_grcm39 <- | ||
function(cross, array=c("guess", "gm", "mm", "mini", "muga")) | ||
{ | ||
# check that it's cross2 | ||
if(!inherits(cross, "cross2")) stop('Input cross must have class "cross2"') | ||
|
||
# markers in the cross object | ||
markers <- unlist(lapply(cross$geno, colnames)) | ||
|
||
# MUGA maps (internal dataset) | ||
muga_maps <- mmconvert::MUGAmaps | ||
|
||
array <- match.arg(array) | ||
if(array == "guess") { | ||
# compare marker names to the four MUGA arrays | ||
# use the one with the most matches | ||
|
||
n_match <- vapply(muga_maps, function(a,b) sum(b %in% a$marker), 0, markers) | ||
if(!any(n_match > 0)) { | ||
stop("No markers found in the MUGA arrays") | ||
} | ||
|
||
array <- names(n_match)[which.max(n_match)] | ||
} | ||
|
||
map <- muga_maps[[array]] | ||
|
||
# number of markers found | ||
n_found <- sum(markers %in% map$marker) | ||
|
||
# if no markers found, stop with an error | ||
if(n_found == 0) { | ||
stop("No markers found in MUGA array") | ||
} | ||
|
||
n_notfound <- length(markers) - n_found | ||
|
||
# if more than 5% of markers omitted, give a warning | ||
if(n_notfound / length(markers) >= 0.05) { | ||
warning("Omitting ", n_notfound, " (", round(n_notfound/length(markers)*100), "%) markers") | ||
} else if(n_notfound > 0) { | ||
message("Omitting ", n_notfound, " markers") | ||
} | ||
|
||
map <- map[map$marker %in% markers, , drop=FALSE] | ||
|
||
gmap <- map_df_to_list(map, "chr", "cM_cox", "marker") | ||
map$Mbp_grcm39 <- map$bp_grcm39/1e6 | ||
pmap <- map_df_to_list(map, "chr", "Mbp_grcm39", "marker") | ||
|
||
# reorder markers in geno | ||
cross$geno <- cross$geno[names(pmap)] | ||
for(chr in names(pmap)) { | ||
g <- cross$geno[[chr]] | ||
g <- g[, names(pmap[[chr]]), drop=FALSE] | ||
cross$geno[[chr]] <- g | ||
} | ||
|
||
|
||
# reorder markers in founder_geno | ||
if("founder_geno" %in% names(cross)) { | ||
cross$founder_geno <- cross$founder_geno[names(pmap)] | ||
for(chr in names(pmap)) { | ||
fg <- cross$founder_geno[[chr]] | ||
fg <- fg[, names(pmap[[chr]]), drop=FALSE] | ||
cross$founder_geno[[chr]] <- fg | ||
} | ||
} | ||
|
||
# paste in new genetic map | ||
cross$gmap <- gmap | ||
|
||
# paste in new physical map | ||
cross$pmap <- pmap | ||
|
||
# make sure that is_x_chr gets subset, if necessary | ||
cross$is_x_chr <- cross$is_x_chr[names(pmap)] | ||
|
||
cross | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# used to skip tests when not on *my* computer in interactive mode | ||
# needed for testing mult-core code, which isn't allowed within R CMD check | ||
isnt_karl <- | ||
function() | ||
{ | ||
!(interactive() && | ||
identical(Sys.getenv("KARL_LOCAL"), "true")) | ||
} | ||
|
||
# is a number? (from assertthat) | ||
is_number <- function(x) is.numeric(x) && length(x)==1 | ||
is_nonneg_number <- function(x) is_number(x) && x >= 0 | ||
is_pos_number <- function(x) is_number(x) && x > 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.