Search in sources :

Example 51 with Structure

use of de.bioforscher.jstructure.model.structure.Structure in project jstructure by JonStargaryen.

the class A05_WriteEarlyFoldingContactCsv method handleLineLocally.

private static Optional<String> handleLineLocally(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);
        earlyFoldingResidues = chain.aminoAcids().filter(aminoAcid -> aminoAcid.getFeature(Start2FoldResidueAnnotation.class).isEarly()).collect(Collectors.toList());
        // filter for contacts of EFR
        PLIPInteractionContainer plipInteractionContainer = chain.getFeature(PLIPInteractionContainer.class);
        System.out.println(pdbId + "\t" + earlyFoldingResidues.size() + "\t" + StandardFormat.format(plipInteractionContainer.getInteractions().size() / (double) earlyFoldingResidues.size()) + "\t" + plipInteractionContainer.getInteractions().size());
        // ignore really small or non-interacting groups of EFR
        if (plipInteractionContainer.getInteractions().size() < 2) {
            return Optional.empty();
        }
        return Optional.of(plipInteractionContainer.getInteractions().stream().map(A05_WriteEarlyFoldingContactCsv::handleInteraction).collect(Collectors.joining(System.lineSeparator())));
    } catch (Exception e) {
        e.printStackTrace();
        logger.info("calculation failed for {}", line, e);
        return Optional.empty();
    }
}
Also used : Chain(de.bioforscher.jstructure.model.structure.Chain) PLIPInteractionContainer(de.bioforscher.jstructure.feature.interactions.PLIPInteractionContainer) Structure(de.bioforscher.jstructure.model.structure.Structure) GenericSecondaryStructure(de.bioforscher.jstructure.feature.sse.GenericSecondaryStructure) IOException(java.io.IOException)

Example 52 with Structure

use of de.bioforscher.jstructure.model.structure.Structure in project jstructure by JonStargaryen.

the class A01_ReportGeneralStatistics method handleStrongFile.

