Skip to content

Commit

Permalink
Merge pull request richarddurbin#24 from mcshane/feature/version2
Browse files Browse the repository at this point in the history
print pbwt version and command line (second try)
  • Loading branch information
richarddurbin committed Mar 1, 2015
2 parents 5b9e482 + 2c54482 commit 277a3cf
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ utils
*.exe
*.out
*.app

# Version file
/version.h
20 changes: 17 additions & 3 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@ HTSLIB = $(HTSDIR)/libhts.a

all: pbwt

PBWT_COMMIT_HASH = ""
ifneq "$(wildcard .git)" ""
PBWT_COMMIT_HASH = $(shell git describe --always --long --dirty | sed 's/^[0-9\.]*-*//')
version.h: $(if $(wildcard version.h),$(if $(findstring "$(PBWT_COMMIT_HASH)",$(shell cat version.h)),,force))
endif
version.h:
echo '#define PBWT_COMMIT_HASH "$(PBWT_COMMIT_HASH)"' > $@

force:

.c.o:
gcc -c $(CFLAGS) $(DFLAGS) $(INCLUDES) $< -o $@


test:
./test/test.pl

Expand All @@ -16,7 +30,7 @@ pbwt: $(PBWT_OBJS) utils
autozygExtract: autozygExtract.o
gcc $(CFLAGS) -o autozygExtract autozygExtract.o utils.o $(HTSLIB) -lpthread -lz -lm

pbwtMain.o: pbwtMain.c pbwt.h utils.h
pbwtMain.o: pbwtMain.c version.h pbwt.h utils.h
gcc $(CFLAGS) -c pbwtMain.c

pbwtCore.o: pbwtCore.c pbwt.h utils.h
Expand Down Expand Up @@ -72,7 +86,7 @@ utils.o: utils.c utils.h
gcc $(CFLAGS) -c utils.c

clean:
rm -f *.o pbwt *~
rm -f *.o pbwt *~ version.h

.PHONY: all test clean
.PHONY: all test clean force

5 changes: 4 additions & 1 deletion pbwt.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@

#include "utils.h"

static int pbwtMajorVersion = 3, pbwtMinorVersion = 0 ;
const static int pbwtMajorVersion = 3, pbwtMinorVersion = 0 ;

const char *pbwtCommitHash(void);
const char *pbwtHtslibVersionString(void);

/* data types */

Expand Down
12 changes: 10 additions & 2 deletions pbwtHtslib.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
#include <htslib/synced_bcf_reader.h>
#include <htslib/faidx.h>

const char *pbwtHtslibVersionString(void)
{
return hts_version();
}

static void readVcfSamples (PBWT *p, bcf_hdr_t *hr)
{
int i, k ;
Expand Down Expand Up @@ -229,8 +234,11 @@ void pbwtWriteVcf (PBWT *p, char *filename, char *referenceFasta, char *mode)
bcf_hdr_printf(bcfHeader, "##contig=<ID=%s,length=%d>", p->chrom, 0x7fffffff); // MAX_CSI_COOR
}
kstring_t str = {0,0,0} ;
ksprintf(&str, "##pbwtVersion=%d.%d+htslib-%s",
pbwtMajorVersion, pbwtMinorVersion, hts_version()) ;
ksprintf(&str, "##pbwtVersion=%d.%d%s%s+htslib-%s", pbwtMajorVersion, pbwtMinorVersion,
strcmp(pbwtCommitHash(),"")==0 ? "" : "-", pbwtCommitHash(), pbwtHtslibVersionString()) ;
bcf_hdr_append(bcfHeader, str.s) ;
str.l = 0;
ksprintf(&str, "##pbwtCommand=pbwt %s", commandLine) ;
bcf_hdr_append(bcfHeader, str.s) ;
free(str.s) ;
bcf_hdr_append(bcfHeader, "##INFO=<ID=AC,Number=A,Type=Integer,Description=\"Allele count in genotypes\">") ;
Expand Down
12 changes: 11 additions & 1 deletion pbwtMain.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
*/

#include "pbwt.h"
#include "version.h"

/*********************************************************/

Expand Down Expand Up @@ -166,6 +167,11 @@ static void recordCommandLine (int argc, char *argv[])
#define FOPEN(name,mode) if (!strcmp (argv[1], "-")) fp = !strcmp(mode,"r") ? stdin : stdout ; else if (!(fp = fopen (argv[1],mode))) die ("failed to open %s file", name, argv[1])
#define FCLOSE if (strcmp(argv[1], "-")) fclose(fp)

const char *pbwtCommitHash(void)
{
return PBWT_COMMIT_HASH ;
}

