use of de.bioforscher.jstructure.model.structure.aminoacid.AminoAcid in project jstructure by JonStargaryen.
the class EvolutionaryCouplingParser method parseHotSpotFile.
static void parseHotSpotFile(Chain chain, InputStream inputStream) {
Document hotSpotDocument = Jsoup.parse(new BufferedReader(new InputStreamReader(inputStream)).lines().collect(Collectors.joining(System.lineSeparator())));
List<AminoAcid> aminoAcids = chain.aminoAcids().collect(Collectors.toList());
hotSpotDocument.getElementsByTag("tr").stream().skip(1).forEach(element -> {
Elements tds = element.getElementsByTag("td");
int residueNumber = Integer.valueOf(tds.get(0).text());
String aa = tds.get(1).text();
int ecCount = Integer.valueOf(tds.get(2).text());
double cumStrength = Double.valueOf(tds.get(3).text());
double ecStrength = Double.valueOf(tds.get(4).text());
int conservation = Integer.valueOf(tds.get(5).text());
AminoAcid aminoAcid = aminoAcids.get(residueNumber - 1);
aminoAcid.getFeatureContainer().addFeature(new HotSpotScoring(ecCount, cumStrength, ecStrength, conservation));
});
// assign baseline
aminoAcids.stream().map(AminoAcid::getFeatureContainer).filter(featureContainer -> !featureContainer.getFeatureOptional(HotSpotScoring.class).isPresent()).forEach(featureContainer -> featureContainer.addFeature(new HotSpotScoring()));
}
use of de.bioforscher.jstructure.model.structure.aminoacid.AminoAcid in project jstructure by JonStargaryen.
the class Start2FoldXmlParser method parseSpecificExperiment.
public static void parseSpecificExperiment(Chain chain, InputStream inputStream, List<Integer> experimentIds) {
// experimentIds);
try {
// assign baseline resp. entry container for each residue
chain.aminoAcids().forEach(aminoAcid -> aminoAcid.getFeatureContainer().addFeature(new Start2FoldResidueAnnotation()));
Document document = Jsoup.parse(inputStream, "UTF-8", "/");
Elements experimentElements = document.getElementsByTag("experiment");
List<Experiment> experiments = experimentElements.stream().map(Experiment::parse).filter(experiment -> experimentIds.contains(experiment.getExperimentId())).collect(Collectors.toList());
if (experimentIds.size() != experiments.size()) {
throw new IllegalArgumentException("did not find all referenced experiments");
}
for (Experiment experiment : experiments) {
assignValuesForEarly(experiment, chain);
}
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
use of de.bioforscher.jstructure.model.structure.aminoacid.AminoAcid in project jstructure by JonStargaryen.
the class Start2FoldXmlParser method assignValuesForEarly.
private static void assignValuesForEarly(Experiment experiment, Chain chain) {
String pdbSequence = chain.getAminoAcidSequence();
String experimentSequence = experiment.getSequence();
// align sequences to ensure correct mapping
SequencePair<ProteinSequence, AminoAcidCompound> pair = null;
try {
pair = Alignments.getPairwiseAlignment(new ProteinSequence(experimentSequence), new ProteinSequence(pdbSequence), Alignments.PairwiseSequenceAlignerType.GLOBAL, new SimpleGapPenalty(), SubstitutionMatrixHelper.getBlosum62());
List<AminoAcid> aminoAcids = chain.aminoAcids().collect(Collectors.toList());
for (Experiment.Residue residue : experiment.getResidues()) {
int experimentIndex = residue.getIndex() - 1;
try {
int pdbIndex;
if (residue.getCode().equals("P") && residue.getIndex() == 1) {
// super-russian fix for STF0017 where the alignment should match theoretically
pdbIndex = 0;
} else {
pdbIndex = pair.getIndexInTargetForQueryAt(experimentIndex);
}
AminoAcid aminoAcid = aminoAcids.get(pdbIndex);
// assign experiment-specific protection level to residue
aminoAcid.getFeature(Start2FoldResidueAnnotation.class).addProtectionLevelEntry(ProtectionLevel.EARLY);
} catch (Exception e) {
// residue not present in structure - e.g. for STF0031 and STF0032
logger.warn("alignment:{}{}", System.lineSeparator(), pair.toString());
logger.warn("failed to map residue {}-{}", residue.getCode(), residue.getIndex(), e);
}
}
} catch (CompoundNotFoundException e) {
throw new IllegalArgumentException(e);
}
}
use of de.bioforscher.jstructure.model.structure.aminoacid.AminoAcid in project jstructure by JonStargaryen.
the class EQuantParser method parseEQuantFile.
public static void parseEQuantFile(Chain chain, Path equantPath) {
try {
String chainId = chain.getChainIdentifier().getChainId();
try (Stream<String> lines = Files.lines(equantPath)) {
// skip header
lines.filter(line -> !line.startsWith("chain")).filter(line -> line.startsWith(chainId)).forEach(line -> {
String[] split = line.split("\\s+");
int residueNumber = Integer.valueOf(split[1]);
double evaluation = Double.valueOf(split[4]);
AminoAcid aminoAcid = chain.select().residueNumber(residueNumber).asAminoAcid();
aminoAcid.getFeatureContainer().addFeature(new EQuantScore(evaluation));
});
}
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
use of de.bioforscher.jstructure.model.structure.aminoacid.AminoAcid 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();
}
}
Aggregations