private static void handleStrongFile(Path path) {
    try {
        String pdbId = Jsoup.parse(path.toFile(), "UTF-8").getElementsByTag("protein").attr("pdb_id");
        Structure structure = StructureParser.fromPdbId(pdbId).parse();
        Chain chain = structure.chains().findFirst().get();
        Start2FoldXmlParser.parse(chain, path);
        boolean hasStabilityData = chain.aminoAcids().map(aminoAcid -> aminoAcid.getFeature(Start2FoldResidueAnnotation.class)).anyMatch(Start2FoldResidueAnnotation::isStrong);
        if (!hasStabilityData) {
            return;
        }
        long count = chain.aminoAcids().filter(aminoAcid -> aminoAcid.getFeature(Start2FoldResidueAnnotation.class).isStrong()).count();
        strong.add((int) count);
        weak.add((int) (chain.aminoAcids().count() - count));
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
Also used : java.util(java.util) Files(java.nio.file.Files) FishersExactTest(edu.northwestern.at.utils.math.statistics.FishersExactTest) Structure(de.bioforscher.jstructure.model.structure.Structure) IOException(java.io.IOException) StructureParser(de.bioforscher.jstructure.model.structure.StructureParser) Collectors(java.util.stream.Collectors) FunctionalResidueParser(de.bioforscher.start2fold.parser.FunctionalResidueParser) UncheckedIOException(java.io.UncheckedIOException) FunctionalResidueAnnotation(de.bioforscher.start2fold.model.FunctionalResidueAnnotation) Start2FoldResidueAnnotation(de.bioforscher.start2fold.model.Start2FoldResidueAnnotation) AccessibleSurfaceArea(de.bioforscher.jstructure.feature.asa.AccessibleSurfaceArea) SetOperations(de.bioforscher.jstructure.mathematics.SetOperations) AminoAcid(de.bioforscher.jstructure.model.structure.aminoacid.AminoAcid) Start2FoldXmlParser(de.bioforscher.start2fold.parser.Start2FoldXmlParser) Chain(de.bioforscher.jstructure.model.structure.Chain) StandardFormat(de.bioforscher.jstructure.StandardFormat) Jsoup(org.jsoup.Jsoup) Pattern(java.util.regex.Pattern) Path(java.nio.file.Path) Chain(de.bioforscher.jstructure.model.structure.Chain) Start2FoldResidueAnnotation(de.bioforscher.start2fold.model.Start2FoldResidueAnnotation) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) Structure(de.bioforscher.jstructure.model.structure.Structure)

Example 53 with Structure

use of de.bioforscher.jstructure.model.structure.Structure in project jstructure by JonStargaryen.

the class A03_WriteFunctionalClassificationArff method handleLine.

private static Optional<String> handleLine(String line) {
    try {
        logger.info("handling {}", line);
        String[] split = line.split(";");
        String pdbId = split[1];
        Structure structure = StructureParser.fromPdbId(pdbId).parse();
        Chain chain = structure.getFirstChain();
        List<AminoAcid> aminoAcids = chain.aminoAcids().collect(Collectors.toList());
        aminoAcids.forEach(RawFeatureVector::assignRawFeatureVector);
        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);
        }
        // ignore proteins lacking annotation of functional residues
        if (functionalResidues.isEmpty()) {
            return Optional.empty();
        }
        // smooth features
        aminoAcids.forEach(aminoAcid -> SmoothedFeatureVector.assignSmoothedFeatureVector(aminoAcids, aminoAcid));
        return Optional.of(aminoAcids.stream().filter(aminoAcid -> !(aminoAcid instanceof Proline)).map(aminoAcid -> {
            SmoothedFeatureVector smoothedFeatureVector = aminoAcid.getFeature(SmoothedFeatureVector.class);
            return StandardFormat.format(smoothedFeatureVector.getEnergy()) + "," + StandardFormat.format(smoothedFeatureVector.getEgor()) + "," + StandardFormat.format(smoothedFeatureVector.getSecondaryStructureElementSize()) + "," + StandardFormat.format(aminoAcid.getFeature(LoopFraction.class).getLoopFraction()) + // already smoothed
            "," + StandardFormat.format(smoothedFeatureVector.getRasa()) + "," + StandardFormat.format(smoothedFeatureVector.getLocalInteractions()) + "," + StandardFormat.format(smoothedFeatureVector.getLocalHydrogen()) + "," + StandardFormat.format(smoothedFeatureVector.getLocalHydrophobic()) + "," + StandardFormat.format(smoothedFeatureVector.getLocalBackbone()) + "," + StandardFormat.format(smoothedFeatureVector.getNonLocalInteractions()) + "," + StandardFormat.format(smoothedFeatureVector.getNonLocalHydrogen()) + "," + StandardFormat.format(smoothedFeatureVector.getNonLocalHydrophobic()) + "," + StandardFormat.format(smoothedFeatureVector.getNonLocalBackbone()) + "," + StandardFormat.format(smoothedFeatureVector.getBetweenness()) + "," + StandardFormat.format(smoothedFeatureVector.getCloseness()) + "," + StandardFormat.format(smoothedFeatureVector.getClusteringCoefficient()) + "," + StandardFormat.format(smoothedFeatureVector.getHydrogenBetweenness()) + "," + StandardFormat.format(smoothedFeatureVector.getHydrogenCloseness()) + "," + StandardFormat.format(smoothedFeatureVector.getHydrogenClusteringCoefficient()) + "," + StandardFormat.format(smoothedFeatureVector.getHydrophobicBetweenness()) + "," + StandardFormat.format(smoothedFeatureVector.getHydrophobicCloseness()) + "," + StandardFormat.format(smoothedFeatureVector.getHydrophobicClusteringCoefficient()) + "," + StandardFormat.format(smoothedFeatureVector.getConvBetweenness()) + "," + StandardFormat.format(smoothedFeatureVector.getConvCloseness()) + "," + StandardFormat.format(smoothedFeatureVector.getConvClusteringCoefficient()) + "," + StandardFormat.format(smoothedFeatureVector.getDistinctNeighborhoods()) + "," + StandardFormat.format(smoothedFeatureVector.getConvDistinctNeighborhoods()) + "," + (functionalResidues.contains(aminoAcid) ? "functional" : "non-functional");
        }).collect(Collectors.joining(System.lineSeparator())));
    } catch (Exception e) {
        logger.warn("computation for {} failed", line, e);
        return Optional.empty();
    }
}
Also used : RawFeatureVector(de.bioforscher.start2fold.model.vector.RawFeatureVector) Proline(de.bioforscher.jstructure.model.structure.aminoacid.Proline) Logger(org.slf4j.Logger) LoopFraction(de.bioforscher.jstructure.feature.loopfraction.LoopFraction) Files(java.nio.file.Files) LoggerFactory(org.slf4j.LoggerFactory) Structure(de.bioforscher.jstructure.model.structure.Structure) IOException(java.io.IOException) StructureParser(de.bioforscher.jstructure.model.structure.StructureParser) Collectors(java.util.stream.Collectors) FunctionalResidueParser(de.bioforscher.start2fold.parser.FunctionalResidueParser) ArrayList(java.util.ArrayList) FunctionalResidueAnnotation(de.bioforscher.start2fold.model.FunctionalResidueAnnotation) List(java.util.List) Start2FoldConstants(de.bioforscher.start2fold.Start2FoldConstants) AminoAcid(de.bioforscher.jstructure.model.structure.aminoacid.AminoAcid) SmoothedFeatureVector(de.bioforscher.start2fold.model.vector.SmoothedFeatureVector) Chain(de.bioforscher.jstructure.model.structure.Chain) Optional(java.util.Optional) StandardFormat(de.bioforscher.jstructure.StandardFormat) Chain(de.bioforscher.jstructure.model.structure.Chain) AminoAcid(de.bioforscher.jstructure.model.structure.aminoacid.AminoAcid) SmoothedFeatureVector(de.bioforscher.start2fold.model.vector.SmoothedFeatureVector) ArrayList(java.util.ArrayList) Proline(de.bioforscher.jstructure.model.structure.aminoacid.Proline) FunctionalResidueAnnotation(de.bioforscher.start2fold.model.FunctionalResidueAnnotation) IOException(java.io.IOException) LoopFraction(de.bioforscher.jstructure.feature.loopfraction.LoopFraction) Structure(de.bioforscher.jstructure.model.structure.Structure) RawFeatureVector(de.bioforscher.start2fold.model.vector.RawFeatureVector)