int main (int argc, char *argv[])
{
FILE *fp ;
Expand All @@ -179,7 +185,11 @@ int main (int argc, char *argv[])
recordCommandLine (argc, argv) ;

if (!argc) /* print help */
{ fprintf (stderr, "Usage: pbwt [ -<command> [options]* ]+\n") ;
{ fprintf (stderr, "Program: pbwt\n") ;
fprintf (stderr, "Version: %d.%d%s%s (using htslib %s)\n", pbwtMajorVersion, pbwtMinorVersion,
strcmp(pbwtCommitHash(),"")==0 ? "" : "-", pbwtCommitHash(), pbwtHtslibVersionString()) ;
fprintf (stderr, "Contact: Richard Durbin [[email protected]]\n") ;
fprintf (stderr, "Usage: pbwt [ -<command> [options]* ]+\n") ;
fprintf (stderr, "Commands:\n") ;
fprintf (stderr, " -check do various checks\n") ;
fprintf (stderr, " -stats print stats depending on commands; writes to stdout\n") ;
Expand Down
12 changes: 6 additions & 6 deletions test/test.pl
Original file line number Diff line number Diff line change
Expand Up @@ -186,24 +186,24 @@ sub test_pbwt
sub test_write_vcf
{
my ($opts,%args) = @_;
test_cmd($opts,%args,cmd=>"$$opts{bin}/pbwt -read $$opts{tmp}/$args{in}.pbwt -readSites $$opts{tmp}/$args{in}.sites -writeVcf - 2>/dev/null | grep -v ^##pbwtVersion >$$opts{tmp}/$args{out}");
test_cmd($opts,%args,cmd=>"$$opts{bin}/pbwt -read $$opts{tmp}/$args{in}.pbwt -readSites $$opts{tmp}/$args{in}.sites -writeVcfGz - 2>/dev/null | $$opts{bin}/pbwt -readVcfGT - -writeVcf - 2>/dev/null | grep -v ^##pbwtVersion >$$opts{tmp}/$args{out}");
test_cmd($opts,%args,cmd=>"$$opts{bin}/pbwt -read $$opts{tmp}/$args{in}.pbwt -readSites $$opts{tmp}/$args{in}.sites -writeBcf - 2>/dev/null | $$opts{bin}/pbwt -readVcfGT - -writeVcf - 2>/dev/null | grep -v ^##pbwtVersion >$$opts{tmp}/$args{out}");
test_cmd($opts,%args,cmd=>"$$opts{bin}/pbwt -read $$opts{tmp}/$args{in}.pbwt -readSites $$opts{tmp}/$args{in}.sites -writeBcfGz - 2>/dev/null | $$opts{bin}/pbwt -readVcfGT - -writeVcf - 2>/dev/null | grep -v ^##pbwtVersion >$$opts{tmp}/$args{out}");
test_cmd($opts,%args,cmd=>"$$opts{bin}/pbwt -read $$opts{tmp}/$args{in}.pbwt -readSites $$opts{tmp}/$args{in}.sites -writeVcf - 2>/dev/null | grep -v ^##pbwt >$$opts{tmp}/$args{out}");
test_cmd($opts,%args,cmd=>"$$opts{bin}/pbwt -read $$opts{tmp}/$args{in}.pbwt -readSites $$opts{tmp}/$args{in}.sites -writeVcfGz - 2>/dev/null | $$opts{bin}/pbwt -readVcfGT - -writeVcf - 2>/dev/null | grep -v ^##pbwt >$$opts{tmp}/$args{out}");
test_cmd($opts,%args,cmd=>"$$opts{bin}/pbwt -read $$opts{tmp}/$args{in}.pbwt -readSites $$opts{tmp}/$args{in}.sites -writeBcf - 2>/dev/null | $$opts{bin}/pbwt -readVcfGT - -writeVcf - 2>/dev/null | grep -v ^##pbwt >$$opts{tmp}/$args{out}");
test_cmd($opts,%args,cmd=>"$$opts{bin}/pbwt -read $$opts{tmp}/$args{in}.pbwt -readSites $$opts{tmp}/$args{in}.sites -writeBcfGz - 2>/dev/null | $$opts{bin}/pbwt -readVcfGT - -writeVcf - 2>/dev/null | grep -v ^##pbwt >$$opts{tmp}/$args{out}");
}

sub test_read_vcf_gt
{
my ($opts,%args) = @_;
test_cmd($opts,%args,cmd=>"$$opts{bin}/pbwt -readVcfGT $$opts{path}/read.vcf -writeVcf - 2>/dev/null | grep -v ^##pbwtVersion >$$opts{tmp}/$args{out}");
test_cmd($opts,%args,cmd=>"$$opts{bin}/pbwt -readVcfGT $$opts{path}/read.vcf -writeVcf - 2>/dev/null | grep -v ^##pbwt >$$opts{tmp}/$args{out}");
}

sub test_pbwt_reference_impute
{
my ($opts,%args) = @_;
# create reference panel pbwt
cmd("$$opts{bin}/pbwt -readVcfGT $$opts{path}/$args{ref}.vcf -writeAll $$opts{tmp}/$args{ref} 2>/dev/null");
test_cmd($opts,%args,cmd=>"$$opts{bin}/pbwt -readVcfGT $$opts{path}/$args{in}.vcf -referenceImpute $$opts{tmp}/$args{ref} -writeVcf - 2>/dev/null | grep -v ^##pbwtVersion > $$opts{tmp}/$args{out}");
test_cmd($opts,%args,cmd=>"$$opts{bin}/pbwt -readVcfGT $$opts{path}/$args{in}.vcf -referenceImpute $$opts{tmp}/$args{ref} -writeVcf - 2>/dev/null | grep -v ^##pbwt > $$opts{tmp}/$args{out}");
}

sub test_merge
Expand Down

0 comments on commit 277a3cf

Please sign in to comment.