use of de.bioforscher.jstructure.efr.model.si.ContactStructuralInformation in project jstructure by JonStargaryen.
the class A03_ReconstructByVariousStrategy method handleChain.
private static void handleChain(ExplorerChain explorerChain) {
logger.info("[{}] starting job", explorerChain.getStfId());
try {
Chain nativeChain = explorerChain.getChain();
Path nativeChainPath = Files.createTempFile("nativechain-", ".pdb");
Files.write(nativeChainPath, nativeChain.getPdbRepresentation().getBytes());
List<ContactStructuralInformation> contactStructuralInformation = explorerChain.getContacts();
// annotate with PLIP data
PLIPInteractionContainer plipInteractionContainer = nativeChain.getFeature(PLIPInteractionContainer.class);
for (ContactStructuralInformation csi : contactStructuralInformation) {
AminoAcid aminoAcid1 = nativeChain.select().residueNumber(csi.getResidueIdentifier1()).asAminoAcid();
AminoAcid aminoAcid2 = nativeChain.select().residueNumber(csi.getResidueIdentifier2()).asAminoAcid();
if (plipInteractionContainer.getHydrogenBonds().stream().anyMatch(hydrogenBond -> isContact(hydrogenBond, aminoAcid1, aminoAcid2))) {
csi.markAsHydrogenBond();
}
if (plipInteractionContainer.getHydrophobicInteractions().stream().anyMatch(hydrophobicInteraction -> isContact(hydrophobicInteraction, aminoAcid1, aminoAcid2))) {
csi.markAsHydrophobicInteraction();
}
}
int numberOfNativeContacts = contactStructuralInformation.size();
int numberOfContactsToSelect = (int) (numberOfNativeContacts * DEFAULT_COVERAGE);
List<ReconstructionContactMap> contactMaps = Stream.of(ReconstructionStrategyDefinition.values()).map(ReconstructionStrategyDefinition::getReconstructionStrategy).flatMap(reconstructionStrategy -> IntStream.range(0, REDUNDANCY).boxed().flatMap(i -> {
if (!reconstructionStrategy.isNegatable()) {
ReconstructionContactMap contactMap = reconstructionStrategy.composeReconstructionContactMap(nativeChain, contactStructuralInformation, numberOfContactsToSelect);
contactMap.setName(reconstructionStrategy.getName() + "-" + (i + 1));
return Stream.of(contactMap);
} else {
// short, long, hydrogen, and hydrophobic bins have to be negated explicitly to get comparable results
Pair<ReconstructionContactMap, ReconstructionContactMap> contactMapPair = reconstructionStrategy.composeReconstructionAndNegatedReconstructionContactMap(nativeChain, contactStructuralInformation, numberOfContactsToSelect);
contactMapPair.getLeft().setName(reconstructionStrategy.getName() + "-" + (i + 1));
contactMapPair.getRight().setName(reconstructionStrategy.getNegatedName() + "-" + (i + 1));
return Stream.of(contactMapPair.getLeft(), contactMapPair.getRight());
}
})).filter(reconstructionContactMap -> reconstructionContactMap.getNumberOfContacts() > 0).collect(Collectors.toList());
Map<String, List<Future<ReconstructionResult>>> reconstructionFutures = new HashMap<>();
for (ReconstructionContactMap contactMap : contactMaps) {
String name = contactMap.getName().split("-")[0];
logger.info("[{}] handling contact map definition {}", explorerChain.getStfId(), 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(), contactMap.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());
logger.info("[{}][{}] {} reconstructs in bin", explorerChain.getStfId(), name, reconstructions.size());
List<TMAlignAlignmentResult> alignmentResults = 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[] { "/home/sb/programs/tmalign", nativeChainPath.toFile().getAbsolutePath(), reconstructPath.toFile().getAbsolutePath() }));
}
logger.info("[{}][{}] {} alignments in bin", explorerChain.getStfId(), name, alignmentResults.size());
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 + "," + rmsd;
logger.info("[{}][{}] {}", explorerChain.getStfId(), name, 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);
}
}
use of de.bioforscher.jstructure.efr.model.si.ContactStructuralInformation in project jstructure by JonStargaryen.
the class A06_WriteStructuralInformationByResidueCsv 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());
// boolean sane = split[6].equalsIgnoreCase("true");
Structure structure = StructureParser.fromPdbId(pdbId).parse();
Chain chain = structure.chains().findFirst().get();
Path start2foldXml = Start2FoldConstants.XML_DIRECTORY.resolve(entryId + ".xml");
Start2FoldXmlParser.parseStability(chain, start2foldXml);
Start2FoldXmlParser.parseSpecificExperiment(chain, start2foldXml, experimentIds);
try {
EvolutionaryCouplingParser.parseHotSpotFile(chain, Start2FoldConstants.COUPLING_DIRECTORY.resolve(entryId.toUpperCase() + "_hs.html"));
} catch (Exception e) {
}
boolean ecAnnotation = chain.aminoAcids().anyMatch(residue -> residue.getFeature(HotSpotScoring.class).getEcCount() > 0);
List<AminoAcid> topScoringResidues;
if (ecAnnotation) {
double fraction = 0.4;
int residuesToSelect = (int) (fraction * chain.aminoAcids().count());
topScoringResidues = chain.aminoAcids().sorted(Comparator.comparingDouble((AminoAcid aminoAcid) -> aminoAcid.getFeature(HotSpotScoring.class).getCumStrength()).reversed()).limit(residuesToSelect).collect(Collectors.toList());
} else {
topScoringResidues = new ArrayList<>();
}
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<AminoAcid> strongResidues = chain.aminoAcids().filter(aminoAcid -> aminoAcid.getFeature(Start2FoldResidueAnnotation.class).isStrong()).collect(Collectors.toList());
List<Integer> functionalResidueNumbers = Start2FoldConstants.extractFunctionalResidueNumbers(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());
List<ContactStructuralInformation> contactStructuralInformation = StructuralInformationParserService.getInstance().parseContactStructuralInformation(Start2FoldConstants.DATA_DIRECTORY.resolve("si").resolve("raw").resolve(entryId.toUpperCase() + ".out"), chain, earlyFoldingResidues);
List<ResidueStructuralInformation> residueStructuralInformation = StructuralInformationParserService.getInstance().composeResidueStructuralInformation(aminoAcids, earlyFoldingResidues, contactStructuralInformation);
ResidueGraph conventionalProteinGraph = ResidueGraph.createResidueGraph(chain, ContactDefinitionFactory.createAlphaCarbonContactDefinition(8.0));
List<AminoAcid> residuesInEarlyFoldingSecondaryStructureElements = chain.aminoAcids().filter(aminoAcid -> !aminoAcid.getFeature(GenericSecondaryStructure.class).getSecondaryStructure().isCoilType()).filter(aminoAcid -> {
GenericSecondaryStructure.SecondaryStructureElement surroundingSecondaryStructureElement = aminoAcid.getFeature(GenericSecondaryStructure.class).getSurroundingSecondaryStructureElement(aminoAcid);
List<AminoAcid> surroundingAminoAcids = chain.getAminoAcids().subList(surroundingSecondaryStructureElement.getStart(), surroundingSecondaryStructureElement.getEnd() + 1);
return surroundingAminoAcids.stream().anyMatch(earlyFoldingResidues::contains);
}).collect(Collectors.toList());
System.out.println("efr: " + (earlyFoldingResidues.size() > 0) + " strong: " + (strongResidues.size() > 0) + " functional: " + (functionalResidues.size() > 0));
return Optional.of(chain.aminoAcids().filter(AminoAcid::isStandardAminoAcid).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();
ResidueStructuralInformation residueStructuralInformationEntry = residueStructuralInformation.get(aminoAcid.getAminoAcidIndex());
GenericSecondaryStructure.SecondaryStructureElement surroundingSecondaryStructureElement = sse.getSurroundingSecondaryStructureElement(aminoAcid);
int sseSize = surroundingSecondaryStructureElement.getSize();
if (sse.getSecondaryStructure().isCoilType()) {
sseSize = 0;
}
int sseTerminusDistance = surroundingSecondaryStructureElement.getTerminusDistance();
if (sse.getSecondaryStructure().isCoilType()) {
sseTerminusDistance = -1;
}
return pdbId + "," + "A" + "," + aminoAcid.getResidueIdentifier() + "," + aminoAcid.getOneLetterCode() + "," + sse.getSecondaryStructure().getReducedRepresentation() + "," + sse.getSecondaryStructure().getOneLetterRepresentation() + "," + (sse.getSecondaryStructure().isHelixType() ? "true" : "false") + "," + (sse.getSecondaryStructure().isStrandType() ? "true" : "false") + "," + (sse.getSecondaryStructure().isCoilType() ? "true" : "false") + "," + sseSize + "," + sseTerminusDistance + "," + (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() + "," + topScoringResidues.contains(aminoAcid) + "," + 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()) + "," + StandardFormat.format(residueStructuralInformationEntry.getAverageRmsdIncrease()) + "," + StandardFormat.format(residueStructuralInformationEntry.getAverageTmScoreIncrease()) + "," + StandardFormat.format(residueStructuralInformationEntry.getAverageQIncrease()) + "," + StandardFormat.format(residueStructuralInformationEntry.getMaximumRmsdIncrease()) + "," + StandardFormat.format(residueStructuralInformationEntry.getMaximumTmScoreIncrease()) + "," + StandardFormat.format(residueStructuralInformationEntry.getMaximumQIncrease()) + "," + StandardFormat.format(residueStructuralInformationEntry.getAverageRmsdIncreaseZScore()) + "," + StandardFormat.format(residueStructuralInformationEntry.getFractionOfTopScoringContacts()) + "," + (earlyFoldingResidues.contains(aminoAcid) ? "early" : "late") + "," + (residuesInEarlyFoldingSecondaryStructureElements.contains(aminoAcid) ? "true" : "false") + "," + functionalAnnotation + "," + (strongResidues.contains(aminoAcid) ? "strong" : "weak") + "," + (earlyFoldingResidues.size() > 0) + "," + (strongResidues.size() > 0) + "," + (functionalResidues.size() > 0) + "," + ecAnnotation;
}).collect(Collectors.joining(System.lineSeparator())));
} catch (Exception e) {
logger.info("calculation failed for {}\nby: {}", line, e.getMessage());
return Optional.empty();
}
}
use of de.bioforscher.jstructure.efr.model.si.ContactStructuralInformation in project jstructure by JonStargaryen.
the class StructuralInformationParserServiceTest method shouldParseStructuralInformationFile.
@Test
public void shouldParseStructuralInformationFile() {
Chain chain = StructureParser.fromPdbId("1bdd").parse().getFirstChain();
List<AminoAcid> aminoAcids = chain.aminoAcids().collect(Collectors.toList());
Start2FoldXmlParser.parseSpecificExperiment(chain, TestUtils.getResourceAsInputStream("efr/STF0045.xml"), Stream.of(185).collect(Collectors.toList()));
List<AminoAcid> earlyFoldingResidues = chain.aminoAcids().filter(aminoAcid -> aminoAcid.getFeature(Start2FoldResidueAnnotation.class).isEarly()).collect(Collectors.toList());
List<ContactStructuralInformation> contactStructuralInformation = StructuralInformationParserService.getInstance().parseContactStructuralInformationFile(TestUtils.getResourceAsInputStream("si/STF0045.out"), chain, earlyFoldingResidues);
contactStructuralInformation.stream().map(ContactStructuralInformation::getCsvLine).forEach(System.out::println);
System.out.println();
List<ResidueStructuralInformation> residueStructuralInformation = StructuralInformationParserService.getInstance().composeResidueStructuralInformation(aminoAcids, earlyFoldingResidues, contactStructuralInformation);
residueStructuralInformation.stream().map(ResidueStructuralInformation::getCsvLine).forEach(System.out::println);
}
use of de.bioforscher.jstructure.efr.model.si.ContactStructuralInformation in project jstructure by JonStargaryen.
the class A02_WriteHeatmapFiles method handleChain.
private static void handleChain(ExplorerChain explorerChain) {
try {
String entryId = explorerChain.getStfId();
System.out.println(entryId);
Chain chain = explorerChain.getChain();
List<ContactStructuralInformation> contactStructuralInformation = explorerChain.getContacts();
StringJoiner stringJoiner = new StringJoiner(System.lineSeparator(), "res1,res2,avg" + System.lineSeparator(), "");
List<AminoAcid> aminoAcids = chain.aminoAcids().collect(Collectors.toList());
SetOperations.cartesianProductOf(aminoAcids, aminoAcids).forEach(pair -> {
int residueIdentifier1 = pair.getLeft().getResidueIdentifier().getResidueNumber();
int residueIdentifier2 = pair.getRight().getResidueIdentifier().getResidueNumber();
Optional<ContactStructuralInformation> information = contactStructuralInformation.stream().filter(contact -> (contact.getResidueIdentifier1() == residueIdentifier1 && contact.getResidueIdentifier2() == residueIdentifier2) || (contact.getResidueIdentifier1() == residueIdentifier2 && contact.getResidueIdentifier2() == residueIdentifier1)).findFirst();
if (information.isPresent()) {
stringJoiner.add(residueIdentifier1 + "," + residueIdentifier2 + "," + information.get().getAverageRmsdIncrease());
} else {
stringJoiner.add(residueIdentifier1 + "," + residueIdentifier2 + "," + "0.0");
}
});
Files.write(Start2FoldConstants.DATA_DIRECTORY.resolve("si").resolve("heatmaps").resolve(entryId + ".csv"), stringJoiner.toString().getBytes());
} catch (Exception e) {
e.printStackTrace();
}
}
use of de.bioforscher.jstructure.efr.model.si.ContactStructuralInformation in project jstructure by JonStargaryen.
the class EvolutionaryCouplingParser method parsePlmScore.
private static void parsePlmScore(ContactStructuralInformation contact, Element table) {
String residueIdentifier1 = String.valueOf(contact.getResidueIdentifier1());
String residueIdentifier2 = String.valueOf(contact.getResidueIdentifier2());
OptionalDouble plmScore = table.getElementsByTag("tr").stream().skip(1).map(element -> element.getElementsByTag("td")).filter(elements -> (elements.get(2).text().equals(residueIdentifier1) && elements.get(4).text().equals(residueIdentifier2)) || (elements.get(2).text().equals(residueIdentifier2) && elements.get(4).text().equals(residueIdentifier1))).mapToDouble(elements -> Double.valueOf(elements.get(6).text())).mapToObj(StandardFormat::format).mapToDouble(Double::valueOf).findFirst();
OptionalInt rank = table.getElementsByTag("tr").stream().skip(1).map(element -> element.getElementsByTag("td")).filter(elements -> (elements.get(2).text().equals(residueIdentifier1) && elements.get(4).text().equals(residueIdentifier2)) || (elements.get(2).text().equals(residueIdentifier2) && elements.get(4).text().equals(residueIdentifier1))).mapToInt(elements -> Integer.valueOf(elements.get(0).text())).findFirst();
contact.setPlmScore(plmScore.orElse(0.0));
contact.setCouplingRank(rank.orElse(-1));
// contact.setCouplingRank(rank.orElse(Integer.MAX_VALUE));
}
Aggregations