Example 54 with Structure

use of de.bioforscher.jstructure.model.structure.Structure in project jstructure by JonStargaryen.

the class A06_EarlyFoldingFrequencies method handleLine.

private static void handleLine(String line) {
    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);
    List<AminoAcid> earlyFoldingResidues = chain.aminoAcids().filter(aminoAcid -> aminoAcid.getFeature(Start2FoldResidueAnnotation.class).isEarly()).collect(Collectors.toList());
    chain.aminoAcids().forEach(aminoAcid -> {
        int ordinal = AminoAcid.Family.resolveOneLetterCode(aminoAcid.getOneLetterCode()).ordinal();
        aminoAcidFrequencies[ordinal]++;
    });
    earlyFoldingResidues.forEach(aminoAcid -> {
        int ordinal = AminoAcid.Family.resolveOneLetterCode(aminoAcid.getOneLetterCode()).ordinal();
        earlyFoldingFrequencies[ordinal]++;
    });
}
Also used : IntStream(java.util.stream.IntStream) Files(java.nio.file.Files) Structure(de.bioforscher.jstructure.model.structure.Structure) IOException(java.io.IOException) StructureParser(de.bioforscher.jstructure.model.structure.StructureParser) Collectors(java.util.stream.Collectors) Start2FoldResidueAnnotation(de.bioforscher.start2fold.model.Start2FoldResidueAnnotation) List(java.util.List) Start2FoldConstants(de.bioforscher.start2fold.Start2FoldConstants) AminoAcid(de.bioforscher.jstructure.model.structure.aminoacid.AminoAcid) Start2FoldXmlParser(de.bioforscher.start2fold.parser.Start2FoldXmlParser) Chain(de.bioforscher.jstructure.model.structure.Chain) StandardFormat(de.bioforscher.jstructure.StandardFormat) Pattern(java.util.regex.Pattern) Chain(de.bioforscher.jstructure.model.structure.Chain) AminoAcid(de.bioforscher.jstructure.model.structure.aminoacid.AminoAcid) Start2FoldResidueAnnotation(de.bioforscher.start2fold.model.Start2FoldResidueAnnotation) Structure(de.bioforscher.jstructure.model.structure.Structure)

Example 55 with Structure

use of de.bioforscher.jstructure.model.structure.Structure in project jstructure by JonStargaryen.

