Skip to content

Commit

Permalink
Updated usage strings to correspond to actual commands
Browse files Browse the repository at this point in the history
  • Loading branch information
pd3 committed Nov 5, 2013
1 parent 7831001 commit 4e73f2a
Show file tree
Hide file tree
Showing 11 changed files with 499 additions and 43 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ CFLAGS= -g -Wall -Wc++-compat -O2
DFLAGS=
OBJS= main.o vcfview.o bcfidx.o tabix.o \
vcfstats.o vcfisec.o vcfmerge.o vcfquery.o vcffilter.o filter.o vcfsom.o \
vcfnorm.o vcfgtcheck.o vcfsubset.o \
vcfnorm.o vcfgtcheck.o vcfsubset.o vcfannotate.o vcfroh.o \
vcfcall.o mcall.o vcmp.o \
ccall.o em.o prob1.o kmin.o # the original samtools calling
INCLUDES= -I. -I$(HTSDIR)
Expand Down Expand Up @@ -58,6 +58,7 @@ vcffilter.o: filter.h
vcfsubset.o: filter.h
vcfnorm.o: rbuf.h
vcffilter.o: rbuf.h
vcfroh.o: rbuf.h

bcftools: $(HTSLIB) $(OBJS)
$(CC) $(CFLAGS) -o $@ $(OBJS) $(HTSLIB) -lpthread -lz -lm
Expand Down
2 changes: 1 addition & 1 deletion bcfidx.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ int main_bcfidx(int argc, char *argv[])
while ((c = getopt(argc, argv, "s:")) >= 0)
if (c == 's') min_shift = atoi(optarg);
if (optind == argc) {
fprintf(stderr, "Usage: bcfidx [-s minShift] <in.bcf>\n");
fprintf(stderr, "Usage: bctools index [-s minShift] <in.bcf>\n");
return 1;
}
if ( bcf_index_build(argv[optind], min_shift)!=0 )
Expand Down
2 changes: 2 additions & 0 deletions bcftools.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ void error(const char *format, ...);
void bcf_hdr_append_version(bcf_hdr_t *hdr, int argc, char **argv, const char *cmd);
const char *hts_bcf_wmode(int file_type);

void *smalloc(size_t size); // safe malloc

#endif
76 changes: 40 additions & 36 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,85 +28,89 @@ int main_vcfnorm(int argc, char *argv[]);
int main_vcfgtcheck(int argc, char *argv[]);
int main_vcfsubset(int argc, char *argv[]);
int main_vcfcall(int argc, char *argv[]);
int main_vcfannotate(int argc, char *argv[]);
int main_vcfroh(int argc, char *argv[]);

typedef struct
{
int (*func)(int, char*[]);
const char *alias, *help, *sep;
const char *alias, *help;
}
cmd_t;

static cmd_t cmds[] =
{
{ .func = main_tabix,
.alias = "tabix",
.help = "tabix for BGZF'd BED, GFF, SAM, VCF and more",
.sep = NULL
.help = "tabix for BGZF'd BED, GFF, SAM, VCF and more"
},
{ .func = main_bcfidx,
.alias = "index",
.help = "index BCF",
.sep = NULL
.help = "index BCF"
},
{ .func = NULL,
.alias = "Core VCF/BCF tools:",
.help = NULL
},
{ .func = main_vcfcall,
.alias = "call",
.help = "SNP/indel calling (former \"view\"; this version is broken)",
.sep = "VCF/BCF tools:"
.help = "SNP/indel calling (former \"view\")"
},
{ .func = main_vcffilter,
.alias = "filter",
.help = "filter VCF files using fixed thresholds",
.sep = NULL
.help = "filter VCF/BCF files using fixed thresholds"
},
{ .func = main_vcfgtcheck,
.alias = "gtcheck",
.help = "tool for detecting swaps and contaminations",
.sep = NULL
.help = "check sample concordance, detect swaps and contaminations"
},
{ .func = main_vcfisec,
.alias = "isec",
.help = "intersections of VCF files",
.sep = NULL
.help = "intersections of VCF/BCF files"
},
{ .func = main_vcfmerge,
.alias = "merge",
.help = "merge VCF files",
.sep = NULL
.help = "merge VCF/BCF files"
},
{ .func = main_vcfnorm,
.alias = "norm",
.help = "normalize indels",
.sep = NULL
.help = "normalize indels"
},
{ .func = main_vcfquery,
.alias = "query",
.help = "transform VCF into user-defined formats",
.sep = NULL
},
{ .func = main_vcfsom,
.alias = "som",
.help = "filter using Self-Organized Maps (broken)",
.sep = NULL
.help = "transform VCF/BCF into user-defined formats"
},
{ .func = main_vcfstats,
.alias = "stats",
.help = "produce VCF stats (former vcfcheck)",
.sep = NULL
.help = "produce VCF/BCF stats (former vcfcheck)"
},
{ .func = main_vcfsubset,
.alias = "subset",
.help = "subset and filter vcf and bcf",
.sep = NULL
.help = "subset and filter VCF/BCF files"
},
{ .func = main_vcfview,
.alias = "view",
.help = "VCF<->BCF conversion",
.sep = NULL
.help = "VCF<->BCF conversion"
},
{ .func = NULL,
.alias = "Other/Experimental tools:" ,
.help = NULL
},
{ .func = main_vcfannotate,
.alias = "annotate",
.help = "-annotate and edit VCF/BCF files", // do not advertise yet
},
{ .func = main_vcfroh,
.alias = "roh",
.help = "-identify runs of autozygosity (HMM)", // do not advertise yet
},
{ .func = main_vcfsom,
.alias = "som",
.help = "filter using Self-Organized Maps (experimental)"
},
{ .func = NULL,
.alias = NULL,
.help = NULL,
.sep = NULL
.help = NULL
}
};

