forked from cnobles/makeUCSCHubFromBedFiles
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsampleScript.R
More file actions
58 lines (41 loc) · 1.71 KB
/
sampleScript.R
File metadata and controls
58 lines (41 loc) · 1.71 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
library("dplyr")
library("R.utils")
options(dplyr.width = Inf)
cmd <- "Rscript ~/geneTherapyPatientReportMaker/check_patient_gtsp.R | grep bthal | grep pPa"
res <- system(cmd, intern=TRUE)
res <- plyr::ldply(strsplit(res, "\t"))
colnames(res) <- c("trial", "patient", "cell", "time", "gtsp", "replicate", "freeze", "sex")
cmd <- paste("Rscript ~/makeUCSCHubFromBedFiles/GTSP2BED_fromDB.R",
paste(unique(res$gtsp), collapse=" "))
system(cmd)
process_sample <- function(trial, patient, cell, time, gtsp) {
fileName <- unique(paste(trial, patient, cell, time, "bed", sep="."))
cmd <- paste("cat", paste(paste0(unique(gtsp), ".bed"), collapse=" "),
">", fileName)
system(cmd)
return(fileName)
}
bedfiles <- (res %>% group_by(trial, patient, cell, time) %>%
summarize(fn=process_sample(trial, patient, cell, time, gtsp)))
csv <- (mutate(bedfiles,
Sample=paste(trial, patient, cell, time, sep="."),
bedfile=fn,
Notes=Sample,
freeze="hg18",
hub="bthal") %>%
ungroup %>%
select(Sample,bedfile,Notes,freeze,hub) )
csv$nrow <- sapply(csv$bedfile, countLines)
csv <- subset(csv, nrow != 0 )
write.csv(csv, file="bed.csv", row.names=FALSE, quote=FALSE)
cmd <- "Rscript ~/makeUCSCHubFromBedFiles/makeUCSChubFromBedFiles.R bed.csv"
system(cmd)
## generate hub for a run after generating bed files
hub <- "run20150728"
freeze <- "hg18"
pattern <- "all.bed"
bedfile <- list.files(".", pattern=pattern)
Sample <- sub(pattern, "", bedfile)
Notes <- sub(".*-(\\d+)", "\\1", Sample)
df <- data.frame(Sample,bedfile,Notes,freeze,hub)
write.csv(df, file="bed.csv", quote=FALSE, row.names=FALSE)