-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCode_Snippets.R
87 lines (63 loc) · 2.27 KB
/
Code_Snippets.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
# Very fast method of getting number of events and parameters from FCS files
if (!require("svDialogs")) {
install.packages("svDialogs", dependencies = TRUE)
library(svDialogs)
}
if (!require("scales")) {
install.packages("scales", dependencies = TRUE)
library(scales)
}
if (!require("tcltk2")) {
install.packages("tcltk2", dependencies = TRUE)
library(tcltk2)
}
# Get user input for file
testfile<-dlg_open()
# Convert to string value
testfile <- capture.output(testfile)[7]
#Remove invalid characters from file input location
testfile <- gsub("[\"]","",testfile)
testfile<-substring (testfile,5)
#Set file and directory
file <- basename (testfile)
dir <- dirname (testfile)
# Set working directory accoding to file chosen
setwd(dir)
# List FCS (and fcs!) files in this location
filesToOpenList <- unique(c(list.files(dir,pattern = ".FCS"),list.files(dir,pattern = ".fcs")))
# Ask to open all files
if (length(filesToOpenList)>1){
OpenAllFiles <- askYesNo("Analyse All FCS Files in this directory?")
}
# Open all FCS files
if (OpenAllFiles==TRUE){
Events <- NULL
Params <- NULL
for (i in filesToOpenList){
# Scan first few lines of FCS file(s)
temp <- scan(i, what="", n=20)
# Number of Events in FCS file
# $TOT\f for Aria / Canto
# $TOT/ for CyTOF
Events <- c(Events, as.numeric(sub(".*\\$TOT/([0-9]+).*|.*\\$TOT\f([0-9]+).*", "\\1", temp[grep("TOT", temp)])))
# Number of parameters
Params <- c(Params, as.numeric(sub(".*\\$PAR/([0-9]+).*|.*\\$PAR\f([0-9]+).*", "\\1", temp[grep("PAR", temp)])))
}
}else{
# Ask which files to open
filesToOpenList <- tk_select.list(filesToOpenList, multiple=TRUE,title="Select files to use.")
Events <- NULL
Params <- NULL
for (i in filesToOpenList){
# Scan first few lines of FCS file(s)
temp <- scan(i, what="", n=20)
# Number of Events in FCS file
# $TOT\f for Aria / Canto
# $TOT/ for CyTOF
Events <- c(Events, as.numeric(sub(".*\\$TOT/([0-9]+).*|.*\\$TOT\f([0-9]+).*", "\\1", temp[grep("TOT", temp)])))
# Number of parameters
Params <- c(Params, as.numeric(sub(".*\\$PAR/([0-9]+).*|.*\\$PAR\f([0-9]+).*", "\\1", temp[grep("PAR", temp)])))
}
}
# Show table
cbind("Files" = filesToOpenList, "Events" = scales::comma(Events), Params)