Java教程

一个实验设计项目

本文主要是介绍一个实验设计项目,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

随机生成小鼠肿瘤生长数据

想要模拟真实世界的情况本身就非常困难。受限于本人数学水平,勉强生成一批均值和方差不断增大的数据,来模拟小鼠肿瘤生长的情况。在这过程中,参考了一些肿瘤方面的文章。

TEM8 marks neovasculogenic tumor-initiating cells in triple-negative breast cancer1
B
Naturally-occurring spinosyn A and its derivatives function as argininosuccinate synthase activator and tumor inhibitor2
A

模拟数据

先写一个能生成x只小鼠y天的肿瘤大小数据集的函数

# generate data set
generate_tumordata <- function(n=10,min=10 ,max=1800,days=90,group = "Control",id="MouseC"){
  mean_seq <- rexp(n=days,rate=1/(max-min))
  mean_seq <- mean_seq[mean_seq>min & mean_seq<max]
  mean_seq <-sort(c(abs(rnorm(n=days-length(mean_seq),mean = (max-min)/2, sd=3)),mean_seq))
  sd_seq <- round(seq(3,days,length.out = days),4)
  data <- map2(mean_seq,sd_seq,rnorm,n=n)
  day_name <- paste0("day",1:days)
  data2 <- data.frame(
    Mouse = paste0(id,1:n),
    Group=rep(group,n),
    t(matrix(unlist(data),nrow = days ,byrow = T))) 
  colnames(data2) <- c("Mouse","Group",day_name)
  return(data2)
}

然后在shiny中展示它

library(shiny)
library(reshape2)
library(tidyverse)
library(lubridate)
source("function.R")
ui <- fluidPage(
  sidebarLayout(
    sidebarPanel("Generate a dataset",
      sliderInput("days","The days of the experiment",min = 3,max = 100,value = 20),
      numericInput("group","Set the groups",min = 1,max = 8,value = 4),
      dateRangeInput("date","input date range",start = as.Date("2020-03-05"))
    ),
    mainPanel(
      navbarPage(title = "Page",
                 tabPanel("Data",
                          h3("Data"),
                          dataTableOutput("dataset"),
                          h3("Data summary"),
                          dataTableOutput("sumdata")
                          
                 ),
                 tabPanel("Plot",
                          plotOutput("plotline",width = "1200px",height = "800px"))
      )
    )
  )
)

server <- function(input, output, session) {
  observe({
    updateDateRangeInput(inputId = "date",end = input$date[1] +input$days)
  })
  data <- reactive({
    days=input$days
    ngroup = input$group
    if(ngroup > 1){
      maplist <- tibble(
        max=c(seq(500,1500,length.out = ngroup-1),2000),
        group=c(paste0("Treat-",LETTERS[1:ngroup-1]),"Control"),
        id=c(paste0("MouseT",LETTERS[1:ngroup-1]),"MouseC")
      )
      t <- pmap(maplist,generate_tumordata,n=10,days=days)
      data <- data.frame()
      for (i in 1:length(t)) {
        d <- as.data.frame(t[[i]])
        data <- rbind(data,d)
      }
    } else {
      data <- generate_tumordata(n=10,days = days)
    }
    colnames(data)[c(-1,-2)] <- as.character(ymd(input$date[1])+c(1:days)) 
    return(data)
  })
  data_sum <- reactive({
    data_melt<- melt(data(),id.vars = c("Mouse","Group"),variable.name = "days",value.name = "tumor_volumn")
    Rmisc::summarySE(data_melt,measurevar = "tumor_volumn",groupvars = c("days","Group"))
  })
  plotline <- reactive({
    req(input$group)
    p <- ggplot(data_sum(),aes(x=.data[["days"]],y=.data[["tumor_volumn"]],color=.data[["Group"]],group=.data[["Group"]]))+
      geom_line(size=1)+
      geom_point(aes(fill=.data[["Group"]]),size=3,shape=21,color="black")+
geom_errorbar(aes(ymax=.data[["tumor_volumn"]]+.data[["sd"]],ymin=.data[["tumor_volumn"]]-.data[["sd"]]),
                  width=0.1,
                  size=0.5)+
      theme_classic()+
      labs(x="date",y="Tumor volumn")+
      theme(axis.text.x = element_text(size = 12,color = "black",angle = 90),
            axis.text.y = element_text(size = 14,color = "black"),
            axis.title.x = element_text(size = 16,color = "black"),
            axis.title.y = element_text(size = 16,color = "black"),
            axis.ticks = element_line(color = "black",size=1),
           )
    return(p)
  })
  output$dataset <- renderDataTable(
    data(),
    options = list(pageLength=15)
  )
  output$sumdata <- renderDataTable(
    data_sum(),
    options = list(pageLength=15)
  )
  output$plotline <- renderPlot(plotline())
}

shinyApp(ui, server)

访问链接在这link
在这里插入图片描述
之后再加入文件上传、下载、筛选等功能。


  1. Xu, J., Yang, X., Deng, Q. et al. TEM8 marks neovasculogenic tumor-initiating cells in triple-negative breast cancer. Nat Commun 12, 4413 (2021). https://doi.org/10.1038/s41467-021-24703-7 ↩︎

  2. Zou, Z., Hu, X., Luo, T. et al. Naturally-occurring spinosyn A and its derivatives function as argininosuccinate synthase activator and tumor inhibitor. Nat Commun 12, 2263 (2021). https://doi.org/10.1038/s41467-021-22235-8 ↩︎

这篇关于一个实验设计项目的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!