From 762760548d8dc88159c7ea3ac7530dadefb13408 Mon Sep 17 00:00:00 2001 From: Piotr Gawron Date: Thu, 19 Dec 2019 09:28:55 +0100 Subject: [PATCH 1/3] coloring wasn't applied to center --- CHANGELOG | 2 ++ .../bioEntity/reaction/ReactionConverter.java | 9 ++++++++- .../mapviewer/commands/ColorModelCommand.java | 7 ++++++- .../commands/ColorModelCommandTest.java | 20 +++++++++++++++++-- 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 3f196171a..553c5916e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -7,6 +7,8 @@ minerva (14.0.6) stable; urgency=medium displayed at all (regresion 14.0.5, #1045) * Bug fix: when there is a problem with database during removing project, project removal doesn't hang (#1058) + * Bug fix: coloring of the reaction wasn't applied to center of reaction + (#1057) -- Piotr Gawron Wed, 18 Dec 2019 12:00:00 +0200 diff --git a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/reaction/ReactionConverter.java b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/reaction/ReactionConverter.java index 925e6e256..87dadad56 100644 --- a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/reaction/ReactionConverter.java +++ b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/reaction/ReactionConverter.java @@ -296,8 +296,15 @@ public class ReactionConverter extends BioEntityConverter { * {@link ColorSchema} to modify reaction */ private void applyColorSchema(Reaction reaction, ColorSchema colorSchema) { + PolylineData pd = new PolylineData(reaction.getLine()); + pd.setColor(colorExtractor.getNormalizedColor(colorSchema)); + if (colorSchema.getLineWidth() != null) { + pd.setWidth(colorSchema.getLineWidth()); + } + reaction.setLine(pd); + for (AbstractNode node : reaction.getNodes()) { - PolylineData pd = new PolylineData(node.getLine()); + pd = new PolylineData(node.getLine()); pd.setColor(colorExtractor.getNormalizedColor(colorSchema)); if (colorSchema.getLineWidth() != null) { pd.setWidth(colorSchema.getLineWidth()); 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 961ad5511..86771e56a 100644 --- a/model-command/src/main/java/lcsb/mapviewer/commands/ColorModelCommand.java +++ b/model-command/src/main/java/lcsb/mapviewer/commands/ColorModelCommand.java @@ -81,13 +81,17 @@ public class ColorModelCommand extends ModelCommand { * @throws InvalidColorSchemaException * thrown when {@link Reaction} was already colored by other schema */ - private void applyColor(Reaction reaction, ColorSchema schema) throws InvalidColorSchemaException { + void applyColor(Reaction reaction, ColorSchema schema) throws InvalidColorSchemaException { if (!reaction.getReactants().get(0).getLine().getColor().equals(Color.BLACK)) { throw new InvalidColorSchemaException( "At least two rows try to set color to reaction: " + reaction.getIdReaction()); } Color color = colorExtractor.getNormalizedColor(schema); + reaction.getLine().setColor(color); + if (schema.getLineWidth() != null) { + reaction.getLine().setWidth(schema.getLineWidth()); + } for (AbstractNode node : reaction.getNodes()) { node.getLine().setColor(color); if (schema.getLineWidth() != null) { @@ -342,6 +346,7 @@ public class ColorModelCommand extends ModelCommand { element.setGlyph(null); } for (Reaction reaction : result.getReactions()) { + reaction.getLine().setColor(Color.BLACK); for (AbstractNode node : reaction.getNodes()) { node.getLine().setColor(Color.BLACK); } 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 b60c45de5..19fa55806 100644 --- a/model-command/src/test/java/lcsb/mapviewer/commands/ColorModelCommandTest.java +++ b/model-command/src/test/java/lcsb/mapviewer/commands/ColorModelCommandTest.java @@ -2,9 +2,8 @@ package lcsb.mapviewer.commands; import static org.junit.Assert.*; -import java.awt.*; +import java.awt.Color; import java.util.*; -import java.util.List; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -460,4 +459,21 @@ public class ColorModelCommandTest extends CommandTestFunctions { assertNotNull(factory.getModifiedElements().get(reaction)); } + @Test + public void testApplyColorToReaction() throws Exception { + Model model = getModelForFile("testFiles/sample.xml", false); + Reaction re4 = model.getReactionByReactionId("re1"); + + ColorSchema schema = new GenericColorSchema(); + schema.setElementId("re1"); + schema.setColor(Color.YELLOW); + schema.setName(null); + + ColorModelCommand factory = new ColorModelCommand(model, new ArrayList<>(), colorExtractor); + + factory.applyColor(re4, schema); + + assertEquals(Color.YELLOW, re4.getLine().getColor()); + } + } -- GitLab From 0b3b120a6cf182ad62327686c7963ed6e4071fc0 Mon Sep 17 00:00:00 2001 From: Piotr Gawron Date: Thu, 19 Dec 2019 09:30:10 +0100 Subject: [PATCH 2/3] changelog updated --- CHANGELOG | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 553c5916e..bb8f99dee 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -8,7 +8,7 @@ minerva (14.0.6) stable; urgency=medium * Bug fix: when there is a problem with database during removing project, project removal doesn't hang (#1058) * Bug fix: coloring of the reaction wasn't applied to center of reaction - (#1057) + (regression 14.0.0, #1057) -- Piotr Gawron Wed, 18 Dec 2019 12:00:00 +0200 -- GitLab From 8abf04b89a636192f75e58fba1e9f565abedfb06 Mon Sep 17 00:00:00 2001 From: Piotr Gawron Date: Thu, 19 Dec 2019 10:49:01 +0100 Subject: [PATCH 3/3] colouring by column identifier_xxx did not work for genetic variants --- CHANGELOG | 2 ++ .../services/utils/ColorSchemaReader.java | 20 +++++++++++++------ .../services/utils/ColorSchemaReaderTest.java | 14 +++++++++++++ .../coloring/uniprot-identifiers.txt | 9 +++++++++ 4 files changed, 39 insertions(+), 6 deletions(-) create mode 100644 service/testFiles/coloring/uniprot-identifiers.txt diff --git a/CHANGELOG b/CHANGELOG index bb8f99dee..8cc1aabf5 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -9,6 +9,8 @@ minerva (14.0.6) stable; urgency=medium project removal doesn't hang (#1058) * Bug fix: coloring of the reaction wasn't applied to center of reaction (regression 14.0.0, #1057) + * Bug fix: genetic variant overlay improperly processed elements identified + by miriam identifiers, like uniprot (#1059) -- Piotr Gawron Wed, 18 Dec 2019 12:00:00 +0200 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 cf038bc32..2c716ec16 100644 --- a/service/src/main/java/lcsb/mapviewer/services/utils/ColorSchemaReader.java +++ b/service/src/main/java/lcsb/mapviewer/services/utils/ColorSchemaReader.java @@ -81,9 +81,7 @@ public class ColorSchemaReader { if (Integer.valueOf(params.get(TextFileUtils.COLUMN_COUNT_PARAM)) == 1) { return readSimpleNameColorSchema(colorInputStream); } else if (params.get(ZipEntryFileFactory.LAYOUT_HEADER_PARAM_TYPE) == null) { - { - return readGenericColorSchema(colorInputStream); - } + return readGenericColorSchema(colorInputStream); } else { ColorSchemaType type = null; try { @@ -393,10 +391,10 @@ public class ColorSchemaReader { private Collection mergeSchemas(Collection schemas) { Map schemasByName = new HashMap<>(); for (ColorSchema colorSchema : schemas) { - ColorSchema mergedSchema = schemasByName.get(colorSchema.getName()); + ColorSchema mergedSchema = schemasByName.get(getColorSchemaIdentifiablePart(colorSchema)); if (mergedSchema == null) { mergedSchema = colorSchema.copy(); - schemasByName.put(colorSchema.getName(), mergedSchema); + schemasByName.put(getColorSchemaIdentifiablePart(colorSchema), mergedSchema); } else { if (mergedSchema instanceof GeneVariationColorSchema) { if (colorSchema instanceof GeneVariationColorSchema) { @@ -420,6 +418,16 @@ public class ColorSchemaReader { return schemasByName.values(); } + private String getColorSchemaIdentifiablePart(ColorSchema colorSchema) { + List identifiers = new ArrayList<>(); + for (MiriamData md : colorSchema.getMiriamData()) { + identifiers.add(md.toString()); + } + Collections.sort(identifiers); + + return StringUtils.join(identifiers, "\n") + "\n" + colorSchema.getName(); + } + /** * Gets color that should be assigned to {@link GeneVariationColorSchema}. * @@ -771,7 +779,7 @@ public class ColorSchemaReader { if (schema.getLineWidth() != null) { result.add(ColorSchemaColumn.LINE_WIDTH); } - if (schema.getName() != null) { + if (getColorSchemaIdentifiablePart(schema) != null) { result.add(ColorSchemaColumn.NAME); } if (schema.getModelName() != null) { 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 798fa15e8..021333a61 100644 --- a/service/src/test/java/lcsb/mapviewer/services/utils/ColorSchemaReaderTest.java +++ b/service/src/test/java/lcsb/mapviewer/services/utils/ColorSchemaReaderTest.java @@ -376,4 +376,18 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions { reader.readColorSchema(fis, TextFileUtils.getHeaderParametersFromFile(fis2)); } + + @Test + public void testGeneticVariantByUniprotIdentifier() throws Exception { + File f = new File("testFiles/coloring/uniprot-identifiers.txt"); + byte[] data = fileToByteArray(f); + + ByteArrayInputStream bin = new ByteArrayInputStream(data); + + Collection schemas = reader.readColorSchema(bin, + TextFileUtils.getHeaderParametersFromFile(new ByteArrayInputStream(data))); + assertNotNull(schemas); + assertEquals(2, schemas.size()); + } + } diff --git a/service/testFiles/coloring/uniprot-identifiers.txt b/service/testFiles/coloring/uniprot-identifiers.txt new file mode 100644 index 000000000..1f646375a --- /dev/null +++ b/service/testFiles/coloring/uniprot-identifiers.txt @@ -0,0 +1,9 @@ +#TYPE=GENETIC_VARIANT +#GENOME_VERSION=hg19 +#GENOME_TYPE=UCSC +position original_DNA alternative_DNA contig allele_frequency color identifier_uniprot +90648003 T G 4 0.3750000 #e58e00 P14416 +90656320 T C 4 0.7034621 #e58e00 P14416 +90755218 G A 4 0.1379310 #e58ec5 P02511 +161709831 G T 6 0.6025862 #e58ec5 P02511 +162525131 G T 6 0.7025762 #e58ec5 P02511 -- GitLab