jennahamlin / tinselR

An Amazing Shiny App
Other
17 stars 4 forks source link

Development #1

Closed jennahamlin closed 3 years ago

jennahamlin commented 4 years ago
jennahamlin commented 4 years ago

regarding the above comment - one mechanism for dealing with this, is using the accept function in fileInput. link explaining how the accept function when included only allows the specified files to be 'seen' in the file upload in the web browser (but not in the rstudio version)

Need to maybe include a help text here, explaining what the data file/structure should be.

jennahamlin commented 4 years ago

link to basic treeviewer shiny app - poke around and adjust to what looks good

jennahamlin commented 4 years ago

Current state both via my personal workstation and now available on internal network

Completed

Working on

jennahamlin commented 4 years ago

State of package -

Completed

Working on

minor issues

jennahamlin commented 4 years ago
jennahamlin commented 4 years ago
jennahamlin commented 4 years ago

moved brush selection and table display out to another module

jennahamlin commented 4 years ago

able to grab node for cladelabels using a function and can annotate the tree but still un able to place brushedPoints selected tips into the vector..

jennahamlin commented 4 years ago

Completed

Issues

To Do

jennahamlin commented 4 years ago

Completed

Issues

To Do

jennahamlin commented 4 years ago

User input thoughts -

jennahamlin commented 4 years ago

Completed

Issues

To Do

jennahamlin commented 4 years ago

Completed

Issues

To Do

jennahamlin commented 4 years ago

Completed

Issues

To Do

jennahamlin commented 4 years ago

Completed

Issues

To Do

jennahamlin commented 4 years ago

updated website with better documentation for Shiny

jennahamlin commented 4 years ago

Issue

bootstrap displays values 1 - 9, need to convert these values to 01 - 09 to be ignored

treein <- treeio::read.newick("/Users/jennahamlin/Desktop/Tinsel/data/example_1504MLEXH-1/1504MLEXH-1.dnd")

str(treein)

#this put an NA in first value, instead of leaving blank
# bs <- as.numeric(treein$node.label)%>%  
  sprintf("%02s",.) 

bs <- ifelse((nchar(treein$node.label)!=2 &!is.na(as.numeric(treein$node.label))) ,paste0("0",treein$node.label),treein$node.label)

treein2<-purrr::list_modify(treein, node.label = bs)

str(treein2)

treein2$node.label

