Example usage for org.apache.commons.io FilenameUtils concat

List of usage examples for org.apache.commons.io FilenameUtils concat

Introduction

In this page you can find the example usage for org.apache.commons.io FilenameUtils concat.

Prototype

public static String concat(String basePath, String fullFilenameToAdd) 

Source Link

Document

Concatenates a filename to a base path using normal command line style rules.

Usage

From source file:edu.cornell.med.icb.goby.modes.TestSplicedSamHelper.java

@Test
// Test  right soft clip:
public void testSamToCompactTrickCase5() throws IOException {

    SAMToCompactMode importer = new SAMToCompactMode();
    importer.setInputFile("test-data/splicedsamhelper/tricky-spliced-5.sam");
    final String outputFilename = FilenameUtils.concat(BASE_TEST_DIR, "spliced-output-alignment-5");
    importer.setOutputFile(outputFilename);
    importer.execute();//from ww w. j  av a2  s  .c  om

    AlignmentReader reader = new AlignmentReaderImpl(outputFilename);
    assertTrue(reader.hasNext());
    Alignments.AlignmentEntry first = reader.next();

    assertEquals(0, first.getQueryIndex());
    assertEquals(0, first.getFragmentIndex());
    assertEquals(71428 - 1, first.getPosition());

}

From source file:com.enioka.jqm.tools.MiscTest.java

@Test
public void testMultiLog() throws Exception {
    PrintStream out_ini = System.out;
    PrintStream err_ini = System.err;

    Helpers.setSingleParam("logFilePerLaunch", "true", em);
    CreationTools.createJobDef(null, true, "App", null, "jqm-tests/jqm-test-datetimemaven/target/test.jar",
            TestHelpers.qVip, 42, "MarsuApplication", null, "Franquin", "ModuleMachin", "other", "other", true,
            em);/*w w  w.  java 2  s. c  o m*/
    int i = JobRequest.create("MarsuApplication", "TestUser").submit();
    addAndStartEngine();
    TestHelpers.waitFor(1, 20000, em);

    String fileName = StringUtils.leftPad("" + i, 10, "0") + ".stdout.log";
    File f = new File(FilenameUtils.concat(((MultiplexPrintStream) System.out).rootLogDir, fileName));

    Assert.assertEquals(1, TestHelpers.getOkCount(em));
    Assert.assertEquals(0, TestHelpers.getNonOkCount(em));
    Assert.assertTrue(f.exists());

    System.setErr(err_ini);
    System.setOut(out_ini);
}

From source file:edu.cornell.med.icb.goby.readers.sam.TestGobyPaperTop5000s.java

/**
 * The first 1M alignments of UAN. This large dataset does not exist on the testing server.
 *
 * @throws java.io.IOException error//w  w  w . j av  a2  s  .  com
 */
// @Test
public void testRoundTrip1M() throws IOException {
    final RoundTripAlignment rtc = new RoundTripAlignment();
    rtc.inputGenomeFilename = findThousandGenome();
    rtc.sourceBamFilename = "test-data/splicedsamhelper/1M.bam";
    rtc.destGobyBasename = FilenameUtils.concat(BASE_TEST_OUTPUT_DIR, "1M");
    rtc.destBamFilename = FilenameUtils.concat(BASE_TEST_OUTPUT_DIR, "1M.bam");
    rtc.canonicalMdzForComparison = false;
    final long start = System.currentTimeMillis();
    rtc.testRoundTripAny();
    System.out.printf("Execution time in ms=%d%n", System.currentTimeMillis() - start);
}

From source file:edu.cornell.med.icb.goby.alignments.TestIterateSortedAlignment.java

