Skip to content

Implement support for custom SNP sets#10

Draft
rnmitchell wants to merge 40 commits into
mainfrom
large_snp_sets
Draft

Implement support for custom SNP sets#10
rnmitchell wants to merge 40 commits into
mainfrom
large_snp_sets

Conversation

@rnmitchell

Copy link
Copy Markdown
Contributor

This MR will implement support for custom, larger SNP sets, including changes to increase the speed of uploading data (and formatting appropriately for EFM).

Comment thread R/app.R
Comment on lines -376 to +402
shinyFileChoose(input, "sample_GetFile", roots=volumes, session=session)
samplefile = reactive({parseFilePaths(volumes, input$sample_GetFile)})
roots = c(home="~", wd=".")
shinyFileChoose(input, "sample_GetFile", roots=roots, session=session, defaultRoot="home")
samplefile = reactive({parseFilePaths(roots, input$sample_GetFile)})

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changing to have file picker default to home directory instead of volumes dir

Comment thread R/app.R
Comment on lines +152 to +174
output$assay_choice = renderUI({
selectInput("assay_choice", tags$span("Select Assay", tags$span(icon(
name = "question-circle",
)
) |>
add_prompt(message = "Select assay used to develop genotypes", position = "right")
), c("Kintelligence", "Custom"))
})
output$assay_GetFile = renderUI({
fluidRow(column(10,shinyFilesButton("assay_GetFile", "Select a custom SNP positions file" ,
title = "Select a custom SNP positions file", multiple = FALSE,
buttonType = "default", class = NULL),
tags$span(
icon(
name = "question-circle",
)
) |>
add_prompt(message = "File containing chromosomal locations for custom SNP panels.\nThis is not required if using the Kintelligence assay.\nColumns required: rsID, chromosome (e.g. 1, 2, 3,), and position (GRCh37).", position = "right")
))
})
output$assay_text = renderUI({
textOutput("assay_file")
})

@rnmitchell rnmitchell May 11, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drop-down menu for "kintelligence" or "custom". If select custom, file selector appears to select file with SNP positions information.

Comment thread R/app.R
Comment on lines +471 to +473
withProgress(message = "Loading References", value = 0, {
if (file.exists(glue("{refs()}/EFM_references.rda"))) {
load(glue("{refs()}/EFM_references.rda"))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

searches first for .rda file

Comment thread R/app.R Outdated
Comment on lines +483 to +497
showModal(modalDialog(
title = "Input Error",
"Please provide reference genotypes before proceeding.",
easyClose = TRUE,
footer = modalButton("Dismiss")
))
}
} else if (!isTruthy(input$cond) & !isTruthy(input$uncond)) {
showModal(modalDialog(
title = "Input Error",
"Please select either an Unconditioned or Conditioned analysis (or both!) before proceeding.",
easyClose = TRUE,
footer = modalButton("Dismiss")
))
} else {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

improved error handling using pop-up windows.

Comment thread R/app.R
Comment on lines +502 to +506
withProgress(message = "Loading Allele Frequency Data", value = 0, {
freq_both = ifelse(!isTruthy(freq()$datapath), input$uploadfreq, freq()$datapath)
freq_major = ifelse(!isTruthy(freq_major()$datapath), input$uploadfreq_major, freq_major()$datapath)
freq_minor = ifelse(!isTruthy(freq_minor()$datapath), input$uploadfreq_minor, freq_minor()$datapath)
popFreq = load_freq(input$twofreqs, freq_both, freq_major, freq_minor)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now loads the frequency data before looping through each sample in manifest (therefore only loads freq data once).

Comment thread R/assigned_A2.R
Comment on lines +24 to +26
lcol = grep("rsid|marker|locus|snp", colname, ignore.case=TRUE, value=TRUE)
chrcol = grep("chr", colname, ignore.case=TRUE, value=TRUE)
poscol = grep("pos", colname, ignore.case=TRUE, value=TRUE)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more flexibility with column names

Comment thread R/format_ref.R
Comment on lines -21 to +23
format_ref = function(refData, refid, refs) {
if (is.numeric(refid)) {
ref_int = names(refData)[refid]
} else {
ref_int = refid
}
ref_profile = euroformix::tableReader(glue("{refs}/EFM_references.csv")) %>%
filter(.data$Sample.Name == ref_int)
#' @importFrom data.table fread
format_ref = function(refid, refs) {
ref_profile = data.frame(fread(glue("{refs}/EFM_references.csv"))) %>%
filter(.data$Sample.Name == refid)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed legacy code that is no longer used; converted to fread() function for fast reading of file.

Comment thread R/read_in_freq.R
Comment on lines +20 to +22
read_in_freq = function(freq){
#efmaf=fread(freq, header=T, sep=",")
tab=data.frame(freq)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rewrite of EFM freqImport() function to improve speed

Comment thread R/run_indiv_efm_set.R
Comment on lines +38 to +44
if (!file.exists(glue("{write_path}/rda_files/{sample}.rda")) | !(keep_bins)) {
evidData = create_evid(sample, replicate, snps_input)
dir.create(file.path(write_path, "rda_files"), showWarnings = FALSE, recursive=TRUE)
save(evidData, file=glue("{write_path}/rda_files/{sample}.rda"))
} else {
load(glue("{write_path}/rda_files/{sample}.rda"))
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Save SNP binned data as .rda file

Comment thread R/run_mixder_ancestry.R Outdated
#' @export
#'
run_mixder_ancestry = function(sample_manifest=NULL, sample=NULL, replicate=NULL, sample_reports = getwd(), output = "output", refpath=NULL, refs=NULL, mixdeconv=TRUE, uncond=TRUE, cond=FALSE, sets=10, dynamicAT=0.015, staticAT=10, minimum_snps=6000, A1_threshold=0.99, A2_threshold=0.6, minor_contrib_threshold=FALSE, keep_bins=TRUE, snps, pcagroups) {
run_mixder_ancestry = function(sample_manifest=NULL, sample=NULL, replicate="", sample_reports = getwd(), output = "output", refpath=NULL, refs=NULL, mixdeconv=TRUE, uncond=TRUE, cond=FALSE, sets=10, dynamicAT=0.015, staticAT=10, minimum_snps=6000, A1_threshold=0.99, A2_threshold=0.6, minor_contrib_threshold=FALSE, keep_bins=TRUE, snps="ancestry", pcagroups="superpopulations") {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added default values

Comment thread R/run_workflow.R
Comment on lines +77 to +82
if (dynamicAT != 0) {
message("creating AT table<br/>")
attable = process_kinreport(id, replicate_id, kinpath, dynamicAT, staticAT)
} else {
attable = staticAT
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If only static AT is applied, then just the single AT value can be used (a table does not need to be created).

Comment thread R/app.R
Comment on lines +462 to +469
if (!isTruthy(samplefile()$datapath)) {
showModal(modalDialog(
title = "Input Error",
"Please provide a sample manifest before proceeding.",
easyClose = TRUE,
footer = modalButton("Dismiss")
))
} else if (!isTruthy(kin_inpath())) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated error handling for missing files in Shiny app- pop-up window will appear stating the problem instead of random closing of the app

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant