Search in sources :

Example 1 with GenericStreamConsumer

use of ubic.gemma.core.util.concurrent.GenericStreamConsumer in project Gemma by PavlidisLab.

the class RepeatScan method execRepeatMasker.

/**
 * Run a gfClient query, using a call to exec().
 *
 * @param querySequenceFile file
 * @param taxon             taxon
 */
private void execRepeatMasker(File querySequenceFile, Taxon taxon) throws IOException {
    this.checkForExe();
    final String cmd = RepeatScan.REPEAT_MASKER + " -parallel 8 -xsmall -species " + taxon.getCommonName() + " " + querySequenceFile.getAbsolutePath();
    RepeatScan.log.info("Running repeatmasker like this: " + cmd);
    final Process run = Runtime.getRuntime().exec(cmd);
    // to ensure that we aren't left waiting for these streams
    GenericStreamConsumer gscErr = new GenericStreamConsumer(run.getErrorStream());
    GenericStreamConsumer gscIn = new GenericStreamConsumer(run.getInputStream());
    gscErr.start();
    gscIn.start();
    try {
        int exitVal = Integer.MIN_VALUE;
        // wait...
        StopWatch overallWatch = new StopWatch();
        overallWatch.start();
        while (exitVal == Integer.MIN_VALUE) {
            try {
                exitVal = run.exitValue();
            } catch (IllegalThreadStateException e) {
            // okay, still waiting.
            }
            Thread.sleep(RepeatScan.UPDATE_INTERVAL_MS);
            String minutes = TimeUtil.getMinutesElapsed(overallWatch);
            RepeatScan.log.info("Repeatmasker: " + minutes + " minutes elapsed");
        }
        overallWatch.stop();
        String minutes = TimeUtil.getMinutesElapsed(overallWatch);
        RepeatScan.log.info("Repeatmasker took a total of " + minutes + " minutes");
        // int exitVal = run.waitFor();
        RepeatScan.log.debug("Repeatmasker exit value=" + exitVal);
    } catch (InterruptedException e) {
        throw new RuntimeException(e);
    }
    RepeatScan.log.debug("Repeatmasker Success");
}
Also used : GenericStreamConsumer(ubic.gemma.core.util.concurrent.GenericStreamConsumer) StopWatch(org.apache.commons.lang3.time.StopWatch)

Example 2 with GenericStreamConsumer

use of ubic.gemma.core.util.concurrent.GenericStreamConsumer in project Gemma by PavlidisLab.

the class AffyPowerToolsProbesetSummarize method tryRun.

