# see https://stegor.readthedocs.io/en/latest/index.html for more details on the tutorial to follow through.

# make sure that you have installed R, RStudio and the complier from either Quartz or Rtools. Install these before opening R as the changes may not be registered otherwise.

# This is to make sure with installing from source is set to the g++ compiler
Sys.setenv("CXX" = "g++")

# installing STEGO.R
if (!require("BiocManager", quietly = TRUE))
  install.packages("BiocManager")

if (!require("devtools", quietly = TRUE))
  install.packages("devtools")

if (!require("usethis", quietly = TRUE))
  install.packages("usethis")


# Install and load gitcreds package
install.packages("gitcreds")
library(gitcreds)

# Set your GitHub PAT securely
gitcreds_set()

# select option:
2

# personal token generated from github
# 1. login
# 2. https://github.com/settings/tokens
# 3. create a public token


# Unset the GITHUB_PAT environment variable
Sys.unsetenv("GITHUB_PAT")

# Install the devtools package if not already installed
library(devtools)
# gitcreds::gitcreds_set()
# Install the GitHub repository
install_github("KerryAM-R/STEGO.R")


# install STEGO.R with Devtools
# if you get asked about installing from SOURCE, select NO.
# if asked about updating the packages, select either 1 for all, or 3 for none.
# also run this line to check for updates
devtools::install_github("KerryAM-R/STEGO.R")

#
# install.packages("https://github.com/KerryAM-R/STEGO.R/archive/master.tar.gz", repos = NULL, type = "source")

# gitcreds::gitcreds_set()
# if asked to update the app either select 1 to updated all
1
# if asked to install from source on the M1 Mac chip (Seurat)
y

# if then prompted with all the bioconductor based packages to install from source on M1 or greater Mac chip
y

# under development - latest build, but may be unstable
# devtools::install_github("KerryAM-R/STEGO.R", ref = "beta-version", force = T)

# import all of the fonts to your system. Will only need to be done the first time.
require(extrafont)
font_import()

# when it asks if you would like to install the different fonts
y

# you many need to add in the git_token, and the Renviorn is opened with the following code.
usethis::edit_r_environ()

# installing olga with system2
system2("python", args = c("-m", "pip", "install", "olga"))
