-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcleanfourunif.R
99 lines (67 loc) · 3.06 KB
/
cleanfourunif.R
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
92
93
94
95
96
97
98
99
cleanfourunif = function(input){
# Bifurcated approach for 95.4% Confidence interval of Start posterior phase distribution is split into two parts
rng3 <- input[3]
rng4 <- input[4]
# Cleaning of the output begins
rngsplit3<-unlist(strsplit(rng3, "\" ", fixed = TRUE))
rngsplit4<-unlist(strsplit(rng4, "\" ", fixed = TRUE))
keeps <- c(".")
rngrange3 <- gsub(paste0(".*?($|'|", paste(paste0("\\",
keeps), collapse = "|"), "|[^[:punct:]]).*?"), "\\1", rngsplit3[2])
rngrange4 <- gsub(paste0(".*?($|'|", paste(paste0("\\",
keeps), collapse = "|"), "|[^[:punct:]]).*?"), "\\1", rngsplit4[2])
rngrangesplit3 <- gsub('BP','',rngrange3)
rngrangesplit4 <- gsub('BP','',rngrange4)
rngrangesplit32 <- strsplit(gsub(paste0("([[:alnum:]]{", # Apply strsplit function
6,
"})"),
"\\1 ",
rngrangesplit3),
" ")[[1]]
rngrangesplit42 <- strsplit(gsub(paste0("([[:alnum:]]{", # Apply strsplit function
6,
"})"),
"\\1 ",
rngrangesplit4),
" ")[[1]]
rngrangesplit32_num <- as.numeric(rngrangesplit32)
rngrangesplit32_num_noNA<-rngrangesplit32_num[!is.na(rngrangesplit32_num)]
rngrangesplit42_num <- as.numeric(rngrangesplit42)
rngrangesplit42_num_noNA<-rngrangesplit42_num[!is.na(rngrangesplit42_num)]
# Cleaned entires
# Filtering accurate results
time.s32 <- rngrangesplit32_num_noNA[1]
time.e32 <- rngrangesplit32_num_noNA[3]
accuracy <- 0
# Define value
x1 <- 5000
# Define lower bound
left1 <- time.e32
# Define upper bound
right1 <- time.s32
# Apply between function
range32 <- between(x1, left1, right1)
time.s42 <- rngrangesplit42_num_noNA[1]
time.e42 <- rngrangesplit42_num_noNA[3]
# Define value
x2 <- 5000
# Define lower bound
left2 <- time.e42
# Define upper bound
right2 <- time.s42
# Apply between function
range42 <- between(x2, left2, right2)
if (range32 == "TRUE" || range42 == "TRUE")
{
accuracy <- accuracy + 1
}
margin32 <- time.s32 - time.e32
margin42 <- time.s42 - time.e42
margin <- margin42 + margin32
distancefromstart <- 0
if (accuracy == 0){
distancefromstart <- min(c(abs(5000-rngrangesplit32_num_noNA[1]),abs(5000-rngrangesplit32_num_noNA[3]),abs(5000-rngrangesplit42_num_noNA[1]),abs(5000-rngrangesplit42_num_noNA[3])))
}
new_row <- c(margin, accuracy, distancefromstart)
unif_df[nrow(unif_df) + 1, ] <<- new_row
}