-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRCircos.Chromosome.Region.Plot.R
147 lines (122 loc) · 6.15 KB
/
RCircos.Chromosome.Region.Plot.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
RCircos.Get.Plot.Region<-function(genomic.data, plot.type)
{
# Check chromosome names, chromStart, and chromEnd positions
# _______________________________________________________________
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
genomic.data <- RCircos.Validate.Genomic.Data(genomic.data, plot.type);
# Calculate the point index for each chromosome location
# _______________________________________________________________
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
data.points <- rep(0, nrow(genomic.data));
start.points <- rep(0, nrow(genomic.data));
end.points <- rep(0, nrow(genomic.data));
for(a.row in 1:nrow(genomic.data))
{
chromosome <- as.character(genomic.data[a.row, 1]);
location <- round((genomic.data[a.row, 2] + genomic.data[a.row, 3])/2, digits=0);
start.location <- genomic.data[a.row,2]
end.location <- genomic.data[a.row,3]
data.points[a.row] <- RCircos.Data.Point(chromosome, location);
start.points[a.row] <- RCircos.Data.Point(chromosome, start.location);
end.points[a.row] <- RCircos.Data.Point(chromosome, end.location);
}
genomic.data["Location"] <- data.points;
genomic.data["Start"] <- start.points;
genomic.data["End"] <- end.points;
# Sort the data by chromosome then start position
# ____________________________________________________
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
genomic.data <- genomic.data[order(genomic.data$Location),];
# The data needs to be held for the RCircos session
# ____________________________________________________
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
return (genomic.data);
}
RCircos.Chromosome.Region.Plot<-function(region, track.num, side)
{
RCircos.Cyto <- RCircos.Get.Plot.Ideogram()
RCircos.Pos <- RCircos.Get.Plot.Positions()
RCircos.Par <- RCircos.Get.Plot.Parameters()
# Plot chromosome outlines, chromosome names, and
# chromosome highlights
# _________________________________________________________
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
region.data <- RCircos.Get.Plot.Region(region, "plot");
start <-as.numeric(region.data[, "Start"]);
end <-as.numeric(region.data[, "End"]);
right.side <- nrow(RCircos.Pos)/2;
outer.location <- RCircos.Par$chr.ideog.pos + RCircos.Par$chrom.width;
inner.location <-RCircos.Par$chr.ideog.pos
data.chroms <- as.character(region[,1]);
chromosomes <- unique(data.chroms);
cyto.chroms <- as.character(RCircos.Cyto$Chromosome);
#--------------------------------------------------
# for(a.chr in 1:length(chromosomes))
# {
# cyto.rows <- which(cyto.chroms==chromosomes[a.chr]);
# locations <- as.numeric(RCircos.Cyto$Location[cyto.rows]);
# chr.start <- min(locations) - RCircos.Cyto$Unit[cyto.rows[1]];
# chr.end <- max(locations);
#--------------------------------------------------
#--------------------------------------------------
# data.rows <- which(data.chroms==chromosomes[a.chr]);
# start[data.rows[start[data.rows]<chr.start]] <- chr.start;
# end[data.rows[end[data.rows]>chr.end]] <- chr.end;
# }
#--------------------------------------------------
locations <- RCircos.Track.Positions(side, track.num);
out.pos <- locations[1];
in.pos <- locations[2];
source("./RCircos.Track.Outline.Simple.R")
RCircos.Track.Outline.Simple(out.pos, in.pos);
a.band =1
for (a.band in 1:nrow(region.data)) {
a.color <- "gray"
if (a.color == "white") {
next
}
a.start <- start[a.band]
a.end <- end[a.band]
#--------------------------------------------------
# pos.x <- c(RCircos.Pos[start:end, 1] * outer.location, RCircos.Pos[end:start, 1] * inner.location)
# pos.y <- c(RCircos.Pos[start:end, 2] * outer.location, RCircos.Pos[end:start, 2] * inner.location)
# polygon(pos.x, pos.y, col = a.color, border = NA)
# the.chr <- RCircos.Cyto[RCircos.Cyto$Chromosome==chroms[a.chr],];
# start <- the.chr$Location[1]- the.chr$Unit[1] + 1;
# end <- the.chr$Location[nrow(the.chr)];
#--------------------------------------------------
polygon.x<- c(RCircos.Pos[a.start:a.end,1]*out.pos, RCircos.Pos[a.end:a.start,1]*in.pos);
polygon.y<- c(RCircos.Pos[a.start:a.end,2]*out.pos, RCircos.Pos[a.end:a.start,2]*in.pos);
polygon(polygon.x, polygon.y, col=a.color);
}
#--------------------------------------------------
# for(a.chr in 1:length(chroms))
# {
# the.chr <- RCircos.Cyto[RCircos.Cyto$Chromosome==chroms[a.chr],];
# start <- the.chr$Location[1]- the.chr$Unit[1] + 1;
# end <- the.chr$Location[nrow(the.chr)];
# mid <- round((end-start+1)/2, digits=0)+start;
# chr.color <- the.chr$ChrColor[nrow(the.chr)];
# # Draw chromosome outlines
# # _________________________________________________________
# # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
# pos.x<- c(RCircos.Pos[start:end,1]*outer.location, RCircos.Pos[end:start,1]*inner.location);
# pos.y<- c(RCircos.Pos[start:end,2]*outer.location, RCircos.Pos[end:start,2]*inner.location);
# polygon(pos.x, pos.y);
# # Add chromosome names
# # _________________________________________________________
# # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
# chr.name <- sub(pattern="chr", replacement="", chroms[a.chr]);
#--------------------------------------------------
#--------------------------------------------------
# text(RCircos.Pos[mid,1]*RCircos.Par$chr.name.pos, RCircos.Pos[mid,2]*RCircos.Par$chr.name.pos,
# label=chr.name, srt=RCircos.Pos$degree[mid]);
#--------------------------------------------------
#--------------------------------------------------
# # Add chromosome highlights
# # _________________________________________________________
# # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
# lines(RCircos.Pos[start:end,]*RCircos.Par$highlight.pos, col=chr.color, lwd=RCircos.Par$highlight.width);
# }
#--------------------------------------------------
}