@Test
public void testIterateSortedReferenceInsertions() throws IOException {

    final String basename = "align-skip-to-1-concat";
    final String basenamePath = FilenameUtils.concat(BASE_TEST_DIR, basename);
    final AlignmentWriterImpl writer = new AlignmentWriterImpl(basenamePath);
    writer.setNumAlignmentEntriesPerChunk(1);

    final int numTargets = 3;
    final int[] targetLengths = new int[numTargets];

    for (int referenceIndex = 0; referenceIndex < numTargets; referenceIndex++) {
        targetLengths[referenceIndex] = 1000;
    }/*from   ww  w  .  j a  v  a2 s.  c o  m*/
    writer.setTargetLengths(targetLengths);
    // we write this alignment sorted:

    writer.setSorted(true);
    Alignments.AlignmentEntry.Builder newEntry;

    newEntry = prepareAlignmentEntryWithReferenceInsertion(0, 1, 100, 30, false, new int[] { 4, 3 });
    writer.appendEntry(newEntry.build());

    writer.close();
    writer.printStats(System.out);

    final Int2IntMap positionMap = new Int2IntOpenHashMap();
    final IntSet variantReadIndices = new IntOpenHashSet();

    IterateSortedAlignmentsListImpl iterator = new IterateSortedAlignmentsListImpl() {
        @Override
        public void observeVariantBase(ConcatSortedAlignmentReader sortedReaders,
                Alignments.AlignmentEntry alignmentEntry,
                Int2ObjectMap<DiscoverVariantPositionData> positionToBases, Alignments.SequenceVariation var,
                char toChar, char fromChar, byte toQual, int currentReferenceIndex, int currentRefPosition,
                int currentReadIndex) {

            variantReadIndices.add(currentReadIndex);
        }

        @Override
        public void processPositions(int referenceIndex, int intermediatePosition,
                DiscoverVariantPositionData positionBaseInfos) {
            int coverage = 0;
            for (PositionBaseInfo info : positionBaseInfos) {
                coverage += info.to != '-' ? 1 : 0;
            }
            // store with one-based position
            positionMap.put(intermediatePosition + 1, coverage);
            System.out.printf("position: %d listSize: %d%n", intermediatePosition, coverage);
        }
    };
    iterator.iterate(basenamePath);

    for (int i = 0; i < 100; i++) {
        assertEquals("[i=" + i + "] position " + i, 0, positionMap.get(i));
    }
    for (int i = 100; i < 103; i++) {
        assertEquals("[i=" + i + "] position " + i, 1, positionMap.get(i));
    }
    for (int i = 103; i < 106; i++) {
        assertEquals("[i=" + i + "] position " + i, 0, positionMap.get(i));
    }
    for (int i = 106; i < 137; i++) {
        assertEquals("[i=" + i + "] position " + i, 1, positionMap.get(i));
    }
    for (int i = 138; i < 150; i++) {
        assertEquals("[i=" + i + "] position " + i, 0, positionMap.get(i));
    }

}

From source file:edu.cornell.med.icb.goby.modes.TestSplicedSamHelper.java

@Test
// Test deletion in the read:
public void testSamToCompactTrickCase6() throws IOException {

    SAMToCompactMode importer = new SAMToCompactMode();
    importer.setInputFile("test-data/splicedsamhelper/tricky-spliced-6.sam");
    final String outputFilename = FilenameUtils.concat(BASE_TEST_DIR, "spliced-output-alignment-6");
    importer.setOutputFile(outputFilename);
    String[] refs = { "NNNNNNTTAGAAAAACAGAGAGAGAAGGAGAGTAAAGGGAGGAGGCGGAGGAGGAGAAAAGAAGAAAGCAGAGANNNNNN" };

    RandomAccessSequenceTestSupport genomeTestSupport = new RandomAccessSequenceTestSupport(refs);
    importer.setGenome(genomeTestSupport);

    importer.execute();/* w  w w.  ja v  a2s  .c  o m*/

    AlignmentReader reader = new AlignmentReaderImpl(outputFilename);
    assertTrue(reader.hasNext());
    Alignments.AlignmentEntry first = reader.next();

    assertEquals(0, first.getQueryIndex());
    assertEquals(0, first.getFragmentIndex());
    assertEquals(7 - 1, first.getPosition());

}

From source file:com.google.jenkins.plugins.storage.AbstractUpload.java

/**
 * This is the workhorse API for performing the actual uploads.  It is
 * performed at the workspace, so that all of the {@link FilePath}s should
 * be local.//w  ww.  j  a v a 2 s .  c o  m
 */
