## ----eval = FALSE-------------------------------------------------------------
# if (!requireNamespace("BiocManager",
#                       quietly = TRUE)) {
#   install.packages("BiocManager")
# }
# BiocManager::install("SynExtend")

## ----build_synteny_object-----------------------------------------------------
suppressMessages(library(SynExtend))
suppressMessages(library(DBI))

file01 <- system.file("extdata",
                      "example_db.sqlite",
                      package = "SynExtend")

# later on there are some auto-adds to the DB, we create a tmp db here so that
# the db that's passed around for examples remains as small as possible...
tmp_db <- tempfile()
system(command = paste("cp",
                       file01,
                       tmp_db))

drv <- dbDriver("SQLite")
conn01 <- dbConnect(drv = drv,
                    tmp_db)

syn <- FindSynteny(dbFile = conn01)

## ----synplots01---------------------------------------------------------------
syn
pairs(syn)

## ----synplots02---------------------------------------------------------------
print(head(syn[[1, 2]]))

## ----synplots03---------------------------------------------------------------
print(head(syn[[2, 1]]))

## ----generate_genecalls-------------------------------------------------------

gr_obj <- rtracklayer::import(system.file("extdata",
                                          "GCF_023585725.1_ASM2358572v1_genomic.gff.gz",
                                          package = "SynExtend"))
genecalls_object <- SquaregffBy(gff_object = gr_obj,
                                verbose = TRUE)

head(genecalls_object)

# in an effort to be space conscious, not all original gffs are kept within this package
genecalls <- get(data("genecalls", package = "SynExtend"))

## ----print_gene_calls---------------------------------------------------------
# this is similar to what was printed above...
head(genecalls[[1]])

## ----generate_initial_links---------------------------------------------------
l01 <- NucleotideOverlap(SyntenyObject = syn,
                         GeneCalls = genecalls,
                         Verbose = TRUE)

## ----link_printing------------------------------------------------------------
head(l01[[1, 2]])
head(l01[[2, 1]])

## ----describe_links-----------------------------------------------------------
p01 <- SummarizePairs(SynExtendObject = l01,
                      DataBase01 = conn01,
                      Verbose = TRUE)

hist(p01$Approx_Global_PID,
     breaks = seq(from = 0,
                  to = 1,
                  by = 0.01))

## ----evaluate_links-----------------------------------------------------------
p02 <- EvaluatePairs(InputPairs = p01,
                            DataBase01 = conn01,
                            EvaluationMethod = "none",
                            FDRCriteria = c("Delta_Background" = 0.001)) # this is the default behavior

hist(p02$Approx_Global_PID,
     breaks = seq(from = 0,
                  to = 1,
                  by = 0.01))

## -----------------------------------------------------------------------------
sessionInfo()

