我在 python 中乱搞类并写了两个小类:
class ClaElement:
start = None
end = None
basesLeft = None
orientation = None
contig = None
size = None
def __init__(self, contig, start, end, orientation, basesLeft=None):
self.contig = contig
self.start = start
self.end = end
self.orientation = orientation
self.basesLeft = basesLeft
self.size = self.end - self.start
def __str__(self):
return "{ClaElement: "+str(self.contig)+"_"+str(self.start)+"_"+str(self.end)+"_"+str(self.orientation)+"}"
def getSize(self):
return self.size
class ClaCluster:
contig = None
clusterElements = []
def __init__(self, contig, firstElement):
self.contig = contig
self.addElement(firstElement)
def addElement(self, claElement):
self.clusterElements.append(claElement)
def …
Run Code Online (Sandbox Code Playgroud) 我想根据ggplot2的geom_count计算颜色.
这是我到目前为止:
ggplot(test3, aes(eleStart, eleLength)) + geom_count(aes(alpha=0.25, color= ..prop..)) +
scale_y_continuous(breaks=seq(0,130,5)) +
scale_x_continuous(breaks=seq(0,114)) +
theme(panel.grid.minor = element_blank())
Run Code Online (Sandbox Code Playgroud)
现在我基本上只想geom_count
用geom_count计算的实际计数而不是它们的比例进行交换.
test3数据帧看起来像:
# A tibble: 294 x 2
# Groups: X1 [56]
eleStart eleLength
<int> <int>
1 0 3
2 0 6
3 0 7
4 0 9
5 0 11
6 0 23
7 0 25
8 0 26
9 0 26
10 0 26
# ... with 284 more rows
Run Code Online (Sandbox Code Playgroud) 当我说binwidth = 20
我得到前者时,我无法正确控制 bin 是从 -10 到 +10 还是从 0 到 20,但我有从 1 开始的数据,我不希望间隔进入负数。
这是我的问题的一个例子:
testData = data.frame(x=c(1,4,6,9,9))
ggplot(data=testData, aes(x=testData$x)) +
geom_histogram(binwidth=3, aes(col=I("white"))) +
scale_x_continuous(breaks=c(1,2,3,4,5,6,7,8,9,10))
Run Code Online (Sandbox Code Playgroud)
很奇怪,如果我使用,binwidth = 2
我最终会得到我想要的间隔:
ggplot(data=testData, aes(x=testData$x)) +
geom_histogram(binwidth=2, aes(col=I("white"))) +
scale_x_continuous(breaks=c(1,2,3,4,5,6,7,8,9,10))
Run Code Online (Sandbox Code Playgroud)
对于更大的数据集,如何让我的 bin 从 1..20、21..40 等开始?
我想使用来自ggplot2的geom_count图,但是值的范围太小,图例中断变成了发生次数的浮点,例如 1 1.5 2 2.5 3
这是一个测试案例:
test = mtcars[1:6,]
ggplot(test, aes(cyl, carb)) +
geom_count(aes(color = ..n.., size = ..n..)) +
guides(color = 'legend')
Run Code Online (Sandbox Code Playgroud)
如何使中断仅发生在整数上?
我无法让这个工作:
awk -F ";" '{for(i=1; i < NF;i++) $i ~ /^_.*/ {print $i}}'
Run Code Online (Sandbox Code Playgroud)
我想迭代所有字段(记录可以有7-9)并且只打印那些以_
上面的行开头的那些在print语句中给出了语法错误,如果我省略了{print $i}
我没有得到任何输出.
这样做的正确方法是怎样的?
我试图使用列表推导来从列表中删除一些项目,只需保留未指定的项目.
例如,如果我有2个列表,a = [1,3,5,7,10]
并且b = [2,4]
我希望保留所有项目a
不在与数字相对应的索引中b
.
现在,我尝试使用,y = [a[x] for x not in b]
但这会产生一个SyntaxError.
y = [a[x] for x in b]
工作正常,并保持我想要删除的元素.
那我该怎么做呢?另外,这是一个很好的方法,或者我应该使用del
?