Commit 2887b1e1 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

Merge branch '827-overlay-data-columns' into 'devel_13.1.x'

Resolve "Overlay data columns - review"

See merge request !801
parents 4682e4b0 5eaef346
minerva (12.3.1~beta.1) unstable; urgency=low
* Small improvement: model_name renamed to map_name in data overlay columns
(#827)
* Small improvement: name, type, reference_genome_type and
reference_genome_version column in genetic variant data overlay are
deprecated (#827)
* Bug fix: deprecated columns in data overlay are not visible to the end user
(#827)
* Bug fix: invalid color in data overlay provides proper feedback to the user
(#822)
* Bug fix: genetic variant overlay without name caused problems (#832)
......@@ -19,6 +26,8 @@ minerva (12.3.1~beta.1) unstable; urgency=low
info/submap panel (#824)
* Bug fix: when changing data in edit user dialog there was a need to click
close button twice (#818)
* Bug fix: empty type for data overlay is allowed (#827)
* Bug fix: genetic variants data overlay was ignoring color parameter (#827)
minerva (13.1.0~beta.0) unstable; urgency=low
* Feature: annotators are more flexible - you can define set of input and
......
......@@ -672,7 +672,7 @@ 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)) {
} else if (column.equals(ColorSchemaColumn.MAP_NAME)) {
sb.append(schema.getModelName() + "\t");
} else if (column.equals(ColorSchemaColumn.VALUE)) {
sb.append(schema.getValue() + "\t");
......@@ -727,7 +727,7 @@ 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)) {
} else if (column.equals(ColorSchemaColumn.MAP_NAME)) {
sb.append(schema.getModelName() + "\t");
} else if (column.equals(ColorSchemaColumn.VALUE)) {
sb.append(schema.getValue() + "\t");
......
......@@ -7,6 +7,7 @@ import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
......@@ -166,7 +167,7 @@ public class ColorSchemaReader {
throw new InvalidColorSchemaException(ColorSchemaColumn.GENE_NAME + " and " + ColorSchemaColumn.NAME
+ " column cannot appear in the same dataset");
}
Integer modelNameColumn = schemaColumns.get(ColorSchemaColumn.MODEL_NAME);
Integer modelNameColumn = schemaColumns.get(ColorSchemaColumn.MAP_NAME);
Integer identifierColumn = schemaColumns.get(ColorSchemaColumn.IDENTIFIER);
Integer variantIdentifierColumn = schemaColumns.get(ColorSchemaColumn.VARIANT_IDENTIFIER);
Integer allelFrequencyColumn = schemaColumns.get(ColorSchemaColumn.ALLEL_FREQUENCY);
......@@ -435,7 +436,7 @@ public class ColorSchemaReader {
}
}
for (ColorSchema colorSchema : schemasByName.values()) {
if (colorSchema instanceof GeneVariationColorSchema) {
if (colorSchema instanceof GeneVariationColorSchema && colorSchema.getColor() == null) {
colorSchema.setColor(getGeneVariantsColor(((GeneVariationColorSchema) colorSchema).getGeneVariations()));
}
}
......@@ -446,7 +447,7 @@ public class ColorSchemaReader {
* Gets color that should be assigned to {@link GeneVariationColorSchema}.
*
* @param geneVariations
* list of viariants
* list of variants
* @return {@link Color} that should be assigned to
* {@link GeneVariationColorSchema}
*/
......@@ -493,7 +494,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 modelNameColumn = schemaColumns.get(ColorSchemaColumn.MAP_NAME);
Integer identifierColumn = schemaColumns.get(ColorSchemaColumn.IDENTIFIER);
Integer elementIdentifierColumn = schemaColumns.get(ColorSchemaColumn.ELEMENT_IDENTIFIER);
if (elementIdentifierColumn == null) {
......@@ -591,21 +592,23 @@ public class ColorSchemaReader {
return result;
}
private List<Class<? extends Element>> parseSpeciesTypes(String typesString, String errorPrefix)
List<Class<? extends Element>> parseSpeciesTypes(String typesString, String errorPrefix)
throws InvalidColorSchemaException {
List<Class<? extends Element>> result = new ArrayList<>();
String[] types = typesString.split(",");
for (String string : types) {
SpeciesMapping mapping = SpeciesMapping.getMappingByString(string);
if (mapping != null) {
result.add(mapping.getModelClazz());
} else {
String validStrings = "";
for (SpeciesMapping speciesMapping : SpeciesMapping.values()) {
validStrings += speciesMapping.getCellDesignerString() + ", ";
if (!string.isEmpty()) {
SpeciesMapping mapping = SpeciesMapping.getMappingByString(string);
if (mapping != null) {
result.add(mapping.getModelClazz());
} else {
String validStrings = "";
for (SpeciesMapping speciesMapping : SpeciesMapping.values()) {
validStrings += speciesMapping.getCellDesignerString() + ", ";
}
throw new InvalidColorSchemaException(
errorPrefix + "Unknown class type: " + string + ". Valid values are: " + validStrings);
}
throw new InvalidColorSchemaException(
errorPrefix + "Unknown class type: " + string + ". Valid values are: " + validStrings);
}
}
return result;
......@@ -718,7 +721,15 @@ public class ColorSchemaReader {
} else {
String columnNames = "";
for (ColorSchemaColumn schemaColumn : ColorSchemaColumn.values()) {
if (schemaColumn.getTypes().contains(type)) {
boolean deprecated = false;
try {
Field f = ColorSchemaColumn.class.getField(schemaColumn.name());
if (f.isAnnotationPresent(Deprecated.class))
deprecated = true;
} catch (NoSuchFieldException | SecurityException e) {
}
if (schemaColumn.getTypes().contains(type) && !deprecated) {
columnNames += schemaColumn.getColumnName() + ", ";
}
}
......@@ -787,7 +798,7 @@ public class ColorSchemaReader {
result.add(ColorSchemaColumn.NAME);
}
if (schema.getModelName() != null) {
result.add(ColorSchemaColumn.MODEL_NAME);
result.add(ColorSchemaColumn.MAP_NAME);
}
if (schema.getElementId() != null) {
result.add(ColorSchemaColumn.ELEMENT_IDENTIFIER);
......
......@@ -156,7 +156,7 @@ public class ColorSchemaXlsxReader {
valueColumn = foundSchemaColumns.get(ColorSchemaColumn.VALUE);
colorColumn = foundSchemaColumns.get(ColorSchemaColumn.COLOR);
nameColumn = foundSchemaColumns.get(ColorSchemaColumn.NAME);
modelNameColumn = foundSchemaColumns.get(ColorSchemaColumn.MODEL_NAME);
modelNameColumn = foundSchemaColumns.get(ColorSchemaColumn.MAP_NAME);
identifierColumn = foundSchemaColumns.get(ColorSchemaColumn.IDENTIFIER);
elementIdentifierColumn = foundSchemaColumns.get(ColorSchemaColumn.ELEMENT_IDENTIFIER);
if (elementIdentifierColumn == null) {
......@@ -326,7 +326,7 @@ public class ColorSchemaXlsxReader {
result.add(ColorSchemaColumn.NAME);
}
if (schema.getModelName() != null) {
result.add(ColorSchemaColumn.MODEL_NAME);
result.add(ColorSchemaColumn.MAP_NAME);
}
if (schema.getElementId() != null) {
result.add(ColorSchemaColumn.ELEMENT_IDENTIFIER);
......
......@@ -19,14 +19,14 @@ public enum ColorSchemaColumn {
/**
* Name of the element.
*/
NAME(new ColorSchemaType[] { ColorSchemaType.GENERIC, ColorSchemaType.GENETIC_VARIANT }),
NAME(new ColorSchemaType[] { ColorSchemaType.GENERIC}),
GENE_NAME(new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }),
/**
* Name of the element.
* Name of the map.
*/
MODEL_NAME(new ColorSchemaType[] { ColorSchemaType.GENERIC, ColorSchemaType.GENETIC_VARIANT }),
MAP_NAME("model_name",new ColorSchemaType[] { ColorSchemaType.GENERIC, ColorSchemaType.GENETIC_VARIANT }),
/**
* Value that will be transformed into new color.
......@@ -43,7 +43,7 @@ public enum ColorSchemaColumn {
/**
* Class type of the element.
*/
TYPE(new ColorSchemaType[] { ColorSchemaType.GENERIC, ColorSchemaType.GENETIC_VARIANT }),
TYPE(new ColorSchemaType[] { ColorSchemaType.GENERIC}),
/**
* New element/reaction color.
......@@ -99,11 +99,13 @@ public enum ColorSchemaColumn {
/**
* What's the {@link ReferenceGenomeType}.
*/
@Deprecated
REFERENCE_GENOME_TYPE(new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }),
/**
* {@link ReferenceGenome#version Version} of the reference genome.
*/
@Deprecated
REFERENCE_GENOME_VERSION(new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }),
/**
......
......@@ -17,6 +17,7 @@ import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.io.output.ByteArrayOutputStream;
......@@ -28,19 +29,24 @@ import org.junit.Test;
import lcsb.mapviewer.commands.ColorExtractor;
import lcsb.mapviewer.commands.ColorModelCommand;
import lcsb.mapviewer.common.TextFileUtils;
import lcsb.mapviewer.model.map.BioEntity;
import lcsb.mapviewer.model.map.MiriamData;
import lcsb.mapviewer.model.map.layout.ColorSchema;
import lcsb.mapviewer.model.map.layout.GeneVariation;
import lcsb.mapviewer.model.map.layout.GeneVariationColorSchema;
import lcsb.mapviewer.model.map.layout.InvalidColorSchemaException;
import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.services.ServiceTestFunctions;
public class ColorSchemaReaderTest extends ServiceTestFunctions {
Logger logger = Logger.getLogger(ColorSchemaReaderTest.class);
ColorSchemaReader reader;
@Before
public void setUp() throws Exception {
reader = new ColorSchemaReader();
}
@After
......@@ -50,8 +56,6 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions {
@Test
public void testReadSchema() throws Exception {
try {
ColorSchemaReader reader = new ColorSchemaReader();
Collection<ColorSchema> schemas = reader.readColorSchema("testFiles/enricoData/ageing.txt");
assertNotNull(schemas);
......@@ -81,8 +85,6 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions {
ByteArrayInputStream bin = new ByteArrayInputStream(data);
ColorSchemaReader reader = new ColorSchemaReader();
Collection<ColorSchema> schemas = reader.readColorSchema(bin,
TextFileUtils.getHeaderParametersFromFile(new ByteArrayInputStream(data)));
assertNotNull(schemas);
......@@ -101,8 +103,6 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions {
ByteArrayInputStream bin = new ByteArrayInputStream(data);
ColorSchemaReader reader = new ColorSchemaReader();
Collection<ColorSchema> schemas = reader.readColorSchema(bin,
TextFileUtils.getHeaderParametersFromFile(new ByteArrayInputStream(data)));
assertNotNull(schemas);
......@@ -140,8 +140,6 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions {
ByteArrayInputStream bin = new ByteArrayInputStream(data);
ColorSchemaReader reader = new ColorSchemaReader();
Collection<ColorSchema> schemas = reader.readColorSchema(bin,
TextFileUtils.getHeaderParametersFromFile(new ByteArrayInputStream(data)));
assertNotNull(schemas);
......@@ -168,8 +166,6 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions {
ByteArrayInputStream bin = new ByteArrayInputStream(data);
ColorSchemaReader reader = new ColorSchemaReader();
Collection<ColorSchema> schemas = reader.readColorSchema(bin,
TextFileUtils.getHeaderParametersFromFile(new ByteArrayInputStream(data)));
assertNotNull(schemas);
......@@ -188,8 +184,6 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions {
ByteArrayInputStream bin = new ByteArrayInputStream(data);
ColorSchemaReader reader = new ColorSchemaReader();
Collection<ColorSchema> schemas = reader.readColorSchema(bin,
TextFileUtils.getHeaderParametersFromFile(new ByteArrayInputStream(data)));
assertNotNull(schemas);
......@@ -203,8 +197,6 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions {
@Test
public void testReadInvalidGeneVariantsSchema() throws Exception {
try {
ColorSchemaReader reader = new ColorSchemaReader();
reader.readColorSchema("testFiles/coloring/gene_variants_invalid_genome.txt");
fail("Exception expected");
} catch (InvalidColorSchemaException e) {
......@@ -217,8 +209,6 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions {
@Test
public void testReadSchema2() throws Exception {
try {
ColorSchemaReader reader = new ColorSchemaReader();
Collection<ColorSchema> schemas = reader.readColorSchema("testFiles/coloring/goodSchema.txt");
assertNotNull(schemas);
......@@ -234,7 +224,6 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions {
public void testReadSchema3() throws Exception {
try {
try {
ColorSchemaReader reader = new ColorSchemaReader();
reader.readColorSchema("testFiles/coloring/wrongSchema.txt");
fail("Excepion expected");
} catch (InvalidColorSchemaException e) {
......@@ -248,7 +237,6 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions {
@Test
public void testProblematicStephanSchema3() throws Exception {
try {
ColorSchemaReader reader = new ColorSchemaReader();
reader.readColorSchema("testFiles/coloring/problematicSchema.txt");
} catch (Exception e) {
e.printStackTrace();
......@@ -259,7 +247,6 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions {
@Test
public void testReadReactionSchema() throws Exception {
try {
ColorSchemaReader reader = new ColorSchemaReader();
Collection<ColorSchema> collection = reader.readColorSchema("testFiles/coloring/reactionSchema.txt");
assertEquals(1, collection.size());
ColorSchema schema = collection.iterator().next();
......@@ -275,8 +262,6 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions {
@Test(timeout = 15000)
public void testNextVersionReadSchema() throws Exception {
try {
ColorSchemaReader reader = new ColorSchemaReader();
Collection<ColorSchema> schemas = reader.readColorSchema("testFiles/coloring/goodLayout.v=1.0.txt");
assertNotNull(schemas);
......@@ -295,8 +280,6 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions {
Model model = getModelForFile("testFiles/coloring/protein_to_color.xml", false);
ColorSchemaReader reader = new ColorSchemaReader();
Collection<ColorSchema> schemas = reader.readColorSchema("testFiles/coloring/problematicSchema.txt");
ColorModelCommand factory = new ColorModelCommand(model, schemas, colorExtractor);
factory.execute();
......@@ -312,7 +295,6 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions {
@Test
public void testColoringWithValueOrColor() throws Exception {
try {
ColorSchemaReader reader = new ColorSchemaReader();
Map<String, String> params = new HashMap<>();
params.put(TextFileUtils.COLUMN_COUNT_PARAM, "3");
......@@ -331,7 +313,6 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions {
@Test
public void testElementsByType() throws Exception {
try {
ColorSchemaReader reader = new ColorSchemaReader();
Map<String, String> params = new HashMap<>();
params.put(TextFileUtils.COLUMN_COUNT_PARAM, "3");
......@@ -349,7 +330,6 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions {
@Test
public void testColoringWithInvalidValueAndColor() throws Exception {
try {
ColorSchemaReader reader = new ColorSchemaReader();
Map<String, String> params = new HashMap<>();
params.put(TextFileUtils.COLUMN_COUNT_PARAM, "3");
......@@ -366,7 +346,6 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions {
@Test
public void testColoringWithEmptyColor() throws Exception {
try {
ColorSchemaReader reader = new ColorSchemaReader();
Map<String, String> params = new HashMap<>();
params.put(TextFileUtils.COLUMN_COUNT_PARAM, "3");
......@@ -383,7 +362,6 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions {
@Test
public void testColoringWithInvalidValueAndColor2() throws Exception {
try {
ColorSchemaReader reader = new ColorSchemaReader();
Map<String, String> params = new HashMap<>();
params.put(TextFileUtils.COLUMN_COUNT_PARAM, "3");
......@@ -398,8 +376,6 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions {
@Test
public void testSchemasWithId() throws Exception {
try {
ColorSchemaReader reader = new ColorSchemaReader();
Collection<ColorSchema> schemas = reader.readColorSchema("testFiles/coloring/schemaWithIdentifiers.txt");
for (ColorSchema colorSchema : schemas) {
for (MiriamData md : colorSchema.getMiriamData()) {
......@@ -417,9 +393,8 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions {
@Test
public void testSchemasWithIdSnakeCase() throws Exception {
try {
ColorSchemaReader reader = new ColorSchemaReader();
Collection<ColorSchema> schemas = reader.readColorSchema("testFiles/coloring/schema_with_identifiers_in_snake_case.txt");
Collection<ColorSchema> schemas = reader
.readColorSchema("testFiles/coloring/schema_with_identifiers_in_snake_case.txt");
for (ColorSchema colorSchema : schemas) {
for (MiriamData md : colorSchema.getMiriamData()) {
assertNotNull(md.getResource());
......@@ -436,8 +411,6 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions {
@Test
public void testSchemasWithEmptyNameAndId() throws Exception {
try {
ColorSchemaReader reader = new ColorSchemaReader();
Collection<ColorSchema> schemas = reader.readColorSchema("testFiles/coloring/schemaIdWithoutName.txt");
for (ColorSchema colorSchema : schemas) {
for (MiriamData md : colorSchema.getMiriamData()) {
......@@ -455,7 +428,6 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions {
@Test
public void testSimpleNameSchemas() throws Exception {
try {
ColorSchemaReader reader = new ColorSchemaReader();
String input = "#header\ns1\ns2\n";
Collection<ColorSchema> schemas = reader
.readSimpleNameColorSchema(new ByteArrayInputStream(input.getBytes(StandardCharsets.UTF_8)));
......@@ -466,4 +438,47 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions {
}
}
@Test
public void testParseSpeciesTypesForEmptyString() throws Exception {
List<Class<? extends Element>> classes = reader.parseSpeciesTypes("", null);
assertEquals(0, classes.size());
}
@Test
public void testColoringWithModelName() throws Exception {
try {
String input = "name\tcolor\tmodel_name\n" +
"s1\t#ff0000\txxx\n" ;
Map<String, String> params = new HashMap<>();
params.put(TextFileUtils.COLUMN_COUNT_PARAM, "3");
Collection<ColorSchema> schemas = reader
.readColorSchema(new ByteArrayInputStream(input.getBytes(StandardCharsets.UTF_8)), params);
assertEquals(1, schemas.size());
assertNotNull(schemas.iterator().next().getModelName());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testColoringWithMapName() throws Exception {
try {
String input = "name\tcolor\tmap_name\n" +
"s1\t#ff0000\txxx\n" ;
Map<String, String> params = new HashMap<>();
params.put(TextFileUtils.COLUMN_COUNT_PARAM, "3");
Collection<ColorSchema> schemas = reader
.readColorSchema(new ByteArrayInputStream(input.getBytes(StandardCharsets.UTF_8)), params);
assertEquals(1, schemas.size());
assertNotNull(schemas.iterator().next().getModelName());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment