コード例 #1
0
  public void testTaxonomySDF() throws IOException {
    try (final TestDirectory dir = new TestDirectory("sdfstats")) {

      // One without tax
      final File smallSdf = ReaderTestUtils.getDNADir(dir);
      final String err =
          checkMainInitBadFlags("-i", smallSdf.getPath(), "-o", "-", "--taxons", "41431");
      TestUtils.containsAll(err, "does not contain taxonomy");

      // One with tax
      final File fullSdf = new File(dir, "sdf_full");
      final File faOut = new File(dir, "ex.fasta.gz");
      makeTestTaxonSdf(fullSdf);

      checkMainInitOk("-i", fullSdf.getPath(), "-o", faOut.getPath(), "--taxons", "41431");

      final String faout = FileHelper.gzFileToString(faOut);
      TestUtils.containsAll(
          faout,
          "gi|218169684|gb|CP001289.1|",
          "gi|218165370|gb|CP001287.1|",
          "gi|218169729|gb|CP001290.1|",
          "gi|218169631|gb|CP001288.1|");
    }
  }
コード例 #2
0
  public void testOk1() throws Exception {
    final File map = File.createTempFile("testok1", "coverageParams");
    try {
      FileUtils.stringToFile(SharedSamConstants.SAM9, map);
      assertTrue(map.isFile());

      final CoverageParams ccp;
      final File outFile = new File(mDir, TEST_OUTPUT);
      assertTrue(outFile.mkdir());

      final List<File> mapped = new ArrayList<>();
      mapped.add(map);

      ccp = getCoverageParams(outFile, mapped);

      assertFalse(ccp.errorRates());
      assertNotNull(ccp.filterParams());
      assertEquals(1, ccp.ioThreads());
      assertEquals(3, ccp.minimumCoverageForBreadth());
      final String ccs = ccp.toString();
      // System.err.println(ccs);
      TestUtils.containsAll(ccs, BASE_PARAMS);
      ccp.close();
    } finally {
      assertTrue(map.delete());
    }
  }
コード例 #3
0
ファイル: KappaMemoTest.java プロジェクト: ppflrs/rtg-core
 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));
 }
コード例 #4
0
ファイル: PacBioParamsTest.java プロジェクト: ppflrs/rtg-core
 public void testToString() {
   final PacBioParams params = PacBioParams.builder().create();
   TestUtils.containsAll(
       params.toString(),
       " directory=" + null,
       " reads=" + null,
       " graph=" + null,
       " trimGraph=" + false);
 }
コード例 #5
0
 private void checkErrorMessage(
     CFlags flags, String[] args, MemoryPrintStream err, String... errMessages) {
   err.outputStream().reset();
   if (errMessages.length == 0) {
     assertTrue(flags.setFlags(args));
     assertEquals("", err.toString());
   } else {
     assertFalse(flags.setFlags(args));
     TestUtils.containsAll(err.toString(), errMessages);
   }
 }
コード例 #6
0
 /** Test method for {@link com.rtg.mode.TranslatedFrame}. */
 public final void test() {
   TestUtils.testPseudoEnum(
       TranslatedFrame.class, "[FORWARD1, FORWARD2, FORWARD3, REVERSE1, REVERSE2, REVERSE3]");
   assertEquals(FORWARD1, REVERSE1.getReverse());
   assertEquals(FORWARD2, REVERSE2.getReverse());
   assertEquals(FORWARD3, REVERSE3.getReverse());
   assertEquals(REVERSE1, FORWARD1.getReverse());
   assertEquals(REVERSE2, FORWARD2.getReverse());
   assertEquals(REVERSE3, FORWARD3.getReverse());
   final byte[] codon = TranslatedFrame.populateCodonAminoArray(new DNA[0]);
   assertEquals(512, codon.length);
   for (byte aCodon : codon) {
     assertEquals(-1, aCodon);
   }
 }
コード例 #7
0
  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");
  }
コード例 #8
0
 public void testIndexType() {
   TestUtils.testEnum(BitIndex.IndexType.class, "[DEFAULT, CHUNKED, SINGLE]");
 }