This does what I want in R but when I put into shiny, I get an error (NA's introduced) and R aborts.

jennahamlin commented 4 years ago

getting snp differences to calculate mean and median based on tips selected

##get mean and median of snp differences  

##read in genetic distance matrix
geneFile <-
  readr::read_delim("/Users/jennahamlin/Desktop/Tinsel/data/example_1504MLEXH-1/1504MLEXH-1_geneticMatrix.tsv",
                    delim = "\t",
                    trim_ws = T, 
                    skip_empty_rows = T,
                    col_names = T)
str(geneFile)

geneFile2 <- dplyr::rename(geneFile, label=1)%>%
  replace(., .=="-", 0)

#convert to long data frame - three columns
geneFile3 <- geneFile2%>%
  na.omit()%>%
  tidyr::pivot_longer(-label)

#this will pull out the value for column1, and column2
geneFile3 %>% 
  dplyr::filter(label == geneFile3$label[1] & name == geneFile3$name[2]) %>% 
  dplyr::pull(value)

#this will pull snp differences using labels
geneFile3 %>% 
  dplyr::filter(label == "2015C-3893_fastx5" & name == "PNUSAE000514_fastx5") %>% 
  dplyr::pull(value)

#this will pull out snp differences based on coordinates in character vector of tips
tips<-c("2015C-3893_fastx5", "PNUSAE000514_fastx5")

geneFile3 %>% 
  dplyr::filter(label == tips[1] & name == tips[2]) %>% 
  dplyr::pull(value)

#using three variables in character vector called tips
tips<-c("2015C-3893_fastx5", "PNUSAE000514_fastx5", "PNUSAE000634_fastx5")

#I can loop through and compare each variable in tips to the list isolate
for (i in 1:length(tips)) {
  geneFile3%>%
    dplyr::filter(label == tips[i] & name == "PNUSAE000514_fastx5") %>% 
    print(dplyr::pull(value))
}

for (i in 1:length(tips)) {
 for (j in 2:length(tips)){
+   tipVector<-geneFile3%>%
+     dplyr::filter(label == tips[i] & name == tips[j]) %>% 
+     print(dplyr::pull(value))
+   print(tipVector)
+   }}
# A tibble: 1 x 3
  label             name                value
  <chr>             <chr>               <chr>
1 2015C-3893_fastx5 PNUSAE000634_fastx5 1    
# A tibble: 1 x 3
  label             name                value
  <chr>             <chr>               <chr>
1 2015C-3893_fastx5 PNUSAE000634_fastx5 1    
# A tibble: 1 x 3
  label               name                value
  <chr>               <chr>               <chr>
1 PNUSAE000514_fastx5 PNUSAE000634_fastx5 2    
# A tibble: 1 x 3
  label               name                value
  <chr>               <chr>               <chr>
1 PNUSAE000514_fastx5 PNUSAE000634_fastx5 2    
# A tibble: 1 x 3
  label               name                value
  <chr>               <chr>               <chr>
1 PNUSAE000634_fastx5 PNUSAE000634_fastx5 0    
# A tibble: 1 x 3
  label               name                value
  <chr>               <chr>               <chr>
1 PNUSAE000634_fastx5 PNUSAE000634_fastx5 0    

**output is repeated twice and are seperate lists**
for (i in 1:length(tips)) {
  for (j in 2:length(tips)){
  tipVector<- geneFile3%>%
    dplyr::filter(label == tips[i] & name == tips[j]) %>% 
    dplyr::pull(value)
  print(tipVector)
}
}
[1] "1"
[1] "1"
[1] "0"
[1] "2"
[1] "2"
[1] "0"
jennahamlin commented 4 years ago

Completed

Issues

To Do

jennahamlin commented 4 years ago

getting snp differences to calculate mean and median based on tips selected - continued

##get mean and median of snp differences  

##read in genetic distance matrix
geneFile <-
  readr::read_delim("/Users/jennahamlin/Desktop/Tinsel/data/example_1504MLEXH-1/1504MLEXH-1_geneticMatrix.tsv",
                    delim = "\t",
                    trim_ws = T, 
                    skip_empty_rows = T,
                    col_names = T)
str(geneFile)

geneFile2 <- dplyr::rename(geneFile, label=1)%>%
  replace(., .=="-", 0)

#convert to long data frame - three columns
geneFile3 <- geneFile2%>%
  na.omit()%>%
  tidyr::pivot_longer(-label)

#using three variables in character vector called tips
 tips<-c("2015C-3893_fastx5", "PNUSAE000514_fastx5", "PNUSAE000634_fastx5")

tipVector <- c()

for (i in 1:length(tips)){
  for (j in 1:length(tips)){
    tipVector[i]<- geneFile3%>%
      dplyr::filter(label == tips[i] & name == tips[j]) %>%
      dplyr::pull(value)
    return(tipVector)
     }
}

**output**
mean(as.numeric(tipVector))
[1] 1
> tipVector
[1] "1" "2" "0" 

I believe this is what I want. Now need to incorporate it shiny.

jennahamlin commented 4 years ago

getting snp differences to calculate mean and median based on tips selected - continued - this will plot the mean snp differences for one monophyletic clade

library(shiny)
library(treeio)
library(ggtree)
library(phytools)
library(ape)

##read in genetic distance matrix
geneFile <-
  readr::read_delim("/Users/jennahamlin/Desktop/Tinsel/data/example_1504MLEXH-1/1504MLEXH-1_geneticMatrix.tsv",
                    delim = "\t",
                    trim_ws = T, 
                    skip_empty_rows = T,
                    col_names = T)
str(geneFile)

geneFile2 <- dplyr::rename(geneFile, label=1)%>%
  replace(., .=="-", 0)

#convert to long data frame - three columns
geneFile3 <- geneFile2%>%
  na.omit()%>%
  tidyr::pivot_longer(-label)

##read in tree file 
treeFile <-treeio::read.newick("/Users/jennahamlin/Desktop/Tinsel/data/example_1504MLEXH-1/1504MLEXH-1.dnd")

tree_plot <-
  ggtree::ggtree(treeFile) +
  ggtree::geom_tiplab() +
  ggplot2::xlim(NA, 0.02)

tree_plot

##using a single monophyletic clade
tips<-c("2015C-3893_fastx5", "PNUSAE000514_fastx5")
tip_vector<-list(c("2015C-3893_fastx5", "PNUSAE000514_fastx5"))

str(tip_vector)

snpVector <- c()

 for (i in 1:length(tips)){
   for (j in 1:length(tips)){
     snpVector[i]<- geneFile3%>%
       dplyr::filter(label == tips[i] & name == tips[j]) %>%
       dplyr::pull(value)
   }
 }

mean(as.numeric(snpVector))

make_layer <- function(tree, tips, label, color) {
  ggtree::geom_cladelabel(
    node = phytools::findMRCA(ape::as.phylo(tree), tips),
    label = label,
    color = color
  )
}

#adjust lapply here to 1:2 when testing for two annotations with snp means
tree_plot + lapply(1, function(i)
     make_layer(
         tree_plot,
         tips = tip_vector[[i]],
         label = paste("Clade", i, mean(as.numeric(snpVector))),
         color = "red"
       ))
jennahamlin commented 4 years ago

getting snp differences to calculate mean based on tips selected - continued

this will plot the mean snp differences for >1 monophyletic clade

next up to combine with the plotting of annotations.


##read in genetic distance matrix
geneFile <-
  readr::read_delim("/Users/jennahamlin/Desktop/Tinsel/data/example_1504MLEXH-1/1504MLEXH-1_geneticMatrix.tsv",
                    delim = "\t",
                    trim_ws = T, 
                    skip_empty_rows = T,
                    col_names = T)
str(geneFile)

geneFile2 <- dplyr::rename(geneFile, label=1)%>%
  replace(., .=="-", 0)

#convert to long data frame - three columns
geneFile3 <- geneFile2%>%
  na.omit()%>%
  tidyr::pivot_longer(-label)
############### now to get it to work for more than one label 
tip_vector<-list(c("2015C-3893_fastx5", "PNUSAE000514_fastx5"),c("2015C-3777_fastx5", "2015C-3506_fastx5"))

snpVector <- c()

snp_anno <- function(geneFile, tips){ 
  for (i in 1:length(tips)){
    for (j in 1:length(tips)){
      snpVector[i]<- geneFile%>%
        dplyr::filter(label == tips[i] & name == tips[j]) %>%
        dplyr::pull(value)
    }
  }
  return(as.numeric(snpVector))
}

snpMean <-lapply(1:2, function(i)
  snp_anno(geneFile = geneFile3,
           tips= tip_vector[[i]]))

str(snpMean)

lapply(snpMean, mean)

## not incorporated yet
make_layer <- function(tree, tips, label, color) {
  ggtree::geom_cladelabel(
    node = phytools::findMRCA(ape::as.phylo(tree), tips),
    label = label,
    color = color
  )
}

#adjust lapply here to 1:2 when testing for two annotations with snp means
tree_plot + lapply(1:2, function(i)
  make_layer(
    tree_plot,
    tips = tip_vector[[i]],
    label = paste("Clade", i),
    color = "red"
  ))
jennahamlin commented 4 years ago

getting snp differences to calculate mean based on tips selected - continued

issue need to have a filter to exclude self vs self rows in the genetic distance long dataframe

library(shiny)
library(treeio)
library(ggtree)
library(phytools)
library(ape)

##read in genetic distance matrix
geneFile <-
  readr::read_delim("/Users/jennahamlin/Desktop/Tinsel/data/example_1504MLEXH-1/1504MLEXH-1_geneticMatrix.tsv",
                    delim = "\t",
                    trim_ws = T, 
                    skip_empty_rows = T,
                    col_names = T)
str(geneFile)

geneFile2 <- dplyr::rename(geneFile, label=1)%>%
  replace(., .=="-", 0)

#convert to long data frame - three columns
geneFile3 <- geneFile2%>%
  na.omit()%>%
  tidyr::pivot_longer(-label)

##read in tree file 
treeFile <-treeio::read.newick("/Users/jennahamlin/Desktop/Tinsel/data/example_1504MLEXH-1/1504MLEXH-1.dnd")

tree_plot <-
  ggtree::ggtree(treeFile) +
  ggtree::geom_tiplab() +
  ggplot2::xlim(NA, 0.02)

tree_plot

##using a single monophyletic clade
tips<-c("2015C-3893_fastx5", "PNUSAE000514_fastx5")
tip_vector<-list(c("2015C-3893_fastx5", "PNUSAE000514_fastx5"))

str(tip_vector)

snpVector <- c()

 for (i in 1:length(tips)){
   for (j in 1:length(tips)){
     snpVector[i]<- geneFile3%>%
       dplyr::filter(label == tips[i] & name == tips[j]) %>%
       dplyr::pull(value)
   }
 }

mean(as.numeric(snpVector))

make_layer <- function(tree, tips, label, color) {
  ggtree::geom_cladelabel(
    node = phytools::findMRCA(ape::as.phylo(tree), tips),
    label = label,
    color = color
  )
}

#adjust lapply here to 1:2 when testing for two annotations with snp means
tree_plot + lapply(1, function(i)
     make_layer(
         tree_plot,
         tips = tip_vector[[i]],
         label = paste("Clade", i, mean(as.numeric(snpVector))),
         color = "red"
       ))

############### now to get it to work for more than one label 
tip_vector<-list(c("2015C-3893_fastx5", "PNUSAE000514_fastx5"),c("2015C-3777_fastx5", "2015C-3506_fastx5"))

snpVector <- c()

snp_anno <- function(geneFile, tips){ 
  for (i in 1:length(tips)){
    for (j in 1:length(tips)){
      snpVector[i]<- geneFile%>%
        dplyr::filter(label == tips[i] & name == tips[j]) %>%
        dplyr::pull(value)
    }
  }
  return(as.numeric(snpVector))
}

snpMean <-lapply(1:2, function(i)
  snp_anno(geneFile = geneFile3,
           tips= tip_vector[[i]]))

str(snpMean)

lapply(snpMean, mean)

make_layer <- function(tree, tips, label, color) {
  ggtree::geom_cladelabel(
    node = phytools::findMRCA(ape::as.phylo(tree), tips),
    label = label,
    color = color
  )
}

#adjust lapply here to 1:2 when testing for two annotations with snp means
tree_plot + lapply(1:2, function(i)
  make_layer(
    tree_plot,
    tips = tip_vector[[i]],
    label = paste("Clade", i, lapply(snpMean[i], mean)),
    color = "red"
  ))
jennahamlin commented 4 years ago

Completed

Issues

To Do

jennahamlin commented 4 years ago

remove rows with duplicated names in two columns (self compared to self)

geneFile2 <- dplyr::rename(geneFile, label=1)%>%
  replace(., .=="-", 0)

#convert to long data frame - three columns
geneFile3 <- geneFile2%>%
  na.omit()%>%
  tidyr::pivot_longer(-label)%>%
  dplyr::distinct(label, value, .keep_all=T)   #Reduced the matrix to half of observations but still keeps rows in which the two ids are the same

geneFile4 <-geneFile3[which(geneFile3$label != geneFile3$name),]
#https://stackoverflow.com/questions/45720038/remove-rows-with-same-name-in-different-columns
jennahamlin commented 4 years ago

added exclude self vs self comparisons in snp_anno function

##read in genetic distance matrix
geneFile <-
  readr::read_delim("/Users/jennahamlin/Desktop/Tinsel/data/example_1504MLEXH-1/1504MLEXH-1_geneticMatrix.tsv",
                    delim = "\t",
                    trim_ws = T, 
                    skip_empty_rows = T,
                    col_names = T)
#str(geneFile)

geneFile2 <- dplyr::rename(geneFile, label=1)%>%
  replace(., .=="-", 0)

#convert to long data frame - three columns
geneFile3 <- geneFile2%>%
  na.omit()%>%
  tidyr::pivot_longer(-label) 

geneFile4 <-geneFile3[which(geneFile3$label != geneFile3$name),]

# #https://stackoverflow.com/questions/45720038/remove-rows-with-same-name-in-different-columns

##read in tree file 
treeFile <-treeio::read.newick("/Users/jennahamlin/Desktop/Tinsel/data/example_1504MLEXH-1/1504MLEXH-1.dnd")

tree_plot <-
  ggtree::ggtree(treeFile) +
  ggtree::geom_tiplab() +
  ggplot2::xlim(NA, 0.02)

tree_plot

############### now to get it to work for more than one label 
tip_vector<-list(c("2015C-3893_fastx5", "PNUSAE000514_fastx5"),c("2015C-3777_fastx5", "2015C-3506_fastx5"))

snpVector <- c()

snp_anno <- function(geneFile, tips){ 
  for (i in 1:length(tips)){
    for (j in 1:length(tips)){
      if(tips[i] == tips[j]) next #https://stackoverflow.com/questions/36329183/exclude-one-fixed-variable-in-for-loop
      snpVector[i]<- geneFile%>%
        dplyr::filter(label == tips[i] & name == tips[j]) %>%
        dplyr::pull(value)
          }
  }
  return(as.numeric(snpVector))
}

snpMean <-lapply(1:2, function(i)
  snp_anno(geneFile = geneFile4,
           tips= tip_vector[[i]]))

str(snpMean)

lapply(snpMean, mean)

make_layer <- function(tree, tips, label, color) {
  ggtree::geom_cladelabel(
    node = phytools::findMRCA(ape::as.phylo(tree), tips),
    label = label,
    color = color
  )
}

#adjust lapply here to 1:2 when testing for two annotations with snp means
tree_plot + lapply(1:2, function(i)
  make_layer(
    tree_plot,
    tips = tip_vector[[i]],
    label = paste("Clade", "\n# SNPs -", lapply(snpMean[i], mean)),
    color = "red"
  ))
jennahamlin commented 4 years ago

Completed

Issues

To Do

jennahamlin commented 4 years ago

adding snp calculation to annotation

This works but can not get it to work in r shiny module

library(shiny)
library(treeio)
library(ggtree)
library(phytools)
library(ape)

##read in tree file 
treeFile <-treeio::read.newick("/Users/jennahamlin/Desktop/Tinsel/data/example_1504MLEXH-1/1504MLEXH-1.dnd")
tree_plot <-phytools::midpoint.root(treeFile)

##read in genetic distance matrix
dataFile <-readr::read_delim("/Users/jennahamlin/Desktop/Tinsel/data/example_1504MLEXH-1/1504MLEXH-1_geneticMatrix.tsv",delim = "\t",trim_ws = T, skip_empty_rows = T,col_names = T)

# Define UI for application that draws a histogram
ui <- fluidPage(

  # Application title
  titlePanel("Test"),

  actionButton("add_annotation","Add clade annotation"),

  # Show a plot of the generated distribution
  mainPanel(
    plotOutput("treeDisplay", brush ="plot_brush"),
            plotOutput("treeDisplay2"),
            textOutput("contents")

  )
)

# Define server logic required to draw a histogram
server <- function(input, output) {

geneObject <- dplyr::rename(dataFile, label = 1)%>%  
      replace(., .=="-", 0) 

  geneFile <- 
    geneObject%>%
      na.omit()%>%
      tidyr::pivot_longer(-label)

  #remove self comparisons for this table - necessary for snp mean/median calculation. 
  geneFileSNP <-
    geneFile[which(geneFile$label != geneFile$name),]

  #reactive that holds base tree - this is how I am building the base tree
  make_tree <- reactive({
    ggtree::ggtree(tree_plot) +
      ggtree::geom_tiplab() +
      ggplot2::xlim(NA, 0.1)
  })

  #render base tree
  output$treeDisplay <- renderPlot({
    make_tree()
  })

  # Initialize a reactive value and set to zero
  n_annotations <- reactiveVal(0)
  annotations <- reactiveValues()

  #reactive that holds the brushed points on a plot
  dataWithSelection <- reactive({
    brushedPoints(make_tree()$data, input$plot_brush)
  })

  tipVector <- c()

  #add to label to vector if isTip == True
  dataWithSelection2 <- eventReactive(input$plot_brush, {
    for (i in 1:length(dataWithSelection()$label)) {
      if (dataWithSelection()$isTip[i] == TRUE)
        tipVector <- c(tipVector, dataWithSelection()$label[i])
    }
    return(tipVector)
  })

  snpVector <- c()

  snp_anno <- function(geneFile, tips){
    for (i in 1:length(tips)){
      for (j in 1:length(tips)){
        if(tips[i] == tips[j]) next #https://stackoverflow.com/questions/36329183/exclude-one-fixed-variable-in-for-loop
        snpVector[i]<- geneFile%>%
          dplyr::filter(label == tips[i] & name == tips[j]) %>%
          dplyr::pull(value)
      }
    }
    return(as.numeric(snpVector))
  }

  make_layer <- function(tree, tips, label, color) {
    ggtree::geom_cladelabel(
      node = phytools::findMRCA(ape::as.phylo(tree), tips),
      label = label,
      color = color,
      offset = 0.02
    )
  }

  snpMean <- eventReactive(input$add_annotation, {
    str(annotations[[paste0("ann", n_annotations())]] <- dataWithSelection2())

    lapply(1:n_annotations(), function(i)
      snp_anno(geneFile = geneFileSNP,
               tips = annotations[[paste0("ann", i)]]
      ))
  })

  #display that layer onto the tree
  anno_plot <- eventReactive(input$add_annotation, {
    # update the reactive value
    new <- n_annotations() + 1
    n_annotations(new)
    annotations[[paste0("ann", n_annotations())]] <- dataWithSelection2()

    plt <-
      make_tree() +
      lapply(1:n_annotations(), function(i)
        make_layer(
          make_tree(),
          tips = annotations[[paste0("ann", i)]],
          label = paste("Clade", "\nSNP -", lapply(snpMean()[i], mean)),
          color = "red"
        ))

    return(plt)
  })

  output$treeDisplay2 <- renderPlot({
    anno_plot()
  })

}

# Run the application 
shinyApp(ui = ui, server = server)
jennahamlin commented 4 years ago

Completed

Issues

To Do

jennahamlin commented 4 years ago

switch ugly/excess tip labels with pretty/labels in R

#load meta data which has key value pairs
metaFile <- readr::read_delim("/Users/jennahamlin/Desktop/Tinsel/data/example_1504MLEXH-1/1504MLEXH-1_metaData.csv", delim = ",",trim_ws = T, skip_empty_rows = T,col_names = T  )

dataFile <-readr::read_delim("/Users/jennahamlin/Desktop/Tinsel/data/example_1504MLEXH-1/1504MLEXH-1_geneticMatrix.tsv",delim = "\t",trim_ws = T, skip_empty_rows = T,col_names = T)

#https://stackoverflow.com/questions/11518958/replacing-columns-names-using-a-data-frame-in-r
#https://stackoverflow.com/questions/50007250/changing-column-names-except-for-the-first-two-columns
colnames(dataFile)[2:ncol(dataFile)] = metaFile$Display.labels[which(metaFile$Tip.labels %in% colnames(dataFile)[2:ncol(dataFile)])]
dataFile$. = metaFile$Display.labels[which(metaFile$Tip.labels %in% dataFile$.)]
jennahamlin commented 4 years ago

switch ugly/excess tip labels with pretty/labels in shiny

##read in genetic distance matrix
dataFile <-reactive({readr::read_delim("/Users/jennahamlin/Desktop/Tinsel/data/example_1504MLEXH-1/1504MLEXH-1_geneticMatrix.tsv",delim = "\t",trim_ws = T, skip_empty_rows = T,col_names = T)})

metaFile <- reactive({readr::read_delim("/Users/jennahamlin/Desktop/Tinsel/data/example_1504MLEXH-1/1504MLEXH-1_metaData.csv", delim = ",",trim_ws = T, skip_empty_rows = T,col_names = T  )})

#numCols <-reactive(2:ncol(dataFie()))
dataFileCols <- reactive({
  dataFile2 <- dataFile()
  colnames(dataFile2)[2:ncol(dataFile2)]<-metaFile()$Display.labels[which(metaFile()$Tip.labels %in% colnames(dataFile2)[2:ncol(dataFile2)])]
  return(dataFile2)
})

dataFileRows <- reactive({
  dataFile3 <- dataFileCols()
  dataFile3$. = metaFile()$Display.labels[which(metaFile()$Tip.labels %in% dataFile3$.)]
  return(dataFile3)
})
jennahamlin commented 4 years ago

Completed

Issues

To Do

jennahamlin commented 4 years ago

change tip labels in phylogenetic tree in R

#load tree and convert tibble - can access tip names by $label
treeFile <-treeio::read.newick("/Users/jennahamlin/Desktop/Tinsel/data/example_1504MLEXH-1/1504MLEXH-1.dnd")

treeFile2 <- phylotools::sub.taxa.label(treeFile, as.data.frame(metaFile))
jennahamlin commented 4 years ago

read in tree file and if meta data file present incorporate as well - Shiny

library(shiny)

ui <- fluidPage(
  fileInput("treefile", label= "tree"),
  fileInput("metafile", "Choose CSV File",
            multiple = FALSE,
            accept = c("text/csv",
                       "text/comma-separated-values,text/plain",
                       ".csv")),
  actionButton("add_tree","Visualize Tree"),
  plotOutput("treeDisplay"),
  tableOutput("contents")
)

server <- function(input, output) {

  get_file_or_default <- reactive({ #this does tip label fix but doesn't work if a meta file is not uploaded
    if (is.null(input$metafile$datapath)) {
      treeio::read.newick(input$treefile$datapath)
    } else {

      dataFile <- readr::read_delim(input$metafile$datapath,
                        delim = ",",
                        trim_ws = T,
                        skip_empty_rows = T,
                        col_names = T)

    treeio::read.newick(input$treefile$datapath)%>%
      phylotools::sub.taxa.label(., as.data.frame(dataFile))
    }
  })

  #reactive that holds base tree - this is how I am building the base tree
  make_tree <- reactive({
    ggtree::ggtree(get_file_or_default()) +
      ggtree::geom_tiplab() +
      ggplot2::xlim(NA, 0.1)
  })

  #displays the tree plot, uses output from the displayTree module
  observeEvent(input$add_tree, {output$treeDisplay <- renderPlot({
    make_tree()})
  })

}

shinyApp(ui, server)
jennahamlin commented 4 years ago

Completed

Issues

To Do

jennahamlin commented 4 years ago

read in genetic distance data and if meta data present change tip labels in genetic distance

library(shiny)

ui <- fluidPage(

  fileInput("geneFile", "Choose gene File",
            multiple = FALSE,
            accept = c("text/csv",
                       "text/comma-separated-values,text/plain",
                       ".csv")),

  fileInput("metaFile", "Choose meta File",
            multiple = FALSE,
            accept = c("text/csv",
                       "text/comma-separated-values,text/plain",
                       ".csv")),

    tableOutput("contents")
)

server <- function(input, output) {

  get_file_or_default <- reactive({ 
    if (is.null(input$metaFile$datapath)) {

      geneFile2 <- readr::read_delim(input$geneFile$datapath,
                                    delim = "\t",
                                    trim_ws = T,
                                    skip_empty_rows = T,
                                    col_names = T)
       } 
      else {

        geneFile2 <- readr::read_delim(input$geneFile$datapath,
                                       delim = "\t",
                                       trim_ws = T,
                                       skip_empty_rows = T,
                                       col_names = T)

         metaFile2 <- readr::read_delim(input$metaFile$datapath,
                                       delim = ",",
                                       trim_ws = T,
                                       skip_empty_rows = T,
                                       col_names = T)

        colnames(geneFile2)[2:ncol(geneFile2)] = metaFile2$Display.labels[which(metaFile2$Tip.labels %in% colnames(geneFile2)[2:ncol(geneFile2)])]

        geneFile2$. = metaFile2$Display.labels[which(metaFile2$Tip.labels %in% geneFile2$.)]

        return(geneFile2)
        return(metaFile2)
      }
    })

   output$contents <- renderTable({
     get_file_or_default()
   })

}

shinyApp(ui, server)
jennahamlin commented 4 years ago

Completed

Issues

To Do

jennahamlin commented 4 years ago

Completed

Issues

To Do

jennahamlin commented 4 years ago

Completed

Issues

To Do

jennahamlin commented 4 years ago

Completed

Issues

To Do

jennahamlin commented 4 years ago

Completed

Issues

To Do

jennahamlin commented 4 years ago

function to check if an annotation is present

offset <- function(make_treeOut){
    if (make_treeOut()$data$x == TRUE){
      max(make_treeOut()$data$x) + 0.02
    }
    else{
      max(make_treeOut()$data$x)
    }
  }

in theory, I want something to test if there is annotation on tree and if a new annotation overlaps, then move it over by X amount (here - 0.02)

jennahamlin commented 4 years ago

Completed

Issues

To Do

jennahamlin commented 4 years ago

Completed

Issues

To Do

jennahamlin commented 4 years ago

Completed

Issues

To Do

jennahamlin commented 4 years ago

Completed

Issues

To Do

jennahamlin commented 4 years ago

Completed

Issues

To Do

jennahamlin commented 4 years ago

Completed

Issues

To Do

User Comments

jennahamlin commented 4 years ago

Completed

Issues

To Do

User Comments

jennahamlin commented 4 years ago

Completed

Issues

To Do

User Comments