-
Notifications
You must be signed in to change notification settings - Fork 0
/
functional_characterization.1.R
executable file
·153 lines (120 loc) · 6.97 KB
/
functional_characterization.1.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
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/mlab/data/software/R-3.2.1-F22/bin/Rscript
## !/usr/bin/Rscript
############################################################################################
##
## Written by Sen Yao, 07/20/2016
## Copyright Sen Yao, Robert Flight, and Hunter Moseley, 07/20/2016. All rights reserved.
##
###########################################################################################
################
## simulation
################
library(IRanges)
library(atom2seq)
library(Biobase)
library(magrittr)
args = commandArgs(trailingOnly=TRUE)
setwd(args[1])
load("non_redundant.RData")
interproRes <- read.table("non_redundant.ipr.tsv", sep="\t", header=FALSE, stringsAsFactors=FALSE, fill=TRUE, quote="", comment.char="")
names(interproRes) <- c("id", "md5", "length", "analysis", "sigAccession", "sigDescription", "start", "stop", "score", "status", "date", "iprAccession", "iprDescription", "GO", "Pathways")
iprData <- unique(interproRes[, c("iprAccession", "iprDescription")])
rownames(iprData) <- iprData$iprAccession
# split this into a list based on the ID string, and then transform to ranges with associated meta data.
splitInter <- split(interproRes, interproRes$id)
splitRanges_all <- lapply(splitInter, interpro2ranges, unique_on = c("sigAccession", "start", "stop"), require_char = "sigAccession")
splitRanges_ipr <- lapply(splitInter, interpro2ranges, unique_on = c("iprAccession", "start", "stop"), require_char = "iprAccession")
# These are what we will work with for all subsequent calculations. `splitInter` has the
# **InterProScan** results split up by the chain, and `splitRanges` has the **InterProScan**
# ranges with the other data as *mcols*. Here they are done two different ways, with *all* of
# the annotations, and with those that have an **InterProScan** database ID with a decent description.
ligand_2_ipr <- subset_annotation_by_ligand(splitRanges_ipr, ligand_ranges)
ligand_ranges_full <- lapply(ligand_ranges, convert_ligands_to_ranges)
ligand_2_ipr_full <- subset_annotation_by_ligand(splitRanges_ipr, ligand_ranges_full)
chain_to_ipr <- lapply(ligand_2_ipr, get_unique_mcol)
chain_to_ipr_full <- lapply(ligand_2_ipr_full, get_unique_mcol)
site_to_chain <- split(non_red$chain.id, non_red$zinc.id)
site_to_ipr <- collapse_chain_to_annotation(chain_to_ipr, site_to_chain)
min_ligands <- c(1, 2, 3, 4)
chain_min_ligands <- lapply(min_ligands, function(min_count){
non_red$chain.id[non_red$ligand.count >= min_count]
})
names(chain_min_ligands) <- min_ligands
annotation_subset_ligands <- lapply(chain_min_ligands, function(in_chains){
tmp_subset <- subset_annotation_by_ligand(splitRanges_ipr, ligand_ranges[in_chains])
tmp_annotation <- lapply(tmp_subset, get_unique_mcol)
tmp_to_ipr <- collapse_chain_to_annotation(tmp_annotation, site_to_chain)
annotation_2_chain <- reverseSplit(tmp_to_ipr)
})
annotation_subset_ligands_full <- lapply(chain_min_ligands, function(in_chains){
tmp_subset <- subset_annotation_by_ligand(splitRanges_ipr, ligand_ranges_full[in_chains])
tmp_annotation <- lapply(tmp_subset, get_unique_mcol)
tmp_to_ipr <- collapse_chain_to_annotation(tmp_annotation, site_to_chain)
annotation_2_chain <- reverseSplit(tmp_to_ipr)
})
setwd(paste("./simulation/", args[2], "_", args[3],sep=""))
load("normal_cluster_assg.RData")
normal_cluster_names <- paste("normal", seq(2, 30), "clusters", sep = ".")
normal_clusters <- lapply(normal_cluster_names, function(in_cluster){
tmp <- eval(parse(text = in_cluster))
split(tmp[,1], tmp[,2])
})
names(normal_clusters) <- normal_cluster_names
#load("compressed_cluster_assg.RData")
#compressed_cluster_names <- paste("compressed", seq(2, 30), "clusters", sep = ".")
#compressed_clusters <- lapply(compressed_cluster_names, function(in_cluster){
# tmp <- eval(parse(text = in_cluster))
# split(tmp[,1], tmp[,2])
#})
#names(compressed_clusters) <- compressed_cluster_names
#load("combined_cluster_assg.RData")
#combined_cluster_names <- paste("combined", seq(2, 30), "clusters", sep = ".")
#combined_clusters <- lapply(combined_cluster_names, function(in_cluster){
# tmp <- eval(parse(text = in_cluster))
# split(tmp[,1], tmp[,2])
#})
#names(combined_clusters) <- combined_cluster_names
normal_combs <- expand.grid(names(annotation_subset_ligands_full), names(normal_clusters), stringsAsFactors = FALSE)
get_n_clust <- function(in_name){
as.numeric(regmatches(in_name, regexpr("\\d{1,2}", in_name)))
}
normal_combs_names <- paste(normal_combs[,1], normal_combs[,2], sep = ",")
normal_combs$n_clust <- get_n_clust(normal_combs[,2])
normal_funct_dist <- lapply(seq(1, nrow(normal_combs)), function(in_comb){
annotation_index <- normal_combs[in_comb, 1]
cluster_index <- normal_combs[in_comb, 2]
calculate_functional_distance2(annotation_subset_ligands_full[[annotation_index]],
normal_clusters[[cluster_index]])
})
names(normal_funct_dist) <- normal_combs_names
#compressed_combs <- expand.grid(names(annotation_subset_ligands_full), names(compressed_clusters), stringsAsFactors = FALSE)
#compressed_combs_names <- paste(compressed_combs[,1], compressed_combs[,2], sep = ",")
#compressed_funct_dist <- lapply(seq(1, nrow(compressed_combs)), function(in_comb){
# annotation_index <- compressed_combs[in_comb, 1]
# cluster_index <- compressed_combs[in_comb, 2]
# calculate_functional_distance2(annotation_subset_ligands_full[[annotation_index]],
# compressed_clusters[[cluster_index]])
#})
#names(compressed_funct_dist) <- compressed_combs_names
#compressed_combs$n_clust <- get_n_clust(compressed_combs[,2])
#combined_combs <- expand.grid(names(annotation_subset_ligands_full), names(combined_clusters), stringsAsFactors = FALSE)
#combined_combs_names <- paste(combined_combs[,1], combined_combs[,2], sep = ",")
#combined_combs$n_clust <- get_n_clust(combined_combs[,2])
#combined_funct_dist <- lapply(seq(1, nrow(combined_combs)), function(in_comb){
# annotation_index <- combined_combs[in_comb, 1]
# cluster_index <- combined_combs[in_comb, 2]
# calculate_functional_distance2(annotation_subset_ligands_full[[annotation_index]],
# combined_clusters[[cluster_index]])
#})
normal_funct_dist <- Map(cleanup_dist, normal_funct_dist, normal_combs$n_clust)
names(normal_funct_dist) <- normal_combs_names
#compressed_funct_dist <- Map(cleanup_dist, compressed_funct_dist, compressed_combs$n_clust)
#names(compressed_funct_dist) <- compressed_combs_names
#combined_funct_dist <- Map(cleanup_dist, combined_funct_dist, combined_combs$n_clust)
#names(combined_funct_dist) <- combined_combs_names
save(normal_funct_dist, normal_combs, file = "normal_funct_dist.RData")
#save(compressed_funct_dist, compressed_combs, file = "compressed_funct_dist.RData")
#save(combined_funct_dist, combined_combs, file = "combined_funct_dist.RData")
# save(normal_clusters, compressed_clusters, file = "named_clusters.RData")
#save(normal_clusters, compressed_clusters, combined_clusters, file = "named_clusters.RData")
#save(annotation_subset_ligands_full, file = "annotation_subset_ligands_full.RData")