-1

输入1

dput(a1  100 200 +
a1  250 270 +
a1  333 340 -
a2  450 460 +)

输入2

dput(a1  101 106 +
a1  112 117 +
a1  258 259 +
a1  258 259 +
a1  258 259 +
a1  258 259 +
a1  258 259 +
a1  258 259 +
a1  258 259 +
a1  258 259 +
a1  258 259 +
a1  260 262 +
a1  260 262 + 
a1  260 262 + 
a1  260 262 + 
a1  260 262 + 
a1  332 333 -
a1  332 333 -
a1  332 333 -
a1  332 333 -
a1  332 333 -
a1  332 333 -
a1  332 333 -
a1  331 333 -
a1  331 333 -
a1  331 333 -
a1  331 333 -
a1  331 333 -
a1  331 333 -)

输出

c   s   e   st  1   2   3   4   5   6   7   8   9   10
a1  100 200 +   1   2   0   0   0   0   0   0   0   0
a1  250 270 +   0   0   0   9   5   0   0   0   0   0
a1  330 340 -   0   0   0   0   0   0   0   6   7   0
a2  450 460 +   0   0   0   0   0   0   0   0   0   0

我想使用 input1 值计算点的密度(input2)。表示 a1-100-200 在这 100 到 200 范围内有多少个点?即3。我想对所有输入值做同样的事情。我想互相比较。但问题是值的长度(200-100=100 或 270-250=20)不同。为了将它们相互比较,我需要以我可以比较的方式缩放它们。所以我想出了 10 个 bins 窗口(输出)。我使用 input1 bin 计算 input2 点。最后,我需要在 x 轴上绘制 bin,在 y 轴上绘制值 xyplot(x(bins),y1(a1:100:200:+)+y2(a1:250:270:+y3...+y4)

“+”表示我们在计算 bin 时需要以 100 作为起点,以 200 作为终点(100-110 将是第一个 bin .....) - 表示完全相反(190-200 将是第一个 bin)

1-10 表示 1 到 10 个 bin

您需要根据 column1 键为 bin 使用第 1 列和第 2 列。我们删除不在范围内的值

c = 字符,s =start,e=end,s=strand,1-10 是 input1 的 bin。是的,你是对的。例如 250-270 应该有 2 个数字差异,因为(270-250=20,因此对于 10 个箱,它将是 20/10=2)

4

1 回答 1

1

The question is still not very well formed so I'm not sure I've quite understood what you want, but you probably want to use a combination of table and cut.

Your sample data

input1 <- data.frame(
  type  = paste("a", rep(1:2, times = c(3, 1)), sep = ""),
  lower = c(100, 250, 333, 450),
  upper = c(200, 270, 340, 460)
)

input2 <- data.frame(
  type = rep.int("a1", 28),
  lower = rep(c(101, 112, 258, 260, 332, 331), times = c(1, 1, 9, 5, 7, 5)),
  upper = rep(c(106, 117, 259, 262, 333), times = c(1, 1, 9, 5, 12))
)

First you define bins based upon the values in input1.

cut_points <- with(input1, sort(c(start, end)))

Then split input2$start by type, cut it up by bins and find the count in each.

with(input2, tapply(start, type, function(x) table(cut(x, cut_points))))

Possibly repeat with the end column.

with(input2, tapply(end, type, function(x) table(cut(x, cut_points))))
于 2011-08-04T12:58:00.863 回答