Search in sources :

Example 16 with Group

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

the class PLIPParser method parse.

public static List<PLIPInteraction> parse(Chain chain, Document document) {
    List<PLIPInteraction> plipInteractions = new ArrayList<>();
    for (PLIPInteractionType plipInteractionType : PLIPInteractionType.values()) {
        logger.debug("parsing interactions of type {}", plipInteractionType);
        Elements interactionElements = document.getElementsByTag(plipInteractionType.getInteractionTag());
        for (Element interactionElement : interactionElements) {
            Optional<Group> currentGroup = interactionElement.getElementsByTag("resnr").stream().map(Element::text).filter(string -> string.length() < 10).mapToInt(Integer::valueOf).mapToObj(residueNumber -> chain.select().residueNumber(residueNumber).asOptionalGroup()).findFirst().orElse(Optional.empty());
            if (!currentGroup.isPresent()) {
                //TODO does a partner in another chain actually make sense?
                logger.trace("reference to group in different chain or failed to parse line:{}{}", System.lineSeparator(), interactionElement.text());
                continue;
            }
            try {
                Constructor<? extends PLIPInteraction> constructor = plipInteractionType.getDescribingClass().getDeclaredConstructor(Group.class, Element.class);
                constructor.setAccessible(true);
                PLIPInteraction plipInteraction = constructor.newInstance(currentGroup.get(), interactionElement);
                plipInteractions.add(plipInteraction);
            } catch (Exception e) {
                // move to root cause
                Throwable cause = e;
                while (cause.getCause() != null) {
                    cause = cause.getCause();
                }
                logger.warn("encountered exception during plip parsing: {}", cause);
                throw new ComputationException(e);
            }
        }
    }
    // merge entries which need merging and remove the merged entries
    List<PLIPInteraction> plipInteractionsToRemove = new ArrayList<>();
    for (PLIPInteraction plipInteraction : plipInteractions) {
        Group partner1 = plipInteraction.getPartner1();
        Group partner2 = plipInteraction.getPartner2();
        if (plipInteraction instanceof PiCationInteraction || plipInteraction instanceof PiStacking || plipInteraction instanceof SaltBridge) {
            // keep only those interactions where the first resNum is smaller
            if (partner1.getResidueNumber().getResidueNumber() > partner2.getResidueNumber().getResidueNumber()) {
                plipInteractionsToRemove.add(plipInteraction);
                continue;
            }
            try {
                if (plipInteraction instanceof PiCationInteraction) {
                    PiCationInteraction otherHalfOfInteraction = plipInteractions.stream().filter(PiCationInteraction.class::isInstance).map(PiCationInteraction.class::cast).filter(piCationInteraction -> piCationInteraction.getPartner1().equals(partner2) && piCationInteraction.getPartner2().equals(partner1)).findFirst().orElseThrow(NoSuchElementException::new);
                    ((PiCationInteraction) plipInteraction).getAtoms1().addAll(otherHalfOfInteraction.getAtoms2());
                } else if (plipInteraction instanceof PiStacking) {
                    PiStacking otherHalfOfInteraction = plipInteractions.stream().filter(PiStacking.class::isInstance).map(PiStacking.class::cast).filter(piStacking -> piStacking.getPartner1().equals(partner2) && piStacking.getPartner2().equals(partner1)).findFirst().orElseThrow(NoSuchElementException::new);
                    ((PiStacking) plipInteraction).getAtoms1().addAll(otherHalfOfInteraction.getAtoms2());
                } else {
                    SaltBridge otherHalfOfInteraction = plipInteractions.stream().filter(SaltBridge.class::isInstance).map(SaltBridge.class::cast).filter(saltBridge -> saltBridge.getPartner1().equals(partner2) && saltBridge.getPartner2().equals(partner1)).findFirst().orElseThrow(NoSuchElementException::new);
                    ((SaltBridge) plipInteraction).getAtoms1().addAll(otherHalfOfInteraction.getAtoms2());
                }
            } catch (NoSuchElementException e) {
                logger.debug("could not find other half of {} {} {}", plipInteraction.getClass().getSimpleName(), plipInteraction.getPartner1().getIdentifier(), plipInteraction.getPartner2().getIdentifier());
            }
        }
    }
    plipInteractions.removeAll(plipInteractionsToRemove);
    return plipInteractions;
}
Also used : Logger(org.slf4j.Logger) ComputationException(de.bioforscher.jstructure.feature.ComputationException) LoggerFactory(org.slf4j.LoggerFactory) Constructor(java.lang.reflect.Constructor) ArrayList(java.util.ArrayList) List(java.util.List) Group(de.bioforscher.jstructure.model.structure.Group) Document(org.jsoup.nodes.Document) Element(org.jsoup.nodes.Element) Chain(de.bioforscher.jstructure.model.structure.Chain) Optional(java.util.Optional) Elements(org.jsoup.select.Elements) NoSuchElementException(java.util.NoSuchElementException) Group(de.bioforscher.jstructure.model.structure.Group) Element(org.jsoup.nodes.Element) ArrayList(java.util.ArrayList) Elements(org.jsoup.select.Elements) ComputationException(de.bioforscher.jstructure.feature.ComputationException) NoSuchElementException(java.util.NoSuchElementException) ComputationException(de.bioforscher.jstructure.feature.ComputationException) NoSuchElementException(java.util.NoSuchElementException)