private void performUploads(Map<String, String> metadata, String bucketName, String objectPrefix,
        GoogleRobotCredentials credentials, UploadSpec uploads, TaskListener listener) throws UploadException {
    try {
        Storage service = module.getStorageService(credentials);
        Executor executor = module.newExecutor();

        // Ensure the bucket exists, fetching it regardless so that we can
        // attach its default ACLs to the objects we upload.
        Bucket bucket = getOrCreateBucket(service, credentials, executor, bucketName);

        for (FilePath include : uploads.inclusions) {
            String relativePath = getRelative(include, uploads.workspace);
            String uploadedFileName = getStrippedFilename(relativePath);
            String finalName = FilenameUtils
                    .separatorsToUnix(FilenameUtils.concat(objectPrefix, uploadedFileName));

            StorageObject object = new StorageObject().setName(finalName).setMetadata(metadata)
                    .setContentDisposition(HttpHeaders.getContentDisposition(include.getName()))
                    .setContentType(detectMIMEType(include.getName()))
                    .setSize(BigInteger.valueOf(include.length()));

            if (isSharedPublicly()) {
                object.setAcl(addPublicReadAccess(getDefaultObjectAcl(bucket, listener)));
            }

            // Give clients an opportunity to decorate the storage
            // object before we store it.
            annotateObject(object, listener);

            // Log that we are uploading the file and begin executing the upload.
            listener.getLogger().println(module.prefix(Messages.AbstractUpload_Uploading(relativePath)));
            performUploadWithRetry(executor, service, bucket, object, include);
        }
    } catch (ForbiddenException e) {
        // If the user doesn't own a bucket then they will end up here.
        throw new UploadException(Messages.AbstractUpload_ForbiddenFileUpload(), e);
    } catch (ExecutorException e) {
        throw new UploadException(Messages.AbstractUpload_ExceptionFileUpload(), e);
    } catch (IOException e) {
        throw new UploadException(Messages.AbstractUpload_ExceptionFileUpload(), e);
    } catch (InterruptedException e) {
        throw new UploadException(Messages.AbstractUpload_ExceptionFileUpload(), e);
    }
}

From source file:edu.cornell.med.icb.goby.alignments.TestMerge.java

