Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corrections for DOF1/HSF1 data #212

Merged
merged 6 commits into from
Oct 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 10 additions & 19 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Workflow derived from https://github.com/r-lib/actions/tree/master/examples
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
Expand All @@ -18,7 +18,7 @@ jobs:
fail-fast: false
matrix:
config:
- {os: macOS-latest, r: 'release'}
- {os: macos-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
Expand All @@ -29,30 +29,21 @@ jobs:
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- uses: r-lib/actions/setup-pandoc@v1
- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v1
- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}
http-user-agent: ${{ matrix.config.http-user-agent }}
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v1
- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: rcmdcheck
extra-packages: any::rcmdcheck
needs: check

- uses: r-lib/actions/check-r-package@v1

- name: Show testthat output
if: always()
run: find check -name 'testthat.Rout*' -exec cat '{}' \; || true
shell: bash

- name: Upload check results
if: failure()
uses: actions/upload-artifact@main
- uses: r-lib/actions/check-r-package@v2
with:
name: ${{ runner.os }}-r${{ matrix.config.r }}-results
path: check
upload-snapshots: true
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: qtl2
Version: 0.29-5
Date: 2022-10-25
Version: 0.29-7
Date: 2022-10-29
Title: Quantitative Trait Locus Mapping in Experimental Crosses
Description: Provides a set of tools to perform quantitative
trait locus (QTL) analysis in experimental crosses. It is a
Expand Down
18 changes: 17 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
## qtl2 0.29-5 (2022-10-25)
## qtl2 0.29-7 (2022-10-29)

### Major changes

- For DOF1 and HSF1, revised the results of `calc_genoprob()` for the
X chromosome, so that it just keeps track of the chromosome from the
DO/HS parent. In males, we are assuming that the DO/HS parent is the
mother.

### Minor changes

- Add dependency on version of Rcpp (>= 1.0.7)

