Search in sources :

Example 1 with TemplateModelingScore

use of de.bioforscher.jstructure.align.result.score.TemplateModelingScore in project jstructure by JonStargaryen.

the class ContactTogglingReconstruction method computePerformance.

private void computePerformance(List<Chain> reconstructions) throws AlignmentException, IOException {
    List<TMAlignAlignmentResult> alignmentResults = new ArrayList<>();
    List<ReconstructionContactMap> reconstructionContactMaps = new ArrayList<>();
    List<Path> tmpFiles = new ArrayList<>();
    for (Chain reconstructedChain : reconstructions) {
        Path reconstructPath = Files.createTempFile("confoldservice-recon", ".pdb");
        tmpFiles.add(reconstructPath);
        Files.write(reconstructPath, reconstructedChain.getPdbRepresentation().getBytes());
        alignmentResults.add(TM_ALIGN_SERVICE.process(new String[] { baselineReconstruction.getTmalignPath(), baselineReconstruction.getReferenceChainPath().toFile().getAbsolutePath(), reconstructPath.toFile().getAbsolutePath() }));
        reconstructionContactMaps.add(ReconstructionContactMap.createReconstructionContactMap(reconstructedChain, baselineReconstruction.getFullMap().getContactDefinition()));
    }
    averageRmsd = alignmentResults.stream().map(TMAlignAlignmentResult::getRootMeanSquareDeviation).mapToDouble(RootMeanSquareDeviation::getScore).average().orElseThrow(() -> new ComputationException("could not generate toggled reconstructs"));
    averageTmScore = alignmentResults.stream().map(TMAlignAlignmentResult::getTemplateModelingScore1).mapToDouble(TemplateModelingScore::getScore).average().orElseThrow(() -> new ComputationException("could not generate toggled reconstructs"));
    averageQ = reconstructionContactMaps.stream().mapToDouble(reconstructContactMap -> BaselineReconstruction.computeQ(baselineReconstruction.getFullMap(), reconstructContactMap)).average().orElseThrow(() -> new ComputationException("could not generate toggled reconstructs"));
    logger.info("[{} / {}]: {} reconstruction of contact {}", counter, numberOfCombinations, contactWasRemoved ? "removal" : "addition", contactToToggle);
    logger.info("[{} / {}]: average RMSD: {}, average TM-score: {}, average Q: {}", counter, numberOfCombinations, StandardFormat.format(averageRmsd), StandardFormat.format(averageTmScore), StandardFormat.format(averageQ));
    if (contactWasRemoved) {
        decreaseRmsd = averageRmsd - baselineReconstruction.getAverageRmsd();
        increaseTMScore = baselineReconstruction.getAverageTmScore() - averageTmScore;
        increaseQ = baselineReconstruction.getAverageQ() - averageQ;
    } else {
        decreaseRmsd = baselineReconstruction.getAverageRmsd() - averageRmsd;
        increaseTMScore = averageTmScore - baselineReconstruction.getAverageTmScore();
        increaseQ = averageQ - baselineReconstruction.getAverageQ();
    }
    logger.info("[{} / {}]: decrease RMSD: {}, increase TM-score: {}, increase Q: {}", counter, numberOfCombinations, StandardFormat.format(decreaseRmsd), StandardFormat.format(increaseTMScore), StandardFormat.format(increaseQ));
    // cleanup
    for (Path tmpFile : tmpFiles) {
        Files.delete(tmpFile);
    }
}
Also used : Path(java.nio.file.Path) Logger(org.slf4j.Logger) ComputationException(de.bioforscher.jstructure.model.feature.ComputationException) Files(java.nio.file.Files) TMAlignService(de.bioforscher.jstructure.align.impl.TMAlignService) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) Callable(java.util.concurrent.Callable) Pair(de.bioforscher.jstructure.mathematics.Pair) ArrayList(java.util.ArrayList) ConfoldServiceWorker(de.bioforscher.jstructure.si.ConfoldServiceWorker) TMAlignAlignmentResult(de.bioforscher.jstructure.align.result.TMAlignAlignmentResult) List(java.util.List) AminoAcid(de.bioforscher.jstructure.model.structure.aminoacid.AminoAcid) Chain(de.bioforscher.jstructure.model.structure.Chain) StandardFormat(de.bioforscher.jstructure.StandardFormat) ReconstructionContactMap(de.bioforscher.jstructure.graph.ReconstructionContactMap) TemplateModelingScore(de.bioforscher.jstructure.align.result.score.TemplateModelingScore) Path(java.nio.file.Path) AlignmentException(de.bioforscher.jstructure.align.AlignmentException) RootMeanSquareDeviation(de.bioforscher.jstructure.align.result.score.RootMeanSquareDeviation) TMAlignAlignmentResult(de.bioforscher.jstructure.align.result.TMAlignAlignmentResult) Chain(de.bioforscher.jstructure.model.structure.Chain) ReconstructionContactMap(de.bioforscher.jstructure.graph.ReconstructionContactMap) ComputationException(de.bioforscher.jstructure.model.feature.ComputationException) ArrayList(java.util.ArrayList)

Example 2 with TemplateModelingScore

use of de.bioforscher.jstructure.align.result.score.TemplateModelingScore 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)

Example 3 with TemplateModelingScore

