Search in sources :

Example 11 with ComputationException

use of de.bioforscher.jstructure.model.feature.ComputationException in project jstructure by JonStargaryen.

the class ProteinLigandInteractionProfiler method annotatePolymerInteractions.

private InteractionContainer annotatePolymerInteractions(Chain chain) {
    try {
        Path outputDirectoryPath = createTemporaryOutputDirectory();
        Structure structure = chain.getParentStructure();
        String[] commandLineCall = composePolymerCommandLineCall(structure, outputDirectoryPath, chain.getChainIdentifier().getChainId());
        // execute command
        executeCommandLineCall(commandLineCall);
        Path outputPath = outputDirectoryPath.resolve("report.xml");
        Document document = Jsoup.parse(outputPath.toFile(), "UTF-8");
        return parseDocument(structure, document);
    } catch (Exception e) {
        throw new ComputationException(e);
    }
}
Also used : Path(java.nio.file.Path) ComputationException(de.bioforscher.jstructure.model.feature.ComputationException) Structure(de.bioforscher.jstructure.model.structure.Structure) Document(org.jsoup.nodes.Document) ComputationException(de.bioforscher.jstructure.model.feature.ComputationException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException)

Example 12 with ComputationException

use of de.bioforscher.jstructure.model.feature.ComputationException in project jstructure by JonStargaryen.

the class SiftsMappingAnnotator method processInternally.

@Override
protected void processInternally(Structure protein) {
    try {
        Document document = downloadXml(protein.getProteinIdentifier().getPdbId());
        protein.chainsWithAminoAcids().forEach(chain -> processInternally(document, chain));
    } catch (NullPointerException e) {
        throw new ComputationException("protein did not provide pdbId, thus, cannot be mapped to UniProt");
    }
}
Also used : ComputationException(de.bioforscher.jstructure.model.feature.ComputationException) Document(org.jsoup.nodes.Document)

Example 13 with ComputationException

use of de.bioforscher.jstructure.model.feature.ComputationException 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 14 with ComputationException

use of de.bioforscher.jstructure.model.feature.ComputationException in project jstructure by JonStargaryen.

the class A03_WriteDatasetCsv method handleLine.

