use of de.bioforscher.jstructure.feature.ComputationException in project jstructure by JonStargaryen.
the class OrientationsOfProteinsInMembranesAnnotator method processInternally.
@Override
protected void processInternally(Protein protein) {
try {
Document document = getDocument(SEARCH_URL + protein.getPdbId().getPdbId());
if (document.text().contains("No matches")) {
throw new ComputationException("did not find OPM entry for " + protein.getIdentifier() + " - possibly it is no membrane protein");
}
// create global membrane object - 3rd link points to download
String downloadLink = document.getElementById("caption").getElementsByTag("a").get(2).attr("href");
try (InputStreamReader inputStreamReader = new InputStreamReader(new URL(BASE_URL + downloadLink).openStream())) {
try (BufferedReader bufferedReader = new BufferedReader(inputStreamReader)) {
byte[] bytes = bufferedReader.lines().collect(Collectors.joining(System.lineSeparator())).getBytes();
// parse protein
Protein opmProtein = ProteinParser.source(new ByteArrayInputStream(bytes)).forceProteinName(ProteinIdentifier.createFromPdbId(downloadLink.split("=")[0].split("/")[1].substring(0, 4))).parse();
Membrane membrane = new Membrane(this);
// superimpose opm protein onto instance of the original protein
//TODO this alignment is by no means perfect, but works for a first glance
SVDSuperimposer.ALPHA_CARBON_SVD_INSTANCE.align(protein.select().aminoAcids().asGroupContainer(), opmProtein.select().aminoAcids().asGroupContainer()).transform(opmProtein);
// extract dummy atoms and move them to membrane object
List<double[]> membraneAtoms = opmProtein.atoms().map(Atom::getParentGroup).filter(group -> group.getThreeLetterCode().equals("DUM")).flatMap(Group::atoms).map(Atom::getCoordinates).collect(Collectors.toList());
membrane.setMembraneAtoms(membraneAtoms);
// extract general information - that is the first table
Element generalDataTable = document.getElementsByClass("data").get(0);
Element thicknessTr = generalDataTable.getElementsByTag("tr").get(1);
membrane.setHydrophobicThickness(thicknessTr.getElementsByTag("td").get(1).text());
Element tiltTr = generalDataTable.getElementsByTag("tr").get(2);
membrane.setTiltAngle(tiltTr.getElementsByTag("td").get(1).text());
Element transferTr = generalDataTable.getElementsByTag("tr").get(3);
membrane.setDeltaGTransfer(transferTr.getElementsByTag("td").get(1).text());
Element topologyTr = generalDataTable.getElementsByTag("tr").get(5);
membrane.setTopology(topologyTr.getElementsByTag("td").get(1).text());
// extract trans-membrane helices - second table
Element transMembraneSubunitsTable = document.getElementsByClass("data").get(1);
List<TransMembraneHelix> helices = transMembraneSubunitsTable.getElementsByTag("tr").stream().skip(1).map(element -> element.getElementsByTag("td").get(0)).map(Element::text).map(TransMembraneHelix::new).collect(Collectors.toList());
membrane.setTransMembraneHelices(helices);
protein.getFeatureContainer().addFeature(membrane);
// //TODO remove, used to evaluate alignment manually
// Files.write(Paths.get(System.getProperty("user.home") + "/ori.pdb"), protein.getPdbRepresentation().getBytes());
// Files.write(Paths.get(System.getProperty("user.home") + "/opm.pdb"), opmProtein.getPdbRepresentation().getBytes());
// //TODO remove, used to evaluate segment positions manually
// Files.write(Paths.get(System.getProperty("user.home") + "/tm.pdb"), protein.select()
// .residueNumber(helices.stream()
// .map(TransMembraneHelix::getSegments)
// .flatMap(Collection::stream)
// .collect(Collectors.toList())
// .toArray(new IntegerRange[0]))
// .asGroupContainer()
// .getPdbRepresentation()
// .getBytes());
}
}
} catch (IOException e) {
throw new ComputationException("failed to fetch OPM file", e);
}
}
use of de.bioforscher.jstructure.feature.ComputationException 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;
}
Aggregations