Skip to content

Commit

Permalink
feat: Added line plots for raw abundances of each guide per gene
Browse files Browse the repository at this point in the history
- Implemented functionality to plot the raw abundance of each sgRNA guide for a selected gene.
- Added the  function to dynamically generate line plots for sgRNA sequences based on user input or default gene selection.
- Plots show the distribution of sgRNA abundances across conditions for the selected gene.
- Improved the server logic to render plots for each selected gene without requiring prior input, with fallback to default gene.
  • Loading branch information
goknurginer committed Oct 15, 2024
1 parent cffd6c8 commit b5a3cad
Showing 1 changed file with 52 additions and 3 deletions.
55 changes: 52 additions & 3 deletions R/app.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ ui <- navbarPage(
actionButton("viewsamples", "View sample information"),
hr(),
radioButtons(
"count_matrix_yes_no",
"count_matrix_yes_no",
label = "Do you have a count matrix?",
choices = list("Yes" = "yes", "No" = "no"), selected = ""
),
Expand Down Expand Up @@ -182,8 +182,8 @@ ui <- navbarPage(
conditionalPanel(
condition = "input.quality_check == 'View guide distribution per gene'", # nolint
h3("The distribution of guides per gene"),
# plotOutput("guide_distribution_per_gene"),
# uiOutput("download_guide_per_gene_button")
plotOutput("guide_distribution_per_gene"),
# uiOutput("download_guide_per_gene_button"),
textOutput("gene_selected")
)
)
Expand Down Expand Up @@ -388,8 +388,57 @@ server <- function(input, output, session) {
req(guide_pdf())
downloadButton("download_guide_pdf")
})
## Display view guide distribution per gene line plots
gene.linePlot <- function(gene = NULL) {
req(edgeR_object())
req(input$selected_gene)
gene <- input$selected_gene
# If no gene is provided, use the first gene in the dataset
if (is.null(gene)) {
gene <- edgeR_object()$genes$Gene_ID[1] # Select the first gene by default
}

# Filter the genes to find the selected gene
gene_rows <- edgeR_object()$genes$Gene_ID == gene
if (any(gene_rows)) {
# Subset the counts for the specified gene
pg <- edgeR_object()$counts[gene_rows, ]

# Reshape the data for plotting
df <- reshape2::melt(pg)

# Rename columns for clarity
colnames(df) <- c("SgRNA_Sequence", "Condition", "Abundance")

# Create line plot using ggplot
p <- ggplot(data = df, aes(x = Condition, y = Abundance, group = SgRNA_Sequence)) +
geom_line(aes(color = SgRNA_Sequence)) +
theme_classic() +
ggtitle(paste0("Gene ", gene, " SgRNA Distribution"))

# Return the plot object
return(p)
} else {
return(NULL)
}
}


output$guide_distribution_per_gene <- renderPlot({
# No need to require input$selected_gene
p <- gene.linePlot() # Default behavior if no gene is provided
if (!is.null(p)) {
print(p)
} else {
plot.new()
text(0.5, 0.5, "No data available for the selected gene.", cex = 1.5)
}
})
}





# Run the app
shinyApp(ui = ui, server = server)

0 comments on commit b5a3cad

Please sign in to comment.