Expand All @@ -132,15 +136,15 @@ static int usage(void)

int i = 0;
const char *sep = NULL;
while (cmds[i].func)
while (cmds[i].alias)
{
if ( cmds[i].sep ) sep = cmds[i].sep;
if ( !cmds[i].func ) sep = cmds[i].alias;
if ( sep )
{
printf("\n -- %s\n", sep);
sep = NULL;
}
printf("\t%-15s %s\n", cmds[i].alias, cmds[i].help);
if ( cmds[i].func && cmds[i].help[0]!='-' ) printf("\t%-15s %s\n", cmds[i].alias, cmds[i].help);
i++;
}

Expand All @@ -153,7 +157,7 @@ int main(int argc, char *argv[])
if (argc < 2) return usage();

int i = 0;
while (cmds[i].func)
while (cmds[i].alias)
{
if ( !strcmp(argv[1],cmds[i].alias) )
{
Expand Down
2 changes: 1 addition & 1 deletion tabix.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ int main_tabix(int argc, char *argv[])
else if (strcmp(optarg, "vcf") == 0) conf_ptr = &tbx_conf_vcf;
}
if (optind == argc) {
fprintf(stderr, "\nUsage: tabix [options] <in.gz> [reg1 [...]]\n\n");
fprintf(stderr, "\nUsage: bcftools tabix [options] <in.gz> [reg1 [...]]\n\n");
fprintf(stderr, "Options: -p STR preset: gff, bed, sam or vcf [gff]\n");
fprintf(stderr, " -s INT column number for sequence names (suppressed by -p) [1]\n");
fprintf(stderr, " -b INT column number for region start [4]\n");
Expand Down
121 changes: 121 additions & 0 deletions vcfannotate.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
#include <stdio.h>
#include <unistd.h>
#include <getopt.h>
#include <ctype.h>
#include <string.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <math.h>
#include <htslib/vcf.h>
#include <htslib/synced_bcf_reader.h>
#include "bcftools.h"

typedef struct _args_t
{
bcf_srs_t *files;
bcf_hdr_t *hdr;
htsFile *out_fh;
int output_type;
bcf_sr_regions_t *tgts;

char **argv, *targets_fname, *regions_fname;
int argc;
}
args_t;

static void init_data(args_t *args)
{
args->hdr = args->files->readers[0].header;

// bcf_hdr_append(args->hdr,"##INFO=<ID=AC,Number=A,Type=Integer,Description=\"Allele count in genotypes\">");
bcf_hdr_append_version(args->hdr, args->argc, args->argv, "bcftools_annotate");
bcf_hdr_fmt_text(args->hdr);

args->out_fh = hts_open("-",hts_bcf_wmode(args->output_type));

args->tgts = bcf_sr_regions_init(args->targets_fname);
}

static void destroy_data(args_t *args)
{
bcf_sr_regions_destroy(args->tgts);
}

static void annotate(args_t *args, bcf1_t *line)
{
}

static void usage(args_t *args)
{
fprintf(stderr, "\n");
fprintf(stderr, "About: Annotate and edit VCF/BCF files.\n");
fprintf(stderr, "Usage: bcftools annotate [OPTIONS] <in.bcf>|<in.vcf>|<in.vcf.gz>|-\n");
fprintf(stderr, "Options:\n");
fprintf(stderr, " -a, --annotations <file> tabix-indexed file with annotations: CHR\tPOS[\tVALUE]+\n");
fprintf(stderr, " -o, --output-type <b|u|z|v> b: compressed BCF, u: uncompressed BCF, z: compressed VCF, v: uncompressed VCF [v]\n");
fprintf(stderr, " -r, --regions <reg|file> same as -t but index-jumps rather than streams to a region (requires indexed VCF/BCF)\n");
fprintf(stderr, "\n");
fprintf(stderr, "\n");
exit(1);
}

int main_vcfannotate(int argc, char *argv[])
{
int c;
args_t *args = (args_t*) calloc(1,sizeof(args_t));
args->argc = argc; args->argv = argv;
args->files = bcf_sr_init();
args->output_type = FT_VCF;

error("not finished yet, sorry\n");

static struct option loptions[] =
{
{"output-type",1,0,'o'},
{"annotations",1,0,'a'},
{"regions",1,0,'r'},
{0,0,0,0}
};
while ((c = getopt_long(argc, argv, "h?o:r:a:",loptions,NULL)) >= 0) {
switch (c) {
case 'o':
switch (optarg[0]) {
case 'b': args->output_type = FT_BCF_GZ; break;
case 'u': args->output_type = FT_BCF; break;
case 'z': args->output_type = FT_VCF_GZ; break;
case 'v': args->output_type = FT_VCF; break;
default: error("The output type \"%s\" not recognised\n", optarg);
};
break;
case 'a': args->targets_fname = optarg; break;
case 'r': args->regions_fname = optarg; break;
case 'h':
case '?': usage(args); break;
default: error("Unknown argument: %s\n", optarg);
}
}

if ( argc<optind+1 ) usage(args);
if ( args->regions_fname )
{
if ( bcf_sr_set_regions(args->files, args->regions_fname)<0 )
error("Failed to read the regions: %s\n", args->regions_fname);
}
if ( !args->targets_fname ) error("Missing the -a option\n");
if ( !bcf_sr_add_reader(args->files, argv[optind]) ) error("Failed to open or the file not indexed: %s\n", argv[optind]);

init_data(args);
bcf_hdr_write(args->out_fh, args->hdr);
while ( bcf_sr_next_line(args->files) )
{
bcf1_t *line = args->files->readers[0].buffer[0];
annotate(args, line);
bcf_write1(args->out_fh, args->hdr, line);
}
hts_close(args->out_fh);
destroy_data(args);
bcf_sr_destroy(args->files);
free(args);
return 0;
}
2 changes: 1 addition & 1 deletion vcfgtcheck.c
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ static void usage(void)
{
fprintf(stderr, "About: Check sample identity. With no -g VCF given, multi-sample cross-check is performed.\n");
fprintf(stderr, " With -s but no -p, likelihoods at all sites are printed.\n");
fprintf(stderr, "Usage: vcfgtcheck [options] [-g <genotypes.vcf.gz>] <query.vcf.gz>\n");
fprintf(stderr, "Usage: bcftools gtcheck [options] [-g <genotypes.vcf.gz>] <query.vcf.gz>\n");
fprintf(stderr, "Options:\n");
fprintf(stderr, " -a, --average-discordance output average discordance for all sites\n");
fprintf(stderr, " -g, --genotypes <file> genotypes to compare against\n");
Expand Down
2 changes: 1 addition & 1 deletion vcfisec.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ static void destroy_data(args_t *args)
static void usage(void)
{
fprintf(stderr, "About: Create intersections, unions and complements of VCF files\n");
fprintf(stderr, "Usage: vcfisec [options] <A.vcf.gz> <B.vcf.gz> ...\n");
fprintf(stderr, "Usage: bcftools isec [options] <A.vcf.gz> <B.vcf.gz> ...\n");
fprintf(stderr, "Options:\n");
fprintf(stderr, " -c, --collapse <string> treat as identical sites with differing alleles for <snps|indels|both|any|some>\n");
fprintf(stderr, " -C, --complement output positions present only in the first file but missing in the others\n");
Expand Down
2 changes: 1 addition & 1 deletion vcfquery.c
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ static int compare_header(bcf_hdr_t *hdr, int *a, int na, char **b, int nb)
static void usage(void)
{
fprintf(stderr, "About: Extracts fields from VCF/BCF file and prints them in user-defined format\n");
fprintf(stderr, "Usage: vcfquery [options] <file.vcf.gz>\n");
fprintf(stderr, "Usage: bcftools query [options] <file.vcf.gz>\n");
fprintf(stderr, "Options:\n");
fprintf(stderr, " -a, --annots <list> alias for -f '%%CHROM\\t%%POS\\t%%MASK\\t%%REF\\t%%ALT\\t%%TYPE\\t' + tab-separated <list> of tags\n");
fprintf(stderr, " -c, --collapse <string> collapse lines with duplicate positions for <snps|indels|both|any|some>\n");
Expand Down
Loading

0 comments on commit 4e73f2a

Please sign in to comment.