public void testToString() throws InvalidParamsException, IOException { final AbstractKappa kappa; kappa = getKappa(); // System.out.println(kappa.toString()); final String exp = FileHelper.resourceToString("com/rtg/variant/bayes/complex/resources/kappamemotest0.txt"); assertTrue(TestUtils.sameLines(exp, kappa.toString(), false)); }
public void testFilterUnmated() throws IOException { final ByteArrayOutputStream log = new ByteArrayOutputStream(); try (PrintStream prLog = new PrintStream(log)) { Diagnostic.setLogStream(prLog); final int numReads = 100; final MapQScoringReadBlocker blocker = new MapQScoringReadBlocker(numReads, 2); blocker.increment(1, 3); blocker.increment(20, 4); blocker.increment(20, 4); blocker.increment(20, 4); // read 20 is blocked for score=4 blocker.increment(3, 1); blocker.increment(3, 1); blocker.increment(3, 1); // read 3 is blocked for score=1 blocker.increment(3, 0); blocker.increment(3, 0); // read 3 is just not blocked for score=0 final File dir = FileUtils.createTempDir("test", "unmatedSamFilter"); OutputStream out = null; try { final File in1 = File.createTempFile("sam", "_1.gz", dir); writeTempFile(in1); final File outFile = File.createTempFile("out", ".gz", dir); out = new GZIPOutputStream(new FileOutputStream(outFile)); final StatusListener listener = new StatusListener(numReads); final ReadBlocker freqBlocker = new ReadBlocker(numReads, 2); freqBlocker.increment(66); freqBlocker.increment(66); final MockSequencesReader msr = new MockSequencesReader(SequenceType.DNA) { @Override public PrereadType getPrereadType() { return PrereadType.UNKNOWN; } @Override public boolean hasQualityData() { return true; } @Override public int read(long sequenceIndex, byte[] dataOut) { dataOut[0] = 1; if (sequenceIndex == 3) { dataOut[1] = 3; dataOut[2] = 3; } else { dataOut[1] = 3; dataOut[2] = 2; } dataOut[3] = 4; return 4; } @Override public int readQuality(final long sequenceIndex, final byte[] dest) { dest[0] = dest[1] = dest[2] = dest[3] = '<' - 33; return 4; } }; final SingleEndSamResultsFilter filter = new SingleEndSamResultsFilter(blocker, freqBlocker, listener, 0, msr, null, false); assertEquals("Alignment", filter.getName()); filter.filterConcat(makeHeader(), out, null, null, mTemplateReader, false, in1); out.close(); final String contents = FileHelper.gzFileToString(outFile); // System.out.println("contents=" + contents); assertTrue( TestUtils.sameLines(SAM_UNMATED_EXPECTED, TestUtils.stripSAMHeader(contents), false)); // now check that the listener has been updated correctly. for (int read = 0; read < numReads; read++) { final int expect; switch (read) { case 1: case 3: expect = ReadStatusTracker.UNMATED_FIRST; break; default: expect = 0; break; } assertEquals("readId=" + read, expect, listener.getStatus(read)); } } finally { if (out != null) { out.close(); } assertTrue(FileHelper.deleteAll(dir)); } } finally { Diagnostic.setLogStream(); } final String logString = log.toString(); // System.err.println(logString); TestUtils.containsAll(logString, "Alignment SAM filter outputs 2/5 records"); }