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);
}
}
Aggregations