Search in sources :

Example 6 with AlignmentException

use of de.bioforscher.jstructure.align.AlignmentException in project jstructure by JonStargaryen.

the class TMAlignService method process.

private synchronized TMAlignAlignmentResult process(String[] arguments, int run) throws AlignmentException {
    try {
        logger.debug("spawning tmalign process with arguments:{}{}", System.lineSeparator(), arguments);
        ProcessBuilder processBuilder = new ProcessBuilder(arguments);
        Process process = processBuilder.start();
        List<String> outputLines;
        try (BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
            outputLines = br.lines().collect(Collectors.toList());
        }
        List<String> errorLines;
        try (BufferedReader br = new BufferedReader(new InputStreamReader(process.getErrorStream()))) {
            errorLines = br.lines().collect(Collectors.toList());
        }
        process.waitFor();
        if (outputLines.stream().anyMatch(line -> line.startsWith("Can not open file:"))) {
            throw new ComputationException("error during tmalign execution:" + System.lineSeparator() + outputLines.stream().collect(Collectors.joining(System.lineSeparator())));
        }
        // errors are not reported in error stream
        if (!errorLines.isEmpty()) {
            throw new ComputationException("error during tmalign execution:" + System.lineSeparator() + errorLines.stream().collect(Collectors.joining(System.lineSeparator())));
        }
        int length1 = 0;
        int length2 = 0;
        int alignedLength = 0;
        RootMeanSquareDeviation rootMeanSquareDeviation = null;
        double seqId = 0;
        TemplateModelingScore templateModelingScore1 = null;
        TemplateModelingScore templateModelingScore2 = null;
        for (String outputLine : outputLines) {
            if (outputLine.startsWith("Length of Chain_1")) {
                length1 = Integer.valueOf(outputLine.split(":")[1].trim().split("\\s+")[0]);
            } else if (outputLine.startsWith("Length of Chain_2")) {
                length2 = Integer.valueOf(outputLine.split(":")[1].trim().split("\\s+")[0]);
            } else if (outputLine.startsWith("Aligned length")) {
                String[] split = outputLine.split("=");
                alignedLength = Integer.valueOf(split[1].split(",")[0].trim());
                rootMeanSquareDeviation = new RootMeanSquareDeviation(Double.valueOf(split[2].split(",")[0].trim()));
                seqId = Double.valueOf(split[4].trim());
            } else if (outputLine.startsWith("TM-score")) {
                double tmscore = Double.valueOf(outputLine.split("=")[1].split("\\(")[0].trim());
                TemplateModelingScore templateModelingScore = new TemplateModelingScore(tmscore);
                if (outputLine.contains("Chain_1")) {
                    templateModelingScore1 = templateModelingScore;
                } else {
                    templateModelingScore2 = templateModelingScore;
                }
            }
        }
        return new TMAlignAlignmentResult(length1, length2, alignedLength, rootMeanSquareDeviation, seqId, templateModelingScore1, templateModelingScore2);
    } catch (Exception e) {
        if (run > 3) {
            logger.warn("tmalign computation finally failed:{}{}", System.lineSeparator(), Arrays.toString(arguments), e);
            throw new AlignmentException("could not run tmalign", e);
        }
        return process(arguments, run + 1);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) AlignmentException(de.bioforscher.jstructure.align.AlignmentException) ComputationException(de.bioforscher.jstructure.model.feature.ComputationException) IOException(java.io.IOException) AlignmentException(de.bioforscher.jstructure.align.AlignmentException) TemplateModelingScore(de.bioforscher.jstructure.align.result.score.TemplateModelingScore) TMAlignAlignmentResult(de.bioforscher.jstructure.align.result.TMAlignAlignmentResult) RootMeanSquareDeviation(de.bioforscher.jstructure.align.result.score.RootMeanSquareDeviation) ComputationException(de.bioforscher.jstructure.model.feature.ComputationException) BufferedReader(java.io.BufferedReader)

Aggregations

AlignmentException (de.bioforscher.jstructure.align.AlignmentException)6 TMAlignAlignmentResult (de.bioforscher.jstructure.align.result.TMAlignAlignmentResult)6 IOException (java.io.IOException)6 ComputationException (de.bioforscher.jstructure.model.feature.ComputationException)5 Path (java.nio.file.Path)5 TMAlignService (de.bioforscher.jstructure.align.impl.TMAlignService)4 ReconstructionContactMap (de.bioforscher.jstructure.graph.ReconstructionContactMap)4 Pair (de.bioforscher.jstructure.mathematics.Pair)4 Chain (de.bioforscher.jstructure.model.structure.Chain)4 AminoAcid (de.bioforscher.jstructure.model.structure.aminoacid.AminoAcid)4 ConfoldServiceWorker (de.bioforscher.jstructure.si.ConfoldServiceWorker)4 Files (java.nio.file.Files)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4 RootMeanSquareDeviation (de.bioforscher.jstructure.align.result.score.RootMeanSquareDeviation)3 TemplateModelingScore (de.bioforscher.jstructure.align.result.score.TemplateModelingScore)3 Collectors (java.util.stream.Collectors)3 StandardFormat (de.bioforscher.jstructure.StandardFormat)2 ContactDefinitionFactory (de.bioforscher.jstructure.graph.contact.definition.ContactDefinitionFactory)2 ExplorerChain (de.bioforscher.jstructure.si.explorer.ExplorerChain)2