This function write with P-matrix

prepPMatrix(anchor, snpId, matGr = NULL, pRAIDS)

Arguments

anchor

a vector of character representing the ancestral group for each profile from the reference where sample.ref == 1. If the admixture proportion is higher than the threshold for one ancestral group, the value is the name of the ancestral group; else "-".

snpId

a vector of character representing the list of snp.id from gdsReference to keep.

matGr

a matrix containing the sample identifiers and where each column is the name of a subcontinental population. The number of row corresponds to the number of samples for each subcontinental population.

pRAIDS

a RAIDSparam an object with all the RAIDS parameters.

Value

a list containing one entry per ancestral group:

ancestral group

a list contenains 2 entries:

f

a list contenains number of rows in matGr + 1 entries:

vector

the first is frequency for all the anchor of each snpId

vector

the other is frequency for all the anchor minus one row of matGr of each snpId

index

a vector contenains 2 entriescontenains number of rows in matGr entries. Each value is the index of the row for which the f of this index corresponds.

Author

Pascal Belleau, Astrid Deschênes and Alexander Krasnitz

Examples


## Required library
library(SNPRelate)
data(demoKnownSuperPop1KG)

## Path to the demo Profile GDS file is located in this package
dataDir <- system.file("extdata/demoAncestryCall", package="RAIDS")


# The name of the synthetic study
studyID <- "MYDATA"

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,
                      fieldPopInfAnc="SuperPop")


matGr <- getMatrixPopSynthetic(pRAIDS=pRAIDS)
fileGDSProfile <- file.path(pathProfileGDS(pRAIDS),
                            paste0(pedStudy(pRAIDS)$Name.ID[1], ".gds"))


gdsProfile <- snpgdsOpen(fileGDSProfile)
pruned <- read.gdsn(index.gdsn(gdsProfile, "pruned.study"))
snpgdsClose(gdsProfile)
gdsReference <- snpgdsOpen(fileReferenceGDS(pRAIDS))

admixDesc <- read.gdsn(index.gdsn(gdsReference, "admixture.desc"))
pos <- admixDesc[admixDesc$id == anchorId(pRAIDS), "id.seq"]

anchor <- read.gdsn(index.gdsn(gdsReference, "anchor.ref"),
                    start=c(1, pos), count=c(-1,1))
snpgdsClose(gdsReference)

rowF <- prepPMatrix( anchor=anchor, snpId = pruned, matGr=matGr, pRAIDS=pRAIDS)
#> Genotype matrix: 28 samples X 61 SNPs
#> Genotype matrix: 27 samples X 61 SNPs
#> Genotype matrix: 5 samples X 61 SNPs
#> Genotype matrix: 33 samples X 61 SNPs
#> Genotype matrix: 10 samples X 61 SNPs
names(rowF)
#> [1] "agEUR" "agEAS" "agAMR" "agAFR" "agSAS"