@Before
public void setUp() throws IOException {
    {//from  w w w . ja v a2 s.  c  o  m
        final AlignmentWriterImpl writer = new AlignmentWriterImpl(
                FilenameUtils.concat(BASE_TEST_DIR, "align-101"));
        writer.setNumAlignmentEntriesPerChunk(1000);
        final int numTargets = 2000;
        final int numQuery = 10;
        int position = 1;
        int score = 30;

        for (int targetIndex = 0; targetIndex < numTargets; targetIndex++) {
            for (int queryIndex = 0; queryIndex < numQuery; queryIndex++) {
                writer.setAlignmentEntry(queryIndex, targetIndex, position++, score++, false,
                        constantQueryLength);
                writer.appendEntry();
                numEntriesIn101++;
            }
        }
        numQueries101 = numQuery;
        writer.close();
    }

    {
        final AlignmentWriterImpl writer = new AlignmentWriterImpl(
                FilenameUtils.concat(BASE_TEST_DIR, "transcript-101"));
        writer.setNumAlignmentEntriesPerChunk(1000);
        final int numTargets = 5;
        int position = 1;
        final int score = 30;
        final String[] transcriptIds = { "transcriptId1", "transcriptId2", "transcriptId3", "transcriptId4",
                "transcriptId5", };
        final int[] transcriptIndex = { 0, 1, 2, 3, 4 };
        final int[] targetLengths = { 1024, 5678, 1237, 9, 143 };
        writer.setTargetLengths(targetLengths);

        final IndexedIdentifier targetIds = new IndexedIdentifier();
        for (int i = 0; i < numTargets; i++) {
            if (transcriptIndex[i] != targetIds.registerIdentifier(new MutableString(transcriptIds[i]))) {
                assert false : "transcript Index must match";
            }
        }

        writer.setTargetIdentifiers(targetIds);

        // make query 0 OK, matches 3 transcripts that belong to the same gene
        // query 1 matches two transcripts, but 2 genes, not OK.
        // query 2 OK: 1 transcript 1 gene.
        writer.setAlignmentEntry(0, transcriptIndex[0], position++, score, false, constantQueryLength);
        writer.appendEntry();
        writer.setAlignmentEntry(0, transcriptIndex[1], position++, score + 1, false, constantQueryLength);
        writer.appendEntry();
        writer.setAlignmentEntry(0, transcriptIndex[2], position++, score + 1, false, constantQueryLength);
        writer.appendEntry();
        writer.setAlignmentEntry(1, transcriptIndex[2], position++, score, false, constantQueryLength);
        writer.appendEntry();
        writer.setAlignmentEntry(1, transcriptIndex[3], position++, score, false, constantQueryLength);
        writer.appendEntry();
        writer.setAlignmentEntry(2, transcriptIndex[4], position++, score, false, constantQueryLength);
        writer.appendEntry();
        writer.close();

    }

    {
        // Will have too many hits info created for it:
        final AlignmentWriterImpl writer = new AlignmentWriterImpl(
                FilenameUtils.concat(BASE_TEST_DIR, "align-102"));
        writer.setNumAlignmentEntriesPerChunk(1000);
        final int numTargets = 2000;
        final int numQuery = 10;
        int position = 1;
        int score = 30;
        for (int targetIndex = 0; targetIndex < numTargets; targetIndex++) {
            for (int queryIndex = 0; queryIndex < numQuery; queryIndex++) {
                writer.setAlignmentEntry(queryIndex, targetIndex, position++, score++, false,
                        constantQueryLength);
                writer.appendEntry();
                numEntriesIn102++;
            }
        }
        numQueries102 = numQuery;
        writer.close();
    }

    {
        // Will have too many hits info created for it:
        final AlignmentWriterImpl writer = new AlignmentWriterImpl(
                FilenameUtils.concat(BASE_TEST_DIR, "align-103"));
        writer.setNumAlignmentEntriesPerChunk(1000);
        final int numTargets = 2000;
        final int numQuery = 10;
        int position = 1;
        int score = 30;
        for (int targetIndex = 0; targetIndex < numTargets; targetIndex++) {
            for (int queryIndex = 0; queryIndex < numQuery; queryIndex++) {
                writer.setAlignmentEntry(queryIndex, targetIndex, position++, score++, false,
                        constantQueryLength);
                writer.appendEntry();
                numEntriesIn103++;
            }
        }
        numQueries103 = numQuery;
        writer.close();
    }

    {
        // Will have too many hits info created for it:
        final AlignmentWriterImpl writer = new AlignmentWriterImpl(
                FilenameUtils.concat(BASE_TEST_DIR, "align-105"));
        System.out.println("preparing 105");
        writer.setNumAlignmentEntriesPerChunk(1000);
        final int numTargets = 2;
        final int numQuery = 10;
        int position = 1;
        int score = 30;
        final IndexedIdentifier targetIds = new IndexedIdentifier();
        for (int i = 0; i < numTargets; i++) {
            targetIds.registerIdentifier(new MutableString("target-" + i));
        }

        writer.setTargetIdentifiers(targetIds);

        for (int targetIndex = 0; targetIndex < numTargets; targetIndex++) {
            for (int queryIndex = 0; queryIndex < numQuery; queryIndex++) {
                writer.setAlignmentEntry(queryIndex, targetIndex, position++, score++, false,
                        constantQueryLength);
                //         System.out.println(String.format("Preparing entry: queryIndex: %d targetIndex: %d position: %d score: %d strand: %b", queryIndex, targetIndex, position++, score++, false));
                writer.appendEntry();

                numEntriesIn105++;
            }
        }
        numQueries105 = numQuery;

        writer.close();
    }

    {
        // Will have too many hits info created for it:
        final AlignmentWriterImpl writer = new AlignmentWriterImpl(
                FilenameUtils.concat(BASE_TEST_DIR, "align-106"));
        writer.setNumAlignmentEntriesPerChunk(1000);
        final int numTargets = 2;
        final int numQuery = 10;
        int position = 1;
        int score = 30;
        final IndexedIdentifier targetIds = new IndexedIdentifier();
        for (int i = 0; i < numTargets; i++) {
            targetIds.registerIdentifier(new MutableString("target-b-" + i));
        }

        writer.setTargetIdentifiers(targetIds);

        for (int targetIndex = 0; targetIndex < numTargets; targetIndex++) {
            for (int queryIndex = 0; queryIndex < numQuery; queryIndex++) {
                writer.setAlignmentEntry(queryIndex, targetIndex, position++, score++, false,
                        constantQueryLength);
                writer.appendEntry();
                numEntriesIn106++;
            }
        }
        numQueries106 = numQuery;

        writer.close();
    }
}

