-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathTheScript_3L.R
More file actions
138 lines (114 loc) · 5 KB
/
Copy pathTheScript_3L.R
File metadata and controls
138 lines (114 loc) · 5 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#Terminal #git config --global user.email ""
#Terminal #git config --global user.name ""
#Console #gitcreds::gitcreds_set()
#Console #usethis::edit_r_environ()
# Setup in Correct Directory
Linux <- file.path("/home", "david", "Documents", "InstrumentQC")
Windows <- file.path("C:", "DailyQC", "InstrumentQC")
OperatingSystem <- Sys.info()["sysname"]
if(OperatingSystem == "Linux"){OS <- Linux
} else if (OperatingSystem == "Windows"){OS <- Windows}
WorkingDirectory <- OS
setwd(WorkingDirectory)
#source("renv/activate.R")
library(stringr)
library(purrr)
# Find out current date
Today <- Sys.Date()
Today <- as.Date(Today)
# Check for Flag Files
AnyFlags <- list.files(WorkingDirectory, pattern="Flag.csv", full.names=TRUE)
if (length(AnyFlags) == 0){
# Git Pull
RepositoryPath <- WorkingDirectory
TheRepo <- git2r::repository(RepositoryPath)
git2r::pull(TheRepo)
# Locating Archive Folder
Instrument <- "3L"
MainFolder <- file.path(WorkingDirectory, "data")
WorkingFolder <- file.path(WorkingDirectory, "data", Instrument)
StorageFolder <- file.path(WorkingFolder, "Archive")
# Gains
Gains <- list.files(StorageFolder, pattern="Archived", full.names=TRUE)
Gains <- read.csv(Gains[1], check.names = FALSE)
LastGainItem <- Gains |> dplyr::slice(1) |> dplyr::pull(DateTime)
LastGainItem <- lubridate::ymd_hms(LastGainItem)
LastGainItem <- as.Date(LastGainItem)
PotentialGainDays <- seq.Date(from = LastGainItem, to = Today, by = "day")
GainRemoveIndex <- which(PotentialGainDays == LastGainItem)
PotentialGainDays <- PotentialGainDays[-GainRemoveIndex]
# MFIs
MFIs <- list.files(StorageFolder, pattern="Bead", full.names=TRUE)
MFIs <- read.csv(MFIs[1], check.names=FALSE)
LastMFIItem <- MFIs |> dplyr::slice(1) |> dplyr::pull(DateTime)
LastMFIItem <- lubridate::ymd_hms(LastMFIItem)
LastMFIItem <- as.Date(LastMFIItem)
PotentialMFIDays <- seq.Date(from = LastMFIItem, to = Today, by = "day")
MFIRemoveIndex <- which(PotentialMFIDays == LastMFIItem)
PotentialMFIDays <- PotentialMFIDays[-MFIRemoveIndex]
# Usage
Apps <- list.files(StorageFolder, pattern="Application", full.names=TRUE)
Apps <- read.csv(Apps[1], check.names=FALSE)
LastAppsItem <- Apps |> dplyr::slice(1) |> dplyr::pull(DateTime)
LastAppsItem <- lubridate::ymd_hms(LastAppsItem)
LastAppsItem <- as.Date(LastAppsItem)
PotentialAppsDays <- seq.Date(from = LastAppsItem, to = Today, by = "day")
AppsRemoveIndex <- which(PotentialAppsDays == LastAppsItem)
PotentialAppsDays <- PotentialAppsDays[-AppsRemoveIndex]
if (!length(PotentialGainDays) == 0){
SetupFolder <- file.path("C:", "CytekbioExport", "Setup")
TheSetupFiles <- list.files(SetupFolder, pattern="DailyQC", full.names=TRUE)
Dates <- as.character(PotentialGainDays)
Dates <- gsub("-", "", Dates)
GainMatches <- TheSetupFiles[str_detect(TheSetupFiles, str_c(Dates, collapse = "|"))]
if (!length(GainMatches) == 0){
file.copy(GainMatches, WorkingFolder)
walk(.x=Instrument, .f=Luciernaga:::DailyQCParse, MainFolder=MainFolder)
}
} else {message("QC data has already been transferred")
GainMatches <- NULL
}
if (!length(PotentialMFIDays) == 0){
FCSFolder <- file.path("D:", "Aurora 3_FCS Files", "Experiments", "Flow Core")
MonthStyle <- format(Today, "%Y-%m")
MonthFolder <- paste0("QC ", MonthStyle)
MonthFolder <- file.path(FCSFolder, MonthFolder)
TheFCSFiles <- list.files(MonthFolder, pattern="fcs", full.names=TRUE, recursive=TRUE)
days <- format(PotentialMFIDays, "%d")
MFIMatches <- TheFCSFiles[str_detect(basename(TheFCSFiles), str_c(days, collapse = "|"))]
if (!length(MFIMatches) == 0){
file.copy(MFIMatches, WorkingFolder)
walk(.x=Instrument, .f=Luciernaga:::QCBeadParse, MainFolder=MainFolder)
}
} else {message("QC data has already been transferred")
MFIMatches <- NULL
}
if (!length(PotentialAppsDays) == 0){
SetupFolder <- file.path("C:", "CytekbioExport")
TheSetupFiles <- list.files(SetupFolder, pattern="Application", full.names=TRUE)
MonthStyle <- format(Today, "%Y-%m")
MonthStyle <- sub("([0-9]{4})-([0-9]{2})", "\\2-\\1", MonthStyle)
MonthStyle <- gsub("-", " ", MonthStyle)
MonthStyle <- paste0(MonthStyle, ".txt")
AppMatches <- TheSetupFiles[str_detect(TheSetupFiles, str_c(MonthStyle, collapse = "|"))]
if (!length(AppMatches) == 0){
if (any(length(GainMatches)|length(MFIMatches) > 0)){
file.copy(AppMatches, WorkingFolder)
walk(.x=Instrument, .f=Luciernaga:::AppQCParse, MainFolder=MainFolder)
}
}
} else {message("QC data has already been transferred")
AppMatches <- NULL
}
if (any(length(PotentialGainDays)|length(PotentialMFIDays)|length(PotentialAppsDays) > 0)){
if (any(length(GainMatches)|length(MFIMatches) > 0)){
# Stage to Git
git2r::add(TheRepo, "*")
TheCommitMessage <- paste0("Update for ", Instrument, " on ", Today)
git2r::commit(TheRepo, message = TheCommitMessage)
cred <- git2r::cred_token(token = "GITHUB_PAT")
git2r::push(TheRepo, credentials = cred)
message("Done ", Today)
} else {message("No files to process ", Today)}
} else {message("No files to process ", Today)}
} else {message("Automation Skipped ", Today)}