Compare commits
No commits in common. "e5a7b726a95e3c70cb3b4517494c196c547df66d" and "f81e4af94e04cdbc572a19ce9f8ef16bd3db4722" have entirely different histories.
e5a7b726a9
...
f81e4af94e
Binary file not shown.
Binary file not shown.
|
@ -1,14 +1,14 @@
|
||||||
library(Biostrings)
|
library(Biostrings)
|
||||||
library(parallel)
|
library(parallel)
|
||||||
|
|
||||||
construct_hvr_sequence <- function(data) {
|
construct_dataframe <- function(data) {
|
||||||
vdj_dataframe <- as.data.frame(data)
|
vdj_string_set <- lapply(data, FUN = Biostrings::DNAStringSet)
|
||||||
hvr_sequence <- paste(vdj_dataframe$v_sequence,
|
vdj_dataframe <- as.data.frame(vdj_string_set)
|
||||||
|
vdj_dataframe$hvr_region <- paste(vdj_dataframe$v_sequence,
|
||||||
vdj_dataframe$d_sequence,
|
vdj_dataframe$d_sequence,
|
||||||
vdj_dataframe$j_sequence,
|
vdj_dataframe$j_sequence,
|
||||||
sep = ""
|
sep = ""
|
||||||
)
|
)
|
||||||
vdj_dataframe$hvr <- hvr_sequence
|
|
||||||
return(vdj_dataframe)
|
return(vdj_dataframe)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,33 +16,8 @@ parse_data <- function(files) {
|
||||||
reversed_sequences <- Biostrings::readQualityScaledDNAStringSet(files[1])
|
reversed_sequences <- Biostrings::readQualityScaledDNAStringSet(files[1])
|
||||||
sequences <- Biostrings::reverseComplement(reversed_sequences)
|
sequences <- Biostrings::reverseComplement(reversed_sequences)
|
||||||
vdj_alignment <- read.csv(files[2])
|
vdj_alignment <- read.csv(files[2])
|
||||||
vdj_dataframe <- construct_hvr_sequence(vdj_alignment)
|
vdj_dataframe <- construct_dataframe(vdj_alignment)
|
||||||
vj_segments <- union(
|
return(list(sequences, vdj_dataframe))
|
||||||
readRDS("data/v_segments.rds"),
|
|
||||||
readRDS("data/j_segments_phe.rds")
|
|
||||||
)
|
|
||||||
return(list(sequences, vj_segments, vdj_dataframe))
|
|
||||||
}
|
|
||||||
|
|
||||||
# TODO Test if grep can return more than one match
|
|
||||||
get_vj_sequence <- function(identifier, names, sequences) {
|
|
||||||
row <- grep(names, pattern = identifier)
|
|
||||||
return(as.character(sequences[row]))
|
|
||||||
}
|
|
||||||
|
|
||||||
construct_full_sequences <- function(vdj_segments, metadata) {
|
|
||||||
v_sequences <- lapply(metadata$v_call,
|
|
||||||
names(vdj_segments),
|
|
||||||
vdj_segments,
|
|
||||||
FUN = get_vj_sequence
|
|
||||||
)
|
|
||||||
j_sequences <- lapply(metadata$j_call,
|
|
||||||
names(vdj_segments),
|
|
||||||
vdj_segments,
|
|
||||||
FUN = get_vj_sequence
|
|
||||||
)
|
|
||||||
full_sequence <- paste(v_sequences, metadata$hvr, j_sequences, sep = "")
|
|
||||||
return(Biostrings::DNAStringSet(full_sequence))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
align_sequence <- function(sequence, vdj_segment) {
|
align_sequence <- function(sequence, vdj_segment) {
|
||||||
|
@ -50,25 +25,20 @@ align_sequence <- function(sequence, vdj_segment) {
|
||||||
pattern = sequence,
|
pattern = sequence,
|
||||||
subject = vdj_segment,
|
subject = vdj_segment,
|
||||||
type = "global-local",
|
type = "global-local",
|
||||||
gapOpening = 1,
|
gapOpening = 1
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
perform_alignment <- function(sequences, vdj_segments, metadata) {
|
perform_alignment <- function(sequences, vdj_segments) {
|
||||||
vj_sequences <- construct_full_sequences(vdj_segments, metadata)
|
sequence_alignment <- mcmapply(sequences,
|
||||||
sequence_alignment <- mcmapply(vj_sequences,
|
vdj_segments$hvr_region,
|
||||||
vdj_segments,
|
|
||||||
FUN = align_sequence,
|
FUN = align_sequence,
|
||||||
mc.cores = detectCores()
|
mc.cores = 4
|
||||||
)
|
)
|
||||||
return(sequence_alignment)
|
return(sequence_alignment)
|
||||||
}
|
}
|
||||||
|
|
||||||
input_files <- c("data/curesim_sequence.fastq", "data/vdj_alignment.csv")
|
input_files <- c("data/curesim_sequence.fastq", "data/vdj_alignment.csv")
|
||||||
data <- parse_data(input_files)
|
data <- parse_data(input_files)
|
||||||
alignment <- perform_alignment(
|
alignment <- perform_alignment(sequences = data[[1]], vdj_segments = data[[2]])
|
||||||
sequences = data[[1]],
|
|
||||||
vdj_segments = data[[2]],
|
|
||||||
metadata = data[[3]]
|
|
||||||
)
|
|
||||||
print(alignment)
|
print(alignment)
|
|
@ -20,8 +20,7 @@ save_data <- function(data, reads) {
|
||||||
process_data <- function(repertoire, reads) {
|
process_data <- function(repertoire, reads) {
|
||||||
columns <- c(
|
columns <- c(
|
||||||
"sequence", "v_sequence_alignment",
|
"sequence", "v_sequence_alignment",
|
||||||
"d_sequence_alignment", "j_sequence_alignment",
|
"d_sequence_alignment", "j_sequence_alignment"
|
||||||
"v_call", "j_call"
|
|
||||||
)
|
)
|
||||||
data <- repertoire[, columns]
|
data <- repertoire[, columns]
|
||||||
dna_sequence <- Biostrings::DNAStringSet(data$sequence)
|
dna_sequence <- Biostrings::DNAStringSet(data$sequence)
|
||||||
|
|
Loading…
Reference in New Issue