The hardware and bandwidth for this mirror is donated by METANET, the Webhosting and Full Service-Cloud Provider.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]metanet.ch.

Package {KRIS}


Type: Package
Title: Keen and Reliable Interface Subroutines for Bioinformatic Analysis
Version: 1.1.14
Description: Provides functions for bioinformatic analysis: calculating linear principal components from numeric data and single-nucleotide polymorphism (SNP) datasets, calculating the fixation index (Fst) with the Hudson method <doi:10.1101/gr.154831.113>, creating scatter plots in 3 views, handling the 'PLINK' binary file format, detecting rough structures and outliers with unsupervised clustering, and calculating matrix multiplication faster for big data.
Depends: R (≥ 3.5.0)
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.3.2
Imports: rARPACK,grDevices,graphics,stats,utils
Suggests: testthat
BugReports: https://github.com/kridsadakorn/kris/issues
URL: https://github.com/kridsadakorn/kris
NeedsCompilation: no
Packaged: 2026-12-02 15:37:40 UTC; kris
Author: Kridsadakorn Chaichoompu ORCID iD [aut, cre], Kristel Van Steen ORCID iD [aut], Fentaw Abegaz ORCID iD [aut], Sissades Tongsima ORCID iD [aut], Philip James Shaw [aut], Anavaj Sakuntabhai ORCID iD [aut], Luisa Pereira ORCID iD [aut]
Maintainer: Kridsadakorn Chaichoompu <kridsadakorn@biostatgen.org>
Repository: CRAN
Date/Publication: 2026-12-03 08:50:19 UTC

KRIS: Keen and Reliable Interface Subroutines for Bioinformatic Analysis

Description

Tools for common steps in the bioinformatic analysis of numeric and SNP data.

Details

Functions:

Example data: simsnp and sample_labels, loaded with data(example_SNP).

KRIS uses rARPACK for the eigen decomposition.

Author(s)

Maintainer: Kridsadakorn Chaichoompu kridsadakorn@biostatgen.org (ORCID)

Authors:

See Also

Useful links:


Linear principal component analysis (PCA)

Description

Computes principal components (PCs) from a numeric matrix or from SNP data in additive coding (0, 1, 2). Missing values are replaced by the column median before the analysis.

Usage

cal.pc.linear(X, PCscore = TRUE, no.pc = NA, data.type = "linear", XXT = TRUE)

Arguments

X

A numeric matrix with samples in rows and features in columns.

PCscore

If TRUE (default), return PC scores. If FALSE, return the eigenvectors.

no.pc

Number of PCs to compute. If NA (default), all PCs are computed.

data.type

Type of data in X: "linear" (default) for numeric data or "snp" for SNPs in additive coding. It sets how each column is scaled.

XXT

If TRUE (default), compute the PCs from X %*% t(X); if FALSE, from X directly. Both give the same PCs, but TRUE is faster when X has many columns.

Value

A list with:

See Also

cal.pc.projection

Examples


#Load simulated dataset
data(example_SNP)

#Using default parameters
PCs <- cal.pc.linear(simsnp$snp)
summary(PCs)

#Preview $PC
print(PCs$PC[1:5,1:3])

#Preview $evalue
print(PCs$evalue[1:3])

plot3views(PCs$PC[,1:3], sample_labels)

#Calculate PCs without PC scores

PCs <- cal.pc.linear(simsnp$snp, PCscore = FALSE)
summary(PCs)

#Preview $PC
print(PCs$PC[1:5,1:3])

#Preview $evalue
print(PCs$evalue[1:3])

plot3views(PCs$PC[,1:3], sample_labels)

#Calculate the top 3 PCs
PCs <- cal.pc.linear(simsnp$snp, no.pc = 3)
summary(PCs)

#Preview $PC
print(PCs$PC[1:5,1:3])

#Preview $evalue
print(PCs$evalue[1:3])

plot3views(PCs$PC[,1:3], sample_labels)

PCA of controls with cases projected onto it

Description

Computes principal components (PCs) from the control group only, then projects the case group onto those PCs. The disease status of every individual is required. Missing values are replaced by the column median before the analysis.