private Collection<RawExpressionDataVector> tryRun(ExpressionExperiment ee, ArrayDesign targetPlatform, Collection<LocalFile> files, Collection<String> accessionsOfInterest, boolean threePrime, String cdfFileName) {
    List<String> celFiles = this.getCelFiles(files, accessionsOfInterest);
    AffyPowerToolsProbesetSummarize.log.info("Located " + celFiles.size() + " cel files");
    String outputPath = this.getOutputFilePath(ee);
    String cmd;
    if (threePrime) {
        cmd = this.getThreePrimeSummarizationCommand(targetPlatform, cdfFileName, celFiles, outputPath);
    } else {
        cmd = this.getCommand(targetPlatform, celFiles, outputPath);
    }
    AffyPowerToolsProbesetSummarize.log.info("Running: " + cmd);
    int exitVal = Integer.MIN_VALUE;
    StopWatch overallWatch = new StopWatch();
    overallWatch.start();
    try {
        final Process run = Runtime.getRuntime().exec(cmd);
        GenericStreamConsumer gscErr = new GenericStreamConsumer(run.getErrorStream());
        GenericStreamConsumer gscIn = new GenericStreamConsumer(run.getInputStream());
        gscErr.start();
        gscIn.start();
        while (exitVal == Integer.MIN_VALUE) {
            try {
                exitVal = run.exitValue();
            } catch (IllegalThreadStateException e) {
            // okay, still waiting.
            }
            Thread.sleep(AffyPowerToolsProbesetSummarize.AFFY_UPDATE_INTERVAL_MS);
            File outputFile = new File(outputPath + File.separator + "apt-probeset-summarize.log");
            Long size = outputFile.length();
            String minutes = TimeUtil.getMinutesElapsed(overallWatch);
            AffyPowerToolsProbesetSummarize.log.info(String.format("apt-probeset-summarize logging output so far: %.2f", size / 1024.0) + " kb (" + minutes + " minutes elapsed)");
        }
        overallWatch.stop();
        String minutes = TimeUtil.getMinutesElapsed(overallWatch);
        AffyPowerToolsProbesetSummarize.log.info("apt-probeset-summarize took a total of " + minutes + " minutes");
        return this.processData(ee, outputPath + File.separator + AffyPowerToolsProbesetSummarize.METHOD + ".summary.txt", targetPlatform);
    } catch (InterruptedException | IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : StopWatch(org.apache.commons.lang3.time.StopWatch) GenericStreamConsumer(ubic.gemma.core.util.concurrent.GenericStreamConsumer) LocalFile(ubic.gemma.model.common.description.LocalFile)

Example 3 with GenericStreamConsumer

use of ubic.gemma.core.util.concurrent.GenericStreamConsumer in project Gemma by PavlidisLab.

the class SimpleFastaCmd method getSequencesFromFastaCmdOutput.

private Collection<BioSequence> getSequencesFromFastaCmdOutput(Process pr) throws IOException {
    try (final InputStream is = new BufferedInputStream(pr.getInputStream());
        InputStream err = pr.getErrorStream()) {
        final FastaParser parser = new FastaParser();
        ParsingStreamConsumer<BioSequence> sg = new ParsingStreamConsumer<>(parser, is);
        GenericStreamConsumer gsc = new GenericStreamConsumer(err);
        sg.start();
        gsc.start();
        try {
            int exitVal = pr.waitFor();
            // Makes sure results are flushed.
            Thread.sleep(200);
            SimpleFastaCmd.log.debug(// often nonzero if some sequences are not found.
            "fastacmd exit value=" + exitVal);
            return parser.getResults();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
}
Also used : BioSequence(ubic.gemma.model.genome.biosequence.BioSequence) ParsingStreamConsumer(ubic.gemma.core.util.concurrent.ParsingStreamConsumer) GenericStreamConsumer(ubic.gemma.core.util.concurrent.GenericStreamConsumer)

Example 4 with GenericStreamConsumer

use of ubic.gemma.core.util.concurrent.GenericStreamConsumer in project Gemma by PavlidisLab.

the class ShellDelegatingBlat method execGfClient.

/**
 * Run a gfClient query, using a call to exec().
 *
 * @param querySequenceFile query sequence file
 * @param outputPath        output path
 * @return collection of blat results
 */
private Collection<BlatResult> execGfClient(File querySequenceFile, String outputPath, int portToUse) throws IOException {
    final String cmd = gfClientExe + " -nohead -minScore=" + ShellDelegatingBlat.MIN_SCORE + " " + host + " " + portToUse + " " + seqDir + " " + querySequenceFile.getAbsolutePath() + " " + outputPath;
    ShellDelegatingBlat.log.info(cmd);
    final Process run = Runtime.getRuntime().exec(cmd);
    // to ensure that we aren't left waiting for these streams
    GenericStreamConsumer gscErr = new GenericStreamConsumer(run.getErrorStream());
    GenericStreamConsumer gscIn = new GenericStreamConsumer(run.getInputStream());
    gscErr.start();
    gscIn.start();
    try {
        int exitVal = Integer.MIN_VALUE;
        // wait...
        StopWatch overallWatch = new StopWatch();
        overallWatch.start();
        while (exitVal == Integer.MIN_VALUE) {
            try {
                exitVal = run.exitValue();
            } catch (IllegalThreadStateException e) {
            // okay, still
            // waiting.
            }
            Thread.sleep(ShellDelegatingBlat.BLAT_UPDATE_INTERVAL_MS);
            // I hope this is okay...
            this.outputFile(outputPath, overallWatch);
        }
        overallWatch.stop();
        String minutes = TimeUtil.getMinutesElapsed(overallWatch);
        ShellDelegatingBlat.log.info("Blat took a total of " + minutes + " minutes");
        // int exitVal = run.waitFor();
        ShellDelegatingBlat.log.debug("blat exit value=" + exitVal);
    } catch (InterruptedException e) {
        throw new RuntimeException(e);
    }
    ShellDelegatingBlat.log.debug("GfClient Success");
    return this.processPsl(outputPath, null);
}
Also used : GenericStreamConsumer(ubic.gemma.core.util.concurrent.GenericStreamConsumer) StopWatch(org.apache.commons.lang3.time.StopWatch)

Aggregations

GenericStreamConsumer (ubic.gemma.core.util.concurrent.GenericStreamConsumer)4 StopWatch (org.apache.commons.lang3.time.StopWatch)3 ParsingStreamConsumer (ubic.gemma.core.util.concurrent.ParsingStreamConsumer)1 LocalFile (ubic.gemma.model.common.description.LocalFile)1 BioSequence (ubic.gemma.model.genome.biosequence.BioSequence)1