Search in sources :

Example 6 with Group

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

the class ProteinParserTest method shouldAnnotateHetAtmsCorrectlyFor1bs2.

@Test
public void shouldAnnotateHetAtmsCorrectlyFor1bs2() {
    /*
         * 1bs2 is an aars structure with the amino acid arginine in the binding site (annotated as ATOM record), some
         * water (annotated as HETATM)
         */
    Protein protein1bs2 = ProteinParser.source("1bs2").parse();
    List<Group> waters = protein1bs2.select().water().asFilteredGroups().collect(Collectors.toList());
    waters.forEach(group -> {
        Assert.assertTrue(group.isLigand());
        Assert.assertTrue("water records ought to start with HETATM", group.getPdbRepresentation().startsWith(Atom.HETATM_PREFIX));
    });
    Group arginineAsLigand = protein1bs2.select().residueNumber(900).asGroup();
    // assert that selection does not return ARG ligand as normal amino acid
    boolean arginineLigandIsNoAminoAcid = protein1bs2.aminoAcids().noneMatch(group -> group.equals(arginineAsLigand));
    Assert.assertTrue("amino acid ligand ought to be not a part of the amino acid chain", arginineLigandIsNoAminoAcid);
    // ensure last amino acid is MET and not the ARG ligand
    Assert.assertThat(protein1bs2.getAminoAcidSequence(), endsWith("M"));
    List<Group> hetatm1bs2 = protein1bs2.select().hetatms().asFilteredGroups().collect(Collectors.toList());
    Assert.assertTrue(hetatm1bs2.containsAll(waters) && hetatm1bs2.contains(arginineAsLigand));
}
Also used : Group(de.bioforscher.jstructure.model.structure.Group) Protein(de.bioforscher.jstructure.model.structure.Protein) Test(org.junit.Test)

Example 7 with Group

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

the class ProteinParserTest method shouldHandleModifiedResidue.

@Test
public void shouldHandleModifiedResidue() {
    Protein protein = ProteinParser.source("1brr").parse();
    Group pca = protein.select().chainName("C").residueNumber(1).asGroup();
    Assert.assertTrue(pca.isAminoAcid());
    Assert.assertFalse(pca.isLigand());
    // assert correct mapping of PCA to GLU
    Assert.assertEquals("incorrect mapping of PCA to GLU", "E", pca.getGroupPrototype().getOneLetterCode().get());
}
Also used : Group(de.bioforscher.jstructure.model.structure.Group) Protein(de.bioforscher.jstructure.model.structure.Protein) Test(org.junit.Test)

Example 8 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 9 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 10 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)

Aggregations

Group (de.bioforscher.jstructure.model.structure.Group)13 Protein (de.bioforscher.jstructure.model.structure.Protein)7 List (java.util.List)6 ProteinParser (de.bioforscher.jstructure.parser.ProteinParser)4 IOException (java.io.IOException)4 Collectors (java.util.stream.Collectors)4 Test (org.junit.Test)4 AbstractFeatureProvider (de.bioforscher.jstructure.model.feature.AbstractFeatureProvider)3 Files (java.nio.file.Files)3 Paths (java.nio.file.Paths)3 Document (org.jsoup.nodes.Document)3 ComputationException (de.bioforscher.jstructure.feature.ComputationException)2 FeatureProviderRegistry (de.bioforscher.jstructure.model.feature.FeatureProviderRegistry)2 Chain (de.bioforscher.jstructure.model.structure.Chain)2 ProteinIdentifier (de.bioforscher.jstructure.model.structure.identifier.ProteinIdentifier)2 DecimalFormat (java.text.DecimalFormat)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Stream (java.util.stream.Stream)2 Jsoup (org.jsoup.Jsoup)2