Skip to content

Commit a37477c

Browse files
committed
fix unit tests
1 parent e73fbd0 commit a37477c

3 files changed

Lines changed: 56 additions & 18 deletions

File tree

‎R/compute_V_gene_delineations.R‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -224,14 +224,8 @@ compute_V_gene_delineations <- function(gapped_V_alleles, as.IRangesList=FALSE)
224224

225225
names(gapped_V_alleles) <- clean_imgt_fasta_header_lines(allele_names, what)
226226

227-
## How many nucleotides sequences are missing on their 3' end
228-
## in order to have a complete FWR3.
229-
fwrcdr_max_nucs <- .IMGT_FWRCDR_MAX_LENGTHS * 3L
230-
fwr3_trimmed <- sum(fwrcdr_max_nucs) - width(gapped_V_alleles)
231-
fwr3_trimmed[fwr3_trimmed < 0L] <- 0L
232-
233227
## IMGT FWR/CDR fixed intervals in nucleotide space.
234-
imgt_bins <- PartitioningByWidth(fwrcdr_max_nucs)
228+
imgt_bins <- PartitioningByWidth(.IMGT_FWRCDR_MAX_LENGTHS * 3L)
235229
midx <- vmatchPattern(GAP_LETTER, gapped_V_alleles)
236230

237231
## Note that lengths() should propagate the names by default but it
@@ -242,6 +236,7 @@ compute_V_gene_delineations <- function(gapped_V_alleles, as.IRangesList=FALSE)
242236
## add the names to that if 'use.names' is TRUE.
243237
ngaps <- setNames(lengths(midx), names(midx))
244238
warn_if_allele_sequences_have_no_gaps(ngaps)
239+
seq_len <- width(gapped_V_alleles) - ngaps # lengths of ungapped sequences
245240