use of de.bioforscher.jstructure.align.result.score.TemplateModelingScore in project jstructure by JonStargaryen.

the class BaselineReconstruction method computeBaselinePerformance.

private void computeBaselinePerformance(List<Chain> reconstructions) throws AlignmentException, IOException {
    List<TMAlignAlignmentResult> alignmentResults = new ArrayList<>();
    List<ReconstructionContactMap> reconstructionContactMaps = new ArrayList<>();
    List<Path> tmpFiles = new ArrayList<>();
    if (reconstructions.isEmpty()) {
        throw new ComputationException("reconstruction did not yield any reconstructs");
    }
    for (Chain reconstructedChain : reconstructions) {
        Path reconstructPath = Files.createTempFile("confoldservice-recon", ".pdb");
        tmpFiles.add(reconstructPath);
        Files.write(reconstructPath, reconstructedChain.getPdbRepresentation().getBytes());
        alignmentResults.add(TM_ALIGN_SERVICE.process(new String[] { tmalignPath, referenceChainPath.toFile().getAbsolutePath(), reconstructPath.toFile().getAbsolutePath() }));
        reconstructionContactMaps.add(ReconstructionContactMap.createReconstructionContactMap(reconstructedChain, fullMap.getContactDefinition()));
    }
    if (alignmentResults.isEmpty()) {
        throw new ComputationException("tmalign did not yield any alignments");
    }
    averageRmsd = alignmentResults.stream().map(TMAlignAlignmentResult::getRootMeanSquareDeviation).mapToDouble(RootMeanSquareDeviation::getScore).average().getAsDouble();
    averageTmScore = alignmentResults.stream().map(TMAlignAlignmentResult::getTemplateModelingScore1).mapToDouble(TemplateModelingScore::getScore).average().getAsDouble();
    averageQ = reconstructionContactMaps.stream().mapToDouble(reconstructContactMap -> computeQ(fullMap, reconstructContactMap)).average().getAsDouble();
    logger.info("baseline reconstruction {} - average RMSD: {}, average TM-score: {}, average Q: {}", iteration, StandardFormat.format(averageRmsd), StandardFormat.format(averageTmScore), StandardFormat.format(averageQ));
    // cleanup
    for (Path tmpFile : tmpFiles) {
        Files.delete(tmpFile);
    }
}
Also used : Path(java.nio.file.Path) Logger(org.slf4j.Logger) ComputationException(de.bioforscher.jstructure.model.feature.ComputationException) Files(java.nio.file.Files) TMAlignService(de.bioforscher.jstructure.align.impl.TMAlignService) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) Callable(java.util.concurrent.Callable) Collectors(java.util.stream.Collectors) Pair(de.bioforscher.jstructure.mathematics.Pair) ArrayList(java.util.ArrayList) ConfoldServiceWorker(de.bioforscher.jstructure.si.ConfoldServiceWorker) TMAlignAlignmentResult(de.bioforscher.jstructure.align.result.TMAlignAlignmentResult) List(java.util.List) AminoAcid(de.bioforscher.jstructure.model.structure.aminoacid.AminoAcid) Chain(de.bioforscher.jstructure.model.structure.Chain) StandardFormat(de.bioforscher.jstructure.StandardFormat) ReconstructionContactMap(de.bioforscher.jstructure.graph.ReconstructionContactMap) TemplateModelingScore(de.bioforscher.jstructure.align.result.score.TemplateModelingScore) Path(java.nio.file.Path) Collections(java.util.Collections) AlignmentException(de.bioforscher.jstructure.align.AlignmentException) RootMeanSquareDeviation(de.bioforscher.jstructure.align.result.score.RootMeanSquareDeviation) TMAlignAlignmentResult(de.bioforscher.jstructure.align.result.TMAlignAlignmentResult) Chain(de.bioforscher.jstructure.model.structure.Chain) ReconstructionContactMap(de.bioforscher.jstructure.graph.ReconstructionContactMap) ComputationException(de.bioforscher.jstructure.model.feature.ComputationException) ArrayList(java.util.ArrayList)

Aggregations

AlignmentException (de.bioforscher.jstructure.align.AlignmentException)3 TMAlignAlignmentResult (de.bioforscher.jstructure.align.result.TMAlignAlignmentResult)3 RootMeanSquareDeviation (de.bioforscher.jstructure.align.result.score.RootMeanSquareDeviation)3 TemplateModelingScore (de.bioforscher.jstructure.align.result.score.TemplateModelingScore)3 ComputationException (de.bioforscher.jstructure.model.feature.ComputationException)3 IOException (java.io.IOException)3 StandardFormat (de.bioforscher.jstructure.StandardFormat)2 TMAlignService (de.bioforscher.jstructure.align.impl.TMAlignService)2 ReconstructionContactMap (de.bioforscher.jstructure.graph.ReconstructionContactMap)2 Pair (de.bioforscher.jstructure.mathematics.Pair)2 Chain (de.bioforscher.jstructure.model.structure.Chain)2 AminoAcid (de.bioforscher.jstructure.model.structure.aminoacid.AminoAcid)2 ConfoldServiceWorker (de.bioforscher.jstructure.si.ConfoldServiceWorker)2 Files (java.nio.file.Files)2 Path (java.nio.file.Path)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Callable (java.util.concurrent.Callable)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2