annonars 0.41.0

Rust template repository
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
use annonars::{
    clinvar_genes, clinvar_minimal, clinvar_sv, common, cons, db_utils, dbsnp, freqs, functional,
    genes, gnomad_mtdna, gnomad_nuclear, gnomad_sv, helixmtdb, regions, server, tsv,
};
use anyhow::Error;
use clap::{command, Args, Parser, Subcommand};

/// CLI parser based on clap.
#[derive(Debug, Clone, Parser)]
#[command(
    author,
    version,
    about = "RocksDB-based genome annotations",
    long_about = "Genome annotation stored in RocksDB."
)]
struct Cli {
    /// Commonly used arguments
    #[command(flatten)]
    common: common::cli::Args,

    /// The sub command to run
    #[command(subcommand)]
    command: Commands,
}

/// Enum supporting the parsing of top-level commands.
#[derive(Debug, Subcommand, Clone)]
enum Commands {
    /// "genes" sub commands
    Gene(Gene),
    /// "tsv" sub commands
    Tsv(Tsv),
    /// "cons" sub commands
    Cons(Cons),
    /// "clinvar-genes" sub commands
    ClinvarGenes(ClinvarGenes),
    /// "clinvar-minimal" sub commands
    ClinvarMinimal(ClinvarMinimal),
    /// "clinvar-sv" sub commands
    ClinvarSv(ClinvarSv),
    /// "freqs" sub commands
    Freqs(Freqs),
    /// "functional" sub commands
    Functional(Functional),
    /// "dbsnp" sub commands
    Dbsnp(Dbsnp),
    /// "helixmtdb" sub commands
    Helixmtdb(Helixmtdb),
    /// "gnomad-mtdna" sub commands
    GnomadMtdna(GnomadMtdna),
    /// "gnomad-nuclear" sub commands
    GnomadNuclear(GnomadNuclear),
    /// "gnomad-sv" sub commands
    GnomadSv(GnomadSv),
    /// "regions" sub commands
    Regions(Regions),
    /// "db-utils" sub commands
    DbUtils(DbUtils),
    /// "server" sub command.
    Server(Server),
}

/// Parsing of "gene" subcommand
#[derive(Debug, Args, Clone)]
struct Gene {
    /// The sub command to run
    #[command(subcommand)]
    command: GeneCommands,
}

/// Enum supporting the parsing of "gene *" subcommands.
#[derive(Debug, Subcommand, Clone)]
enum GeneCommands {
    /// "import" sub command
    Import(Box<genes::cli::import::Args>),
    /// "query" sub command
    Query(Box<genes::cli::query::Args>),
}

/// Parsing of "tsv" subcommand
#[derive(Debug, Args, Clone)]
struct Tsv {
    /// The sub command to run
    #[command(subcommand)]
    command: TsvCommands,
}

/// Enum supporting the parsing of "tsv *" subcommands.
#[derive(Debug, Subcommand, Clone)]
enum TsvCommands {
    /// "import" sub command
    Import(tsv::cli::import::Args),
    /// "query" sub command
    Query(tsv::cli::query::Args),
}

/// Parsing of "clinvar-minimal" subcommand.
#[derive(Debug, Args, Clone)]
struct ClinvarGenes {
    /// The sub command to run
    #[command(subcommand)]
    command: ClinvarGeneCommands,
}

/// Enum supporting the parsing of "clinvar-gene *" subcommands.
#[derive(Debug, Subcommand, Clone)]
enum ClinvarGeneCommands {
    /// "import" sub command
    Import(clinvar_genes::cli::import::Args),
    /// "query" sub command
    Query(clinvar_genes::cli::query::Args),
}

/// Parsing of "clinvar-minimal" subcommand.
#[derive(Debug, Args, Clone)]
struct ClinvarMinimal {
    /// The sub command to run
    #[command(subcommand)]
    command: ClinvarMinimalCommands,
}