private static Optional<String> handleLine(String line) {
    try {
        System.out.println(line);
        String[] split = line.split(";");
        String entryId = split[0];
        String pdbId = split[1];
        List<Integer> experimentIds = Pattern.compile(",").splitAsStream(split[2].replaceAll("\\[", "").replaceAll("]", "")).map(Integer::valueOf).collect(Collectors.toList());
        Structure structure = StructureParser.fromPdbId(pdbId).parse();
        Chain chain = structure.chains().findFirst().get();
        Start2FoldXmlParser.parseSpecificExperiment(chain, Start2FoldConstants.XML_DIRECTORY.resolve(entryId + ".xml"), experimentIds);
        EvolutionaryCouplingParser.parseHotSpotFile(chain, Start2FoldConstants.COUPLING_DIRECTORY.resolve(entryId.toUpperCase() + "_hs.html"));
        EQuantParser.parseEQuantFile(chain, Start2FoldConstants.EQUANT_DIRECTORY.resolve(entryId.toLowerCase() + ".equant-small.txt"));
        List<AminoAcid> earlyFoldingResidues = chain.aminoAcids().filter(aminoAcid -> aminoAcid.getFeature(Start2FoldResidueAnnotation.class).isEarly()).collect(Collectors.toList());
        List<Integer> functionalResidueNumbers = Start2FoldConstants.extractFunctioanlResidueNumbers(split);
        List<AminoAcid> functionalResidues = new ArrayList<>();
        // do nothing if no annotation of functional residues exists
        if (!functionalResidueNumbers.isEmpty()) {
            FunctionalResidueParser.parse(chain, functionalResidueNumbers);
            chain.aminoAcids().filter(aminoAcid -> aminoAcid.getFeature(FunctionalResidueAnnotation.class).isFunctional()).forEach(functionalResidues::add);
        }
        List<AminoAcid> aminoAcids = chain.aminoAcids().collect(Collectors.toList());
        ProteinGraph conventionalProteinGraph = ProteinGraphFactory.createProteinGraph(chain, ProteinGraphFactory.InteractionScheme.CALPHA8);
        return Optional.of(chain.aminoAcids().map(aminoAcid -> {
            GenericSecondaryStructure sse = aminoAcid.getFeature(GenericSecondaryStructure.class);
            HotSpotScoring hotSpotScoring = aminoAcid.getFeature(HotSpotScoring.class);
            PLIPInteractionContainer plipInteractionContainer = aminoAcid.getFeature(PLIPInteractionContainer.class);
            PLIPInteractionContainer nonLocalPlipInteractionContainer = new PLIPInteractionContainer(null, plipInteractionContainer.getInteractions().stream().filter(inter -> Math.abs(inter.getPartner1().getResidueIndex() - inter.getPartner2().getResidueIndex()) > 5).collect(Collectors.toList()));
            PLIPInteractionContainer localPlipInteractionContainer = new PLIPInteractionContainer(null, plipInteractionContainer.getInteractions().stream().filter(inter -> !nonLocalPlipInteractionContainer.getInteractions().contains(inter)).collect(Collectors.toList()));
            String equantScore = "NA";
            try {
                equantScore = StandardFormat.format(aminoAcid.getFeature(EQuantScore.class).getEvaluation());
            } catch (ComputationException e) {
                logger.warn("missing equant scoring for {}", aminoAcid);
            }
            String functionalAnnotation = "NA";
            if (functionalResidues.size() > 0) {
                functionalAnnotation = functionalResidues.contains(aminoAcid) ? "functional" : "non-functional";
            }
            ResidueTopologicPropertiesContainer residueTopologicPropertiesContainer = aminoAcid.getFeature(ResidueTopologicPropertiesContainer.class);
            double terminusDistance = aminoAcids.indexOf(aminoAcid);
            terminusDistance = Math.min(terminusDistance, aminoAcids.size() - terminusDistance);
            terminusDistance /= (double) aminoAcids.size();
            return pdbId + "," + "A" + "," + aminoAcid.getResidueIdentifier() + "," + aminoAcid.getOneLetterCode() + "," + sse.getSecondaryStructure().getReducedRepresentation() + "," + sse.getSecondaryStructure().getOneLetterRepresentation() + "," + sse.getSurroundingSecondaryStructureElement(aminoAcid).getSize() + "," + (aminoAcid.getFeature(AccessibleSurfaceArea.class).isExposed() ? "exposed" : "buried") + "," + StandardFormat.format(aminoAcid.getFeature(GeometricProperties.class).getDistanceToCentroid()) + "," + StandardFormat.format(terminusDistance) + "," + plipInteractionContainer.getHydrogenBonds().size() + "," + plipInteractionContainer.getHydrophobicInteractions().size() + "," + plipInteractionContainer.getBackboneInteractions().size() + "," + plipInteractionContainer.getInteractions().size() + "," + localPlipInteractionContainer.getHydrogenBonds().size() + "," + localPlipInteractionContainer.getHydrophobicInteractions().size() + "," + localPlipInteractionContainer.getBackboneInteractions().size() + "," + localPlipInteractionContainer.getInteractions().size() + "," + nonLocalPlipInteractionContainer.getHydrogenBonds().size() + "," + nonLocalPlipInteractionContainer.getHydrophobicInteractions().size() + "," + nonLocalPlipInteractionContainer.getBackboneInteractions().size() + "," + nonLocalPlipInteractionContainer.getInteractions().size() + "," + StandardFormat.format(aminoAcid.getFeature(EnergyProfile.class).getSolvationEnergy()) + "," + StandardFormat.format(aminoAcid.getFeature(EgorAgreement.class).getEgorPrediction()) + "," + equantScore + "," + StandardFormat.format(aminoAcid.getFeature(AccessibleSurfaceArea.class).getRelativeAccessibleSurfaceArea()) + "," + StandardFormat.format(aminoAcid.getFeature(LoopFraction.class).getLoopFraction()) + "," + hotSpotScoring.getEcCount() + "," + StandardFormat.format(hotSpotScoring.getCumStrength()) + "," + StandardFormat.format(hotSpotScoring.getEcStrength()) + "," + hotSpotScoring.getConservation() + "," + StandardFormat.format(residueTopologicPropertiesContainer.getFullPlip().getBetweenness()) + "," + StandardFormat.format(residueTopologicPropertiesContainer.getFullPlip().getCloseness()) + "," + StandardFormat.format(residueTopologicPropertiesContainer.getFullPlip().getClusteringCoefficient()) + "," + StandardFormat.format(residueTopologicPropertiesContainer.getHydrogenPlip().getBetweenness()) + "," + StandardFormat.format(residueTopologicPropertiesContainer.getHydrogenPlip().getCloseness()) + "," + StandardFormat.format(residueTopologicPropertiesContainer.getHydrogenPlip().getClusteringCoefficient()) + "," + StandardFormat.format(residueTopologicPropertiesContainer.getHydrophobicPlip().getBetweenness()) + "," + StandardFormat.format(residueTopologicPropertiesContainer.getHydrophobicPlip().getCloseness()) + "," + StandardFormat.format(residueTopologicPropertiesContainer.getHydrophobicPlip().getClusteringCoefficient()) + "," + conventionalProteinGraph.getContactsOf(aminoAcid).size() + "," + conventionalProteinGraph.getLocalContactsOf(aminoAcid).size() + "," + conventionalProteinGraph.getNonLocalContactsOf(aminoAcid).size() + "," + StandardFormat.format(residueTopologicPropertiesContainer.getConventional().getBetweenness()) + "," + StandardFormat.format(residueTopologicPropertiesContainer.getConventional().getCloseness()) + "," + StandardFormat.format(residueTopologicPropertiesContainer.getConventional().getClusteringCoefficient()) + "," + StandardFormat.format(residueTopologicPropertiesContainer.getFullPlip().getDistinctNeighborhoodCount()) + "," + StandardFormat.format(residueTopologicPropertiesContainer.getConventional().getDistinctNeighborhoodCount()) + "," + (earlyFoldingResidues.contains(aminoAcid) ? "early" : "late") + "," + functionalAnnotation;
        }).collect(Collectors.joining(System.lineSeparator())));
    } catch (Exception e) {
        logger.info("calculation failed for {}", line, e);
        return Optional.empty();
    }
}
Also used : LoopFraction(de.bioforscher.jstructure.feature.loopfraction.LoopFraction) ComputationException(de.bioforscher.jstructure.model.feature.ComputationException) LoggerFactory(org.slf4j.LoggerFactory) Structure(de.bioforscher.jstructure.model.structure.Structure) GenericSecondaryStructure(de.bioforscher.jstructure.feature.sse.GenericSecondaryStructure) StructureParser(de.bioforscher.jstructure.model.structure.StructureParser) EgorAgreement(de.bioforscher.jstructure.feature.energyprofile.EgorAgreement) HotSpotScoring(de.bioforscher.start2fold.model.HotSpotScoring) FunctionalResidueParser(de.bioforscher.start2fold.parser.FunctionalResidueParser) ArrayList(java.util.ArrayList) FunctionalResidueAnnotation(de.bioforscher.start2fold.model.FunctionalResidueAnnotation) EQuantScore(de.bioforscher.start2fold.model.EQuantScore) ProteinGraphFactory(de.bioforscher.jstructure.feature.graphs.ProteinGraphFactory) AminoAcid(de.bioforscher.jstructure.model.structure.aminoacid.AminoAcid) Start2FoldXmlParser(de.bioforscher.start2fold.parser.Start2FoldXmlParser) Chain(de.bioforscher.jstructure.model.structure.Chain) StandardFormat(de.bioforscher.jstructure.StandardFormat) EnergyProfile(de.bioforscher.jstructure.feature.energyprofile.EnergyProfile) Logger(org.slf4j.Logger) GeometricProperties(de.bioforscher.jstructure.feature.geometry.GeometricProperties) Files(java.nio.file.Files) ResidueTopologicPropertiesContainer(de.bioforscher.jstructure.feature.graphs.ResidueTopologicPropertiesContainer) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) PLIPInteractionContainer(de.bioforscher.jstructure.feature.interactions.PLIPInteractionContainer) Start2FoldResidueAnnotation(de.bioforscher.start2fold.model.Start2FoldResidueAnnotation) List(java.util.List) AccessibleSurfaceArea(de.bioforscher.jstructure.feature.asa.AccessibleSurfaceArea) Start2FoldConstants(de.bioforscher.start2fold.Start2FoldConstants) EQuantParser(de.bioforscher.start2fold.parser.EQuantParser) ProteinGraph(de.bioforscher.jstructure.feature.graphs.ProteinGraph) Optional(java.util.Optional) EvolutionaryCouplingParser(de.bioforscher.start2fold.parser.EvolutionaryCouplingParser) Pattern(java.util.regex.Pattern) Chain(de.bioforscher.jstructure.model.structure.Chain) ArrayList(java.util.ArrayList) GenericSecondaryStructure(de.bioforscher.jstructure.feature.sse.GenericSecondaryStructure) HotSpotScoring(de.bioforscher.start2fold.model.HotSpotScoring) LoopFraction(de.bioforscher.jstructure.feature.loopfraction.LoopFraction) ComputationException(de.bioforscher.jstructure.model.feature.ComputationException) Structure(de.bioforscher.jstructure.model.structure.Structure) GenericSecondaryStructure(de.bioforscher.jstructure.feature.sse.GenericSecondaryStructure) GeometricProperties(de.bioforscher.jstructure.feature.geometry.GeometricProperties) AccessibleSurfaceArea(de.bioforscher.jstructure.feature.asa.AccessibleSurfaceArea) AminoAcid(de.bioforscher.jstructure.model.structure.aminoacid.AminoAcid) ProteinGraph(de.bioforscher.jstructure.feature.graphs.ProteinGraph) EgorAgreement(de.bioforscher.jstructure.feature.energyprofile.EgorAgreement) Start2FoldResidueAnnotation(de.bioforscher.start2fold.model.Start2FoldResidueAnnotation) ResidueTopologicPropertiesContainer(de.bioforscher.jstructure.feature.graphs.ResidueTopologicPropertiesContainer) FunctionalResidueAnnotation(de.bioforscher.start2fold.model.FunctionalResidueAnnotation) EQuantScore(de.bioforscher.start2fold.model.EQuantScore) ComputationException(de.bioforscher.jstructure.model.feature.ComputationException) IOException(java.io.IOException) EnergyProfile(de.bioforscher.jstructure.feature.energyprofile.EnergyProfile) PLIPInteractionContainer(de.bioforscher.jstructure.feature.interactions.PLIPInteractionContainer)

