Commit d47a3508 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

Merge branch 'bugs' into 'master'

Bug fixes

Issues solved:
#50, #31, #41, #46,  #38, #43, #48

See merge request !2
parents ba6e311f e5c8f78f
......@@ -6,3 +6,4 @@ map_images/
*/target/
web/src/main/webapp/svnversion.txt
*.war
/target/
minerva (10.0.3) stable; urgency=medium
* Bug fix: login cannot contain whitespace
* Bug fix: search for multiple drugs will not return more drugs than
queried for
* Bug fix: drug list for some proteins (like RHOA) hung webpage
* Bug fix: comments on submaps issue
* Bug fix: link to submap from comment panel
* Overlay coloring can be defined in Configuration
-- Piotr Gawron <piotr.gawron@uni.lu> Thu, 10 Oct 2016 10:01:16 +0200
minerva (10.0.2) stable; urgency=medium
* Bug fix: markers for mirna targets visibility
......
......@@ -68,7 +68,12 @@ public class ChEMBLParser extends DrugAnnotation implements IExternalService {
/**
* Url that list of all child nodes for chembl ontology term.
*/
private static final String PARENT_CHILD_API_URL = "https://www.ebi.ac.uk/chembl/api/data/molecule_form?parent=";
private static final String PARENT_CHILD_API_URL = "https://www.ebi.ac.uk/chembl/api/data/molecule_form/";
/**
* Suffix that should be added to {@link #PARENT_CHILD_API_URL}.
*/
private static final String PARENT_CHILD_API_URL_SUFFIX = ".xml";
/**
* Url used for finding targets containing uniprot identifiers. Important -
......@@ -420,7 +425,7 @@ public class ChEMBLParser extends DrugAnnotation implements IExternalService {
List<Target> targets = new ArrayList<>();
try {
String id = drugId.getResource();
String query = PARENT_CHILD_API_URL + id;
String query = PARENT_CHILD_API_URL + id + PARENT_CHILD_API_URL_SUFFIX;
String page = getWebPageContent(query);
Document document = super.getXmlDocumentFromString(page);
......
......@@ -54,7 +54,7 @@ public class PubmedParser extends CachableInterface implements IExternalService
/**
* Version of the remote API thnat is supported by this connecting class.
*/
static final String SUPPORTED_VERSION = "4.5.2";
static final String SUPPORTED_VERSION = "4.5.3";
/**
* Connector used for accessing data from miriam registry.
......
......@@ -18,7 +18,6 @@ import java.util.Set;
import org.apache.log4j.Logger;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -64,7 +63,7 @@ public class ChEMBLParserTest extends AnnotationTestFunctions {
@Test
public void test1FindDrug() throws Exception {
try {
//do it with cache turned on
// do it with cache turned on
chemblParser.setCache(cache);
Drug drug = chemblParser.findDrug("CABOZANTINIB");
......@@ -213,11 +212,11 @@ public class ChEMBLParserTest extends AnnotationTestFunctions {
@Test
public void test9FindDrug() throws Exception {
try {
String n = "PONATINIB";
Drug test = chemblParser.findDrug(n);
String name = "PONATINIB";
Drug test = chemblParser.findDrug(name);
assertEquals("CHEMBL1171837", test.getSources().get(0).getResource());
assertEquals("PONATINIB", test.getName());
assertEquals(name, test.getName());
assertNull(test.getDescription());
assertEquals(3, test.getTargets().size());
} catch (Exception e) {
......@@ -228,7 +227,6 @@ public class ChEMBLParserTest extends AnnotationTestFunctions {
}
@Test
@Ignore("Bug 452")
public void test10FindDrug() throws Exception {
try {
String n = "DEXAMETHASONE";
......
package lcsb.mapviewer.common.geometry;
import java.awt.Color;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
/**
* Parser clas to extract {@link Color} objects from {@link String}.
*
* @author Piotr Gawron
*
*/
public class ColorParser {
/**
* Base of the hex representation.
*/
private static final int HEX_BASE = 16;
/**
* Length of the string describing color in rgb: "#RRGGBB".
*/
private static final int COLOR_STRING_LENGTH = 7;
/**
* Where starts description of red color in stirng representing color.
*/
private static final int COLOR_SUBSTRING_START_RED = 1;
/**
* Where starts description of green color in stirng representing color.
*/
private static final int COLOR_SUBSTRING_START_GREEN = 3;
/**
* Where starts description of blue color in stirng representing color.
*/
private static final int COLOR_SUBSTRING_START_BLUE = 5;
/**
* Extracts {@link Color} from input {@link String}.
*
* @param string
* text to process
* @return {@link Color} obtained from input text
*/
public Color parse(String string) {
if (string.charAt(0) != '#') {
string = "#" + string;
}
if (string.length() != COLOR_STRING_LENGTH) {
throw new InvalidArgumentException("Invalid color value: " + string + ". Correct format: #xxxxxx (where x is a hex value)");
} else {
return new Color(Integer.valueOf(string.substring(COLOR_SUBSTRING_START_RED, COLOR_SUBSTRING_START_GREEN), HEX_BASE), //
Integer.valueOf(string.substring(COLOR_SUBSTRING_START_GREEN, COLOR_SUBSTRING_START_BLUE), HEX_BASE), //
Integer.valueOf(string.substring(COLOR_SUBSTRING_START_BLUE, COLOR_STRING_LENGTH), HEX_BASE));
}
}
}
package lcsb.mapviewer.common.geometry;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import java.awt.Color;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
public class ColorParserTest {
@AfterClass
public static void tearDownAfterClass() throws Exception {
}
@Before
public void setUp() throws Exception {
}
@After
public void tearDown() throws Exception {
}
@Test
public void testSetInvalidColor() throws Exception {
try {
ColorParser parser = new ColorParser();
parser.parse("qwe");
fail("Exception expected");
} catch (InvalidArgumentException e) {
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testSetInvalidColor2() throws Exception {
try {
ColorParser parser = new ColorParser();
parser.parse("fffffff");
fail("Exception expected");
} catch (InvalidArgumentException e) {
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testSetColor() throws Exception {
try {
ColorParser parser = new ColorParser();
Color color = parser.parse("#ffffff");
assertEquals(Color.WHITE, color);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
}
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>lcsb.mapviewer</groupId>
<artifactId>parent</artifactId>
<version>1.0</version>
</parent>
<artifactId>converter-graphics</artifactId>
<name>MapViewer graphics converter</name>
<description>Converter that allows to transform model into graphic representation</description>
<dependencies>
<!-- dependency from the MapViewer model -->
<dependency>
<groupId>lcsb.mapviewer</groupId>
<artifactId>model</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>lcsb.mapviewer</groupId>
<artifactId>model-command</artifactId>
<version>1.0</version>
</dependency>
<!-- Log4J -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
<!-- Library used for generating svg -->
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>batik-rasterizer</artifactId>
<version>${batik.version}</version>
</dependency>
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>batik-svggen</artifactId>
<version>${batik.version}</version>
</dependency>
<!-- iText library for generating pdf -->
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>${itext.version}</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>${itext.version}</version>
</dependency>
</dependencies>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>lcsb.mapviewer</groupId>
<artifactId>parent</artifactId>
<version>1.0</version>
</parent>
<artifactId>converter-graphics</artifactId>
<name>MapViewer graphics converter</name>
<description>Converter that allows to transform model into graphic representation</description>
<dependencies>
<!-- dependency from the MapViewer model -->
<dependency>
<groupId>lcsb.mapviewer</groupId>
<artifactId>model</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>lcsb.mapviewer</groupId>
<artifactId>model-command</artifactId>
<version>1.0</version>
</dependency>
<!-- Log4J -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
<!-- Library used for generating svg -->
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>batik-rasterizer</artifactId>
<version>${batik.version}</version>
</dependency>
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>batik-svggen</artifactId>
<version>${batik.version}</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<!-- iText library for generating pdf -->
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>${itext.version}</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>${itext.version}</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
......@@ -14,6 +14,7 @@ import java.util.Map;
import org.apache.log4j.Logger;
import lcsb.mapviewer.commands.ColorExtractor;
import lcsb.mapviewer.common.MimeType;
import lcsb.mapviewer.converter.graphics.layer.LayerConverter;
import lcsb.mapviewer.converter.graphics.reaction.ReactionConverter;
......@@ -26,6 +27,7 @@ import lcsb.mapviewer.model.map.reaction.Reaction;
import lcsb.mapviewer.model.map.species.Complex;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.model.map.species.Species;
import lcsb.mapviewer.modelutils.map.ElementUtils;
/**
* This class is responsible for creation of the image from the model. It's an
......@@ -93,6 +95,16 @@ public abstract class AbstractImageGenerator {
*/
private Rectangle2D.Double border = null;
/**
* Object that helps to convert {@link ColorSchema} values into colors.
*/
private ColorExtractor colorExtractor = null;
/**
* Util class for simple operations on {@link Element elements}.
*/
private ElementUtils eu = new ElementUtils();
/**
* This class contains a list of params that are used for drawing.
*
......@@ -170,6 +182,16 @@ public abstract class AbstractImageGenerator {
*/
private List<Map<Object, ColorSchema>> visibleLayouts = new ArrayList<>();
/**
* Color that should be used for drawing overlays with minimum value.
*/
private Color minColor = Color.BLACK;
/**
* Color that should be used for drawing overlays with maximum value.
*/
private Color maxColor = Color.BLACK;
/**
* @param scale
* scale to set
......@@ -481,6 +503,50 @@ public abstract class AbstractImageGenerator {
return result;
}
/**
* Returns {@link Color} that should be used for drawing overlays with
* maximum value.
*
* @return {@link Color} that should be used for drawing overlays with
* maximum value
*/
public Color getMaxColor() {
return maxColor;
}
/**
* Returns {@link Color} that should be used for drawing overlays with
* minimum value.
*
* @return {@link Color} that should be used for drawing overlays with
* minimum value
*/
public Color getMinColor() {
return minColor;
}
/**
* @param minColor
* minColor to set
* @return object with all parameters
* @see #minColor
*/
public Params minColor(Color minColor) {
this.minColor = minColor;
return this;
}
/**
* @param maxColor
* maxColor to set
* @return object with all parameters
* @see #maxColor
*/
public Params maxColor(Color maxColor) {
this.maxColor = maxColor;
return this;
}
}
/**
......@@ -526,6 +592,8 @@ public abstract class AbstractImageGenerator {
this.level = params.getLevel();
this.scale = params.getScale();
colorExtractor = new ColorExtractor(params.getMinColor(), params.getMaxColor());
// set border frame extended by a margin
border = new Rectangle2D.Double(
params.getX() - SINGLE_FRAME_MARGIN, params.getY() - SINGLE_FRAME_MARGIN, params.getWidth() * scale + 2 * SINGLE_FRAME_MARGIN,
......@@ -557,17 +625,18 @@ public abstract class AbstractImageGenerator {
// Get the SBGN display format option from the model
this.sbgnFormat = params.getModel().isSbgnFormat();
// Correct order of displaying is: aliases, reactions, compartments, layers.
// Correct order of displaying is: elements, reactions, compartments,
// layers.
// In this way we can display all reactions and overlay them by compartments
// or layers if they should be solid and hide complexity behind it
// draw all aliases
for (Element alias : params.getModel().getSortedSpeciesList()) {
// draw only aliases that don't have parents (aren't included in any
// draw all elements
for (Element element : params.getModel().getSortedSpeciesList()) {
// draw only elements that don't have parents (aren't included in any
// compartment/complexes)
if (alias instanceof Species) {
if (((Species) alias).getComplex() == null) {
drawAlias((Species) alias, params.getVisibleLayoutsForElement(alias));
if (element instanceof Species) {
if (((Species) element).getComplex() == null) {
drawSpecies((Species) element, params.getVisibleLayoutsForElement(element));
}
}
}
......@@ -576,11 +645,11 @@ public abstract class AbstractImageGenerator {
drawReaction(reaction, params.getVisibleLayoutsForElement(reaction));
}
// draw all compartments
for (Compartment ca : params.getModel().getSortedCompartments()) {
// draw only aliases that don't have parents (aren't included in any
for (Compartment compartment : params.getModel().getSortedCompartments()) {
// draw only compartment that don't have parents (aren't included in any
// compartment/complexes)
if (ca.getCompartment() == null) {
drawCompartmentAlias(ca, params.isNested(), params.getVisibleLayoutsForElement(ca), params);
if (compartment.getCompartment() == null) {
drawCompartment(compartment, params.isNested(), params.getVisibleLayoutsForElement(compartment), params);
}
}
......@@ -611,25 +680,26 @@ public abstract class AbstractImageGenerator {
}
/**
* This method draw a compartment alias on a graphics.
* This method draw a {@link Compartment} on a graphics.
*
* @param compAlias
* @param compartment
* object that we want to draw
* @param nested
* are the compartments drawn in hierarchical view
* @param visibleLayouts
* list of {@link ColorSchema} used for coloring alias in layouts
* list of {@link ColorSchema} used for coloring element in layouts
* @param params
* list of all params to create apropriate image
* @throws DrawingException
* thrown when there was a problem with drawing compartment alias
* thrown when there was a problem with drawing {@link Compartment}
*/
protected void drawCompartmentAlias(final Compartment compAlias, final boolean nested, List<ColorSchema> visibleLayouts, Params params)
protected void drawCompartment(final Compartment compartment, final boolean nested, List<ColorSchema> visibleLayouts, Params params)
throws DrawingException {
// If 'compAlias' has not the big enough visibility level then should not be
// If 'compartment' has not the big enough visibility level then should not
// be
// visible.
if (compAlias.getVisibilityLevel() > level) {
if (compartment.getVisibilityLevel() > level) {
return;
}
......@@ -640,25 +710,25 @@ public abstract class AbstractImageGenerator {
*/
boolean fill = true;
if (compAlias.getTransparencyLevel() <= level) {
if (compartment.getTransparencyLevel() <= level) {
fill = false;
}
// get a converter for this compartment
AliasConverter converter = new AliasConverter(compAlias);
ElementConverterImpl converter = new ElementConverterImpl(compartment, colorExtractor);
ConverterParams compartmentParams = new ConverterParams().textCentered(fill).level(level);
if (nested) {
compartmentParams.fill(fill).scale(Math.max(scale, 1));
}
// we draw compartment alias only when we have hierarchical view or it's
// standard compartment (not the artifital pathway)
if (nested || !(compAlias instanceof PathwayCompartment)) {
// we draw compartment only when we have hierarchical view or it's
// standard compartment (not the pathway)
if (nested || !(compartment instanceof PathwayCompartment)) {
try {
converter.drawAlias(compAlias, graphics, compartmentParams, visibleLayouts);
converter.drawElement(compartment, graphics, compartmentParams, visibleLayouts);
} catch (Exception e) {
throw new DrawingException("Problem with drawing alias \"" + compAlias.getElementId() + "\" (name: \"" + compAlias.getName() + "\").", e);
throw new DrawingException(eu.getElementTag(compartment) + "Problem with drawing element.", e);
}
}
......@@ -668,48 +738,48 @@ public abstract class AbstractImageGenerator {
if (fill) {
return;
}
List<Element> result = new ArrayList<Element>();
result.addAll(compAlias.getElements());
List<Element> result = new ArrayList<>();
result.addAll(compartment.getElements());
Collections.sort(result, Element.SIZE_COMPARATOR);
// draw all children of this compartment
for (Element alias : result) {
// if a child is a standard alias
if (alias instanceof Species) {
drawAlias((Species) alias, params.getVisibleLayoutsForElement(alias));
} else if (alias instanceof Compartment) {