{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE)

Quick Report

Generating a quick report for loxcodeR analysis

library(loxcoder)
library(shiny)
library(DT)
saveRDS(NN156_small, file="Loxcode_experiments/NN156_small.rds")
saveRDS(NN156, file="Loxcode_experiments/NN156.rds")
saveRDS(NN167, file="Loxcode_experiments/NN167.rds")
saveRDS(NN167_small, file="Loxcode_experiments/NN167_small.rds")
NN156_small <- readRDS(file="Loxcode_experiments/NN156_small.rds")
NN156 <- readRDS(file="Loxcode_experiments/NN156.rds")
NN167 <- readRDS(file="Loxcode_experiments/NN167.rds")

load data


load small data for server

# # load distance maps 
 loxcoder::load_origin_distmaps('/wehisan/general/user_managed/grpu_naik.s_2/TW/maps/origin/')
 loxcoder::load_pair_distmaps('/wehisan/general/user_managed/grpu_naik.s_2/TW/maps/origin/')
 #load sample sheet and fastq directory
 samplesheet = "/wehisan/general/user_managed/grpu_naik.s_2/2019_Sequencing_Runs/NN156/191007_M04529_0207_000000000-CNWC9/fastq/nn156_samples_small.xlsx" #  Samplenames
 fastq_dir = "/wehisan/general/user_managed/grpu_naik.s_2/2019_Sequencing_Runs/NN156/191007_M04529_0207_000000000-CNWC9/fastq/"
NN156_small <- loxcoder::load_from_xlsx(name = 'NN156_small', s=samplesheet,dir=fastq_dir, load = TRUE, full = FALSE)
# # load distance maps 
 loxcoder::load_origin_distmaps('/wehisan/general/user_managed/grpu_naik.s_2/TW/maps/origin/')
 loxcoder::load_pair_distmaps('/wehisan/general/user_managed/grpu_naik.s_2/TW/maps/origin/')
 #load sample sheet and fastq directory
 samplesheet = "/stornext/Home/data/allstaff/n/ng.j/jngwehi/NN167_samples_small.xlsx" #  Samplenames
 fastq_dir = "/wehisan/general/user_managed/grpu_naik.s_2/2019_Sequencing_Runs/NN167/saraT_221119/191119_M04529_0218_000000000-CTC4W/Data/Intensities/BaseCalls/"
NN167_small <- loxcoder::load_from_xlsx(name = 'NN167_small', s=samplesheet,dir=fastq_dir, load = TRUE, full = FALSE)

load small data for desktop

# # load distance maps 
 loxcoder::load_origin_distmaps('/wehisan/general/user_managed/grpu_naik.s_2/TW/maps/origin/')
 loxcoder::load_pair_distmaps('/wehisan/general/user_managed/grpu_naik.s_2/TW/maps/origin/')
 #load sample sheet and fastq directory
 samplesheet = "/Volumes/Naik_NGS/2019_Sequencing_Runs/NN156/191007_M04529_0207_000000000-CNWC9/fastq/nn156_samples_small.xlsx" #  Samplenames
 fastq_dir = "/Volumes/Naik_NGS/2019_Sequencing_Runs/NN156/191007_M04529_0207_000000000-CNWC9/fastq/"
Small <- loxcoder::load_from_xlsx(name = 'NN156', s=samplesheet,dir=fastq_dir,suffix_R1='_R1_001.fastq', suffix_R2='_R2_001.fastq', load = TRUE, full = FALSE)

analysis {.tabset .tabset-fade}

summary table

DT::datatable(loxcoder::summary_table(Small, "all_samples"))

test sample table

DT::datatable(loxcoder::sample_table(M, "test_matrix"))

heatmap

loxcoder::heatmap_plot(N,code_set="test_codeset")

heatmap

loxcoder::heatmap_plot(D,code_set="all_codes")

read stats

loxcoder::readstats_plot(D, plot="size",fill=FALSE)

complexity

loxcoder::readstats_plot(D, plot="complexity")

size vs complex

#loxcoder::readstats_plot(D, plot="both")

ratio

#loxcoder::readstats_plot(D, plot="ratio")

saturation

p <- loxcoder::saturation_plot(Small,code_set="all_codes")
ggplotly(p)

pair comparison plot

p <- loxcoder::pair_comparison_plot(Small@samples$M2_P5_A_1, Small@samples$M3_P5_A_2, c(254,254), plot="size")
ggplotly(p)

test code

sample1 = D@samples$M2_P5_A_1
sample2 = D@samples$M3_P5_A_2
dist_range = c(254,254)
loxcoder::get_comparison_table(sample1, sample2, dist_range)

test make_codeset

s = c(3, 6)
c = c(1, 254)
n = "test_codeset"
M = loxcoder::make_codeset(D, n, s, c)

test delete_codeset

d = "test"
M = loxcoder::delete_codeset(N, d)

test create codeset

n = "test2"
I = c(76,2,3,4,5,12,999)
c = "all_codes"
M = loxcoder::make_codeset_index(D,c,I,n)

test make_count_matrix

n = "test_matrix"
I = c("M2_P5_A_1")
c = "all_samples"
M = loxcoder::make_count_matrix(D, c, I, n)
M@count_matrixes[["test_matrix"]]
loxcoder::sample_comparison_pie(D)

test rename_sample

lox = Small
lox = rename_sample(lox, "all_samples", "test", "M2_P5_A_1")
print(lox)
validateFastq <- function(samplesheet, files) {
  files = sort(files[grepl(".fastq$", files)])
  R1 = sort(files[grepl("R1_001.", files)])
  R2 = sort(files[grepl("R2_001.", files)])

  if ("sample" %in% names(samplesheet)){
    sample_names = sort(samplesheet$sample)
  } else {
    showNotification("Sample sheet is invalid. Missing `sample` column.")
    return(FALSE)
  }

  # find the fastq files for each sample
  for (i in sample_names) {
    if (sum(grepl(i,R1))!=1 || sum(grepl(i,R2))!=1) {
      showNotification("Could not find sample", i, "in fastq directory.")
      return(FALSE)
    }
  }

  # checks if there are two runs each in fastq directory
  if (length(R1) != length(R2)) {
    for (s in R1){
      if ((gsub("_R1_001", "_R2_001", s) %in% R2) == FALSE) {
        showNotification(paste(s, "is missing `R2_001` run in fastq directory."))
      }
    }
    for (s in R2){
      if ((gsub("_R2_001", "_R1_001", s) %in% R1) == FALSE) {
        showNotification(paste(s, "is missing `R1_001` run in fastq directory."))
      }
    }
  }

  return (TRUE)
}

samplesheet = read_excel("/wehisan/general/user_managed/grpu_naik.s_2/2019_Sequencing_Runs/NN156/191007_M04529_0207_000000000-CNWC9/fastq/nn156_samples_small.xlsx")
files = list.files(fastq_dir)
validateFastq(samplesheet, files)

test merge experiments

test = merge_experiments(Small, Full, name="test", type="union")

app example

shiny::shinyApp(

  ui = shiny::fluidPage(
    shiny::selectInput("matrix", "Sample:", choices = names(D@count_matrixes)),
    shiny::selectInput("codeset", "Codes:", choices = names(D@code_sets)),
    shiny::plotOutput("Plot")
    ),

  server = function(input, output) {
    output$Plot = renderPlot({
    loxcoder::heatmap_plot(D,code_set=input$codeset)
    })
    },

    options = list(height = 600)
)
sample_table(Small, "all_samples")


jngwehi/loxcodeR documentation built on March 17, 2020, 5:32 p.m.