From 4e88579959d3b6728ddd17179427b7d7538534ff Mon Sep 17 00:00:00 2001 From: maximiliankoch Date: Wed, 20 Jul 2016 16:22:54 +0100 Subject: [PATCH] created basic structrue and moved the feature-shortabel-generator into tools. --- .gitignore | 52 ++++ README.md | 1 - feature-shortabel-generator/pom.xml | 249 +++++++++++++++++ .../generator/ShortlabelGenerator.java | 252 ++++++++++++++++++ .../generator/ShortlabelGeneratorManager.java | 53 ++++ .../ShortlabelGeneratorObserver.java | 24 ++ .../events/FeatureAnnotationFoundEvent.java | 52 ++++ .../events/ObjRetrieveErrorEvent.java | 54 ++++ .../generator/events/RangeErrorEvent.java | 58 ++++ .../events/ResultingSequenceChangedEvent.java | 57 ++++ .../generator/events/SequenceErrorEvent.java | 86 ++++++ .../events/SuccessfulGeneratedEvent.java | 36 +++ .../generator/events/TypeErrorEvent.java | 50 ++++ .../events/UndefinedMutationEvent.java | 22 ++ .../FeatureShortlabelGenerationException.java | 32 +++ .../generator/model/AminoAcids.java | 59 ++++ .../utils/OntologyServiceHelper.java | 44 +++ .../utils/ShortlabelGeneratorHelper.java | 103 +++++++ .../resources/META-INF/database.properties | 4 + .../META-INF/shortlabel-generator-config.xml | 107 ++++++++ .../test/java/ShortlabelGeneratorTest.java | 29 ++ .../src/test/java/impl/FeatureObserver.java | 59 ++++ pom.xml | 0 23 files changed, 1482 insertions(+), 1 deletion(-) create mode 100644 .gitignore delete mode 100644 README.md create mode 100644 feature-shortabel-generator/pom.xml create mode 100644 feature-shortabel-generator/src/main/java/uk/ac/ebi/intact/tools/feature/shortlabel/generator/ShortlabelGenerator.java create mode 100644 feature-shortabel-generator/src/main/java/uk/ac/ebi/intact/tools/feature/shortlabel/generator/ShortlabelGeneratorManager.java create mode 100644 feature-shortabel-generator/src/main/java/uk/ac/ebi/intact/tools/feature/shortlabel/generator/ShortlabelGeneratorObserver.java create mode 100644 feature-shortabel-generator/src/main/java/uk/ac/ebi/intact/tools/feature/shortlabel/generator/events/FeatureAnnotationFoundEvent.java create mode 100644 feature-shortabel-generator/src/main/java/uk/ac/ebi/intact/tools/feature/shortlabel/generator/events/ObjRetrieveErrorEvent.java create mode 100644 feature-shortabel-generator/src/main/java/uk/ac/ebi/intact/tools/feature/shortlabel/generator/events/RangeErrorEvent.java create mode 100644 feature-shortabel-generator/src/main/java/uk/ac/ebi/intact/tools/feature/shortlabel/generator/events/ResultingSequenceChangedEvent.java create mode 100644 feature-shortabel-generator/src/main/java/uk/ac/ebi/intact/tools/feature/shortlabel/generator/events/SequenceErrorEvent.java create mode 100644 feature-shortabel-generator/src/main/java/uk/ac/ebi/intact/tools/feature/shortlabel/generator/events/SuccessfulGeneratedEvent.java create mode 100644 feature-shortabel-generator/src/main/java/uk/ac/ebi/intact/tools/feature/shortlabel/generator/events/TypeErrorEvent.java create mode 100644 feature-shortabel-generator/src/main/java/uk/ac/ebi/intact/tools/feature/shortlabel/generator/events/UndefinedMutationEvent.java create mode 100644 feature-shortabel-generator/src/main/java/uk/ac/ebi/intact/tools/feature/shortlabel/generator/exception/FeatureShortlabelGenerationException.java create mode 100644 feature-shortabel-generator/src/main/java/uk/ac/ebi/intact/tools/feature/shortlabel/generator/model/AminoAcids.java create mode 100644 feature-shortabel-generator/src/main/java/uk/ac/ebi/intact/tools/feature/shortlabel/generator/utils/OntologyServiceHelper.java create mode 100644 feature-shortabel-generator/src/main/java/uk/ac/ebi/intact/tools/feature/shortlabel/generator/utils/ShortlabelGeneratorHelper.java create mode 100644 feature-shortabel-generator/src/main/resources/META-INF/database.properties create mode 100644 feature-shortabel-generator/src/main/resources/META-INF/shortlabel-generator-config.xml create mode 100644 feature-shortabel-generator/src/test/java/ShortlabelGeneratorTest.java create mode 100644 feature-shortabel-generator/src/test/java/impl/FeatureObserver.java create mode 100644 pom.xml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..74da54c --- /dev/null +++ b/.gitignore @@ -0,0 +1,52 @@ +*.class + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.ear + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + +# maven +target/ +pom.xml.tag +pom.xml.releaseBackup +pom.xml.versionsBackup +pom.xml.next +release.properties + +# intelliJ idea git ignore +*.iml +.idea + +# eclipse specific git ignore +*.pydevproject +.project +.metadata +bin/** +tmp/** +tmp/**/* +*.tmp +*.bak +*.swp +*~.nib +local.properties +.classpath +.settings/ +.loadpath + +# External tool builders +.externalToolBuilders/ + +# Locally stored "Eclipse launch configurations" +*.launch + +# Logs +*.log + +# Hidden files +.DS_Store \ No newline at end of file diff --git a/README.md b/README.md deleted file mode 100644 index 39d93cf..0000000 --- a/README.md +++ /dev/null @@ -1 +0,0 @@ -# intact-tools diff --git a/feature-shortabel-generator/pom.xml b/feature-shortabel-generator/pom.xml new file mode 100644 index 0000000..47be972 --- /dev/null +++ b/feature-shortabel-generator/pom.xml @@ -0,0 +1,249 @@ + + + + + uk.ac.ebi.intact.maven + intact-hibernate-master + 44 + + + 4.0.0 + + uk.ac.ebi.intact.tools + feature-shortabel-genrator + 1.0-SNAPSHOT + + + 3.2.9.RELEASE + 2.1.20-SNAPSHOT + 3.0.2-SNAPSHOT + 1.2.17-SNAPSHOT + + + + + uk.ac.ebi.intact.bridges + intact-ols-light + ${bridges.version} + + + org.slf4j + slf4j-log4j13 + + + + + + psidev.psi.mi.jami + jami-core + ${psi.jami.version} + + + + + + uk.ac.ebi.intact.jami + intact-jami + ${intact.jami.version} + + + + + org.springframework + spring-core + ${spring.version} + + + + org.springframework + spring-web + ${spring.version} + + + + javax.servlet + servlet-api + 2.5 + provided + + + + javax.servlet.jsp + jsp-api + 2.2 + provided + + + + org.springframework + spring-webmvc + ${spring.version} + + + + org.springframework + spring-test + ${spring.version} + test + + + + org.springframework + spring-aspects + ${spring.version} + + + + org.springframework + spring-orm + ${spring.version} + + + + org.springframework + spring-oxm + ${spring.version} + + + + org.springframework + spring-aop + ${spring.version} + + + + org.springframework + spring-tx + ${spring.version} + + + + org.springframework + spring-context + ${spring.version} + + + + org.springframework + spring-beans + ${spring.version} + + + + org.springframework + spring-jdbc + ${spring.version} + + + + org.hibernate.javax.persistence + hibernate-jpa-2.1-api + 1.0.0.Final + + + + + junit + junit + 4.11 + test + + + + com.jayway.jsonpath + json-path-assert + 0.8.1 + test + + + + net.sourceforge.dynamicreports + dynamicreports-core + 4.0.1 + + + + javax.servlet + servlet-api + 2.5 + provided + + + javax.servlet.jsp + jsp-api + 2.2 + provided + + + javax.servlet + jstl + 1.2 + provided + + + javax.el + el-api + 2.2 + provided + + + + org.glassfish.web + el-impl + 2.2 + + + + + + + maven-compiler-plugin + + 1.7 + 1.7 + + + + maven-surefire-plugin + + + **/*Tests.java + + + + + + + + nexus-ebi-repo-old + http://www.ebi.ac.uk/intact/maven/nexus/content/repositories/ebi-repo/ + + + nexus-ebi-release-repo + http://www.ebi.ac.uk/Tools/maven/repos/content/groups/ebi-repo/ + + + nexus-ebi-snapshot-repo + http://www.ebi.ac.uk/Tools/maven/repos/content/groups/ebi-snapshots/ + + + + + + + + pst-release + EBI Nexus Repository + http://www.ebi.ac.uk/Tools/maven/repos/content/repositories/pst-release + + + + false + pst-snapshots + EBI Nexus Snapshots Repository + http://www.ebi.ac.uk/Tools/maven/repos/content/repositories/pst-snapshots + + + \ No newline at end of file diff --git a/feature-shortabel-generator/src/main/java/uk/ac/ebi/intact/tools/feature/shortlabel/generator/ShortlabelGenerator.java b/feature-shortabel-generator/src/main/java/uk/ac/ebi/intact/tools/feature/shortlabel/generator/ShortlabelGenerator.java new file mode 100644 index 0000000..6c1ecb4 --- /dev/null +++ b/feature-shortabel-generator/src/main/java/uk/ac/ebi/intact/tools/feature/shortlabel/generator/ShortlabelGenerator.java @@ -0,0 +1,252 @@ +package uk.ac.ebi.intact.tools.feature.shortlabel.generator; + +import org.springframework.beans.factory.annotation.Required; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; +import psidev.psi.mi.jami.model.Annotation; +import psidev.psi.mi.jami.model.Range; +import uk.ac.ebi.intact.jami.dao.IntactDao; +import uk.ac.ebi.intact.jami.model.extension.ExperimentalRange; +import uk.ac.ebi.intact.jami.model.extension.IntactCvTerm; +import uk.ac.ebi.intact.jami.model.extension.IntactFeatureEvidence; +import uk.ac.ebi.intact.jami.model.extension.IntactInteractor; +import uk.ac.ebi.intact.tools.feature.shortlabel.generator.events.*; +import uk.ac.ebi.intact.tools.feature.shortlabel.generator.exception.FeatureShortlabelGenerationException; +import uk.ac.ebi.intact.tools.feature.shortlabel.generator.utils.OntologyServiceHelper; +import uk.ac.ebi.intact.tools.feature.shortlabel.generator.utils.ShortlabelGeneratorHelper; + +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; + +/** + * Created by Maximilian Koch (mkoch@ebi.ac.uk). + */ +public class ShortlabelGenerator { + private final static String MUTATION_MI_ID = "MI:0118"; + private final static String CV_TERM_REMARK_INTERNAL_AC = "EBI-20"; + private final static int OLS_SEARCHING_DEPTH = 10; + private final static int TRIES = 3; + private boolean isPollyQ = false; + private boolean isUndifinedMutation; + + private static Set allowedFeatureTypes = new HashSet(); + + private ShortlabelGeneratorManager manager = new ShortlabelGeneratorManager(); + private ShortlabelGeneratorHelper helper = new ShortlabelGeneratorHelper(); + + private IntactDao intactDao; + + public ShortlabelGenerator() { + initAllowedFeatureTypes(); + } + + private void initAllowedFeatureTypes() { + allowedFeatureTypes.addAll(OntologyServiceHelper.getOntologyServiceHelper().getAssociatedMITerms(MUTATION_MI_ID, OLS_SEARCHING_DEPTH)); + } + + public void subscribeToEvents(ShortlabelGeneratorObserver shortlabelGeneratorObserver) { + manager.setShortlabelGeneratorObserver(shortlabelGeneratorObserver); + } + + @Transactional(propagation = Propagation.REQUIRED, value = "jamiTransactionManager", readOnly = true) + public IntactFeatureEvidence getFeatureEvidence(String ac, int tries) { + + IntactFeatureEvidence featureEvidence = intactDao.getFeatureEvidenceDao().getByAc(ac); + if (featureEvidence == null && tries > 0) { + tries--; + featureEvidence = getFeatureEvidence(ac, tries); + } else if (featureEvidence == null && tries == 0) { + ObjRetrieveErrorEvent event = new ObjRetrieveErrorEvent(ac, null, + ObjRetrieveErrorEvent.ErrorType.UNABLE_TO_RETRIEVE_FEATURE); + manager.fireOnRetrieveObjErrorEvent(event); + throw new FeatureShortlabelGenerationException(); + } + return featureEvidence; + } + + @Transactional(propagation = Propagation.REQUIRED, value = "jamiTransactionManager", readOnly = true) + public void generateNewShortLabel(String ac) { + IntactFeatureEvidence featureEvidence = getFeatureEvidence(ac, TRIES); + generateNewShortLabel(featureEvidence); + } + + @Transactional(propagation = Propagation.REQUIRED, value = "jamiTransactionManager", readOnly = true) + public void generateNewShortLabel(IntactFeatureEvidence featureEvidence) { + String orgShortlabel = featureEvidence.getShortName(); + String featureAc = featureEvidence.getAc(); + String interactorAc; + String interactorSeq; + String interactorType; + Iterator rangeIterator; + + IntactInteractor interactor = helper.getInteractorByFeatureEvidence(featureEvidence); + + if (interactor == null) { + ObjRetrieveErrorEvent event = new ObjRetrieveErrorEvent(featureAc, null, ObjRetrieveErrorEvent.ErrorType.UNABLE_RETRIEVE_INTERACTOR); + manager.fireOnRetrieveObjErrorEvent(event); + throw new FeatureShortlabelGenerationException(); + } + + interactorAc = interactor.getAc(); + interactorType = interactor.getInteractorType().getShortName(); + + if(helper.isUndefinedMutation(featureEvidence)){ + UndefinedMutationEvent event = new UndefinedMutationEvent(featureAc, interactorAc); + manager.fireOnUndefinedMutationEvent(event); + throw new FeatureShortlabelGenerationException(); + } + + if (!interactorType.equals("protein") && !interactorType.equals("peptide")) { + TypeErrorEvent event = new TypeErrorEvent(featureAc, interactorAc, TypeErrorEvent.ObjTypeErrorType.WRONG_INTERACTOR_TYPE); + manager.fireOnTypeErrorEvent(event); + throw new FeatureShortlabelGenerationException(); + } + + interactorSeq = helper.getInteractorSeqByInteractor(interactor); + + if (interactorSeq == null) { + ObjRetrieveErrorEvent event = new ObjRetrieveErrorEvent(featureAc, interactorAc, ObjRetrieveErrorEvent.ErrorType.UNABLE_RETRIEVE_INTERACTOR_SEQUENCE); + manager.fireOnRetrieveObjErrorEvent(event); + throw new FeatureShortlabelGenerationException(); + } + + if (!allowedFeatureTypes.contains(featureEvidence.getType().getMIIdentifier())) { + TypeErrorEvent event = new TypeErrorEvent(featureAc, interactorAc, TypeErrorEvent.ObjTypeErrorType.WRONG_FEATURE_TYPE); + manager.fireOnTypeErrorEvent(event); + throw new FeatureShortlabelGenerationException(); + } + + for (Annotation annotation : featureEvidence.getAnnotations()) { + if (annotation.getTopic() == getIntActCVTermRemarkInternal(3)) { + if (annotation.getValue().startsWith(FeatureAnnotationFoundEvent.AnnotationType.FEATURE_CORRECTED.getMessage())) { + FeatureAnnotationFoundEvent event = new FeatureAnnotationFoundEvent(featureAc, interactorAc, FeatureAnnotationFoundEvent.AnnotationType.FEATURE_CORRECTED); + manager.fireOnFeatureAnnotationFoundEvent(event); + } else if (annotation.getValue().startsWith(FeatureAnnotationFoundEvent.AnnotationType.FEATURE_WRONG.getMessage())) { + FeatureAnnotationFoundEvent event = new FeatureAnnotationFoundEvent(featureAc, interactorAc, FeatureAnnotationFoundEvent.AnnotationType.FEATURE_WRONG); + manager.fireOnFeatureAnnotationFoundEvent(event); + throw new FeatureShortlabelGenerationException(); + } else if (annotation.getTopic().getShortName().equals(FeatureAnnotationFoundEvent.AnnotationType.SHORTLABEL_NO_UPDATE.getMessage())) { + FeatureAnnotationFoundEvent event = new FeatureAnnotationFoundEvent(featureAc, interactorAc, FeatureAnnotationFoundEvent.AnnotationType.SHORTLABEL_NO_UPDATE); + manager.fireOnFeatureAnnotationFoundEvent(event); + throw new FeatureShortlabelGenerationException(); + } + } + } + + featureEvidence.setShortName(""); + rangeIterator = featureEvidence.getRanges().iterator(); + while (rangeIterator.hasNext()) { + ExperimentalRange range = (ExperimentalRange) rangeIterator.next(); + String newShortlabel = ""; + long rangeStart; + long rangeEnd; + String orgSeq; + String resSeq; + String calculatedOrgSeq; + if (range == null) { + RangeErrorEvent event = new RangeErrorEvent(featureAc, interactorAc, null, RangeErrorEvent.ErrorType.RANGE_NULL); + manager.fireOnRangeErrorEvent(event); + throw new FeatureShortlabelGenerationException(); + } + + String rangeAc = range.getAc(); + + if (range.getStart().getStart() == 0) { + RangeErrorEvent event = new RangeErrorEvent(featureAc, interactorAc, rangeAc, RangeErrorEvent.ErrorType.START_POS_ZERO); + manager.fireOnRangeErrorEvent(event); + throw new FeatureShortlabelGenerationException(); + } + if (range.getStart().isPositionUndetermined()) { + RangeErrorEvent event = new RangeErrorEvent(featureAc, interactorAc, rangeAc, RangeErrorEvent.ErrorType.START_POS_UNDETERMINED); + manager.fireOnRangeErrorEvent(event); + throw new FeatureShortlabelGenerationException(); + } + if (range.getResultingSequence().getOriginalSequence() == null) { + RangeErrorEvent event = new RangeErrorEvent(featureAc, interactorAc, rangeAc, RangeErrorEvent.ErrorType.ORG_SEQ_NULL); + manager.fireOnRangeErrorEvent(event); + throw new FeatureShortlabelGenerationException(); + } + if (range.getResultingSequence().getNewSequence() == null) { + RangeErrorEvent event = new RangeErrorEvent(featureAc, interactorAc, rangeAc, RangeErrorEvent.ErrorType.RES_SEQ_NULL); + manager.fireOnRangeErrorEvent(event); + throw new FeatureShortlabelGenerationException(); + } + + rangeStart = range.getStart().getStart(); + rangeEnd = range.getEnd().getEnd(); + orgSeq = range.getResultingSequence().getOriginalSequence(); + resSeq = range.getResultingSequence().getNewSequence(); + calculatedOrgSeq = helper.generateOrgSeq(interactorSeq, rangeStart, rangeEnd); + + if (calculatedOrgSeq == null) { + SequenceErrorEvent event = new SequenceErrorEvent(featureAc, interactorAc, rangeAc, SequenceErrorEvent.ErrorType.UNABLE_CALCULATE_ORG_SEQ); + manager.fireOnSeqErrorEvent(event); + throw new FeatureShortlabelGenerationException(); + } + if (helper.orgSeqWrong(orgSeq, calculatedOrgSeq)) { + String message = "Original sequence does not match interactor sequence. Is " + orgSeq + " should be " + calculatedOrgSeq + " Range: (" + rangeStart + "-" + rangeEnd + ")"; + SequenceErrorEvent event = new SequenceErrorEvent(featureAc, interactorAc, rangeAc, SequenceErrorEvent.ErrorType.ORG_SEQ_WRONG, message); + manager.fireOnSeqErrorEvent(event); + throw new FeatureShortlabelGenerationException(); + } + if (helper.containsLowerCaseLetters(resSeq)) { + SequenceErrorEvent event = new SequenceErrorEvent(featureAc, interactorAc, rangeAc, SequenceErrorEvent.ErrorType.RES_SEQ_CONTAINS_LOWER_CASE); + manager.fireOnSeqErrorEvent(event); + throw new FeatureShortlabelGenerationException(); + } + + newShortlabel += helper.seq2ThreeLetterCodeOnDefault(orgSeq); + + if (helper.isSingleAminoAcidChange(rangeStart, rangeEnd)) { + newShortlabel += helper.generateNonSequentialRange(rangeStart); + } else { + newShortlabel += helper.generateSequentialRange(rangeStart, rangeEnd); + } + + if (helper.resultingSeqDescreased(orgSeq, resSeq)) { + if (helper.isDeletion(orgSeq, resSeq)) { + ResultingSequenceChangedEvent event = new ResultingSequenceChangedEvent(featureAc, interactorAc, rangeAc, ResultingSequenceChangedEvent.ChangeType.DELETION); + manager.fireOnResSeqChangedEvent(event); + newShortlabel += helper.newSequence2ThreeLetterCodeOnDelete(range.getResultingSequence().getOriginalSequence()); + } else { + ResultingSequenceChangedEvent event = new ResultingSequenceChangedEvent(featureAc, interactorAc, rangeAc, ResultingSequenceChangedEvent.ChangeType.DECREASE); + manager.fireOnResSeqChangedEvent(event); + newShortlabel += helper.seq2ThreeLetterCodeOnDefault(range.getResultingSequence().getNewSequence()); + } + } else if (helper.resultingSeqIncreased(orgSeq, resSeq)) { + ResultingSequenceChangedEvent event = new ResultingSequenceChangedEvent(featureAc, interactorAc, rangeAc, ResultingSequenceChangedEvent.ChangeType.INCREASE); + manager.fireOnResSeqChangedEvent(event); + newShortlabel += helper.seq2ThreeLetterCodeOnDefault(range.getResultingSequence().getNewSequence()); + } else { + ResultingSequenceChangedEvent event = new ResultingSequenceChangedEvent(featureAc, + interactorAc, rangeAc, ResultingSequenceChangedEvent.ChangeType.STABLE); + manager.fireOnResSeqChangedEvent(event); + newShortlabel += helper.seq2ThreeLetterCodeOnDefault(range.getResultingSequence().getNewSequence()); + } + + featureEvidence.setShortName(featureEvidence.getShortName() + newShortlabel + (rangeIterator.hasNext() ? "," : "")); + } + SuccessfulGeneratedEvent event = new SuccessfulGeneratedEvent(featureAc, interactorAc, featureEvidence, orgShortlabel); + manager.fireOnSuccessfulGeneratedEvent(event); + } + + @Transactional(propagation = Propagation.REQUIRED, value = "jamiTransactionManager", readOnly = true) + private IntactCvTerm getIntActCVTermRemarkInternal(int tries) { + IntactCvTerm intactCvTerm = intactDao.getCvTermDao().getByAc(CV_TERM_REMARK_INTERNAL_AC); + if (intactCvTerm == null && tries > 0) { + tries--; + intactCvTerm = getIntActCVTermRemarkInternal(tries); + } else if (intactCvTerm == null && tries == 0) { + ObjRetrieveErrorEvent event = new ObjRetrieveErrorEvent(null, null, ObjRetrieveErrorEvent.ErrorType.UNABLE_TO_RETRIEVE_CV_REMARK_INTERNAL); + manager.fireOnRetrieveObjErrorEvent(event); + throw new FeatureShortlabelGenerationException(); + } + return intactCvTerm; + } + + @Required + public void setIntactDao(IntactDao intactDao) { + this.intactDao = intactDao; + } +} diff --git a/feature-shortabel-generator/src/main/java/uk/ac/ebi/intact/tools/feature/shortlabel/generator/ShortlabelGeneratorManager.java b/feature-shortabel-generator/src/main/java/uk/ac/ebi/intact/tools/feature/shortlabel/generator/ShortlabelGeneratorManager.java new file mode 100644 index 0000000..d32a109 --- /dev/null +++ b/feature-shortabel-generator/src/main/java/uk/ac/ebi/intact/tools/feature/shortlabel/generator/ShortlabelGeneratorManager.java @@ -0,0 +1,53 @@ +package uk.ac.ebi.intact.tools.feature.shortlabel.generator; + +import uk.ac.ebi.intact.tools.feature.shortlabel.generator.events.*; + +/** + * Created by Maximilian Koch (mkoch@ebi.ac.uk). + */ +public class ShortlabelGeneratorManager { + + protected ShortlabelGeneratorObserver shortlabelGeneratorObserver; + + public void fireOnRangeErrorEvent(RangeErrorEvent event) { + shortlabelGeneratorObserver.onRangeErrorEvent(event); + } + + public void fireOnSuccessfulGeneratedEvent(SuccessfulGeneratedEvent event) { + shortlabelGeneratorObserver.onSuccessfulGeneratedEvent(event); + + } + + public void fireOnRetrieveObjErrorEvent(ObjRetrieveErrorEvent event) { + shortlabelGeneratorObserver.onRetrieveObjErrorEvent(event); + + } + + public void fireOnFeatureAnnotationFoundEvent(FeatureAnnotationFoundEvent event) { + shortlabelGeneratorObserver.onFeatureAnnotationFoundEvent(event); + + } + + public void fireOnSeqErrorEvent(SequenceErrorEvent event) { + shortlabelGeneratorObserver.onSeqErrorEvent(event); + + } + + public void fireOnResSeqChangedEvent(ResultingSequenceChangedEvent event){ + shortlabelGeneratorObserver.onResSeqChangedEvent(event); + + } + + public void fireOnTypeErrorEvent(TypeErrorEvent event){ + shortlabelGeneratorObserver.onTypeErrorEvent(event); + + } + + public void setShortlabelGeneratorObserver(ShortlabelGeneratorObserver shortlabelGeneratorObserver) { + this.shortlabelGeneratorObserver = shortlabelGeneratorObserver; + } + + public void fireOnUndefinedMutationEvent(UndefinedMutationEvent event){ + shortlabelGeneratorObserver.onUndefinedMutation(event); + } +} diff --git a/feature-shortabel-generator/src/main/java/uk/ac/ebi/intact/tools/feature/shortlabel/generator/ShortlabelGeneratorObserver.java b/feature-shortabel-generator/src/main/java/uk/ac/ebi/intact/tools/feature/shortlabel/generator/ShortlabelGeneratorObserver.java new file mode 100644 index 0000000..9139c40 --- /dev/null +++ b/feature-shortabel-generator/src/main/java/uk/ac/ebi/intact/tools/feature/shortlabel/generator/ShortlabelGeneratorObserver.java @@ -0,0 +1,24 @@ +package uk.ac.ebi.intact.tools.feature.shortlabel.generator; + +import uk.ac.ebi.intact.tools.feature.shortlabel.generator.events.*; + +/** + * Created by Maximilian Koch (mkoch@ebi.ac.uk). + */ +public interface ShortlabelGeneratorObserver { + void onRangeErrorEvent(RangeErrorEvent event); + + void onSuccessfulGeneratedEvent(SuccessfulGeneratedEvent event); + + void onRetrieveObjErrorEvent(ObjRetrieveErrorEvent event); + + void onFeatureAnnotationFoundEvent(FeatureAnnotationFoundEvent event); + + void onSeqErrorEvent(SequenceErrorEvent event); + + void onResSeqChangedEvent(ResultingSequenceChangedEvent event); + + void onTypeErrorEvent(TypeErrorEvent event); + + void onUndefinedMutation(UndefinedMutationEvent undefinedMutationEvent); +} diff --git a/feature-shortabel-generator/src/main/java/uk/ac/ebi/intact/tools/feature/shortlabel/generator/events/FeatureAnnotationFoundEvent.java b/feature-shortabel-generator/src/main/java/uk/ac/ebi/intact/tools/feature/shortlabel/generator/events/FeatureAnnotationFoundEvent.java new file mode 100644 index 0000000..edb0090 --- /dev/null +++ b/feature-shortabel-generator/src/main/java/uk/ac/ebi/intact/tools/feature/shortlabel/generator/events/FeatureAnnotationFoundEvent.java @@ -0,0 +1,52 @@ +package uk.ac.ebi.intact.tools.feature.shortlabel.generator.events; + + +/** + * Created by Maximilian Koch (mkoch@ebi.ac.uk). + */ +public class FeatureAnnotationFoundEvent { + private String featureAc; + private String interactorAc; + private AnnotationType type; + private String message; + + public FeatureAnnotationFoundEvent(String featureAc, String interactorAc, AnnotationType type) { + this.featureAc = (featureAc == null) ? "undefined" : featureAc; + this.interactorAc = (interactorAc == null) ? "undefined" : interactorAc; + this.type = type; + this.message = type.getMessage(); + } + + public String getFeatureAc() { + return featureAc; + } + + public String getInteractorAc() { + return interactorAc; + } + + public AnnotationType getType() { + return type; + } + + public String getMessage() { + return message; + } + + public enum AnnotationType { + FEATURE_WRONG("Sequence change details about this feature cannot be ascertained or do not fit with the current version of the referenced protein, so they have been deleted as a result of our quality control procedures. The original label was "), + FEATURE_CORRECTED("This feature has been corrected as a result of our quality control procedures. The original label was "), + SHORTLABEL_NO_UPDATE("shortlabel-no-update"); + + + private String message; + + AnnotationType(String message) { + this.message = message; + } + + public String getMessage() { + return message; + } + } +} diff --git a/feature-shortabel-generator/src/main/java/uk/ac/ebi/intact/tools/feature/shortlabel/generator/events/ObjRetrieveErrorEvent.java b/feature-shortabel-generator/src/main/java/uk/ac/ebi/intact/tools/feature/shortlabel/generator/events/ObjRetrieveErrorEvent.java new file mode 100644 index 0000000..44a98e6 --- /dev/null +++ b/feature-shortabel-generator/src/main/java/uk/ac/ebi/intact/tools/feature/shortlabel/generator/events/ObjRetrieveErrorEvent.java @@ -0,0 +1,54 @@ +package uk.ac.ebi.intact.tools.feature.shortlabel.generator.events; + +/** + * Created by Maximilian Koch (mkoch@ebi.ac.uk). + */ +public class ObjRetrieveErrorEvent { + private String featureAc; + private String interactorAc; + private ErrorType errorType; + private String message; + + public ObjRetrieveErrorEvent(String featureAc, String interactorAc, ErrorType error) { + this.featureAc = (featureAc == null) ? "undefined" : featureAc; + this.interactorAc = (interactorAc == null) ? "undefined" : interactorAc; + this.errorType = error; + this.message = error.getMessage(); + } + + public String getFeatureAc() { + return featureAc; + } + + public String getInteractorAc() { + return interactorAc; + } + + public ErrorType getErrorType() { + return errorType; + } + + public String getMessage() { + return message; + } + + public enum ErrorType { + UNABLE_RETRIEVE_INTERACTOR("Can not receive Interactor from IntactFeatureEvidence object"), + UNABLE_TO_RETRIEVE_FEATURE("Can not receive IntactFeatureEvidence"), + UNABLE_TO_RETRIEVE_CV_REMARK_INTERNAL("Can not receive remark_internal IntactCvTerm object"), + UNABLE_RETRIEVE_INTERACTOR_SEQUENCE("Can not receive Interactor Sequence from Interactor object"), + WRONG_INTERACTOR_TYPE("Interactor is not of type mutation"), + WRONG_FEATURE_TYPE("Feature is not of type mutation"); + + + private String message; + + ErrorType(String message) { + this.message = message; + } + + public String getMessage() { + return message; + } + } +} diff --git a/feature-shortabel-generator/src/main/java/uk/ac/ebi/intact/tools/feature/shortlabel/generator/events/RangeErrorEvent.java b/feature-shortabel-generator/src/main/java/uk/ac/ebi/intact/tools/feature/shortlabel/generator/events/RangeErrorEvent.java new file mode 100644 index 0000000..7c63d05 --- /dev/null +++ b/feature-shortabel-generator/src/main/java/uk/ac/ebi/intact/tools/feature/shortlabel/generator/events/RangeErrorEvent.java @@ -0,0 +1,58 @@ +package uk.ac.ebi.intact.tools.feature.shortlabel.generator.events; + +/** + * Created by Maximilian Koch (mkoch@ebi.ac.uk). + */ +public class RangeErrorEvent { + private String featureAc; + private String interactorAc; + private String rangeAc; + private ErrorType errorType; + private String message; + + public RangeErrorEvent(String featureAc, String interactorAc, String rangeAc, ErrorType error) { + this.featureAc = (featureAc == null) ? "undefined" : featureAc; + this.interactorAc = (interactorAc == null) ? "undefined" : interactorAc; + this.rangeAc = (rangeAc == null) ? "undefined" : rangeAc; + this.errorType = error; + this.message = error.getMessage(); + } + + public String getFeatureAc() { + return featureAc; + } + + public String getInteractorAc() { + return interactorAc; + } + + public String getRangeAc() { + return rangeAc; + } + + public ErrorType getErrorType() { + return errorType; + } + + public String getMessage() { + return message; + } + + public enum ErrorType { + RANGE_NULL("No ranges could be found"), + START_POS_ZERO("Starting position is 0"), + START_POS_UNDETERMINED("Positions are undetermined"), + RES_SEQ_NULL("Resulting sequence is null"), + ORG_SEQ_NULL("Original sequence is null"); + + private String message; + + ErrorType(String message) { + this.message = message; + } + + public String getMessage() { + return message; + } + } +} diff --git a/feature-shortabel-generator/src/main/java/uk/ac/ebi/intact/tools/feature/shortlabel/generator/events/ResultingSequenceChangedEvent.java b/feature-shortabel-generator/src/main/java/uk/ac/ebi/intact/tools/feature/shortlabel/generator/events/ResultingSequenceChangedEvent.java new file mode 100644 index 0000000..57d366b --- /dev/null +++ b/feature-shortabel-generator/src/main/java/uk/ac/ebi/intact/tools/feature/shortlabel/generator/events/ResultingSequenceChangedEvent.java @@ -0,0 +1,57 @@ +package uk.ac.ebi.intact.tools.feature.shortlabel.generator.events; + +/** + * Created by Maximilian Koch (mkoch@ebi.ac.uk). + */ +public class ResultingSequenceChangedEvent { + private String featureAc; + private String interactorAc; + private String rangeAc; + private ChangeType changeType; + private String message; + + public ResultingSequenceChangedEvent(String featureAc, String interactorAc, String rangeAc, ChangeType change) { + this.featureAc = (featureAc == null) ? "undefined" : featureAc; + this.interactorAc = (interactorAc == null) ? "undefined" : interactorAc; + this.rangeAc = (rangeAc == null) ? "undefined" : rangeAc; + this.changeType = change; + this.message = change.getMessage(); + } + + public String getFeatureAc() { + return featureAc; + } + + public String getInteractorAc() { + return interactorAc; + } + + public String getRangeAc() { + return rangeAc; + } + + public ChangeType getChangeType() { + return changeType; + } + + public String getMessage() { + return message; + } + + public enum ChangeType { + DELETION("Resulting sequence contains deletions"), + INCREASE("Resulting sequence has increased"), + DECREASE("Resulting sequence has decreased"), + STABLE("Resulting sequence hasn't changed in length"); + + private String message; + + ChangeType(String message) { + this.message = message; + } + + public String getMessage() { + return message; + } + } +} diff --git a/feature-shortabel-generator/src/main/java/uk/ac/ebi/intact/tools/feature/shortlabel/generator/events/SequenceErrorEvent.java b/feature-shortabel-generator/src/main/java/uk/ac/ebi/intact/tools/feature/shortlabel/generator/events/SequenceErrorEvent.java new file mode 100644 index 0000000..3c07cb0 --- /dev/null +++ b/feature-shortabel-generator/src/main/java/uk/ac/ebi/intact/tools/feature/shortlabel/generator/events/SequenceErrorEvent.java @@ -0,0 +1,86 @@ +package uk.ac.ebi.intact.tools.feature.shortlabel.generator.events; + + +/** + * Created by Maximilian Koch (mkoch@ebi.ac.uk). + */ +public class SequenceErrorEvent { + private String featureAc; + private String interactorAc; + private String rangeAc; + private ErrorType errorType; + private String message; + + + public SequenceErrorEvent(String featureAc, String interactorAc, String rangeAc, ErrorType error) { + this.featureAc = (featureAc == null) ? "undefined" : featureAc; + this.interactorAc = (interactorAc == null) ? "undefined" : interactorAc; + this.rangeAc = (rangeAc == null) ? "undefined" : rangeAc; + this.errorType = error; + this.message = error.getMessage(); + } + + public SequenceErrorEvent(String featureAc, String interactorAc, String rangeAc, ErrorType error, String message) { + this.featureAc = (featureAc == null) ? "undefined" : featureAc; + this.interactorAc = (interactorAc == null) ? "undefined" : interactorAc; + this.rangeAc = (rangeAc == null) ? "undefined" : rangeAc; + this.errorType = error; + this.message = message; + } + + public String getFeatureAc() { + return featureAc; + } + + public void setFeatureAc(String featureAc) { + this.featureAc = featureAc; + } + + public String getInteractorAc() { + return interactorAc; + } + + public void setInteractorAc(String interactorAc) { + this.interactorAc = interactorAc; + } + + public String getRangeAc() { + return rangeAc; + } + + public void setRangeAc(String rangeAc) { + this.rangeAc = rangeAc; + } + + public ErrorType getErrorType() { + return errorType; + } + + public void setErrorType(ErrorType errorType) { + this.errorType = errorType; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public enum ErrorType { + UNABLE_CALCULATE_ORG_SEQ("Couldn't calculate original sequence from whole sequence"), + ORG_SEQ_WRONG("Original sequence does not match interactor sequence"), + RES_SEQ_CONTAINS_LOWER_CASE("Resulting sequence contains lower case letters"); + + private String message; + + ErrorType(String message) { + this.message = message; + } + + public String getMessage() { + return message; + } + } +} diff --git a/feature-shortabel-generator/src/main/java/uk/ac/ebi/intact/tools/feature/shortlabel/generator/events/SuccessfulGeneratedEvent.java b/feature-shortabel-generator/src/main/java/uk/ac/ebi/intact/tools/feature/shortlabel/generator/events/SuccessfulGeneratedEvent.java new file mode 100644 index 0000000..1e31148 --- /dev/null +++ b/feature-shortabel-generator/src/main/java/uk/ac/ebi/intact/tools/feature/shortlabel/generator/events/SuccessfulGeneratedEvent.java @@ -0,0 +1,36 @@ +package uk.ac.ebi.intact.tools.feature.shortlabel.generator.events; + +import uk.ac.ebi.intact.jami.model.extension.IntactFeatureEvidence; + +/** + * Created by Maximilian Koch (mkoch@ebi.ac.uk). + */ +public class SuccessfulGeneratedEvent { + private String featureAc; + private String interactorAc; + private IntactFeatureEvidence featureEvidence; + private String originalShortlabel; + + public SuccessfulGeneratedEvent(String featureAc, String interactorAc, IntactFeatureEvidence featureEvidence, String originalShortlabel) { + this.featureAc = (featureAc == null) ? "undefined" : featureAc; + this.interactorAc = (interactorAc == null) ? "undefined" : interactorAc; + this.featureEvidence = featureEvidence; + this.originalShortlabel = originalShortlabel; + } + + public String getFeatureAc() { + return featureAc; + } + + public String getInteractorAc() { + return interactorAc; + } + + public IntactFeatureEvidence getFeatureEvidence() { + return featureEvidence; + } + + public String getOriginalShortlabel() { + return originalShortlabel; + } +} diff --git a/feature-shortabel-generator/src/main/java/uk/ac/ebi/intact/tools/feature/shortlabel/generator/events/TypeErrorEvent.java b/feature-shortabel-generator/src/main/java/uk/ac/ebi/intact/tools/feature/shortlabel/generator/events/TypeErrorEvent.java new file mode 100644 index 0000000..0737bda --- /dev/null +++ b/feature-shortabel-generator/src/main/java/uk/ac/ebi/intact/tools/feature/shortlabel/generator/events/TypeErrorEvent.java @@ -0,0 +1,50 @@ +package uk.ac.ebi.intact.tools.feature.shortlabel.generator.events; + + +/** + * Created by Maximilian Koch (mkoch@ebi.ac.uk). + */ +public class TypeErrorEvent { + private String featureAc; + private String interactorAc; + private ObjTypeErrorType errorType; + private String message; + + public TypeErrorEvent(String featureAc, String interactorAc, ObjTypeErrorType error) { + this.featureAc = (featureAc == null) ? "undefined" : featureAc; + this.interactorAc = (interactorAc == null) ? "undefined" : interactorAc; + this.errorType = error; + this.message = error.getMessage(); + } + + public String getFeatureAc() { + return featureAc; + } + + public String getInteractorAc() { + return interactorAc; + } + + public ObjTypeErrorType getErrorType() { + return errorType; + } + + public String getMessage() { + return message; + } + + public enum ObjTypeErrorType { + WRONG_INTERACTOR_TYPE("Interactor is not of type mutation"), + WRONG_FEATURE_TYPE("Feature is not of type mutation"); + + private String message; + + ObjTypeErrorType(String message) { + this.message = message; + } + + public String getMessage() { + return message; + } + } +} diff --git a/feature-shortabel-generator/src/main/java/uk/ac/ebi/intact/tools/feature/shortlabel/generator/events/UndefinedMutationEvent.java b/feature-shortabel-generator/src/main/java/uk/ac/ebi/intact/tools/feature/shortlabel/generator/events/UndefinedMutationEvent.java new file mode 100644 index 0000000..98aca68 --- /dev/null +++ b/feature-shortabel-generator/src/main/java/uk/ac/ebi/intact/tools/feature/shortlabel/generator/events/UndefinedMutationEvent.java @@ -0,0 +1,22 @@ +package uk.ac.ebi.intact.tools.feature.shortlabel.generator.events; + +/** + * Created by Maximilian Koch (mkoch@ebi.ac.uk). + */ +public class UndefinedMutationEvent { + private String featureAc; + private String interactorAc; + + public UndefinedMutationEvent(String featureAc, String interactorAc) { + this.featureAc = (featureAc == null) ? "undefined" : featureAc; + this.interactorAc = (interactorAc == null) ? "undefined" : interactorAc; + } + + public String getFeatureAc() { + return featureAc; + } + + public String getInteractorAc() { + return interactorAc; + } +} diff --git a/feature-shortabel-generator/src/main/java/uk/ac/ebi/intact/tools/feature/shortlabel/generator/exception/FeatureShortlabelGenerationException.java b/feature-shortabel-generator/src/main/java/uk/ac/ebi/intact/tools/feature/shortlabel/generator/exception/FeatureShortlabelGenerationException.java new file mode 100644 index 0000000..025fe2b --- /dev/null +++ b/feature-shortabel-generator/src/main/java/uk/ac/ebi/intact/tools/feature/shortlabel/generator/exception/FeatureShortlabelGenerationException.java @@ -0,0 +1,32 @@ +package uk.ac.ebi.intact.tools.feature.shortlabel.generator.exception; + +/** + * Created by Maximilian Koch (mkoch@ebi.ac.uk). + */ +public class FeatureShortlabelGenerationException extends RuntimeException { + + private String message; + + public FeatureShortlabelGenerationException() { + super(); + } + + public FeatureShortlabelGenerationException(String message) { + super(message); + this.message = message; + } + + public FeatureShortlabelGenerationException(Throwable cause) { + super(cause); + } + + @Override + public String toString() { + return message; + } + + @Override + public String getMessage() { + return message; + } +} diff --git a/feature-shortabel-generator/src/main/java/uk/ac/ebi/intact/tools/feature/shortlabel/generator/model/AminoAcids.java b/feature-shortabel-generator/src/main/java/uk/ac/ebi/intact/tools/feature/shortlabel/generator/model/AminoAcids.java new file mode 100644 index 0000000..02bc878 --- /dev/null +++ b/feature-shortabel-generator/src/main/java/uk/ac/ebi/intact/tools/feature/shortlabel/generator/model/AminoAcids.java @@ -0,0 +1,59 @@ +package uk.ac.ebi.intact.tools.feature.shortlabel.generator.model; + +/** + * Created by Maximilian Koch (mkoch@ebi.ac.uk). + */ +public enum AminoAcids { + ALANINE('A', "ala"), + ASPARAGINE_OR_ASPARTIC_ACID('B', "asx"), + CYSTEINE('C', "cys"), + ASPARTIC_ACID('D', "asp"), + GLUTAMIC_ACID('E', "glu"), + PHENYLALANINE('F', "phe"), + GLYCINE('G', "gly"), + HISTIDINE('H', "his"), + ISOLEUCINE('I', "ile"), + LYSINE('K', "lys"), + LEUCINE('L', "leu"), + METHIONINE('M', "met"), + ASPARAGINE('N', "asn"), + SELENOCYSTEINE('U', "sec"), + PROLINE('P', "pro"), + GLUTAMINE('Q', "gln"), + ARGININE('R', "arg"), + SERINE('S', "ser"), + THREONINE('T', "thr"), + PYRROLYSINE('O', "pyl"), + VALINE('V', "val"), + TRYPTOPHAN('W', "trp"), + ANY_CODON('X', "xaa"), + TYROSINE('Y', "tyr"), + GLUTAMINE_OR_GLUTAMIC_ACID('Z', "glx"), + STOP_CODON('*', "*"), + DELETION('.', "del"); + + private Character oneLetterCode; + private String threeLetterCode; + + AminoAcids(Character oneLetterCode, String threeLetterCode) { + this.oneLetterCode = oneLetterCode; + this.threeLetterCode = threeLetterCode; + } + + public Character getOneLetterCode() { + return oneLetterCode; + } + + public String getThreeLetterCode() { + return threeLetterCode; + } + + public static String getThreeLetterCodeByOneLetterCode(Character oneLetterCode) { + for (AminoAcids aminoAcids : values()) { + if (aminoAcids.getOneLetterCode() == oneLetterCode) { + return aminoAcids.getThreeLetterCode(); + } + } + return null; + } +} diff --git a/feature-shortabel-generator/src/main/java/uk/ac/ebi/intact/tools/feature/shortlabel/generator/utils/OntologyServiceHelper.java b/feature-shortabel-generator/src/main/java/uk/ac/ebi/intact/tools/feature/shortlabel/generator/utils/OntologyServiceHelper.java new file mode 100644 index 0000000..1a7354f --- /dev/null +++ b/feature-shortabel-generator/src/main/java/uk/ac/ebi/intact/tools/feature/shortlabel/generator/utils/OntologyServiceHelper.java @@ -0,0 +1,44 @@ +package uk.ac.ebi.intact.tools.feature.shortlabel.generator.utils; + +import uk.ac.ebi.intact.bridges.olslight.OlsLightService; +import uk.ac.ebi.intact.bridges.olslight.OntologyId; +import uk.ac.ebi.intact.bridges.olslight.OntologyService; +import uk.ac.ebi.intact.bridges.olslight.OntologyServiceException; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * Created by Maximilian Koch (mkoch@ebi.ac.uk). + */ +public class OntologyServiceHelper { + + private static OntologyServiceHelper ontologyServiceHelper = new OntologyServiceHelper(); + private static OntologyService ontologyService = new OlsLightService(); + + private OntologyServiceHelper() {} + + public static OntologyServiceHelper getOntologyServiceHelper() { + return ontologyServiceHelper; + } + + public List getAssociatedMITerms(String miTerm, int depth) { + List associatedMITerms = new ArrayList(); + Map psiMITerms = null; + try { + psiMITerms = ontologyService.getTermChildren(OntologyId.PSI_MI, miTerm, depth); + } catch (OntologyServiceException e) { + e.printStackTrace(); + } + if (psiMITerms == null) { + System.err.println("Could not retrieve PSIMI-Terms from OLS"); + System.exit(0); + } + for (Map.Entry entry : psiMITerms.entrySet()) { + associatedMITerms.add(entry.getKey()); + } + associatedMITerms.add(miTerm); + return associatedMITerms; + } +} diff --git a/feature-shortabel-generator/src/main/java/uk/ac/ebi/intact/tools/feature/shortlabel/generator/utils/ShortlabelGeneratorHelper.java b/feature-shortabel-generator/src/main/java/uk/ac/ebi/intact/tools/feature/shortlabel/generator/utils/ShortlabelGeneratorHelper.java new file mode 100644 index 0000000..0895064 --- /dev/null +++ b/feature-shortabel-generator/src/main/java/uk/ac/ebi/intact/tools/feature/shortlabel/generator/utils/ShortlabelGeneratorHelper.java @@ -0,0 +1,103 @@ +package uk.ac.ebi.intact.tools.feature.shortlabel.generator.utils; + +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; +import psidev.psi.mi.jami.model.Polymer; +import uk.ac.ebi.intact.jami.model.extension.IntactFeatureEvidence; +import uk.ac.ebi.intact.jami.model.extension.IntactInteractor; +import uk.ac.ebi.intact.tools.feature.shortlabel.generator.model.AminoAcids; + +import java.util.Objects; + +/** + * Created by Maximilian Koch (mkoch@ebi.ac.uk). + */ +public class ShortlabelGeneratorHelper { + + public boolean orgSeqWrong(String originalSequence, String newGeneratedOriginalSequence) { + return !originalSequence.equals(newGeneratedOriginalSequence); + } + + public boolean containsLowerCaseLetters(String resultingSequence) { + return !resultingSequence.equals(resultingSequence.toUpperCase()); + } + + public boolean isSingleAminoAcidChange(Long startPosition, Long endPosition) { + return startPosition.equals(endPosition); + } + + public boolean resultingSeqDescreased(String originalSequence, String resultingSequence) { + return originalSequence.length() > resultingSequence.length(); + } + + public boolean resultingSeqIncreased(String originalSequence, String resultingSequence) { + return originalSequence.length() < resultingSequence.length(); + } + + public String generateNonSequentialRange(Long startingPosition) { + //Non sequential position are like: ile345thr + return String.valueOf(startingPosition); + } + + public String generateSequentialRange(Long startingPosition, Long endPosition) { + //sequential position are like: pro_thr_leu12-14ala_ala_pro + return startingPosition + "-" + endPosition; + } + + @Transactional(readOnly = true, propagation = Propagation.REQUIRED, value = "jamiTransactionManager") + public String generateOrgSeq(String interactorSequence, Long startingPosition, Long endPosition) { + //Check if the displayed original sequence of a feature, still matches with the whole sequence. + String originalSequence = ""; + while (startingPosition.intValue() <= endPosition.intValue()) { + originalSequence += interactorSequence.charAt(startingPosition.intValue() - 1); + startingPosition++; + } + return originalSequence; + } + + @Transactional(readOnly = true, propagation = Propagation.REQUIRED, value = "jamiTransactionManager") + public String getInteractorSeqByInteractor(IntactInteractor intactInteractor) { + //A polymer is an interactor with a sequence + try { + return ((Polymer) intactInteractor).getSequence(); + } catch (ClassCastException e) { + return null; + } + } + + @Transactional(readOnly = true, propagation = Propagation.REQUIRED, value = "jamiTransactionManager") + public IntactInteractor getInteractorByFeatureEvidence(IntactFeatureEvidence intactFeatureEvidence) { + //To get the whole sequence of a feature, we need to get the interactor + return (IntactInteractor) intactFeatureEvidence.getParticipant().getInteractor(); + } + + public String seq2ThreeLetterCodeOnDefault(String sequence) { + String sequenceAsThreeLetterCode = ""; + for (int i = 0; i < sequence.length(); i++) { + sequenceAsThreeLetterCode += AminoAcids.getThreeLetterCodeByOneLetterCode(sequence.charAt(i)); + if (i < sequence.length() - 1) { + sequenceAsThreeLetterCode += "_"; + } + } + return sequenceAsThreeLetterCode; + } + + public String newSequence2ThreeLetterCodeOnDelete(String originalSequence) { + String sequenceAsThreeLetterCode = AminoAcids.getThreeLetterCodeByOneLetterCode(originalSequence.charAt(0)) + "_"; + for (int i = 0; i < originalSequence.length() - 2; i++) { + sequenceAsThreeLetterCode += "del_"; + } + sequenceAsThreeLetterCode += AminoAcids.getThreeLetterCodeByOneLetterCode(originalSequence.charAt(originalSequence.length() - 1)); + return sequenceAsThreeLetterCode; + } + + public boolean isDeletion(String originalSequence, String newSequence) { + return newSequence.length() == 2 && + originalSequence.charAt(0) == newSequence.charAt(0) && + originalSequence.charAt(originalSequence.length() - 1) == newSequence.charAt(newSequence.length() - 1); + } + + public boolean isUndefinedMutation(IntactFeatureEvidence featureEvidence) { + return Objects.equals(featureEvidence.getShortName(), "undefined mutation"); + } +} diff --git a/feature-shortabel-generator/src/main/resources/META-INF/database.properties b/feature-shortabel-generator/src/main/resources/META-INF/database.properties new file mode 100644 index 0000000..c7ca67b --- /dev/null +++ b/feature-shortabel-generator/src/main/resources/META-INF/database.properties @@ -0,0 +1,4 @@ +db.driver=${db.driver} +db.url=${db.url} +db.user=${db.user} +db.password=${db.password} \ No newline at end of file diff --git a/feature-shortabel-generator/src/main/resources/META-INF/shortlabel-generator-config.xml b/feature-shortabel-generator/src/main/resources/META-INF/shortlabel-generator-config.xml new file mode 100644 index 0000000..808963a --- /dev/null +++ b/feature-shortabel-generator/src/main/resources/META-INF/shortlabel-generator-config.xml @@ -0,0 +1,107 @@ + + + + + + + + + + + + + + + + + + + + classpath:META-INF/database.properties + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + false + none + after_transaction + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/feature-shortabel-generator/src/test/java/ShortlabelGeneratorTest.java b/feature-shortabel-generator/src/test/java/ShortlabelGeneratorTest.java new file mode 100644 index 0000000..a1252e5 --- /dev/null +++ b/feature-shortabel-generator/src/test/java/ShortlabelGeneratorTest.java @@ -0,0 +1,29 @@ +import impl.FeatureObserver; +import org.junit.Before; +import org.junit.Test; +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; +import uk.ac.ebi.intact.tools.feature.shortlabel.generator.ShortlabelGenerator; +import uk.ac.ebi.intact.tools.feature.shortlabel.generator.exception.FeatureShortlabelGenerationException; + +/** + * Created by Maximilian Koch (mkoch@ebi.ac.uk). + */ +public class ShortlabelGeneratorTest { + + private ShortlabelGenerator getShortlabelGenerator(){ + ApplicationContext context = new ClassPathXmlApplicationContext("META-INF/shortlabel-generator-config.xml"); + return context.getBean(ShortlabelGenerator.class); + } + + @Test + public void ShortlabelGeneratorTest_1(){ + ShortlabelGenerator shortlabelGenerator = getShortlabelGenerator(); + shortlabelGenerator.subscribeToEvents(new FeatureObserver()); + try{ + shortlabelGenerator.generateNewShortLabel("EBI-10769146"); + } catch (FeatureShortlabelGenerationException ignored){ + //Only used to stop method... + } + } +} diff --git a/feature-shortabel-generator/src/test/java/impl/FeatureObserver.java b/feature-shortabel-generator/src/test/java/impl/FeatureObserver.java new file mode 100644 index 0000000..5bd4877 --- /dev/null +++ b/feature-shortabel-generator/src/test/java/impl/FeatureObserver.java @@ -0,0 +1,59 @@ +package impl; + +import uk.ac.ebi.intact.tools.feature.shortlabel.generator.ShortlabelGeneratorObserver; +import uk.ac.ebi.intact.tools.feature.shortlabel.generator.events.*; + +/** + * Created by Maximilian Koch (mkoch@ebi.ac.uk). + */ +public class FeatureObserver implements ShortlabelGeneratorObserver { + @Override + public void onRangeErrorEvent(RangeErrorEvent event) { + if (event.getErrorType().equals(RangeErrorEvent.ErrorType.RANGE_NULL)) { + System.out.println(event.getFeatureAc() + "\t" + event.getMessage()); + } else if (event.getErrorType().equals(RangeErrorEvent.ErrorType.ORG_SEQ_NULL)) { + System.out.println(event.getFeatureAc() + "\t" + event.getMessage()); + } else if (event.getErrorType().equals(RangeErrorEvent.ErrorType.RES_SEQ_NULL)) { + System.out.println(event.getFeatureAc() + "\t" + event.getMessage()); + } else if (event.getErrorType().equals(RangeErrorEvent.ErrorType.START_POS_ZERO)) { + System.out.println(event.getFeatureAc() + "\t" + event.getMessage()); + } else if (event.getErrorType().equals(RangeErrorEvent.ErrorType.START_POS_UNDETERMINED)) { + System.out.println(event.getFeatureAc() + "\t" + event.getMessage()); + } + } + + @Override + public void onSuccessfulGeneratedEvent(SuccessfulGeneratedEvent event) { + System.out.println("Everything seems fine about " + event.getFeatureAc() + "OS: " + event.getOriginalShortlabel() + " -> " + event.getFeatureEvidence().getShortName()); + } + + @Override + public void onRetrieveObjErrorEvent(ObjRetrieveErrorEvent event) { + System.out.println(event.getMessage()); + } + + @Override + public void onFeatureAnnotationFoundEvent(FeatureAnnotationFoundEvent event) { + System.out.println(event.getMessage()); + } + + @Override + public void onSeqErrorEvent(SequenceErrorEvent event) { + System.out.println(event.getMessage()); + } + + @Override + public void onResSeqChangedEvent(ResultingSequenceChangedEvent event) { + System.out.println(event.getMessage()); + } + + @Override + public void onTypeErrorEvent(TypeErrorEvent event) { + System.out.println(event.getMessage()); + } + + @Override + public void onUndefinedMutation(UndefinedMutationEvent undefinedMutationEvent) { + + } +} diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..e69de29