Search in sources :

Example 1 with BaselineReconstruction

use of de.bioforscher.jstructure.si.model.BaselineReconstruction in project jstructure by JonStargaryen.

the class StructuralInformationService method process.

public void process(Chain referenceChain, String jobName, Path confoldPath, Path tmalignPath, Path outputDirectory, int numberOfThreads, double baselineFrequency) {
    try {
        ExecutorService executorService = Executors.newFixedThreadPool(numberOfThreads);
        List<AminoAcid> aminoAcids = referenceChain.aminoAcids().collect(Collectors.toList());
        int numberOfAminoAcids = aminoAcids.size();
        ReconstructionContactMap fullMap = ReconstructionContactMap.createReconstructionContactMap(referenceChain, ContactDefinitionFactory.createAlphaCarbonContactDefinition(8.0));
        List<Pair<AminoAcid, AminoAcid>> contacts = fullMap.getLongRangeContacts();
        int numberOfLongRangeContacts = contacts.size();
        String sequence = fullMap.getSequence();
        String secondaryStructure = fullMap.getSecondaryStructureElements();
        // report general statistics
        logger.info("evaluating structural information of chain with {} residues and {} long-range contacts", numberOfAminoAcids, numberOfLongRangeContacts);
        logger.info("present long-range contacts:{}{}", System.lineSeparator(), composeConsoleOutput(fullMap.getLongRangeContacts()));
        logger.info("coverage per position:{}{}", System.lineSeparator(), aminoAcids.stream().map(fullMap::getNonLocalContactsOf).mapToInt(List::size).mapToObj(size -> {
            if (size < 10) {
                return String.valueOf(size);
            } else {
                return "*";
            }
        }).collect(Collectors.joining()));
        // write reference structure
        Path referenceChainStructurePath = Files.createTempFile("confoldservice-ref", ".pdb");
        Files.write(referenceChainStructurePath, referenceChain.getPdbRepresentation().getBytes());
        // create outputDirectory
        Path reconstructionDirectory = outputDirectory.resolve(jobName);
        if (!Files.exists(reconstructionDirectory)) {
            Files.createDirectory(reconstructionDirectory);
        }
        // create sampling containers
        List<Future<BaselineReconstruction>> baselineFutures = new ArrayList<>();
        for (int iteration = 0; iteration < COVERAGE; iteration++) {
            baselineFutures.add(executorService.submit(new BaselineReconstruction(iteration, referenceChainStructurePath, referenceChain, fullMap, sequence, secondaryStructure, baselineFrequency, confoldPath.toFile().getAbsolutePath(), tmalignPath.toFile().getAbsolutePath(), outputDirectory, jobName)));
        }
        List<BaselineReconstruction> baselineReconstructions = baselineFutures.stream().map(this::getBaselineFuture).collect(Collectors.toList());
        // create toggling reconstructions
        int numberOfCombinations = baselineReconstructions.size() * contacts.size();
        logger.info("reconstructing individual maps by contact toggling - evaluating {} combinations", numberOfCombinations);
        int counter = 1;
        List<Future<ContactTogglingReconstruction>> contactToggleFutures = new ArrayList<>();
        for (Pair<AminoAcid, AminoAcid> contact : contacts) {
            for (BaselineReconstruction baselineReconstruction : baselineReconstructions) {
                contactToggleFutures.add(executorService.submit(baselineReconstruction.createContactTogglingReconstruction(contact, counter, numberOfCombinations)));
                counter++;
            }
        }
        Path outputPath = outputDirectory.resolve(jobName + ".out");
        FileWriter outputWriter = new FileWriter(outputPath.toFile());
        contactToggleFutures.stream().map(this::getContactToggleFuture).filter(Optional::isPresent).map(Optional::get).map(contactTogglingReconstruction -> contactTogglingReconstruction.getContactToToggle() + "\t" + contactTogglingReconstruction.isContactWasRemoved() + "\t" + StandardFormat.format(contactTogglingReconstruction.getBaselineReconstruction().getAverageRmsd()) + "\t" + StandardFormat.format(contactTogglingReconstruction.getBaselineReconstruction().getAverageTmScore()) + "\t" + StandardFormat.format(contactTogglingReconstruction.getBaselineReconstruction().getAverageQ()) + "\t" + StandardFormat.format(contactTogglingReconstruction.getAverageRmsd()) + "\t" + StandardFormat.format(contactTogglingReconstruction.getAverageTmScore()) + "\t" + StandardFormat.format(contactTogglingReconstruction.getAverageQ()) + "\t" + StandardFormat.format(contactTogglingReconstruction.getDecreaseRmsd()) + "\t" + StandardFormat.format(contactTogglingReconstruction.getIncreaseTMScore()) + "\t" + StandardFormat.format(contactTogglingReconstruction.getIncreaseQ()) + System.lineSeparator()).forEach(line -> {
            try {
                outputWriter.write(line);
                outputWriter.flush();
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        });
        // clean up
        outputWriter.close();
        Files.delete(referenceChainStructurePath);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
Also used : Path(java.nio.file.Path) ContactTogglingReconstruction(de.bioforscher.jstructure.si.model.ContactTogglingReconstruction) Logger(org.slf4j.Logger) Files(java.nio.file.Files) LoggerFactory(org.slf4j.LoggerFactory) FileWriter(java.io.FileWriter) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) Pair(de.bioforscher.jstructure.mathematics.Pair) Executors(java.util.concurrent.Executors) ArrayList(java.util.ArrayList) UncheckedIOException(java.io.UncheckedIOException) List(java.util.List) Future(java.util.concurrent.Future) AminoAcid(de.bioforscher.jstructure.model.structure.aminoacid.AminoAcid) Chain(de.bioforscher.jstructure.model.structure.Chain) BaselineReconstruction(de.bioforscher.jstructure.si.model.BaselineReconstruction) Optional(java.util.Optional) StandardFormat(de.bioforscher.jstructure.StandardFormat) ReconstructionContactMap(de.bioforscher.jstructure.graph.ReconstructionContactMap) Path(java.nio.file.Path) ExecutorService(java.util.concurrent.ExecutorService) ContactDefinitionFactory(de.bioforscher.jstructure.graph.contact.definition.ContactDefinitionFactory) ReconstructionContactMap(de.bioforscher.jstructure.graph.ReconstructionContactMap) Optional(java.util.Optional) AminoAcid(de.bioforscher.jstructure.model.structure.aminoacid.AminoAcid) FileWriter(java.io.FileWriter) ArrayList(java.util.ArrayList) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) BaselineReconstruction(de.bioforscher.jstructure.si.model.BaselineReconstruction) Pair(de.bioforscher.jstructure.mathematics.Pair)

Aggregations

StandardFormat (de.bioforscher.jstructure.StandardFormat)1 ReconstructionContactMap (de.bioforscher.jstructure.graph.ReconstructionContactMap)1 ContactDefinitionFactory (de.bioforscher.jstructure.graph.contact.definition.ContactDefinitionFactory)1 Pair (de.bioforscher.jstructure.mathematics.Pair)1 Chain (de.bioforscher.jstructure.model.structure.Chain)1 AminoAcid (de.bioforscher.jstructure.model.structure.aminoacid.AminoAcid)1 BaselineReconstruction (de.bioforscher.jstructure.si.model.BaselineReconstruction)1 ContactTogglingReconstruction (de.bioforscher.jstructure.si.model.ContactTogglingReconstruction)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Optional (java.util.Optional)1 ExecutorService (java.util.concurrent.ExecutorService)1 Executors (java.util.concurrent.Executors)1 Future (java.util.concurrent.Future)1 Collectors (java.util.stream.Collectors)1