/// Enum supporting the parsing of "clinvar-minimal *" subcommands.
#[derive(Debug, Subcommand, Clone)]
enum ClinvarMinimalCommands {
    /// "import" sub command
    Import(clinvar_minimal::cli::import::Args),
    /// "query" sub command
    Query(clinvar_minimal::cli::query::Args),
}

/// Parsing of "clinvar-sv" subcommand.
#[derive(Debug, Args, Clone)]
struct ClinvarSv {
    /// The sub command to run
    #[command(subcommand)]
    command: ClinvarSvCommands,
}

/// Enum supporting the parsing of "clinvar-sv *" subcommands.
#[derive(Debug, Subcommand, Clone)]
enum ClinvarSvCommands {
    /// "import" sub command
    Import(clinvar_sv::cli::import::Args),
    /// "query" sub command
    Query(clinvar_sv::cli::query::Args),
}

/// Parsing of "cons" subcommand.
#[derive(Debug, Args, Clone)]
struct Cons {
    /// The sub command to run
    #[command(subcommand)]
    command: ConsCommands,
}

/// Enum supporting the parsing of "dbsnp *" subcommands.
#[derive(Debug, Subcommand, Clone)]
enum ConsCommands {
    /// "import" sub command
    Import(cons::cli::import::Args),
    /// "query" sub command
    Query(cons::cli::query::Args),
}

/// Parsing of "dbsnp" subcommands.
#[derive(Debug, Args, Clone)]
struct Dbsnp {
    /// The sub command to run
    #[command(subcommand)]
    command: DbsnpCommands,
}

/// Enum supporting the parsing of "dbsnp *" subcommands.
#[derive(Debug, Subcommand, Clone)]
enum DbsnpCommands {
    /// "import" sub command
    Import(dbsnp::cli::import::Args),
    /// "query" sub command
    Query(dbsnp::cli::query::Args),
}

/// Parsing of "freqs" subcommands.
#[derive(Debug, Args, Clone)]
struct Freqs {
    /// The sub command to run
    #[command(subcommand)]
    command: FreqsCommands,
}

/// Enum supporting the parsing of "freqs *" subcommands.
#[derive(Debug, Subcommand, Clone)]
enum FreqsCommands {
    /// "import" sub command
    Import(freqs::cli::import::Args),
    /// "query" sub command
    Query(freqs::cli::query::Args),
}

/// Parsing of "functional" subcommands.
#[derive(Debug, Args, Clone)]
struct Functional {
    /// The sub command to run
    #[command(subcommand)]
    command: FunctionalCommands,
}

/// Enum supporting the parsing of "functional *" subcommands.
#[derive(Debug, Subcommand, Clone)]
enum FunctionalCommands {
    /// "import" sub command
    Import(functional::cli::import::Args),
    /// "query" sub command
    Query(functional::cli::query::Args),
}

/// Parsing of "helixmtdb" subcommands.
#[derive(Debug, Args, Clone)]
struct Helixmtdb {
    /// The sub command to run
    #[command(subcommand)]
    command: HelixmtdbCommands,
}

/// Enum supporting the parsing of "helixmtdb *" subcommands.
#[derive(Debug, Subcommand, Clone)]
enum HelixmtdbCommands {
    /// "import" sub command
    Import(helixmtdb::cli::import::Args),
    /// "query" sub command
    Query(helixmtdb::cli::query::Args),
}

/// Parsing of "gnomad-mtdna" subcommands.
#[derive(Debug, Args, Clone)]
struct GnomadMtdna {
    /// The sub command to run
    #[command(subcommand)]
    command: GnomadMtdnaCommands,
}

/// Enum supporting the parsing of "gnomad-mtdna *" subcommands.
#[derive(Debug, Subcommand, Clone)]
enum GnomadMtdnaCommands {
    /// "import" sub command
    Import(gnomad_mtdna::cli::import::Args),
    /// "query" sub command
    Query(gnomad_mtdna::cli::query::Args),
}

