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

Merge branch '1141-transcription-site-should-have-color' into 'master'

Resolve "Transcription site should have color"

Closes #1141

See merge request !1391
parents 520de473 512968a8
Pipeline #51018 canceled with stage
in 3 minutes and 56 seconds
......@@ -5,6 +5,8 @@ minerva (16.1.0~alpha.0) stable; urgency=medium
(#219)
* Small improvement: possibility to provide image coords as json file (#1307)
* Small improvement: possibility to show reaction name (#1355)
* Small improvement: modification residues can use different color then
species if format allows (SBGN, SBML) (#1141)
* Small improvement: possibility to show element id (#1229)
* Small improvement: There is possibility to provide custom CSS style (#1017)
* Small improvement: API provides information about modifier type (#1085)
......
package lcsb.mapviewer.converter.model.celldesigner.structure.fields;
import java.awt.Color;
import java.io.Serializable;
import org.apache.logging.log4j.LogManager;
......@@ -416,6 +417,7 @@ public class CellDesignerModificationResidue implements Serializable {
result.setIdModificationResidue(idModificationResidue);
result.setName(name);
result.setPosition(converter.getCoordinatesByPosition(element, pos, result.getWidth()));
result.setBorderColor(element.getBorderColor());
return result;
}
......@@ -431,6 +433,7 @@ public class CellDesignerModificationResidue implements Serializable {
} else {
result.setWidth(element.getWidth() * size);
}
result.setBorderColor(element.getBorderColor());
return result;
}
......@@ -443,6 +446,7 @@ public class CellDesignerModificationResidue implements Serializable {
pos = angle;
}
result.setPosition(converter.getCoordinatesByPosition(element, pos, result.getWidth()));
result.setBorderColor(element.getBorderColor());
return result;
}
......@@ -452,6 +456,7 @@ public class CellDesignerModificationResidue implements Serializable {
result.setIdModificationResidue(idModificationResidue);
result.setName(name);
result.setPosition(converter.getCoordinatesByPosition(element, angle, result.getWidth()));
result.setBorderColor(element.getBorderColor());
return result;
}
......@@ -467,6 +472,14 @@ public class CellDesignerModificationResidue implements Serializable {
} else {
result.setDirection("RIGHT");
}
result.setBorderColor(element.getBorderColor());
if (result.getActive() != null) {
if (result.getActive()) {
result.setBorderColor(Color.RED);
} else {
result.setBorderColor(Color.BLACK);
}
}
return result;
}
......@@ -483,6 +496,7 @@ public class CellDesignerModificationResidue implements Serializable {
angle = 0.0;
}
result.setPosition(converter.getCoordinatesByPosition(element, angle));
result.setBorderColor(element.getBorderColor());
return result;
}
......@@ -496,6 +510,7 @@ public class CellDesignerModificationResidue implements Serializable {
angle = 0.0;
}
result.setPosition(converter.getResidueCoordinates(element, angle));
result.setBorderColor(element.getBorderColor());
return result;
}
......
......@@ -32,7 +32,9 @@ import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.model.ModelComparator;
import lcsb.mapviewer.model.map.model.ModelFullIndexed;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.model.map.species.Gene;
import lcsb.mapviewer.model.map.species.GenericProtein;
import lcsb.mapviewer.model.map.species.Rna;
import lcsb.mapviewer.model.map.species.SimpleMolecule;
public abstract class CellDesignerTestFunctions extends TestUtils {
......@@ -117,6 +119,22 @@ public abstract class CellDesignerTestFunctions extends TestUtils {
return protein;
}
protected static Rna createRna() {
Rna rna = new Rna("id" + (idCounter++));
assignCoordinates(30, 40, 10, 20, rna);
return rna;
}
protected static Gene createGene() {
Gene rna = new Gene("id" + (idCounter++));
assignCoordinates(30, 40, 10, 20, rna);
return rna;
}
protected SimpleMolecule createSimpleMolecule() {
SimpleMolecule result = new SimpleMolecule("id" + (idCounter++));
assignCoordinates(50, 60, 20, 20, result);
......
......@@ -2,29 +2,86 @@ package lcsb.mapviewer.converter.model.celldesigner.structure.fields;
import static org.junit.Assert.assertNotNull;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import java.awt.geom.Point2D;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
public class CellDesignerModificationResidueTest {
import lcsb.mapviewer.converter.model.celldesigner.CellDesignerTestFunctions;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.model.map.species.field.BindingRegion;
import lcsb.mapviewer.model.map.species.field.CodingRegion;
import lcsb.mapviewer.model.map.species.field.ModificationResidue;
import lcsb.mapviewer.model.map.species.field.ModificationSite;
import lcsb.mapviewer.model.map.species.field.ProteinBindingDomain;
import lcsb.mapviewer.model.map.species.field.RegulatoryRegion;
import lcsb.mapviewer.model.map.species.field.Residue;
import lcsb.mapviewer.model.map.species.field.TranscriptionSite;
@AfterClass
public static void tearDownAfterClass() throws Exception {
}
@RunWith(Parameterized.class)
public class CellDesignerModificationResidueTest extends CellDesignerTestFunctions {
@Before
public void setUp() throws Exception {
private CellDesignerModificationResidue region;
private Element species;
public CellDesignerModificationResidueTest(final ModificationResidue residue) {
residue.setPosition(new Point2D.Double(100, 200));
this.region = new CellDesignerModificationResidue(residue);
this.species = residue.getSpecies();
}
@After
public void tearDown() throws Exception {
@Parameters(name = "{index} : {0}")
public static Collection<Object[]> data() throws IOException {
Collection<Object[]> data = new ArrayList<>();
ModificationResidue residue;
residue = new BindingRegion();
residue.setSpecies(createProtein());
data.add(new Object[] { residue });
residue = new CodingRegion();
residue.setSpecies(createRna());
data.add(new Object[] { residue });
residue = new ProteinBindingDomain();
residue.setSpecies(createRna());
data.add(new Object[] { residue });
residue = new RegulatoryRegion();
residue.setSpecies(createGene());
data.add(new Object[] { residue });
residue = new TranscriptionSite();
((TranscriptionSite)residue).setDirection("LEFT");
residue.setSpecies(createGene());
data.add(new Object[] { residue });
residue = new ModificationSite();
residue.setSpecies(createGene());
data.add(new Object[] { residue });
residue = new Residue();
residue.setSpecies(createProtein());
data.add(new Object[] { residue });
return data;
}
@Test
public void test() {
CellDesignerModificationResidue region = new CellDesignerModificationResidue();
public void testToString() {
assertNotNull(region.toString());
}
@Test
public void testToModificationResidueContainsColor() {
ModificationResidue residue = region.createModificationResidue(species);
assertNotNull(residue.getBorderColor());
}
}
......@@ -289,6 +289,7 @@ public class SbgnmlXmlExporter {
Glyph stateVariableGlyph = parseStateVariable(mr);
stateVariableGlyph.setId(newGlyph.getId().concat("-").concat(stateVariableGlyph.getId()));
newGlyph.getGlyph().add(stateVariableGlyph);
addRenderInformation(stateVariableGlyph, mr);
}
if (protein.getStructuralState() != null && !protein.getStructuralState().getValue().isEmpty()) {
newGlyph.getGlyph().add(createStateVariableForStructuralState(protein.getStructuralState()));
......@@ -356,6 +357,12 @@ public class SbgnmlXmlExporter {
colorParser.colorToHtml(element.getBorderColor()), lineWidth);
}
private void addRenderInformation(final Glyph glyph, final ModificationResidue element) {
float lineWidth = element.getSpecies().getLineWidth().floatValue();
RenderUtil.addStyle(renderInformation, glyph.getId(), colorParser.colorToHtml(Color.WHITE),
colorParser.colorToHtml(element.getBorderColor()), lineWidth);
}
private void addRenderInformation(final Glyph glyph, final PolylineData line) {
float lineWidth = (float) line.getWidth();
RenderUtil.addStyle(renderInformation, glyph.getId(), colorParser.colorToHtml(Color.WHITE),
......
......@@ -1070,6 +1070,22 @@ public class SbgnmlXmlParser {
}
}
private void assignRenderInformation(final ModificationResidue element, final Glyph glyph) {
if (renderInformation != null) {
Style style = RenderUtil.getStyle(renderInformation, glyph);
if (style != null) {
try {
element.setBorderColor(extractColor(style.getG().getStroke()));
} catch (final InvalidArgumentException e) {
logger.warn("Invalid border color: " + style.getG().getStroke());
}
}
}
if (element.getBorderColor() == null) {
element.setBorderColor(Color.BLACK);
}
}
private void assignRenderInformation(final PolylineData line, final Arc glyph) {
if (renderInformation != null) {
Style style = RenderUtil.getStyle(renderInformation, glyph);
......@@ -1263,6 +1279,8 @@ public class SbgnmlXmlParser {
mr.setPosition(new Point2D.Double(x, y));
assignRenderInformation(mr, stateVariable);
return mr;
}
......
......@@ -98,7 +98,7 @@ public class ModificationResidueConverter extends DrawableConverter<Modification
Color c = graphics.getColor();
graphics.setColor(Color.WHITE);
graphics.fill(ellipse);
graphics.setColor(c);
graphics.setColor(residue.getBorderColor());
graphics.draw(ellipse);
ModificationState state = residue.getState();
......@@ -111,6 +111,7 @@ public class ModificationResidueConverter extends DrawableConverter<Modification
graphics.drawString(str, (int) x, (int) y);
graphics.setFont(tmpFont);
}
graphics.setColor(c);
}
private Font getStructuralFont() {
......@@ -144,7 +145,7 @@ public class ModificationResidueConverter extends DrawableConverter<Modification
Color c = graphics.getColor();
graphics.setColor(Color.WHITE);
graphics.fill(ellipse);
graphics.setColor(c);
graphics.setColor(modificationSite.getBorderColor());
graphics.draw(ellipse);
graphics.drawLine((int) p.getX(), (int) (p.getY() + diameter / 2), (int) p.getX(), (int) y);
......@@ -158,6 +159,7 @@ public class ModificationResidueConverter extends DrawableConverter<Modification
graphics.drawString(str, (int) textX, (int) textY);
graphics.setFont(tmpFont);
}
graphics.setColor(c);
}
protected void drawBindingRegion(final BindingRegion bindingRegion, final Graphics2D graphics) {
......@@ -181,7 +183,7 @@ public class ModificationResidueConverter extends DrawableConverter<Modification
Color c = graphics.getColor();
graphics.setColor(Color.WHITE);
graphics.fill(rectangle);
graphics.setColor(c);
graphics.setColor(modification.getBorderColor());
graphics.draw(rectangle);
String str = modification.getName();
......@@ -193,6 +195,7 @@ public class ModificationResidueConverter extends DrawableConverter<Modification
graphics.drawString(str, (int) textX, (int) textY);
graphics.setFont(tmpFont);
}
graphics.setColor(c);
}
......@@ -201,16 +204,6 @@ public class ModificationResidueConverter extends DrawableConverter<Modification
}
protected void drawTranscriptionSite(final TranscriptionSite transcriptionSite, final Graphics2D graphics) {
Color color = graphics.getColor();
if (transcriptionSite.getActive()) {
color = Color.RED;
} else {
color = Color.BLACK;
}
if (transcriptionSite.getSpecies() != null && transcriptionSite.getSpecies().getFillColor().equals(Color.WHITE)) {
color = Color.BLACK;
}
double y = transcriptionSite.getPosition().getY();
double x = transcriptionSite.getPosition().getX();
if (transcriptionSite.getDirection().equals("RIGHT")) {
......@@ -229,7 +222,7 @@ public class ModificationResidueConverter extends DrawableConverter<Modification
Point2D p3 = new Point2D.Double(x, y);
PolylineData line = new PolylineData(Arrays.asList(p1, p2, p3));
line.setColor(color);
line.setColor(transcriptionSite.getBorderColor());
line.getEndAtd().setArrowType(ArrowType.FULL);
line.getEndAtd().setLen(TRANSCRIPTION_SITE_ARROW_LENGTH);
line.getEndAtd().setAngle(TRANSCRIPTION_SITE_ARROW_ANGLE);
......
......@@ -8,6 +8,7 @@ import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.geom.Point2D;
import java.awt.image.BufferedImage;
......@@ -26,6 +27,7 @@ import lcsb.mapviewer.model.map.species.field.BindingRegion;
import lcsb.mapviewer.model.map.species.field.CodingRegion;
import lcsb.mapviewer.model.map.species.field.ModificationResidue;
import lcsb.mapviewer.model.map.species.field.ModificationSite;
import lcsb.mapviewer.model.map.species.field.ModificationState;
import lcsb.mapviewer.model.map.species.field.ProteinBindingDomain;
import lcsb.mapviewer.model.map.species.field.RegulatoryRegion;
import lcsb.mapviewer.model.map.species.field.Residue;
......@@ -54,6 +56,21 @@ public class ModificationResidueConverterTest extends GraphicsTestFunctions {
verify(converter, times(1)).drawResidue(any(), any(), anyBoolean());
}
@Test
public void testDrawResidueWithState() throws Exception {
BufferedImage bi = new BufferedImage(200, 200, BufferedImage.TYPE_INT_ARGB);
Graphics2D graphics = bi.createGraphics();
Residue residue = new Residue();
residue.setState(ModificationState.ACETYLATED);
residue.setBorderColor(Color.BLACK);
residue.setPosition(new Point2D.Double(10, 10));
ModificationResidueConverter converter = Mockito.spy(new ModificationResidueConverter());
converter.drawModification(residue, graphics, new ConverterParams());
verify(converter, times(1)).drawResidue(any(), any(), anyBoolean());
}
@Test
public void testDrawBindingRegion() throws Exception {
BufferedImage bi = new BufferedImage(200, 200, BufferedImage.TYPE_INT_ARGB);
......
......@@ -23,6 +23,7 @@ import lcsb.mapviewer.converter.model.sbml.SbmlModelUtils;
import lcsb.mapviewer.model.LogMarker;
import lcsb.mapviewer.model.ProjectLogEntryType;
import lcsb.mapviewer.model.graphics.ArrowType;
import lcsb.mapviewer.model.map.Drawable;
import lcsb.mapviewer.model.map.species.field.AbstractRegionModification;
import lcsb.mapviewer.model.map.species.field.BindingRegion;
import lcsb.mapviewer.model.map.species.field.CodingRegion;
......@@ -52,32 +53,32 @@ public class ModificationResidueExporter {
public LocalStyle createStyle(final ModificationResidue element) {
if (element instanceof Residue) {
return createEllipseStyle();
return createEllipseStyle(element);
} else if (element instanceof ModificationSite) {
return createModificationSiteStyle((ModificationSite) element);
} else if (element instanceof TranscriptionSite) {
return createTranscriptionSiteStyle((TranscriptionSite) element);
} else if (element instanceof RegulatoryRegion) {
return createRectangleStyle();
return createRectangleStyle(element);
} else if (element instanceof BindingRegion) {
return createRectangleStyle();
return createRectangleStyle(element);
} else if (element instanceof CodingRegion) {
return createRectangleStyle();
return createRectangleStyle(element);
} else if (element instanceof ProteinBindingDomain) {
return createRectangleStyle();
return createRectangleStyle(element);
} else {
logger.warn(new LogMarker(ProjectLogEntryType.EXPORT_ISSUE, element.getSpecies()),
"Don't know how to render modification residue: " + new ElementUtils().getElementTag(element));
return createEllipseStyle();
return createEllipseStyle(element);
}
}
public LocalStyle createStyle(final StructuralState structuralState) {
return createEllipseStyle();
return createEllipseStyle(structuralState);
}
private LocalStyle createRectangleStyle() {
LocalStyle style = createGenericStyle();
private LocalStyle createRectangleStyle(final Drawable element) {
LocalStyle style = createGenericStyle(element);
Rectangle rectangle = new Rectangle();
rectangle.setRx(new RelAbsVector(0, 0));
......@@ -95,15 +96,7 @@ public class ModificationResidueExporter {
private LocalStyle createTranscriptionSiteStyle(final TranscriptionSite transcriptionSite) {
LocalStyle style = createGenericStyle();
ColorDefinition color;
if (transcriptionSite.getActive()) {
color = sbmlModelUtils.getColorDefinition(Color.RED);
} else {
color = sbmlModelUtils.getColorDefinition(Color.BLACK);
}
if (transcriptionSite.getSpecies() != null && transcriptionSite.getSpecies().getFillColor().equals(Color.WHITE)) {
color = sbmlModelUtils.getColorDefinition(Color.BLACK);
}
ColorDefinition color = sbmlModelUtils.getColorDefinition(transcriptionSite.getBorderColor());
style.getGroup().setStroke(color.getId());
style.getGroup().setEndHead(ArrowType.FULL.name());
......@@ -186,8 +179,8 @@ public class ModificationResidueExporter {
return style;
}
private LocalStyle createEllipseStyle() {
LocalStyle style = createGenericStyle();
private LocalStyle createEllipseStyle(final Drawable element) {
LocalStyle style = createGenericStyle(element);
Ellipse ellipse = new Ellipse();
ellipse.setCx(new RelAbsVector(0, 50));
......@@ -200,6 +193,23 @@ public class ModificationResidueExporter {
return style;
}
private LocalStyle createGenericStyle(final Drawable element) {
LocalStyle style = createGenericStyle();
style.getGroup().setStroke(sbmlModelUtils.getColorDefinition(element.getBorderColor()).getId());
return style;
}
private LocalStyle createGenericStyle() {
LocalStyle style = sbmlModelUtils.createStyle();
ColorDefinition color = sbmlModelUtils.getColorDefinition(Color.BLACK);
ColorDefinition background = sbmlModelUtils.getColorDefinition(Color.WHITE);
style.getGroup().setStroke(color.getId());
style.getGroup().setStrokeWidth(1.0);
style.getGroup().setFill(background.getId());
style.getGroup().setFontSize((short) 10);
return style;
}
public LocalStyle createTextStyle(final ModificationResidue mr) {
return createTextStyle();
}
......@@ -216,17 +226,6 @@ public class ModificationResidueExporter {
return createTextStyle();
}
private LocalStyle createGenericStyle() {
LocalStyle style = sbmlModelUtils.createStyle();
ColorDefinition color = sbmlModelUtils.getColorDefinition(Color.BLACK);
ColorDefinition background = sbmlModelUtils.getColorDefinition(Color.WHITE);
style.getGroup().setStroke(color.getId());
style.getGroup().setStrokeWidth(1.0);
style.getGroup().setFill(background.getId());
style.getGroup().setFontSize((short) 10);
return style;
}
public BoundingBox createBoundingBoxForModification(final ModificationResidue mr) {
double width = getModificationWidth(mr);
double height = getModificationHeight(mr);
......
package lcsb.mapviewer.converter.model.sbml.species;
import java.awt.Color;
import java.awt.geom.Point2D;
import java.util.ArrayList;
import java.util.HashMap;
......@@ -378,12 +379,22 @@ public class SbmlSpeciesParser extends SbmlElementParser<org.sbml.jsbml.Species>
double z = residueGlyph.getBoundingBox().getPosition().getZ();
mr.setPosition(new Point2D.Double(x + width / 2, y + height / 2));
mr.setZ((int) Math.round(z));
LocalStyle style = getStyleForGlyph(residueGlyph);
if (style != null) {
Color borderColor = getColorByColorDefinition(style.getGroup().getStroke());
mr.setBorderColor(borderColor);
}
if (mr instanceof AbstractRegionModification) {
((AbstractRegionModification) mr).setWidth(width);
((AbstractRegionModification) mr).setHeight(height);
}
}
}
if (mr.getBorderColor() == null) {
mr.setBorderColor(Color.BLACK);
}
}
}
......
......@@ -543,18 +543,21 @@ public class SbmlExporterTest extends SbmlTestFunctions {
mr.setName("217U");
mr.setState(ModificationState.PHOSPHORYLATED);
mr.setPosition(new Point2D.Double(10, 11));
mr.setBorderColor(Color.YELLOW);
mr.setZ(100);
element.addResidue(mr);
mr = new Residue("Y");
mr.setName("218");
mr.setState(ModificationState.PHOSPHORYLATED);
mr.setPosition(new Point2D.Double(10, 12));
mr.setBorderColor(Color.BLUE);
mr.setZ(102);
element.addResidue(mr);
mr = new Residue("Z");
mr.setName("219");
mr.setState(ModificationState.UBIQUITINATED);
mr.setPosition(new Point2D.Double(10, 13));
mr.setBorderColor(Color.RED);
mr.setZ(1000);