246241
all_real_lens <- lapply(midx, .compute_fwrcdr_real_lengths, imgt_bins)
247242
tmp <- lapply(all_real_lens, PartitioningByWidth)
@@ -253,7 +248,7 @@ compute_V_gene_delineations <- function(gapped_V_alleles, as.IRangesList=FALSE)
253248
all_gaps_contained <-
254249
vapply(all_real_lens, attr, logical(1), "all_gaps_contained")
255250
coding_frame_start <- 2L - (starting_gap + 2L) %% 3L
256-
mcols(IRL) <- DataFrame(fwr3_trimmed=fwr3_trimmed,
251+
mcols(IRL) <- DataFrame(seq_len=seq_len,
257252
coding_frame_start=coding_frame_start,
258253
starting_gap=starting_gap,
259254
all_gaps_in_frame=all_gaps_in_frame,

‎man/compute_V_gene_delineations.Rd‎

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ compute_V_gene_delineations(gapped_V_alleles, as.IRangesList=FALSE)
4646
\item The data.frame returned by \code{compute_V_gene_delineations()} has
4747
the following additional columns:
4848
\enumerate{
49-
\item \code{fwr3_trimmed}: how many nucleotides a sequence is
50-
missing on its 3' end in order to have a complete FWR3;
49+
\item \code{seq_len}: length of the sequence after removal of
50+
the gaps;
5151
\item \code{starting_gap}: size (in number of nucleotides) of
5252
gap block located at the very beginning of the sequence
5353
if any (0 if no such block);
@@ -82,10 +82,10 @@ compute_V_gene_delineations(gapped_V_alleles, as.IRangesList=FALSE)
8282
8383
\examples{
8484
## ---------------------------------------------------------------------
85-
## BASIC USAGE
85+
## 1. USING HUMAN GERMLINE V GENE ALLELE SEQUENCES FROM OGRDB
8686
## ---------------------------------------------------------------------
8787
## Visit https://ogrdb.airr-community.org/germline_sets/Homo%20sapiens
88-
## for the list of germline sets available for human at OGRDB.
88+
## for the list of human germline sets available at OGRDB.
8989
9090
## Download OGRDB germline gene allele sequences for human locus IGK
9191
## to a temporary directory:
@@ -106,9 +106,6 @@ as.character(IGKV_alleles[1:3])
106106
IGKV_gene_delinea <- compute_V_gene_delineations(IGKV_alleles)
107107
head(IGKV_gene_delinea)
108108
109-
## ---------------------------------------------------------------------
110-
## COMPARE WITH V GENE DELINEATIONS PROVIDED BY AIRR-C JSON FILE
111-
## ---------------------------------------------------------------------
112109
## As a sanity check, we're going to compare 'IGKV_gene_delinea' with
113110
## the V gene delineations provided by the corresponding AIRR-C JSON
114111
## file from OGRDB.
@@ -134,6 +131,51 @@ IGKV_gene_delinea2 <- IGKV_gene_delinea2[ , shared_colnames]
134131
## order):
135132
stopifnot(same_ndm_data(IGKV_gene_delinea, IGKV_gene_delinea2))
136133

134+
## Remove temporary directory:
135+
unlink(destdir, recursive=TRUE)
136+
137+
## ---------------------------------------------------------------------
138+
## 2. USING MOUSE GERMLINE V GENE ALLELE SEQUENCES FROM OGRDB
139+
## ---------------------------------------------------------------------
140+
## Visit https://ogrdb.airr-community.org/germline_sets/Mus%20musculus
141+
## for the list of mouse germline sets available at OGRDB.
142+
143+
## Download OGRDB germline V gene allele sequences for locus IGL of
144+
## mouse strain MSM/MsJ to a temporary directory:
145+
germline_set <- c(`MSM/MsJ IGLV`=1)
146+
147+
dir.create(destdir <- tempfile())
148+
download_OGRDB_germline_sequences("Mus musculus", germline_set,
149+
destdir=destdir)
150+
151+
## List the downloaded files:
152+
list.files(destdir) # 1 FASTA file
153+
154+
## Compute the V gene delineations for 'IGKV_alleles':
155+
IGLV_alleles <- file.path(destdir, "IGLV.fasta")
156+
IGLV_gene_delinea <- compute_V_gene_delineations(IGLV_alleles)
157+
IGLV_gene_delinea
158+
159+
## Note that for the first two alleles, the length of the **ungapped**
160+
## sequence (seq_len) is smaller than the FWR3 end position (fwr3_end):
161+
IGLV_gene_delinea[ , c("fwr3_end", "seq_len")]
162+
163+
## In other words, the sequences of alleles IGLV0-37NY*00 and
164+
## IGLV0-COOR*00 end before the end of their FWR3.
165+
166+
## This is reflected in the V gene delineations provided by the
167+
## corresponding AIRR-C JSON file from OGRDB:
168+
download_OGRDB_germline_json("Mus musculus", germline_set,
169+
destdir=destdir)
170+
list.files(destdir)
171+
ogrdb_json_file <- file.path(destdir, "IGLV.json")
172+
IGLV_gene_delinea2 <- makeogrannote(ogrdb_json_file)
173+
IGLV_gene_delinea2
174+
175+
## As you can see, when a V allele sequence ends before the end of
176+
## its FWR3, the FWR3 end position reported in the AIRR-C JSON file
177+
## is the position of the last nucleotide in the (ungapped) sequence.
178+
137179
## Remove temporary directory:
138180
unlink(destdir, recursive=TRUE)
139181
}

‎tests/testthat/test-clean_allele_set.R‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ test_that(".drop_repeated_alleles()", {
2626
expect_true(is(object_mcols, "DataFrame"))
2727
expected_colnames <- c(
2828
"locus",
29-
setdiff(names(igblastr:::NDM_COL2CLASS), "chain_type"),
30-
"starting_gap", "all_gaps_in_frame", "all_gaps_contained",
31-
"chain_type"
29+
setdiff(names(igblastr:::NDM_COL2CLASS),
30+
c("chain_type", "coding_frame_start")),
31+
"seq_len", "coding_frame_start", "starting_gap",
32+
"all_gaps_in_frame", "all_gaps_contained", "chain_type"
3233
)
3334
expect_identical(colnames(object_mcols), expected_colnames)
3435
expect_identical(object_mcols[ , "allele_name"], names(object))

0 commit comments

Comments
 (0)