Usage

cal.pc.projection(
  X,
  status,
  individual_id = NULL,
  labels = NULL,
  no.pc = NA,
  data.type = "snp"
)

Arguments

X

A numeric matrix with samples in rows and features in columns.

status

A numeric vector with the disease status of each individual: 1 for control, 2 for case. Individuals with any other value are left out of the result.

individual_id

Optional character vector of individual IDs.

labels

Optional character vector of labels, such as population names.

no.pc

Number of PCs to compute. If NA (default), all PCs are computed.

data.type

Type of data in X: "snp" (default) for SNPs in additive coding, or "linear" for numeric data. It sets how each column is scaled. Both the centre and the scale are taken from the control group and applied to the cases.

Value

A list in which controls come first, then cases:

See Also

cal.pc.linear

Examples


data(example_SNP)

#Create a random list of disease status, 1 = Control and 2 = Case

set.seed(1)
ind_status <- sample(c(1,2), size = length(sample_labels), replace = TRUE)

PCs <- cal.pc.projection(simsnp$snp, status = ind_status,
labels = sample_labels)
summary(PCs)

#Preview $PC
print(PCs$PC[1:5,1:3])

#Preview $status
print(PCs$status[1:3])

plot3views(PCs$PC[,1:3], PCs$label)

#Calculate the top 3 PCs

PCs <- cal.pc.projection(simsnp$snp, status = ind_status,
labels = sample_labels, no.pc = 3)
summary(PCs)

#Preview $PC
print(PCs$PC[1:5,1:3])

plot3views(PCs$PC[,1:3], PCs$label)



Fixation index (Fst) for each SNP between two groups

Description

Computes Fst for every SNP between two groups of individuals with the Hudson method (Hudson et al. 1992; Bhatia et al. 2013).

Usage

fst.each.snp.hudson(X, idx.p1, idx.p2)

Arguments

X

A matrix of SNPs in additive coding (0, 1, 2), with individuals in rows and SNPs in columns.

idx.p1

Row indices of the individuals in the first group.

idx.p2

Row indices of the individuals in the second group.

Value

A numeric vector with one Fst value per SNP (column of X).

References

Bhatia, G., Patterson, N., Sankararaman, S., and Price, A.L. (2013). Estimating and interpreting FST: The impact of rare variants. Genome Res. 23, 1514-1521.

Hudson, R.R., Slatkin, M., and Maddison, W.P. (1992). Estimation of levels of gene flow from DNA sequence data. Genetics 132, 583-589.

See Also

fst.hudson

Examples



#Load simulated dataset
data(example_SNP)

idx1 <- which(sample_labels == 'pop1')
idx2 <- which(sample_labels == 'pop2')
fst.pairwise <- fst.each.snp.hudson(simsnp$snp, idx1, idx2)

#Print out the Fst values of the first three SNPs between 'pop1' and 'pop2'
print(fst.pairwise[1:3])


Average fixation index (Fst) between two groups

Description

Computes the average Fst over all SNPs between two groups of individuals with the Hudson method (Hudson et al. 1992). The average is taken as a ratio of averages, as recommended by Bhatia et al. (2013).

Usage

fst.hudson(X, idx.p1, idx.p2)

Arguments

X

A matrix of SNPs in additive coding (0, 1, 2), with individuals in rows and SNPs in columns.

idx.p1

Row indices of the individuals in the first group.

idx.p2

Row indices of the individuals in the second group.

Value

A single Fst value.

References

Bhatia, G., Patterson, N., Sankararaman, S., and Price, A.L. (2013). Estimating and interpreting FST: The impact of rare variants. Genome Res. 23, 1514-1521.

Hudson, R.R., Slatkin, M., and Maddison, W.P. (1992). Estimation of levels of gene flow from DNA sequence data. Genetics 132, 583-589.

See Also

fst.each.snp.hudson

Examples



#Load simulated dataset
data(example_SNP)

idx1 <- which(sample_labels == 'pop1')
idx2 <- which(sample_labels == 'pop2')
fst <- fst.hudson(simsnp$snp, idx1, idx2)

