forked from maryamsadeghimehr/HCV_Modelling
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHCV_model_exe.R
More file actions
92 lines (85 loc) · 3.73 KB
/
HCV_model_exe.R
File metadata and controls
92 lines (85 loc) · 3.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#############Executable file ######################################
#########################################
### Scenario: We need to choose the treatment scenario that we want to apply
### Simulation starts at time of HCV infection
### This file include all the required packages, and call all the required sources
### In this file the Cohort Size and the duration of simulation are defined.
#####################################################################
cat("\014")
cat('\n')
cat('***********************************************************\n')
cat('Mathematical Modeling of Hepatitis C Virus Progression Disease\n')
cat('\t \t 2017')
cat('\n')
cat('\n \t Version: 10')
cat('\n Requires files: \n')
cat('simulate_cohort.r: To do the simulation \n')
cat('baseline.r: Identify the baseline chracteristics \n')
cat('hazard_fun.r: Calls file specifying the hazard functions \n')
cat('params_cov.r: To choose parameters file \n')
cat('scenario_treatFx.r: To choose the treatment scenario \n')
cat('simulate_cohort.r: To do the simulation \n')
cat('TransitionTime.r: Shows all the possible transitions\n')
cat('***********************************************************\n')
#############################################################
#setwd("~/HCV_project_2017/hcv_git/hcv_modeling")
rm(list = ls())
wd = getwd()
######################### Required Packages #################
require(MASS)
require(msm)
require(mstate)
require(survival)
require(splines)
require(plyr)
require(gems)
#########################################################
start.time <- Sys.time()
current_dir = getwd()
########################################################
cohortSize <- 50 # specify how many patients to simulate
maxTime <- 100 # specify duration of simulation in years
#ans <- readline(prompt="Please enter the treatment scenario you are interested to study: Treating patients in (and after) stage F0, F1, F2, F3, F4 or BL (baseline) \t")
ans <- "Fg"
diag_scenario = c("Baseline","Birth","IDU", "ex_IDU")
diag_ind = 1
###########################################################
data <- read.table("baseline_data.txt", header = T)
bm <- read.table("Mort_CH_Swiss.txt", header=T)
all_cases = matrix(NA,1,52 + 13)
for (case in 1:nrow(data))
{
print(case)
#####################Source Codes ###########################
source("baseline.R") # call file specifying baseline characteristics
source(sprintf("scenario_treat%s.R",ans))
source("hazard_fun.R") # call file specifying the hazard functions
source("params_cov.R") #choose parameters file
source("TransitionTime.R")
source("sim_cohort.R") # call the cohort simulator
#########################################################
mainDir <- wd
today <- Sys.Date()
dd = format(today, format = "%B%d%Y")
subDir <- sprintf("outputDirectoryFgscenario_v1_%s_%s",dd,ans)
dir.create(file.path(mainDir, subDir), showWarnings = FALSE)
wd = setwd(file.path(mainDir, subDir))
mainDir <- wd
setwd(file.path(mainDir, subDir))
# print(getwd())
write.table(cohort@time.to.state, sprintf("treatFg_v1%s_%s",case, dd))
########################################################
write.table(cbind(cohort@time.to.state, bl), sprintf("treatFg_baseline_v1%s_%s",case, dd))
all_cases = rbind(as.matrix(all_cases),as.matrix(read.table(sprintf("treatFg_baseline_v1%s_%s",case, dd))))
setwd(current_dir)
}
#####################################
end.time <- Sys.time()
cat('***********************************************************\n')
print("Required time: ")
print(end.time - start.time)
cat('***********************************************************\n')
today <- Sys.Date()
dd = format(today, format = "%B%d%Y")
write.table(all_cases, sprintf("All_cases_Fg_v1%s_%s",dd, ans))
write.table(all_cases, sprintf("All_cases_Fg_v1%s_%s.csv",dd, ans))