コード例 #9
0
  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");
    }
  }
  private void checkDetails(final CompressedMemorySequencesReader msr) throws IOException {
    assertTrue(msr.integrity());
    final SequencesIterator it = msr.iterator();
    final StringBuilder sb = new StringBuilder();
    msr.infoString(sb);
    TestUtils.containsAll(
        sb.toString(),
        "Memory Usage\tbytes\tlength",
        //      "24\t69\tSeqData",    TODO: uncomment this after long read FastScorer done.
        "3\t3\tSeqChecksums",
        "114\t3\tNames",
        "32\t4\tPositions");
    assertEquals(mDir, msr.path());
    assertEquals(3, msr.numberSequences());
    it.seek(1L);
    assertEquals("bob-the-builder", it.currentName());
    assertEquals(1L, it.currentSequenceId());
    assertEquals(17, it.currentLength());
    assertEquals(17L + 20L, msr.lengthBetween(1L, 3L));
    final byte[] read = new byte[100];
    assertEquals(17, it.readCurrent(read));
    assertEquals(DNA.T.ordinal(), read[0]);
    assertEquals(DNA.A.ordinal(), read[1]);
    assertEquals(DNA.G.ordinal(), read[2]);

    assertTrue(msr.getSdfId().available());
    // this doesnt work because on some platforms (eg MacOSX) the canonical directory and directory
    // are not necessarily the same
    // assertEquals(msr.directory().hashCode(), msr.hashCode());
    assertEquals(SequenceType.DNA, msr.type());
    assertEquals(32L + 17L + 20L, msr.totalLength());
    assertEquals(17L, msr.minLength());
    assertEquals(32L, msr.maxLength());
    final long[] counts = msr.residueCounts();
    assertEquals(5, counts.length);
    assertEquals(18L, counts[DNA.A.ordinal()]);
    assertEquals(0L, counts[DNA.N.ordinal()]);

    assertEquals(true, msr.hasHistogram());
    final long[] hist = msr.histogram();
    assertEquals(3L, hist[0]);
    assertEquals(0L, hist[1]);
    assertEquals(0L, msr.nBlockCount());
    assertEquals(0L, msr.longestNBlock());
    assertNotNull(msr.posHistogram());
    assertEquals(0.0, msr.globalQualityAverage());
    assertNotNull(msr.positionQualityAverage());
    assertEquals(PrereadArm.UNKNOWN, msr.getArm());
    assertEquals(PrereadType.UNKNOWN, msr.getPrereadType());

    // seek beyond last sequence
    try {
      it.seek(3L);
      fail();
    } catch (IllegalArgumentException e) {
      // expected
    }
    // must leave it positioned at a valid sequence
    it.seek(2L);
    assertEquals(2L, it.currentSequenceId());
  }
コード例 #11
0
 public void testValidator() throws IOException {
   Diagnostic.setLogStream();
   final MemoryPrintStream err = new MemoryPrintStream();
   final CliDiagnosticListener listener = new CliDiagnosticListener(err.printStream());
   Diagnostic.addListener(listener);
   final File tempDir = FileHelper.createTempDirectory();
   try {
     final CFlags flags =
         new CFlags("PhyloTest", TestUtils.getNullPrintStream(), err.printStream());
     SimilarityCli.initFlags(flags);
     checkErrorMessage(
         flags,
         new String[] {"-o", "blah", "-I", "ba", "-i", "humbug"},
         err,
         "Only set one of --input or --input-list-file");
     checkErrorMessage(
         flags,
         new String[] {"-o", "blah", "-i", "humbug"},
         err,
         "The specified SDF, \"humbug\", does not exist.");
     final File fakePaired = new File(tempDir, "fakePaired");
     assertTrue(fakePaired.mkdir());
     final File left = new File(fakePaired, "left");
     assertTrue(left.mkdir());
     assertTrue(new File(fakePaired, "right").mkdir());
     checkErrorMessage(
         flags,
         new String[] {"-o", "blah", "-i", fakePaired.getPath()},
         err,
         "The specified SDF, \"" + fakePaired.getPath() + "\", is a paired end SDF.");
     checkErrorMessage(
         flags, new String[] {"-o", "blah"}, err, "Must set one of --input or --input-list-file");
     checkErrorMessage(
         flags,
         new String[] {"-o", "blah", "-I", "ba"},
         err,
         "The specified list file, \"ba\", does not exist.");
     checkErrorMessage(
         flags,
         new String[] {"-o", "blah", "-I", fakePaired.getPath()},
         err,
         "The specified list file,",
         "\"" + fakePaired.getPath() + "\",",
         "directory.");
     final File fakeList = new File(tempDir, "fakeList.txt");
     assertTrue(fakeList.createNewFile());
     checkErrorMessage(
         flags,
         new String[] {"-o", fakePaired.getPath(), "-I", fakeList.getPath()},
         err,
         "The directory",
         "\"" + fakePaired.getPath() + "\"",
         "already exists.");
     checkErrorMessage(
         flags,
         new String[] {"-o", "blah", "-I", fakeList.getPath(), "-w", "-1"},
         err,
         "The specified flag \"--word\" has invalid value \"-1\". It should be greater than or equal to \"1\".");
     checkErrorMessage(
         flags,
         new String[] {"-o", "blah", "-I", fakeList.getPath(), "-w", "0"},
         err,
         "The specified flag \"--word\" has invalid value \"0\". It should be greater than or equal to \"1\".");
     checkErrorMessage(
         flags,
         new String[] {"-o", "blah", "-I", fakeList.getPath(), "-w", "33"},
         err,
         "The specified flag \"--word\" has invalid value \"33\". It should be less than or equal to \"32\".");
     checkErrorMessage(
         flags,
         new String[] {"-o", "blah", "-I", fakeList.getPath(), "--max-reads", "0"},
         err,
         "The --max-reads must be greater than 0");
     checkErrorMessage(
         flags,
         new String[] {"-o", "blah", "-I", fakeList.getPath(), "-w", "20", "-s", "20"},
         err);
     checkErrorMessage(
         flags,
         new String[] {"-o", "blah", "-i", left.getPath(), "--max-reads", "1"},
         err,
         "Only set --max-reads when using --input-list-file");
     checkErrorMessage(flags, new String[] {"-o", "blah", "-i", left.getPath()}, err);
   } finally {
     Diagnostic.removeListener(listener);
     err.close();
     assertTrue(FileHelper.deleteAll(tempDir));
   }
 }