Skip to content

Commit

Permalink
function working for fake data
Browse files Browse the repository at this point in the history
  • Loading branch information
Yousuf28 committed Sep 3, 2024
1 parent 513c1fc commit 96650a7
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 18 deletions.
6 changes: 4 additions & 2 deletions R/get_bw_score.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#' Studyid number
#' @param path_db Mandatory, character \cr
#' path of database
#' @param fake_study optional, Boolean \cr
#' whether study generated by SENDsanitizer package
#' @return dataframe
#'
#' @examples
Expand All @@ -16,7 +18,7 @@
#' @importFrom RSQLite dbConnect
#' @importFrom RSQLite SQLite

get_bw_score <- function(studyid, path_db) {
get_bw_score <- function(studyid, path_db,fake_study=FALSE) {

studyid <- as.character(studyid)

Expand Down Expand Up @@ -319,7 +321,7 @@ path <- path_db
BW_df_selected_column <- joined_BW_df[, c("USUBJID", "STUDYID", "BWSTRESN", "BWSTRESN_Init")]

# Add "ARMCD","SETCD","SEX" to "selected_df"
master_CompileData <- get_compile_data(studyid = studyid, path_db = path_db)
master_CompileData <- get_compile_data(studyid = studyid, path_db = path_db,fake_study = fake_study)
STUDYID_less_master_CompileData <- master_CompileData[, c("USUBJID", "ARMCD","SETCD","SEX")]
BW_df_merged_ARMCD <- merge(BW_df_selected_column, STUDYID_less_master_CompileData, by = "USUBJID")

Expand Down
28 changes: 26 additions & 2 deletions R/get_compile_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#' Studyid number
#' @param path_db Mandatory, character \cr
#' path of database
#' @param fake_study optional, Boolean \cr
#' whether study generated by SENDsanitizer package
#' @return dataframe
#'
#' @examples
Expand All @@ -11,7 +13,7 @@
#' }
#' @export

get_compile_data <- function(studyid, path_db) {
get_compile_data <- function(studyid, path_db,fake_study=FALSE) {
studyid <- as.character(studyid)
path <- path_db
con <- DBI::dbConnect(DBI::dbDriver('SQLite'), dbname = path)
Expand All @@ -23,7 +25,28 @@ get_compile_data <- function(studyid, path_db) {
statement = stat,
params=list(x=studyid))
domain
}
}

if(fake_study){
dm <- con_db('dm')
data.table::setDT(dm)
ts <- con_db('ts')
data.table::setDT(ts)
species <- ts$TSVAL[which(ts$TSPARMCD=='SPECIES')]
dm <- dm[,c('STUDYID','USUBJID','SPECIES','SEX','ARMCD','ARM','SETCD')]
dm[,`:=`(Species=species,SPECIES=NULL,ARMCD=ARM,ARM=NULL)]
dm[ARMCD=='Control',`:=`(ARMCD='vehicle')]
dm <- dm[ARMCD %in% c('vehicle','HD')]
data.table::setDF(dm)
return(dm)


} else{






#Pull relevant domain data for each domain
bw <- con_db('bw')
Expand Down Expand Up @@ -301,4 +324,5 @@ get_compile_data <- function(studyid, path_db) {
dplyr::rename(ARMCD = DOSE_RANKING)

master_CompileData
}
}
14 changes: 10 additions & 4 deletions R/get_final_score.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#' Studyid number
#' @param path_db Mandatory, character \cr
#' path of database
#' @param fake_study optional, Boolean \cr
#' whether study generated by SENDsanitizer package
#' @return dataframe
#'
#' @param domain Mandatory, character or vector \cr
Expand All @@ -20,7 +22,8 @@
#' }
#' @export

get_all_score <- function(studyid, path_db, domain= c('lb','mi', 'bw')) {
get_all_score <- function(studyid, path_db, domain= c('lb','mi', 'bw'),
fake_study=FALSE) {

studyid <- as.character(studyid)
path_db <- fs::path(path_db)
Expand All @@ -29,15 +32,18 @@ result_return <- list(studyid_res = studyid)
for(i in 1:domain_len){
cur_dom <- domain[i]
if(cur_dom=='lb'){
df <- get_lb_score(studyid, path_db)
df <- get_lb_score(studyid, path_db,
fake_study = fake_study)

}else if(cur_dom=='mi') {

df <- get_mi_score(studyid, path_db)
df <- get_mi_score(studyid, path_db,
fake_study = fake_study)

} else if (cur_dom=='bw'){

df <- get_bw_score(studyid, path_db)
df <- get_bw_score(studyid, path_db,
fake_study = fake_study)

} else{
stop('check your domain')
Expand Down
6 changes: 4 additions & 2 deletions R/get_lb_score.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#' Studyid number
#' @param path_db Mandatory, character \cr
#' path of database
#' @param fake_study optional, Boolean \cr
#' whether study generated by SENDsanitizer package
#' @return score
#'
#' @examples
Expand All @@ -12,7 +14,7 @@
#' }
#' @export

get_lb_score <- function(studyid, path_db) {
get_lb_score <- function(studyid, path_db,fake_study=FALSE) {

studyid <- as.character(studyid)
path <- path_db
Expand Down Expand Up @@ -97,7 +99,7 @@ path <- path_db
dplyr::ungroup()

# get master compile data
master_CompileData <- get_compile_data(studyid, path_db)
master_CompileData <- get_compile_data(studyid, path_db,fake_study = fake_study)
#<><><><><><><><><><><><><><><><>... Remove TK animals and Recovery animals......<><><><><><>.............
#<><><><><><><><> master_CompileData is free of TK animals and Recovery animals<><><><><><><><><><><><><><>
# Remove the TK animals and Recovery animals
Expand Down
9 changes: 6 additions & 3 deletions R/get_mi_score.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#' Studyid number
#' @param path_db Mandatory, character \cr
#' path of database
#' @param fake_study optional, Boolean \cr
#' whether study generated by SENDsanitizer package
#' @return score
#'
#' @examples
Expand All @@ -12,7 +14,7 @@
#' }
#' @export

get_mi_score <- function(studyid, path_db) {
get_mi_score <- function(studyid, path_db,fake_study=FALSE) {
studyid <- as.character(studyid)
path <- path_db
con <- DBI::dbConnect(DBI::dbDriver('SQLite'), dbname = path)
Expand Down Expand Up @@ -101,7 +103,7 @@ path <- path_db
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

master_CompileData <- get_compile_data(studyid = studyid,
path_db = path_db)
path_db = path_db,fake_study = fake_study)

# Filter the data frame
tk_recovery_less_MIData <- MIData %>% dplyr::filter (USUBJID %in% master_CompileData$USUBJID)
Expand Down Expand Up @@ -347,7 +349,8 @@ master_CompileData <- get_compile_data(studyid = studyid,
} else {
# If number of columns is more than 7, get the max value from column 7 to the end
#ScoredData_subset_HD$highest_score <- apply(ScoredData_subset_HD[, 7:ncol(ScoredData_subset_HD)], 1, max, na.rm = TRUE)
ScoredData_subset_HD$highest_score <- matrixStats::rowMaxs(as.matrix(ScoredData_subset_HD[, 7:ncol(ScoredData_subset_HD)]), na.rm = TRUE)
ScoredData_subset_HD$highest_score <- matrixStats::rowMaxs(as.matrix(ScoredData_subset_HD[, 7:ncol(ScoredData_subset_HD)]),
na.rm = TRUE)
}

# Move the highest_score column to be the third column
Expand Down
10 changes: 9 additions & 1 deletion man/get_all_score.Rd

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

5 changes: 4 additions & 1 deletion man/get_bw_score.Rd

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

5 changes: 4 additions & 1 deletion man/get_compile_data.Rd

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

5 changes: 4 additions & 1 deletion man/get_lb_score.Rd

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

5 changes: 4 additions & 1 deletion man/get_mi_score.Rd

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

0 comments on commit 96650a7

Please sign in to comment.