Skip to content

Commit

Permalink
fillmissing (#60)
Browse files Browse the repository at this point in the history
* do not infer states for chrY

* update test-coverage

* Input cell list for phasing

* Add ability to annotate with a flat dataframe

* Add annotation test

* Adjust hscn test

* Update hscn test to choose cells correctly

* Update tests

* Increment version number to 0.12.0
  • Loading branch information
marcjwilliams1 authored Jan 7, 2025
1 parent 5a53d08 commit 1be71aa
Show file tree
Hide file tree
Showing 9 changed files with 299 additions and 62 deletions.
68 changes: 41 additions & 27 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
@@ -1,47 +1,61 @@
# 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:
branches:
- master
branches: [main, master]
pull_request:
branches:
- master

name: test-coverage
name: test-coverage.yaml

permissions: read-all

jobs:
test-coverage:
runs-on: macOS-latest
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GH_TOKEN }}

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

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::covr, any::xml2
needs: coverage

- uses: r-lib/actions/setup-pandoc@v1
- name: Install xquartz
run: brew install --cask xquartz
- name: Query dependencies
- name: Test coverage
run: |
install.packages('remotes')
saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2)
writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version")
cov <- covr::package_coverage(
quiet = FALSE,
clean = FALSE,
install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package")
)
covr::to_cobertura(cov)
shell: Rscript {0}

- name: Cache R packages
uses: actions/cache@v1
- uses: codecov/codecov-action@v4
with:
path: ${{ env.R_LIBS_USER }}
key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }}
restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-
# Fail if error if not on PR, or if on PR and token is given
fail_ci_if_error: ${{ github.event_name != 'pull_request' || secrets.CODECOV_TOKEN }}
file: ./cobertura.xml
plugin: noop
disable_search: true
token: ${{ secrets.CODECOV_TOKEN }}

- name: Install dependencies
- name: Show testthat output
if: always()
run: |
install.packages(c("remotes"))
remotes::install_deps(dependencies = TRUE)
remotes::install_cran("covr")
shell: Rscript {0}
## --------------------------------------------------------------------
find '${{ runner.temp }}/package' -name 'testthat.Rout*' -exec cat '{}' \; || true
shell: bash