/// Parsing of "gnomad-nuclear" subcommands.
#[derive(Debug, Args, Clone)]
struct GnomadNuclear {
    /// The sub command to run
    #[command(subcommand)]
    command: GnomadNuclearCommands,
}

/// Enum supporting the parsing of "gnomad-nuclear *" subcommands.
#[derive(Debug, Subcommand, Clone)]
enum GnomadNuclearCommands {
    /// "import" sub command
    Import(gnomad_nuclear::cli::import::Args),
    /// "query" sub command
    Query(gnomad_nuclear::cli::query::Args),
}

/// Parsing of "gnomad-sv" subcommands.
#[derive(Debug, Args, Clone)]
struct GnomadSv {
    /// The sub command to run
    #[command(subcommand)]
    command: GnomadSvCommands,
}

/// Enum supporting the parsing of "gnomad-sv *" subcommands.
#[derive(Debug, Subcommand, Clone)]
enum GnomadSvCommands {
    /// "import" sub command
    Import(gnomad_sv::cli::import::Args),
    /// "query" sub command
    Query(gnomad_sv::cli::query::Args),
}

/// Parsing of "regions" subcommands.
#[derive(Debug, Args, Clone)]
struct Regions {
    /// The sub command to run
    #[command(subcommand)]
    command: RegionsCommands,
}

/// Enum supporting the parsing of "regions *" subcommands.
#[derive(Debug, Subcommand, Clone)]
enum RegionsCommands {
    /// "import" sub command
    Import(regions::cli::import::Args),
    /// "query" sub command
    Query(regions::cli::query::Args),
}

/// Parsing of "db-utils" subcommands.
#[derive(Debug, Args, Clone)]
struct DbUtils {
    /// The sub command to run
    #[command(subcommand)]
    command: DbUtilsCommands,
}

/// Enum supporting the parsing of "db-utils *" subcommands.
#[derive(Debug, Subcommand, Clone)]
enum DbUtilsCommands {
    /// "copy" sub command
    Copy(db_utils::cli::copy::Args),
    /// "dump-meta" sub command
    DumpMeta(db_utils::cli::dump_meta::Args),
}

/// Parsing of "server" subcommands.
#[derive(Debug, Args, Clone)]
struct Server {
    /// The sub command to run.
    #[command(subcommand)]
    command: ServerCommands,
}

/// Enum supporting the parsing of "server *" subcommands.
#[derive(Debug, Subcommand, Clone)]
enum ServerCommands {
    /// "run" sub command.
    Run(Box<server::run::Args>),
    /// Dump the schema.
    Schema(Box<crate::server::schema::Args>),
}