Example 17 with Group

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

the class AbstractAlignmentAlgorithm method comparableGroupContainerPair.

/**
     * Creates a comparable entity of 2 {@link AtomContainer} objects. They fulfill certain criteria:
     * <ul>
     *     <li>{@link Atom}s are cloned
     *     <li>for each {@link Group} only shared atoms are retained</li>
     *     <li>{@link Atom}s are in identical ordering</li>
     *     <li>{@link Atom}s are wrapped in {@link Group} objects if they were initially</li>
     * </ul>
     * @param container1 a collection of reference atoms
     * @param container2 a collection of candidate atoms
     * @param minimalSetOfAtomNames the lower bound of required atom names present (e.g. by setting CA, every time an
     *                              amino acid missing the alpha carbon will result in an exception thrown)
     * @param maximalSetOfAtomNames the upper bound of required atom names present (e.g. by setting CA, everything else
     *                              will be dropped, even when both amino acids would share more atoms)
     * @return a pair of both collections which can now be aligned
     */
static Pair<GroupContainer, GroupContainer> comparableGroupContainerPair(AtomContainer container1, AtomContainer container2, Set<String> minimalSetOfAtomNames, Set<String> maximalSetOfAtomNames) {
    //TODO what happens for alternative positions?
    GroupContainer groupContainer1 = cloneIntoGroupContainer(container1);
    GroupContainer groupContainer2 = cloneIntoGroupContainer(container2);
    int limitingSize = Math.min(groupContainer1.getGroups().size(), groupContainer2.getGroups().size());
    List<Group> groups1 = new ArrayList<>();
    List<Group> groups2 = new ArrayList<>();
    for (int groupIndex = 0; groupIndex < limitingSize; groupIndex++) {
        Group group1 = groupContainer1.getGroups().get(groupIndex);
        Group group2 = groupContainer2.getGroups().get(groupIndex);
        Pair<List<Atom>, List<Atom>> sharedAtoms = selectSharedAtoms(group1, group2, minimalSetOfAtomNames, maximalSetOfAtomNames);
        // remove additional/not-shared atoms
        group1.getAtoms().clear();
        group1.getAtoms().addAll(sharedAtoms.getLeft());
        group2.getAtoms().clear();
        group2.getAtoms().addAll(sharedAtoms.getRight());
        logger.trace("shared atoms between {} and {}: {}", group1, group2, sharedAtoms);
        groups1.add(group1);
        groups2.add(group2);
    }
    return new Pair<>(groups1.stream().collect(StructureCollectors.toGroupContainer()), groups2.stream().collect(StructureCollectors.toGroupContainer()));
}
Also used : Group(de.bioforscher.jstructure.model.structure.Group) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) GroupContainer(de.bioforscher.jstructure.model.structure.container.GroupContainer) Pair(de.bioforscher.jstructure.model.Pair)

Example 18 with Group

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

the class SecondaryStructureAnnotator method isBonded.

/**
     * Test if two groups are forming an H-Bond. The bond tested is from the CO
     * of group i to the NH of group j. Acceptor (i) and donor (j). The donor of
     * i has to be j, and the acceptor of j has to be i. DSSP defines H-Bonds if
     * the energy < -500 cal/mol.
     *
     * @param i
     *            group one
     * @param j
     *            group two
     * @return flag if the two are forming an Hbond
     */
