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

Fixes instantation of Cohort when providing directory of the pipeline… #19

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
18 changes: 11 additions & 7 deletions R/Cohort.R
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,10 @@ Cohort <- R6Class("Cohort",
warning("Pipeline report not found: ", report_path)
return(NULL)
}

# Read pipeline report
report_lines <- readLines(report_path)

# Extract launch directory and samplesheet path
launch_dir <- grep("launchDir:", report_lines, value = TRUE)
samplesheet_path <- grep("input:", report_lines, value = TRUE)
Expand All @@ -208,12 +208,16 @@ Cohort <- R6Class("Cohort",
warning("Could not find launch directory or samplesheet path in pipeline report")
return(NULL)
}

# Clean up paths
launch_dir <- gsub(".*launchDir: ", "", launch_dir)
samplesheet_filename <- gsub(".*input: ", "", samplesheet_path)
samplesheet_filename <- gsub("^\\./", "", samplesheet_filename)
samplesheet_path <- file.path(launch_dir, gsub("^\\./", "", samplesheet_filename))
if(grepl("^/", samplesheet_filename)) { #TRUE if the samplesheet is already a full path
samplesheet_path <- samplesheet_filename
} else {
samplesheet_path <- file.path(launch_dir, gsub("^\\./", "", samplesheet_filename))
}

if (!file.exists(samplesheet_path)) {
warning("Samplesheet not found: ", samplesheet_path)
Expand Down Expand Up @@ -252,10 +256,10 @@ Cohort <- R6Class("Cohort",
somatic_snvs = "sage/somatic/.*/.*sage.somatic.vcf.gz$",
somatic_variant_annotations = "snpeff/somatic/.*/.*ann.bcf$",
somatic_snv_cn = "snv_multiplicity3/.*/.*est_snv_cn_somatic.rds",
activities_sbs_signatures = "signatures/sigprofilerassignment/somatic/.*/sbs_results/.*/Assignment_Solution_Activities.txt",
activities_sbs_signatures = "signatures/sigprofilerassignment/somatic/.*/sbs_results/Assignment_Solution/Activities/sbs_Assignment_Solution_Activities.txt",
matrix_sbs_signatures = "signatures/sigprofilerassignment/somatic/.*/SBS/sigmat_results.SBS96.all",
decomposed_sbs_signatures = "signatures/sigprofilerassignment/somatic/.*/sbs_results/.*/Decomposed_MutationType_Probabilities.txt",
activities_indel_signatures = "signatures/sigprofilerassignment/somatic/.*/indel_results/.*/Assignment_Solution_Activities.txt",
decomposed_sbs_signatures = "signatures/sigprofilerassignment/somatic/.*/sbs_results/Assignment_Solution/Activities/Decomposed_MutationType_Probabilities*.txt",
activities_indel_signatures = "signatures/sigprofilerassignment/somatic/.*/indel_results/Assignment_Solution/Activities/indel_Assignment_Solution_Activities.txt",
matrix_indel_signatures = "signatures/sigprofilerassignment/somatic/.*/ID/sigmat_results.ID83.all",
decomposed_indel_signatures = "signatures/sigprofilerassignment/somatic/.*/indel_results/.*/Decomposed_MutationType_Probabilities.txt",
hrdetect = "hrdetect/.*/hrdetect_results.rds",
Expand Down
8 changes: 7 additions & 1 deletion R/metadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,13 @@ create_metadata <- function(
) {
# Initialize metadata with all possible columns
metadata <- initialize_metadata_columns(pair)

# change NA to NULL
fix_entries = c("tumor_type", "disease", "primary_site", "inferred_sex", "jabba_gg", "events", "somatic_snvs", "germline_snvs", "tumor_coverage", "estimate_library_complexity", "alignment_summary_metrics", "insert_size_metrics", "wgs_metrics", "het_pileups", "activities_indel_signatures", "deconstructsigs_sbs_signatures", "activities_sbs_signatures", "hrdetect", "onenesstwoness")
for (x in fix_entries) {
if (!exists(x) || is.null(get(x)) || is.na(get(x))) {
assign(x, NULL)
}
}
# Add each component sequentially
metadata <- add_basic_metadata(metadata, tumor_type, disease, primary_site)
metadata <- add_sex_information(metadata, inferred_sex, jabba_gg, tumor_coverage)
Expand Down
2 changes: 1 addition & 1 deletion R/segment-width-distribution.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
get_segstats <- function(
balanced_jabba_gg,
tumor_coverage,
coverage_field = "foreground.X",
coverage_field = "foreground",
settings = internal_settings_path,
ref = "hg19",
max_na = 0.9,
Expand Down
Binary file modified src/RcppExports.o
Binary file not shown.
Binary file modified src/Skilift.so
Binary file not shown.
11 changes: 7 additions & 4 deletions tests/testthat/test-metadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,8 @@ setup({
seqnames = "chr1",
start = 1,
end = length(foreground_values),
field = "foreground.X",
## field = "foreground.X",
field = "foreground",
ncn = 2
) {
# Create GRanges object with required structure
Expand Down Expand Up @@ -762,7 +763,8 @@ test_that("add_coverage_metrics processes tumor coverage correctly", {
metadata <- initialize_metadata_columns("TEST001")

# Create mock coverage data
mock_coverage <- list(foreground.X = c(1, 2, 1, 2, 1, 2))
## mock_coverage <- list(foreground.X = c(1, 2, 1, 2, 1, 2))
mock_coverage <- list(foreground = c(1, 2, 1, 2, 1, 2))
temp_file <- tempfile(fileext = ".rds")
saveRDS(mock_coverage, temp_file)

Expand Down Expand Up @@ -836,7 +838,8 @@ test_that("add_coverage_metrics combines coverage and QC metrics", {
metadata <- initialize_metadata_columns("TEST001")

# Create mock coverage data
mock_coverage <- list(foreground.X = c(1, 2, 1, 2, 1, 2))
## mock_coverage <- list(foreground.X = c(1, 2, 1, 2, 1, 2))
mock_coverage <- list(foreground = c(1, 2, 1, 2, 1, 2))
coverage_file <- tempfile(fileext = ".rds")
saveRDS(mock_coverage, coverage_file)

Expand Down Expand Up @@ -1539,7 +1542,7 @@ test_that("add_coverage_parameters requires purity and ploidy", {
metadata <- initialize_metadata_columns("TEST001")
# Note: purity and ploidy are not set

mock_coverage <- list(foreground.X = c(1, 2, 3))
mock_coverage <- list(foreground = c(1, 2, 3))
temp_file <- tempfile(fileext = ".rds")
saveRDS(mock_coverage, temp_file)

Expand Down