-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreadAmplitudeFiles.R
74 lines (69 loc) · 3.11 KB
/
readAmplitudeFiles.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
ddPCRdata <- setClass("ddPCRdata", slots = c(assayData = "list", phenoData = "list", experimentData = "list"))
readAmplitudeFiles <- function(files, nrows=25000, verbose=FALSE){ # not used in pipeline
nFiles <- length(files)
Ch1.Amplitude <- matrix(NA, nrow = nrows, ncol = nFiles)
Ch2.Amplitude <- matrix(NA, nrow = nrows, ncol = nFiles)
Cluster <- matrix(NA, nrow = nrows, ncol = nFiles)
Color <- matrix(NA, nrow = nrows, ncol = nFiles)
Use <- matrix(FALSE, nrow = nrows, ncol = nFiles)
Total.Droplets <- rep(NA, nFiles)
Sample.Names <- rep("NA", nFiles)
Ch1.Max <- rep(NA, nFiles)
Ch2.Max <- rep(NA, nFiles)
for(i in 1:nFiles)
{
if(file.exists(files[i]) == TRUE)
{
sample.data <- read.table(file = files[i], header = TRUE,sep = ",")
if(verbose == TRUE){
if(dim(sample.data)[1] > nrows){
cat("Too many rows in data file: '", basename(files[i]),"'\n", sep="")
next
} else {cat("Reading amplitude data: '", basename(files[i]),"'\n", sep="")}
}
Sample.Names[i] <- mgsub(x=basename(files[i]), pattern = c("_Amplitude.csv",".csv"), replacement = c("",""))
### ADD PHENODATA
columns <- c("totalDroplets","minOutlier","maxOutlier","threshold","thresholdMeanStDev","minAmplitude","maxAmplitude","minRain","maxRain")
channel.1 <- matrix(data = NA, nrow = length(Sample.Names), ncol = length(columns),
dimnames = list(Sample.Names, columns))
channel.2 <- matrix(data = NA, nrow = length(Sample.Names), ncol = length(columns),
dimnames = list(Sample.Names, columns))
Total.Droplets[i] <- dim(sample.data)[1]
Ch1.Amplitude[1:Total.Droplets[i],i] <- sample.data[,1]
Ch2.Amplitude[1:Total.Droplets[i],i] <- sample.data[,2]
Cluster[1:Total.Droplets[i],i] <- sample.data[,3]
Use[1:Total.Droplets[i],i] <- TRUE
Ch1.Max[i] <- max(sample.data[,1])
Ch2.Max[i] <- max(sample.data[,2])
}
}
assayData <- list(Ch1.Amplitude = Ch1.Amplitude, Ch2.Amplitude = Ch2.Amplitude, Cluster = Cluster, Use = Use)
phenoData <- list(channel.1 = channel.1, channel.2 = channel.2)
experimentData <- list(
Channel.Name=c("Ch1.Amplitude" ,"Ch2.Amplitude"),
Cluster.Number=c(1,2,3,4,0,5),
Cluster.Name=c("ch1-ch2-", "ch1+ch2-", "ch1+ch2+", "ch1-ch+", "outlier", "rain"),
Cluster.Color=c("black", "blue", "orange", "green", "red", "purple")
)
object <- new('ddPCRdata', assayData=assayData, phenoData=phenoData, experimentData=experimentData)
return(object)
}
combineSamples <- function(path, files, verbose = FALSE){
combined.data <- NULL
if(verbose == TRUE){
cat("Reading Amplitude files.\n")
}
for(i in 1:length(files))
{
nrlines <- NULL
file.name <- file.path(path, files[i])
if(length(count.fields(file.name)) > 0){
sample.data <- read.table(file=file.name, header = TRUE, sep = ",")
combined.data <- rbind(combined.data, sample.data )
}
}
if(verbose == TRUE){
cat("Amplitude files are combined.\n")
}
return(combined.data)
}