1 package org.broadinstitute.hellbender.tools.walkers.variantutils; 2 3 import org.broadinstitute.hellbender.CommandLineProgramTest; 4 import org.broadinstitute.hellbender.exceptions.UserException; 5 import org.broadinstitute.hellbender.testutils.IntegrationTestSpec; 6 import org.testng.annotations.Test; 7 8 import java.io.IOException; 9 import java.util.Arrays; 10 11 public final class VariantsToTableIntegrationTest extends CommandLineProgramTest { variantsToTableCmd(final String moreArgs)12 private String variantsToTableCmd(final String moreArgs) { 13 return " --variant " + getToolTestDataDir() + "soap_gatk_annotated.noChr_lines.vcf" + 14 " -F CHROM -F POS -F ID -F REF -F ALT -F QUAL -F FILTER -F TRANSITION -F DP -F SB -F set -F RankSumP -F refseq.functionalClass*" + 15 " -O %s " + moreArgs; 16 } 17 variantsToTableMultiAllelicCmd(final String moreArgs)18 private String variantsToTableMultiAllelicCmd(final String moreArgs) { 19 return " --variant " + getToolTestDataDir() + "multiallelic.vcf" + 20 " -F CHROM -F POS -F ID -F REF -F ALT -F QUAL -F MULTI-ALLELIC -F AC -F AF" + 21 " -O %s" + moreArgs; 22 } 23 variantsToTableCmdNoSamples(final String moreArgs)24 private String variantsToTableCmdNoSamples(final String moreArgs) { 25 return " --variant " + getToolTestDataDir() + "vcfexample.noSamples.vcf" + 26 " -O %s" + moreArgs; 27 } 28 29 @Test testInputFileFail()30 public void testInputFileFail() throws IOException { 31 final IntegrationTestSpec spec = new IntegrationTestSpec( 32 " --variant does_not_exist.vcf -O %s", 33 1, UserException.CouldNotReadInputFile.class); 34 spec.executeTest("testComplexVariantsToTable-FAIL", this); 35 } 36 37 @Test testOutputFileFail()38 public void testOutputFileFail() throws IOException { 39 final IntegrationTestSpec spec = new IntegrationTestSpec( 40 " --variant " + getToolTestDataDir() + "soap_gatk_annotated.noChr_lines.vcf" + 41 " -O /does_not_exists/txt.table", 42 1, UserException.CouldNotCreateOutputFile.class); 43 spec.executeTest("testComplexVariantsToTable-FAIL", this); 44 } 45 46 @Test testComplexVariantsToTableFail()47 public void testComplexVariantsToTableFail() throws IOException { 48 final IntegrationTestSpec spec = new IntegrationTestSpec( 49 variantsToTableCmd("--error-if-missing-data"), 50 1, UserException.class); 51 spec.executeTest("testComplexVariantsToTable-FAIL", this); 52 } 53 54 @Test testUnfilteredGenotypeFieldsFail()55 public void testUnfilteredGenotypeFieldsFail() throws IOException { 56 final IntegrationTestSpec spec = new IntegrationTestSpec( 57 " --variant " + getToolTestDataDir() + "vcfexample2.vcf" + 58 " -GF RD -GF FT --error-if-missing-data" + 59 " -O %s", 60 1, 61 UserException.class); 62 spec.executeTest("testUnfilteredGenotypeFields-FAIL", this); 63 } 64 65 @Test testNoSamples()66 public void testNoSamples() throws IOException { 67 final IntegrationTestSpec spec = new IntegrationTestSpec( 68 variantsToTableCmdNoSamples(" -F CHROM -F POS -F ID -F REF -F ALT -F QUAL -F FILTER -F TRANSITION -F EVENTLENGTH"), 69 Arrays.asList(getToolTestDataDir() + "expected.vcfexample.noSamples.table")); 70 spec.executeTest("testNoSamples", this); 71 } 72 73 @Test testNoSamplesSoNoGenotypes()74 public void testNoSamplesSoNoGenotypes() throws IOException { 75 final IntegrationTestSpec spec = new IntegrationTestSpec( 76 variantsToTableCmdNoSamples(" -GF DP"), 77 1, 78 UserException.class); 79 spec.executeTest("testNoSamples", this); 80 } 81 82 @Test testComplexVariantsToTable()83 public void testComplexVariantsToTable() throws IOException { 84 final IntegrationTestSpec spec = new IntegrationTestSpec( 85 variantsToTableCmd(""), 86 Arrays.asList(getToolTestDataDir() + "expected.soap_gatk_annotated.noChr_lines.table")); 87 spec.executeTest("testComplexVariantsToTable", this); 88 } 89 90 @Test testMultiAllelicOneRecord()91 public void testMultiAllelicOneRecord() throws IOException { 92 final IntegrationTestSpec spec = new IntegrationTestSpec( 93 variantsToTableMultiAllelicCmd(""), 94 Arrays.asList(getToolTestDataDir() + "expected.multiallelic.table")); 95 spec.executeTest("testMultiAllelicOneRecord", this); 96 } 97 98 @Test testMultiAllelicSplitRecords()99 public void testMultiAllelicSplitRecords() throws IOException { 100 final IntegrationTestSpec spec = new IntegrationTestSpec( 101 variantsToTableMultiAllelicCmd(" -SMA"), 102 Arrays.asList(getToolTestDataDir() + "expected.multiallelic.SMA.table")); 103 spec.executeTest("testMultiAllelicSplitRecords", this); 104 } 105 106 @Test testGenotypeFields()107 public void testGenotypeFields() throws IOException { 108 final IntegrationTestSpec spec = new IntegrationTestSpec( 109 " --variant " + getToolTestDataDir() + "vcfexample2.vcf" + 110 " -GF RD" + 111 " -O %s", 112 Arrays.asList(getToolTestDataDir() + "expected.vcfexample2.GF_RD.table")); 113 spec.executeTest("testGenotypeFields", this); 114 } 115 116 @Test testUnfilteredGenotypeFields()117 public void testUnfilteredGenotypeFields() throws IOException { 118 final IntegrationTestSpec spec = new IntegrationTestSpec( 119 " --variant " + getToolTestDataDir() + "vcfexample2.vcf" + 120 " -GF RD -GF FT" + 121 " -O %s", 122 Arrays.asList(getToolTestDataDir() + "expected.vcfexample2.GF_RD.FT.table")); 123 spec.executeTest("testUnfilteredGenotypeFields", this); 124 } 125 126 @Test testMultiallelicGenotypeFields()127 public void testMultiallelicGenotypeFields() throws IOException { 128 final IntegrationTestSpec spec = new IntegrationTestSpec( 129 " --variant " + getToolTestDataDir() + "multiallelic_gt.vcf" + 130 " -F CHROM -F POS -F ID -F REF -F ALT -F QUAL -F MULTI-ALLELIC" + 131 " -GF PL -GF AD" + 132 " -SMA" + 133 " -O %s", 134 Arrays.asList(getToolTestDataDir() + "expected.multiallelic_gt.table")); 135 spec.executeTest("testMultiallelicGenotypeFields", this); 136 } 137 138 @Test testGenotypeFieldsWithInline()139 public void testGenotypeFieldsWithInline() throws IOException { 140 final IntegrationTestSpec spec = new IntegrationTestSpec( 141 " --variant " + getToolTestDataDir() + "vcfexample2.vcf" + 142 " -GF RD -GF GT -GF GQ" + 143 " -O %s", 144 Arrays.asList(getToolTestDataDir() + "expected.vcfexample2.GF_RD.GF_GT.GF_GT.table")); 145 spec.executeTest("testGenotypeFieldsWithInline", this); 146 } 147 148 @Test testSplitMultiallelicFields()149 public void testSplitMultiallelicFields() throws IOException { 150 //missing AS INFO and FORMAT fields are handled 151 //R-type FORMAT annotations work (MMQ) 152 //A-type FORMAT annotations wotk (TLOD) 153 final IntegrationTestSpec spec = new IntegrationTestSpec( 154 " --variant " + getToolTestDataDir() + "../../GenotypeGVCFs/threeSamples.2alts.vcf" + 155 " -SMA -F CHROM -F POS -F REF -F ALT -F FOO -ASF TLOD -ASGF TLOD -ASGF AD -ASGF MMQ -ASGF BAR -raw" + 156 " -O %s", 157 Arrays.asList(getToolTestDataDir() + "expected.threeSamples.2alts.MT.txt")); 158 spec.executeTest("testGenotypeFieldsWithInline", this); 159 160 //asking for allele-specific fields without splitting produces reasonable output 161 final IntegrationTestSpec spec2 = new IntegrationTestSpec( 162 " --variant " + getToolTestDataDir() + "../../GenotypeGVCFs/threeSamples.2alts.vcf" + 163 " -F CHROM -F POS -F REF -F ALT -ASGF TLOD -ASGF AD -ASGF MMQ -raw" + 164 " -O %s", 165 Arrays.asList(getToolTestDataDir() + "expected.threeSamples.2alts.MT.noSplit.txt")); 166 spec2.executeTest("testGenotypeFieldsWithInline", this); 167 168 //A-type INFO annotations work 169 final IntegrationTestSpec spec4 = new IntegrationTestSpec( 170 " --variant " + getToolTestDataDir() + "../../../VQSR/expected/applyIndelAlleleSpecificResult.vcf" + 171 " -SMA -F CHROM -F POS -F REF -F ALT -ASF AS_BaseQRankSum -ASGF AD -raw -ASF AS_FilterStatus" + 172 " -O %s", 173 Arrays.asList(getToolTestDataDir() + "expected.ASindelVQSR.txt")); 174 spec4.executeTest("testGenotypeFieldsWithInline", this); 175 } 176 177 @Test testListFields()178 public void testListFields() throws IOException { 179 final IntegrationTestSpec spec = new IntegrationTestSpec( 180 " --variant " + getToolTestDataDir() + "vcfexample.withMLE.vcf" + 181 " -GF PL" + 182 " -O %s", 183 Arrays.asList(getToolTestDataDir() + "expected.vcfexample.withMLE.GF_PL.table")); 184 spec.executeTest("testGenotypeFields", this); 185 } 186 187 @Test testMoltenOutput()188 public void testMoltenOutput() throws IOException { 189 final IntegrationTestSpec spec = new IntegrationTestSpec( 190 " --variant " + getToolTestDataDir() + "vcfexample2.vcf" + 191 " -F CHROM -F POS -F ID -F REF -F ALT -F QUAL -F FILTER" + 192 " --moltenize" + 193 " -O %s", 194 Arrays.asList(getToolTestDataDir() + "expected.vcfexample2.moltenize.table")); 195 spec.executeTest("testMoltenOutput", this); 196 } 197 198 @Test testMoltenOutputWithGenotypeFields()199 public void testMoltenOutputWithGenotypeFields() throws IOException { 200 final IntegrationTestSpec spec = new IntegrationTestSpec( 201 " --variant " + getToolTestDataDir() + "vcfexample2.vcf" + 202 " -GF RD" + 203 " --moltenize" + 204 " -O %s", 205 Arrays.asList(getToolTestDataDir() + "expected.vcfexample2.GF_RD.moltenize.table")); 206 spec.executeTest("testMoltenOutputWithGenotypeFields", this); 207 } 208 209 @Test testMoltenOutputWithMultipleAlleles()210 public void testMoltenOutputWithMultipleAlleles() throws IOException { 211 final IntegrationTestSpec spec = new IntegrationTestSpec( 212 " --variant " + getToolTestDataDir() + "multiallelic.vcf" + 213 " -F CHROM -F POS -F ID -F REF -F ALT -F QUAL -F MULTI-ALLELIC -F AC -F AF" + 214 " --moltenize -SMA" + 215 " -O %s", 216 Arrays.asList(getToolTestDataDir() + "expected.multiallelic.moltenize.SMA.table")); 217 spec.executeTest("testMoltenOutputWithMultipleAlleles", this); 218 } 219 } 220