From source file:com.enderville.enderinstaller.ui.Installer.java

private void loadModDescription(String modName) {
    JPanel p = getModDescriptionPane();
    p.removeAll();/*from ww  w.  ja  v  a2 s . c  o  m*/
    p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));

    final String extras = InstallerConfig.getExtraModsFolder();
    final String modFolderName = FilenameUtils.concat(extras, modName);
    File modFolder = new File(modFolderName);
    if (!modFolder.exists()) {
        LOGGER.error("Mod folder for " + modName + " does not exist.");
    }
    File descrFile = new File(FilenameUtils.concat(modFolderName, "description.txt"));
    File imgFile = new File(FilenameUtils.concat(modFolderName, "image.png"));
    if (!descrFile.exists() && !imgFile.exists()) {
        p.add(new JLabel("<html>No description for:<br>" + modName + "</html>"));
    } else {
        if (imgFile.exists()) {
            try {
                JLabel label = new JLabel();
                BufferedImage img = ImageIO.read(imgFile);
                label.setIcon(new ImageIcon(img));
                p.add(label);
            } catch (IOException e) {
                LOGGER.error("Error reading image file: " + imgFile.getPath(), e);
            }
        }
        if (descrFile.exists()) {
            StringBuilder buffer = new StringBuilder();
            try {
                BufferedReader r = new BufferedReader(new FileReader(descrFile));
                String l = null;
                while ((l = r.readLine()) != null) {
                    buffer.append(l + "\n");
                }
                r.close();
                JEditorPane area = new JEditorPane();
                area.setContentType("text/html");
                area.setText(buffer.toString());
                area.setEditable(false);
                area.addHyperlinkListener(this);
                area.setCaretPosition(0);
                p.add(new JScrollPane(area));
            } catch (IOException e) {
                LOGGER.error("Error reading description file: " + descrFile.getPath(), e);
            }
        }
    }

    p.validate();
    p.repaint();
}

From source file:es.urjc.mctwp.image.impl.dicom.DicomImagePlugin.java

/**
 * Obtains a DICOM representation for single image
 * //  w ww.  jav  a 2 s .  c om
 * @param single
 * @return
 * @throws ImageException
 */
private List<File> toDicom(SingleImage single, File outputDir) throws ImageException {
    List<File> result = new ArrayList<File>();
    File content = single.getContent();

    try {

        String ext = StringUtils.substringAfterLast(content.getName(), FilenameUtils.EXTENSION_SEPARATOR_STR);
        if (ext == null)
            ext = SingleImageDicomImpl.DCM_EXT;
        File dest = new File(FilenameUtils.concat(outputDir.getAbsolutePath(),
                single.getId() + FilenameUtils.EXTENSION_SEPARATOR_STR + ext));
        FileUtils.copyFile(content, dest);
        result.add(dest);

    } catch (Exception e) {
        logger.error(e.getMessage());
        throw new ImageException(e);
    }

    return result;
}

From source file:edu.cornell.med.icb.goby.modes.TestSplicedSamHelper.java

@Test
public void testSamToCompactTrickCase7() throws IOException {

    SAMToCompactMode importer = new SAMToCompactMode();
    importer.setInputFile("test-data/splicedsamhelper/tricky-spliced-7.sam");
    final String outputFilename = FilenameUtils.concat(BASE_TEST_DIR, "spliced-output-alignment-7");
    importer.setOutputFile(outputFilename);
    String[] refs = { "NNNNNNTTAGAAAAACAGAGAGAGAAGGAGAGTAAAGGGAGGAGGCGGAGGAGGAGAAAAGAAGAAAGCAGAGANNNNNN" };

    RandomAccessSequenceTestSupport genomeTestSupport = new RandomAccessSequenceTestSupport(refs);
    importer.setGenome(genomeTestSupport);

    importer.execute();//from w  w  w .j  a  v  a  2  s  .co m

    AlignmentReader reader = new AlignmentReaderImpl(outputFilename);
    assertTrue(reader.hasNext());
    Alignments.AlignmentEntry first = reader.next();

    assertEquals(0, first.getQueryIndex());
    assertEquals(0, first.getFragmentIndex());
    assertEquals(8 - 1, first.getPosition());

}