我使用networkx模块在python2.7中有以下函数,产生错误.
for H in networkx.connected_component_subgraphs(G):
bestScore = -1.0
for n, d in H.nodes_iter(data=True):
if d['Score'] > bestScore:
bestScore = d['Score']
bestSV = n
if bestSV is not None:
selectedSVs.add(bestSV)
Run Code Online (Sandbox Code Playgroud)
错误:
Traceback (most recent call last):
File "cnvClassifier.py", line 128, in <module>
for n, d in H.nodes_iter(data=True):
AttributeError: 'Graph' object has no attribute 'nodes_iter'
Run Code Online (Sandbox Code Playgroud)
有谁知道出了什么问题?
我有三个文件,如下所示
FILE1.TXT
"aba" 0 0
"aba" 0 0 1
"abc" 0 1
"abd" 1 1
"xxx" 0 0
Run Code Online (Sandbox Code Playgroud)
FILE2.TXT
"xyz" 0 0
"aba" 0 0 0 0
"aba" 0 0 0 1
"xxx" 0 0
"abc" 1 1
Run Code Online (Sandbox Code Playgroud)
file3.txt
"xyx" 0 0
"aba" 0 0
"aba" 0 1 0
"xxx" 0 0 0 1
"abc" 1 1
Run Code Online (Sandbox Code Playgroud)
我想基于前两列找到所有三个文件中的类似元素.为了找到两个文件中的类似元素,我使用了类似的东西
awk 'FNR==NR{a[$1,$2]++;next}a[$1,$2]' file1.txt file2.txt
Run Code Online (Sandbox Code Playgroud)
但是,当输入文件超过2时,我们怎样才能在所有文件中找到类似的元素?有人可以帮忙吗?
使用当前的awk解决方案,输出会忽略重复的键列并将输出作为
"xxx" 0 0
Run Code Online (Sandbox Code Playgroud)
如果我们假设输出来自file1.txt,则预期输出为:
"aba" 0 0
"aba" 0 0 1
"xxx" 0 0
Run Code Online (Sandbox Code Playgroud)
即它应该获得具有重复键列的行.
我有一个文件列,如下所示:
chr1 91.4062
chr10 97.9150
chr11 116.7630
chr12 106.7870
chr13 116.1050
chr14 126.2180
chr15 110.2320
chr16 96.8076
chr17 113.5970
chr18 86.1011
chr19 130.6770
chr2 111.4620
chr20 68.4864
chr21 107.0810
chr22 140.7750
chr23 110.9590
chr24 68.4785
chr25 102.2080
chr26 72.2762
chr27 96.2213
chr28 85.5570
chr29 126.3800
chr3 116.1830
chr30 89.5663
chr31 89.1227
chr32 128.6190
chr4 117.3620
chr5 78.1921
chr6 85.4915
chr7 107.2620
chr8 112.9560
chr9 69.0250
chrX 66.0736
Run Code Online (Sandbox Code Playgroud)
我想基于第1列对其进行排序,输出应如下所示:
chr1 91.4062
chr2 111.4620
chr3 116.1830
chr4 117.3620
chr5 78.1921
chr6 85.4915 …
Run Code Online (Sandbox Code Playgroud) 我有两个文件,如下所示,以制表符分隔:
档案A.
chr1 123 aa b c d
chr1 234 a b c d
chr1 345 aa b c d
chr1 456 a b c d
....
Run Code Online (Sandbox Code Playgroud)
文件B.
xxxx abcd chr1 123 aa c d e
yyyy defg chr1 345 aa e f g
...
Run Code Online (Sandbox Code Playgroud)
我想基于3列"chr1","123"和"aa"加入这两个文件,并将文件B中的前两列添加到文件A中,这样输出如下所示:输出:
chr1 123 aa b c d xxxx abcd
chr1 234 a b c d
chr1 345 aa b c d yyyy defg
chr1 456 a b c d
Run Code Online (Sandbox Code Playgroud)
谁能帮助你在awk中做到这一点.如果可能使用awk oneliners?
显示的图表由以下R代码生成.
png("test.png")
plot(data[,4],data[,3],type='l',col="green")
par(new=TRUE)
plot(data[,4],data[,2],type='l',col="red")
dev.off()
Run Code Online (Sandbox Code Playgroud)
两个图的Y轴范围不同,如图所示,它被覆盖.有人可以帮助为这两个图设置相同的Y轴范围.
我在Mac终端中使用更少的命令打开时显示了^ M字符的文本文件。我尝试使用以下命令删除^ M字符。
awk '{ gsub("\n", "\r"); print $0;}' input > output
cat input | tr ‘\n’ ‘\r’ > output
Run Code Online (Sandbox Code Playgroud)
但是他们都不起作用。有人可以使用某些Linux命令来帮助解决此问题。
我写这篇文章是为了寻求一些帮助,使用计划(多进程)或计划(多核)并在我闪亮的应用程序中杀死长时间运行的进程.该应用程序具有多个未来事件(长时间运行的进程),这些事件在单击其相应的actionButton时运行.下面是app中服务器函数中使用的future()命令的示例应用程序.我一直在使用stopMulticoreFuture(fut)来杀死进程.
library(shiny)
library(shinydashboard)
library(promises)
plan(multicore)
library(ipc)
sidebar <- dashboardSidebar(width = 200, sidebarMenu(id = "tabs",
menuItem("File", tabName = "tab1", icon = icon("fas fa-file"))))
body <- tabItem(tabName = "tab1",h2("Input File"),
fluidRow(tabPanel(
"Upload file",
value = "upload_file",
fileInput(
inputId = "uploadFile",
label = "Upload Input file",
multiple = FALSE,
accept = c(".txt")
),
checkboxInput('header', label = 'Header', TRUE)
),
box(
title = "Filter X rows",
width = 7,
status = "info",
tabsetPanel(
id = "input_tab",
tabPanel(
"Parameters",
numericInput(
"nrows",
label = "Entire number …
Run Code Online (Sandbox Code Playgroud) 我有一个数据框 DF,下面显示了两列 A 和 B:
A B
1 0
3 0
4 0
2 1
6 0
4 1
7 1
8 1
1 0
Run Code Online (Sandbox Code Playgroud)
执行滑动窗口方法,如下所示。在大小为 3 的滑动窗口中计算列 B 的平均值,使用:rollapply(DF$B, width=3,by=1) 滑动 1。每个窗口的平均值显示在左侧。
A: 1 3 4 2 6 4 7 8 1
B: 0 0 0 1 0 1 1 1 0
[0 0 0] 0
[0 0 1] 0.33
[0 1 0] 0.33
[1 0 1] 0.66
[0 1 1] 0.66
[1 1 1] 1
[1 1 0] …
Run Code Online (Sandbox Code Playgroud) server <- function(input, output, session) {
out1_rows <- reactiveVal()
observeEvent(input$run1, {
prog <- Progress$new(session)
prog$set(message = "Analysis in progress",
detail = "This may take a while...",
value = NULL)
fut1 = future({
system(paste("Command1" , input$file ">", "out1.txt"))
system(paste("Command2" , out1.txt ">", "out2.txt"))
head_rows <- read.delim("out2.txt")
return(head_rows)
}) %...>%
out1_rows() %>%
finally( ~ prog$close())
NULL
})
observeEvent(req(out1_rows()), {
output$out_table <-
DT::renderDataTable(DT::datatable(
out1_rows(),
)
))
observeEvent(input$cancel, {
async_pid <- fut1$job$pid ##this is empty
#async_pid <- Sys.getpid() ##this return PID for main process …
Run Code Online (Sandbox Code Playgroud) 下面的代码使用ggplot
和生成两个图ggplotly
。尽管使用了layout()
ggplotly,图例仍然位于右侧。图例必须位于底部。任何人都可以帮助将图例移动到 ggplotly 的底部吗?我已经尝试了 R +shiny+plotly 的解决方案:ggplotly 将图例移至右侧,但在这里不起作用。如果我错过了显而易见的事情,有人可以帮忙吗?
measure<-c("MSAT","MSAT","GPA","MSAT","MSAT","GPA","GPA","GPA")
score<-c(500, 490, 2.9, 759, 550, 1.2, 3.1, 3.2)
data<-data.frame(measure,score)
ui <- fluidPage(
mainPanel(
plotOutput("myplot" ),
plotlyOutput("myplot2" )
)
)
server <- function(input, output) {
myplot <- reactive({
gpl1 <- ggplot(data,aes(y=reorder(measure, score),x=score,fill=score)) +
geom_bar(stat="identity")+
theme(legend.position="bottom")+
xlab("x")+
ylab("y")+
labs(title = NULL)
gpl1
})
myplot2 <- reactive({
gpl2 <- ggplot(data,aes(y=reorder(measure, score),x=score,fill=score)) +
geom_bar(stat="identity") +
theme(legend.position="bottom")+
xlab("x")+
ylab("y")+
labs(title = NULL)
ggplotly(gpl2) %>%
layout(legend = list(orientation = 'h', …
Run Code Online (Sandbox Code Playgroud) r ×5
awk ×3
asynchronous ×2
compare ×1
dataframe ×1
delimiter ×1
file ×1
ggplot2 ×1
ggplotly ×1
join ×1
kill-process ×1
linux ×1
networkx ×1
python ×1
r-plotly ×1
scatter-plot ×1
set ×1
shiny-server ×1
sorting ×1