Search in sources :

Example 6 with AminoAcid

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

the class ProteinParserTest method shouldHandleProteinWithOligopeptide.

@Test
public void shouldHandleProteinWithOligopeptide() {
    Protein protein = ProteinParser.source("1lyb").parse();
    // contains peptide-like groups - ought to be an AminoAcid
    AminoAcid statine = (AminoAcid) protein.select().groupName("STA").asGroup();
    Assert.assertTrue(statine.getPolymerType() == GroupPrototype.PolymerType.PEPTIDE_LIKE);
    Assert.assertTrue(statine.isAminoAcid());
    Assert.assertFalse(statine.isLigand());
    Assert.assertTrue(protein.aminoAcids().collect(Collectors.toList()).contains(statine));
}
Also used : AminoAcid(de.bioforscher.jstructure.model.structure.aminoacid.AminoAcid) Protein(de.bioforscher.jstructure.model.structure.Protein) Test(org.junit.Test)

Example 7 with AminoAcid

use of de.bioforscher.jstructure.model.structure.aminoacid.AminoAcid 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();
    }
}
Also used : LoopFraction(de.bioforscher.jstructure.feature.loopfraction.LoopFraction) ComputationException(de.bioforscher.jstructure.model.feature.ComputationException) LoggerFactory(org.slf4j.LoggerFactory) EQuantScore(de.bioforscher.jstructure.efr.model.EQuantScore) Structure(de.bioforscher.jstructure.model.structure.Structure) GenericSecondaryStructure(de.bioforscher.jstructure.feature.sse.GenericSecondaryStructure) StructureParser(de.bioforscher.jstructure.model.structure.StructureParser) EgorAgreement(de.bioforscher.jstructure.feature.energyprofile.EgorAgreement) HotSpotScoring(de.bioforscher.jstructure.efr.model.HotSpotScoring) ArrayList(java.util.ArrayList) AminoAcid(de.bioforscher.jstructure.model.structure.aminoacid.AminoAcid) Chain(de.bioforscher.jstructure.model.structure.Chain) ResidueStructuralInformation(de.bioforscher.jstructure.efr.model.si.ResidueStructuralInformation) StandardFormat(de.bioforscher.jstructure.StandardFormat) Path(java.nio.file.Path) EnergyProfile(de.bioforscher.jstructure.feature.energyprofile.EnergyProfile) Logger(org.slf4j.Logger) GeometricProperties(de.bioforscher.jstructure.feature.geometry.GeometricProperties) Start2FoldResidueAnnotation(de.bioforscher.jstructure.efr.model.Start2FoldResidueAnnotation) Files(java.nio.file.Files) de.bioforscher.jstructure.efr.parser(de.bioforscher.jstructure.efr.parser) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) FunctionalResidueAnnotation(de.bioforscher.jstructure.efr.model.FunctionalResidueAnnotation) Start2FoldConstants(de.bioforscher.jstructure.efr.Start2FoldConstants) List(java.util.List) AccessibleSurfaceArea(de.bioforscher.jstructure.feature.asa.AccessibleSurfaceArea) ResidueTopologicPropertiesContainer(de.bioforscher.jstructure.graph.ResidueTopologicPropertiesContainer) ResidueGraph(de.bioforscher.jstructure.graph.ResidueGraph) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) ContactStructuralInformation(de.bioforscher.jstructure.efr.model.si.ContactStructuralInformation) PLIPInteractionContainer(de.bioforscher.jstructure.feature.interaction.PLIPInteractionContainer) Comparator(java.util.Comparator) ContactDefinitionFactory(de.bioforscher.jstructure.graph.contact.definition.ContactDefinitionFactory) Chain(de.bioforscher.jstructure.model.structure.Chain) ArrayList(java.util.ArrayList) GenericSecondaryStructure(de.bioforscher.jstructure.feature.sse.GenericSecondaryStructure) ContactStructuralInformation(de.bioforscher.jstructure.efr.model.si.ContactStructuralInformation) HotSpotScoring(de.bioforscher.jstructure.efr.model.HotSpotScoring) LoopFraction(de.bioforscher.jstructure.feature.loopfraction.LoopFraction) ComputationException(de.bioforscher.jstructure.model.feature.ComputationException) ArrayList(java.util.ArrayList) List(java.util.List) Structure(de.bioforscher.jstructure.model.structure.Structure) GenericSecondaryStructure(de.bioforscher.jstructure.feature.sse.GenericSecondaryStructure) GeometricProperties(de.bioforscher.jstructure.feature.geometry.GeometricProperties) AccessibleSurfaceArea(de.bioforscher.jstructure.feature.asa.AccessibleSurfaceArea) Path(java.nio.file.Path) AminoAcid(de.bioforscher.jstructure.model.structure.aminoacid.AminoAcid) EgorAgreement(de.bioforscher.jstructure.feature.energyprofile.EgorAgreement) Start2FoldResidueAnnotation(de.bioforscher.jstructure.efr.model.Start2FoldResidueAnnotation) ResidueTopologicPropertiesContainer(de.bioforscher.jstructure.graph.ResidueTopologicPropertiesContainer) ResidueStructuralInformation(de.bioforscher.jstructure.efr.model.si.ResidueStructuralInformation) FunctionalResidueAnnotation(de.bioforscher.jstructure.efr.model.FunctionalResidueAnnotation) EQuantScore(de.bioforscher.jstructure.efr.model.EQuantScore) ComputationException(de.bioforscher.jstructure.model.feature.ComputationException) IOException(java.io.IOException) EnergyProfile(de.bioforscher.jstructure.feature.energyprofile.EnergyProfile) ResidueGraph(de.bioforscher.jstructure.graph.ResidueGraph) PLIPInteractionContainer(de.bioforscher.jstructure.feature.interaction.PLIPInteractionContainer)

