@@ -215,6 +215,8 @@ download_OGRDB_germline_set <-
215215 vapply(query , .encode_OGRDB_URL_component , character (1 ))
216216}
217217
218+
219+ # ## No longer used. Superseded by download_OGRDB_germline_set() above.
218220# ## Retrieves:
219221# ## /germline/set/
220222# ## {species}/{set_name}/{release_version}/{format}
@@ -314,255 +316,3 @@ download_OGRDB_germline_set <-
314316 ans # named list
315317}
316318
317-
318- # ## - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
319- # ## download_germline_sequences_from_OGRDB()
320- # ##
321-
322- .infer_region_type_from_seqid <- function (seqid , locus )
323- {
324- stopifnot(is.character(seqid ), isSingleNonWhiteString(locus ),
325- all(has_prefix(seqid , locus )))
326- pos <- nchar(locus ) + 1L
327- region_type <- substr(seqid , pos , pos )
328- stopifnot(all(region_type %in% VDJ_REGION_TYPES ))
329- region_type
330- }
331-
332- .check_ungapped_seqs <- function (ungapped_seqs ,
333- species , species_subgroup = NULL , set_name ,
334- release_version = " published" ,
335- extended = FALSE )
336- {
337- format <- if (extended ) " airr_ex" else " airr"
338- parsed_json <- .fetch_germline_set_from_OGRDB(species ,
339- species_subgroup = species_subgroup ,
340- set_name = set_name ,
341- release_version = release_version ,
342- format = format )
343- stop(" paranoid.mode not ready yet" )
344- }
345-
346- # ## Downloads the germline sequences (ungapped) for the specified
347- # ## species/species_subgroup/set_name/release_version.
348- # ## Produces a subset of the following 7 FASTA files: IGHV.fasta,
349- # ## IGHD.fasta, IGHJ.fasta, IGKV.fasta, IGKJ.fasta, IGLV.fasta, and
350- # ## IGLJ.fasta. The exact subset produced depends on the species/set_name.
351- # ## Returns the number of files produced.
352- # ## NOTE: Superseded by download_OGRDB_germline_sequences()!
353- download_germline_sequences_from_OGRDB <-
354- function (species , species_subgroup = NULL , set_name ,
355- locus = c(" IGH" , " IGK" , " IGL" ),
356- release_version = " published" ,
357- extended = FALSE , destdir = " ." ,
358- paranoid.mode = FALSE )
359- {
360- stopifnot(isSingleNonWhiteString(release_version ),
361- isTRUEorFALSE(extended ),
362- isSingleNonWhiteString(destdir ),
363- isTRUEorFALSE(paranoid.mode ))
364- locus <- match.arg(locus )
365-
366- format <- if (extended ) " ungapped_ex" else " ungapped"
367- fasta_lines <- .fetch_germline_set_from_OGRDB(species ,
368- species_subgroup = species_subgroup ,
369- set_name = set_name ,
370- release_version = release_version ,
371- format = format )
372- filepath <- tempfile(fileext = " .fasta" )
373- writeLines(fasta_lines , filepath )
374- ungapped_seqs <- readDNAStringSet(filepath )
375- seq_region_types <- .infer_region_type_from_seqid(names(ungapped_seqs ),
376- locus )
377-
378- if (paranoid.mode )
379- .check_ungapped_seqs(ungapped_seqs ,
380- species , species_subgroup = species_subgroup ,
381- set_name = set_name ,
382- release_version = release_version ,
383- extended = extended )
384-
385- from <- paste0(" germline set " , set_name , " (" , species , " )" )
386- file_count <- 0L
387- for (region_type in VDJ_REGION_TYPES ) {
388- selected_seqs <- ungapped_seqs [seq_region_types == region_type ]
389- if (length(selected_seqs ) == 0L )
390- next
391- filename <- paste0(locus , region_type , " .fasta" )
392- destfile <- file.path(destdir , filename )
393- message(" Write " , length(selected_seqs ), " " , region_type , " regions " ,
394- " from " , from , " to " , filename , " ... " , appendLF = FALSE )
395- if (file.exists(destfile ))
396- stop(wmsg(filename , " file already exists in " , destdir , " /" ))
397- writeXStringSet(selected_seqs , destfile )
398- message(" ok" )
399- file_count <- file_count + 1L
400- }
401- file_count
402- }
403-
404-
405- # ## - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
406- # ## download_human_germline_sequences_from_OGRDB()
407- # ##
408-
409- # ## Downloads the germline sequences (ungapped) for all the Human germline
410- # ## sets. See list of Human germline sets here:
411- # ## https://ogrdb.airr-community.org/germline_sets/Homo%20sapiens
412- # ## Returns the number of files produced (should be 7).
413- # ##
414- # ## NOTE: No longer needed! Use download_OGRDB_germline_sequences() instead.
415- download_human_germline_sequences_from_OGRDB <-
416- function (release_version = " published" ,
417- extended = FALSE , destdir = " ." ,
418- paranoid.mode = FALSE )
419- {
420- stopifnot(isSingleNonWhiteString(release_version ),
421- isTRUEorFALSE(extended ),
422- isSingleNonWhiteString(destdir ),
423- isTRUEorFALSE(paranoid.mode ))
424-
425- # # Produces files: IGHV.fasta, IGHD.fasta, IGHJ.fasta
426- file_count <-
427- download_germline_sequences_from_OGRDB(" Human" ,
428- set_name = " IGH_VDJ" , locus = " IGH" ,
429- release_version = release_version , extended = extended ,
430- destdir = destdir , paranoid.mode = paranoid.mode )
431- # # Produces files: IGKV.fasta, IGKJ.fasta
432- file_count <- file_count +
433- download_germline_sequences_from_OGRDB(" Human" ,
434- set_name = " IGKappa_VJ" , locus = " IGK" ,
435- release_version = release_version , extended = extended ,
436- destdir = destdir , paranoid.mode = paranoid.mode )
437- # # Produces files: IGLV.fasta, IGLJ.fasta
438- file_count <- file_count +
439- download_germline_sequences_from_OGRDB(" Human" ,
440- set_name = " IGLambda_VJ" , locus = " IGL" ,
441- release_version = release_version , extended = extended ,
442- destdir = destdir , paranoid.mode = paranoid.mode )
443- file_count
444- }
445-
446-
447- # ## - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
448- # ## download_mouse_germline_sequences_from_OGRDB()
449- # ##
450-
451- # ## 'set_names' is expected to be a vector of Set Names from
452- # ## the Germline Sets table displayed at
453- # ## https://ogrdb.airr-community.org/germline_sets/Mus%20musculus
454- # ## except special Set Names "IGKJ (all strains)" and "IGLJ (all strains)".
455- # ## Assumes that all the Set Names in 'set_names' are of the
456- # ## form "<Species subgroup> <group>", where <group> is
457- # ## one of IGH, IGKV, an IGLV.
458- # ## Returns a 4-column matrix with colum names: set_name, species_subgroup,
459- # ## group, and locus.
460- .set_names_as_matrix <- function (set_names )
461- {
462- if (! is.character(set_names ) || anyNA(set_names ))
463- stop(wmsg(" 'set_names' must be a character vector with no NAs" ))
464- set_names <- trimws2(set_names )
465- if (anyDuplicated(set_names ))
466- stop(wmsg(" 'set_names' cannot contain duplicates" ))
467- FORBIDDEN_SET_NAMES <- c(" IGKJ (all strains)" , " IGLJ (all strains)" )
468- if (any(tolower(set_names ) %in% tolower(FORBIDDEN_SET_NAMES ))) {
469- in1string <- paste0(' "' , FORBIDDEN_SET_NAMES , ' "' , collapse = " or " )
470- stop(wmsg(" 'set_names' cannot contain " , in1string ))
471- }
472- split_set_names <- strsplit(set_names , split = " " , fixed = TRUE )
473- if (! all(lengths(split_set_names ) == 2L ))
474- stop(wmsg(" each Set Name in 'set_names' must contain exactly 1 space" ))
475- data <- unlist(split_set_names )
476- if (is.null(data ))
477- data <- character (0 )
478- m <- matrix (data , ncol = 2L , byrow = TRUE ,
479- dimnames = list (NULL , c(" species_subgroup" , " group" )))
480- loci <- substr(m [ , " group" ], 1L , 3L )
481- bad_idx <- which(! (loci %in% c(" IGH" , " IGK" , " IGL" )))
482- if (length(bad_idx ) != 0L ) {
483- in1string <- paste(set_names [bad_idx ], collapse = " , " )
484- stop(wmsg(" Bad Set Name(s): " , in1string , " ." ),
485- " \n " ,
486- wmsg(" The first 3 letters of the 2nd part of the name " ,
487- " is not a valid locus name." ))
488- }
489- set_name <- matrix (set_names , dimnames = list (NULL , " set_name" ))
490- locus <- matrix (loci , dimnames = list (NULL , " locus" ))
491- ans <- cbind(set_name , m , locus )
492- species_subgroup <- unique(ans [ , " species_subgroup" ])
493- if (length(species_subgroup ) > 1L )
494- warning(wmsg(" the supplied Set Names are from " ,
495- " more than one Species subgroup" ))
496- ans
497- }
498-
499- # ## Downloads the germline sequences (ungapped) for the specified Mouse
500- # ## germline sets. See list of Mouse germline sets here:
501- # ## https://ogrdb.airr-community.org/germline_sets/Mus%20musculus
502- # ## Returns the number of files produced (will be typically between 4 and 7).
503- # ##
504- # ## To download all the germline sequences for Mouse strain A/J:
505- # ##
506- # ## set_names <- c("A/J IGKV", "A/J IGLV")
507- # ## download_mouse_germline_sequences_from_OGRDB(set_names)
508- # ##
509- # ## --> produces 4 FASTA files (partial germline db).
510- # ##
511- # ## To download all the germline sequences for Mouse strain C57BL/6:
512- # ##
513- # ## download_mouse_germline_sequences_from_OGRDB("C57BL/6 IGH")
514- # ##
515- # ## --> produces 5 FASTA files (partial germline db).
516- # ##
517- # ## To download all the germline sequences for Mouse strain C57BL/6J:
518- # ##
519- # ## set_names <- c("C57BL/6J IGKV", "C57BL/6J IGLV")
520- # ## download_mouse_germline_sequences_from_OGRDB(set_names)
521- # ##
522- # ## --> produces 4 FASTA files (partial germline db).
523- # ##
524- # ## To download all the germline sequences for Mouse strain CAST/EiJ:
525- # ##
526- # ## set_names <- c("CAST/EiJ IGH", "CAST/EiJ IGKV", "CAST/EiJ IGLV")
527- # ## download_mouse_germline_sequences_from_OGRDB(set_names)
528- # ##
529- # ## --> produces 7 FASTA files (full germline db).
530- # ##
531- # ## NOTE: No longer needed! Use download_OGRDB_germline_sequences() instead.
532- download_mouse_germline_sequences_from_OGRDB <-
533- function (set_names ,
534- release_version = " published" ,
535- extended = FALSE , destdir = " ." ,
536- paranoid.mode = FALSE )
537- {
538- stopifnot(isSingleNonWhiteString(release_version ),
539- isTRUEorFALSE(extended ),
540- isSingleNonWhiteString(destdir ),
541- isTRUEorFALSE(paranoid.mode ))
542-
543- m <- .set_names_as_matrix(set_names )
544- set_names <- m [ , " set_name" ]
545- species_subgroups <- m [ , " species_subgroup" ]
546- loci <- m [ , " locus" ]
547- file_count <- 0L
548- for (i in seq_len(nrow(m ))) {
549- file_count <- file_count +
550- download_germline_sequences_from_OGRDB(" Mouse" ,
551- species_subgroup = species_subgroups [[i ]],
552- set_name = set_names [[i ]], locus = loci [[i ]],
553- release_version = release_version , extended = extended ,
554- destdir = destdir , paranoid.mode = paranoid.mode )
555- }
556- file_count <- file_count +
557- download_germline_sequences_from_OGRDB(" Mouse" ,
558- set_name = " IGKJ (all strains)" , locus = " IGK" ,
559- release_version = release_version , extended = extended ,
560- destdir = destdir , paranoid.mode = paranoid.mode )
561- file_count <- file_count +
562- download_germline_sequences_from_OGRDB(" Mouse" ,
563- set_name = " IGLJ (all strains)" , locus = " IGL" ,
564- release_version = release_version , extended = extended ,
565- destdir = destdir , paranoid.mode = paranoid.mode )
566- file_count
567- }
568-
0 commit comments