scDHA.class: scDHA classification

Description Usage Arguments Value Examples

View source: R/Analysis.R

Description

Perform classification of new data based on available data.

Usage

1
2
3
4
5
6
7
scDHA.class(
  train = train,
  train.label = train.label,
  test = test,
  ncores = 10L,
  seed = NULL
)

Arguments

train

Expression matrix of available data, with rows represent samples and columns represent genes.

train.label

A vector containing label for each sample in training data.

test

Expression matrix new data for classification, with rows represent samples and columns represent genes.

ncores

Number of processor cores to use.

seed

Seed for reproducibility.

Value

A vector contain classified labels for new data.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
library(scDHA)
#Load example data (Goolam dataset)
data('Goolam'); data <- t(Goolam$data); label <- as.character(Goolam$label)
#Log transform the data 
data <- log2(data + 1)
#Split data into training and testing sets
set.seed(1)
idx <- sample.int(nrow(data), size = round(nrow(data)*0.75))
train.x <- data[idx, ]; train.y <- label[idx]
test.x <- data[-idx, ]; test.y <- label[-idx]
if(torch::torch_is_installed()) #scDHA need libtorch installed
{
  #Predict the labels of cells in testing set
  prediction <- scDHA.class(train = train.x, train.label = train.y, test = test.x, 
                            ncores = 2, seed = 1)
  #Calculate accuracy of the predictions
  acc <- round(sum(test.y == prediction)/length(test.y), 2)
  print(paste0("Accuracy = ", acc))
}

scDHA documentation built on Sept. 16, 2021, 1:07 a.m.