From 5f6653242cd59885df064e9cc502b01bbd85936c Mon Sep 17 00:00:00 2001
From: Xiuwen Zheng <zhengxwen@users.noreply.github.com>
Date: Thu, 14 Mar 2024 20:44:12 -0500
Subject: [PATCH] new option 'all' in hlaUniqueAllele()

---
 DESCRIPTION            |  4 ++--
 NEWS                   |  6 ++++++
 R/DataUtilities.R      | 16 ++++++++++++++--
 man/hlaUniqueAllele.Rd | 10 +++++++---
 4 files changed, 29 insertions(+), 7 deletions(-)

diff --git a/DESCRIPTION b/DESCRIPTION
index a399433..4a611ed 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -1,8 +1,8 @@
 Package: HIBAG
 Type: Package
 Title: HLA Genotype Imputation with Attribute Bagging
-Version: 1.38.4
-Date: 2024-03-11
+Version: 1.39.4
+Date: 2024-03-14
 Depends: R (>= 3.2.0)
 Imports: methods, RcppParallel
 Suggests: parallel, ggplot2, reshape2, gdsfmt, SNPRelate, SeqArray, knitr,
diff --git a/NEWS b/NEWS
index 378cbc4..2d7d37d 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,9 @@
+CHANGES IN VERSION 1.39.4
+-------------------------
+
+    o new option 'all' in `hlaUniqueAllele()`
+
+
 CHANGES IN VERSION 1.38.3
 -------------------------
 
diff --git a/R/DataUtilities.R b/R/DataUtilities.R
index 75ad5a4..4324d48 100644
--- a/R/DataUtilities.R
+++ b/R/DataUtilities.R
@@ -1136,7 +1136,7 @@ hlaAlleleDigit <- function(obj, max.resolution=NA_character_, rm.suffix=FALSE)
 # Get unique HLA alleles
 #
 
-hlaUniqueAllele <- function(hla)
+hlaUniqueAllele <- function(hla, all=NA)
 {
     # check
     stopifnot(is.character(hla) | inherits(hla, "hlaAlleleClass"))
@@ -1147,7 +1147,19 @@ hlaUniqueAllele <- function(hla)
         hla <- unique(hla)
         .Call(HIBAG_SortAlleleStr, hla)
     } else {
-        hlaUniqueAllele(as.character(c(hla$value$allele1, hla$value$allele2)))
+        s <- c(hla$value$allele1, hla$value$allele2)
+        if (isTRUE(all))
+        {
+            if (!is.null(hla$dosage))
+            {
+                s <- rownames(hla$dosage)
+            } else if (!is.null(hla$postprob))
+            {
+                s <- strsplit(rownames(hla$postprob), "/", fixed=TRUE)
+                s <- unique(unlist(s))
+            }
+        }
+        hlaUniqueAllele(as.character(s))
     }
 }
 
diff --git a/man/hlaUniqueAllele.Rd b/man/hlaUniqueAllele.Rd
index 52487f7..ad050a9 100644
--- a/man/hlaUniqueAllele.Rd
+++ b/man/hlaUniqueAllele.Rd
@@ -7,11 +7,15 @@
     Get unique HLA alleles, which are in ascending order.
 }
 \usage{
-hlaUniqueAllele(hla)
+hlaUniqueAllele(hla, all=NA)
 }
 \arguments{
-    \item{hla}{character-type HLA alleles, or a
-        \code{\link{hlaAlleleClass}} object}
+    \item{hla}{character-type HLA alleles, or a \code{\link{hlaAlleleClass}}
+        object}
+    \item{all}{when \code{hla} is a \code{hlaAlleleClass} object and
+        \code{all=TRUE}, return all HLA alleles if \code{hla$dosage} or
+        \code{hla$postprob} exists; otherwise, only return the alleles in
+        \code{hla$value}}
 }
 \details{
     Each HLA allele name has a unique number corresponding to up to four sets