Save vdj alignment sequences to a CSV

This commit is contained in:
coolneng 2021-03-23 19:33:32 +01:00
parent 97b8914cd5
commit f6ad675cc4
Signed by: coolneng
GPG Key ID: 9893DA236405AF57
1 changed files with 14 additions and 12 deletions

View File

@ -19,21 +19,23 @@ amplify_rows <- function(data, column, factor) {
return(rep(data, factor)) return(rep(data, factor))
} }
save_data <- function(data, name) { save_data <- function(data) {
if (name == "sequence") { Biostrings::writeXStringSet(data$sequence, "data/sequence.fasta")
file_name <- paste("data/", name, ".fasta", sep = "") vdj_sequences <- data[-1]
Biostrings::writeXStringSet(data, file_name, format = "fasta") write.csv(vdj_sequences, "data/vdj_alignment.csv", row.names = FALSE)
} else {
file_name <- paste("data/", name, ".txt", sep = "")
cat(data, file = file_name, sep = "\n")
}
} }
process_data <- function(repertoire, sequencing_runs) { process_data <- function(repertoire, sequencing_runs) {
columns <- c("sequence", "v_call", "j_call") columns <- c(
"sequence", "v_sequence_alignment",
"d_sequence_alignment", "j_sequence_alignment"
)
data <- repertoire[, columns] data <- repertoire[, columns]
amplified_data <- mapply(data, names(data), sequencing_runs, FUN = amplify_rows) amplified_data <- mapply(data, names(data),
invisible(mapply(amplified_data, names(amplified_data), FUN = save_data)) sequencing_runs,
FUN = amplify_rows
)
save_data(amplified_data)
} }
parse_cli_arguments <- function(args) { parse_cli_arguments <- function(args) {
@ -48,4 +50,4 @@ arguments <- parse_cli_arguments(args)
number_of_sequences <- as.integer(arguments[1]) number_of_sequences <- as.integer(arguments[1])
sequencing_runs <- as.integer(arguments[2]) sequencing_runs <- as.integer(arguments[2])
repertoire <- generate_repertoire(number_of_sequences) repertoire <- generate_repertoire(number_of_sequences)
process_data(repertoire, sequencing_runs) process_data(repertoire, sequencing_runs)