Defines functions UpdateRelease

Documented in UpdateRelease

#' Update function for protein aligment upon new IMGT HLA data release
#' This updates the protein aligment used in checking HLA loci and alleles as well as in the amino acid analysis.
#' @param Restore Logical specifying if the original alignment file be restored.
#' @param Force Logical specifiying if update should be forced.
#' @param Output Logical indicating if error reporting should be written to file.
UpdateRelease <- function(Force=F,Restore=F,Output=F) {

  if( !inherits(try(XML::readHTMLTable("http://cran.r-project.org/web/packages/BIGDAWG/index.html",header=F),silent=T),"try-error") ) {

    MainDir <- getwd()
    on.exit(setwd(MainDir), add = TRUE)

    getDir <- path.package('BIGDAWG')
    putDir <- paste(getDir,"/data",sep="")
    if(!dir.exists(putDir)) { dir.create(putDir) }

    if(!Restore) {

      #Check current version against BIGDAWG version
      if(!Force) {


        # Get IMGT Release Version
        Release <- read.table("release_version.txt",comment.char="",sep="\t")
        Release <- apply(Release,MARGIN=1,FUN=function(x) gsub(": ",":",x))
        RV.current <- unlist(strsplit(Release[3],split=":"))[2]

        # Get BIGDAWG
        UPL <- paste(path.package('BIGDAWG'),"/data/UpdatePtnAlign.RData",sep="")
        UpdatePtnList <- NULL ; rm(UpdatePtnList)
        if( file.exists(UPL) ) {
          EPL <- UpdatePtnList
        } else {
          EPL <- ExonPtnList
          UPL.flag=F }

        RV.BIGDAWG <- EPL$Release.Version

        cat("Versions:\n","IMGT/HLA current: ",RV.current,"\n BIGDAWG version: ",RV.BIGDAWG,"\n")
        if(grepl(RV.current,RV.BIGDAWG)) { Flag <- T } else { Flag <- F }

      } else {

        Flag <- F

      }# End if() for setting Flag

      #Run Update if Flag = T
      if(Flag) {

        cat("\nYour database seems up to date. Use Force = T to force the update.")

      } else {

        # For creating UpdatePtnAlign.RData object
        # Define download directory
          Safe <- dir()
          Safe <- c(Safe[!grepl(".txt",Safe)],"UpdatePtnAlign.RData")

        #STEP 1: Define Loci and Read in Reference Exon Map Files
          Loci <- c("A","B","C","DPA1","DPB1","DQA1","DQB1","DRB1","DRB3","DRB4","DRB5")

          #Currently DRB1, DRB3, DRB4, DRB5 aligments in single file
          #Remove if split into individual files
          Loci.get <- c("A","B","C","DPA1","DPB1","DQA1","DQB1","DRB")

          #Exon Info
          RefTab <- BIGDAWG::ExonPtnList$RefExons

        #STEP 2: Download protein alignments and other ancillary files
          cat("Updating reference object for the amino acid analysis.\n")
          cat("Downloading alignment files from the IMGT/HLA.\n")
          Release <- read.table('Release.txt',sep="\t") # created during GetFiles download

        #STEP 3: Format alignments for exons of interest
          cat("Formatting alignment files.\n")
          for(i in 1:length(Loci)) { Locus <- Loci[i] ; ExonPtnAlign.Create(Locus,RefTab) }

        #STEP 4: Create ExonPtnAlign list object for BIGDAWG package

        #STEP 5: Clean up
          cat("Cleaning up.\n")
          invisible(file.remove(dir()[which(dir() %in% Safe!=T)]))


    } else if (Restore) {

      if(!file.exists('UpdatePtnAlign.RData')) { stop("No prior update to restore.", call.= F) }
      cat("Restoring original alignment reference object for amino acid analysis.\n")


  } else {

    stop("Update stopped.",call.=F)



Try the BIGDAWG package in your browser

Any scripts or data that you put into this service are public.

BIGDAWG documentation built on Nov. 17, 2021, 5:08 p.m.