-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFiloQuant_Merge_Analysis.R
70 lines (48 loc) · 1.89 KB
/
FiloQuant_Merge_Analysis.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
##FOR shCTRLm
##set the working directory for the desired group of files for analysis
library(readr)
library(ggplot2)
library(RColorBrewer)
library(reshape2)
library(gridExtra)
library(tools)
library(plyr)
library(matrixStats)
library(tidyverse)
path <- file.choose()
DIR <- dirname(path)
##call a certain type of file, in this case anything ending with .csv,
##and populate it into a list called "filename"
filenames <- dir(DIR, full.names=TRUE, pattern =".csv")
filename_short <- file_path_sans_ext(basename(filenames))
##Create a "vector"? named filopodiaCounts and have this hold the number of rows counted
##in each .csv file
##skip = 1 is because the first two rows in each file is 1.header
##Retrieve filopodia counts
shCTRLmfilopodiaCounts <- sapply(filenames, function(f) nrow(read.csv(f, header = F, skip = 1)))
data.frame(shCTRLmfilopodiaCounts)
# retrieve edge length
EdgeL <- data.frame(nrow = length(filenames), ncol = 2)
for (filename in filenames) {
p = file_path_sans_ext(basename(filename))
Values <- read_csv(filename)
colnames(Values) <- c("ID","x","y" ,"Length", "edge")
EdgeL[filename, ] <- sum(Values$edge)
}
EdgeL <- EdgeL[-c(1),]
colnames(EdgeL) <- c("Name", "edge")
# Average Filopodia length
AverageLength <- data.frame(nrow = length(filenames), ncol = 2)
for (filename in filenames) {
p = file_path_sans_ext(basename(filename))
Values <- read_csv(filename)
colnames(Values) <- c("ID","x","y" ,"Length", "edge")
AverageLength[filename, ] <- mean(Values$Length)
}
AverageLength <- AverageLength[-c(1),]
colnames(AverageLength) <- c("x", "y")
Results <- data.frame(filename_short, shCTRLmfilopodiaCounts,EdgeL$edge, AverageLength$x)
colnames(Results) <- c("filename","Filopodia_count", "EdgeL", "Average_Length")
# Rename the result table
##the other paralog filopodia counts also
write.csv(Results, file=paste(DIR, "_Results.csv", sep=""), row.names = T)