#Print out the Fst value between 'pop1' and 'pop2'
print(fst)


Scatter plots in three views

Description

Draws the first three columns of X as three scatter plots (PC1 vs PC2, PC3 vs PC2 and PC1 vs PC3) plus a legend, in a 2 x 2 layout.

Usage

plot3views(
  X,
  labels,
  only.row = NA,
  plot.legend = NA,
  plot.pattern = NA,
  plot.color = NA
)

Arguments

X

A matrix or data.frame with at least 3 numeric columns. Only the first 3 columns are used.

labels

A character vector with one label per row of X. Points with the same label share a color and symbol.

only.row

Optional vector of row numbers to plot. If NA (default), all rows are plotted.

plot.legend

Optional character vector of the labels to style; see Details.

plot.pattern

Optional vector of point symbols (characters or integers, as in pch), one per entry of plot.legend.

plot.color

Optional vector of colors (names, hex codes or integers), one per entry of plot.legend.

Details

To choose your own colors and symbols, give plot.legend, plot.pattern and plot.color together, all of the same length. If any of them is missing or the lengths differ, the default colors and symbols are used. See the examples.

The argument col.pat.table was removed in version 1.1.5.

Value

NULL, invisibly. The function is called for its plot.

Examples


#Load simulated dataset
data(example_SNP)

PCs <- cal.pc.linear(simsnp$snp, no.pc = 3)
plot3views( PCs$PC, sample_labels)

#To change colors and patterns using symbols
all.labels <- unique(sample_labels)
my.colors <- c('pink', 'cyan', 'green')
my.patterns <- c(0,1,2)
plot3views(PCs$PC, labels = sample_labels, plot.legend = all.labels,
plot.pattern = my.patterns, plot.color = my.colors)

#To change patterns using characters
my.patterns <- c('o', 'x', '#')
#To change colors using Hex code
my.colors <- c('#E74C3C', '#8E44AD', '#2ECC71')
plot3views(PCs$PC, labels = sample_labels, plot.legend = all.labels,
plot.pattern = my.patterns, plot.color = my.colors)

Read binary PLINK files (BED, BIM and FAM)

Description

Reads a SNP dataset stored in the binary PLINK format. All three files are needed: BED (genotypes), BIM (SNP information) and FAM (individual information).

Usage

read.bed(bed, bim, fam, only.snp = FALSE)

Arguments

bed

Path to the BED file.

bim

Path to the BIM file.

fam

Path to the FAM file.

only.snp

If TRUE, return only the SNP matrix. Default FALSE.

Details

The file format is the PLINK 1.9 binary format, described in the "File formats" section of the PLINK 1.9 documentation and in Chang et al. (2015), GigaScience 4:7, doi:10.1186/s13742-015-0047-8.

Value

A list with:

If only.snp = TRUE, the list holds only $snp. If a file is missing or the BED file is not valid, the function prints a message and returns NA.

See Also

write.bed

Examples


#Use the example files embedded in the package.
bed <- system.file("extdata", "example_SNP.bed", package="KRIS")
bim <- system.file("extdata", "example_SNP.bim", package="KRIS")
fam <- system.file("extdata", "example_SNP.fam", package="KRIS")
snp <- read.bed(bed, bim, fam )

#Check the objects inside 'snp'
ls(snp)

#Preview $snp
print(snp$snp[1:10, 1:10])

#Preview $snp.info
head(snp$snp.info)

#Preview $ind.info
head(snp$ind.info)

(Internal) Replace missing values

Description

Used internally by the PCA functions.

Usage

replace.missing(X, missing = NA, rep)

Arguments

X

A vector.

missing

The value that marks a missing entry. Default NA.

rep

A vector of replacement values, the same length as X.

Value

X with its missing entries replaced by the matching values of rep.


Unsupervised clustering to detect rough structure and outliers

Description

Clusters samples on 3 variables, such as the first three principal components. The data are first rotated in each pair of axes to the angle that best separates the points. Clusters are then split wherever the gap between neighboring values on an axis, relative to the range of that axis, is larger than min.space.

