R/ancestryAnalysis.R
computeKNNRefSyn.RdThe function runs k-nearest neighbors analysis on a subset of the synthetic data set. The function uses the 'knn' package.
computeKNNRefSyn(listEigenvector, pRAIDS)a list containing 4 entries:
sample.ida vector of character strings
representing the identifiers of the synthetic profiles analysed.
sample1Kga vector of character strings
representing the identifiers of the 1KG reference profiles used to
generate the synthetic profiles.
spa vector of character strings representing
the known super population ancestry of the 1KG reference profiles used
to generate the synthetic profiles.
matKNNa data.frame containing the super population
inference for each synthetic profiles for different values of PCA
dimensions D and k-neighbors values K. The fourth column title
corresponds to the fieldPopInfAnc parameter.
The data.frame contains 4 columns:
sample.ida character string representing
the identifier of the synthetic profile analysed.
Da numeric strings representing
the value of the PCA dimension used to infer the super population.
Ka numeric strings representing
the value of the k-neighbors used to infer the super population.
fieldPopInfAnc valuea character string representing
the inferred ancestry.
## Load the demo PCA on the synthetic profiles projected on the
## demo 1KG reference PCA
data(demoPCASyntheticProfiles)
## Load the known ancestry for the demo 1KG reference profiles
data(demoKnownSuperPop1KG)
## Path to the demo Profile GDS file is located in this package
dataDir <- system.file("extdata/demoKNNSynthetic", package="RAIDS")
# The name of the synthetic study
studyID <- "MYDATA.Synthetic"
studyDF <- data.frame(study.id=studyID,
study.desc=studyID,
study.platform="NotDef",
stringsAsFactors=FALSE)
pathProfileGDS <- file.path(dataDir) # , "ex1.gds"
fileReferenceGDS <- system.file("extdata/tests/ex1_good_small_1KG.gds", package="RAIDS")
pedStudy <- data.frame(Name.ID=c("ex1"),
Case.ID=c("ex1"),
Sample.Type=c("type"),
Diagnosis="NotDef",
Source=c("NotDef"),
stringsAsFactors=FALSE)
row.names(pedStudy) <- pedStudy$Name.ID
pRAIDS <- RAIDSparam(studyDF=studyDF,
pedStudy=pedStudy,
pathProfileGDS=pathProfileGDS,
fileReferenceGDS=fileReferenceGDS)
## Projects synthetic profiles on 1KG PCA
results <- computeKNNRefSyn(listEigenvector=demoPCASyntheticProfiles,
pRAIDS=pRAIDS)
## The inferred ancestry for the synthetic profiles for different values
## of D and K
head(results$matKNN)
#> sample.id D K superPop
#> 1 1.ex1.HG00246.1 2 2 SAS
#> 2 1.ex1.HG00325.1 2 2 EAS
#> 3 1.ex1.HG00611.1 2 2 SAS
#> 4 1.ex1.HG01173.1 2 2 EAS
#> 5 1.ex1.HG02165.1 2 2 EAS
#> 6 1.ex1.HG01112.1 2 2 AMR