Example 8 with AminoAcid

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

the class A01_CreatePyMolRenderJobsForEarlyFoldingResidues method composePyMolCommand.

private static String composePyMolCommand(String 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<Integer> earlyFoldingResidues = chain.aminoAcids().filter(aminoAcid -> aminoAcid.getFeature(Start2FoldResidueAnnotation.class).isEarly()).map(AminoAcid::getResidueIdentifier).map(ResidueIdentifier::getResidueNumber).collect(Collectors.toList());
    return "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() + earlyFoldingResidues.stream().map(res -> "color efr, resi " + res).collect(Collectors.joining(System.lineSeparator())) + System.lineSeparator() + "ray" + System.lineSeparator() + "png " + Start2FoldConstants.PYMOL_DIRECTORY.resolve(entryId + "-efr.png") + System.lineSeparator();
}
Also used : 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) 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 9 with AminoAcid

use of de.bioforscher.jstructure.model.structure.aminoacid.AminoAcid 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)

Example 10 with AminoAcid

use of de.bioforscher.jstructure.model.structure.aminoacid.AminoAcid 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();
    }
}
Also used : DataSource(de.bioforscher.jstructure.si.explorer.DataSource) List(java.util.List) Files(java.nio.file.Files) StringJoiner(java.util.StringJoiner) SetOperations(de.bioforscher.jstructure.mathematics.SetOperations) AminoAcid(de.bioforscher.jstructure.model.structure.aminoacid.AminoAcid) Chain(de.bioforscher.jstructure.model.structure.Chain) ExplorerChain(de.bioforscher.jstructure.si.explorer.ExplorerChain) Optional(java.util.Optional) ContactStructuralInformation(de.bioforscher.jstructure.efr.model.si.ContactStructuralInformation) Collectors(java.util.stream.Collectors) Start2FoldConstants(de.bioforscher.jstructure.efr.Start2FoldConstants) Chain(de.bioforscher.jstructure.model.structure.Chain) ExplorerChain(de.bioforscher.jstructure.si.explorer.ExplorerChain) AminoAcid(de.bioforscher.jstructure.model.structure.aminoacid.AminoAcid) ContactStructuralInformation(de.bioforscher.jstructure.efr.model.si.ContactStructuralInformation) StringJoiner(java.util.StringJoiner)

Aggregations

AminoAcid (de.bioforscher.jstructure.model.structure.aminoacid.AminoAcid)66 Chain (de.bioforscher.jstructure.model.structure.Chain)40 Collectors (java.util.stream.Collectors)40 IOException (java.io.IOException)36 Files (java.nio.file.Files)35 List (java.util.List)31 StandardFormat (de.bioforscher.jstructure.StandardFormat)26 StructureParser (de.bioforscher.jstructure.model.structure.StructureParser)26 Path (java.nio.file.Path)25 Structure (de.bioforscher.jstructure.model.structure.Structure)23 Pattern (java.util.regex.Pattern)17 Logger (org.slf4j.Logger)16 LoggerFactory (org.slf4j.LoggerFactory)16 Start2FoldResidueAnnotation (de.bioforscher.jstructure.efr.model.Start2FoldResidueAnnotation)15 UncheckedIOException (java.io.UncheckedIOException)14 ArrayList (java.util.ArrayList)14 Stream (java.util.stream.Stream)14 Start2FoldResidueAnnotation (de.bioforscher.start2fold.model.Start2FoldResidueAnnotation)13 Optional (java.util.Optional)13 Pair (de.bioforscher.jstructure.mathematics.Pair)11