From b746ebaa9728ead2462b9910c4ee9a9032a0dce9 Mon Sep 17 00:00:00 2001 From: Piotr Gawron <piotr.gawron@uni.lu> Date: Tue, 20 Feb 2018 17:48:48 +0100 Subject: [PATCH] various style checking warnings fixed --- .../annotation/services/ChemicalParser.java | 1 - .../annotation/services/ModelAnnotator.java | 1345 +++++++++-------- .../services/annotators/BrendaAnnotator.java | 275 ++-- .../services/annotators/ChebiAnnotator.java | 3 - .../annotators/MultipleAnnotatorsTest.java | 112 +- .../annotators/UniprotAnnotatorTest.java | 677 ++++----- .../lcsb/mapviewer/common/Comparator.java | 2 - .../java/lcsb/mapviewer/common/XmlParser.java | 1 - .../lcsb/mapviewer/run/ConsoleConverter.java | 450 ------ .../java/lcsb/mapviewer/run/RunOptions.java | 413 ----- .../ParameterCollectionXmlParser.java | 3 - .../annotation/AllAnnotationTests.java | 4 +- .../model/sbml/SbmlElementParser.java | 1 - .../converter/model/sbml/SbmlParser.java | 1 - .../sbml/species/SbmlSpeciesParserTest.java | 2 - .../converter/OverviewParserTest.java | 1 - .../mapviewer/commands/ColorModelCommand.java | 5 - .../commands/ColorModelCommandTest.java | 18 +- .../ApplySimpleLayoutModelCommandTest.java | 13 +- .../map/OverviewImageLinkComparator.java | 1 + .../compartment/CompartmentComparator.java | 4 +- .../model/map/kinetics/SbmlParameter.java | 3 +- .../map/layout/graphics/LayerComparator.java | 1 - .../model/map/modifier/Inhibition.java | 81 +- .../model/map/modifier/Modulation.java | 81 +- .../map/modifier/PhysicalStimulation.java | 83 +- .../mapviewer/model/map/modifier/Trigger.java | 81 +- .../model/map/modifier/UnknownCatalysis.java | 83 +- .../model/map/modifier/UnknownInhibition.java | 84 +- .../map/reaction/AbstractNodeComparator.java | 6 +- .../model/map/species/ElementComparator.java | 1 - .../model/map/species/field/Structure.java | 681 +++++---- ...tityWithAccessionedSequenceComparator.java | 67 +- .../ComplexAndSimpleEntityComparator.java | 76 +- .../comparators/IonAndComplexComparator.java | 127 +- .../mapviewer/api/users/UserController.java | 1 - .../projects/models/ModelRestImplTest.java | 1 - .../services/interfaces/ISearchService.java | 2 +- .../services/utils/ColorSchemaReader.java | 1 - .../services/view/AbstractTargetView.java | 136 -- .../services/impl/LayoutServiceTest2.java | 1 - .../services/utils/ColorSchemaReaderTest.java | 6 +- .../mapviewer/bean/utils/StartupBean.java | 1 - .../security/MvInvalidSessionStrategy.java | 156 +- 44 files changed, 2021 insertions(+), 3071 deletions(-) delete mode 100644 console/src/main/java/lcsb/mapviewer/run/ConsoleConverter.java delete mode 100644 console/src/main/java/lcsb/mapviewer/run/RunOptions.java delete mode 100644 service/src/main/java/lcsb/mapviewer/services/view/AbstractTargetView.java diff --git a/annotation/src/main/java/lcsb/mapviewer/annotation/services/ChemicalParser.java b/annotation/src/main/java/lcsb/mapviewer/annotation/services/ChemicalParser.java index 886b9f1a89..4172c33e14 100644 --- a/annotation/src/main/java/lcsb/mapviewer/annotation/services/ChemicalParser.java +++ b/annotation/src/main/java/lcsb/mapviewer/annotation/services/ChemicalParser.java @@ -1,6 +1,5 @@ package lcsb.mapviewer.annotation.services; -import java.io.FileNotFoundException; import java.io.IOException; import java.util.ArrayList; import java.util.Collection; diff --git a/annotation/src/main/java/lcsb/mapviewer/annotation/services/ModelAnnotator.java b/annotation/src/main/java/lcsb/mapviewer/annotation/services/ModelAnnotator.java index 792c637103..dfe1637a68 100644 --- a/annotation/src/main/java/lcsb/mapviewer/annotation/services/ModelAnnotator.java +++ b/annotation/src/main/java/lcsb/mapviewer/annotation/services/ModelAnnotator.java @@ -12,13 +12,12 @@ import java.util.Set; import javax.annotation.PostConstruct; -import org.apache.commons.logging.Log; import org.apache.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import lcsb.mapviewer.annotation.services.annotators.AnnotatorException; -import lcsb.mapviewer.annotation.services.annotators.BrendaAnnotator; import lcsb.mapviewer.annotation.services.annotators.BiocompendiumAnnotator; +import lcsb.mapviewer.annotation.services.annotators.BrendaAnnotator; import lcsb.mapviewer.annotation.services.annotators.CazyAnnotator; import lcsb.mapviewer.annotation.services.annotators.ChebiAnnotator; import lcsb.mapviewer.annotation.services.annotators.ElementAnnotator; @@ -54,673 +53,677 @@ import lcsb.mapviewer.modelutils.map.ElementUtils; */ public class ModelAnnotator { - /** - * Time required for annotating in - * {@link #performAnnotations(Model, IProgressUpdater)} method. - */ - private static final double ANNOTATING_RATIO = 0.8; - /** - * Time required for copying annotations from other elements in - * {@link #performAnnotations(Model, IProgressUpdater)} method. - */ - private static final double COPYING_RATIO = 0.2; - - /** - * Connector used for accessing data from miriam registry. - */ - @Autowired - private MiriamConnector miriamConnector; - - /** - * Default class logger. - */ - private static Logger logger = Logger.getLogger(ModelAnnotator.class); - - /** - * BRENDA annotator. - */ - @Autowired - private BrendaAnnotator brendaAnnotator; - - /** - * Service accessing <a href= "http://biocompendium.embl.de/" >internal - * annotating service</a>. - */ - @Autowired - private BiocompendiumAnnotator biocompendiumAnnotator; - - /** - * CAZy annotator. - */ - @Autowired - private CazyAnnotator cazyAnnotator; - - /** - * Backend to the chebi database. - */ - @Autowired - private ChebiAnnotator chebiBackend; - - /** - * Uniprot annotator. - */ - @Autowired - private UniprotAnnotator uniprotAnnotator; - - /** - * PDB annotator. - */ - @Autowired - private PdbAnnotator pdbAnnotator; - - /** - * Recon annotator. - */ - @Autowired - private ReconAnnotator reconAnnotator; - - /** - * Service accessing <a href= "http://www.ebi.ac.uk/QuickGO/" >Gene - * Ontology</a>. - */ - @Autowired - private GoAnnotator goAnnotator; - - /** - * Service accessing <a href= "http://www.genenames.org/" >HUGO Gene - * Nomenclature Committee</a>. - */ - @Autowired - private HgncAnnotator hgncAnnotator; - - /** - * Service accessing <a href= "http://www.kegg.jp/" > KEGG EC Nomenclature</a>. - */ - @Autowired - private KeggAnnotator keggAnnotator; - - /** - * Service accessing <a href= "http://www.ncbi.nlm.nih.gov/gene/" >Entrez</a>. - */ - @Autowired - private EntrezAnnotator entrezAnnotator; - - /** - * Service accessing <a href= "http://ensembl.org">Ensembl</a>. - */ - @Autowired - private EnsemblAnnotator ensemblAnnotator; - - /** - * STITCH annotator. - */ - @Autowired - private StitchAnnotator stitchAnnotator; - - /** - * STRING annotator. - */ - @Autowired - private StringAnnotator stringAnnotator; - - /** - * TAIR annotator. - */ - @Autowired - private TairAnnotator tairAnnotator; - - - /** - * List of all avaliable {@link ElementAnnotator} objects. - */ - private List<ElementAnnotator> availableAnnotators; - - /** - * List of all avaliable {@link ElementAnnotator} objects. - */ - private List<ElementAnnotator> defaultAnnotators; - - /** - * Post intintialization method. Will be called after spring creates beans and - * set the list of valid annotators. - */ - @PostConstruct - public final void init() { - availableAnnotators = new ArrayList<>(); - defaultAnnotators = new ArrayList<>(); - - addAnnotator(brendaAnnotator); - addAnnotator(biocompendiumAnnotator); - addAnnotator(cazyAnnotator); - addAnnotator(chebiBackend); - addAnnotator(uniprotAnnotator); - addAnnotator(goAnnotator); - addAnnotator(hgncAnnotator); - addAnnotator(keggAnnotator); - addAnnotator(pdbAnnotator); - addAnnotator(reconAnnotator); - addAnnotator(entrezAnnotator); - addAnnotator(ensemblAnnotator); - addAnnotator(stitchAnnotator); - addAnnotator(stringAnnotator); - addAnnotator(tairAnnotator); - } - - /** - * Adds annotator list of available annotators in {@link ModelAnnotator} - * class. - * - * @param annotator - * {@link ElementAnnotator} annotator o add - */ - private void addAnnotator(ElementAnnotator annotator) { - availableAnnotators.add(annotator); - if (annotator.isDefault()) { - defaultAnnotators.add(annotator); - } - } - - /** - * Performs all possible and automatic annotations on the model. - * - * @param model - * model to update - * @param progressUpdater - * callback function used for updating progress of the function - */ - public void performAnnotations(Model model, final IProgressUpdater progressUpdater) { - performAnnotations(model, progressUpdater, null, null); - } - - /** - * Performs all possible and automatic annotations on the model. - * - * @param annotators - * this map contains lists of {@link ElementAnnotator} objects that - * should be used for a given classes - * @param model - * model to update - * @param progressUpdater - * callback function used for updating progress of the function - */ - public void performAnnotations(Model model, final IProgressUpdater progressUpdater, Map<Class<?>, - List<ElementAnnotator>> annotators, Map<Class<?>, List<UserAnnotatorsParam>> annotatorsParams) { - progressUpdater.setProgress(0); - List<Model> models = new ArrayList<Model>(); - models.add(model); - models.addAll(model.getSubmodels()); - final double size = models.size(); - double counter = 0; - for (Model m : models) { - final double ratio = counter / size; - - copyAnnotationFromOtherSpecies(m, new IProgressUpdater() { - @Override - public void setProgress(final double progress) { - progressUpdater.setProgress(ratio * IProgressUpdater.MAX_PROGRESS + (progress * COPYING_RATIO) / size); - } - }); - annotateModel(m, new IProgressUpdater() { - - @Override - public void setProgress(double progress) { - progressUpdater - .setProgress(ratio * IProgressUpdater.MAX_PROGRESS + (COPYING_RATIO * IProgressUpdater.MAX_PROGRESS + progress * ANNOTATING_RATIO) / size); - } - }, annotators, annotatorsParams); - counter++; - } - } - - /** - * Due to some limitation of CellDesigner, some annotations are missing in xml - * file. Therefore there are two other places where we look for annotations: - * <ul> - * <li>notes,</li> - * <li>other elements with the same name and type.</li> - * </ul> - * - * This method copies data to elements without annotations from other elements - * with the same name and type. - * - * @param model - * model in which element annotations are updated - * @param progressUpdater - * callback function that updates the progress of function execution - */ - protected void copyAnnotationFromOtherSpecies(Model model, IProgressUpdater progressUpdater) { - double counter = 0; - double amount = model.getElements().size(); - for (Species element : model.getSpeciesList()) { - if (element.getMiriamData().size() == 0) { - List<Element> speciesList = model.getElementsByName(element.getName()); - for (Element species2 : speciesList) { - if (species2.getClass().equals(element.getClass()) && species2.getMiriamData().size() > 0 && element.getMiriamData().size() == 0) { - for (MiriamData md : species2.getMiriamData()) { - element.addMiriamData(new MiriamData(md)); - } - } - } - } - counter++; - progressUpdater.setProgress(counter / amount * IProgressUpdater.MAX_PROGRESS); - } - } - - /** - * Annotates all elements in the model using set of {@link ElementAnnotator} - * given in the param. If the set is empty then all annotators will be used. - * - * @param annotators - * this map contains lists of {@link ElementAnnotator} objects that - * should be used for a given classes - * @param model - * model where annotation shoud be updated - * @param progressUpdater - * callback function used to refresh progress of function execution - */ - protected void annotateModel(Model model, IProgressUpdater progressUpdater, Map<Class<?>, List<ElementAnnotator>> annotators) { - annotateModel(model, progressUpdater, annotators, null); - } - - /** - * Annotates all elements in the model using set of {@link ElementAnnotator} - * given in the param. If the set is empty then all annotators will be used. - * - * @param annotators - * this map contains lists of {@link ElementAnnotator} objects that - * should be used for a given classes - * @param annotatorsParams - * this map contains lists of {@link UserAnnotatorsParam} objects that - * should be used for a given {@link ElementAnnotator} class - * @param model - * model where annotation should be updated - * @param progressUpdater - * callback function used to refresh progress of function execution - */ - protected void annotateModel(Model model, IProgressUpdater progressUpdater, Map<Class<?>, List<ElementAnnotator>> annotators, - Map<Class<?>, List<UserAnnotatorsParam>> annotatorsParams) { - ElementUtils elementUtils = new ElementUtils(); - - progressUpdater.setProgress(0); - - double counter = 0; - double amount = model.getElements().size() + model.getReactions().size(); - - // annotate all elements - for (Element element : model.getElements()) { - List<ElementAnnotator> list = null; - if (annotators != null) { - list = annotators.get(element.getClass()); - } - if (list == null) { - list = getDefaultAnnotators(); - } - - for (ElementAnnotator elementAnnotator : list) { - try { - if (annotatorsParams != null){ - List<UserAnnotatorsParam> params = annotatorsParams.get(elementAnnotator.getClass()); - if (params != null) { - elementAnnotator.annotateElement(element, params); - } - } else { - elementAnnotator.annotateElement(element); - } - - } catch (AnnotatorException e) { - logger.warn(elementUtils.getElementTag(element) + " " + elementAnnotator.getCommonName() + " annotation problem: " + e.getMessage()); - } - } - counter++; - progressUpdater.setProgress(IProgressUpdater.MAX_PROGRESS * counter / amount); - } - - // annotate all reactions - for (BioEntity element : model.getReactions()) { - List<ElementAnnotator> list = null; - if (annotators != null) { - list = annotators.get(element.getClass()); - } - if (list == null) { - list = getDefaultAnnotators(); - } - - for (ElementAnnotator elementAnnotator : list) { - try { - elementAnnotator.annotateElement(element); - } catch (AnnotatorException e) { - logger.warn(elementUtils.getElementTag(element) + " " + elementAnnotator.getCommonName() + " annotation problem", e); - } - } - counter++; - progressUpdater.setProgress(IProgressUpdater.MAX_PROGRESS * counter / amount); - } - } - - /** - * Returns list of default annotators ({@link ElementAnnotator} with - * {@link ElementAnnotator#isDefault} flag). - * - * @return list of default annotators - */ - List<ElementAnnotator> getDefaultAnnotators() { - return defaultAnnotators; - } - - /** - * This method returns list of improper annotations for the model. Improper - * annotation is the annotation of the wrong type for given type of element. - * Types of proper annotations are defined in {@link MiriamType} enum. - * - * @param m - * model - * @param updater - * updater call back function that updat information about progress - * of the function - * @param validAnnotations - * map that contains information which {@link MiriamType miriam - * types} are valid for which class - * @return list of improper annotations - */ - public Collection<ImproperAnnotations> findImproperAnnotations(Model m, IProgressUpdater updater, - Map<Class<? extends BioEntity>, Set<MiriamType>> validAnnotations) { - if (validAnnotations == null) { - logger.warn("List of valid annotations is missing. Using default."); - validAnnotations = getDefaultValidClasses(); - } - updater.setProgress(0.0); - List<Model> models = new ArrayList<Model>(); - models.add(m); - models.addAll(m.getSubmodels()); - List<ImproperAnnotations> result = new ArrayList<>(); - - double modelSize = models.size(); - double modelCounter = 0; - for (Model model : models) { - double ratio = modelCounter / modelSize; - double size = model.getElements().size() + model.getReactions().size(); - double counter = 0; - for (Element element : model.getElements()) { - result.addAll(findImproperAnnotations(element, validAnnotations.get(element.getClass()))); - counter++; - updater.setProgress(ratio * IProgressUpdater.MAX_PROGRESS + (counter / size * IProgressUpdater.MAX_PROGRESS) / modelSize); - } - for (Reaction reaction : model.getReactions()) { - result.addAll(findImproperAnnotations(reaction, validAnnotations.get(reaction.getClass()))); - counter++; - updater.setProgress(ratio * IProgressUpdater.MAX_PROGRESS + (counter / size * IProgressUpdater.MAX_PROGRESS) / modelSize); - } - modelCounter++; - } - return result; - } - - /** - * This method returns list of improper annotations for the element. - * - * @param element - * where we look for improper annotations - * @param validClasses - * list of {@link MiriamType miriam types} that are valid for a given - * {@link BioEntity} - * @return list of improper annotations - */ - protected List<ImproperAnnotations> findImproperAnnotations(BioEntity element, Collection<MiriamType> validClasses) { - List<ImproperAnnotations> result = new ArrayList<>(); - for (MiriamData md : element.getMiriamData()) { - boolean valid = false; - if (validClasses.contains(md.getDataType())) { - valid = true; - } - if (valid && miriamConnector.getUrlString(md) == null) { - valid = false; - } - if (!valid) { - result.add(new ImproperAnnotations(element, md)); - } - } - return result; - } - - /** - * Returns list of all elements that miss annotation. - * - * @param m - * model where the search is performed - * @param requestedAnnotations - * map that contains information which {@link MiriamType miriam - * types} are obigatory for which class - * - * @return list of all elements that miss annotation - */ - public Collection<ProblematicAnnotation> findMissingAnnotations(Model m, Map<Class<? extends BioEntity>, Set<MiriamType>> requestedAnnotations) { - if (requestedAnnotations == null) { - logger.warn("List of requested annotations is missing. Using default."); - requestedAnnotations = getDefaultRequiredClasses(); - } - List<ProblematicAnnotation> result = new ArrayList<>(); - - List<Model> models = new ArrayList<>(); - models.add(m); - models.addAll(m.getSubmodels()); - for (Model model : models) { - for (Element alias : model.getElements()) { - result.addAll(findMissing(alias, requestedAnnotations.get(alias.getClass()))); - } - for (Reaction reaction : model.getReactions()) { - result.addAll(findMissing(reaction, requestedAnnotations.get(reaction.getClass()))); - } - } - return result; - } - - /** - * Checks if {@link BioEntity} is properly annotated and if not return info - * about missing annotation. - * - * @param element - * object to be checked - * @param requestedAnnotations - * at list one of this annotations should appear in the element, if - * the list is null then check is skipped, if the list is empty - * (size()==0) then method checks if element contains at least one - * miriam - * @return list of containing improper annotations about element - */ - private List<ProblematicAnnotation> findMissing(BioEntity element, Collection<MiriamType> requestedAnnotations) { - List<ProblematicAnnotation> result = new ArrayList<>(); - // if there are no requested annotations then don't check - if (requestedAnnotations == null) { - return result; - // if there are no requested annotations, but the list was mentioned then - // we check if at least one annotation exists - } else if (requestedAnnotations.size() == 0) { - if (element.getMiriamData().size() == 0) { - result.add(new MissingAnnotation(element)); - } - return result; - } - // check if at least one annotation match requested list - for (MiriamData md : element.getMiriamData()) { - for (MiriamType mt : requestedAnnotations) { - if (mt.equals(md.getDataType())) { - return result; - } - } - } - result.add(new MissingRequiredAnnotations(element, requestedAnnotations)); - return result; - } - - /** - * - * @return {@link #availableAnnotators} - */ - public List<ElementAnnotator> getAvailableAnnotators() { - return availableAnnotators; - } - - /** - * Returns list of available annotators for a given class type. - * - * @param clazz - * class type - * @return list of available annotators for a given class type - */ - public List<ElementAnnotator> getAvailableAnnotators(Class<?> clazz) { - List<ElementAnnotator> result = new ArrayList<ElementAnnotator>(); - for (ElementAnnotator annotator : availableAnnotators) { - if (annotator.isAnnotatable(clazz)) { - result.add(annotator); - } - } - return result; - } - - /** - * Returns list of {@link ElementAnnotator} names that are available for class - * given in the parameter. - * - * @param clazz - * class for which list of annotators will be returned - * @return annotators names for a given class - */ - public List<String> getAvailableAnnotatorNames(Class<?> clazz) { - List<String> result = new ArrayList<>(); - for (ElementAnnotator annotator : getAvailableAnnotators(clazz)) { - result.add(annotator.getCommonName()); - } - return result; - } - - /** - * Returns list of default {@link ElementAnnotator} names that are available - * for class given in the parameter. - * - * @param clazz - * class for which list of default annotators will be returned - * @return annotators names for a given class - */ - public List<String> getAvailableDefaultAnnotatorNames(Class<?> clazz) { - List<String> result = new ArrayList<>(); - for (ElementAnnotator annotator : getAvailableDefaultAnnotators(clazz)) { - result.add(annotator.getCommonName()); - } - return result; - } - - /** - * Returns list of default {@link ElementAnnotator annotators} that are - * available for class given in the parameter. - * - * @param clazz - * class for which list of default annotators will be returned - * @return annotators for a given class - */ - public List<ElementAnnotator> getAvailableDefaultAnnotators(Class<?> clazz) { - List<ElementAnnotator> result = new ArrayList<>(); - for (ElementAnnotator annotator : availableAnnotators) { - if (annotator.isAnnotatable(clazz) && annotator.isDefault()) { - result.add(annotator); - } - } - return result; - } - - /** - * Converts list of strings into list of {@link ElementAnnotator}. Strings - * must be valid {@link ElementAnnotator} common names. - * - * @param list - * list of {@link ElementAnnotator#getCommonName()}. - * @return list of {@link ElementAnnotator annotators} - */ - public List<ElementAnnotator> getAnnotatorsFromCommonNames(List<String> list) { - List<ElementAnnotator> result = new ArrayList<>(); - for (String string : list) { - boolean added = false; - for (ElementAnnotator annotator : availableAnnotators) { - if (annotator.getCommonName().equals(string)) { - added = true; - result.add(annotator); - } - } - if (!added) { - throw new InvalidArgumentException("Unknown annotator name: " + string); - } - } - return result; - } - - /** - * Returns map with informations about default valid {@link MiriamType miriam - * types } for {@link BioEntity} class type. - * - * @return map with informations about valid {@link MiriamType miriam types } - * for {@link BioEntity} class type - */ - @SuppressWarnings("unchecked") - public Map<Class<? extends BioEntity>, Set<MiriamType>> getDefaultValidClasses() { - Map<Class<? extends BioEntity>, Set<MiriamType>> result = new HashMap<Class<? extends BioEntity>, Set<MiriamType>>(); - ElementUtils eu = new ElementUtils(); - ClassTreeNode tree = eu.getAnnotatedElementClassTree(); - - Queue<ClassTreeNode> nodes = new LinkedList<ClassTreeNode>(); - nodes.add(tree); - while (!nodes.isEmpty()) { - ClassTreeNode node = nodes.poll(); - Set<MiriamType> set = new HashSet<MiriamType>(); - Class<? extends BioEntity> clazz = (Class<? extends BioEntity>) node.getClazz(); - for (MiriamType mt : MiriamType.values()) { - for (Class<?> clazz2 : mt.getValidClass()) { - if (clazz2.isAssignableFrom(clazz)) { - set.add(mt); - } - } - } - result.put(clazz, set); - for (ClassTreeNode child : node.getChildren()) { - nodes.add(child); - } - } - return result; - } - - /** - * Returns map with informations about default required {@link MiriamType - * miriam types } for {@link BioEntity} class type. - * - * @return map with informations about required {@link MiriamType miriam types - * } for {@link BioEntity} class type - */ - @SuppressWarnings("unchecked") - public Map<Class<? extends BioEntity>, Set<MiriamType>> getDefaultRequiredClasses() { - Map<Class<? extends BioEntity>, Set<MiriamType>> result = new HashMap<>(); - ElementUtils eu = new ElementUtils(); - ClassTreeNode tree = eu.getAnnotatedElementClassTree(); - - Queue<ClassTreeNode> nodes = new LinkedList<>(); - nodes.add(tree); - while (!nodes.isEmpty()) { - ClassTreeNode node = nodes.poll(); - Set<MiriamType> set = null; - Class<? extends BioEntity> clazz = (Class<? extends BioEntity>) node.getClazz(); - if ((Boolean) (node.getData())) { - set = new HashSet<>(); - for (MiriamType mt : MiriamType.values()) { - for (Class<?> clazz2 : mt.getRequiredClass()) { - if (clazz2.isAssignableFrom(clazz)) { - set.add(mt); - } - } - } - } - result.put(clazz, set); - for (ClassTreeNode child : node.getChildren()) { - nodes.add(child); - } - } - return result; - } + /** + * Time required for annotating in + * {@link #performAnnotations(Model, IProgressUpdater)} method. + */ + private static final double ANNOTATING_RATIO = 0.8; + /** + * Time required for copying annotations from other elements in + * {@link #performAnnotations(Model, IProgressUpdater)} method. + */ + private static final double COPYING_RATIO = 0.2; + + /** + * Connector used for accessing data from miriam registry. + */ + @Autowired + private MiriamConnector miriamConnector; + + /** + * Default class logger. + */ + private static Logger logger = Logger.getLogger(ModelAnnotator.class); + + /** + * BRENDA annotator. + */ + @Autowired + private BrendaAnnotator brendaAnnotator; + + /** + * Service accessing <a href= "http://biocompendium.embl.de/" >internal + * annotating service</a>. + */ + @Autowired + private BiocompendiumAnnotator biocompendiumAnnotator; + + /** + * CAZy annotator. + */ + @Autowired + private CazyAnnotator cazyAnnotator; + + /** + * Backend to the chebi database. + */ + @Autowired + private ChebiAnnotator chebiBackend; + + /** + * Uniprot annotator. + */ + @Autowired + private UniprotAnnotator uniprotAnnotator; + + /** + * PDB annotator. + */ + @Autowired + private PdbAnnotator pdbAnnotator; + + /** + * Recon annotator. + */ + @Autowired + private ReconAnnotator reconAnnotator; + + /** + * Service accessing <a href= "http://www.ebi.ac.uk/QuickGO/" >Gene + * Ontology</a>. + */ + @Autowired + private GoAnnotator goAnnotator; + + /** + * Service accessing <a href= "http://www.genenames.org/" >HUGO Gene + * Nomenclature Committee</a>. + */ + @Autowired + private HgncAnnotator hgncAnnotator; + + /** + * Service accessing <a href= "http://www.kegg.jp/" > KEGG EC Nomenclature</a>. + */ + @Autowired + private KeggAnnotator keggAnnotator; + + /** + * Service accessing <a href= "http://www.ncbi.nlm.nih.gov/gene/" >Entrez</a>. + */ + @Autowired + private EntrezAnnotator entrezAnnotator; + + /** + * Service accessing <a href= "http://ensembl.org">Ensembl</a>. + */ + @Autowired + private EnsemblAnnotator ensemblAnnotator; + + /** + * STITCH annotator. + */ + @Autowired + private StitchAnnotator stitchAnnotator; + + /** + * STRING annotator. + */ + @Autowired + private StringAnnotator stringAnnotator; + + /** + * TAIR annotator. + */ + @Autowired + private TairAnnotator tairAnnotator; + + /** + * List of all avaliable {@link ElementAnnotator} objects. + */ + private List<ElementAnnotator> availableAnnotators; + + /** + * List of all avaliable {@link ElementAnnotator} objects. + */ + private List<ElementAnnotator> defaultAnnotators; + + /** + * Post intintialization method. Will be called after spring creates beans and + * set the list of valid annotators. + */ + @PostConstruct + public final void init() { + availableAnnotators = new ArrayList<>(); + defaultAnnotators = new ArrayList<>(); + + addAnnotator(brendaAnnotator); + addAnnotator(biocompendiumAnnotator); + addAnnotator(cazyAnnotator); + addAnnotator(chebiBackend); + addAnnotator(uniprotAnnotator); + addAnnotator(goAnnotator); + addAnnotator(hgncAnnotator); + addAnnotator(keggAnnotator); + addAnnotator(pdbAnnotator); + addAnnotator(reconAnnotator); + addAnnotator(entrezAnnotator); + addAnnotator(ensemblAnnotator); + addAnnotator(stitchAnnotator); + addAnnotator(stringAnnotator); + addAnnotator(tairAnnotator); + } + + /** + * Adds annotator list of available annotators in {@link ModelAnnotator} class. + * + * @param annotator + * {@link ElementAnnotator} annotator o add + */ + private void addAnnotator(ElementAnnotator annotator) { + availableAnnotators.add(annotator); + if (annotator.isDefault()) { + defaultAnnotators.add(annotator); + } + } + + /** + * Performs all possible and automatic annotations on the model. + * + * @param model + * model to update + * @param progressUpdater + * callback function used for updating progress of the function + */ + public void performAnnotations(Model model, final IProgressUpdater progressUpdater) { + performAnnotations(model, progressUpdater, null, null); + } + + /** + * Performs all possible and automatic annotations on the model. + * + * @param annotators + * this map contains lists of {@link ElementAnnotator} objects that + * should be used for a given classes + * @param model + * model to update + * @param progressUpdater + * callback function used for updating progress of the function + */ + public void performAnnotations(Model model, final IProgressUpdater progressUpdater, + Map<Class<?>, List<ElementAnnotator>> annotators, Map<Class<?>, List<UserAnnotatorsParam>> annotatorsParams) { + progressUpdater.setProgress(0); + List<Model> models = new ArrayList<Model>(); + models.add(model); + models.addAll(model.getSubmodels()); + final double size = models.size(); + double counter = 0; + for (Model m : models) { + final double ratio = counter / size; + + copyAnnotationFromOtherSpecies(m, new IProgressUpdater() { + @Override + public void setProgress(final double progress) { + progressUpdater.setProgress(ratio * IProgressUpdater.MAX_PROGRESS + (progress * COPYING_RATIO) / size); + } + }); + annotateModel(m, new IProgressUpdater() { + + @Override + public void setProgress(double progress) { + progressUpdater.setProgress(ratio * IProgressUpdater.MAX_PROGRESS + + (COPYING_RATIO * IProgressUpdater.MAX_PROGRESS + progress * ANNOTATING_RATIO) / size); + } + }, annotators, annotatorsParams); + counter++; + } + } + + /** + * Due to some limitation of CellDesigner, some annotations are missing in xml + * file. Therefore there are two other places where we look for annotations: + * <ul> + * <li>notes,</li> + * <li>other elements with the same name and type.</li> + * </ul> + * + * This method copies data to elements without annotations from other elements + * with the same name and type. + * + * @param model + * model in which element annotations are updated + * @param progressUpdater + * callback function that updates the progress of function execution + */ + protected void copyAnnotationFromOtherSpecies(Model model, IProgressUpdater progressUpdater) { + double counter = 0; + double amount = model.getElements().size(); + for (Species element : model.getSpeciesList()) { + if (element.getMiriamData().size() == 0) { + List<Element> speciesList = model.getElementsByName(element.getName()); + for (Element species2 : speciesList) { + if (species2.getClass().equals(element.getClass()) && species2.getMiriamData().size() > 0 + && element.getMiriamData().size() == 0) { + for (MiriamData md : species2.getMiriamData()) { + element.addMiriamData(new MiriamData(md)); + } + } + } + } + counter++; + progressUpdater.setProgress(counter / amount * IProgressUpdater.MAX_PROGRESS); + } + } + + /** + * Annotates all elements in the model using set of {@link ElementAnnotator} + * given in the param. If the set is empty then all annotators will be used. + * + * @param annotators + * this map contains lists of {@link ElementAnnotator} objects that + * should be used for a given classes + * @param model + * model where annotation shoud be updated + * @param progressUpdater + * callback function used to refresh progress of function execution + */ + protected void annotateModel(Model model, IProgressUpdater progressUpdater, + Map<Class<?>, List<ElementAnnotator>> annotators) { + annotateModel(model, progressUpdater, annotators, null); + } + + /** + * Annotates all elements in the model using set of {@link ElementAnnotator} + * given in the param. If the set is empty then all annotators will be used. + * + * @param annotators + * this map contains lists of {@link ElementAnnotator} objects that + * should be used for a given classes + * @param annotatorsParams + * this map contains lists of {@link UserAnnotatorsParam} objects that + * should be used for a given {@link ElementAnnotator} class + * @param model + * model where annotation should be updated + * @param progressUpdater + * callback function used to refresh progress of function execution + */ + protected void annotateModel(Model model, IProgressUpdater progressUpdater, + Map<Class<?>, List<ElementAnnotator>> annotators, Map<Class<?>, List<UserAnnotatorsParam>> annotatorsParams) { + ElementUtils elementUtils = new ElementUtils(); + + progressUpdater.setProgress(0); + + double counter = 0; + double amount = model.getElements().size() + model.getReactions().size(); + + // annotate all elements + for (Element element : model.getElements()) { + List<ElementAnnotator> list = null; + if (annotators != null) { + list = annotators.get(element.getClass()); + } + if (list == null) { + list = getDefaultAnnotators(); + } + + for (ElementAnnotator elementAnnotator : list) { + try { + if (annotatorsParams != null) { + List<UserAnnotatorsParam> params = annotatorsParams.get(elementAnnotator.getClass()); + if (params != null) { + elementAnnotator.annotateElement(element, params); + } + } else { + elementAnnotator.annotateElement(element); + } + + } catch (AnnotatorException e) { + logger.warn(elementUtils.getElementTag(element) + " " + elementAnnotator.getCommonName() + + " annotation problem: " + e.getMessage()); + } + } + counter++; + progressUpdater.setProgress(IProgressUpdater.MAX_PROGRESS * counter / amount); + } + + // annotate all reactions + for (BioEntity element : model.getReactions()) { + List<ElementAnnotator> list = null; + if (annotators != null) { + list = annotators.get(element.getClass()); + } + if (list == null) { + list = getDefaultAnnotators(); + } + + for (ElementAnnotator elementAnnotator : list) { + try { + elementAnnotator.annotateElement(element); + } catch (AnnotatorException e) { + logger.warn( + elementUtils.getElementTag(element) + " " + elementAnnotator.getCommonName() + " annotation problem", e); + } + } + counter++; + progressUpdater.setProgress(IProgressUpdater.MAX_PROGRESS * counter / amount); + } + } + + /** + * Returns list of default annotators ({@link ElementAnnotator} with + * {@link ElementAnnotator#isDefault} flag). + * + * @return list of default annotators + */ + List<ElementAnnotator> getDefaultAnnotators() { + return defaultAnnotators; + } + + /** + * This method returns list of improper annotations for the model. Improper + * annotation is the annotation of the wrong type for given type of element. + * Types of proper annotations are defined in {@link MiriamType} enum. + * + * @param m + * model + * @param updater + * updater call back function that updat information about progress of + * the function + * @param validAnnotations + * map that contains information which {@link MiriamType miriam types} + * are valid for which class + * @return list of improper annotations + */ + public Collection<ImproperAnnotations> findImproperAnnotations(Model m, IProgressUpdater updater, + Map<Class<? extends BioEntity>, Set<MiriamType>> validAnnotations) { + if (validAnnotations == null) { + logger.warn("List of valid annotations is missing. Using default."); + validAnnotations = getDefaultValidClasses(); + } + updater.setProgress(0.0); + List<Model> models = new ArrayList<Model>(); + models.add(m); + models.addAll(m.getSubmodels()); + List<ImproperAnnotations> result = new ArrayList<>(); + + double modelSize = models.size(); + double modelCounter = 0; + for (Model model : models) { + double ratio = modelCounter / modelSize; + double size = model.getElements().size() + model.getReactions().size(); + double counter = 0; + for (Element element : model.getElements()) { + result.addAll(findImproperAnnotations(element, validAnnotations.get(element.getClass()))); + counter++; + updater.setProgress( + ratio * IProgressUpdater.MAX_PROGRESS + (counter / size * IProgressUpdater.MAX_PROGRESS) / modelSize); + } + for (Reaction reaction : model.getReactions()) { + result.addAll(findImproperAnnotations(reaction, validAnnotations.get(reaction.getClass()))); + counter++; + updater.setProgress( + ratio * IProgressUpdater.MAX_PROGRESS + (counter / size * IProgressUpdater.MAX_PROGRESS) / modelSize); + } + modelCounter++; + } + return result; + } + + /** + * This method returns list of improper annotations for the element. + * + * @param element + * where we look for improper annotations + * @param validClasses + * list of {@link MiriamType miriam types} that are valid for a given + * {@link BioEntity} + * @return list of improper annotations + */ + protected List<ImproperAnnotations> findImproperAnnotations(BioEntity element, Collection<MiriamType> validClasses) { + List<ImproperAnnotations> result = new ArrayList<>(); + for (MiriamData md : element.getMiriamData()) { + boolean valid = false; + if (validClasses.contains(md.getDataType())) { + valid = true; + } + if (valid && miriamConnector.getUrlString(md) == null) { + valid = false; + } + if (!valid) { + result.add(new ImproperAnnotations(element, md)); + } + } + return result; + } + + /** + * Returns list of all elements that miss annotation. + * + * @param m + * model where the search is performed + * @param requestedAnnotations + * map that contains information which {@link MiriamType miriam types} + * are obigatory for which class + * + * @return list of all elements that miss annotation + */ + public Collection<ProblematicAnnotation> findMissingAnnotations(Model m, + Map<Class<? extends BioEntity>, Set<MiriamType>> requestedAnnotations) { + if (requestedAnnotations == null) { + logger.warn("List of requested annotations is missing. Using default."); + requestedAnnotations = getDefaultRequiredClasses(); + } + List<ProblematicAnnotation> result = new ArrayList<>(); + + List<Model> models = new ArrayList<>(); + models.add(m); + models.addAll(m.getSubmodels()); + for (Model model : models) { + for (Element alias : model.getElements()) { + result.addAll(findMissing(alias, requestedAnnotations.get(alias.getClass()))); + } + for (Reaction reaction : model.getReactions()) { + result.addAll(findMissing(reaction, requestedAnnotations.get(reaction.getClass()))); + } + } + return result; + } + + /** + * Checks if {@link BioEntity} is properly annotated and if not return info + * about missing annotation. + * + * @param element + * object to be checked + * @param requestedAnnotations + * at list one of this annotations should appear in the element, if the + * list is null then check is skipped, if the list is empty (size()==0) + * then method checks if element contains at least one miriam + * @return list of containing improper annotations about element + */ + private List<ProblematicAnnotation> findMissing(BioEntity element, Collection<MiriamType> requestedAnnotations) { + List<ProblematicAnnotation> result = new ArrayList<>(); + // if there are no requested annotations then don't check + if (requestedAnnotations == null) { + return result; + // if there are no requested annotations, but the list was mentioned then + // we check if at least one annotation exists + } else if (requestedAnnotations.size() == 0) { + if (element.getMiriamData().size() == 0) { + result.add(new MissingAnnotation(element)); + } + return result; + } + // check if at least one annotation match requested list + for (MiriamData md : element.getMiriamData()) { + for (MiriamType mt : requestedAnnotations) { + if (mt.equals(md.getDataType())) { + return result; + } + } + } + result.add(new MissingRequiredAnnotations(element, requestedAnnotations)); + return result; + } + + /** + * + * @return {@link #availableAnnotators} + */ + public List<ElementAnnotator> getAvailableAnnotators() { + return availableAnnotators; + } + + /** + * Returns list of available annotators for a given class type. + * + * @param clazz + * class type + * @return list of available annotators for a given class type + */ + public List<ElementAnnotator> getAvailableAnnotators(Class<?> clazz) { + List<ElementAnnotator> result = new ArrayList<ElementAnnotator>(); + for (ElementAnnotator annotator : availableAnnotators) { + if (annotator.isAnnotatable(clazz)) { + result.add(annotator); + } + } + return result; + } + + /** + * Returns list of {@link ElementAnnotator} names that are available for class + * given in the parameter. + * + * @param clazz + * class for which list of annotators will be returned + * @return annotators names for a given class + */ + public List<String> getAvailableAnnotatorNames(Class<?> clazz) { + List<String> result = new ArrayList<>(); + for (ElementAnnotator annotator : getAvailableAnnotators(clazz)) { + result.add(annotator.getCommonName()); + } + return result; + } + + /** + * Returns list of default {@link ElementAnnotator} names that are available for + * class given in the parameter. + * + * @param clazz + * class for which list of default annotators will be returned + * @return annotators names for a given class + */ + public List<String> getAvailableDefaultAnnotatorNames(Class<?> clazz) { + List<String> result = new ArrayList<>(); + for (ElementAnnotator annotator : getAvailableDefaultAnnotators(clazz)) { + result.add(annotator.getCommonName()); + } + return result; + } + + /** + * Returns list of default {@link ElementAnnotator annotators} that are + * available for class given in the parameter. + * + * @param clazz + * class for which list of default annotators will be returned + * @return annotators for a given class + */ + public List<ElementAnnotator> getAvailableDefaultAnnotators(Class<?> clazz) { + List<ElementAnnotator> result = new ArrayList<>(); + for (ElementAnnotator annotator : availableAnnotators) { + if (annotator.isAnnotatable(clazz) && annotator.isDefault()) { + result.add(annotator); + } + } + return result; + } + + /** + * Converts list of strings into list of {@link ElementAnnotator}. Strings must + * be valid {@link ElementAnnotator} common names. + * + * @param list + * list of {@link ElementAnnotator#getCommonName()}. + * @return list of {@link ElementAnnotator annotators} + */ + public List<ElementAnnotator> getAnnotatorsFromCommonNames(List<String> list) { + List<ElementAnnotator> result = new ArrayList<>(); + for (String string : list) { + boolean added = false; + for (ElementAnnotator annotator : availableAnnotators) { + if (annotator.getCommonName().equals(string)) { + added = true; + result.add(annotator); + } + } + if (!added) { + throw new InvalidArgumentException("Unknown annotator name: " + string); + } + } + return result; + } + + /** + * Returns map with informations about default valid {@link MiriamType miriam + * types } for {@link BioEntity} class type. + * + * @return map with informations about valid {@link MiriamType miriam types } + * for {@link BioEntity} class type + */ + @SuppressWarnings("unchecked") + public Map<Class<? extends BioEntity>, Set<MiriamType>> getDefaultValidClasses() { + Map<Class<? extends BioEntity>, Set<MiriamType>> result = new HashMap<Class<? extends BioEntity>, Set<MiriamType>>(); + ElementUtils eu = new ElementUtils(); + ClassTreeNode tree = eu.getAnnotatedElementClassTree(); + + Queue<ClassTreeNode> nodes = new LinkedList<ClassTreeNode>(); + nodes.add(tree); + while (!nodes.isEmpty()) { + ClassTreeNode node = nodes.poll(); + Set<MiriamType> set = new HashSet<MiriamType>(); + Class<? extends BioEntity> clazz = (Class<? extends BioEntity>) node.getClazz(); + for (MiriamType mt : MiriamType.values()) { + for (Class<?> clazz2 : mt.getValidClass()) { + if (clazz2.isAssignableFrom(clazz)) { + set.add(mt); + } + } + } + result.put(clazz, set); + for (ClassTreeNode child : node.getChildren()) { + nodes.add(child); + } + } + return result; + } + + /** + * Returns map with informations about default required {@link MiriamType miriam + * types } for {@link BioEntity} class type. + * + * @return map with informations about required {@link MiriamType miriam types } + * for {@link BioEntity} class type + */ + @SuppressWarnings("unchecked") + public Map<Class<? extends BioEntity>, Set<MiriamType>> getDefaultRequiredClasses() { + Map<Class<? extends BioEntity>, Set<MiriamType>> result = new HashMap<>(); + ElementUtils eu = new ElementUtils(); + ClassTreeNode tree = eu.getAnnotatedElementClassTree(); + + Queue<ClassTreeNode> nodes = new LinkedList<>(); + nodes.add(tree); + while (!nodes.isEmpty()) { + ClassTreeNode node = nodes.poll(); + Set<MiriamType> set = null; + Class<? extends BioEntity> clazz = (Class<? extends BioEntity>) node.getClazz(); + if ((Boolean) (node.getData())) { + set = new HashSet<>(); + for (MiriamType mt : MiriamType.values()) { + for (Class<?> clazz2 : mt.getRequiredClass()) { + if (clazz2.isAssignableFrom(clazz)) { + set.add(mt); + } + } + } + } + result.put(clazz, set); + for (ClassTreeNode child : node.getChildren()) { + nodes.add(child); + } + } + return result; + } } diff --git a/annotation/src/main/java/lcsb/mapviewer/annotation/services/annotators/BrendaAnnotator.java b/annotation/src/main/java/lcsb/mapviewer/annotation/services/annotators/BrendaAnnotator.java index a3df6fdc1a..59969b9406 100644 --- a/annotation/src/main/java/lcsb/mapviewer/annotation/services/annotators/BrendaAnnotator.java +++ b/annotation/src/main/java/lcsb/mapviewer/annotation/services/annotators/BrendaAnnotator.java @@ -4,7 +4,6 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.List; -import java.util.regex.Pattern; import org.apache.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; @@ -31,145 +30,139 @@ import lcsb.mapviewer.model.map.species.Rna; */ public class BrendaAnnotator extends ElementAnnotator implements IExternalService { - /** - * Default class logger. - */ - private static Logger logger = Logger.getLogger(BrendaAnnotator.class); - - /** - * Service used for annotation of entities using {@link MiriamType#TAIR_LOCUS - * TAIR}. - */ - @Autowired - private TairAnnotator tairAnnotator; - - /** - * Default constructor. - */ - public BrendaAnnotator() { - super(BrendaAnnotator.class, new Class[] { Protein.class, Gene.class, Rna.class }, false); - } - - @Override - public ExternalServiceStatus getServiceStatus() { - ExternalServiceStatus status = new ExternalServiceStatus(getCommonName(), getUrl()); - - GeneralCacheInterface cacheCopy = getCache(); - this.setCache(null); - - try { - Collection<MiriamData> mds = new UniprotAnnotator().uniProtToEC(createMiriamData(MiriamType.UNIPROT, "P12345")); - - status.setStatus(ExternalServiceStatusType.OK); - List<String> ecs = new ArrayList<>(); - if (mds != null) { - for (MiriamData md: mds) { - ecs.add(md.getResource()); - } - } - if (mds == null || mds.size() != 2 || ecs.indexOf("2.6.1.1") < 0 || ecs.indexOf("2.6.1.7") < 0) { - status.setStatus(ExternalServiceStatusType.CHANGED); - } - } catch (Exception e) { - logger.error(status.getName() + " is down", e); - status.setStatus(ExternalServiceStatusType.DOWN); - } - this.setCache(cacheCopy); - return status; - } - - @Override - public void annotateElement(BioEntity object) throws AnnotatorException { - if (isAnnotatable(object)) { - - MiriamData mdTair = null; - for (MiriamData md : object.getMiriamData()) { - if (md.getDataType().equals(MiriamType.BRENDA)) { - return; - } - else if (md.getDataType().equals(MiriamType.TAIR_LOCUS)) { - mdTair = md; - } - } - - if (mdTair != null) { - tairAnnotator.annotateElement(object); - } - - List<MiriamData> mdUniprots = new ArrayList<MiriamData>(); - for (MiriamData md : object.getMiriamData()) { - if (md.getDataType().equals(MiriamType.UNIPROT)) { - mdUniprots.add(md); - } - } - - UniprotAnnotator uniprotAnnotator = new UniprotAnnotator(); - - - List<String> ecIds = new ArrayList<String>(); - for (MiriamData mdUniprot: mdUniprots) { - try { - Collection<MiriamData> mdECs = uniprotAnnotator.uniProtToEC(mdUniprot); - if (mdECs != null) { - for (MiriamData mdEC: mdECs) { - mdEC.setAnnotator(BrendaAnnotator.class); - mdEC.setDataType(MiriamType.BRENDA); - if (ecIds.indexOf(mdEC.getResource()) == -1) { - ecIds.add(mdEC.getResource()); - object.addMiriamData(mdEC); - } - } - } - } catch (UniprotSearchException e) { - logger.warn("Cannot find EC data for UniProt id: " + mdUniprot.getResource()); - } - } - } - } - - - @Override - public Object refreshCacheQuery(Object query) throws SourceNotAvailable { - String name; - String result = null; - if (query instanceof String) { - name = (String) query; - if (name.startsWith("http")) { - try { - result = getWebPageContent(name); - } catch (IOException e) { - throw new SourceNotAvailable(e); - } - } else { - throw new InvalidArgumentException("Don't know what to do with query: " + query); - } - } else { - throw new InvalidArgumentException("Don't know what to do with class: " + query.getClass()); - } - return result; - } - - - - - @Override - public String getCommonName() { - return MiriamType.BRENDA.getCommonName(); - } - - @Override - public String getUrl() { - return MiriamType.BRENDA.getDbHomepage(); - } - - @Override - protected WebPageDownloader getWebPageDownloader() { - return super.getWebPageDownloader(); - } - - @Override - protected void setWebPageDownloader(WebPageDownloader webPageDownloader) { - super.setWebPageDownloader(webPageDownloader); - } + /** + * Default class logger. + */ + private static Logger logger = Logger.getLogger(BrendaAnnotator.class); + + /** + * Service used for annotation of entities using {@link MiriamType#TAIR_LOCUS + * TAIR}. + */ + @Autowired + private TairAnnotator tairAnnotator; + + /** + * Default constructor. + */ + public BrendaAnnotator() { + super(BrendaAnnotator.class, new Class[] { Protein.class, Gene.class, Rna.class }, false); + } + + @Override + public ExternalServiceStatus getServiceStatus() { + ExternalServiceStatus status = new ExternalServiceStatus(getCommonName(), getUrl()); + + GeneralCacheInterface cacheCopy = getCache(); + this.setCache(null); + + try { + Collection<MiriamData> mds = new UniprotAnnotator().uniProtToEC(createMiriamData(MiriamType.UNIPROT, "P12345")); + + status.setStatus(ExternalServiceStatusType.OK); + List<String> ecs = new ArrayList<>(); + if (mds != null) { + for (MiriamData md : mds) { + ecs.add(md.getResource()); + } + } + if (mds == null || mds.size() != 2 || ecs.indexOf("2.6.1.1") < 0 || ecs.indexOf("2.6.1.7") < 0) { + status.setStatus(ExternalServiceStatusType.CHANGED); + } + } catch (Exception e) { + logger.error(status.getName() + " is down", e); + status.setStatus(ExternalServiceStatusType.DOWN); + } + this.setCache(cacheCopy); + return status; + } + + @Override + public void annotateElement(BioEntity object) throws AnnotatorException { + if (isAnnotatable(object)) { + + MiriamData mdTair = null; + for (MiriamData md : object.getMiriamData()) { + if (md.getDataType().equals(MiriamType.BRENDA)) { + return; + } else if (md.getDataType().equals(MiriamType.TAIR_LOCUS)) { + mdTair = md; + } + } + + if (mdTair != null) { + tairAnnotator.annotateElement(object); + } + + List<MiriamData> mdUniprots = new ArrayList<MiriamData>(); + for (MiriamData md : object.getMiriamData()) { + if (md.getDataType().equals(MiriamType.UNIPROT)) { + mdUniprots.add(md); + } + } + + UniprotAnnotator uniprotAnnotator = new UniprotAnnotator(); + + List<String> ecIds = new ArrayList<String>(); + for (MiriamData mdUniprot : mdUniprots) { + try { + Collection<MiriamData> mdECs = uniprotAnnotator.uniProtToEC(mdUniprot); + if (mdECs != null) { + for (MiriamData mdEC : mdECs) { + mdEC.setAnnotator(BrendaAnnotator.class); + mdEC.setDataType(MiriamType.BRENDA); + if (ecIds.indexOf(mdEC.getResource()) == -1) { + ecIds.add(mdEC.getResource()); + object.addMiriamData(mdEC); + } + } + } + } catch (UniprotSearchException e) { + logger.warn("Cannot find EC data for UniProt id: " + mdUniprot.getResource()); + } + } + } + } + + @Override + public Object refreshCacheQuery(Object query) throws SourceNotAvailable { + String name; + String result = null; + if (query instanceof String) { + name = (String) query; + if (name.startsWith("http")) { + try { + result = getWebPageContent(name); + } catch (IOException e) { + throw new SourceNotAvailable(e); + } + } else { + throw new InvalidArgumentException("Don't know what to do with query: " + query); + } + } else { + throw new InvalidArgumentException("Don't know what to do with class: " + query.getClass()); + } + return result; + } + + @Override + public String getCommonName() { + return MiriamType.BRENDA.getCommonName(); + } + + @Override + public String getUrl() { + return MiriamType.BRENDA.getDbHomepage(); + } + + @Override + protected WebPageDownloader getWebPageDownloader() { + return super.getWebPageDownloader(); + } + + @Override + protected void setWebPageDownloader(WebPageDownloader webPageDownloader) { + super.setWebPageDownloader(webPageDownloader); + } } diff --git a/annotation/src/main/java/lcsb/mapviewer/annotation/services/annotators/ChebiAnnotator.java b/annotation/src/main/java/lcsb/mapviewer/annotation/services/annotators/ChebiAnnotator.java index b526374026..cc2af5f03a 100644 --- a/annotation/src/main/java/lcsb/mapviewer/annotation/services/annotators/ChebiAnnotator.java +++ b/annotation/src/main/java/lcsb/mapviewer/annotation/services/annotators/ChebiAnnotator.java @@ -1,7 +1,5 @@ package lcsb.mapviewer.annotation.services.annotators; -import java.net.MalformedURLException; -import java.net.URL; import java.util.ArrayList; import java.util.HashSet; import java.util.LinkedList; @@ -9,7 +7,6 @@ import java.util.List; import java.util.Queue; import java.util.Set; -import javax.xml.namespace.QName; import javax.xml.ws.WebServiceException; import org.apache.log4j.Logger; diff --git a/annotation/src/test/java/lcsb/mapviewer/annotation/services/annotators/MultipleAnnotatorsTest.java b/annotation/src/test/java/lcsb/mapviewer/annotation/services/annotators/MultipleAnnotatorsTest.java index 27c802a421..7107cb2661 100644 --- a/annotation/src/test/java/lcsb/mapviewer/annotation/services/annotators/MultipleAnnotatorsTest.java +++ b/annotation/src/test/java/lcsb/mapviewer/annotation/services/annotators/MultipleAnnotatorsTest.java @@ -1,82 +1,66 @@ package lcsb.mapviewer.annotation.services.annotators; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.mockito.Matchers.anyString; -import static org.mockito.Mockito.when; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; -import java.util.Set; import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; import lcsb.mapviewer.annotation.AnnotationTestFunctions; -import lcsb.mapviewer.annotation.cache.WebPageDownloader; -import lcsb.mapviewer.annotation.services.ExternalServiceStatusType; -import lcsb.mapviewer.common.exception.InvalidArgumentException; import lcsb.mapviewer.model.map.MiriamData; import lcsb.mapviewer.model.map.MiriamType; import lcsb.mapviewer.model.map.species.GenericProtein; import lcsb.mapviewer.model.map.species.Species; public class MultipleAnnotatorsTest extends AnnotationTestFunctions { - - @Autowired - KeggAnnotator keggAnnotator; - - @Autowired - UniprotAnnotator uniprotAnnotator; - - @Autowired - HgncAnnotator hgncAnnotator; - - @Autowired - BiocompendiumAnnotator biocompendiumAnnotator; - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testAnnotateUniprotByUniprotAndKegg() throws Exception { - try { - - Species protein = new GenericProtein("id"); - protein.setName("bla"); - protein.addMiriamData(new MiriamData(MiriamType.UNIPROT, "P12345")); - - keggAnnotator.annotateElement(protein); - uniprotAnnotator.annotateElement(protein); - hgncAnnotator.annotateElement(protein); - //biocompendiumAnnotator.annotateElement(protein); - - - int cntNoAnnotator = 0; - for (MiriamData md: protein.getMiriamData()) { - if (md.getAnnotator() == null) { - cntNoAnnotator++; - } - } - - assertTrue("Wrong number of annotated elements with no information about annotator", cntNoAnnotator == 1); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + + @Autowired + KeggAnnotator keggAnnotator; + + @Autowired + UniprotAnnotator uniprotAnnotator; + + @Autowired + HgncAnnotator hgncAnnotator; + + @Autowired + BiocompendiumAnnotator biocompendiumAnnotator; + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testAnnotateUniprotByUniprotAndKegg() throws Exception { + try { + + Species protein = new GenericProtein("id"); + protein.setName("bla"); + protein.addMiriamData(new MiriamData(MiriamType.UNIPROT, "P12345")); + + keggAnnotator.annotateElement(protein); + uniprotAnnotator.annotateElement(protein); + hgncAnnotator.annotateElement(protein); + // biocompendiumAnnotator.annotateElement(protein); + + int cntNoAnnotator = 0; + for (MiriamData md : protein.getMiriamData()) { + if (md.getAnnotator() == null) { + cntNoAnnotator++; + } + } + + assertTrue("Wrong number of annotated elements with no information about annotator", cntNoAnnotator == 1); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } } diff --git a/annotation/src/test/java/lcsb/mapviewer/annotation/services/annotators/UniprotAnnotatorTest.java b/annotation/src/test/java/lcsb/mapviewer/annotation/services/annotators/UniprotAnnotatorTest.java index 18172cd7d1..7a1f8552f7 100644 --- a/annotation/src/test/java/lcsb/mapviewer/annotation/services/annotators/UniprotAnnotatorTest.java +++ b/annotation/src/test/java/lcsb/mapviewer/annotation/services/annotators/UniprotAnnotatorTest.java @@ -9,7 +9,6 @@ import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.when; import java.io.IOException; -import java.util.ArrayList; import java.util.Collection; import org.junit.After; @@ -31,342 +30,344 @@ import lcsb.mapviewer.model.map.species.Species; public class UniprotAnnotatorTest extends AnnotationTestFunctions { - @Autowired - UniprotAnnotator uniprotAnnotator; - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testAnnotate1() throws Exception { - try { - - Species protein = new GenericProtein("id"); - protein.setName("P12345"); - uniprotAnnotator.annotateElement(protein); - - assertTrue(protein.getMiriamData().size() > 0); - - boolean entrez = false; - boolean hgnc = false; - boolean uniprot = false; - boolean ec = false; - - for (MiriamData md : protein.getMiriamData()) { - if (md.getDataType().equals(MiriamType.UNIPROT)) { - uniprot = true; - } else if (md.getDataType().equals(MiriamType.HGNC_SYMBOL)) { - hgnc = true; - } else if (md.getDataType().equals(MiriamType.ENTREZ)) { - entrez = true; - } else if (md.getDataType().equals(MiriamType.EC)) { - ec = true; - } - } - assertTrue("No HGNC annotation extracted from uniprot annotator", hgnc); - assertTrue("No ENTREZ annotation extracted from uniprot annotator", entrez); - assertTrue("No UNIPROT annotation extracted from uniprot annotator", uniprot); - assertTrue("No UNIPROT annotation extracted from uniprot annotator", ec); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - - } - - @Test - public void testEC1() throws Exception { - try { - - Collection<MiriamData> mds = uniprotAnnotator.uniProtToEC(new MiriamData(MiriamType.UNIPROT, "P12345")); - - assertEquals(mds.size(), 2); - MiriamData md1 = new MiriamData(MiriamType.EC, "2.6.1.1", UniprotAnnotator.class); - MiriamData md2 = new MiriamData(MiriamType.EC, "2.6.1.7", UniprotAnnotator.class); - for (MiriamData md: mds) { - assertTrue(md.compareTo(md1) == 0 || md.compareTo(md2) == 0); - } - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - - } - - @Test - public void testEC2() throws Exception { - try { - - Collection<MiriamData> mds = uniprotAnnotator.uniProtToEC(new MiriamData(MiriamType.UNIPROT, "P25405")); - - assertTrue("No EC miriam data extracted from uniprot annotator", mds.size() > 0); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - - } - - @Test - public void testInvalidUniprotToECNull() throws Exception { - try { - assertNull(uniprotAnnotator.uniProtToEC(null)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testInvalidUniprotToECWrongMd() throws Exception { - try { - uniprotAnnotator.uniProtToEC(new MiriamData(MiriamType.WIKIPEDIA, "bla")); - fail("Exception expected"); - } catch (InvalidArgumentException e) { - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testAnnotateInvalid2() throws Exception { - try { - Species protein = new GenericProtein("id"); - uniprotAnnotator.annotateElement(protein); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - - } - - @Test - public void testInvalidUniprotToHgnc() throws Exception { - try { - assertNull(uniprotAnnotator.uniProtToHgnc(null)); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testInvalidUniprotToHgnc2() throws Exception { - try { - uniprotAnnotator.uniProtToHgnc(new MiriamData(MiriamType.WIKIPEDIA, "bla")); - fail("Exception expected"); - } catch (InvalidArgumentException e) { - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testAnnotate2() throws Exception { - try { - Species protein = new GenericProtein("id"); - protein.setName("bla"); - protein.addMiriamData(new MiriamData(MiriamType.UNIPROT, "P01308")); - uniprotAnnotator.annotateElement(protein); - - assertTrue(protein.getMiriamData().size() > 1); - - boolean entrez = false; - boolean hgnc = false; - boolean uniprot = false; - - for (MiriamData md : protein.getMiriamData()) { - if (md.getDataType().equals(MiriamType.UNIPROT)) { - uniprot = true; - } else if (md.getDataType().equals(MiriamType.HGNC_SYMBOL)) { - hgnc = true; - } else if (md.getDataType().equals(MiriamType.ENTREZ)) { - entrez = true; - } - } - assertTrue("No HGNC annotation extracted from uniprot annotator", hgnc); - assertTrue("No ENTREZ annotation extracted from uniprot annotator", entrez); - assertTrue("No UNIPROT annotation extracted from uniprot annotator", uniprot); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - - } - - @Test - public void testAnnotateInvalidUniprot() throws Exception { - try { - Species protein = new GenericProtein("id"); - protein.setName("bla"); - protein.addMiriamData(new MiriamData(MiriamType.UNIPROT, "bla")); - uniprotAnnotator.annotateElement(protein); - - assertEquals(1, protein.getMiriamData().size()); - - assertEquals(1, getWarnings().size()); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - - } - - @Test - public void testAnnotateInvalid() throws Exception { - try { - Species protein = new GenericProtein("id"); - protein.setName("bla"); - uniprotAnnotator.annotateElement(protein); - - assertEquals(0, protein.getMiriamData().size()); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - - } - - @Test - public void testUniprotToHgnc() throws Exception { - try { - assertEquals(new MiriamData(MiriamType.HGNC_SYMBOL, "KDR", UniprotAnnotator.class), uniprotAnnotator.uniProtToHgnc(new MiriamData(MiriamType.UNIPROT, "P35968"))); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testRefreshInvalidCacheQuery() throws Exception { - try { - uniprotAnnotator.refreshCacheQuery("invalid_query"); - fail("Exception expected"); - } catch (InvalidArgumentException e) { - assertTrue(e.getMessage().contains("Don't know what to do")); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testRefreshInvalidCacheQuery2() throws Exception { - try { - uniprotAnnotator.refreshCacheQuery(new Object()); - fail("Exception expected"); - } catch (InvalidArgumentException e) { - assertTrue(e.getMessage().contains("Don't know what to do")); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testRefreshCacheQuery() throws Exception { - try { - Object res = uniprotAnnotator.refreshCacheQuery("http://google.pl/"); - assertNotNull(res); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testStatus() throws Exception { - try { - assertEquals(ExternalServiceStatusType.OK, uniprotAnnotator.getServiceStatus().getStatus()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testSimulateDownStatus() throws Exception { - WebPageDownloader downloader = uniprotAnnotator.getWebPageDownloader(); - try { - WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class); - when(mockDownloader.getFromNetwork(anyString(), anyString(), anyString())).thenThrow(new IOException()); - uniprotAnnotator.setWebPageDownloader(mockDownloader); - assertEquals(ExternalServiceStatusType.DOWN, uniprotAnnotator.getServiceStatus().getStatus()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } finally { - uniprotAnnotator.setWebPageDownloader(downloader); - } - } - - @Test - public void testAnnotateWithUniprotServerError() throws Exception { - WebPageDownloader downloader = uniprotAnnotator.getWebPageDownloader(); - GeneralCacheInterface cache = uniprotAnnotator.getCache(); - uniprotAnnotator.setCache(new GeneralCacheWithExclusion(cache, 1)); - try { - WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class); - when(mockDownloader.getFromNetwork(anyString(), anyString(), anyString())).thenThrow(new IOException()); - uniprotAnnotator.setWebPageDownloader(mockDownloader); - Species protein = new GenericProtein("id"); - protein.addMiriamData(new MiriamData(MiriamType.UNIPROT, "P01308")); - uniprotAnnotator.annotateElement(protein); - fail("Exception expected"); - } catch (AnnotatorException e) { - } catch (Exception e) { - e.printStackTrace(); - throw e; - } finally { - uniprotAnnotator.setCache(cache); - uniprotAnnotator.setWebPageDownloader(downloader); - } - } - - @Test - public void testSimulateDownStatus2() throws Exception { - WebPageDownloader downloader = uniprotAnnotator.getWebPageDownloader(); - try { - WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class); - when(mockDownloader.getFromNetwork(anyString(), anyString(), anyString())).thenReturn(""); - uniprotAnnotator.setWebPageDownloader(mockDownloader); - assertEquals(ExternalServiceStatusType.DOWN, uniprotAnnotator.getServiceStatus().getStatus()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } finally { - uniprotAnnotator.setWebPageDownloader(downloader); - } - } - - @Test - public void testSimulateChangedStatus() throws Exception { - WebPageDownloader downloader = uniprotAnnotator.getWebPageDownloader(); - try { - WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class); - when(mockDownloader.getFromNetwork(anyString(), anyString(), anyString())).thenReturn("GN Name=ACSS2; Synonyms=ACAS2;"); - uniprotAnnotator.setWebPageDownloader(mockDownloader); - assertEquals(ExternalServiceStatusType.CHANGED, uniprotAnnotator.getServiceStatus().getStatus()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } finally { - uniprotAnnotator.setWebPageDownloader(downloader); - } - } + @Autowired + UniprotAnnotator uniprotAnnotator; + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testAnnotate1() throws Exception { + try { + + Species protein = new GenericProtein("id"); + protein.setName("P12345"); + uniprotAnnotator.annotateElement(protein); + + assertTrue(protein.getMiriamData().size() > 0); + + boolean entrez = false; + boolean hgnc = false; + boolean uniprot = false; + boolean ec = false; + + for (MiriamData md : protein.getMiriamData()) { + if (md.getDataType().equals(MiriamType.UNIPROT)) { + uniprot = true; + } else if (md.getDataType().equals(MiriamType.HGNC_SYMBOL)) { + hgnc = true; + } else if (md.getDataType().equals(MiriamType.ENTREZ)) { + entrez = true; + } else if (md.getDataType().equals(MiriamType.EC)) { + ec = true; + } + } + assertTrue("No HGNC annotation extracted from uniprot annotator", hgnc); + assertTrue("No ENTREZ annotation extracted from uniprot annotator", entrez); + assertTrue("No UNIPROT annotation extracted from uniprot annotator", uniprot); + assertTrue("No UNIPROT annotation extracted from uniprot annotator", ec); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + + } + + @Test + public void testEC1() throws Exception { + try { + + Collection<MiriamData> mds = uniprotAnnotator.uniProtToEC(new MiriamData(MiriamType.UNIPROT, "P12345")); + + assertEquals(mds.size(), 2); + MiriamData md1 = new MiriamData(MiriamType.EC, "2.6.1.1", UniprotAnnotator.class); + MiriamData md2 = new MiriamData(MiriamType.EC, "2.6.1.7", UniprotAnnotator.class); + for (MiriamData md : mds) { + assertTrue(md.compareTo(md1) == 0 || md.compareTo(md2) == 0); + } + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + + } + + @Test + public void testEC2() throws Exception { + try { + + Collection<MiriamData> mds = uniprotAnnotator.uniProtToEC(new MiriamData(MiriamType.UNIPROT, "P25405")); + + assertTrue("No EC miriam data extracted from uniprot annotator", mds.size() > 0); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + + } + + @Test + public void testInvalidUniprotToECNull() throws Exception { + try { + assertNull(uniprotAnnotator.uniProtToEC(null)); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testInvalidUniprotToECWrongMd() throws Exception { + try { + uniprotAnnotator.uniProtToEC(new MiriamData(MiriamType.WIKIPEDIA, "bla")); + fail("Exception expected"); + } catch (InvalidArgumentException e) { + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testAnnotateInvalid2() throws Exception { + try { + Species protein = new GenericProtein("id"); + uniprotAnnotator.annotateElement(protein); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + + } + + @Test + public void testInvalidUniprotToHgnc() throws Exception { + try { + assertNull(uniprotAnnotator.uniProtToHgnc(null)); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testInvalidUniprotToHgnc2() throws Exception { + try { + uniprotAnnotator.uniProtToHgnc(new MiriamData(MiriamType.WIKIPEDIA, "bla")); + fail("Exception expected"); + } catch (InvalidArgumentException e) { + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testAnnotate2() throws Exception { + try { + Species protein = new GenericProtein("id"); + protein.setName("bla"); + protein.addMiriamData(new MiriamData(MiriamType.UNIPROT, "P01308")); + uniprotAnnotator.annotateElement(protein); + + assertTrue(protein.getMiriamData().size() > 1); + + boolean entrez = false; + boolean hgnc = false; + boolean uniprot = false; + + for (MiriamData md : protein.getMiriamData()) { + if (md.getDataType().equals(MiriamType.UNIPROT)) { + uniprot = true; + } else if (md.getDataType().equals(MiriamType.HGNC_SYMBOL)) { + hgnc = true; + } else if (md.getDataType().equals(MiriamType.ENTREZ)) { + entrez = true; + } + } + assertTrue("No HGNC annotation extracted from uniprot annotator", hgnc); + assertTrue("No ENTREZ annotation extracted from uniprot annotator", entrez); + assertTrue("No UNIPROT annotation extracted from uniprot annotator", uniprot); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + + } + + @Test + public void testAnnotateInvalidUniprot() throws Exception { + try { + Species protein = new GenericProtein("id"); + protein.setName("bla"); + protein.addMiriamData(new MiriamData(MiriamType.UNIPROT, "bla")); + uniprotAnnotator.annotateElement(protein); + + assertEquals(1, protein.getMiriamData().size()); + + assertEquals(1, getWarnings().size()); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + + } + + @Test + public void testAnnotateInvalid() throws Exception { + try { + Species protein = new GenericProtein("id"); + protein.setName("bla"); + uniprotAnnotator.annotateElement(protein); + + assertEquals(0, protein.getMiriamData().size()); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + + } + + @Test + public void testUniprotToHgnc() throws Exception { + try { + assertEquals(new MiriamData(MiriamType.HGNC_SYMBOL, "KDR", UniprotAnnotator.class), + uniprotAnnotator.uniProtToHgnc(new MiriamData(MiriamType.UNIPROT, "P35968"))); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testRefreshInvalidCacheQuery() throws Exception { + try { + uniprotAnnotator.refreshCacheQuery("invalid_query"); + fail("Exception expected"); + } catch (InvalidArgumentException e) { + assertTrue(e.getMessage().contains("Don't know what to do")); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testRefreshInvalidCacheQuery2() throws Exception { + try { + uniprotAnnotator.refreshCacheQuery(new Object()); + fail("Exception expected"); + } catch (InvalidArgumentException e) { + assertTrue(e.getMessage().contains("Don't know what to do")); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testRefreshCacheQuery() throws Exception { + try { + Object res = uniprotAnnotator.refreshCacheQuery("http://google.pl/"); + assertNotNull(res); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testStatus() throws Exception { + try { + assertEquals(ExternalServiceStatusType.OK, uniprotAnnotator.getServiceStatus().getStatus()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testSimulateDownStatus() throws Exception { + WebPageDownloader downloader = uniprotAnnotator.getWebPageDownloader(); + try { + WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class); + when(mockDownloader.getFromNetwork(anyString(), anyString(), anyString())).thenThrow(new IOException()); + uniprotAnnotator.setWebPageDownloader(mockDownloader); + assertEquals(ExternalServiceStatusType.DOWN, uniprotAnnotator.getServiceStatus().getStatus()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } finally { + uniprotAnnotator.setWebPageDownloader(downloader); + } + } + + @Test + public void testAnnotateWithUniprotServerError() throws Exception { + WebPageDownloader downloader = uniprotAnnotator.getWebPageDownloader(); + GeneralCacheInterface cache = uniprotAnnotator.getCache(); + uniprotAnnotator.setCache(new GeneralCacheWithExclusion(cache, 1)); + try { + WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class); + when(mockDownloader.getFromNetwork(anyString(), anyString(), anyString())).thenThrow(new IOException()); + uniprotAnnotator.setWebPageDownloader(mockDownloader); + Species protein = new GenericProtein("id"); + protein.addMiriamData(new MiriamData(MiriamType.UNIPROT, "P01308")); + uniprotAnnotator.annotateElement(protein); + fail("Exception expected"); + } catch (AnnotatorException e) { + } catch (Exception e) { + e.printStackTrace(); + throw e; + } finally { + uniprotAnnotator.setCache(cache); + uniprotAnnotator.setWebPageDownloader(downloader); + } + } + + @Test + public void testSimulateDownStatus2() throws Exception { + WebPageDownloader downloader = uniprotAnnotator.getWebPageDownloader(); + try { + WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class); + when(mockDownloader.getFromNetwork(anyString(), anyString(), anyString())).thenReturn(""); + uniprotAnnotator.setWebPageDownloader(mockDownloader); + assertEquals(ExternalServiceStatusType.DOWN, uniprotAnnotator.getServiceStatus().getStatus()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } finally { + uniprotAnnotator.setWebPageDownloader(downloader); + } + } + + @Test + public void testSimulateChangedStatus() throws Exception { + WebPageDownloader downloader = uniprotAnnotator.getWebPageDownloader(); + try { + WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class); + when(mockDownloader.getFromNetwork(anyString(), anyString(), anyString())) + .thenReturn("GN Name=ACSS2; Synonyms=ACAS2;"); + uniprotAnnotator.setWebPageDownloader(mockDownloader); + assertEquals(ExternalServiceStatusType.CHANGED, uniprotAnnotator.getServiceStatus().getStatus()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } finally { + uniprotAnnotator.setWebPageDownloader(downloader); + } + } } diff --git a/commons/src/main/java/lcsb/mapviewer/common/Comparator.java b/commons/src/main/java/lcsb/mapviewer/common/Comparator.java index 6030a1a6f1..92102ccf02 100644 --- a/commons/src/main/java/lcsb/mapviewer/common/Comparator.java +++ b/commons/src/main/java/lcsb/mapviewer/common/Comparator.java @@ -1,9 +1,7 @@ package lcsb.mapviewer.common; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; import org.apache.log4j.Logger; diff --git a/commons/src/main/java/lcsb/mapviewer/common/XmlParser.java b/commons/src/main/java/lcsb/mapviewer/common/XmlParser.java index 66be945a96..2a7890b879 100644 --- a/commons/src/main/java/lcsb/mapviewer/common/XmlParser.java +++ b/commons/src/main/java/lcsb/mapviewer/common/XmlParser.java @@ -8,7 +8,6 @@ import java.io.InputStream; import java.io.StringReader; import java.io.StringWriter; import java.util.ArrayList; -import java.util.Collection; import java.util.List; import javax.xml.parsers.DocumentBuilder; diff --git a/console/src/main/java/lcsb/mapviewer/run/ConsoleConverter.java b/console/src/main/java/lcsb/mapviewer/run/ConsoleConverter.java deleted file mode 100644 index ef5e72cef0..0000000000 --- a/console/src/main/java/lcsb/mapviewer/run/ConsoleConverter.java +++ /dev/null @@ -1,450 +0,0 @@ -package lcsb.mapviewer.run; - -import java.awt.geom.Point2D; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.IOException; -import java.io.PrintWriter; -import java.io.UnsupportedEncodingException; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.apache.log4j.Logger; - -import lcsb.mapviewer.annotation.services.MiriamConnector; -import lcsb.mapviewer.common.exception.InvalidArgumentException; -import lcsb.mapviewer.common.exception.InvalidStateException; -import lcsb.mapviewer.converter.InvalidInputDataExecption; -import lcsb.mapviewer.converter.model.celldesigner.CellDesignerXmlParser; -import lcsb.mapviewer.model.graphics.PolylineData; -import lcsb.mapviewer.model.map.InconsistentModelException; -import lcsb.mapviewer.model.map.MiriamData; -import lcsb.mapviewer.model.map.MiriamType; -import lcsb.mapviewer.model.map.model.Model; -import lcsb.mapviewer.model.map.model.ModelFullIndexed; -import lcsb.mapviewer.model.map.modifier.Catalysis; -import lcsb.mapviewer.model.map.reaction.Modifier; -import lcsb.mapviewer.model.map.reaction.Product; -import lcsb.mapviewer.model.map.reaction.Reactant; -import lcsb.mapviewer.model.map.reaction.Reaction; -import lcsb.mapviewer.model.map.species.Element; -import lcsb.mapviewer.model.map.species.Species; -import lcsb.mapviewer.modelutils.map.ElementUtils; - -/** - * This class is entry point for console tool to convert data from tab separated - * file a CellDesigner format. - * - * @author Piotr Gawron - * - */ -public class ConsoleConverter { - - /** - * Default class logger. - */ - private final Logger logger = Logger.getLogger(ConsoleConverter.class); - - /** - * Options from the input. - */ - private RunOptions inputOptions; - - /** - * Connector used for accessing data from miriam registry. - */ - private MiriamConnector mc = new MiriamConnector(); - - /** - * Util class used to access some information about {@link Element}. - */ - private ElementUtils elementUtils = new ElementUtils(); - - /** - * Default constructor. - * - * @param args - * parameters with which the program was run - */ - public ConsoleConverter(String[] args) { - inputOptions = new RunOptions(args); - } - - /** - * Main entry point to the program. - * - * @param args - * parameters with which the program was run - */ - public static void main(String[] args) { - // ApplicationContextLoader.loadApplicationContext("consoleApplicationContext.xml"); - ConsoleConverter main = new ConsoleConverter(args); - // ApplicationContextLoader.injectDependencies(main); - try { - main.run(); - } catch (InvalidInputDataExecption e) { - main.logger.error(e, e); - } - } - - /** - * This method transform {@link #inputOptions input data}. - * - * @throws InvalidInputDataExecption - * thrown when the input data are invalid - */ - private void run() throws InvalidInputDataExecption { - if (inputOptions.isFormat()) { - inputOptions.printFormat(); - } else if (!inputOptions.isValidInput() || inputOptions.isHelpOption()) { - inputOptions.printHelp(); - } else { - logger.debug("Running..."); - - String nodesFilename = inputOptions.getNodesFilename(); - - Model model = new ModelFullIndexed(null); - model.setWidth(inputOptions.getModelSize()); - model.setHeight(inputOptions.getModelSize()); - - Set<Element> elements = null; - try { - elements = getNodes(nodesFilename); - } catch (IOException e) { - throw new InvalidInputDataExecption("Problem with input file: " + nodesFilename, e); - } - - double middleX = inputOptions.getModelSize() / 2; - double middleY = inputOptions.getModelSize() / 2; - - double size = elements.size(); - double x = 0; - - for (Element alias : model.getElements()) { - alias.setWidth(inputOptions.getAliasWidth()); - alias.setHeight(inputOptions.getAliasHeight()); - double angle = x / size * 2 * Math.PI; - alias.setX(middleX + Math.sin(angle) * inputOptions.getRadius()); - alias.setY(middleY + Math.cos(angle) * inputOptions.getRadius()); - model.addElement(alias); - x++; - } - - String reactionsFilename = inputOptions.getReactionsFilename(); - - List<Reaction> reactions; - try { - reactions = getReactions(reactionsFilename, model); - } catch (IOException e) { - throw new InvalidInputDataExecption("Problem with input file: " + reactionsFilename, e); - } - model.addReactions(reactions); - String outputFilename = inputOptions.getOutputFilename(); - - CellDesignerXmlParser parser = new CellDesignerXmlParser(); - PrintWriter writer = null; - try { - writer = new PrintWriter(outputFilename, "UTF-8"); - writer.println(parser.toXml(model)); - } catch (FileNotFoundException e) { - throw new InvalidInputDataExecption("Problem with output file: " + outputFilename, e); - } catch (UnsupportedEncodingException e) { - logger.error(e, e); - } catch (InconsistentModelException e) { - throw new InvalidStateException(e); - } finally { - writer.close(); - } - - } - } - - /** - * Returns list of {@link Reaction reactions} obtained from input file. - * - * @param filename - * file with information about reactions - * @param model - * {@link Model} where the data about nodes is stored - * @return list of {@link Reaction reactions} obtained from input file - * @throws InvalidInputDataExecption - * thrown when the file is invalid - * @throws IOException - * thrown when there is a problem with acceesing input file - */ - private List<Reaction> getReactions(String filename, Model model) throws InvalidInputDataExecption, IOException { - List<Reaction> result = new ArrayList<Reaction>(); - Integer identifierColumn = null; - Integer typeColumn = null; - Integer reactantsColumn = null; - Integer modifiersColumn = null; - Integer productsColumn = null; - Integer annotationsColumn = null; - Set<Integer> ids = new HashSet<Integer>(); - BufferedReader br = new BufferedReader(new FileReader(new File(filename))); - try { - String line = br.readLine(); - String[] cols = line.split("\t", -1); - int columns = cols.length; - for (int i = 0; i < cols.length; i++) { - if (cols[i].equalsIgnoreCase(RunOptions.IDENTIFIER_REACTIONS_HEADER)) { - identifierColumn = i; - } else if (cols[i].equalsIgnoreCase(RunOptions.TYPE_REACTIONS_HEADER)) { - typeColumn = i; - } else if (cols[i].equalsIgnoreCase(RunOptions.REACTANTS_REACTIONS_HEADER)) { - reactantsColumn = i; - } else if (cols[i].equalsIgnoreCase(RunOptions.MODIFIERS_REACTIONS_HEADER)) { - modifiersColumn = i; - } else if (cols[i].equalsIgnoreCase(RunOptions.PRODUCTS_REACTIONS_HEADER)) { - productsColumn = i; - } else if (cols[i].equalsIgnoreCase(RunOptions.ANNOTATIONS_REACTIONS_HEADER)) { - annotationsColumn = i; - } else { - throw new InvalidInputDataExecption("Unknown column name " + cols[i], filename); - } - } - if (identifierColumn == null) { - throw new InvalidInputDataExecption("No \"" + RunOptions.IDENTIFIER_REACTIONS_HEADER + "\" defined.", filename); - } else if (typeColumn == null) { - throw new InvalidInputDataExecption("No \"" + RunOptions.TYPE_REACTIONS_HEADER + "\" defined.", filename); - } else if (reactantsColumn == null) { - throw new InvalidInputDataExecption("No \"" + RunOptions.REACTANTS_REACTIONS_HEADER + "\" defined.", filename); - } else if (modifiersColumn == null) { - throw new InvalidInputDataExecption("No \"" + RunOptions.MODIFIERS_REACTIONS_HEADER + "\" defined.", filename); - } else if (productsColumn == null) { - throw new InvalidInputDataExecption("No \"" + RunOptions.PRODUCTS_REACTIONS_HEADER + "\" defined.", filename); - } else if (annotationsColumn == null) { - throw new InvalidInputDataExecption("No \"" + RunOptions.ANNOTATIONS_REACTIONS_HEADER + "\" defined.", filename); - } - int row = 2; - while ((line = br.readLine()) != null) { - cols = line.split("\t", -1); - if (cols.length != columns) { - throw new InvalidInputDataExecption("Invalid number of columns in row " + row, filename); - } - String id = cols[identifierColumn]; - if (ids.contains(id)) { - throw new InvalidInputDataExecption("Id \"" + id + "\" is not unique.", filename); - } - - String className = cols[typeColumn]; - Class<?> clazz = elementUtils.getClassByName(className); - if (clazz == null) { - throw new InvalidInputDataExecption("Unknown element type: " + className, filename); - } - List<Product> products = new ArrayList<Product>(); - String productString = cols[productsColumn]; - for (String string : productString.split(",")) { - if (!string.isEmpty()) { - Species alias = model.getElementByElementId(string.trim()); - Product product = new Product(alias); - products.add(product); - } - } - if (products.size() == 0) { - throw new InvalidInputDataExecption("List of products cannot be empty (row: " + row + ")", filename); - } - - List<Reactant> reactants = new ArrayList<Reactant>(); - String reactantString = cols[reactantsColumn]; - for (String string : reactantString.split(",")) { - if (!string.isEmpty()) { - Species element = model.getElementByElementId(string.trim()); - Reactant product = new Reactant(element); - reactants.add(product); - } - } - if (reactants.size() == 0) { - throw new InvalidInputDataExecption("List of reactants cannot be empty (row: " + row + ")", filename); - } - - List<Modifier> modifiers = new ArrayList<Modifier>(); - String modifierString = cols[modifiersColumn]; - for (String string : modifierString.split(",")) { - if (!string.isEmpty()) { - Species element = model.getElementByElementId(string.trim()); - Modifier modifier = new Catalysis(element); - modifiers.add(modifier); - } - } - Element alias1 = products.get(0).getElement(); - Element alias2 = reactants.get(0).getElement(); - - Point2D middle = new Point2D.Double((alias1.getCenterX() + alias2.getCenterX()) / 2, (alias1.getCenterY() + alias2.getCenterY()) / 2); - - Set<MiriamData> annotations = new HashSet<MiriamData>(); - if (annotationsColumn != null) { - String[] annotationString = cols[annotationsColumn].split(","); - for (String string : annotationString) { - if (!string.isEmpty()) { - try { - annotations.add(MiriamType.getMiriamByUri(string)); - } catch (InvalidArgumentException e) { - throw new InvalidInputDataExecption("Invalid miriam urn: " + string, filename); - } - } - } - } - - try { - if (!Reaction.class.isAssignableFrom(clazz)) { - throw new InvalidInputDataExecption("Invalid reaction type type: " + className, filename); - } - Reaction reaction = (Reaction) clazz.newInstance(); - for (Product product : products) { - product.setLine(new PolylineData(middle, product.getElement().getCenter())); - reaction.addProduct(product); - } - for (Reactant reactant : reactants) { - reactant.setLine(new PolylineData(reactant.getElement().getCenter(), middle)); - reaction.addReactant(reactant); - } - for (Modifier modifier : modifiers) { - modifier.setLine(new PolylineData(middle, modifier.getElement().getCenter())); - reaction.addModifier(modifier); - } - reaction.addMiriamData(annotations); - reaction.setIdReaction(id); - result.add(reaction); - } catch (InstantiationException e) { - throw new InvalidStateException(e); - } catch (IllegalAccessException e) { - throw new InvalidStateException(e); - } - row++; - } - } finally { - br.close(); - } - return result; - } - - /** - * This method parses the data from input file into set of {@link Element - * elements}. - * - * @param filename - * nam of input file - * @return set of {@link Element elements} - * @throws InvalidInputDataExecption - * thrown when the input data is invalid - * @throws IOException - * thrown when there is a problem with input file - */ - private Set<Element> getNodes(String filename) throws InvalidInputDataExecption, IOException { - ElementUtils elementUtils = new ElementUtils(); - - Set<Element> result = new HashSet<>(); - Set<String> ids = new HashSet<>(); - - Integer identifierColumn = null; - Integer typeColumn = null; - Integer nameColumn = null; - Integer annotationsColumn = null; - - BufferedReader br = new BufferedReader(new FileReader(new File(filename))); - try { - String line = br.readLine(); - String[] cols = line.split("\t", -1); - int columns = cols.length; - for (int i = 0; i < cols.length; i++) { - if (cols[i].equalsIgnoreCase(RunOptions.IDENTIFIER_NODES_HEADER)) { - identifierColumn = i; - } else if (cols[i].equalsIgnoreCase(RunOptions.TYPE_NODES_HEADER)) { - typeColumn = i; - } else if (cols[i].equalsIgnoreCase(RunOptions.NAME_NODES_HEADER)) { - nameColumn = i; - } else if (cols[i].equalsIgnoreCase(RunOptions.ANNOTATIONS_NODES_HEADER)) { - annotationsColumn = i; - } else { - throw new InvalidInputDataExecption("Unknown column name " + cols[i], filename); - } - } - if (identifierColumn == null) { - throw new InvalidInputDataExecption("No \"" + RunOptions.IDENTIFIER_NODES_HEADER + "\" defined.", filename); - } - if (typeColumn == null) { - throw new InvalidInputDataExecption("No \"" + RunOptions.TYPE_NODES_HEADER + "\" defined.", filename); - } - if (nameColumn == null) { - throw new InvalidInputDataExecption("No \"" + RunOptions.NAME_NODES_HEADER + "\" defined.", filename); - } - int row = 2; - while ((line = br.readLine()) != null) { - if (line.isEmpty()) { - continue; - } - cols = line.split("\t", -1); - if (cols.length != columns) { - throw new InvalidInputDataExecption( - "Invalid number of columns in row " + row + ". Expected " + columns + ", but " + cols.length + " found", filename); - } - String id = cols[identifierColumn]; - if (ids.contains(id)) { - throw new InvalidInputDataExecption("Id \"" + id + "\" is not unique.", filename); - } - - String className = cols[typeColumn]; - Class<?> clazz = elementUtils.getClassByName(className); - if (clazz == null) { - throw new InvalidInputDataExecption("Unknown element type: " + className, filename); - } - String name = cols[nameColumn]; - if (name.isEmpty()) { - throw new InvalidInputDataExecption("Name cannot be empty (row " + row + ").", filename); - } - Set<MiriamData> annotations = new HashSet<MiriamData>(); - if (annotationsColumn != null) { - String[] annotationString = cols[annotationsColumn].split(","); - for (String string : annotationString) { - if (!string.isEmpty()) { - try { - annotations.add(MiriamType.getMiriamByUri(string)); - } catch (InvalidArgumentException e) { - throw new InvalidInputDataExecption("Invalid miriam urn: " + string, filename); - } - } - } - } - - try { - if (!Element.class.isAssignableFrom(clazz)) { - throw new InvalidInputDataExecption("Invliad element type: " + className, filename); - } - Element element = (Element) clazz.getConstructor(String.class).newInstance(id); - element.setName(name); - element.addMiriamData(annotations); - result.add(element); - } catch (ReflectiveOperationException | SecurityException e) { - throw new InvalidStateException(e); - } - row++; - } - } finally { - br.close(); - } - - return result; - } - - /** - * @return the mc - * @see #mc - */ - public MiriamConnector getMc() { - return mc; - } - - /** - * @param mc - * the mc to set - * @see #mc - */ - public void setMc(MiriamConnector mc) { - this.mc = mc; - } -} diff --git a/console/src/main/java/lcsb/mapviewer/run/RunOptions.java b/console/src/main/java/lcsb/mapviewer/run/RunOptions.java deleted file mode 100644 index c8a80569ab..0000000000 --- a/console/src/main/java/lcsb/mapviewer/run/RunOptions.java +++ /dev/null @@ -1,413 +0,0 @@ -package lcsb.mapviewer.run; - -import java.util.List; - -import org.apache.commons.cli.BasicParser; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.CommandLineParser; -import org.apache.commons.cli.HelpFormatter; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.OptionBuilder; -import org.apache.commons.cli.Options; -import org.apache.commons.cli.ParseException; -import org.apache.log4j.Logger; - -import lcsb.mapviewer.model.map.reaction.Reaction; -import lcsb.mapviewer.model.map.species.Element; -import lcsb.mapviewer.modelutils.map.ElementUtils; - -/** - * This class is used to parse and store input data for {@link ConsoleConverter} - * . - * - * @author Piotr Gawron - * - */ -public class RunOptions { - /** - * Default class logger. - */ - private final Logger logger = Logger.getLogger(RunOptions.class); - - /** - * Default size of the model (width/height). - */ - private static final int MODEL_SIZE = 8000; - /** - * What is the default radius of the circle used for positioning elements. - */ - private static final double RADIUS = 3500; - - /** - * Default width of created alias. - */ - private static final int ALIAS_WIDTH = 80; - - /** - * Default height of created alias. - */ - private static final int ALIAS_HEIGHT = 20; - - /** - * What is the abbreviation of help option. - */ - private static final String HELP_OPTION = "h"; - /** - * What is the abbreviation of nodes file option. - */ - private static final String NODES_OPTION = "ni"; - /** - * What is the abbreviation of reactions file option. - */ - private static final String REACTIONS_OPTION = "ri"; - /** - * What is the abbreviation of output file option. - */ - private static final String OUTPUT_OPTION = "o"; - /** - * What is the abbreviation of printing file format option. - */ - private static final String FORMAT_OPTION = "f"; - - /** - * String used for identifier column in nodes file. - */ - public static final String IDENTIFIER_NODES_HEADER = "IDENTIFIER"; - /** - * String used for type column in nodes file. - */ - public static final String TYPE_NODES_HEADER = "TYPE"; - /** - * String used for name column in nodes file. - */ - public static final String NAME_NODES_HEADER = "NAME"; - /** - * String used for annotations column in nodes file. - */ - public static final String ANNOTATIONS_NODES_HEADER = "ANNOTATIONS"; - - /** - * Description of nodes file. - */ - private static final String NODES_DESCRIPTION = "<nodes-file>\n" - + "This file contains information about node elements (chemicals, proteins, etc.) " // - + "that will be included in the output file. The file is tab separeted list of elements " // - + "with the header row. Following columns are obligatory:\n" // - + "* " + IDENTIFIER_NODES_HEADER - + " - unique identifier of the element\n" // - + "* " + TYPE_NODES_HEADER - + " - type of the element. Following types are acceptable: $TYPES\n" // - + "* " + NAME_NODES_HEADER + " - name of the element\n" // - + "* " + ANNOTATIONS_NODES_HEADER + " - comma separated list of annotations in " // - + "Miriam format (http://www.ebi.ac.uk/miriam/main/)\n"; // - - /** - * String used for identifier column in reactions file. - */ - public static final String IDENTIFIER_REACTIONS_HEADER = IDENTIFIER_NODES_HEADER; - /** - * String used for type column in reactions file. - */ - public static final String TYPE_REACTIONS_HEADER = TYPE_NODES_HEADER; - /** - * String used for reactants column in reactions file. - */ - public static final String REACTANTS_REACTIONS_HEADER = "REACTANTS"; - /** - * String used for modifiers column in reactions file. - */ - public static final String MODIFIERS_REACTIONS_HEADER = "MODIFIERS"; - /** - * String used for products column in reactions file. - */ - public static final String PRODUCTS_REACTIONS_HEADER = "PRODUCTS"; - /** - * String used for annotations column in reactions file. - */ - public static final String ANNOTATIONS_REACTIONS_HEADER = ANNOTATIONS_NODES_HEADER; - - /** - * Description of reactions file. - */ - private static final String REACTIONS_DESCRIPTION = "<reactions-file>\n" // - + "This file contains information about reactions. The file is tab separeted list of all " // - + "reactions with the header row. Following columns are obligatory:\n" // - + "* " + IDENTIFIER_REACTIONS_HEADER - + " - unique identifier of the reaction\n" // - + "* " - + TYPE_REACTIONS_HEADER - + " - type of the element. Following types are acceptable: $R_TYPES\n" // - + "* " + REACTANTS_REACTIONS_HEADER + " - comma separated list of reactant identifiers\n" // - + "* " + MODIFIERS_REACTIONS_HEADER + " - comma separated list of modifier identifiers\n" // - + "* " + PRODUCTS_REACTIONS_HEADER + " - comma separated list of product identifiers\n" // - + "* " + ANNOTATIONS_REACTIONS_HEADER + " - comma separated list of annotations in " // - + "Miriam format (http://www.ebi.ac.uk/miriam/main/)\n"; // - - /** - * Object with available input options. - */ - private Options options; - - /** - * What should be the command line to run the program. - */ - private String commandLineRun = null; - - /** - * Was the input valid? - */ - private boolean validInput = false; - - /** - * Data parsed from input. - */ - private CommandLine commandLine; - - /** - * Default constructor that parses data. - * - * @param args - * parameters used to run the program - */ - public RunOptions(String[] args) { - options = new Options(); - options.addOption(createOption("nodes-input", NODES_OPTION, true, "nodes-file", "tab separated file with input nodes (chemicals, proteins, etc.)")); - options.addOption(createOption("reaction-input", REACTIONS_OPTION, true, "reactions-file", "tab separated file with input reactions")); - options.addOption(createOption("output", OUTPUT_OPTION, true, "output-file", "CellDesigner file with output diagram")); - OptionBuilder.isRequired(false); - options.addOption(HELP_OPTION, false, "print this help menu"); - options.addOption(FORMAT_OPTION, false, "print format of input files"); - - commandLineRun = "java -jar " + new java.io.File(ConsoleConverter.class.getProtectionDomain().getCodeSource().getLocation().getPath()).getName() - + " [options]"; - - CommandLineParser parser = new BasicParser(); - - try { - validInput = true; - commandLine = parser.parse(options, args); - if (getNodesFilename() == null || getReactionsFilename() == null || getOutputFilename() == null) { - validInput = false; - } - } catch (ParseException e) { - validInput = false; - logger.info(e.getMessage()); - } - - } - - /** - * Creates new {@link Option} object. - * - * @param optionName - * full name of the option - * @param optionAbbreviation - * abbreviation of the option - * @param hasArgument - * has the option argument - * @param argumentName - * name of the argument - * @param description - * description of the option - * @return {@link Option} created from input values - */ - private Option createOption(String optionName, String optionAbbreviation, boolean hasArgument, String argumentName, String description) { - OptionBuilder.hasArg(hasArgument); - if (hasArgument) { - OptionBuilder.withArgName(argumentName); - } - OptionBuilder.withDescription(description); - OptionBuilder.withLongOpt(optionName); - return OptionBuilder.create(optionAbbreviation); - } - - /** - * @return the options - * @see #options - */ - public Options getOptions() { - return options; - } - - /** - * @param options - * the options to set - * @see #options - */ - public void setOptions(Options options) { - this.options = options; - } - - /** - * @return the commandLineRun - * @see #commandLineRun - */ - public String getCommandLineRun() { - return commandLineRun; - } - - /** - * @param commandLineRun - * the commandLineRun to set - * @see #commandLineRun - */ - public void setCommandLineRun(String commandLineRun) { - this.commandLineRun = commandLineRun; - } - - /** - * @return the validInput - * @see #validInput - */ - public boolean isValidInput() { - return validInput; - } - - /** - * @param validInput - * the validInput to set - * @see #validInput - */ - public void setValidInput(boolean validInput) { - this.validInput = validInput; - } - - /** - * @return the commandLine - * @see #commandLine - */ - public CommandLine getCommandLine() { - return commandLine; - } - - /** - * @param commandLine - * the commandLine to set - * @see #commandLine - */ - public void setCommandLine(CommandLine commandLine) { - this.commandLine = commandLine; - } - - /** - * Prints help to the console how to used the program (what parameters to put - * and what are they used for). - */ - public void printHelp() { - HelpFormatter formatter = new HelpFormatter(); - formatter.printHelp(commandLineRun, options); - } - - /** - * Prints information about input file formats. - */ - public void printFormat() { - String desc = NODES_DESCRIPTION; - ElementUtils eu = new ElementUtils(); - List<Class<? extends Element>> classes = eu.getAvailableElementSubclasses(); - String classString = ""; - for (Class<? extends Element> class1 : classes) { - classString += class1.getSimpleName() + ", "; - } - desc = desc.replaceAll("\\$TYPES", classString); - desc += "\n"; - - List<Class<? extends Reaction>> rClasses = eu.getAvailableReactionSubclasses(); - classString = ""; - for (Class<? extends Reaction> class1 : rClasses) { - classString += class1.getSimpleName().replace("Reaction", "") + ", "; - } - - desc += REACTIONS_DESCRIPTION.replaceAll("\\$R_TYPES", classString); - System.out.println(desc); - } - - /** - * Checks if {@link #HELP_OPTION} was selected in the input. - * - * @return <code>true</code> if {@link #HELP_OPTION} was selected, - * <code>false</code> otherwise - */ - public boolean isHelpOption() { - return commandLine.hasOption(HELP_OPTION); - } - - /** - * Returns name of the nodes file. - * - * @return name of the nodes file - */ - public String getNodesFilename() { - return commandLine.getOptionValue(NODES_OPTION); - } - - /** - * Returns name of the reactions file. - * - * @return name of the reactions file - */ - public String getReactionsFilename() { - return commandLine.getOptionValue(REACTIONS_OPTION); - } - - /** - * Returns name of the output file. - * - * @return name of the output file - */ - public String getOutputFilename() { - return commandLine.getOptionValue(OUTPUT_OPTION); - } - - /** - * Checks if {@link #FORMAT_OPTION} was selected in the input. - * - * @return <code>true</code> if {@link #FORMAT_OPTION} was selected, - * <code>false</code> otherwise - */ - public boolean isFormat() { - return commandLine.hasOption(FORMAT_OPTION); - } - - /** - * Returns size of created {@link lcsb.mapviewer.model.map.model.Model}. - * - * @return size of created {@link lcsb.mapviewer.model.map.model.Model} - */ - public int getModelSize() { - return RunOptions.MODEL_SIZE; - } - - /** - * Returns width of created - * {@link lcsb.mapviewer.model.map.species.Element}. - * - * @return width of created - * {@link lcsb.mapviewer.model.map.species.Element} - */ - public int getAliasWidth() { - return RunOptions.ALIAS_WIDTH; - } - - /** - * Returns height of created - * {@link lcsb.mapviewer.model.map.species.Element}. - * - * @return height of created - * {@link lcsb.mapviewer.model.map.species.Element} - */ - public int getAliasHeight() { - return RunOptions.ALIAS_HEIGHT; - } - - /** - * Returns radius of the circle on which elements will be located in the - * output CellDesigner file. - * - * @return radius of the circle on which elements will be located - */ - public double getRadius() { - return RunOptions.RADIUS; - } - -} diff --git a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/parameter/ParameterCollectionXmlParser.java b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/parameter/ParameterCollectionXmlParser.java index cf551a6b1a..20d8dcd964 100644 --- a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/parameter/ParameterCollectionXmlParser.java +++ b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/parameter/ParameterCollectionXmlParser.java @@ -16,11 +16,8 @@ public class ParameterCollectionXmlParser extends XmlParser { private ParameterXmlParser parameterParser; - private Model model; - public ParameterCollectionXmlParser(Model model) { parameterParser = new ParameterXmlParser(model); - this.model = model; } public Set<SbmlParameter> parseXmlParameterCollection(Node functionsNode) throws InvalidXmlSchemaException { diff --git a/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/annotation/AllAnnotationTests.java b/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/annotation/AllAnnotationTests.java index 6b34932db2..21ab5296be 100644 --- a/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/annotation/AllAnnotationTests.java +++ b/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/annotation/AllAnnotationTests.java @@ -4,11 +4,9 @@ import org.junit.runner.RunWith; import org.junit.runners.Suite; import org.junit.runners.Suite.SuiteClasses; -import lcsb.mapviewer.converter.annotation.XmlAnnotationParserTest; - @RunWith(Suite.class) @SuiteClasses({ NoteFieldTest.class, // - RestAnnotationParserTest.class, // + RestAnnotationParserTest.class, // }) public class AllAnnotationTests { diff --git a/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/SbmlElementParser.java b/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/SbmlElementParser.java index c84692525e..1c8468a8c9 100644 --- a/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/SbmlElementParser.java +++ b/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/SbmlElementParser.java @@ -15,7 +15,6 @@ import org.sbml.jsbml.ext.layout.Layout; import lcsb.mapviewer.common.Pair; import lcsb.mapviewer.converter.InvalidInputDataExecption; -import lcsb.mapviewer.model.map.compartment.Compartment; import lcsb.mapviewer.model.map.species.Element; public abstract class SbmlElementParser<T extends org.sbml.jsbml.Symbol> extends SbmlBioEntityParser { diff --git a/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/SbmlParser.java b/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/SbmlParser.java index 9d6c69c344..cb5c319385 100644 --- a/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/SbmlParser.java +++ b/converter-sbml/src/main/java/lcsb/mapviewer/converter/model/sbml/SbmlParser.java @@ -33,7 +33,6 @@ import lcsb.mapviewer.converter.model.sbml.species.SbmlSpeciesParser; import lcsb.mapviewer.model.map.BioEntity; import lcsb.mapviewer.model.map.InconsistentModelException; import lcsb.mapviewer.model.map.MiriamData; -import lcsb.mapviewer.model.map.kinetics.SbmlFunction; import lcsb.mapviewer.model.map.model.Model; import lcsb.mapviewer.model.map.model.ModelFullIndexed; import lcsb.mapviewer.model.map.modifier.Modulation; diff --git a/converter-sbml/src/test/java/lcsb/mapviewer/converter/model/sbml/species/SbmlSpeciesParserTest.java b/converter-sbml/src/test/java/lcsb/mapviewer/converter/model/sbml/species/SbmlSpeciesParserTest.java index c82b00a7e4..2a049eecec 100644 --- a/converter-sbml/src/test/java/lcsb/mapviewer/converter/model/sbml/species/SbmlSpeciesParserTest.java +++ b/converter-sbml/src/test/java/lcsb/mapviewer/converter/model/sbml/species/SbmlSpeciesParserTest.java @@ -6,7 +6,6 @@ import java.io.FileNotFoundException; import org.apache.log4j.Logger; import org.junit.Test; -import org.sbml.jsbml.SBMLDocument; import lcsb.mapviewer.converter.ConverterParams; import lcsb.mapviewer.converter.InvalidInputDataExecption; @@ -129,5 +128,4 @@ public class SbmlSpeciesParserTest { assertTrue(element instanceof Unknown); } - } diff --git a/converter/src/test/java/lcsb/mapviewer/converter/OverviewParserTest.java b/converter/src/test/java/lcsb/mapviewer/converter/OverviewParserTest.java index feace015ae..373feff8d7 100644 --- a/converter/src/test/java/lcsb/mapviewer/converter/OverviewParserTest.java +++ b/converter/src/test/java/lcsb/mapviewer/converter/OverviewParserTest.java @@ -7,7 +7,6 @@ import static org.junit.Assert.fail; import java.awt.geom.Point2D; import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.util.ArrayList; import java.util.Enumeration; diff --git a/model-command/src/main/java/lcsb/mapviewer/commands/ColorModelCommand.java b/model-command/src/main/java/lcsb/mapviewer/commands/ColorModelCommand.java index bda5fc3e61..dc51d7bd73 100644 --- a/model-command/src/main/java/lcsb/mapviewer/commands/ColorModelCommand.java +++ b/model-command/src/main/java/lcsb/mapviewer/commands/ColorModelCommand.java @@ -4,22 +4,17 @@ import java.awt.Color; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; -import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Set; import org.apache.log4j.Logger; -import lcsb.mapviewer.common.Pair; import lcsb.mapviewer.common.comparator.StringComparator; import lcsb.mapviewer.common.exception.InvalidArgumentException; import lcsb.mapviewer.common.exception.NotImplementedException; import lcsb.mapviewer.model.graphics.ArrowTypeData; import lcsb.mapviewer.model.map.BioEntity; import lcsb.mapviewer.model.map.MiriamData; -import lcsb.mapviewer.model.map.MiriamRelationType; -import lcsb.mapviewer.model.map.MiriamType; import lcsb.mapviewer.model.map.compartment.Compartment; import lcsb.mapviewer.model.map.layout.ColorSchema; import lcsb.mapviewer.model.map.layout.InvalidColorSchemaException; diff --git a/model-command/src/test/java/lcsb/mapviewer/commands/ColorModelCommandTest.java b/model-command/src/test/java/lcsb/mapviewer/commands/ColorModelCommandTest.java index 4f6be19fe0..7d0d731afd 100644 --- a/model-command/src/test/java/lcsb/mapviewer/commands/ColorModelCommandTest.java +++ b/model-command/src/test/java/lcsb/mapviewer/commands/ColorModelCommandTest.java @@ -16,7 +16,6 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; -import lcsb.mapviewer.common.Pair; import lcsb.mapviewer.model.map.BioEntity; import lcsb.mapviewer.model.map.MiriamData; import lcsb.mapviewer.model.map.MiriamType; @@ -88,15 +87,15 @@ public class ColorModelCommandTest extends CommandTestFunctions { Model model = getModelForFile("testFiles/coloring_model.xml", true); Collection<ColorSchema> schemas = new ArrayList<>(); ColorSchema schema = new GenericColorSchema(); - schema.addMiriamData(new MiriamData(MiriamType.HGNC,"11138")); + schema.addMiriamData(new MiriamData(MiriamType.HGNC, "11138")); schema.setValue(1.0); schemas.add(schema); schema = new GenericColorSchema(); - schema.addMiriamData(new MiriamData(MiriamType.CHEBI,"CHEBI:15377")); + schema.addMiriamData(new MiriamData(MiriamType.CHEBI, "CHEBI:15377")); schema.setValue(1.0); schemas.add(schema); schema = new GenericColorSchema(); - schema.addMiriamData(new MiriamData(MiriamType.CHEBI,"CHEBI:15376")); + schema.addMiriamData(new MiriamData(MiriamType.CHEBI, "CHEBI:15376")); schema.setValue(1.0); schemas.add(schema); @@ -365,7 +364,7 @@ public class ColorModelCommandTest extends CommandTestFunctions { public void testReactionMatchWithProteinMiriamData() throws Exception { try { GenericColorSchema colorSchema = new GenericColorSchema(); - colorSchema.addMiriamData(new MiriamData(MiriamType.HGNC_SYMBOL,"SNCA")); + colorSchema.addMiriamData(new MiriamData(MiriamType.HGNC_SYMBOL, "SNCA")); Reaction reaction = new Reaction(); @@ -387,7 +386,7 @@ public class ColorModelCommandTest extends CommandTestFunctions { public void testReactionMatchWithMiriamData() throws Exception { try { GenericColorSchema colorSchema = new GenericColorSchema(); - colorSchema.addMiriamData(new MiriamData(MiriamType.PUBMED,"1234")); + colorSchema.addMiriamData(new MiriamData(MiriamType.PUBMED, "1234")); Reaction reaction = new Reaction(); reaction.addMiriamData(new MiriamData(MiriamType.PUBMED, "1234")); @@ -496,7 +495,6 @@ public class ColorModelCommandTest extends CommandTestFunctions { } } - public void testAliasColoringWithUnknownElementSourceId() throws Exception { try { Model model = getModelForFile("testFiles/sample.xml", false); @@ -543,12 +541,12 @@ public class ColorModelCommandTest extends CommandTestFunctions { try { Reaction reaction = new Reaction(); reaction.addMiriamData(new MiriamData(MiriamType.PUBMED, "1234")); - + Model model = new ModelFullIndexed(null); model.addReaction(reaction); GenericColorSchema colorSchema = new GenericColorSchema(); - colorSchema.addMiriamData(new MiriamData(MiriamType.PUBMED,"1234")); + colorSchema.addMiriamData(new MiriamData(MiriamType.PUBMED, "1234")); List<ColorSchema> schemas = new ArrayList<>(); schemas.add(colorSchema); @@ -564,6 +562,4 @@ public class ColorModelCommandTest extends CommandTestFunctions { } - - } diff --git a/model-command/src/test/java/lcsb/mapviewer/commands/layout/ApplySimpleLayoutModelCommandTest.java b/model-command/src/test/java/lcsb/mapviewer/commands/layout/ApplySimpleLayoutModelCommandTest.java index c3769d731b..4acc6bcc88 100644 --- a/model-command/src/test/java/lcsb/mapviewer/commands/layout/ApplySimpleLayoutModelCommandTest.java +++ b/model-command/src/test/java/lcsb/mapviewer/commands/layout/ApplySimpleLayoutModelCommandTest.java @@ -5,7 +5,6 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import java.awt.Dimension; import java.awt.geom.Dimension2D; import java.awt.geom.Point2D; import java.util.ArrayList; @@ -215,7 +214,8 @@ public class ApplySimpleLayoutModelCommandTest { elements.add(p2); p2.addElement(p1); - layoutModelCommand.modifyElementLocation(elements, null, new Point2D.Double(100, 100), new DoubleDimension(200, 200)); + layoutModelCommand.modifyElementLocation(elements, null, new Point2D.Double(100, 100), + new DoubleDimension(200, 200)); assertTrue(p1.getX() >= 100); assertTrue(p1.getY() >= 100); @@ -241,20 +241,21 @@ public class ApplySimpleLayoutModelCommandTest { Compartment compartmentToLayout = new SquareCompartment("comp-id2"); compartmentToLayout.addElement(protein); - + staticCompartment.addElement(compartmentToLayout); - + Set<Element> elements = new HashSet<>(); elements.add(protein); elements.add(compartmentToLayout); - layoutModelCommand.modifyElementLocation(elements, null, new Point2D.Double(1000, 1000), new DoubleDimension(2000, 2000)); + layoutModelCommand.modifyElementLocation(elements, null, new Point2D.Double(1000, 1000), + new DoubleDimension(2000, 2000)); assertFalse(protein.getX() >= 1000); assertFalse(protein.getY() >= 1000); assertTrue(staticCompartment.contains(protein)); - + assertFalse(compartmentToLayout.getX() >= 1000); assertFalse(compartmentToLayout.getY() >= 1000); diff --git a/model/src/main/java/lcsb/mapviewer/model/map/OverviewImageLinkComparator.java b/model/src/main/java/lcsb/mapviewer/model/map/OverviewImageLinkComparator.java index eeb7f3ba0b..8ffff6767c 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/OverviewImageLinkComparator.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/OverviewImageLinkComparator.java @@ -16,6 +16,7 @@ public class OverviewImageLinkComparator extends Comparator<OverviewImageLink> { /** * Default class logger. */ + @SuppressWarnings("unused") private static Logger logger = Logger.getLogger(OverviewImageLinkComparator.class); /** diff --git a/model/src/main/java/lcsb/mapviewer/model/map/compartment/CompartmentComparator.java b/model/src/main/java/lcsb/mapviewer/model/map/compartment/CompartmentComparator.java index 80b2870b9c..524cbddb45 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/compartment/CompartmentComparator.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/compartment/CompartmentComparator.java @@ -11,7 +11,6 @@ import lcsb.mapviewer.common.comparator.DoubleComparator; import lcsb.mapviewer.common.comparator.IntegerComparator; import lcsb.mapviewer.common.comparator.PointComparator; import lcsb.mapviewer.common.exception.InvalidArgumentException; -import lcsb.mapviewer.model.map.reaction.AbstractNodeComparator; import lcsb.mapviewer.model.map.species.Element; import lcsb.mapviewer.model.map.species.ElementComparator; @@ -45,11 +44,10 @@ public class CompartmentComparator extends Comparator<Compartment> { super(Compartment.class); this.epsilon = epsilon; } - + protected Comparator<?> getParentComparator() { return new ElementComparator(epsilon); } - /** * Default constructor. diff --git a/model/src/main/java/lcsb/mapviewer/model/map/kinetics/SbmlParameter.java b/model/src/main/java/lcsb/mapviewer/model/map/kinetics/SbmlParameter.java index aa27e7764a..aba446815c 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/kinetics/SbmlParameter.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/kinetics/SbmlParameter.java @@ -4,7 +4,6 @@ import java.io.Serializable; import javax.persistence.Column; import javax.persistence.Entity; -import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; @@ -50,7 +49,7 @@ public class SbmlParameter implements Serializable, SbmlArgument { private String name; private Double value; - + @ManyToOne() private SbmlUnit units; diff --git a/model/src/main/java/lcsb/mapviewer/model/map/layout/graphics/LayerComparator.java b/model/src/main/java/lcsb/mapviewer/model/map/layout/graphics/LayerComparator.java index 8f842708ac..222ab0a8f7 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/layout/graphics/LayerComparator.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/layout/graphics/LayerComparator.java @@ -7,7 +7,6 @@ import lcsb.mapviewer.common.Configuration; import lcsb.mapviewer.common.comparator.BooleanComparator; import lcsb.mapviewer.common.comparator.IntegerComparator; import lcsb.mapviewer.common.comparator.StringComparator; -import lcsb.mapviewer.common.exception.NotImplementedException; import lcsb.mapviewer.model.graphics.PolylineDataComparator; /** diff --git a/model/src/main/java/lcsb/mapviewer/model/map/modifier/Inhibition.java b/model/src/main/java/lcsb/mapviewer/model/map/modifier/Inhibition.java index a7ee536523..9079867dce 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/modifier/Inhibition.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/modifier/Inhibition.java @@ -6,7 +6,6 @@ import javax.persistence.Entity; import lcsb.mapviewer.common.exception.NotImplementedException; import lcsb.mapviewer.model.map.reaction.Modifier; import lcsb.mapviewer.model.map.species.Element; -import lcsb.mapviewer.model.map.species.Species; /** * This class defines inhibition modifier in the reaction. @@ -18,45 +17,45 @@ import lcsb.mapviewer.model.map.species.Species; @DiscriminatorValue("INHIBITION_MODIFIER") public class Inhibition extends Modifier { - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * Default constructor. - */ - public Inhibition() { - super(); - } - - /** - * Constructor that creates inhibition modifier for given element. - * - * @param element - * element object to which this modifier is assigned - */ - public Inhibition(Element element) { - super(element); - } - - /** - * Constructor that creates object with data taken from parameter inhibition. - * - * @param inhibition - * object from which data are initialized - */ - public Inhibition(Inhibition inhibition) { - super(inhibition); - } - - @Override - public Inhibition copy() { - if (this.getClass() == Inhibition.class) { - return new Inhibition(this); - } else { - throw new NotImplementedException("Method copy() should be overriden in class " + this.getClass()); - } - } + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * Default constructor. + */ + public Inhibition() { + super(); + } + + /** + * Constructor that creates inhibition modifier for given element. + * + * @param element + * element object to which this modifier is assigned + */ + public Inhibition(Element element) { + super(element); + } + + /** + * Constructor that creates object with data taken from parameter inhibition. + * + * @param inhibition + * object from which data are initialized + */ + public Inhibition(Inhibition inhibition) { + super(inhibition); + } + + @Override + public Inhibition copy() { + if (this.getClass() == Inhibition.class) { + return new Inhibition(this); + } else { + throw new NotImplementedException("Method copy() should be overriden in class " + this.getClass()); + } + } } diff --git a/model/src/main/java/lcsb/mapviewer/model/map/modifier/Modulation.java b/model/src/main/java/lcsb/mapviewer/model/map/modifier/Modulation.java index b909f91c2a..6b29c11ffb 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/modifier/Modulation.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/modifier/Modulation.java @@ -6,7 +6,6 @@ import javax.persistence.Entity; import lcsb.mapviewer.common.exception.NotImplementedException; import lcsb.mapviewer.model.map.reaction.Modifier; import lcsb.mapviewer.model.map.species.Element; -import lcsb.mapviewer.model.map.species.Species; /** * This class defines modulation modifier in the reaction. @@ -18,45 +17,45 @@ import lcsb.mapviewer.model.map.species.Species; @DiscriminatorValue("MODULATION_MODIFIER") public class Modulation extends Modifier { - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * Default constructor. - */ - public Modulation() { - super(); - } - - /** - * Constructor that creates modulation modifier for given element. - * - * @param element - * element object to which this modifier is assigned - */ - public Modulation(Element element) { - super(element); - } - - /** - * Constructor that creates object with data taken from parameter modulation. - * - * @param modulation - * object from which data are initialized - */ - public Modulation(Modulation modulation) { - super(modulation); - } - - @Override - public Modulation copy() { - if (this.getClass() == Modulation.class) { - return new Modulation(this); - } else { - throw new NotImplementedException("Method copy() should be overriden in class " + this.getClass()); - } - } + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * Default constructor. + */ + public Modulation() { + super(); + } + + /** + * Constructor that creates modulation modifier for given element. + * + * @param element + * element object to which this modifier is assigned + */ + public Modulation(Element element) { + super(element); + } + + /** + * Constructor that creates object with data taken from parameter modulation. + * + * @param modulation + * object from which data are initialized + */ + public Modulation(Modulation modulation) { + super(modulation); + } + + @Override + public Modulation copy() { + if (this.getClass() == Modulation.class) { + return new Modulation(this); + } else { + throw new NotImplementedException("Method copy() should be overriden in class " + this.getClass()); + } + } } diff --git a/model/src/main/java/lcsb/mapviewer/model/map/modifier/PhysicalStimulation.java b/model/src/main/java/lcsb/mapviewer/model/map/modifier/PhysicalStimulation.java index 40114e8b15..f7e40ddc45 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/modifier/PhysicalStimulation.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/modifier/PhysicalStimulation.java @@ -6,7 +6,6 @@ import javax.persistence.Entity; import lcsb.mapviewer.common.exception.NotImplementedException; import lcsb.mapviewer.model.map.reaction.Modifier; import lcsb.mapviewer.model.map.species.Element; -import lcsb.mapviewer.model.map.species.Species; /** * This class defines physical stimulation modifier in the reaction. @@ -18,46 +17,46 @@ import lcsb.mapviewer.model.map.species.Species; @DiscriminatorValue("PHYSICAL_STIMULATION_MODIFIER") public class PhysicalStimulation extends Modifier { - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * Default constructor. - */ - public PhysicalStimulation() { - super(); - } - - /** - * Constructor that creates physical stimulation modifier for given element. - * - * @param element - * element object to which this modifier is assigned - */ - public PhysicalStimulation(Element element) { - super(element); - } - - /** - * Constructor that creates object with data taken from parameter physical - * stimulation. - * - * @param physicalStimulation - * object from which data are initialized - */ - public PhysicalStimulation(PhysicalStimulation physicalStimulation) { - super(physicalStimulation); - } - - @Override - public PhysicalStimulation copy() { - if (this.getClass() == PhysicalStimulation.class) { - return new PhysicalStimulation(this); - } else { - throw new NotImplementedException("Method copy() should be overriden in class " + this.getClass()); - } - } + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * Default constructor. + */ + public PhysicalStimulation() { + super(); + } + + /** + * Constructor that creates physical stimulation modifier for given element. + * + * @param element + * element object to which this modifier is assigned + */ + public PhysicalStimulation(Element element) { + super(element); + } + + /** + * Constructor that creates object with data taken from parameter physical + * stimulation. + * + * @param physicalStimulation + * object from which data are initialized + */ + public PhysicalStimulation(PhysicalStimulation physicalStimulation) { + super(physicalStimulation); + } + + @Override + public PhysicalStimulation copy() { + if (this.getClass() == PhysicalStimulation.class) { + return new PhysicalStimulation(this); + } else { + throw new NotImplementedException("Method copy() should be overriden in class " + this.getClass()); + } + } } diff --git a/model/src/main/java/lcsb/mapviewer/model/map/modifier/Trigger.java b/model/src/main/java/lcsb/mapviewer/model/map/modifier/Trigger.java index 99baa3f051..66f653d6d5 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/modifier/Trigger.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/modifier/Trigger.java @@ -6,7 +6,6 @@ import javax.persistence.Entity; import lcsb.mapviewer.common.exception.NotImplementedException; import lcsb.mapviewer.model.map.reaction.Modifier; import lcsb.mapviewer.model.map.species.Element; -import lcsb.mapviewer.model.map.species.Species; /** * This class defines trigger modifier in the reaction. @@ -18,45 +17,45 @@ import lcsb.mapviewer.model.map.species.Species; @DiscriminatorValue("TRIGGER_MODIFIER") public class Trigger extends Modifier { - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * Default constructor. - */ - public Trigger() { - super(); - } - - /** - * Constructor that creates trigger modifier for given element. - * - * @param element - * element object to which this modifier is assigned - */ - public Trigger(Element element) { - super(element); - } - - /** - * Constructor that creates object with data taken from parameter trigger. - * - * @param trigger - * object from which data are initialized - */ - public Trigger(Trigger trigger) { - super(trigger); - } - - @Override - public Trigger copy() { - if (this.getClass() == Trigger.class) { - return new Trigger(this); - } else { - throw new NotImplementedException("Method copy() should be overriden in class " + this.getClass()); - } - } + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * Default constructor. + */ + public Trigger() { + super(); + } + + /** + * Constructor that creates trigger modifier for given element. + * + * @param element + * element object to which this modifier is assigned + */ + public Trigger(Element element) { + super(element); + } + + /** + * Constructor that creates object with data taken from parameter trigger. + * + * @param trigger + * object from which data are initialized + */ + public Trigger(Trigger trigger) { + super(trigger); + } + + @Override + public Trigger copy() { + if (this.getClass() == Trigger.class) { + return new Trigger(this); + } else { + throw new NotImplementedException("Method copy() should be overriden in class " + this.getClass()); + } + } } diff --git a/model/src/main/java/lcsb/mapviewer/model/map/modifier/UnknownCatalysis.java b/model/src/main/java/lcsb/mapviewer/model/map/modifier/UnknownCatalysis.java index 6fd3092453..fd299cb378 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/modifier/UnknownCatalysis.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/modifier/UnknownCatalysis.java @@ -6,7 +6,6 @@ import javax.persistence.Entity; import lcsb.mapviewer.common.exception.NotImplementedException; import lcsb.mapviewer.model.map.reaction.Modifier; import lcsb.mapviewer.model.map.species.Element; -import lcsb.mapviewer.model.map.species.Species; /** * This class defines unknown catalysis modifier in the reaction. @@ -18,46 +17,46 @@ import lcsb.mapviewer.model.map.species.Species; @DiscriminatorValue("UNKNOWN_CATALYSIS_MODIFIER") public class UnknownCatalysis extends Modifier { - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * Default constructor. - */ - public UnknownCatalysis() { - super(); - } - - /** - * Constructor that creates unknown catalysis modifier for given element. - * - * @param element - * element object to which this modifier is assigned - */ - public UnknownCatalysis(Element element) { - super(element); - } - - /** - * Constructor that creates object with data taken from parameter unknown - * catalysis. - * - * @param unknownCatalysis - * object from which data are initialized - */ - public UnknownCatalysis(UnknownCatalysis unknownCatalysis) { - super(unknownCatalysis); - } - - @Override - public UnknownCatalysis copy() { - if (this.getClass() == UnknownCatalysis.class) { - return new UnknownCatalysis(this); - } else { - throw new NotImplementedException("Method copy() should be overriden in class " + this.getClass()); - } - } + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * Default constructor. + */ + public UnknownCatalysis() { + super(); + } + + /** + * Constructor that creates unknown catalysis modifier for given element. + * + * @param element + * element object to which this modifier is assigned + */ + public UnknownCatalysis(Element element) { + super(element); + } + + /** + * Constructor that creates object with data taken from parameter unknown + * catalysis. + * + * @param unknownCatalysis + * object from which data are initialized + */ + public UnknownCatalysis(UnknownCatalysis unknownCatalysis) { + super(unknownCatalysis); + } + + @Override + public UnknownCatalysis copy() { + if (this.getClass() == UnknownCatalysis.class) { + return new UnknownCatalysis(this); + } else { + throw new NotImplementedException("Method copy() should be overriden in class " + this.getClass()); + } + } } diff --git a/model/src/main/java/lcsb/mapviewer/model/map/modifier/UnknownInhibition.java b/model/src/main/java/lcsb/mapviewer/model/map/modifier/UnknownInhibition.java index 05c76708f7..65d97ab656 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/modifier/UnknownInhibition.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/modifier/UnknownInhibition.java @@ -6,7 +6,6 @@ import javax.persistence.Entity; import lcsb.mapviewer.common.exception.NotImplementedException; import lcsb.mapviewer.model.map.reaction.Modifier; import lcsb.mapviewer.model.map.species.Element; -import lcsb.mapviewer.model.map.species.Species; /** * This class defines unknown inhibition modifier in the reaction. @@ -18,47 +17,46 @@ import lcsb.mapviewer.model.map.species.Species; @DiscriminatorValue("UNKNOWN_INHIBITION_MODIFIER") public class UnknownInhibition extends Modifier { - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * Default constructor. - */ - public UnknownInhibition() { - super(); - } - - /** - * Constructor that creates unknown inhibition modifier for given and - * element. - * - * @param element - * element object to which this modifier is assigned - */ - public UnknownInhibition(Element element) { - super(element); - } - - /** - * Constructor that creates object with data taken from parameter unknown - * inhibition. - * - * @param unknownInhibition - * object from which data are initialized - */ - public UnknownInhibition(UnknownInhibition unknownInhibition) { - super(unknownInhibition); - } - - @Override - public UnknownInhibition copy() { - if (this.getClass() == UnknownInhibition.class) { - return new UnknownInhibition(this); - } else { - throw new NotImplementedException("Method copy() should be overriden in class " + this.getClass()); - } - } + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * Default constructor. + */ + public UnknownInhibition() { + super(); + } + + /** + * Constructor that creates unknown inhibition modifier for given and element. + * + * @param element + * element object to which this modifier is assigned + */ + public UnknownInhibition(Element element) { + super(element); + } + + /** + * Constructor that creates object with data taken from parameter unknown + * inhibition. + * + * @param unknownInhibition + * object from which data are initialized + */ + public UnknownInhibition(UnknownInhibition unknownInhibition) { + super(unknownInhibition); + } + + @Override + public UnknownInhibition copy() { + if (this.getClass() == UnknownInhibition.class) { + return new UnknownInhibition(this); + } else { + throw new NotImplementedException("Method copy() should be overriden in class " + this.getClass()); + } + } } diff --git a/model/src/main/java/lcsb/mapviewer/model/map/reaction/AbstractNodeComparator.java b/model/src/main/java/lcsb/mapviewer/model/map/reaction/AbstractNodeComparator.java index 693855bee6..b68812bfd9 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/reaction/AbstractNodeComparator.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/reaction/AbstractNodeComparator.java @@ -1,13 +1,11 @@ package lcsb.mapviewer.model.map.reaction; -import lcsb.mapviewer.common.Comparator; +import org.apache.log4j.Logger; +import lcsb.mapviewer.common.Comparator; import lcsb.mapviewer.common.Configuration; -import lcsb.mapviewer.common.exception.InvalidClassException; import lcsb.mapviewer.model.graphics.PolylineDataComparator; -import org.apache.log4j.Logger; - /** * This class implements comparator interface for AbstractNode. It also handles * comparison of subclasses of AbstractNode class. diff --git a/model/src/main/java/lcsb/mapviewer/model/map/species/ElementComparator.java b/model/src/main/java/lcsb/mapviewer/model/map/species/ElementComparator.java index 098c7d1f67..7a985fc597 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/species/ElementComparator.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/species/ElementComparator.java @@ -9,7 +9,6 @@ import lcsb.mapviewer.common.Comparator; import lcsb.mapviewer.common.Configuration; import lcsb.mapviewer.common.comparator.ColorComparator; import lcsb.mapviewer.common.comparator.DoubleComparator; -import lcsb.mapviewer.common.comparator.IntegerComparator; import lcsb.mapviewer.common.comparator.StringComparator; import lcsb.mapviewer.common.comparator.StringListComparator; import lcsb.mapviewer.common.comparator.StringSetComparator; diff --git a/model/src/main/java/lcsb/mapviewer/model/map/species/field/Structure.java b/model/src/main/java/lcsb/mapviewer/model/map/species/field/Structure.java index 5d92fdcce2..97f37f09a2 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/species/field/Structure.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/species/field/Structure.java @@ -1,8 +1,8 @@ package lcsb.mapviewer.model.map.species.field; import java.io.Serializable; -import java.util.Map; import java.util.HashMap; +import java.util.Map; import javax.persistence.Column; import javax.persistence.Entity; @@ -14,350 +14,359 @@ import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; -import org.apache.commons.collections.map.HashedMap; - import lcsb.mapviewer.common.exception.NotImplementedException; /** - * This class stores structure information as obtained from the SIFTS API - * (https://www.ebi.ac.uk/pdbe/api/doc/sifts.html best_structures), which provides - * the following fields - * pdb_id: the PDB ID which maps to the UniProt ID - * chain_id: the specific chain of the PDB which maps to the UniProt ID - * coverage: the percent coverage of the entire UniProt sequence - * resolution: the resolution of the structure - * start: the structure residue number which maps to the start of the mapped sequence - * unp_start: the sequence residue number which maps to the structure start - * end: the structure residue number which maps to the end of the mapped sequence - * unp_end: the sequence residue number which maps to the structure end - * experimental_method: type of experiment used to determine structure - * tax_id: taxonomic ID of the protein's original organism + * This class stores structure information as obtained from the SIFTS API + * (https://www.ebi.ac.uk/pdbe/api/doc/sifts.html best_structures), which + * provides the following fields pdb_id: the PDB ID which maps to the UniProt ID + * chain_id: the specific chain of the PDB which maps to the UniProt ID + * coverage: the percent coverage of the entire UniProt sequence resolution: the + * resolution of the structure start: the structure residue number which maps to + * the start of the mapped sequence unp_start: the sequence residue number which + * maps to the structure start end: the structure residue number which maps to + * the end of the mapped sequence unp_end: the sequence residue number which + * maps to the structure end experimental_method: type of experiment used to + * determine structure tax_id: taxonomic ID of the protein's original organism * * @author David Hoksza * */ @Entity @Table(name = "structure_table") -//@org.hibernate.annotations.GenericGenerator(name = "test-increment-strategy", strategy = "increment") +// @org.hibernate.annotations.GenericGenerator(name = "test-increment-strategy", +// strategy = "increment") public class Structure implements Serializable { - - /** - * - */ - private static final long serialVersionUID = 1L; - - - /** - * Unique identifier in the database. - */ - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "iddb", unique = true, nullable = false) - private int id; - - /** - * Uniprot record to which this structure belongs to. - */ - @ManyToOne(fetch = FetchType.EAGER) - @JoinColumn(name = "uniprot_id", nullable = false) - private UniprotRecord uniprot; - - /** - * the PDB ID which maps to the UniProt ID - */ - @Column(name = "pdb_id") - private String pdbId = null; - - /** - * the specific chain of the PDB which maps to the UniProt ID - */ - @Column(name = "chain_id") - private String chainId = null; - - /** - * the percent coverage of the entire UniProt sequence - */ - @Column(name = "coverage") - private Double coverage = null; - - /** - * the resolution of the structure - */ - @Column(name = "resolution") - private Double resolution = null; - - /** - * the structure residue number which maps to the start of the mapped sequence - */ - @Column(name = "struct_start") - private Integer structStart = null; - - /** - * the structure residue number which maps to the end of the mapped sequence - */ - @Column(name = "struct_end") - private Integer structEnd = null; - - /** - * the sequence residue number which maps to the structure start - */ - @Column(name = "unp_start") - private Integer unpStart = null; - - /** - * the sequence residue number which maps to the structure end - */ - @Column(name = "unp_end") - private Integer unpEnd = null; - - /** - * type of experiment used to determine structure - */ - @Column(name = "experimental_method") - private String experimentalMethod = null; - - /** - * taxonomic ID of the protein's original organism - */ - @Column(name = "tax_id") - private Integer taxId = null; - - /** - * Default constructor. - */ - public Structure() { - } - - /** - * Constructor that initialize object with the data taken from the parameter. - * - * @param s - * original object from which data is taken - */ - public Structure(Structure s) { - this.id = s.id; - this.uniprot = s.uniprot; - this.pdbId = s.pdbId; - this.chainId = s.chainId; - this.coverage = s.coverage; - this.resolution = s.resolution; - this.structStart = s.structStart; - this.structEnd = s.structEnd; - this.unpStart = s.unpStart; - this.unpEnd = s.unpEnd; - this.experimentalMethod = s.experimentalMethod; - this.taxId = s.taxId; - } - - /** - * Creates copy of the object. - * - * @return copy of the object. - */ - public Structure copy() { - if (this.getClass() == Structure.class) { - return new Structure(this); - } else { - throw new NotImplementedException("Method copy() should be overriden in class " + this.getClass()); - } - } - - /** - * @return the idModificationResidue - * @see #id - */ - public int getId() { - return id; - } - - /** - * @param id - * the id to set - * @see #id - */ - public void setId(int id) { - this.id = id; - } - - /** - * @return the uniprot - */ - public UniprotRecord getUniprot() { - return uniprot; - } - - /** - * @param uniprot the uniprot to set - */ - public void setUniprot(UniprotRecord uniprot) { - this.uniprot = uniprot; - } - - /** - * @return the pdbId - */ - public String getPdbId() { - return pdbId; - } - - /** - * @param pdbId the pdbId to set - */ - public void setPdbId(String pdbId) { - this.pdbId = pdbId; - } - - /** - * @return the chainId - */ - public String getChainId() { - return chainId; - } - - /** - * @param chainId the chainId to set - */ - public void setChainId(String chainId) { - this.chainId = chainId; - } - - /** - * @return the coverage - */ - public Double getCoverage() { - return coverage; - } - - /** - * @param coverage the coverage to set - */ - public void setCoverage(Double coverage) { - this.coverage = coverage; - } - - /** - * @return the resolution - */ - public Double getResolution() { - return resolution; - } - - /** - * @param resolution the resolution to set - */ - public void setResolution(Double resolution) { - this.resolution = resolution; - } - - /** - * @return the structStart - */ - public Integer getStructStart() { - return structStart; - } - - /** - * @param structStart the structStart to set - */ - public void setStructStart(Integer structStart) { - this.structStart = structStart; - } - - /** - * @return the structEnd - */ - public Integer getStructEnd() { - return structEnd; - } - - /** - * @param structEnd the structEnd to set - */ - public void setStructEnd(Integer structEnd) { - this.structEnd = structEnd; - } - - /** - * @return the unpStart - */ - public Integer getUnpStart() { - return unpStart; - } - - /** - * @param unpStart the unpStart to set - */ - public void setUnpStart(Integer unpStart) { - this.unpStart = unpStart; - } - - /** - * @return the unpEnd - */ - public Integer getUnpEnd() { - return unpEnd; - } - - /** - * @param unpEnd the unpEnd to set - */ - public void setUnpEnd(Integer unpEnd) { - this.unpEnd = unpEnd; - } - - /** - * @return the experimentalMethod - */ - public String getExperimentalMethod() { - return experimentalMethod; - } - - /** - * @param experimentalMethod the experimentalMethod to set - */ - public void setExperimentalMethod(String experimentalMethod) { - this.experimentalMethod = experimentalMethod; - } - - /** - * @return the taxId - */ - public Integer getTaxId() { - return taxId; - } - - /** - * @param taxId the taxId to set - */ - public void setTaxId(Integer taxId) { - this.taxId = taxId; - } - - /* (non-Javadoc) - * @see java.lang.Object#toString() - */ - @Override - public String toString() { - return "Structure [pdbId=" + pdbId + ", chainId=" + chainId + ", coverage=" + coverage + ", resolution=" - + resolution + ", structStart=" + structStart + ", structEnd=" + structEnd + ", unpStart=" + unpStart - + ", unpEnd=" + unpEnd + ", experimentalMethod=" + experimentalMethod + ", taxId=" + taxId + "]"; - } - - public Map<String, Object> toMap() { - Map<String, Object> result = new HashMap<>(); - - result.put("pdbId", this.pdbId); - result.put("chainId", this.chainId); - result.put("coverage", this.coverage); - result.put("resolution", this.resolution); - result.put("structStart", this.structStart); - result.put("structEnd", this.structEnd); - result.put("unpStart", this.unpStart); - result.put("unpEnd", this.unpEnd); - result.put("experimentalMethod", this.experimentalMethod); - result.put("taxId", this.taxId); - - return result; - } + + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * Unique identifier in the database. + */ + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "iddb", unique = true, nullable = false) + private int id; + + /** + * Uniprot record to which this structure belongs to. + */ + @ManyToOne(fetch = FetchType.EAGER) + @JoinColumn(name = "uniprot_id", nullable = false) + private UniprotRecord uniprot; + + /** + * the PDB ID which maps to the UniProt ID + */ + @Column(name = "pdb_id") + private String pdbId = null; + + /** + * the specific chain of the PDB which maps to the UniProt ID + */ + @Column(name = "chain_id") + private String chainId = null; + + /** + * the percent coverage of the entire UniProt sequence + */ + @Column(name = "coverage") + private Double coverage = null; + + /** + * the resolution of the structure + */ + @Column(name = "resolution") + private Double resolution = null; + + /** + * the structure residue number which maps to the start of the mapped sequence + */ + @Column(name = "struct_start") + private Integer structStart = null; + + /** + * the structure residue number which maps to the end of the mapped sequence + */ + @Column(name = "struct_end") + private Integer structEnd = null; + + /** + * the sequence residue number which maps to the structure start + */ + @Column(name = "unp_start") + private Integer unpStart = null; + + /** + * the sequence residue number which maps to the structure end + */ + @Column(name = "unp_end") + private Integer unpEnd = null; + + /** + * type of experiment used to determine structure + */ + @Column(name = "experimental_method") + private String experimentalMethod = null; + + /** + * taxonomic ID of the protein's original organism + */ + @Column(name = "tax_id") + private Integer taxId = null; + + /** + * Default constructor. + */ + public Structure() { + } + + /** + * Constructor that initialize object with the data taken from the parameter. + * + * @param s + * original object from which data is taken + */ + public Structure(Structure s) { + this.id = s.id; + this.uniprot = s.uniprot; + this.pdbId = s.pdbId; + this.chainId = s.chainId; + this.coverage = s.coverage; + this.resolution = s.resolution; + this.structStart = s.structStart; + this.structEnd = s.structEnd; + this.unpStart = s.unpStart; + this.unpEnd = s.unpEnd; + this.experimentalMethod = s.experimentalMethod; + this.taxId = s.taxId; + } + + /** + * Creates copy of the object. + * + * @return copy of the object. + */ + public Structure copy() { + if (this.getClass() == Structure.class) { + return new Structure(this); + } else { + throw new NotImplementedException("Method copy() should be overriden in class " + this.getClass()); + } + } + + /** + * @return the idModificationResidue + * @see #id + */ + public int getId() { + return id; + } + + /** + * @param id + * the id to set + * @see #id + */ + public void setId(int id) { + this.id = id; + } + + /** + * @return the uniprot + */ + public UniprotRecord getUniprot() { + return uniprot; + } + + /** + * @param uniprot + * the uniprot to set + */ + public void setUniprot(UniprotRecord uniprot) { + this.uniprot = uniprot; + } + + /** + * @return the pdbId + */ + public String getPdbId() { + return pdbId; + } + + /** + * @param pdbId + * the pdbId to set + */ + public void setPdbId(String pdbId) { + this.pdbId = pdbId; + } + + /** + * @return the chainId + */ + public String getChainId() { + return chainId; + } + + /** + * @param chainId + * the chainId to set + */ + public void setChainId(String chainId) { + this.chainId = chainId; + } + + /** + * @return the coverage + */ + public Double getCoverage() { + return coverage; + } + + /** + * @param coverage + * the coverage to set + */ + public void setCoverage(Double coverage) { + this.coverage = coverage; + } + + /** + * @return the resolution + */ + public Double getResolution() { + return resolution; + } + + /** + * @param resolution + * the resolution to set + */ + public void setResolution(Double resolution) { + this.resolution = resolution; + } + + /** + * @return the structStart + */ + public Integer getStructStart() { + return structStart; + } + + /** + * @param structStart + * the structStart to set + */ + public void setStructStart(Integer structStart) { + this.structStart = structStart; + } + + /** + * @return the structEnd + */ + public Integer getStructEnd() { + return structEnd; + } + + /** + * @param structEnd + * the structEnd to set + */ + public void setStructEnd(Integer structEnd) { + this.structEnd = structEnd; + } + + /** + * @return the unpStart + */ + public Integer getUnpStart() { + return unpStart; + } + + /** + * @param unpStart + * the unpStart to set + */ + public void setUnpStart(Integer unpStart) { + this.unpStart = unpStart; + } + + /** + * @return the unpEnd + */ + public Integer getUnpEnd() { + return unpEnd; + } + + /** + * @param unpEnd + * the unpEnd to set + */ + public void setUnpEnd(Integer unpEnd) { + this.unpEnd = unpEnd; + } + + /** + * @return the experimentalMethod + */ + public String getExperimentalMethod() { + return experimentalMethod; + } + + /** + * @param experimentalMethod + * the experimentalMethod to set + */ + public void setExperimentalMethod(String experimentalMethod) { + this.experimentalMethod = experimentalMethod; + } + + /** + * @return the taxId + */ + public Integer getTaxId() { + return taxId; + } + + /** + * @param taxId + * the taxId to set + */ + public void setTaxId(Integer taxId) { + this.taxId = taxId; + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return "Structure [pdbId=" + pdbId + ", chainId=" + chainId + ", coverage=" + coverage + ", resolution=" + + resolution + ", structStart=" + structStart + ", structEnd=" + structEnd + ", unpStart=" + unpStart + + ", unpEnd=" + unpEnd + ", experimentalMethod=" + experimentalMethod + ", taxId=" + taxId + "]"; + } + + public Map<String, Object> toMap() { + Map<String, Object> result = new HashMap<>(); + + result.put("pdbId", this.pdbId); + result.put("chainId", this.chainId); + result.put("coverage", this.coverage); + result.put("resolution", this.resolution); + result.put("structStart", this.structStart); + result.put("structEnd", this.structEnd); + result.put("unpStart", this.unpStart); + result.put("unpEnd", this.unpEnd); + result.put("experimentalMethod", this.experimentalMethod); + result.put("taxId", this.taxId); + + return result; + } } diff --git a/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/ComplexAndEntityWithAccessionedSequenceComparator.java b/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/ComplexAndEntityWithAccessionedSequenceComparator.java index 63c7a06813..5eb802095f 100644 --- a/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/ComplexAndEntityWithAccessionedSequenceComparator.java +++ b/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/ComplexAndEntityWithAccessionedSequenceComparator.java @@ -5,6 +5,7 @@ import java.util.Set; import lcsb.mapviewer.common.exception.InvalidArgumentException; import lcsb.mapviewer.model.map.MiriamData; +import lcsb.mapviewer.model.map.MiriamType; import lcsb.mapviewer.model.map.species.Complex; import lcsb.mapviewer.reactome.model.ReactomeEntityWithAccessionedSequence; import lcsb.mapviewer.reactome.model.ReactomeReferenceEntity; @@ -19,40 +20,42 @@ import lcsb.mapviewer.reactome.utils.ComparatorException; * @author Piotr Gawron * */ -public class ComplexAndEntityWithAccessionedSequenceComparator extends ANodeComparator<Complex, ReactomeEntityWithAccessionedSequence> { +public class ComplexAndEntityWithAccessionedSequenceComparator + extends ANodeComparator<Complex, ReactomeEntityWithAccessionedSequence> { - /** - * Default constructor. - */ - public ComplexAndEntityWithAccessionedSequenceComparator() { - super(Complex.class, ReactomeEntityWithAccessionedSequence.class); - } + /** + * Default constructor. + */ + public ComplexAndEntityWithAccessionedSequenceComparator() { + super(Complex.class, ReactomeEntityWithAccessionedSequence.class); + } - @Override - public boolean compareNodes(Complex complex, ReactomeEntityWithAccessionedSequence entity) throws ComparatorException { - Set<MiriamData> complex1Ids; - try { - complex1Ids = getRcu().getIdsForComplex(complex); - } catch (Exception e) { - throw new ComparatorException(e); - } - Set<String> uniprotIds2 = new HashSet<String>(); + @Override + public boolean compareNodes(Complex complex, ReactomeEntityWithAccessionedSequence entity) + throws ComparatorException { + Set<MiriamData> complex1Ids; + try { + complex1Ids = getRcu().getIdsForComplex(complex); + } catch (Exception e) { + throw new ComparatorException(e); + } + Set<String> uniprotIds2 = new HashSet<String>(); - ReactomeReferenceEntity reference = entity.getReferenceEntity(); - if (reference instanceof ReactomeReferenceGeneProduct) { - uniprotIds2.add(reference.getIdentifier()); - } else { - throw new InvalidArgumentException("Unknown class type (" + reference.getClass() + "). Don't know what to do"); - } - if (complex1Ids.size() != uniprotIds2.size()) { - return false; - } - for (String string : uniprotIds2) { - if (!complex1Ids.contains(string)) { - return false; - } - } - return true; - } + ReactomeReferenceEntity reference = entity.getReferenceEntity(); + if (reference instanceof ReactomeReferenceGeneProduct) { + uniprotIds2.add(reference.getIdentifier()); + } else { + throw new InvalidArgumentException("Unknown class type (" + reference.getClass() + "). Don't know what to do"); + } + if (complex1Ids.size() != uniprotIds2.size()) { + return false; + } + for (String string : uniprotIds2) { + if (!complex1Ids.contains(new MiriamData(MiriamType.UNIPROT, string))) { + return false; + } + } + return true; + } } diff --git a/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/ComplexAndSimpleEntityComparator.java b/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/ComplexAndSimpleEntityComparator.java index dd7761548c..d1ef82927a 100644 --- a/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/ComplexAndSimpleEntityComparator.java +++ b/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/ComplexAndSimpleEntityComparator.java @@ -21,43 +21,43 @@ import lcsb.mapviewer.reactome.utils.ComparatorException; */ public class ComplexAndSimpleEntityComparator extends ANodeComparator<Complex, ReactomeSimpleEntity> { - /** - * Default constructor. - */ - public ComplexAndSimpleEntityComparator() { - super(Complex.class, ReactomeSimpleEntity.class); - } - - @Override - public boolean compareNodes(Complex complex, ReactomeSimpleEntity simpleEntity) throws ComparatorException { - Set<MiriamData> complex1Ids; - try { - complex1Ids = getRcu().getIdsForComplex(complex); - } catch (Exception e) { - throw new ComparatorException(e); - } - - Set<MiriamData> entityIds2 = new HashSet<MiriamData>(); - - for (ReactomeReferenceEntity reference : simpleEntity.getReferenceEntities()) { - if (reference instanceof ReactomeReferenceMolecule) { - boolean isChebi = false; - if (reference.getReferenceDatabase() != null) { - for (String name : reference.getReferenceDatabase().getNames()) { - if (name.equalsIgnoreCase("ChEBI")) { - isChebi = true; - } - } - } - if (isChebi) { - String chebi = "CHEBI:" + reference.getIdentifier(); - if (complex1Ids.contains(chebi)) { - entityIds2.add(new MiriamData(MiriamRelationType.BQ_BIOL_IS_DESCRIBED_BY, MiriamType.CHEBI, chebi)); - } - } - } - } - return compareSets(complex1Ids, entityIds2); - } + /** + * Default constructor. + */ + public ComplexAndSimpleEntityComparator() { + super(Complex.class, ReactomeSimpleEntity.class); + } + + @Override + public boolean compareNodes(Complex complex, ReactomeSimpleEntity simpleEntity) throws ComparatorException { + Set<MiriamData> complex1Ids; + try { + complex1Ids = getRcu().getIdsForComplex(complex); + } catch (Exception e) { + throw new ComparatorException(e); + } + + Set<MiriamData> entityIds2 = new HashSet<MiriamData>(); + + for (ReactomeReferenceEntity reference : simpleEntity.getReferenceEntities()) { + if (reference instanceof ReactomeReferenceMolecule) { + boolean isChebi = false; + if (reference.getReferenceDatabase() != null) { + for (String name : reference.getReferenceDatabase().getNames()) { + if (name.equalsIgnoreCase("ChEBI")) { + isChebi = true; + } + } + } + if (isChebi) { + MiriamData chebi = new MiriamData(MiriamType.CHEBI, "CHEBI:" + reference.getIdentifier()); + if (complex1Ids.contains(chebi)) { + entityIds2.add(chebi); + } + } + } + } + return compareSets(complex1Ids, entityIds2); + } } diff --git a/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/IonAndComplexComparator.java b/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/IonAndComplexComparator.java index 2c3efb2541..051f549e9e 100644 --- a/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/IonAndComplexComparator.java +++ b/reactome/src/main/java/lcsb/mapviewer/reactome/utils/comparators/IonAndComplexComparator.java @@ -5,6 +5,7 @@ import java.util.List; import lcsb.mapviewer.annotation.services.annotators.ChebiSearchException; import lcsb.mapviewer.common.exception.InvalidArgumentException; import lcsb.mapviewer.model.map.MiriamData; +import lcsb.mapviewer.model.map.MiriamType; import lcsb.mapviewer.model.map.species.Ion; import lcsb.mapviewer.reactome.model.ReactomeComplex; import lcsb.mapviewer.reactome.model.ReactomeDefinedSet; @@ -16,75 +17,75 @@ import lcsb.mapviewer.reactome.model.ReactomeSimpleEntity; import lcsb.mapviewer.reactome.utils.ComparatorException; /** - * This class allows to compare {@link Ion} element (internal - * representation) and {@link ReactomeComplex} (reactome model). + * This class allows to compare {@link Ion} element (internal representation) + * and {@link ReactomeComplex} (reactome model). * * @author Piotr Gawron * */ public class IonAndComplexComparator extends ANodeComparator<Ion, ReactomeComplex> { - /** - * Default constructor. - */ - public IonAndComplexComparator() { - super(Ion.class, ReactomeComplex.class); - } + /** + * Default constructor. + */ + public IonAndComplexComparator() { + super(Ion.class, ReactomeComplex.class); + } - @Override - public boolean compareNodes(Ion species, ReactomeComplex entity) throws ComparatorException { - try { - List<MiriamData> chebi1 = getChebiBackend().getOntologyChebiIdsForChebiName(species.getName()); - String chebi2 = null; - if (chebi1.size() == 0) { // if we don't have id then return false (even - // with - // two null values we cannot claim that they are - // equal) - return false; - } - int matched = 0; - for (ReactomePhysicalEntity entity2 : entity.getHasComponents()) { - if (entity2 instanceof ReactomeSimpleEntity) { - for (ReactomeReferenceEntity reference : ((ReactomeSimpleEntity) entity2).getReferenceEntities()) { - if (reference instanceof ReactomeReferenceMolecule) { - boolean isChebi = false; - if (reference.getReferenceDatabase() != null) { - for (String name : reference.getReferenceDatabase().getNames()) { - if (name.equalsIgnoreCase("ChEBI")) { - isChebi = true; - } - } - } - if (isChebi) { - chebi2 = "CHEBI:" + reference.getIdentifier(); - if (chebi1.contains(chebi2)) { - matched++; - } // in other case we cannot claim that there are different - // (maybe - // there are more molecule references and other is going to - // point to correct chebi id) - } - } - } - } else if (entity2 instanceof ReactomeDefinedSet) { - if (getGlobalComparator().compareNodes(species, (ReactomeDefinedSet) entity2)) { - matched++; - } - } else if (entity2 instanceof ReactomeComplex) { - if (getGlobalComparator().compareNodes(species, (ReactomeComplex) entity2)) { - matched++; - } - } else if (entity2 instanceof ReactomeEntityWithAccessionedSequence) { - return false; - } else { - throw new InvalidArgumentException( - "Cannot determine the way of comparison for provided class types: " + species.getClass() + ", " + entity2.getClass()); - } - } - return matched == entity.getHasComponents().size(); - } catch (ChebiSearchException e) { - throw new ComparatorException(e); - } - } + @Override + public boolean compareNodes(Ion species, ReactomeComplex entity) throws ComparatorException { + try { + List<MiriamData> chebi1 = getChebiBackend().getOntologyChebiIdsForChebiName(species.getName()); + String chebi2 = null; + if (chebi1.size() == 0) { // if we don't have id then return false (even + // with + // two null values we cannot claim that they are + // equal) + return false; + } + int matched = 0; + for (ReactomePhysicalEntity entity2 : entity.getHasComponents()) { + if (entity2 instanceof ReactomeSimpleEntity) { + for (ReactomeReferenceEntity reference : ((ReactomeSimpleEntity) entity2).getReferenceEntities()) { + if (reference instanceof ReactomeReferenceMolecule) { + boolean isChebi = false; + if (reference.getReferenceDatabase() != null) { + for (String name : reference.getReferenceDatabase().getNames()) { + if (name.equalsIgnoreCase("ChEBI")) { + isChebi = true; + } + } + } + if (isChebi) { + chebi2 = "CHEBI:" + reference.getIdentifier(); + if (chebi1.contains(new MiriamData(MiriamType.CHEBI, chebi2))) { + matched++; + } // in other case we cannot claim that there are different + // (maybe + // there are more molecule references and other is going to + // point to correct chebi id) + } + } + } + } else if (entity2 instanceof ReactomeDefinedSet) { + if (getGlobalComparator().compareNodes(species, (ReactomeDefinedSet) entity2)) { + matched++; + } + } else if (entity2 instanceof ReactomeComplex) { + if (getGlobalComparator().compareNodes(species, (ReactomeComplex) entity2)) { + matched++; + } + } else if (entity2 instanceof ReactomeEntityWithAccessionedSequence) { + return false; + } else { + throw new InvalidArgumentException("Cannot determine the way of comparison for provided class types: " + + species.getClass() + ", " + entity2.getClass()); + } + } + return matched == entity.getHasComponents().size(); + } catch (ChebiSearchException e) { + throw new ComparatorException(e); + } + } } diff --git a/rest-api/src/main/java/lcsb/mapviewer/api/users/UserController.java b/rest-api/src/main/java/lcsb/mapviewer/api/users/UserController.java index 4312f60b41..33ee71a1b5 100644 --- a/rest-api/src/main/java/lcsb/mapviewer/api/users/UserController.java +++ b/rest-api/src/main/java/lcsb/mapviewer/api/users/UserController.java @@ -17,7 +17,6 @@ import org.springframework.security.authentication.UsernamePasswordAuthenticatio import org.springframework.security.core.Authentication; import org.springframework.security.core.AuthenticationException; import org.springframework.security.core.context.SecurityContextHolder; -import org.springframework.security.core.session.SessionRegistry; import org.springframework.security.web.authentication.WebAuthenticationDetails; import org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler; import org.springframework.util.MultiValueMap; diff --git a/rest-api/src/test/java/lcsb/mapviewer/api/projects/models/ModelRestImplTest.java b/rest-api/src/test/java/lcsb/mapviewer/api/projects/models/ModelRestImplTest.java index 0b7b40b3ab..7004816d7c 100644 --- a/rest-api/src/test/java/lcsb/mapviewer/api/projects/models/ModelRestImplTest.java +++ b/rest-api/src/test/java/lcsb/mapviewer/api/projects/models/ModelRestImplTest.java @@ -14,7 +14,6 @@ import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; import lcsb.mapviewer.api.RestTestFunctions; -import lcsb.mapviewer.common.exception.InvalidArgumentException; import lcsb.mapviewer.model.Project; import lcsb.mapviewer.model.map.model.Model; import lcsb.mapviewer.services.interfaces.IModelService; diff --git a/service/src/main/java/lcsb/mapviewer/services/interfaces/ISearchService.java b/service/src/main/java/lcsb/mapviewer/services/interfaces/ISearchService.java index 1229bba669..08d53f7a87 100644 --- a/service/src/main/java/lcsb/mapviewer/services/interfaces/ISearchService.java +++ b/service/src/main/java/lcsb/mapviewer/services/interfaces/ISearchService.java @@ -278,7 +278,7 @@ public interface ISearchService { * @param perfectMatch * should the match be perfect * @param ipAddress - * ip address of a client who is searchin (used for logging purpose) + * ip address of a client who is searching (used for logging purpose) * @return list of objects that matches the query sorted by the match quality */ SearchElementResult searchByQuery(Model model, String query, int limit, Boolean perfectMatch, String ipAddress); diff --git a/service/src/main/java/lcsb/mapviewer/services/utils/ColorSchemaReader.java b/service/src/main/java/lcsb/mapviewer/services/utils/ColorSchemaReader.java index 624927757a..7a4fd26597 100644 --- a/service/src/main/java/lcsb/mapviewer/services/utils/ColorSchemaReader.java +++ b/service/src/main/java/lcsb/mapviewer/services/utils/ColorSchemaReader.java @@ -457,7 +457,6 @@ public class ColorSchemaReader { */ protected Collection<ColorSchema> readGenericColorSchema(InputStream colorInputStream) throws IOException, InvalidColorSchemaException { - MiriamConnector mc = new MiriamConnector(); List<ColorSchema> result = new ArrayList<>(); BufferedReader br = new BufferedReader(new InputStreamReader(colorInputStream)); diff --git a/service/src/main/java/lcsb/mapviewer/services/view/AbstractTargetView.java b/service/src/main/java/lcsb/mapviewer/services/view/AbstractTargetView.java deleted file mode 100644 index 9e633bfd0b..0000000000 --- a/service/src/main/java/lcsb/mapviewer/services/view/AbstractTargetView.java +++ /dev/null @@ -1,136 +0,0 @@ -package lcsb.mapviewer.services.view; - -import java.io.Serializable; - -/** - * View representation. - * - * @author Ayan Rota - * - */ -public class AbstractTargetView implements Serializable { - - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * Icon associated with the target. - */ - private String icon; - - /** - * Type of the target. Possible values are set in - */ - private String type; - - /** - * Is the target selectable by client. - */ - private Boolean selectable = false; - - /** - * Is the target selected by client. - */ - private Boolean selected = false; - - /** - * Is the target visiblke to the client. - */ - private Boolean visible = false; - - /** - * defualt constructor. - */ - public AbstractTargetView() { - super(); - } - - - /** - * @return the icon - * @see #icon - */ - public String getIcon() { - return icon; - } - - /** - * @param icon - * the icon to set - * @see #icon - */ - public void setIcon(String icon) { - this.icon = icon; - } - - /** - * @return the selectable - * @see #selectable - */ - public Boolean getSelectable() { - return selectable; - } - - /** - * @param selectable - * the selectable to set - * @see #selectable - */ - public void setSelectable(Boolean selectable) { - this.selectable = selectable; - } - - /** - * @return the selected - * @see #selected - */ - public Boolean getSelected() { - return selected; - } - - /** - * @param selected - * the selected to set - * @see #selected - */ - public void setSelected(Boolean selected) { - this.selected = selected; - } - - /** - * @return the visible - * @see #visible - */ - public Boolean getVisible() { - return visible; - } - - /** - * @param visible - * the visible to set - * @see #visible - */ - public void setVisible(Boolean visible) { - this.visible = visible; - } - - /** - * @return the type - * @see #type - */ - public String getType() { - return type; - } - - /** - * @param type - * the type to set - * @see #type - */ - public void setType(String type) { - this.type = type; - } - -} diff --git a/service/src/test/java/lcsb/mapviewer/services/impl/LayoutServiceTest2.java b/service/src/test/java/lcsb/mapviewer/services/impl/LayoutServiceTest2.java index ef9c4ddf5b..850c869589 100644 --- a/service/src/test/java/lcsb/mapviewer/services/impl/LayoutServiceTest2.java +++ b/service/src/test/java/lcsb/mapviewer/services/impl/LayoutServiceTest2.java @@ -17,7 +17,6 @@ import org.junit.Test; import lcsb.mapviewer.commands.ColorExtractor; import lcsb.mapviewer.commands.ColorModelCommand; -import lcsb.mapviewer.common.Pair; import lcsb.mapviewer.common.TextFileUtils; import lcsb.mapviewer.converter.ConverterParams; import lcsb.mapviewer.converter.model.celldesigner.CellDesignerXmlParser; diff --git a/service/src/test/java/lcsb/mapviewer/services/utils/ColorSchemaReaderTest.java b/service/src/test/java/lcsb/mapviewer/services/utils/ColorSchemaReaderTest.java index 671877a0c7..dd0b10fab0 100644 --- a/service/src/test/java/lcsb/mapviewer/services/utils/ColorSchemaReaderTest.java +++ b/service/src/test/java/lcsb/mapviewer/services/utils/ColorSchemaReaderTest.java @@ -24,10 +24,8 @@ import org.junit.Test; import lcsb.mapviewer.commands.ColorExtractor; import lcsb.mapviewer.commands.ColorModelCommand; -import lcsb.mapviewer.common.Pair; import lcsb.mapviewer.common.TextFileUtils; import lcsb.mapviewer.model.map.MiriamData; -import lcsb.mapviewer.model.map.MiriamType; import lcsb.mapviewer.model.map.layout.ColorSchema; import lcsb.mapviewer.model.map.layout.InvalidColorSchemaException; import lcsb.mapviewer.model.map.model.Model; @@ -323,7 +321,7 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions { Collection<ColorSchema> schemas = reader.readColorSchema("testFiles/coloring/schemaWithIdentifiers.txt"); for (ColorSchema colorSchema : schemas) { - for (MiriamData md: colorSchema.getMiriamData()) { + for (MiriamData md : colorSchema.getMiriamData()) { assertNotNull(md.getResource()); assertFalse(md.getResource().isEmpty()); } @@ -342,7 +340,7 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions { Collection<ColorSchema> schemas = reader.readColorSchema("testFiles/coloring/schemaIdWithoutName.txt"); for (ColorSchema colorSchema : schemas) { - for (MiriamData md: colorSchema.getMiriamData()) { + for (MiriamData md : colorSchema.getMiriamData()) { assertFalse(md.getResource().isEmpty()); assertNull(colorSchema.getName()); } diff --git a/web/src/main/java/lcsb/mapviewer/bean/utils/StartupBean.java b/web/src/main/java/lcsb/mapviewer/bean/utils/StartupBean.java index 20dad609ea..ba6523f3be 100644 --- a/web/src/main/java/lcsb/mapviewer/bean/utils/StartupBean.java +++ b/web/src/main/java/lcsb/mapviewer/bean/utils/StartupBean.java @@ -15,7 +15,6 @@ import lcsb.mapviewer.model.Project; import lcsb.mapviewer.model.ProjectStatus; import lcsb.mapviewer.model.map.layout.ReferenceGenome; import lcsb.mapviewer.model.user.ConfigurationElementType; -import lcsb.mapviewer.persist.dao.ProjectDao; import lcsb.mapviewer.services.interfaces.IConfigurationService; import lcsb.mapviewer.services.interfaces.IProjectService; import lcsb.mapviewer.services.interfaces.IReferenceGenomeService; diff --git a/web/src/main/java/lcsb/mapviewer/security/MvInvalidSessionStrategy.java b/web/src/main/java/lcsb/mapviewer/security/MvInvalidSessionStrategy.java index b457ecbfe3..baeb961e25 100644 --- a/web/src/main/java/lcsb/mapviewer/security/MvInvalidSessionStrategy.java +++ b/web/src/main/java/lcsb/mapviewer/security/MvInvalidSessionStrategy.java @@ -10,8 +10,6 @@ import org.apache.log4j.Logger; import org.springframework.security.web.session.InvalidSessionStrategy; import org.springframework.util.StringUtils; -import lcsb.mapviewer.common.Configuration; - /** * Implementation of the Spring invalidation startegy. Class used when user * session was invalidated (expired). @@ -21,88 +19,90 @@ import lcsb.mapviewer.common.Configuration; */ public class MvInvalidSessionStrategy implements InvalidSessionStrategy { - /** - * Default class logger. - */ - private static Logger logger = Logger.getLogger(MvInvalidSessionStrategy.class); + /** + * Default class logger. + */ + private static Logger logger = Logger.getLogger(MvInvalidSessionStrategy.class); - /** - * String identifier of the faces request header. - */ - private static final String FACES_REQUEST_HEADER = "faces-request"; + /** + * String identifier of the faces request header. + */ + private static final String FACES_REQUEST_HEADER = "faces-request"; - /** - * Default constructor. - * - * @param invalidSessionUrl - * url that should be used when session was invalidated - */ - public MvInvalidSessionStrategy(String invalidSessionUrl) { - logger.debug("Invalid session url (not used): " + invalidSessionUrl); - } + /** + * Default constructor. + * + * @param invalidSessionUrl + * url that should be used when session was invalidated + */ + public MvInvalidSessionStrategy(String invalidSessionUrl) { + logger.debug("Invalid session url (not used): " + invalidSessionUrl); + } - @Override - public void onInvalidSessionDetected(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { -// boolean ajaxRedirect = "partial/ajax".equals(request.getHeader(FACES_REQUEST_HEADER)); -// -// if (!response.isCommitted()) { -// if (ajaxRedirect) { -// // with expired ajax queries we have a problem.. We must refresh webpage -// // and create a new session, -// // we cannot redirect directly to the original page, because browser -// // won't reload it, -// // so the trick is to send javascript code that will reload browser -// String reloadString = createAjaxReloadPageXml(); -// logger.info("Session expired with Ajax request, reloadXml:" + reloadString); -// -// response.setContentType("text/xml"); -// response.getWriter().write(reloadString); -// -// } else { -// String requestURI; -// if (!Configuration.LOGIN_PAGE.endsWith(request.getServletPath())) { -// // we don't want to redirect, let's keep the last url -// requestURI = getRequestUrl(request); -// logger.info("Session expired without Ajax request:" + requestURI); -// } else { -// requestURI = getRequestUrl(request); -// logger.info("User forced logout" + requestURI); -// } -// -// logger.info("Staring new session"); -// request.getSession(true); -// response.sendRedirect(requestURI); -// } -// } -// return; - } + @Override + public void onInvalidSessionDetected(HttpServletRequest request, HttpServletResponse response) + throws IOException, ServletException { + // boolean ajaxRedirect = + // "partial/ajax".equals(request.getHeader(FACES_REQUEST_HEADER)); + // + // if (!response.isCommitted()) { + // if (ajaxRedirect) { + // // with expired ajax queries we have a problem.. We must refresh webpage + // // and create a new session, + // // we cannot redirect directly to the original page, because browser + // // won't reload it, + // // so the trick is to send javascript code that will reload browser + // String reloadString = createAjaxReloadPageXml(); + // logger.info("Session expired with Ajax request, reloadXml:" + reloadString); + // + // response.setContentType("text/xml"); + // response.getWriter().write(reloadString); + // + // } else { + // String requestURI; + // if (!Configuration.LOGIN_PAGE.endsWith(request.getServletPath())) { + // // we don't want to redirect, let's keep the last url + // requestURI = getRequestUrl(request); + // logger.info("Session expired without Ajax request:" + requestURI); + // } else { + // requestURI = getRequestUrl(request); + // logger.info("User forced logout" + requestURI); + // } + // + // logger.info("Staring new session"); + // request.getSession(true); + // response.sendRedirect(requestURI); + // } + // } + // return; + } - /** - * Returns request url. - * - * @param request - * request object - * @return request url - */ - private String getRequestUrl(HttpServletRequest request) { - StringBuffer requestURL = request.getRequestURL(); + /** + * Returns request url. + * + * @param request + * request object + * @return request url + */ + private String getRequestUrl(HttpServletRequest request) { + StringBuffer requestURL = request.getRequestURL(); - String queryString = request.getQueryString(); - if (StringUtils.hasText(queryString)) { - requestURL.append("?").append(queryString); - } + String queryString = request.getQueryString(); + if (StringUtils.hasText(queryString)) { + requestURL.append("?").append(queryString); + } - logger.info("Url: " + requestURL.toString()); - return requestURL.toString(); - } + logger.info("Url: " + requestURL.toString()); + return requestURL.toString(); + } - /** - * Creates ajax string that reload site in the client browser. - * - * @return ajax string that reload browser - */ - private String createAjaxReloadPageXml() { - return "<partial-response><changes><eval><![CDATA[location.reload(true);]]></eval></changes></partial-response>"; - } + /** + * Creates ajax string that reload site in the client browser. + * + * @return ajax string that reload browser + */ + private String createAjaxReloadPageXml() { + return "<partial-response><changes><eval><![CDATA[location.reload(true);]]></eval></changes></partial-response>"; + } } -- GitLab