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());
}
});
}
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());
}
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));
}
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;
}
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());
}
Aggregations