Skip to content
Snippets Groups Projects
Commit 8a1c3f22 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

Merge branch '242-overlay-data-should-provide-possibility-to-distinguish-submaps' into 'master'

Resolve "overlay data should provide possibility to distinguish submaps"

Closes #242

See merge request piotr.gawron/minerva!170
parents d8f01ce2 4b63adc8
No related branches found
No related tags found
1 merge request!170Resolve "overlay data should provide possibility to distinguish submaps"
Pipeline #
......@@ -10,6 +10,7 @@ import java.util.Map;
import org.apache.log4j.Logger;
import lcsb.mapviewer.common.Pair;
import lcsb.mapviewer.common.comparator.StringComparator;
import lcsb.mapviewer.common.exception.NotImplementedException;
import lcsb.mapviewer.model.graphics.ArrowTypeData;
import lcsb.mapviewer.model.map.BioEntity;
......@@ -20,6 +21,7 @@ import lcsb.mapviewer.model.map.compartment.Compartment;
import lcsb.mapviewer.model.map.layout.ColorSchema;
import lcsb.mapviewer.model.map.layout.InvalidColorSchemaException;
import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.model.ModelData;
import lcsb.mapviewer.model.map.model.ModelSubmodelConnection;
import lcsb.mapviewer.model.map.reaction.AbstractNode;
import lcsb.mapviewer.model.map.reaction.Product;
......@@ -60,6 +62,8 @@ public class ColorModelCommand extends ModelCommand {
*/
private ElementUtils eu = new ElementUtils();
private StringComparator stringComparator = new StringComparator();
/**
* Default constructor.
*
......@@ -125,6 +129,9 @@ public class ColorModelCommand extends ModelCommand {
if (schema.getName() != null) {
return false;
}
if (!modelMatch(reaction.getModelData(), schema)) {
return false;
}
if (schema.getReactionIdentifier() != null
&& schema.getReactionIdentifier().equalsIgnoreCase(reaction.getIdReaction())) {
......@@ -150,6 +157,19 @@ public class ColorModelCommand extends ModelCommand {
return false;
}
private boolean modelMatch(ModelData model, ColorSchema schema) {
if (schema.getModelName() != null && !schema.getModelName().isEmpty()) {
if (model == null) {
logger.warn("Model of element is null...");
return false;
}
if (stringComparator.compare(model.getName(), schema.getModelName()) != 0) {
return false;
}
}
return true;
}
/**
* Applies color schema into the {@link Element}.
*
......@@ -181,6 +201,9 @@ public class ColorModelCommand extends ModelCommand {
*/
protected boolean match(Element element, ColorSchema schema) {
if (element instanceof Species) {
if (!modelMatch(element.getModelData(), schema)) {
return false;
}
if (schema.getName() != null) {
if (!element.getName().equalsIgnoreCase(schema.getName())) {
return false;
......
......@@ -362,4 +362,94 @@ public class ColorModelCommandTest extends CommandTestFunctions {
}
@Test
public void testReactionColoringWithModelNotMatching() throws Exception {
try {
Model model = getModelForFile("testFiles/reactions_to_color.xml", false);
ColorSchema schema = new GenericColorSchema();
schema.setReactionIdentifier("re4");
schema.setName(null);
schema.setModelName(model.getName() + "XXX");
Collection<ColorSchema> schemas = new ArrayList<>();
schemas.add(schema);
ColorModelCommand factory = new ColorModelCommand(model, schemas, colorExtractor);
Map<Object, ColorSchema> map = factory.getModifiedElements();
assertEquals(0, map.values().size());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testReactionColoringWithModelMatch() throws Exception {
try {
Model model = getModelForFile("testFiles/reactions_to_color.xml", false);
ColorSchema schema = new GenericColorSchema();
schema.setReactionIdentifier("re4");
schema.setName(null);
schema.setModelName(model.getName());
Collection<ColorSchema> schemas = new ArrayList<>();
schemas.add(schema);
ColorModelCommand factory = new ColorModelCommand(model, schemas, colorExtractor);
Map<Object, ColorSchema> map = factory.getModifiedElements();
assertEquals(1, map.values().size());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testAliasColoringWithModelNotMatching() throws Exception {
try {
Model model = getModelForFile("testFiles/sample.xml", false);
ColorSchema schema = new GenericColorSchema();
schema.setName("CNC");
schema.setModelName(model.getName() + "XXX");
Collection<ColorSchema> schemas = new ArrayList<>();
schemas.add(schema);
ColorModelCommand factory = new ColorModelCommand(model, schemas, colorExtractor);
Map<Object, ColorSchema> map = factory.getModifiedElements();
assertEquals(0, map.values().size());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testAliasColoringWithModelMatch() throws Exception {
try {
Model model = getModelForFile("testFiles/sample.xml", false);
ColorSchema schema = new GenericColorSchema();
schema.setName("CNC");
schema.setModelName(model.getName());
Collection<ColorSchema> schemas = new ArrayList<>();
schemas.add(schema);
ColorModelCommand factory = new ColorModelCommand(model, schemas, colorExtractor);
Map<Object, ColorSchema> map = factory.getModifiedElements();
assertEquals(1, map.values().size());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
}
......@@ -792,6 +792,8 @@ public class LayoutService implements ILayoutService {
sb.append("\t");
} else if (column.equals(ColorSchemaColumn.NAME)) {
sb.append(schema.getName() + "\t");
} else if (column.equals(ColorSchemaColumn.MODEL_NAME)) {
sb.append(schema.getModelName() + "\t");
} else if (column.equals(ColorSchemaColumn.VALUE)) {
sb.append(schema.getValue() + "\t");
} else if (column.equals(ColorSchemaColumn.COMPARTMENT)) {
......@@ -847,6 +849,8 @@ public class LayoutService implements ILayoutService {
sb.append("\t");
} else if (column.equals(ColorSchemaColumn.NAME)) {
sb.append(schema.getName() + "\t");
} else if (column.equals(ColorSchemaColumn.MODEL_NAME)) {
sb.append(schema.getModelName() + "\t");
} else if (column.equals(ColorSchemaColumn.VALUE)) {
sb.append(schema.getValue() + "\t");
} else if (column.equals(ColorSchemaColumn.COMPARTMENT)) {
......
......@@ -157,6 +157,7 @@ public class ColorSchemaReader {
Integer colorColumn = schemaColumns.get(ColorSchemaColumn.COLOR);
Integer contigColumn = schemaColumns.get(ColorSchemaColumn.CONTIG);
Integer nameColumn = schemaColumns.get(ColorSchemaColumn.NAME);
Integer modelNameColumn = schemaColumns.get(ColorSchemaColumn.MODEL_NAME);
Integer identifierColumn = schemaColumns.get(ColorSchemaColumn.IDENTIFIER);
Integer variantIdentifierColumn = schemaColumns.get(ColorSchemaColumn.VARIANT_IDENTIFIER);
Integer allelFrequencyColumn = schemaColumns.get(ColorSchemaColumn.ALLEL_FREQUENCY);
......@@ -202,6 +203,9 @@ public class ColorSchemaReader {
if (nameColumn != null) {
processNameColumn(schema, values[nameColumn]);
}
if (modelNameColumn != null) {
processModelNameColumn(schema, values[modelNameColumn]);
}
if (compartmentColumn != null) {
processCompartmentColumn(schema, values[compartmentColumn]);
}
......@@ -328,6 +332,12 @@ public class ColorSchemaReader {
schema.setName(content);
}
}
private void processModelNameColumn(ColorSchema schema, String content) {
if (!content.isEmpty()) {
schema.setModelName(content);
}
}
/**
* Sets proper compartment names to {@link ColorSchema} from cell content.
......@@ -463,6 +473,7 @@ public class ColorSchemaReader {
Integer valueColumn = schemaColumns.get(ColorSchemaColumn.VALUE);
Integer colorColumn = schemaColumns.get(ColorSchemaColumn.COLOR);
Integer nameColumn = schemaColumns.get(ColorSchemaColumn.NAME);
Integer modelNameColumn = schemaColumns.get(ColorSchemaColumn.MODEL_NAME);
Integer identifierColumn = schemaColumns.get(ColorSchemaColumn.IDENTIFIER);
Integer reactionIdentifierColumn = schemaColumns.get(ColorSchemaColumn.REACTION_IDENTIFIER);
Integer compartmentColumn = schemaColumns.get(ColorSchemaColumn.COMPARTMENT);
......@@ -499,6 +510,9 @@ public class ColorSchemaReader {
if (nameColumn != null) {
processNameColumn(schema, values[nameColumn]);
}
if (modelNameColumn != null) {
processModelNameColumn(schema, values[modelNameColumn]);
}
if (valueColumn != null) {
schema.setValue(parseValueColumn(values[valueColumn], errorPrefix));
}
......@@ -729,6 +743,9 @@ public class ColorSchemaReader {
if (schema.getName() != null) {
result.add(ColorSchemaColumn.NAME);
}
if (schema.getModelName() != null) {
result.add(ColorSchemaColumn.MODEL_NAME);
}
if (schema.getReactionIdentifier() != null) {
result.add(ColorSchemaColumn.REACTION_IDENTIFIER);
}
......
......@@ -3,7 +3,6 @@ package lcsb.mapviewer.services.utils.data;
import java.util.HashSet;
import java.util.Set;
import lcsb.mapviewer.model.map.layout.ReferenceGenome;
import lcsb.mapviewer.model.map.layout.ReferenceGenomeType;
......@@ -16,136 +15,141 @@ import lcsb.mapviewer.model.map.layout.ReferenceGenomeType;
*/
public enum ColorSchemaColumn {
/**
* Name of the element.
*/
NAME("name", new ColorSchemaType[] { ColorSchemaType.GENERIC, ColorSchemaType.GENETIC_VARIANT }), //
/**
* Value that will be transformed into new color.
*
* @see ColorSchemaColumn#COLOR
*/
VALUE("value", new ColorSchemaType[] { ColorSchemaType.GENERIC }), //
/**
* In which compartment the element should be located.
*/
COMPARTMENT("compartment", new ColorSchemaType[] { ColorSchemaType.GENERIC, ColorSchemaType.GENETIC_VARIANT }), //
/**
* Class type of the element.
*/
TYPE("type", new ColorSchemaType[] { ColorSchemaType.GENERIC, ColorSchemaType.GENETIC_VARIANT }), //
/**
* New element/reaction color.
*/
COLOR("color", new ColorSchemaType[] { ColorSchemaType.GENERIC, ColorSchemaType.GENETIC_VARIANT }), //
/**
* Identifier of the element.
*/
IDENTIFIER("identifier", new ColorSchemaType[] { ColorSchemaType.GENERIC, ColorSchemaType.GENETIC_VARIANT }), //
/**
* Reaction identifier.
*/
REACTION_IDENTIFIER("reactionIdentifier", new ColorSchemaType[] { ColorSchemaType.GENERIC }), //
/**
* New line width of the reaction.
*/
LINE_WIDTH("lineWidth", new ColorSchemaType[] { ColorSchemaType.GENERIC }), //
/**
* Position where gene variants starts.
*/
POSITION("position", new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }), //
/**
* Original DNA of the variant.
*/
ORIGINAL_DNA("original_dna", new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }), //
/**
* Alternative DNA of the variant.
*/
ALTERNATIVE_DNA("alternative_dna", new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }), //
/**
* Short description of the entry.
*/
DESCRIPTION("description", new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT, ColorSchemaType.GENERIC }), //
/**
* Variant references.
*/
REFERENCES("references", new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }), //
/**
* What's the {@link ReferenceGenomeType}.
*/
REFERENCE_GENOME_TYPE("reference_genome_type", new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }), //
/**
* {@link ReferenceGenome#version Version} of the reference genome.
*/
REFERENCE_GENOME_VERSION("reference_genome_version", new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }), //
/**
* Contig where variant was observed.
*/
CONTIG("contig", new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }), //
ALLEL_FREQUENCY("allel_frequency", new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }), //
VARIANT_IDENTIFIER("variant_identifier", new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }), //
/**
* Should the direction of reaction be reversed.
*/
REVERSE_REACTION("reverseReaction", new ColorSchemaType[] { ColorSchemaType.GENERIC }); //
/**
* Default constructor that creates enum entry.
*
* @param title
* {@link #title}
* @param types
* list of {@link ColumnType types} where this column is allowed
*/
ColorSchemaColumn(String title, ColorSchemaType[] types) {
this.title = title;
for (ColorSchemaType colorSchemaType : types) {
this.types.add(colorSchemaType);
}
}
/**
* Human readable title used in input file.
*/
private String title;
/**
* Set of types where column is allowed.
*/
private Set<ColorSchemaType> types = new HashSet<>();
/**
*
* @return {@link #title}
*/
public String getTitle() {
return title;
}
/**
* @return the types
* @see #types
*/
public Set<ColorSchemaType> getTypes() {
return types;
}
/**
* Name of the element.
*/
NAME("name", new ColorSchemaType[] { ColorSchemaType.GENERIC, ColorSchemaType.GENETIC_VARIANT }), //
/**
* Name of the element.
*/
MODEL_NAME("model_name", new ColorSchemaType[] { ColorSchemaType.GENERIC, ColorSchemaType.GENETIC_VARIANT }), //
/**
* Value that will be transformed into new color.
*
* @see ColorSchemaColumn#COLOR
*/
VALUE("value", new ColorSchemaType[] { ColorSchemaType.GENERIC }), //
/**
* In which compartment the element should be located.
*/
COMPARTMENT("compartment", new ColorSchemaType[] { ColorSchemaType.GENERIC, ColorSchemaType.GENETIC_VARIANT }), //
/**
* Class type of the element.
*/
TYPE("type", new ColorSchemaType[] { ColorSchemaType.GENERIC, ColorSchemaType.GENETIC_VARIANT }), //
/**
* New element/reaction color.
*/
COLOR("color", new ColorSchemaType[] { ColorSchemaType.GENERIC, ColorSchemaType.GENETIC_VARIANT }), //
/**
* Identifier of the element.
*/
IDENTIFIER("identifier", new ColorSchemaType[] { ColorSchemaType.GENERIC, ColorSchemaType.GENETIC_VARIANT }), //
/**
* Reaction identifier.
*/
REACTION_IDENTIFIER("reactionIdentifier", new ColorSchemaType[] { ColorSchemaType.GENERIC }), //
/**
* New line width of the reaction.
*/
LINE_WIDTH("lineWidth", new ColorSchemaType[] { ColorSchemaType.GENERIC }), //
/**
* Position where gene variants starts.
*/
POSITION("position", new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }), //
/**
* Original DNA of the variant.
*/
ORIGINAL_DNA("original_dna", new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }), //
/**
* Alternative DNA of the variant.
*/
ALTERNATIVE_DNA("alternative_dna", new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }), //
/**
* Short description of the entry.
*/
DESCRIPTION("description", new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT, ColorSchemaType.GENERIC }), //
/**
* Variant references.
*/
REFERENCES("references", new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }), //
/**
* What's the {@link ReferenceGenomeType}.
*/
REFERENCE_GENOME_TYPE("reference_genome_type", new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }), //
/**
* {@link ReferenceGenome#version Version} of the reference genome.
*/
REFERENCE_GENOME_VERSION("reference_genome_version", new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }), //
/**
* Contig where variant was observed.
*/
CONTIG("contig", new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }), //
ALLEL_FREQUENCY("allel_frequency", new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }), //
VARIANT_IDENTIFIER("variant_identifier", new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }), //
/**
* Should the direction of reaction be reversed.
*/
REVERSE_REACTION("reverseReaction", new ColorSchemaType[] { ColorSchemaType.GENERIC }); //
/**
* Default constructor that creates enum entry.
*
* @param title
* {@link #title}
* @param types
* list of {@link ColumnType types} where this column is allowed
*/
ColorSchemaColumn(String title, ColorSchemaType[] types) {
this.title = title;
for (ColorSchemaType colorSchemaType : types) {
this.types.add(colorSchemaType);
}
}
/**
* Human readable title used in input file.
*/
private String title;
/**
* Set of types where column is allowed.
*/
private Set<ColorSchemaType> types = new HashSet<>();
/**
*
* @return {@link #title}
*/
public String getTitle() {
return title;
}
/**
* @return the types
* @see #types
*/
public Set<ColorSchemaType> getTypes() {
return types;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment