-
Notifications
You must be signed in to change notification settings - Fork 0
/
senFinder.R
54 lines (36 loc) · 1.09 KB
/
senFinder.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#clear the R environment
rm(list=ls())
# Call library
library(dplyr)
library(tidyr)
library(ggplot2)
library(lattice)
library(caret)
library(e1071)
# Retrieve command-line arguments
args <- commandArgs(trailingOnly = TRUE)
# Check if the required arguments are provided
if (length(args) != 2) {
stop("Two arguments are required: an RDS file and a CSV file.")
}
# Assign arguments to variables
rds_file <- args[1]
csv_file <- args[2]
# Load the RDS file
svm_model <- readRDS(rds_file)
# Load the CSV file
new_data <- read.csv(csv_file)
# modify data
features <- new_data[, -which(names(new_data) == "Sample_id")]
sample_labels <- new_data$Sample_id
# predict the data
# Generate predictions
predicted_labels <- predict(svm_model, newdata = features)
# Convert X1 to Yes and X0 to No
converted_labels <- ifelse(predicted_labels == "X1", "Yes", "No")
# Create a dataframe
df <- data.frame(Column1 = sample_labels, Column2 = converted_labels)
# Modify column names
colnames(df) <- c("Sample_id", "Senescence_status")
# Save the updated dataset
write.csv(df, "./predicted_results.csv", row.names = FALSE)