- Revisions so that `genoprob_to_alleleprob()` to work with DOF1 and
HSF1. `plot_onegeno()` should also work now in these cases.
(Issue #140 and Issue #141)

### Bug fixes

- Revised `predict_snpgeno()` to work for DOF1 and HSF1 populations.
Expand All @@ -20,6 +31,11 @@
- Issue a warning message if founder genotypes are included but not
used (Issue #211).

- The treatment of the male X chromosome in DOF1 and HSF1 was
incorrect. We're now assuming that the DO or HS parent was the
mother in the F1 cross, in which case males will be hemizygous for
one of the DO/HS founder alleles.


## qtl2 0.28 (2021-10-11)

Expand Down
6 changes: 5 additions & 1 deletion R/predict_snpgeno.R
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ function(cross, geno, cores=1)

# ugh deal with DOF1/HSF1 specially
if(cross$crosstype %in% c("dof1", "hsf1")) {
ph2[] <- 9 # one chromosome is from 9th founder
if(!is_x_chr[chr]) ph2[] <- 9 # one chromosome is from 9th founder
else {
if(any(is_male)) ph2[is_male,] <- ph1[is_male,,drop=FALSE]
if(any(!is_male)) ph2[!is_male,] <- 9
}
}

if(ncol(fg) != ncol(ph1) ||
Expand Down
4 changes: 4 additions & 0 deletions R/snpprob_from_cross.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ snpprob_from_cross <-
map <- cross$pmap
if(is.null(map)) map <- cross$gmap

if(cross$crosstype %in% c("hsf1", "dof1")) { # if HSF1 or DOF1, drop last founder
cross$founder_geno <- cross$founder_geno[,-ncol(cross$founder_geno)]
}

sdp <- calc_sdp(t(do.call("cbind", cross$founder_geno)))

snpinfo <- data.frame(chr=rep(chr_names(cross), n_mar(cross)),
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
### [R/qtl2](https://kbroman.org/qtl2/)

[![R build status](https://github.com/rqtl/qtl2/workflows/R-CMD-check/badge.svg)](https://github.com/rqtl/qtl2/actions)
[![R-CMD-check](https://github.com/rqtl/qtl2/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/rqtl/qtl2/actions/workflows/R-CMD-check.yaml)
[![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/qtl2)](https://cran.r-project.org/package=qtl2)

[Karl Broman](https://kbroman.org)
Expand Down
87 changes: 23 additions & 64 deletions src/cross_dof1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,7 @@ const bool DOF1::check_geno(const int gen, const bool is_observed_value,
const int n_alleles = 8;
const int n_geno = 8;

if(!is_x_chr || is_female) { // autosome or female X
if(gen>= 1 && gen <= n_geno) return true;
}
else { // male X
if(gen>=n_geno+1 && gen <=n_geno+n_alleles) return true;
}
if(gen>= 1 && gen <= n_geno) return true;

return false; // otherwise a problem
}
Expand Down Expand Up @@ -56,13 +51,15 @@ const double DOF1::emit(const int obs_gen, const int true_gen, const double erro

if(obs_gen==0) return 0.0; // missing

int f1;
if(!is_x_chr || is_female) // autosome or female X
f1 = founder_geno[true_gen-1];
else
f1 = founder_geno[true_gen-9];
int f1 = founder_geno[true_gen-1];

int f2 = founder_geno[8]; // 9th founder is the other strain
int f2;
if(is_x_chr && !is_female) {
f2 = f1; // assuming female DO x male 9th strain, so male is hemizygous DO chr
} else {
// autosome or female X chr
f2 = founder_geno[8]; // 9th founder is the other strain
}

// treat founder hets as missing
if(f1==2) f1 = 0;
Expand Down Expand Up @@ -162,30 +159,18 @@ const double DOF1::step(const int gen_left, const int gen_right, const double re
const IntegerVector DOF1::possible_gen(const bool is_x_chr, const bool is_female,
const IntegerVector& cross_info)
{
int n_alleles = 8;
int n_geno = 8;

if(is_x_chr && !is_female) { // male X chromosome
IntegerVector result(n_alleles);
for(int i=0; i<n_alleles; i++)
result[i] = n_geno+i+1;
return result;
}
else { // autosome or female X
IntegerVector result(n_geno);
for(int i=0; i<n_geno; i++)
result[i] = i+1;
return result;
}
IntegerVector result(n_geno);
for(int i=0; i<n_geno; i++)
result[i] = i+1;
return result;

}

const int DOF1::ngen(const bool is_x_chr)
{
int n_alleles = 8;
int n_geno = 8;

if(is_x_chr) return n_geno+n_alleles;
return n_geno;
return 8;
}

const int DOF1::nalleles()
Expand All @@ -195,28 +180,14 @@ const int DOF1::nalleles()

const NumericMatrix DOF1::geno2allele_matrix(const bool is_x_chr)
{
const int n_alleles = 8;
const int n_geno = 8;

if(is_x_chr) {
NumericMatrix result(n_geno+n_alleles, n_alleles);
// female X
for(int trueg=0; trueg<n_geno; trueg++)
result(trueg,trueg) = 1.0;
// male X
for(int trueg=0; trueg<n_alleles; trueg++)
result(trueg+n_geno, trueg) = 1.0;

return result;
}
else { // autosome
NumericMatrix result(n_geno,n_alleles);
NumericMatrix result(n_geno,n_geno);

for(int trueg=0; trueg<n_geno; trueg++)
result(trueg,trueg) = 1.0;
for(int trueg=0; trueg<n_geno; trueg++)
result(trueg,trueg) = 1.0;

return result;
}
return result;
}

// check that sex conforms to expectation
Expand Down Expand Up @@ -332,24 +303,12 @@ const std::vector<std::string> DOF1::geno_names(const std::vector<std::string> a
{
int n_alleles = alleles.size();

if(is_x_chr) {
std::vector<std::string> result(n_alleles*2);
std::vector<std::string> result(n_alleles);

for(int i=0; i<n_alleles; i++) {
result[i] = alleles[i] + "X";
result[i+n_alleles] = alleles[i] + "Y";
}
for(int i=0; i<n_alleles; i++)
result[i] = alleles[i];

return result;
}
else {
std::vector<std::string> result(n_alleles);

for(int i=0; i<n_alleles; i++)
result[i] = alleles[i];

return result;
}
return result;
}

const double DOF1::est_rec_frac(const NumericVector& gamma, const bool is_x_chr,
Expand Down
86 changes: 22 additions & 64 deletions src/cross_hsf1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,7 @@ const bool HSF1::check_geno(const int gen, const bool is_observed_value,
const int n_alleles = 8;
const int n_geno = 8;

if(!is_x_chr || is_female) { // autosome or female X
if(gen>= 1 && gen <= n_geno) return true;
}
else { // male X
if(gen>=n_geno+1 && gen <=n_geno+n_alleles) return true;
}
if(gen>= 1 && gen <= n_geno) return true;

return false; // otherwise a problem
}
Expand Down Expand Up @@ -56,13 +51,15 @@ const double HSF1::emit(const int obs_gen, const int true_gen, const double erro

if(obs_gen==0) return 0.0; // missing

int f1;
if(!is_x_chr || is_female) // autosome or female X
f1 = founder_geno[true_gen-1];
else
f1 = founder_geno[true_gen-9];
int f1 = founder_geno[true_gen-1];

int f2 = founder_geno[8]; // 9th founder is the other strain
int f2;
if(is_x_chr && !is_female) {
f2 = f1; // assuming female DO x male 9th strain, so male is hemizygous DO chr
} else {
// autosome or female X chr
f2 = founder_geno[8]; // 9th founder is the other strain
}

// treat founder hets as missing
if(f1==2) f1 = 0;
Expand Down Expand Up @@ -160,30 +157,17 @@ const double HSF1::step(const int gen_left, const int gen_right, const double re
const IntegerVector HSF1::possible_gen(const bool is_x_chr, const bool is_female,
const IntegerVector& cross_info)
{
int n_alleles = 8;
int n_geno = 8;

if(is_x_chr && !is_female) { // male X chromosome
IntegerVector result(n_alleles);
for(int i=0; i<n_alleles; i++)
result[i] = n_geno+i+1;
return result;
}
else { // autosome or female X
IntegerVector result(n_geno);
for(int i=0; i<n_geno; i++)
result[i] = i+1;
return result;
}
IntegerVector result(n_geno);
for(int i=0; i<n_geno; i++)
result[i] = i+1;
return result;
}

const int HSF1::ngen(const bool is_x_chr)
{
int n_alleles = 8;
int n_geno = 8;

if(is_x_chr) return n_geno+n_alleles;
return n_geno;
return 8;
}

const int HSF1::nalleles()
Expand All @@ -193,28 +177,14 @@ const int HSF1::nalleles()

const NumericMatrix HSF1::geno2allele_matrix(const bool is_x_chr)
{
const int n_alleles = 8;
const int n_geno = 8;

if(is_x_chr) {
NumericMatrix result(n_geno+n_alleles, n_alleles);
// female X
for(int trueg=0; trueg<n_geno; trueg++)
result(trueg,trueg) = 1.0;
// male X
for(int trueg=0; trueg<n_alleles; trueg++)
result(trueg+n_geno, trueg) = 1.0;
NumericMatrix result(n_geno,n_geno);

return result;
}
else { // autosome
NumericMatrix result(n_geno,n_alleles);

for(int trueg=0; trueg<n_geno; trueg++)
result(trueg,trueg) = 1.0;
for(int trueg=0; trueg<n_geno; trueg++)
result(trueg,trueg) = 1.0;

return result;
}
return result;
}

// check that sex conforms to expectation
Expand Down Expand Up @@ -330,24 +300,12 @@ const std::vector<std::string> HSF1::geno_names(const std::vector<std::string> a
{
int n_alleles = alleles.size();

if(is_x_chr) {
std::vector<std::string> result(n_alleles*2);

for(int i=0; i<n_alleles; i++) {
result[i] = alleles[i] + "X";
result[i+n_alleles] = alleles[i] + "Y";
}

return result;
}
else {
std::vector<std::string> result(n_alleles);
std::vector<std::string> result(n_alleles);

for(int i=0; i<n_alleles; i++)
result[i] = alleles[i];
for(int i=0; i<n_alleles; i++)
result[i] = alleles[i];

return result;
}
return result;
}

const double HSF1::est_rec_frac(const NumericVector& gamma, const bool is_x_chr,
Expand Down
Loading