Search in sources :

Example 6 with ReconstructionContactMap

use of de.bioforscher.jstructure.graph.ReconstructionContactMap in project jstructure by JonStargaryen.

the class A04_CreateRmsdVsCoveragePlot method handleChain.

private static void handleChain(ExplorerChain explorerChain) {
    logger.info("handling chain {}", explorerChain.getStfId());
    try {
        Chain nativeChain = explorerChain.getChain();
        Path nativeChainPath = Files.createTempFile("nativechain-", ".pdb");
        Files.write(nativeChainPath, nativeChain.getPdbRepresentation().getBytes());
        ReconstructionContactMap nativeContactMap = ReconstructionContactMap.createReconstructionContactMap(nativeChain, ContactDefinitionFactory.createAlphaCarbonContactDefinition(8.0));
        List<AminoAcid> aminoAcids = nativeChain.getAminoAcids();
        List<Pair<AminoAcid, AminoAcid>> contacts = nativeContactMap.getLongRangeContacts();
        int numberNativeLongRangeContacts = contacts.size();
        List<ReconstructionContactMap> reconstructionContactMaps = new ArrayList<>();
        for (int coverage = 5; coverage <= 100; coverage = coverage + 5) {
            int numberOfContactsToSelect = (int) Math.round(0.01 * coverage * numberNativeLongRangeContacts);
            for (int run = 0; run < REDUNDANCY; run++) {
                Collections.shuffle(contacts);
                List<Pair<AminoAcid, AminoAcid>> selectedContacts = contacts.subList(0, numberOfContactsToSelect);
                ReconstructionContactMap contactMap = new ReconstructionContactMap(aminoAcids, selectedContacts, nativeContactMap.getContactDefinition());
                contactMap.setName("p" + coverage + "-" + (run + 1));
                reconstructionContactMaps.add(contactMap);
            }
        }
        Map<String, List<Future<ReconstructionResult>>> reconstructionFutures = new HashMap<>();
        for (ReconstructionContactMap contactMap : reconstructionContactMaps) {
            String name = contactMap.getName().split("-")[0];
            logger.info("handling contact map with coverage {}", name);
            if (!reconstructionFutures.containsKey(name)) {
                reconstructionFutures.put(name, new ArrayList<>());
            }
            List<Future<ReconstructionResult>> bin = reconstructionFutures.get(name);
            bin.add(executorService.submit(new ConfoldServiceWorker("/home/sb/programs/confold_v1.0/confold.pl", contactMap.getSequence(), contactMap.getSecondaryStructureElements(), contactMap.getCaspRRRepresentation(), nativeContactMap.getConfoldRRType())));
        }
        for (Map.Entry<String, List<Future<ReconstructionResult>>> reconstructionFuture : reconstructionFutures.entrySet()) {
            try {
                String name = reconstructionFuture.getKey();
                List<Chain> reconstructions = reconstructionFuture.getValue().stream().map(future -> {
                    try {
                        return future.get();
                    } catch (Exception e) {
                        throw new ComputationException(e);
                    }
                }).map(ReconstructionResult::getChains).flatMap(Collection::stream).collect(Collectors.toList());
                List<TMAlignAlignmentResult> alignmentResults = 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[] { "/home/sb/programs/tmalign", nativeChainPath.toFile().getAbsolutePath(), reconstructPath.toFile().getAbsolutePath() }));
                }
                if (alignmentResults.isEmpty()) {
                    throw new ComputationException("tmalign did not yield any alignments");
                }
                for (TMAlignAlignmentResult alignmentResult : alignmentResults) {
                    double rmsd = alignmentResult.getRootMeanSquareDeviation().getScore();
                    String line = explorerChain.getStfId() + "," + name.replace("p", "") + "," + rmsd;
                    logger.info(line);
                    fileWriter.write(line + System.lineSeparator());
                    fileWriter.flush();
                }
                // cleanup
                for (Path tmpFile : tmpFiles) {
                    Files.delete(tmpFile);
                }
            } catch (IOException e) {
                throw new ComputationException(e);
            }
        }
    } catch (IOException | AlignmentException e) {
        throw new ComputationException(e);
    }
}
Also used : java.util(java.util) ComputationException(de.bioforscher.jstructure.model.feature.ComputationException) TMAlignService(de.bioforscher.jstructure.align.impl.TMAlignService) LoggerFactory(org.slf4j.LoggerFactory) TestUtils(de.bioforscher.testutil.TestUtils) Future(java.util.concurrent.Future) AminoAcid(de.bioforscher.jstructure.model.structure.aminoacid.AminoAcid) Chain(de.bioforscher.jstructure.model.structure.Chain) ReconstructionResult(de.bioforscher.jstructure.si.model.ReconstructionResult) Path(java.nio.file.Path) AlignmentException(de.bioforscher.jstructure.align.AlignmentException) ExecutorService(java.util.concurrent.ExecutorService) Logger(org.slf4j.Logger) Files(java.nio.file.Files) FileWriter(java.io.FileWriter) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) Pair(de.bioforscher.jstructure.mathematics.Pair) Executors(java.util.concurrent.Executors) ConfoldServiceWorker(de.bioforscher.jstructure.si.ConfoldServiceWorker) TMAlignAlignmentResult(de.bioforscher.jstructure.align.result.TMAlignAlignmentResult) Paths(java.nio.file.Paths) ExplorerChain(de.bioforscher.jstructure.si.explorer.ExplorerChain) ReconstructionContactMap(de.bioforscher.jstructure.graph.ReconstructionContactMap) ContactDefinitionFactory(de.bioforscher.jstructure.graph.contact.definition.ContactDefinitionFactory) Chain(de.bioforscher.jstructure.model.structure.Chain) ExplorerChain(de.bioforscher.jstructure.si.explorer.ExplorerChain) ReconstructionContactMap(de.bioforscher.jstructure.graph.ReconstructionContactMap) AlignmentException(de.bioforscher.jstructure.align.AlignmentException) ReconstructionResult(de.bioforscher.jstructure.si.model.ReconstructionResult) ComputationException(de.bioforscher.jstructure.model.feature.ComputationException) Pair(de.bioforscher.jstructure.mathematics.Pair) Path(java.nio.file.Path) ConfoldServiceWorker(de.bioforscher.jstructure.si.ConfoldServiceWorker) AminoAcid(de.bioforscher.jstructure.model.structure.aminoacid.AminoAcid) IOException(java.io.IOException) ComputationException(de.bioforscher.jstructure.model.feature.ComputationException) AlignmentException(de.bioforscher.jstructure.align.AlignmentException) IOException(java.io.IOException) TMAlignAlignmentResult(de.bioforscher.jstructure.align.result.TMAlignAlignmentResult) Future(java.util.concurrent.Future) ReconstructionContactMap(de.bioforscher.jstructure.graph.ReconstructionContactMap)

