-
Notifications
You must be signed in to change notification settings - Fork 1
/
blockShift.R
89 lines (70 loc) · 2.24 KB
/
blockShift.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
rppa.vshift.vector <- function (v, by)
{
if (by == 0) return(v)
else if (by >= 0) return(c(NA + 1:by, v[1:(length(v) - by)]))
else return(c(v[(-by + 1):(length(v) - by)]))
}
rppa.hshift <- function(spots)
{
if(!is.null(attr(spots, "hshifted")))
{
cat("This slide has already been vshifted! Do you really want to continue? (yes/no)")
answer <- readline()
if(answer != "yes") return()
}
range <- min(spots$Block): max(spots$Block)
for(b in range)
{
blockB <- subset(spots, Block == b)
spots[spots$Block==b,] <- unsplit(
lapply(split(blockB, blockB$Row), function(x)
{
by <- unique(x$hshift)
x <- x[with(x, order(Column)),]
x$Signal <- rppa.vshift.vector(x$Signal, by)
x$FG <- rppa.vshift.vector(x$FG, by)
x$BG <- rppa.vshift.vector(x$BG, by)
x$Flag <- rppa.vshift.vector(x$Flag, by)
x$Diameter <- rppa.vshift.vector(x$Diameter, by)
return(x)
}), blockB$Row)
}
attr(spots, "hshifted") <- TRUE
return(spots)
}
rppa.vshift <- function(spots, blocks=NA, rows=NA, by=NA)
{
if(!is.null(attr(spots, "vshifted"))){
cat("This slide has already been vshifted! Do you really want to continue?")
answer <- readline()
if(answer != "yes") return()
}
if(is.na(blocks[1])) range <- min(spots$Block):max(spots$Block)
else range <- blocks
for(b in range)
{
blockB <- subset(spots, Block==b);
spots[spots$Block==b,] <- unsplit(
lapply(split(blockB, blockB$Column), function(x, rows, by)
{
if(is.na(by))
by <- unique(x$vshift)
x <- x[with(x, order(Row)),]
if(is.na(rows[1])){
x$Signal <- rppa.vshift.vector(x$Signal, by)
x$FG <- rppa.vshift.vector(x$FG, by)
x$BG <- rppa.vshift.vector(x$BG, by)
x$Flag <- rppa.vshift.vector(x$Flag, by)
x$Diameter <- rppa.vshift.vector(x$Diameter, by)
}
else{
for(field in c("Signal", "FG", "BG"))
x[rows,field] <- rppa.vshift.vector(x[rows, field], by)
}
return(x);
}, rows=rows, by=by)
, blockB$Column)
}
attr(spots, "vshifted") <- TRUE
return(spots)
}