Example 15 with ComputationException

use of de.bioforscher.jstructure.model.feature.ComputationException 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

ComputationException (de.bioforscher.jstructure.model.feature.ComputationException)15 IOException (java.io.IOException)14 Path (java.nio.file.Path)10 Chain (de.bioforscher.jstructure.model.structure.Chain)8 AminoAcid (de.bioforscher.jstructure.model.structure.aminoacid.AminoAcid)8 Files (java.nio.file.Files)8 Logger (org.slf4j.Logger)8 LoggerFactory (org.slf4j.LoggerFactory)8 Collectors (java.util.stream.Collectors)7 StandardFormat (de.bioforscher.jstructure.StandardFormat)5 AlignmentException (de.bioforscher.jstructure.align.AlignmentException)5 TMAlignAlignmentResult (de.bioforscher.jstructure.align.result.TMAlignAlignmentResult)5 ReconstructionContactMap (de.bioforscher.jstructure.graph.ReconstructionContactMap)5 ContactDefinitionFactory (de.bioforscher.jstructure.graph.contact.definition.ContactDefinitionFactory)5 Pair (de.bioforscher.jstructure.mathematics.Pair)5 Structure (de.bioforscher.jstructure.model.structure.Structure)5 ConfoldServiceWorker (de.bioforscher.jstructure.si.ConfoldServiceWorker)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5 TMAlignService (de.bioforscher.jstructure.align.impl.TMAlignService)4