Example 7 with ReconstructionContactMap

use of de.bioforscher.jstructure.graph.ReconstructionContactMap in project jstructure by JonStargaryen.

the class A04A_CreatePyMolRendering method handleChain.

private static void handleChain(ExplorerChain explorerChain) {
    logger.info("handling chain {}", explorerChain.getStfId());
    try {
        Chain nativeChain = explorerChain.getChain();
        Path nativeChainPath = Files.createTempFile("nativechain-", ".pdb");
        Files.write(nativeChainPath, nativeChain.getPdbRepresentation().getBytes());
        ReconstructionContactMap nativeContactMap = ReconstructionContactMap.createReconstructionContactMap(nativeChain, ContactDefinitionFactory.createAlphaCarbonContactDefinition(8.0));
        List<AminoAcid> aminoAcids = nativeChain.getAminoAcids();
        List<Pair<AminoAcid, AminoAcid>> contacts = nativeContactMap.getLongRangeContacts();
        int numberNativeLongRangeContacts = contacts.size();
        List<ReconstructionContactMap> reconstructionContactMaps = new ArrayList<>();
        IntStream.of(5, 30, 100).forEach(coverage -> {
            int numberOfContactsToSelect = (int) Math.round(0.01 * coverage * numberNativeLongRangeContacts);
            for (int run = 0; run < REDUNDANCY; run++) {
                Collections.shuffle(contacts);
                List<Pair<AminoAcid, AminoAcid>> selectedContacts = contacts.subList(0, numberOfContactsToSelect);
                ReconstructionContactMap contactMap = new ReconstructionContactMap(aminoAcids, selectedContacts, nativeContactMap.getContactDefinition());
                contactMap.setName("p" + coverage + "-" + (run + 1));
                reconstructionContactMaps.add(contactMap);
            }
        });
        Map<String, List<Future<ReconstructionResult>>> reconstructionFutures = new HashMap<>();
        for (ReconstructionContactMap contactMap : reconstructionContactMaps) {
            String name = contactMap.getName().split("-")[0];
            logger.info("handling contact map with coverage {}", name);
            if (!reconstructionFutures.containsKey(name)) {
                reconstructionFutures.put(name, new ArrayList<>());
            }
            List<Future<ReconstructionResult>> bin = reconstructionFutures.get(name);
            bin.add(executorService.submit(new ConfoldServiceWorker("/home/sb/programs/confold_v1.0/confold.pl", contactMap.getSequence(), contactMap.getSecondaryStructureElements(), contactMap.getCaspRRRepresentation(), nativeContactMap.getConfoldRRType())));
        }
        for (Map.Entry<String, List<Future<ReconstructionResult>>> reconstructionFuture : reconstructionFutures.entrySet()) {
            try {
                String name = reconstructionFuture.getKey();
                List<Chain> reconstructions = reconstructionFuture.getValue().stream().map(future -> {
                    try {
                        return future.get();
                    } catch (Exception e) {
                        throw new ComputationException(e);
                    }
                }).map(ReconstructionResult::getChains).flatMap(Collection::stream).collect(Collectors.toList());
                for (Chain reconstructedChain : reconstructions) {
                    Files.write(OUTPUT_PATH.resolve(name + ".pdb"), reconstructedChain.getPdbRepresentation().getBytes());
                }
            } catch (IOException e) {
                throw new ComputationException(e);
            }
        }
    } catch (IOException e) {
        throw new ComputationException(e);
    }
}
Also used : IntStream(java.util.stream.IntStream) java.util(java.util) Logger(org.slf4j.Logger) ComputationException(de.bioforscher.jstructure.model.feature.ComputationException) Files(java.nio.file.Files) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) TestUtils(de.bioforscher.testutil.TestUtils) Collectors(java.util.stream.Collectors) Pair(de.bioforscher.jstructure.mathematics.Pair) Executors(java.util.concurrent.Executors) ConfoldServiceWorker(de.bioforscher.jstructure.si.ConfoldServiceWorker) Future(java.util.concurrent.Future) Paths(java.nio.file.Paths) AminoAcid(de.bioforscher.jstructure.model.structure.aminoacid.AminoAcid) Chain(de.bioforscher.jstructure.model.structure.Chain) ExplorerChain(de.bioforscher.jstructure.si.explorer.ExplorerChain) ReconstructionResult(de.bioforscher.jstructure.si.model.ReconstructionResult) ReconstructionContactMap(de.bioforscher.jstructure.graph.ReconstructionContactMap) Path(java.nio.file.Path) ExecutorService(java.util.concurrent.ExecutorService) ContactDefinitionFactory(de.bioforscher.jstructure.graph.contact.definition.ContactDefinitionFactory) Chain(de.bioforscher.jstructure.model.structure.Chain) ExplorerChain(de.bioforscher.jstructure.si.explorer.ExplorerChain) ReconstructionContactMap(de.bioforscher.jstructure.graph.ReconstructionContactMap) ReconstructionResult(de.bioforscher.jstructure.si.model.ReconstructionResult) ComputationException(de.bioforscher.jstructure.model.feature.ComputationException) Pair(de.bioforscher.jstructure.mathematics.Pair) Path(java.nio.file.Path) ConfoldServiceWorker(de.bioforscher.jstructure.si.ConfoldServiceWorker) AminoAcid(de.bioforscher.jstructure.model.structure.aminoacid.AminoAcid) IOException(java.io.IOException) ComputationException(de.bioforscher.jstructure.model.feature.ComputationException) IOException(java.io.IOException) Future(java.util.concurrent.Future) ReconstructionContactMap(de.bioforscher.jstructure.graph.ReconstructionContactMap)

