Skip to content

Commit

Permalink
bw score part is being tested
Browse files Browse the repository at this point in the history
  • Loading branch information
aminuldu07 committed Oct 9, 2024
1 parent a5c8295 commit 1c18e1e
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 50 deletions.
23 changes: 19 additions & 4 deletions R/get_bw_score.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ get_bw_score <- function(studyid = NULL,
use_xpt_file = FALSE,
master_compiledata = NULL,
return_individual_scores = FALSE) {

browser()
studyid <- as.character(studyid)
path <- path_db

Expand Down Expand Up @@ -79,6 +79,21 @@ get_bw_score <- function(studyid = NULL,

}

# Ensuring "BWSTRESN", "VISITDY", "BWDY" columns are numeric
bw$BWSTRESN <- as.numeric(bw$BWSTRESN)
bw$VISITDY <- as.numeric(bw$VISITDY)
bw$BWDY <- as.numeric(bw$BWDY)

#check for NAs introduced by the conversion
if (any(is.na(bw$BWSTRESN))) {
warning("Non-numeric values in BWSTRESN were coerced to NA")
}
if (any(is.na(bw$VISITDY))) {
warning("Non-numeric values in VISITDY were coerced to NA")
}
if (any(is.na(bw$BWDY))) {
warning("Non-numeric values in BWDY were coerced to NA")
}

#.................. "BodyWeight_zScore" .....calculation........
#................... Initial BW weight calculation..............
Expand Down Expand Up @@ -138,7 +153,7 @@ get_bw_score <- function(studyid = NULL,
# Set BWSTRESN to 0 for the rows that meet the condition
null_visitdy_large_bw$BWSTRESN <- 0

# Choose the row with the minimum BWDY value greater than 5
# Choose the row with the minimum VISITDY value greater than 5
closest_row_null_visitdy <- which.min(null_visitdy_large_bw$VISITDY)
SubjectInitialWeight <- null_visitdy_large_bw[closest_row_null_visitdy, c("STUDYID", "USUBJID", "BWSTRESN", "VISITDY")]
}
Expand Down Expand Up @@ -179,7 +194,7 @@ get_bw_score <- function(studyid = NULL,
# only the first occurrence of each unique USUBJID will be kept, and subsequent duplicates will be removed
StudyInitialWeights <- StudyInitialWeights[!duplicated(StudyInitialWeights$USUBJID), ]


browser()
#.......................................................................
# ..........Final day "StudyBodyWeights" calculation.....................

Expand Down Expand Up @@ -212,7 +227,7 @@ get_bw_score <- function(studyid = NULL,

# 1. Check if BWTESTCD == TERMBW is present
SubjectBodyWeight <- subj_bw_data[subj_bw_data$BWTESTCD == "TERMBW",
c("STUDYID", "USUBJID", "BWTESTCD","BWSTRESN", "VISITDY")] #,"BWNOMDY","BWNOMLBL","BWBLFL")]
c("STUDYID", "USUBJID", "BWTESTCD","BWSTRESN", "VISITDY")]

# If BWTESTCD == TERMBW not present,
# 2. If no BWTESTCD == TERMBW,try VISITDY > 5"
Expand Down
87 changes: 41 additions & 46 deletions inst/testing_rscript.R
Original file line number Diff line number Diff line change
Expand Up @@ -461,49 +461,44 @@ predicted_rf <- predicted_random_forest_model(dbPath_liver, dbPath_not_liver)
# print(time_taken)
# #####
#
# ####bw##score testing
# ######
# rm(list = ls())
# devtools::load_all(".")
#
# path_db = 'C:/Users/mdaminulisla.prodhan/OneDrive - FDA/2023-2024_projects/FAKE_DATABASES/all_fakedata_liver_/FAKE10663'
# #
# # fake_xpt_compiltdata <- get_compile_data(studyid = NULL,
# # path_db,
# # fake_study = TRUE,
# # use_xpt_file = TRUE)
# #
# #
# # studyid = '10663'
# # path_db = 'C:/Users/mdaminulisla.prodhan/OneDrive - FDA/2023-2024_projects/FAKE_DATABASES/liver_1.db'
# # fake_compiledata <- get_compile_data(studyid,
# # path_db,
# # fake_study = TRUE,
# # use_xpt_file = FALSE)
#
#
#
#
#
#
# fake_bw_xpt <- get_bw_score(studyid = NULL,
# path_db,
# fake_study = TRUE,
# master_compiledata = NULL,
# return_individual_scores = FALSE,
# use_xpt_file = TRUE)
#
#
#
#
#
#
#
#
#
#
#
#
#
#
# https://aminuldu07.github.io/SENDQSAR/
####bw##score testing
######
rm(list = ls())
devtools::load_all(".")

path_db = 'C:/Users/mdaminulisla.prodhan/OneDrive - FDA/2023-2024_projects/FAKE_DATABASES/all_fakedata_liver_/FAKE10663'
path_db = "C:/Users/mdaminulisla.prodhan/OneDrive - FDA/2023-2024_projects/FAKE_DATABASES/all_fakedata_liver_/FAKE11094"

fake_bw_xpt <- get_bw_score(studyid = NULL,
path_db,
fake_study = TRUE,
master_compiledata = NULL,
return_individual_scores = FALSE,
use_xpt_file = TRUE)

# for multiple folders

rm(list = ls())
devtools::load_all(".")

# Set the main directory
main_dir <- "C:/Users/mdaminulisla.prodhan/OneDrive - FDA/2023-2024_projects/FAKE_DATABASES/all_fakedata_liver_/"

# List all subdirectories
subdirs <- list.dirs(main_dir, full.names = TRUE, recursive = FALSE)

fake_xpt_results <- list()

# Loop through each subdirectory and process it
for (subdir in subdirs) {
# Assuming your function works with each subdirectory
fake_bw_xpt <- get_bw_score(studyid = NULL,
path_db = subdir,
fake_study = TRUE,
master_compiledata = NULL,
return_individual_scores = FALSE,
use_xpt_file = TRUE)

# Do something with the result, e.g., store it in a list
fake_xpt_results <- append(fake_xpt_results, list(fake_bw_xpt))
}

0 comments on commit 1c18e1e

Please sign in to comment.