the class A02_CreatePyMolRenderJobsForStrongResidues method composePyMolCommand.

private static Optional<String> composePyMolCommand(Path path) {
    try {
        String entryId = path.toFile().getName().split("\\.")[0];
        String pdbId = Jsoup.parse(path.toFile(), "UTF-8").getElementsByTag("protein").attr("pdb_id");
        Structure structure = StructureParser.fromPdbId(pdbId).parse();
        Chain chain = structure.chains().findFirst().get();
        Start2FoldXmlParser.parse(chain, Start2FoldConstants.XML_DIRECTORY.resolve(entryId + ".xml"));
        List<Integer> strongResidues = chain.aminoAcids().filter(aminoAcid -> aminoAcid.getFeature(Start2FoldResidueAnnotation.class).isStrong()).map(AminoAcid::getResidueIdentifier).map(ResidueIdentifier::getResidueNumber).collect(Collectors.toList());
        if (strongResidues.isEmpty()) {
            return Optional.empty();
        }
        return Optional.of("delete all" + System.lineSeparator() + "fetch " + pdbId + ", async=0" + System.lineSeparator() + // hide non-relevant stuff
        "hide everything" + System.lineSeparator() + "show cartoon, chain A" + System.lineSeparator() + // decolor everything
        "color grey80" + System.lineSeparator() + "zoom (chain A)" + System.lineSeparator() + strongResidues.stream().map(res -> "color efr, resi " + res).collect(Collectors.joining(System.lineSeparator())) + System.lineSeparator() + "ray" + System.lineSeparator() + "png " + Start2FoldConstants.PYMOL_DIRECTORY.resolve(entryId + "-strong.png") + System.lineSeparator());
    } catch (IOException e) {
        return Optional.empty();
    }
}
Also used : Start2FoldResidueAnnotation(de.bioforscher.jstructure.efr.model.Start2FoldResidueAnnotation) Files(java.nio.file.Files) ResidueIdentifier(de.bioforscher.jstructure.model.identifier.ResidueIdentifier) Structure(de.bioforscher.jstructure.model.structure.Structure) IOException(java.io.IOException) StructureParser(de.bioforscher.jstructure.model.structure.StructureParser) Collectors(java.util.stream.Collectors) Start2FoldXmlParser(de.bioforscher.jstructure.efr.parser.Start2FoldXmlParser) Start2FoldConstants(de.bioforscher.jstructure.efr.Start2FoldConstants) List(java.util.List) AminoAcid(de.bioforscher.jstructure.model.structure.aminoacid.AminoAcid) Chain(de.bioforscher.jstructure.model.structure.Chain) Optional(java.util.Optional) StandardFormat(de.bioforscher.jstructure.StandardFormat) Jsoup(org.jsoup.Jsoup) Path(java.nio.file.Path) Chain(de.bioforscher.jstructure.model.structure.Chain) AminoAcid(de.bioforscher.jstructure.model.structure.aminoacid.AminoAcid) Start2FoldResidueAnnotation(de.bioforscher.jstructure.efr.model.Start2FoldResidueAnnotation) IOException(java.io.IOException) Structure(de.bioforscher.jstructure.model.structure.Structure)

Aggregations

Structure (de.bioforscher.jstructure.model.structure.Structure)61 IOException (java.io.IOException)45 Collectors (java.util.stream.Collectors)40 Chain (de.bioforscher.jstructure.model.structure.Chain)39 Files (java.nio.file.Files)35 StructureParser (de.bioforscher.jstructure.model.structure.StructureParser)30 Path (java.nio.file.Path)26 AminoAcid (de.bioforscher.jstructure.model.structure.aminoacid.AminoAcid)23 List (java.util.List)22 StandardFormat (de.bioforscher.jstructure.StandardFormat)21 Logger (org.slf4j.Logger)20 LoggerFactory (org.slf4j.LoggerFactory)20 Test (org.junit.Test)19 Group (de.bioforscher.jstructure.model.structure.Group)18 UncheckedIOException (java.io.UncheckedIOException)18 Pattern (java.util.regex.Pattern)17 Stream (java.util.stream.Stream)17 Jsoup (org.jsoup.Jsoup)17 ComputationException (de.bioforscher.jstructure.model.feature.ComputationException)16 java.util (java.util)15