From a7c1df5ce27a5492d3d7150f53b27131432feec6 Mon Sep 17 00:00:00 2001 From: coolneng Date: Thu, 22 Apr 2021 01:17:35 +0200 Subject: [PATCH] Refactor get_vj_sequence function --- src/alignment.r | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/alignment.r b/src/alignment.r index 63b161a..3b0aab9 100644 --- a/src/alignment.r +++ b/src/alignment.r @@ -11,6 +11,13 @@ parse_data <- function(file) { return(list(sequences, vj_segments)) } +parse_metadata <- function(metadata) { + id_elements <- unlist(strsplit(metadata, split = " ")) + v_identifier <- id_elements[2] + j_identifier <- id_elements[3] + return(list(v_id = v_identifier, j_id = j_identifier)) +} + match_id_sequence <- function(names, vdj_segments, id) { matches <- grep(names, pattern = id) row <- matches[1] @@ -18,12 +25,10 @@ match_id_sequence <- function(names, vdj_segments, id) { } get_vj_sequence <- function(metadata, names, vdj_segments) { - id_elements <- unlist(strsplit(metadata, split = " ")) - v_identifier <- id_elements[2] - j_identifier <- id_elements[3] - v_sequence <- match_id_sequence(names, vdj_segments, id = v_identifier) - j_sequence <- match_id_sequence(names, vdj_segments, id = j_identifier) - return(c(v_sequence, j_sequence)) + identifiers <- parse_metadata(metadata) + v_sequence <- match_id_sequence(names, vdj_segments, id = identifiers["v_id"]) + j_sequence <- match_id_sequence(names, vdj_segments, id = identifiers["j_id"]) + return(list(v_seq = v_sequence, j_seq = j_sequence)) } fetch_vj_sequences <- function(sequences, vdj_segments) {