Example 8 with ReconstructionContactMap

use of de.bioforscher.jstructure.graph.ReconstructionContactMap 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)

Example 9 with ReconstructionContactMap

use of de.bioforscher.jstructure.graph.ReconstructionContactMap in project jstructure by JonStargaryen.

the class BaselineReconstruction method createContactTogglingReconstruction.

public ContactTogglingReconstruction createContactTogglingReconstruction(Pair<AminoAcid, AminoAcid> contactToToggle, int counter, int numberOfCombinations) {
    List<Pair<AminoAcid, AminoAcid>> contacts = new ArrayList<>(sampledMap.getLongRangeContacts());
    boolean contactWasRemoved = determineIfMapContainsContact(sampledMap, contactToToggle);
    if (contactWasRemoved) {
        contacts.removeIf(pair -> pairsMatchByResidueIdentifier(pair, contactToToggle));
    } else {
        contacts.add(contactToToggle);
    }
    return new ContactTogglingReconstruction(this, counter, numberOfCombinations, contactToToggle, contactWasRemoved, new ReconstructionContactMap(sampledMap.getAminoAcids(), contacts, fullMap.getContactDefinition()));
}
Also used : ReconstructionContactMap(de.bioforscher.jstructure.graph.ReconstructionContactMap) ArrayList(java.util.ArrayList) Pair(de.bioforscher.jstructure.mathematics.Pair)

Aggregations

ReconstructionContactMap (de.bioforscher.jstructure.graph.ReconstructionContactMap)9 Pair (de.bioforscher.jstructure.mathematics.Pair)8 Path (java.nio.file.Path)7 Chain (de.bioforscher.jstructure.model.structure.Chain)6 AminoAcid (de.bioforscher.jstructure.model.structure.aminoacid.AminoAcid)6 ConfoldServiceWorker (de.bioforscher.jstructure.si.ConfoldServiceWorker)6 IOException (java.io.IOException)6 Files (java.nio.file.Files)6 Logger (org.slf4j.Logger)6 LoggerFactory (org.slf4j.LoggerFactory)6 ComputationException (de.bioforscher.jstructure.model.feature.ComputationException)5 Collectors (java.util.stream.Collectors)5 AlignmentException (de.bioforscher.jstructure.align.AlignmentException)4 TMAlignService (de.bioforscher.jstructure.align.impl.TMAlignService)4 TMAlignAlignmentResult (de.bioforscher.jstructure.align.result.TMAlignAlignmentResult)4 ContactDefinitionFactory (de.bioforscher.jstructure.graph.contact.definition.ContactDefinitionFactory)4 ArrayList (java.util.ArrayList)4 ExecutorService (java.util.concurrent.ExecutorService)4 Executors (java.util.concurrent.Executors)4 Future (java.util.concurrent.Future)4