ValidateInterpretation implements Callable<Integer> { @Override public Integer call() throws Exception { PrintWriter writer = null; int passes = 0; int failures = 0; try { writer = writer(outputFile); ListMultimap<String, Interpretation> expected = read(expectedFile); ListMultimap<String, Interpretation> observed = read(observedFile); for (String sample : observed.keySet()) { for (Interpretation e : expected.get(sample)) { Genotype expectedGenotype = asGenotype(e); for (Haplotype expectedHaplotype : expectedGenotype.getHaplotypes()) { for (AlleleList expectedAlleleList : expectedHaplotype.getAlleleLists()) { if (shouldValidate(e, expectedAlleleList)) { for (Allele expectedAllele : expectedAlleleList.getAlleles()) { boolean match = false; for (Interpretation o : observed.get(sample)) { AlleleList observedAlleleList = asAlleleList(o); if (sameLocus(observedAlleleList, expectedAlleleList)) { for (Allele observedAllele : observedAlleleList.getAlleles()) { if (matchByField(expectedAllele.getGlstring(), observedAllele.getGlstring()) >= resolution) { match = true; break; } } } if (match) { passes++; } else { failures++; } } if (!printSummary) { writer.println((match ? "PASS" : "FAIL") + "\t" + sample + "\t" + expectedAllele); } } } } } } } if (printSummary) { writer.println("PASS\t" + passes); writer.println("FAIL\t" + failures); } return 0; } finally { try { writer.close(); } catch (Exception e) { e.printStackTrace(); System.exit(1); } } } ValidateInterpretation(final File expectedFile,
                                  final File observedFile,
                                  final File outputFile,
                                  final int resolution,
                                  final List<String> loci,
                                  final boolean printSummary,
                                  final GlClient glclient); @Override Integer call(); static void main(final String[] args);  }
@Test public void testValidateInterpretationResolution1() throws Exception { copyResource("expected.txt", expectedFile); copyResource("observed.txt", observedFile); ValidateInterpretation resolution1 = new ValidateInterpretation(expectedFile, observedFile, outputFile, 1, loci, printSummary, glclient); Integer result = resolution1.call(); for (String output : Files.readLines(outputFile, Charsets.UTF_8)) { assertTrue(output.startsWith("PASS")); } }
@Test public void testValidateInterpretationResolution3() throws Exception { copyResource("expected.txt", expectedFile); copyResource("observed.txt", observedFile); ValidateInterpretation resolution3 = new ValidateInterpretation(expectedFile, observedFile, outputFile, 3, loci, printSummary, glclient); Integer result = resolution3.call(); int passes = 0; int failures = 0; for (String output : Files.readLines(outputFile, Charsets.UTF_8)) { if (output.startsWith("PASS")) { passes++; } else { failures++; assertTrue(output.contains("HLA-A*03:01:01")); } } assertEquals(7, passes); assertEquals(1, failures); }
@Test public void testValidateInterpretationResolution4() throws Exception { copyResource("expected.txt", expectedFile); copyResource("observed.txt", observedFile); ValidateInterpretation resolution4 = new ValidateInterpretation(expectedFile, observedFile, outputFile, 4, loci, printSummary, glclient); Integer result = resolution4.call(); for (String output : Files.readLines(outputFile, Charsets.UTF_8)) { assertTrue(output.startsWith("FAIL")); } }