Search in sources :

Example 1 with Chain

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

the class UniProtMutationsForBindingSite method handleBindingSite.

private static void handleBindingSite(BindingSite bindingSite) {
    String uniProtId = AARSConstants.lines(EFFECTS_TSV).map(line -> line.split(DEL)).filter(split -> split[0].equals(bindingSite.pdbId)).filter(split -> split[1].equals(bindingSite.chainId)).findAny().get()[2];
    // load original, full structure
    Chain originalChain = ProteinParser.source(bindingSite.pdbId).parse().select().chainName(bindingSite.chainId).asChain();
    String pdbSequence = originalChain.getAminoAcidSequence();
    String uniProtSequence = loadUniProtSequence(uniProtId);
    // align sequences
    SequencePair<ProteinSequence, AminoAcidCompound> alignment = needle(uniProtSequence, pdbSequence);
    System.out.println(bindingSite);
    System.out.println(alignment);
    // load renumbered, but not transformed chain
    Chain renumberedChain = ProteinParser.source(Paths.get("/home/bittrich/git/aars_analysis/data/msa/" + classToProcess + "/renumbered_structures/" + bindingSite.pdbId + "_renum.pdb")).parse().select().chainName(bindingSite.chainId).asChain();
    // key: renumbered, transformed binding site group - value: original group in PDB chain
    List<Integer> residueIndices = bindingSite.residues.stream().map(Group::getResidueNumber).map(ResidueNumber::getResidueNumber).collect(Collectors.toList());
    Map<Group, Group> groupMapping = renumberedChain.aminoAcids().filter(aminoAcid -> residueIndices.contains(aminoAcid.getResidueNumber())).collect(Collectors.toMap(Function.identity(), // map each group to the entity in the not renumbered structure
    renumberedGroup -> originalChain.select().groupName(renumberedGroup.getThreeLetterCode()).asFilteredGroups().min(Comparator.comparingDouble(originalGroup -> originalGroup.calculate().centroid().distanceFast(renumberedGroup.calculate().centroid()))).get()));
    // determine sequence position in sequence alignment - rarely these indices do not match
    groupMapping.entrySet().forEach(entry -> {
        int residueIndex = originalChain.getGroups().indexOf(entry.getValue()) + 1;
        System.out.print("mapped: " + entry.getKey().getIdentifier() + " -> " + entry.getValue().getIdentifier() + " -> uniprot ");
        try {
            int indexInUniProt = alignment.getIndexInQueryForTargetAt(residueIndex);
            System.out.println(alignment.getCompoundInQueryAt(indexInUniProt).getLongName().toUpperCase() + "-" + indexInUniProt);
            String indexToFind = String.valueOf(indexInUniProt);
            AARSConstants.lines(EFFECTS_TSV).map(line -> line.split("\t")).filter(split -> split[0].equals(bindingSite.pdbId)).filter(split -> split[1].equals(bindingSite.chainId)).filter(split -> refersToPosition(split, indexToFind)).forEach(split -> {
                String outputLine = bindingSite.pdbId + DEL + bindingSite.chainId + DEL + split[2] + DEL + bindingSite.clazz + DEL + bindingSite.aa + DEL + bindingSite.mode + DEL + entry.getKey().getResidueNumber() + DEL + entry.getValue().getResidueNumber() + DEL + split[3] + DEL + split[4] + DEL + split[5] + DEL + split[6] + DEL + split[7] + System.lineSeparator();
                System.out.println(outputLine);
                output.append(outputLine);
            });
        } catch (ArrayIndexOutOfBoundsException e) {
            System.out.println("failed!");
            warnings.append("#could not map ").append(entry.getValue().getIdentifier()).append(" in ").append(bindingSite.pdbId).append("_").append(bindingSite.chainId).append(" to UniProt sequence").append(System.lineSeparator());
        }
    });
}
Also used : Function(java.util.function.Function) ProteinSequence(org.biojava.nbio.core.sequence.ProteinSequence) SimpleGapPenalty(org.biojava.nbio.alignment.SimpleGapPenalty) Group(de.bioforscher.jstructure.model.structure.Group) Map(java.util.Map) Chain(de.bioforscher.jstructure.model.structure.Chain) SubstitutionMatrixHelper(org.biojava.nbio.core.alignment.matrices.SubstitutionMatrixHelper) CompoundNotFoundException(org.biojava.nbio.core.exceptions.CompoundNotFoundException) Protein(de.bioforscher.jstructure.model.structure.Protein) Path(java.nio.file.Path) ResidueNumber(de.bioforscher.jstructure.model.structure.ResidueNumber) ProteinIdentifier(de.bioforscher.jstructure.model.structure.identifier.ProteinIdentifier) ProteinParser(de.bioforscher.jstructure.parser.ProteinParser) Files(java.nio.file.Files) SequencePair(org.biojava.nbio.core.alignment.template.SequencePair) AminoAcidCompound(org.biojava.nbio.core.sequence.compound.AminoAcidCompound) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) File(java.io.File) UncheckedIOException(java.io.UncheckedIOException) List(java.util.List) Paths(java.nio.file.Paths) Alignments(org.biojava.nbio.alignment.Alignments) Document(org.jsoup.nodes.Document) Jsoup(org.jsoup.Jsoup) Pattern(java.util.regex.Pattern) Comparator(java.util.Comparator) Chain(de.bioforscher.jstructure.model.structure.Chain) Group(de.bioforscher.jstructure.model.structure.Group) ProteinSequence(org.biojava.nbio.core.sequence.ProteinSequence) AminoAcidCompound(org.biojava.nbio.core.sequence.compound.AminoAcidCompound)

