【问题标题】:Using rentrez and shiny to download protein sequences使用rentrez和shiny下载蛋白质序列
【发布时间】:2018-09-25 01:42:13
【问题描述】:

我是 R 和 Shiny 的新手。到目前为止,我能够使用rentrez 包制作一个从ncbi 获取蛋白质序列的脚本。但是我无法让它在闪亮的应用程序中工作。

我在 ui 中有以下输入

 sidebarPanel(
                    uiOutput("maps.protein.input")
                  ),

在应用文件中:

output$maps.protein.input <- renderUI({
selectInput("prot.accession", "Accession:", as.list(pep.accession))

这部分运行良好,它将 pep.accession 列表读入selectInput

现在我想用rentrez下载蛋白质序列

protein_seq <- reactive({

                    raw_seq <- entrez_fetch(db="protein", id= paste(input$prot.accession), rettype = "fasta")
                    raw_seq <- str_sub(raw_seq, start = str_locate(pattern = "\n", protein_seq)[,1] +1 )
                    str_replace_all(raw_seq, "[\r\n]" , "")

 }) 

在我使用的 R 脚本中:

protein_seq <- entrez_fetch(db="protein", id="XP_011524437.1", rettype = "fasta")
protein_seq <- str_sub(protein_seq, start = str_locate(pattern = "\n", protein_seq)[,1] +1 )
protein_seq <- str_replace_all(protein_seq, "[\r\n]" , "")

并且此代码有效。我只是想让它具有交互性。

【问题讨论】:

  • 您需要提供一些可重现的数据,以便我们提供帮助。例如,在您的代码中,pep.accession 是什么?
  • 您遇到的具体问题是什么?它不工作吗?你有错误吗?

标签: r shiny


【解决方案1】:

这里有一个解决方案。我在selectInput 中使用了XP_011524437.1,因为我不知道pep.accession 是什么。您可以在您的应用程序中更改它。我还更正了str_sub 中的逻辑并添加了req() 语句。

library(shiny)
library(rentrez)

ui <- fluidPage(
  sidebarPanel(
    uiOutput("maps.protein.input")
  ),
  mainPanel(
    textOutput("result1")
  )
)

server <- function(input, output, session) {
  output$maps.protein.input <- renderUI({
    selectInput("prot.accession", "Accession:", "XP_011524437.1")
  })

  protein_seq <- reactive({
    req(input$prot.accession)
    raw_seq <- entrez_fetch(db = "protein", id = input$prot.accession, rettype = "fasta")
    raw_seq <- stringr::str_sub(raw_seq, start = str_locate(pattern = "\n", raw_seq)[,1] +1 )
    stringr::str_replace_all(raw_seq, "[\r\n]" , "")
    return(raw_seq)
  })

  output$result1 <- renderText({
    paste0("Protein sequence: ", as.character(protein_seq()))
  })
}

shinyApp(ui, server)

【讨论】:

  • 谢谢!这帮助很大!
猜你喜欢
  • 2017-10-26
  • 2013-09-18
  • 2012-06-27
  • 2013-01-16
  • 1970-01-01
  • 2013-01-22
  • 1970-01-01
  • 2017-01-28
  • 1970-01-01
相关资源
最近更新 更多