2021-02-21 20:59:39 +01:00
|
|
|
library(immuneSIM)
|
2021-02-26 02:19:40 +01:00
|
|
|
library(Biostrings)
|
2021-02-21 20:59:39 +01:00
|
|
|
|
2021-02-25 20:00:35 +01:00
|
|
|
generate_repertoires <- function(number_of_sequences) {
|
|
|
|
b_chain <- immuneSIM(
|
|
|
|
number_of_seqs = number_of_sequences,
|
|
|
|
species = "hs",
|
|
|
|
receptor = "tr",
|
|
|
|
chain = "b",
|
|
|
|
verbose = TRUE
|
|
|
|
)
|
2021-02-28 02:23:28 +01:00
|
|
|
return(b_chain)
|
2021-02-25 20:00:35 +01:00
|
|
|
}
|
2021-02-21 20:59:39 +01:00
|
|
|
|
2021-02-26 02:19:40 +01:00
|
|
|
process_chain <- function(repertoire) {
|
|
|
|
sequences <- as.character(repertoire$sequence)
|
|
|
|
counts <- as.integer(repertoire$counts)
|
|
|
|
reads <- Biostrings::DNAStringSet(rep(sequences, counts))
|
|
|
|
names(reads) <- seq_len(length(reads))
|
|
|
|
reverse_complement <- Biostrings::reverseComplement(reads)
|
|
|
|
return(reverse_complement)
|
|
|
|
}
|
|
|
|
|
|
|
|
preprocess_data <- function(repertoires) {
|
|
|
|
filtered_repertoires <- lapply(repertoires, process_chain)
|
|
|
|
names(filtered_repertoires) <- names(repertoires)
|
|
|
|
return(filtered_repertoires)
|
|
|
|
}
|
|
|
|
|
2021-02-26 02:20:11 +01:00
|
|
|
save_data <- function(repertoires) {
|
|
|
|
for (chain in names(repertoires)) {
|
|
|
|
file_name <- paste("data/", chain, ".fastq", sep = "")
|
|
|
|
Biostrings::writeXStringSet(repertoires[[chain]], file_name, format = "fastq")
|
|
|
|
}
|
|
|
|
}
|
2021-02-21 20:59:39 +01:00
|
|
|
|
2021-02-25 20:02:11 +01:00
|
|
|
parse_cli_arguments <- function(args) {
|
|
|
|
if (length(args) != 1) {
|
|
|
|
stop("usage: repertoire.r <number of sequences>")
|
|
|
|
}
|
|
|
|
return(as.integer(args[1]))
|
|
|
|
}
|
|
|
|
|
|
|
|
args <- commandArgs(trailingOnly = TRUE)
|
|
|
|
number_of_sequences <- parse_cli_arguments(args)
|
|
|
|
sim_repertoire <- generate_repertoires(number_of_sequences)
|
2021-02-26 02:19:40 +01:00
|
|
|
processed_data <- preprocess_data(sim_repertoire)
|
2021-02-26 02:20:11 +01:00
|
|
|
save_data(processed_data)
|