public void testExplosion() throws Exception { try (TestDirectory td = new TestDirectory()) { final File f = FileHelper.resourceToGzFile( "com/rtg/vcf/resources/vcfsubset.vcf", new File(td, "vcf.vcf.gz")); final File out = new File(td, "out.vcf"); assertEquals( "Records skipped due to invalid or incompatible sample fields: 1" + StringUtils.LS, checkMainInitWarn( "-i", f.getPath(), "-o", out.getPath(), "--remove-format", "GT", "--remove-format", "DS", "-Z")); final String content = FileHelper.fileToString(out); final String nonheader = StringUtils.grepMinusV(content, "^#"); assertTrue(nonheader.startsWith("X\t60052")); } }
public void testMissingSample() throws Exception { try (TestDirectory td = new TestDirectory()) { final File f = FileHelper.resourceToGzFile( "com/rtg/vcf/resources/vcfsubset.vcf", new File(td, "vcf.vcf.gz")); final File out = new File(td, "out.vcf"); assertEquals( "Error: Sample fields not contained in VCF header: BL RJ" + StringUtils.LS, checkMainInitBadFlags( "-i", f.getPath(), "-o", out.getPath(), "--keep-sample", "HG00097", "--keep-sample", "HG00099", "--keep-sample", "BL", "--keep-sample", "RJ", "-Z")); } }
public void testRemoveMulti() throws Exception { try (TestDirectory td = new TestDirectory()) { final File f = FileHelper.resourceToGzFile( "com/rtg/vcf/resources/vcfsubset.vcf", new File(td, "vcf.vcf.gz")); final File out = new File(td, "out.vcf"); checkMainInitOk( "-i", f.getPath(), "-o", out.getPath(), "--remove-samples", "--keep-info", "AN", "--keep-info", "AC", "--keep-filter", "YEA", "-Z"); final String content = FileHelper.fileToString(out); final String editedContent = StringUtils.grepMinusV(StringUtils.grepMinusV(content, "^##RUN-ID"), "^##CL"); mNano.check("vcfsubset-multi.vcf", editedContent); } }
public void testKeepSamples() throws Exception { try (TestDirectory td = new TestDirectory()) { final File f = FileHelper.resourceToGzFile( "com/rtg/vcf/resources/vcfsubset.vcf", new File(td, "vcf.vcf.gz")); final File out = new File(td, "out.vcf"); checkMainInitOk( "-i", f.getPath(), "-o", out.getPath(), "--keep-sample", "HG00096", "--keep-sample", "HG00100", "-Z"); final String content = FileHelper.fileToString(out); final String editedContent = StringUtils.grepMinusV(StringUtils.grepMinusV(content, "^##RUN-ID"), "^##CL"); mNano.check("vcfsubset-keepsamples.vcf", editedContent); } }
public void testValidation() throws Exception { try (TestDirectory main = new TestDirectory()) { final File in = FileHelper.resourceToGzFile( "com/rtg/vcf/resources/vcfsubset.vcf", new File(main, "vcf.vcf.gz")); final File foo = new File(main, "foo"); final File out = new File(main, "out.vcf.gz"); final File out2 = new File(main, "out.vcf"); String err = checkHandleFlagsErr("-i", foo.getPath(), "-o", out.getPath()); TestUtils.containsAll(TestUtils.unwrap(err), "Given file ", " does not exist."); err = checkHandleFlagsErr("-i", main.getPath(), "-o", out.getPath()); TestUtils.containsAll(TestUtils.unwrap(err), main.getPath() + "\" is a directory"); assertTrue(out.createNewFile()); err = checkHandleFlagsErr("-i", in.getPath(), "-o", new File(main, "out.vcf").getPath()); TestUtils.containsAll( TestUtils.unwrap(err), "The file \"" + out.getPath() + "\" already exists"); assertTrue(out2.createNewFile()); err = checkHandleFlagsErr("-i", in.getPath(), "-o", out2.getPath(), "--no-gzip"); TestUtils.containsAll( TestUtils.unwrap(err), "The file \"" + out2.getPath() + "\" already exists"); err = checkHandleFlagsErr( "-i", in.getPath(), "-o", new File(main, "newout.gz").getPath(), "--remove-infos", "--remove-info", "blah"); TestUtils.containsAll( TestUtils.unwrap(err), "Only one of --remove-infos, --remove-info, or --keep-info can be set"); err = checkHandleFlagsErr( "-i", in.getPath(), "-o", new File(main, "newout.gz").getPath(), "--remove-infos", "--keep-info", "blah"); TestUtils.containsAll( TestUtils.unwrap(err), "Only one of --remove-infos, --remove-info, or --keep-info can be set"); err = checkHandleFlagsErr( "-i", in.getPath(), "-o", new File(main, "newout.gz").getPath(), "--remove-info", "feh", "--keep-info", "blah"); TestUtils.containsAll( TestUtils.unwrap(err), "Only one of --remove-infos, --remove-info, or --keep-info can be set"); err = checkHandleFlagsErr( "-i", in.getPath(), "-o", new File(main, "newout.gz").getPath(), "--remove-filters", "--remove-filter", "blah"); TestUtils.containsAll( TestUtils.unwrap(err), "Only one of --remove-filters, --remove-filter, or --keep-filter can be set"); err = checkHandleFlagsErr( "-i", in.getPath(), "-o", new File(main, "newout.gz").getPath(), "--remove-filters", "--keep-filter", "blah"); TestUtils.containsAll( TestUtils.unwrap(err), "Only one of --remove-filters, --remove-filter, or --keep-filter can be set"); err = checkHandleFlagsErr( "-i", in.getPath(), "-o", new File(main, "newout.gz").getPath(), "--remove-filter", "feh", "--keep-filter", "blah"); TestUtils.containsAll( TestUtils.unwrap(err), "Only one of --remove-filters, --remove-filter, or --keep-filter can be set"); err = checkHandleFlagsErr( "-i", in.getPath(), "-o", new File(main, "newout.gz").getPath(), "--remove-samples", "--remove-sample", "blah"); TestUtils.containsAll( TestUtils.unwrap(err), "Only one of --remove-samples, --remove-sample, or --keep-sample can be set"); err = checkHandleFlagsErr( "-i", in.getPath(), "-o", new File(main, "newout.gz").getPath(), "--remove-samples", "--keep-sample", "blah"); TestUtils.containsAll( TestUtils.unwrap(err), "Only one of --remove-samples, --remove-sample, or --keep-sample can be set"); err = checkHandleFlagsErr( "-i", in.getPath(), "-o", new File(main, "newout.gz").getPath(), "--remove-sample", "feh", "--keep-sample", "blah"); TestUtils.containsAll( TestUtils.unwrap(err), "Only one of --remove-samples, --remove-sample, or --keep-sample can be set"); err = checkHandleFlagsErr( "-i", in.getPath(), "-o", new File(main, "newout.gz").getPath(), "--remove-format", "feh", "--keep-format", "blah"); TestUtils.containsAll( TestUtils.unwrap(err), "Only one of --remove-format or --keep-format can be set"); } }