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
use anyhow::Result;
use clap::Parser;
mod select;
mod split;
mod stats;
mod concat;
use select::*;
use split::*;
use stats::*;
use concat::*;
#[derive(Parser, Debug)]
#[command(
author = "size_t",
version = "version 0.1.1",
about = "vcfkit: a simple program for vcf/bcf file manipulation",
long_about = "vcfkit: a simple program for vcf/bcf file manipulation\nrepo: https::github.com/sharkLoc/vcfkit.git\nemail: dwood8146@gmail.com"
)]
struct Args {
#[clap(subcommand)]
command: Subcli,
}
#[derive(Parser, Debug)]
#[allow(non_camel_case_types)]
enum Subcli {
/// concatenate VCF/BCF files from the same set of samples
concat {
/// input VCF/BCF file list, containing the path to the files, one per line and no blank line.
#[arg(short= 'l', long = "list")]
list: String,
/// if specified, output bgzip compressed file.
#[arg(short = 'z', long = "gzip")]
gzip: bool,
/// output vcf file name, or write to stdout.
out: Option<String>,
},
/// convert BCF file to VCF file formats
convert {
/// input bcf file, or read from stdin.
bcf: Option<String>,
/// if specified, output bgzip compressed file.
#[arg(short = 'z', long = "gzip")]
gzip: bool,
/// output vcf file name, or write to stdout.
#[arg(short = 'o', long = "out")]
out : String
},
/// select SNP/INDEL variants from a VCF file
select {
/// input vcf[.gz] file, or read from stdin.
vcf: Option<String>,
/// select variant type: SNP/INDEL
#[arg(short = 'k', long = "keep", default_value_t = String::from("SNP") )]
keep: String,
/// if specified, output bgzip compressed file.
#[arg(short = 'z', long = "gzip")]
gzip: bool,
/// output vcf file name, or write to stdout.
out: Option<String>,
},
/// split vcf file by chromosome name
split {
/// input vcf[.gz] file, or read from stdin.
vcf: Option<String>,
/// split vcf file output dir.
#[arg(short = 'o', long = "out")]
outdir: String,
},
///statistics including alleles frequence, missing rate, etc.
stats {
/// input vcf[.gz] file, or read from stdin.
vcf: Option<String>,
},
}
fn main() -> Result<(), anyhow::Error> {
let arg = Args::parse();
match arg.command {
Subcli::select {
vcf,
keep,
gzip,
out,
} => match vcf {
Some(v) => {
if let Some(o) = out {
let _x = select_sites(&Some(&v), &keep, gzip, &Some(&o))?;
} else {
let _x = select_sites(&Some(&v), &keep, gzip, &None)?;
}
}
None => {
if let Some(o) = out {
let _x = select_sites(&None, &keep, gzip, &Some(&o))?;
} else {
let _x = select_sites(&None, &keep, gzip, &None)?;
}
}
}
Subcli::split {
vcf,
outdir,
} => match vcf {
Some(v) => { let _x = split_by_chr(&Some(&v), &outdir)?; }
None => { let _x = split_by_chr(&None, &outdir)?; }
}
Subcli::concat {
list,
gzip,
out
} => match out {
Some(x) => { let _x = concat_vcfs(&list, gzip, &Some(&x))?;}
None => { let _x = concat_vcfs(&list, gzip, &None)?; }
}
Subcli::convert {
bcf,
gzip,
out
} => match bcf {
Some(v) => { let _x = bcf2vcf(&Some(&v), gzip, &out)?; }
None => { let _x = bcf2vcf(&None, gzip, &out)?; }
}
Subcli::stats {vcf} => match vcf {
Some(v) => { let _x = calc_sites(&Some(&v));}
None => { let _x = calc_sites(&None);}
}
}
Ok(())
}