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

[GEN-1636] add IDs from retraction form in the retraction steps for creating clinical release files #164

Merged
merged 4 commits into from
Dec 10, 2024
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
23 changes: 16 additions & 7 deletions scripts/release/create_release_files.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ now <- function(timeOnly = F, tz = "US/Pacific") {
}

filter_for_release <- function(dataset, selected_dataset, selected_cohort,
sor_df_filtered, retracted_patient)
sor_df_filtered, retracted_patient,
retracted_sample = NULL)
{
# get the list of released columns
release_cols <- sor_df_filtered %>%
Expand All @@ -94,12 +95,18 @@ filter_for_release <- function(dataset, selected_dataset, selected_cohort,

release_cols <- intersect(release_cols, colnames(dataset))

# filter the data by cohort and release columns
# filter the data by cohort, release columns, remove retracted patients
release_dat <- dataset %>%
filter(cohort_internal==selected_cohort) %>%
filter(!record_id %in% retracted_patient) %>%
select(all_of(release_cols))

# remove retracted sample
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it might be best to have some unit tests for this function since it does the retraction
EDIT: Based on coordination meeting discussion, this has to wait due to deadline tmrw 12/11

if(!is.null(retracted_sample) && length(retracted_sample) > 0){
release_dat <- release_dat %>%
filter(!cpt_genie_sample_id %in% retracted_sample)
}

return(release_dat)
}

Expand Down Expand Up @@ -159,12 +166,13 @@ if (verbose) {
print(glue("{now(timeOnly = T)}: extracting release status for {selected_cohort} {release_version}-{release_type} from SOR column '{clinical_column}'..."))
}

# get the list of retracted patient
# get the lists of retracted patient and samples
if (verbose) {
print(glue("{now(timeOnly = T)}: loading retracted patients ({syn_id_retraction}) for the release..."))
print(glue("{now(timeOnly = T)}: loading retracted patients/samples ({syn_id_retraction}) for the release..."))
}
retracted_table <- synTableQuery(glue("SELECT patient_id FROM {syn_id_retraction} WHERE cohort like '%{selected_cohort}%'"))$asDataFrame()
retracted_pt_list <- retracted_table$patient_id
retracted_table <- synTableQuery(glue("SELECT * FROM {syn_id_retraction} WHERE cohort like '%{selected_cohort}%'"))$asDataFrame()
retracted_pt_list <- na.omit(retracted_table$patient_id)
retracted_sam_list <- na.omit(retracted_table$sample_id)

# main -----------------

Expand Down Expand Up @@ -234,7 +242,8 @@ cpt_derived_release <- filter_for_release(cpt_derived_redacted,
'Cancer panel test level dataset',
selected_cohort,
sor_df_filtered = sor_df_filtered,
retracted_patient = retracted_pt_list)
retracted_patient = retracted_pt_list,
retracted_sample = retracted_sam_list)
if('PRISSMM Tumor Marker level dataset' %in% unique(sor_df_filtered$dataset)){
prissmm_tm_derived_release <- filter_for_release(prissmm_tm_derived_redacted,
'PRISSMM Tumor Marker level dataset',
Expand Down
Loading
Loading