private boolean isBonded(List<AminoAcid> residues, int i, int j) {
    Group residue1 = residues.get(i);
    Group residue2 = residues.get(j);
    SecondaryStructure state1 = getState(residue1);
    SecondaryStructure state2 = getState(residue2);
    double don1e = state1.getDonor1().getEnergy();
    double don2e = state1.getDonor2().getEnergy();
    double acc1e = state2.getAccept1().getEnergy();
    double acc2e = state2.getAccept2().getEnergy();
    Group don1p = state1.getDonor1().getPartner();
    Group don2p = state1.getDonor2().getPartner();
    Group acc1p = state2.getAccept1().getPartner();
    Group acc2p = state2.getAccept2().getPartner();
    // Either donor from i is j, or accept from j is i
    boolean hbond = (residue2.equals(don1p) && don1e < HBONDHIGHENERGY) || (residue2.equals(don2p) && don2e < HBONDHIGHENERGY) || (residue1.equals(acc1p) && acc1e < HBONDHIGHENERGY) || (residue1.equals(acc2p) && acc2e < HBONDHIGHENERGY);
    if (hbond) {
        logger.debug("*** H-bond from CO of {} to NH of {}", i, j);
        return true;
    }
    return false;
}
Also used : Group(de.bioforscher.jstructure.model.structure.Group)

Example 19 with Group

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

the class AbstractItemSetMinerDataSetComposer method handleLine.

private String handleLine(Protein protein, String line, boolean functional) {
    try {
        String[] sectionSplit = line.split("_");
        PLIPInteractionContainer container = protein.getFeatureContainer().getFeature(PLIPInteractionContainer.class);
        // extract peculiar residues
        List<Group> groups = Stream.of(sectionSplit).skip(1).map(residueSection -> extractResidue(protein, residueSection)).collect(Collectors.toList());
        return groups.stream().map(group -> mapToString(container, group)).collect(Collectors.joining(",", line + ",", "," + (functional ? "" : "non-") + "functional"));
    } catch (Exception e) {
        e.fillInStackTrace();
        // thrown upon missing backbone atoms during secondary structure assignment
        return "";
    }
}
Also used : AbstractFeatureProvider(de.bioforscher.jstructure.model.feature.AbstractFeatureProvider) EnergyProfile(de.bioforscher.jstructure.feature.energyprofile.EnergyProfile) ProteinParser(de.bioforscher.jstructure.parser.ProteinParser) LoopFraction(de.bioforscher.jstructure.feature.loopfraction.LoopFraction) Files(java.nio.file.Files) FileWriter(java.io.FileWriter) DecimalFormat(java.text.DecimalFormat) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) PLIPInteractionContainer(de.bioforscher.jstructure.feature.interactions.PLIPInteractionContainer) List(java.util.List) AccessibleSurfaceArea(de.bioforscher.jstructure.feature.asa.AccessibleSurfaceArea) PLIPInteraction(de.bioforscher.jstructure.feature.interactions.PLIPInteraction) Stream(java.util.stream.Stream) Paths(java.nio.file.Paths) Group(de.bioforscher.jstructure.model.structure.Group) Map(java.util.Map) Protein(de.bioforscher.jstructure.model.structure.Protein) FeatureProviderRegistry(de.bioforscher.jstructure.model.feature.FeatureProviderRegistry) Group(de.bioforscher.jstructure.model.structure.Group) PLIPInteractionContainer(de.bioforscher.jstructure.feature.interactions.PLIPInteractionContainer) IOException(java.io.IOException)

Example 20 with Group

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

the class AbstractItemSetMinerDataSetComposer method extractResidue.

private Group extractResidue(Protein protein, String residueSection) {
    String[] split = residueSection.split("-");
    Group group = protein.select().chainName(split[0]).residueNumber(Integer.valueOf(split[1].substring(1))).asGroup();
    // check for integrity
    if (!group.getGroupPrototype().getOneLetterCode().get().equals(split[1].substring(0, 1))) {
        // happens for alternative positions
        throw new IllegalArgumentException("amino acid does not match expectation: " + residueSection + " found " + group.getGroupPrototype().getOneLetterCode());
    }
    return group;
}
Also used : Group(de.bioforscher.jstructure.model.structure.Group)

Aggregations

Group (de.bioforscher.jstructure.model.structure.Group)28 Atom (de.bioforscher.jstructure.model.structure.Atom)10 Chain (de.bioforscher.jstructure.model.structure.Chain)8 Structure (de.bioforscher.jstructure.model.structure.Structure)8 IOException (java.io.IOException)8 List (java.util.List)8 Collectors (java.util.stream.Collectors)8 Document (org.jsoup.nodes.Document)7 Element (org.jsoup.nodes.Element)7 Test (org.junit.Test)7 Protein (de.bioforscher.jstructure.model.structure.Protein)6 Files (java.nio.file.Files)6 Stream (java.util.stream.Stream)6 Elements (org.jsoup.select.Elements)6 Logger (org.slf4j.Logger)6 LoggerFactory (org.slf4j.LoggerFactory)6 BufferedReader (java.io.BufferedReader)4 InputStreamReader (java.io.InputStreamReader)4 UncheckedIOException (java.io.UncheckedIOException)4 URL (java.net.URL)4