66# ##
77
88
9+ .read_version_file <- function (dirpath )
10+ {
11+ stopifnot(isSingleNonWhiteString(dirpath ))
12+ version_path <- file.path(dirpath , " version" )
13+ if (! file.exists(version_path ))
14+ stop(wmsg(" missing 'version' file in " , dirpath , " /" ))
15+ version <- readLines(version_path )
16+ if (length(version ) != 1L )
17+ stop(wmsg(" file '" , version_path , " ' should contain exactly one line" ))
18+ version <- trimws2(version )
19+ if (version == " " )
20+ stop(wmsg(" file '" , version_path , " ' contains only white spaces" ))
21+ version
22+ }
23+
24+
925# ## - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1026# ## .create_missing_builtin_AIRR_human_germline_dbs()
1127# ##
1228
1329.form_builtin_AIRR_human_germline_db_name <- function (fasta_dir )
1430{
15- loci <- get_loci_from_input_germline_fasta_set(fasta_dir )
31+ loci_in1string <- paste(IG_LOCI , collapse = " +" )
32+ version <- basename(dirname(fasta_dir ))
33+ db_name <- sprintf(" _AIRR.human.%s.%s" , loci_in1string , version )
1634 flavor <- basename(fasta_dir )
1735 stopifnot(flavor %in% c(" ref" , " src" ))
18- version <- basename(dirname(fasta_dir ))
19- db_name <- sprintf(" _AIRR.human.%s.%s" , paste(loci , collapse = " +" ), version )
2036 if (flavor == " src" )
2137 db_name <- paste0(db_name , " .src" )
2238 db_name
3046 db_name <- .form_builtin_AIRR_human_germline_db_name(fasta_dir )
3147 db_path <- file.path(destdir , db_name )
3248 if (! (only.if.missing && dir.exists(db_path )))
33- create_germline_db(fasta_dir , db_path )
49+ create_germline_db(fasta_dir , IG_LOCI , db_path )
3450}
3551
3652.create_missing_builtin_AIRR_human_germline_dbs <- function (human_dir , destdir )
3753{
3854 stopifnot(isSingleNonWhiteString(human_dir ), dir.exists(human_dir ))
3955 human_subdirs <- list.dirs(human_dir , recursive = FALSE )
4056 fasta_dirs <- file.path(rep(human_subdirs , each = 2L ), c(" ref" , " src" ))
41- for (fasta_dir in fasta_dirs ) {
57+ for (fasta_dir in fasta_dirs )
4258 .create_builtin_AIRR_human_germline_db(fasta_dir , destdir ,
4359 only.if.missing = TRUE )
44- }
4560}
4661
4762
5166
5267.form_builtin_AIRR_mouse_germline_db_name <- function (fasta_dir )
5368{
54- loci <- get_loci_from_input_germline_fasta_set(fasta_dir )
5569 strain <- basename(fasta_dir )
56- version <- read_version_file(fasta_dir )
57- sprintf(" _AIRR.mouse.%s.%s.%s" , strain , paste(loci , collapse = " +" ), version )
70+ loci_in1string <- paste(IG_LOCI , collapse = " +" )
71+ version <- .read_version_file(fasta_dir )
72+ sprintf(" _AIRR.mouse.%s.%s.%s" , strain , loci_in1string , version )
5873}
5974
6075.create_builtin_AIRR_mouse_germline_db <- function (fasta_dir , destdir ,
6580 db_name <- .form_builtin_AIRR_mouse_germline_db_name(fasta_dir )
6681 db_path <- file.path(destdir , db_name )
6782 if (! (only.if.missing && dir.exists(db_path )))
68- create_germline_db(fasta_dir , db_path )
83+ create_germline_db(fasta_dir , IG_LOCI , db_path )
6984}
7085
7186.create_missing_builtin_AIRR_mouse_germline_dbs <- function (mouse_dir , destdir )
7287{
7388 fasta_dirs <- list.dirs(mouse_dir , recursive = FALSE )
74- for (fasta_dir in fasta_dirs ) {
89+ for (fasta_dir in fasta_dirs )
7590 .create_builtin_AIRR_mouse_germline_db(fasta_dir , destdir ,
7691 only.if.missing = TRUE )
77- }
7892}
7993
8094
@@ -119,7 +133,7 @@ create_all_builtin_germline_dbs <- function(destdir)
119133
120134 create_missing_builtin_germline_dbs(tmp_destdir )
121135
122- # # Everyting went fine so we can rename 'tmp_destdir' to 'destdir'.
136+ # # Everything went fine so we can rename 'tmp_destdir' to 'destdir'.
123137 rename_file(tmp_destdir , destdir )
124138}
125139
@@ -128,23 +142,21 @@ create_all_builtin_germline_dbs <- function(destdir)
128142# ## .create_builtin_IMGT_c_region_db()
129143# ##
130144
131- .form_builtin_IMGT_c_region_db_name <- function (organism , fasta_dir ,
132- tcr.db = FALSE )
145+ .form_builtin_IMGT_c_region_db_name <- function (organism , loci , version )
133146{
134147 stopifnot(isSingleNonWhiteString(organism ))
135- loci <- get_loci_from_input_c_region_fasta_set(fasta_dir , tcr.db = tcr.db )
136- version <- read_version_file(fasta_dir )
137148 sprintf(" _IMGT.%s.%s.%s" , organism , paste(loci , collapse = " +" ), version )
138149}
139150
140- .create_builtin_IMGT_c_region_db <- function (fasta_dir , organism , destdir ,
141- tcr.db = FALSE )
151+ .create_builtin_IMGT_c_region_db <- function (fasta_dir , loci_prefix ,
152+ organism , destdir )
142153{
143154 stopifnot(isSingleNonWhiteString(destdir ), dir.exists(destdir ))
144- db_name <- .form_builtin_IMGT_c_region_db_name(organism , fasta_dir ,
145- tcr.db = tcr.db )
155+ loci <- list_loci_in_c_region_fasta_dir(fasta_dir , loci_prefix )
156+ version <- .read_version_file(fasta_dir )
157+ db_name <- .form_builtin_IMGT_c_region_db_name(organism , loci , version )
146158 db_path <- file.path(destdir , db_name )
147- create_c_region_db(fasta_dir , db_path , tcr.db = tcr.db )
159+ create_c_region_db(fasta_dir , loci , db_path )
148160}
149161
150162
@@ -170,16 +182,17 @@ create_all_builtin_c_region_dbs <- function(destdir)
170182 for (organism in names(LATIN_NAMES )) {
171183 organism_dir <- file.path(IMGT_c_region_dir , organism )
172184 fasta_dir <- file.path(organism_dir , " IG" , " 14.1" )
173- .create_builtin_IMGT_c_region_db(fasta_dir , organism , tmp_destdir )
185+ .create_builtin_IMGT_c_region_db(fasta_dir , " IG" , organism ,
186+ tmp_destdir )
174187 fasta_dir <- file.path(organism_dir , " TR" )
175188 if (dir.exists(fasta_dir ))
176- .create_builtin_IMGT_c_region_db(fasta_dir , organism , tmp_destdir ,
177- tcr.db = TRUE )
189+ .create_builtin_IMGT_c_region_db(fasta_dir , " TR " , organism ,
190+ tmp_destdir )
178191 }
179192
180193 # # Any other built-in C-region dbs to create?
181194
182- # # Everyting went fine so we can rename 'tmp_destdir' to 'destdir'.
195+ # # Everything went fine so we can rename 'tmp_destdir' to 'destdir'.
183196 rename_file(tmp_destdir , destdir , replace = TRUE )
184197}
185198
0 commit comments