pub fn main() -> Result<(), anyhow::Error> {
    let cli = Cli::parse();

    // Build a tracing subscriber according to the configuration in `cli.common`.
    let collector = tracing_subscriber::fmt()
        .with_target(false)
        .with_writer(std::io::stderr)
        .with_max_level(match cli.common.verbose.log_level() {
            Some(level) => match level {
                log::Level::Error => tracing::Level::ERROR,
                log::Level::Warn => tracing::Level::WARN,
                log::Level::Info => tracing::Level::INFO,
                log::Level::Debug => tracing::Level::DEBUG,
                log::Level::Trace => tracing::Level::TRACE,
            },
            None => tracing::Level::INFO,
        })
        .compact()
        .finish();

    tracing::subscriber::with_default(collector, || {
        match &cli.command {
            Commands::Gene(args) => match &args.command {
                GeneCommands::Import(args) => genes::cli::import::run(&cli.common, args)?,
                GeneCommands::Query(args) => genes::cli::query::run(&cli.common, args)?,
            },
            Commands::Tsv(args) => match &args.command {
                TsvCommands::Import(args) => tsv::cli::import::run(&cli.common, args)?,
                TsvCommands::Query(args) => tsv::cli::query::run(&cli.common, args)?,
            },
            Commands::ClinvarGenes(args) => match &args.command {
                ClinvarGeneCommands::Import(args) => {
                    clinvar_genes::cli::import::run(&cli.common, args)?
                }
                ClinvarGeneCommands::Query(args) => {
                    clinvar_genes::cli::query::run(&cli.common, args)?
                }
            },
            Commands::ClinvarMinimal(args) => match &args.command {
                ClinvarMinimalCommands::Import(args) => {
                    clinvar_minimal::cli::import::run(&cli.common, args)?
                }
                ClinvarMinimalCommands::Query(args) => {
                    clinvar_minimal::cli::query::run(&cli.common, args)?
                }
            },
            Commands::ClinvarSv(args) => match &args.command {
                ClinvarSvCommands::Import(args) => clinvar_sv::cli::import::run(&cli.common, args)?,
                ClinvarSvCommands::Query(args) => clinvar_sv::cli::query::run(&cli.common, args)?,
            },
            Commands::Cons(args) => match &args.command {
                ConsCommands::Import(args) => cons::cli::import::run(&cli.common, args)?,
                ConsCommands::Query(args) => cons::cli::query::run(&cli.common, args)?,
            },
            Commands::Dbsnp(args) => match &args.command {
                DbsnpCommands::Import(args) => dbsnp::cli::import::run(&cli.common, args)?,
                DbsnpCommands::Query(args) => dbsnp::cli::query::run(&cli.common, args)?,
            },
            Commands::Freqs(args) => match &args.command {
                FreqsCommands::Import(args) => freqs::cli::import::run(&cli.common, args)?,
                FreqsCommands::Query(args) => freqs::cli::query::run(&cli.common, args)?,
            },
            Commands::Functional(args) => match &args.command {
                FunctionalCommands::Import(args) => {
                    functional::cli::import::run(&cli.common, args)?
                }
                FunctionalCommands::Query(args) => functional::cli::query::run(&cli.common, args)?,
            },
            Commands::Helixmtdb(args) => match &args.command {
                HelixmtdbCommands::Import(args) => helixmtdb::cli::import::run(&cli.common, args)?,
                HelixmtdbCommands::Query(args) => helixmtdb::cli::query::run(&cli.common, args)?,
            },
            Commands::GnomadMtdna(args) => match &args.command {
                GnomadMtdnaCommands::Import(args) => {
                    gnomad_mtdna::cli::import::run(&cli.common, args)?
                }
                GnomadMtdnaCommands::Query(args) => {
                    gnomad_mtdna::cli::query::run(&cli.common, args)?
                }
            },
            Commands::GnomadNuclear(args) => match &args.command {
                GnomadNuclearCommands::Import(args) => {
                    gnomad_nuclear::cli::import::run(&cli.common, args)?
                }
                GnomadNuclearCommands::Query(args) => {
                    gnomad_nuclear::cli::query::run(&cli.common, args)?
                }
            },
            Commands::GnomadSv(args) => match &args.command {
                GnomadSvCommands::Import(args) => gnomad_sv::cli::import::run(&cli.common, args)?,
                GnomadSvCommands::Query(args) => gnomad_sv::cli::query::run(&cli.common, args)?,
            },
            Commands::Regions(args) => match &args.command {
                RegionsCommands::Import(args) => regions::cli::import::run(&cli.common, args)?,
                RegionsCommands::Query(args) => regions::cli::query::run(&cli.common, args)?,
            },
            Commands::DbUtils(args) => match &args.command {
                DbUtilsCommands::Copy(args) => db_utils::cli::copy::run(&cli.common, args)?,
                DbUtilsCommands::DumpMeta(args) => {
                    db_utils::cli::dump_meta::run(&cli.common, args)?
                }
            },
            Commands::Server(args) => match &args.command {
                ServerCommands::Run(args) => server::run::run(&cli.common, args)?,
                ServerCommands::Schema(args) => {
                    server::schema::run(&cli.common, args)?;
                }
            },
        }

        Ok::<(), Error>(())
    })?;

    tracing::info!("All done! Have a nice day.");

    Ok(())
}