R/ancestryAnalysis.R
ancestryInferencePCAKNN.RdThis function runs most steps leading to the ancestry inference call on a specific profile. First, the function creates the Profile GDS file for the specific profile using the information from a RDS Sample description file and the Population Reference GDS file.
ancestryInferencePCAKNN(pRAIDS = RAIDSparam())a list containing 4 entries:
pcaSamplea list containing the information related
to the eigenvectors. The list contains those 3 entries:
sample.ida character string representing the unique
identifier of the current profile.
eigenvector.refa matrix of numeric containing
the eigenvectors for the reference profiles.
eigenvectora matrix of numeric containing the
eigenvectors for the current profile projected on the PCA from the
reference profiles.
paraSamplea list containing the results with
different D and K values that lead to optimal parameter
selection. The list contains those entries:
dfPCAa data.frame containing statistical results
on all combined synthetic results done with a fixed value of D (the
number of dimensions). The data.frame contains those columns:
Da numeric representing the value of D (the
number of dimensions).
mediana numeric representing the median of the
minimum AUROC obtained (within super populations) for all combination of
the fixed D value and all tested K values.
mada numeric representing the MAD of the minimum
AUROC obtained (within super populations) for all combination of the fixed
D value and all tested K values.
upQuartilea numeric representing the upper quartile
of the minimum AUROC obtained (within super populations) for all
combination of the fixed D value and all tested K values.
ka numeric representing the optimal K value
(the number of neighbors) for a fixed D value.
dfPopa data.frame containing statistical results on
all combined synthetic results done with different values of D (the
number of dimensions) and K (the number of neighbors).
The data.frame contains those columns:
Da numeric representing the value of D (the
number of dimensions).
Ka numeric representing the value of K (the
number of neighbors).
AUROC.mina numeric representing the minimum accuracy
obtained by grouping all the synthetic results by super-populations, for
the specified values of D and K.
AUROCa numeric representing the accuracy obtained
by grouping all the synthetic results for the specified values of D
and K.
Accu.CMa numeric representing the value of accuracy
of the confusion matrix obtained by grouping all the synthetic results for
the specified values of D and K.
dfAUROCa data.frame the summary of the results by
super-population. The data.frame contains
those columns:
Da numeric representing the value of D (the
number of dimensions).
Ka numeric representing the value of K (the
number of neighbors).
Calla character string representing the
super-population.
La numeric representing the lower value of the 95%
confidence interval for the AUROC obtained for the fixed values of
super-population, D and K.
AUROCa numeric representing the AUROC obtained for
the fixed values of super-population, D and K.
Ha numeric representing the higher value of the 95%
confidence interval for the AUROC obtained for the fixed values of
super-population, D and K.
Da numeric representing the optimal D value
(the number of dimensions) for the specific profile.
Ka numeric representing the optimal K value
(the number of neighbors) for the specific profile.
listDa numeric representing the optimal D
values (the number of dimensions) for the specific profile. More than one
D is possible.
KNNSamplea data.frame containing the inferred
ancestry for different values of K and D. The
data.frame contains those columns:
sample.ida character string representing the unique
identifier of the current profile.
Da numeric representing the value of D (the
number of dimensions) used to infer the ancestry.
Ka numeric representing the value of K (the
number of neighbors) used to infer the ancestry.
SuperPopa character string representing the inferred
ancestry for the specified D and K values.
KNNSynthetica data.frame containing the inferred
ancestry for each synthetic data for different values of K and
D.
The data.frame
contains those columns:
sample.ida character string representing the unique
identifier of the current synthetic data.
Da numeric representing the value of D (the
number of dimensions) used to infer the ancestry.
Ka numeric representing the value of K (the
number of neighbors) used to infer the ancestry.
infer.superPopa character string representing the
inferred ancestry for the specified D and K values.
ref.superPopa character string representing the known
ancestry from the reference
Ancestrya data.frame containing the inferred
ancestry for the current profile. The data.frame contains those
columns:
sample.ida character string representing the unique
identifier of the current profile.
Da numeric representing the value of D (the
number of dimensions) used to infer the ancestry.
Ka numeric representing the value of K (the
number of neighbors) used to infer the ancestry.
SuperPopa character string representing the inferred
ancestry.
pRAIDSa list of class RAIDSparam a list of
the parameters.
The runExomeAncestry() function generates 3 types of files in the OUTPUT directory.
The ancestry inference CSV file (".Ancestry.csv" file)
The inference information RDS file (".infoCall.rds" file)
The parameter information RDS files from the synthetic inference ("KNN.synt.*.rds" files in a sub-directory)
In addition, a sub-directory (named using the profile ID) is also created.
Galinsky KJ, Bhatia G, Loh PR, Georgiev S, Mukherjee S, Patterson NJ, Price AL. Fast Principal-Component Analysis Reveals Convergent Evolution of ADH1B in Europe and East Asia. Am J Hum Genet. 2016 Mar 3;98(3):456-72. doi: 10.1016/j.ajhg.2015.12.022. Epub 2016 Feb 25.
## Path to the demo 1KG GDS file is located in this package
dataDir <- system.file("extdata", package="RAIDS")
#################################################################
## The 1KG GDS file and the 1KG SNV Annotation GDS file
## need to be located in the same directory
## Note that the 1KG GDS file used for this example is a
## simplified version and CANNOT be used for any real analysis
#################################################################
path1KG <- file.path(dataDir, "tests")
fileReferenceGDS <- file.path(path1KG, "ex1_good_small_1KG.gds")
fileAnnotGDS <- file.path(path1KG, "ex1_good_small_1KG_Annot.gds")
#################################################################
## The Sample SNP pileup files (one per sample) need
## to be located in the same directory.
#################################################################
demoProfileEx1 <- file.path(dataDir, "example", "snpPileup", "ex1.txt.gz")
#################################################################
## The path where the Profile GDS Files (one per sample)
## will be created need to be specified.
#################################################################
pathProfileGDS <- file.path(tempdir(), "out.tmp")
if(!dir.exists(pathProfileGDS)){
dir.create(pathProfileGDS)
}
####################################################################
## Fix seed to ensure reproducible results
####################################################################
set.seed(3043)
pRAIDS <- RAIDS:::RAIDSparam(profileFile=demoProfileEx1,
genoSource="snp-pileup",
pathProfileGDS=pathProfileGDS,
fileReferenceGDS=fileReferenceGDS,
fileReferenceAnnotGDS=fileAnnotGDS
)
res <- ancestryInferencePCAKNN(pRAIDS=pRAIDS)
#> Warning: A K smaller than 3 could not give robust results.
res$Ancestry
#> sample.id D K superPop
#> 192 ex1 15 11 AFR
unlink(file.path(pathProfileGDS, paste0(pedStudy(res$pRAIDS)$Name.ID[1], ".gds")) , force=TRUE)
if (length(dir(pathProfileGDS)) == 0) {
unlink(pathProfileGDS, recursive = TRUE)
}