Example 2 with Chain

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

the class ModelIntegrityTest method shouldGetGroupCopy.

@Test
public void shouldGetGroupCopy() {
    GroupContainer copiedGroups = protein.select().chainName("A", "C").groupName(Asparagine.THREE_LETTER_CODE).asGroupContainer().createCopy();
    Assert.assertTrue(copiedGroups instanceof Chain);
    System.out.println(copiedGroups.getPdbRepresentation());
}
Also used : Chain(de.bioforscher.jstructure.model.structure.Chain) GroupContainer(de.bioforscher.jstructure.model.structure.container.GroupContainer) Test(org.junit.Test)

Example 3 with Chain

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

the class PLIPParserTest method shouldAnnotateProtein.

@Test
public void shouldAnnotateProtein() {
    String pdbId = "1brr";
    String chainId = "A";
    Chain chain = ProteinParser.source(pdbId).parse().select().chainName(chainId).asChain();
    PLIPParser.parse(chain, PLIPRestServiceQuery.getDocument(pdbId, chainId));
}
Also used : Chain(de.bioforscher.jstructure.model.structure.Chain) Test(org.junit.Test)

Example 4 with Chain

use of de.bioforscher.jstructure.model.structure.Chain 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 5 with Chain

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

the class LinkInteractionsToTopologyAndSequenceMotifs method handleLine.

private static void handleLine(String line) {
    System.out.println(line);
    // load protein, calculate features
    Protein protein = ProteinParser.source(line.split("_")[0]).parse();
    plipAnnotator.process(protein);
    sequenceMotifAnnotator.process(protein);
    topologyAnnotator.process(protein);
    // select wanted chain
    Chain chain = protein.select().chainName(line.split("_")[1]).asChain();
    System.out.println(chain.getAminoAcidSequence());
}
Also used : Chain(de.bioforscher.jstructure.model.structure.Chain) Protein(de.bioforscher.jstructure.model.structure.Protein)

Aggregations

Chain (de.bioforscher.jstructure.model.structure.Chain)6 Test (org.junit.Test)3 Group (de.bioforscher.jstructure.model.structure.Group)2 Protein (de.bioforscher.jstructure.model.structure.Protein)2 List (java.util.List)2 Document (org.jsoup.nodes.Document)2 ComputationException (de.bioforscher.jstructure.feature.ComputationException)1 ResidueNumber (de.bioforscher.jstructure.model.structure.ResidueNumber)1 GroupContainer (de.bioforscher.jstructure.model.structure.container.GroupContainer)1 ProteinIdentifier (de.bioforscher.jstructure.model.structure.identifier.ProteinIdentifier)1 ProteinParser (de.bioforscher.jstructure.parser.ProteinParser)1 File (java.io.File)1 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 Constructor (java.lang.reflect.Constructor)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1