Skip to content

Commit

Permalink
Drop duplicate cell types
Browse files Browse the repository at this point in the history
  • Loading branch information
bschilder committed Oct 4, 2024
1 parent 0941d8c commit a402f60
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 8 deletions.
8 changes: 8 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,14 @@ body:
If that's not possible, please at least include a screenshot of your data and other relevant details.
See [here](https://www.r-bloggers.com/2020/10/how-to-make-a-reprex/) for an intro to making a reproducible example (i.e. reprex) and why they're important!
Surrounding your code in triple backticks will render it nicely on GitHub.
placeholder: |
# For example:
```R
df <- data.frame(list(a=rep(2,3), b=rep(1,3)))
df["bTYPO"]
```
validations:
required: true

Expand All @@ -58,7 +62,9 @@ body:
Copy and paste the R console output.
placeholder: |
# For example:
```R
Error in `[.data.frame`(df, "bTYPO") : undefined columns selected
```
validations:
required: true

Expand All @@ -82,6 +88,7 @@ body:
description: |
Copy and paste the output of the `sessionInfo() R function.
placeholder: |
```R
R version 4.4.1 (2024-06-14)
Platform: aarch64-apple-darwin20
Running under: macOS 15.0
Expand All @@ -101,4 +108,5 @@ body:
...
...
...
```
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: MAGMA.Celltyping
Type: Package
Title: Find Causal Cell-Types Underlying Complex Trait Genetics
Version: 2.0.13
Version: 2.0.14
Authors@R:
c(person(given = "Brian",
family = "Schilder",
Expand Down
11 changes: 11 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# MAGMA.Celltyping 2.0.14

## New features

* Make sure `get_example_gwas` caches data.

## Bug fixes

* `create_gene_covar_file`: Add check to drop duplicate cell types (after ignoring case)
* `load_magma_results_file`: Update message to include scenario where cell types dropped due to be duplicated.

# MAGMA.Celltyping 2.0.13

## New features
Expand Down
1 change: 0 additions & 1 deletion R/calculate_celltype_associations.r
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ calculate_celltype_associations <- function(ctd,
path <- sprintf("%s.%s.gsa.out",
sumstatsPrefix2,
analysis_name)

path <- get_actual_path(path)
#### Use existing results, or compute new ones ####
if ((!file.exists(path)) || isTRUE(force_new)) {
Expand Down
3 changes: 2 additions & 1 deletion R/check_quantiles.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ check_quantiles <- function(ctd,
function(lvl,
.matrix_name=matrix_name,
.metric=metric[1]){
messager("Checking CTD: level ",lvl,v=TRUE, parallel = TRUE)
messager("Checking CTD ",matrix_name," matrix: ",
"level ",lvl,v=TRUE, parallel = TRUE)
ctd_1lvl <- ctd[[lvl]]
if(.metric=="n"){
col_unique <- apply(ctd_1lvl[[.matrix_name]], 2,
Expand Down
14 changes: 13 additions & 1 deletion R/create_gene_covar_file.r
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,21 @@ create_gene_covar_file <- function(genesOutFile,
dup_genes <- duplicated(quantDat2$entrez)
if(sum(dup_genes, na.rm = TRUE)>0){
messager("Removing", sum(dup_genes, na.rm = TRUE),
"genes with duplicate entrez IDs.",v=verbose)
"gene(s) with duplicate entrez IDs.",v=verbose)
quantDat2 <- quantDat2[!dup_genes,]
}
#### Ensure there are no duplicate cell types when ignoring case (which MAGMA does) ####
dup_ct <- duplicated(toupper(colnames(quantDat2)))
if(sum(dup_ct)>0){
messager("Removing", sum(dup_ct, na.rm = TRUE),
"cell type(s) with duplicate cell types (when ignoring upper/lowercase):",
paste(shQuote(colnames(quantDat2)[dup_ct]), collapse = ","),
"Please consider regenerating your CTD object with",
"unique cell type names (when ignoring upper/lowercase)",
"for more accurate results.",
v=verbose)
quantDat2 <- quantDat2[,!dup_ct]
}
#### Write genes covar file to disk ####
geneCovarFile <- tempfile()
utils::write.table(
Expand Down
3 changes: 2 additions & 1 deletion R/get_example_gwas.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ get_example_gwas <- function(trait = c(
"prospective_memory"
),
munged = TRUE,
storage_dir = tempdir(),
storage_dir = tools::R_user_dir("MAGMA.Celltyping",
which="cache"),
timeout = 60 * 5,
verbose = TRUE) {
trait <- tolower(trait)[1]
Expand Down
3 changes: 2 additions & 1 deletion R/load_magma_results_file.r
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ load_magma_results_file <- function(path,
messager(numCTinCTD,
"celltypes in ctd but",numCTinRes,"in results file.",
"Some celltypes may have been dropped due if the variance",
"being too low (i.e. set contains only one gene used in analysis).")
"being too low (i.e. set contains only one gene used in analysis)",
"OR duplicate celltype names (after ignoring case).")
messager(
"<50% of celltypes missing.",
"Attemping to fix by removing missing cell-types:\n",
Expand Down
2 changes: 1 addition & 1 deletion R/prepare_quantile_groups.r
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ prepare_quantile_groups <- function(ctd,
ctd <- lapply(ctd, EWCE::bin_specificity_into_quantiles,
numberOfBins = numberOfBins,
matrix_name = "specificity_quantiles")
}
}
#### Compute specificity deciles ####
ctd <- lapply(ctd, EWCE::bin_specificity_into_quantiles,
numberOfBins = 10,
Expand Down
2 changes: 1 addition & 1 deletion man/get_example_gwas.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a402f60

Please sign in to comment.