- name: Test coverage
run: covr::codecov()
shell: Rscript {0}
- name: Upload test results
if: failure()
uses: actions/upload-artifact@v4
with:
name: coverage-test-failures
path: ${{ runner.temp }}/package
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: signals
Title: Single Cell Genomes with Allele Specificity
Version: 0.11.4
Version: 0.12.0
Author@R: c(person("Marc", "Williams", email = "[email protected]",
role = c("aut", "cre")),
person("Tyler", "Funnell",
Expand Down Expand Up @@ -41,7 +41,7 @@ Imports:
grid,
ggforce,
ggtree
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
Suggests:
knitr,
rmarkdown,
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# signals 0.12.0

* option to input cells to use for phasing for each chromosome
* plotHeatmap with arbitrary annotation dataframe
* remove chrY

# signals 0.11.4

* fix typo assigning A->B
Expand Down
32 changes: 26 additions & 6 deletions R/callHSCN.R
Original file line number Diff line number Diff line change
Expand Up @@ -624,14 +624,15 @@ filter_haplotypes <- function(haplotypes, fraction){
#' @param phased_haplotypes Use this if you want to manually define the haplotypes phasing if for example the default heuristics used by signals does not return a good fit.
#' @param clustering_method Method to use to cluster cells for haplotype phasing, default is `copy` (using copy column), other option is `breakpoints` (using breakpoint for clustering)
#' @param maxloherror Maximum value for LOH error rate
#' @param chr_cell_list Cells to use for phasing for each chromosome, this should be a named list with a vector of cell_ids for each chromosome eg list("1" = c("cell_id1", "cell_id2)) etc. Default is null. If provided overrides internal phasing.
#' @param mincells Minimum cluster size used for phasing, default = 7
#' @param overwritemincells Force the number of cells to use for clustering/phasing rather than use the output of the clustering
#' @param viterbver Version of viterbi algorithm to use (cpp or R)
#' @param cluster_per_chr Whether to cluster per chromosome to rephase alleles or not
#' @param filterhaplotypes filter out haplotypes present in less than X fraction, default is 0.1
#' @param firstpassfiltering Filter out cells with large discrepancy after first pass state assignment
#' @param smoothsingletons Remove singleton bins by smoothing over based on states in adjacent bins
#' @param fillmissing For bins with missing counts fill in values based on neighbouring bins
#' @param fillmissing For bins with missing counts fill in values based on neighbouring bins, this ensures that the returned object is the same size as input CNbins
#' @param global_phasing_for_diploid When using cluster_per_chr, use all cells for phasing diploid regions within the cluster
#' @param chrs_for_global_phasing Which chromosomes to phase using all cells for diploid regions, default is NULL which uses all chromosomes
#' @param female Default is `TRUE`, if set to `FALSE` and patient is "XY", X chromosome states are set to A|0 where A=Hmmcopy state
Expand Down Expand Up @@ -692,6 +693,7 @@ callHaplotypeSpecificCN <- function(CNbins,
smoothsingletons = TRUE,
fillmissing = TRUE,
global_phasing_for_balanced = FALSE,
chr_cell_list = NULL,
chrs_for_global_phasing = NULL,
female = TRUE) {
if (!clustering_method %in% c("copy", "breakpoints")) {
Expand Down Expand Up @@ -724,13 +726,13 @@ callHaplotypeSpecificCN <- function(CNbins,

if (female == TRUE){
#do not infer states for chr "Y"
#haplotypes <- dplyr::filter(haplotypes, chr != "Y")
#CNbins <- dplyr::filter(CNbins, chr != "Y")
haplotypes <- dplyr::filter(haplotypes, chr != "Y")
CNbins <- dplyr::filter(CNbins, chr != "Y")
} else{
#do not infer states for chr "X" or "Y"
#haplotypes <- dplyr::filter(haplotypes, chr != "Y")
haplotypes <- dplyr::filter(haplotypes, chr != "Y")
haplotypes <- dplyr::filter(haplotypes, chr != "X")
#CNbins <- dplyr::filter(CNbins, chr != "Y")
CNbins <- dplyr::filter(CNbins, chr != "Y")
}

nhaplotypes <- haplotypes %>%
Expand Down Expand Up @@ -842,7 +844,7 @@ callHaplotypeSpecificCN <- function(CNbins,

ascn_filt$balance <- ifelse(ascn_filt$phase == "Balanced", 0, 1)

if (is.null(phased_haplotypes)) {
if (is.null(phased_haplotypes) & is.null(chr_cell_list)){
chrlist <- proportion_imbalance(ascn_filt,
haplotypes_filt,
phasebyarm = phasebyarm,
Expand All @@ -854,6 +856,24 @@ callHaplotypeSpecificCN <- function(CNbins,
)
propdf <- chrlist$propdf
chrlist <- chrlist$chrlist
} else{
message("Using user provided cell list for phasing chromosomes")
#use the user provided list of cells to use for phasing
chrlist <- chr_cell_list
propdf <- NULL

#check user provided chrcellist contains info for all chromosomes
check_chr <- all(names(chr_cell_list) %in% unique(ascn_filt$chr))
if (check_chr == FALSE){
stop("Cells for phasing not specified for all chromosomes in chr_cell_list")
}
check_cells <- all(as.vector(unlist(chr_cell_list)) %in% unique(ascn_filt$cell_id))
if (check_cells == FALSE){
stop("Not all cell_id's in chr_cell_list are present in CNbins or haplotypes")
}
}

if (is.null(phased_haplotypes)) {
phased_haplotypes <- phase_haplotypes_bychr(
ascn = ascn_filt,
haplotypes = haplotypes_filt,
Expand Down
Loading

0 comments on commit 1be71aa

Please sign in to comment.