ValidateInterpretation implements Callable<Integer> { static ListMultimap<String, Interpretation> read(final File file) throws IOException { BufferedReader reader = null; final ListMultimap<String, Interpretation> interpretations = ArrayListMultimap.create(); final Interpretation.Builder builder = Interpretation.builder(); try { reader = reader(file); CharStreams.readLines(reader, new LineProcessor<Void>() { private int count = 0; @Override public boolean processLine(final String line) throws IOException { String[] tokens = line.split("\t"); if (tokens.length < 6) { throw new IOException("illegal interpretation format, expected at least 6 columns, found " + tokens.length + "\nline=" + line); } Interpretation interpretation = builder.reset() .withSample(tokens[0]) .withLocus(tokens[1]) .withGeneFamily(tokens[2]) .withAlleleDb(tokens[3]) .withAlleleVersion(tokens[4]) .withGlstring(tokens[5]) .withConsensus(tokens.length > 6 ? tokens[6] : null) .build(); interpretations.put(interpretation.sample(), interpretation); count++; return true; } @Override public Void getResult() { return null; } }); return interpretations; } finally { try { reader.close(); } catch (Exception e) { } } } 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 testReadExpectedEmpty() throws Exception { assertTrue(read(expectedFile).isEmpty()); }
@Test(expected=IOException.class) public void testReadExpectedInvalid() throws Exception { copyResource("expected-invalid.txt", expectedFile); read(expectedFile); }
@Test public void testReadExpected() throws Exception { copyResource("expected.txt", expectedFile); ListMultimap<String, Interpretation> expected = read(expectedFile); assertNotNull(expected); assertEquals(2, expected.get("sample0").size()); assertEquals("HLA-A*03:01:01+HLA-A*03:01:01", expected.get("sample0").get(0).glstring()); assertEquals(1, expected.get("sample2").size()); assertEquals("HLA-A*03:01:01+HLA-A*03:01:02", expected.get("sample2").get(0).glstring()); }
@Test public void testReadObservedEmpty() throws Exception { assertTrue(read(observedFile).isEmpty()); }
@Test(expected=IOException.class) public void testReadObservedInvalid() throws Exception { copyResource("observed-invalid.txt", observedFile); read(observedFile); }
@Test public void testReadObserved() throws Exception { copyResource("observed.txt", observedFile); ListMultimap<String, Interpretation> observed = read(observedFile); assertNotNull(observed); assertEquals(6, observed.get("sample0").size()); assertEquals("HLA-A*03:01:01/HLA-A*03:01:01", observed.get("sample0").get(0).glstring()); assertEquals(1, observed.get("sample2").size()); assertEquals("HLA-A*03:01:02/HLA-A*03:01:03", observed.get("sample2").get(0).glstring()); }