Usage

rubikclust(X, min.space = 0.4, rotation = TRUE)

Arguments

X

A numeric matrix with samples in rows and at least 3 columns. Only the first 3 columns are used. Missing values are not allowed.

min.space

Smallest gap, relative to the range of an axis, that separates two clusters. Default 0.4.

rotation

If TRUE (default), rotate the axes before clustering.

Value

A numeric vector with the cluster number of each sample.

Examples

#Load simulated dataset
data(example_SNP)

PCs <- cal.pc.linear(simsnp$snp, no.pc = 3)

#Run rubikclust with the default parameters
groups <- rubikclust(PCs$PC)
#Check clustering results
print(groups)

#Check cluster's distribution
table(groups)

#Check the plot, highlight the points according to the clustering result
mylabels <- paste0("group", as.factor(groups))
plot3views( PCs$PC, labels = mylabels)

#Run rubikclust with min.space = 0.02
groups <- rubikclust(PCs$PC, min.space = 0.02)
#Check clustering results
print(groups)

#Check cluster's distribution
table(groups)

#Check the plot, highlight the points according to the clustering result
mylabels <- paste0("group", as.factor(groups))
plot3views( PCs$PC, labels = mylabels)

Population labels for simsnp

Description

The population label of each of the 103 individuals in simsnp: "pop1", "pop2" or "outlier3".

Usage

data(example_SNP)

Format

A vector with 103 elements.

See Also

simsnp


Simulated SNP dataset

Description

2,000 independent SNPs for 103 simulated individuals: two populations of 50 individuals each, plus 3 outliers. The genetic distance between the populations was set to Fst = 0.01, as in Balding and Nichols (1995).

Usage

data(example_SNP)

Format

A list with 3 elements: snp, snp.info and ind.info.

Details

snp

A numeric matrix with 103 rows (individuals) and 2,000 columns (SNPs), in additive coding (0, 1, 2).

snp.info

A data.frame with one row per SNP and the columns chr (chromosome), ID (SNP ID), GD (genetic distance), position, allele1 and allele2.

ind.info

A data.frame with one row per individual and the columns FamID (family ID), IndID (individual ID), PatID (father ID), MatID (mother ID), sex and phenotype.

References

Balding, D.J., and Nichols, R.A. (1995). A method for quantifying differentiation between populations at multi-allelic loci and its implications for investigating identity and paternity. Genetica 96, 3-12.

See Also

sample_labels


Write a SNP object to binary PLINK files (BED, BIM and FAM)

Description

Saves a SNP object, such as one returned by read.bed, as BED, BIM and FAM files.

Usage

write.bed(object, file)

Arguments

object

A list with $snp, $snp.info and $ind.info; see Details.

file

Output path without extension. The function adds .bed, .bim and .fam. Existing files are overwritten.

Details

object must contain:

The file format is the PLINK 1.9 binary format, described in the "File formats" section of the PLINK 1.9 documentation and in Chang et al. (2015), GigaScience 4:7, doi:10.1186/s13742-015-0047-8.

Value

NULL, invisibly.

See Also

read.bed

Examples



#Load example data
data(example_SNP)

#Save 'simsnp' to the file as defined in 'save.file'
save.file <- file.path(tempdir(),"new_SNP")
write.bed(simsnp , save.file)

Multiply a large matrix by its transpose

Description

Computes X %*% t(X) by splitting the columns of X into blocks of window.size columns and adding up the products of the blocks. This "divide and conquer" approach speeds up the computation for matrices with many columns.

Usage

xxt(X, window.size = 5)

Arguments

X

A numeric matrix.

window.size

Number of columns in each block. Must be a positive integer no larger than ncol(X). Default 5.

Value

The matrix X %*% t(X). If the input is invalid, the function prints a message and returns NULL.

Examples



#Create a random matrix
X <-matrix(runif(100), ncol=20)
R1  <- xxt(X)

#Show the result (R1)
print(R1)
R2 <- X %*% t(X)

#Show the result (R2)
print(R2)



These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.