use of de.bioforscher.jstructure.align.result.score.RootMeanSquareDeviation 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);
}
}
use of de.bioforscher.jstructure.align.result.score.RootMeanSquareDeviation 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);
}
}
use of de.bioforscher.jstructure.align.result.score.RootMeanSquareDeviation 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);
}
}
Aggregations