Exemplo n.º 1
0
 public void testInputAsFile() throws IOException {
   final File que = File.createTempFile("p2f", "flag");
   final String err = checkMainInitBadFlags("-o", "testFile", "-i", que.getPath());
   assertTrue(
       err.contains("Error: The specified file, \"" + que.getPath() + "\", is not an SDF."));
   assertTrue(FileHelper.deleteAll(que));
 }
 public void testFencePost() throws IOException {
   final File dir = FileUtils.createTempDir("cmsrt", "fencepost");
   try {
     randomSDF(dir, 256, 8200, 2L * 1024 * 1024);
     final CompressedMemorySequencesReader reader =
         (CompressedMemorySequencesReader)
             CompressedMemorySequencesReader.createSequencesReader(
                 dir, true, false, LongRange.NONE);
     assertTrue(reader.checkChecksums());
   } finally {
     assertTrue(FileHelper.deleteAll(dir));
   }
 }
Exemplo n.º 3
0
 public void testValidUse() throws Exception {
   try (TestDirectory dir = new TestDirectory("sdf2fasta")) {
     createPreread(">x" + StringUtils.LS + "actgn" + StringUtils.LS, dir);
     final String pathpr = dir.getPath();
     try {
       runCommandWithNamedOutput(JUNITOUT, pathpr, "ACTGN");
       runCommandWithNamedOutput(JUNITOUT + ".FA", pathpr, "ACTGN");
       runCommandWithNamedOutput(JUNITOUT + ".fasta", pathpr, "ACTGN");
       runCommandLineLength2(pathpr);
     } finally {
       FileHelper.deleteAll(dir);
     }
     createPrereadProtein(dir);
     runCommandWithNamedOutput(JUNITOUT, pathpr, "X*ARNDCQEGHILKMFPSTWYV");
   }
 }
  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");
  }
Exemplo n.º 5
0
 @Override
 public void tearDown() {
   assertTrue(FileHelper.deleteAll(mDir));
   mDir = null;
 }
 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));
   }
 }